2
0
mirror of https://github.com/tenrok/vue-native-websocket.git synced 2026-05-17 04:19:38 +03:00

Feature handle skip scheme ws url

if skip scheme url, like ` //localhost:8080` ,  add `ws` or
`wss` .
This commit is contained in:
denzow
2018-05-07 21:36:44 +09:00
parent 649485e28b
commit c0f0209fe0
2 changed files with 18 additions and 0 deletions
+4
View File
@@ -3,6 +3,10 @@ import Emitter from './Emitter'
export default class {
constructor (connectionUrl, opts = {}) {
this.format = opts.format && opts.format.toLowerCase()
if(connectionUrl.startsWith('//')){
const scheme = window.location.protocol === 'https:' ? 'wss' : 'ws';
connectionUrl = `${scheme}://${connectionUrl}`
}
this.connectionUrl = connectionUrl
this.opts = opts
+14
View File
@@ -23,6 +23,20 @@ describe('Observer.js', () => {
}, vm)
})
it('fires onopen event skip scheme', (done) => {
mockServer = new Server(wsUrl)
mockServer.on('connection', ws => {
ws.send('hi')
})
Vue.use(VueNativeSock, '//localhost:8080')
let vm = new Vue()
observer = new Observer(wsUrl)
Emitter.addListener('onopen', (data) => {
expect(data.type).to.equal('open')
mockServer.stop(done)
}, vm)
})
// TODO: DRY
it('passes a json commit to the provided vuex store', (done) => {
let expectedMsg = { mutation: 'setName', value: 'steve' }