Skip to content

Commit 8376ad1

Browse files
authored
Merge pull request nathantsoi#53 from denzow/master
Feature handle skip scheme ws url
2 parents b7f3a45 + c0f0209 commit 8376ad1

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Observer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import Emitter from './Emitter'
33
export default class {
44
constructor (connectionUrl, opts = {}) {
55
this.format = opts.format && opts.format.toLowerCase()
6+
if(connectionUrl.startsWith('//')){
7+
const scheme = window.location.protocol === 'https:' ? 'wss' : 'ws';
8+
connectionUrl = `${scheme}://${connectionUrl}`
9+
}
610
this.connectionUrl = connectionUrl
711
this.opts = opts
812

test/unit/specs/Observer.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ describe('Observer.js', () => {
2323
}, vm)
2424
})
2525

26+
it('fires onopen event skip scheme', (done) => {
27+
mockServer = new Server(wsUrl)
28+
mockServer.on('connection', ws => {
29+
ws.send('hi')
30+
})
31+
Vue.use(VueNativeSock, '//localhost:8080')
32+
let vm = new Vue()
33+
observer = new Observer(wsUrl)
34+
Emitter.addListener('onopen', (data) => {
35+
expect(data.type).to.equal('open')
36+
mockServer.stop(done)
37+
}, vm)
38+
})
39+
2640
// TODO: DRY
2741
it('passes a json commit to the provided vuex store', (done) => {
2842
let expectedMsg = { mutation: 'setName', value: 'steve' }

0 commit comments

Comments
 (0)