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:
@@ -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
|
||||
|
||||
|
||||
@@ -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' }
|
||||
|
||||
Reference in New Issue
Block a user