mirror of
https://github.com/tenrok/vue-native-websocket.git
synced 2026-06-21 00:20:34 +03:00
Merge pull request #53 from denzow/master
Feature handle skip scheme ws url
This commit is contained in:
@@ -3,6 +3,10 @@ import Emitter from './Emitter'
|
|||||||
export default class {
|
export default class {
|
||||||
constructor (connectionUrl, opts = {}) {
|
constructor (connectionUrl, opts = {}) {
|
||||||
this.format = opts.format && opts.format.toLowerCase()
|
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.connectionUrl = connectionUrl
|
||||||
this.opts = opts
|
this.opts = opts
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,20 @@ describe('Observer.js', () => {
|
|||||||
}, vm)
|
}, 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
|
// TODO: DRY
|
||||||
it('passes a json commit to the provided vuex store', (done) => {
|
it('passes a json commit to the provided vuex store', (done) => {
|
||||||
let expectedMsg = { mutation: 'setName', value: 'steve' }
|
let expectedMsg = { mutation: 'setName', value: 'steve' }
|
||||||
|
|||||||
Reference in New Issue
Block a user