2
0
mirror of https://github.com/tenrok/vue-native-websocket.git synced 2026-06-18 03:30:35 +03:00

support websocket protocol, this is optional option.

This commit is contained in:
Aaron Chen
2017-06-29 15:31:50 +08:00
parent fd5d4a6a59
commit 93e17ffe0f
3 changed files with 7 additions and 7 deletions
+2 -2
View File
@@ -3,10 +3,10 @@ import Emitter from './Emitter'
export default {
install (Vue, connection, store, opts = {}) {
install (Vue, connection, protocol = '', store, opts = {}) {
if (!connection) { throw new Error('[vue-native-socket] cannot locate connection') }
let observer = new Observer(connection, store, opts)
let observer = new Observer(connection, store, protocol, opts)
Vue.prototype.$socket = observer.WebSocket
+4 -4
View File
@@ -1,15 +1,15 @@
import Emitter from './Emitter'
export default class {
constructor (connectionUrl, store, opts = {}) {
constructor (connectionUrl, protocol, store, opts = {}) {
this.format = opts.format && opts.format.toLowerCase()
this.connect(connectionUrl)
this.connect(connectionUrl, protocol)
if (store) { this.store = store }
this.onEvent()
}
connect (connectionUrl) {
this.WebSocket = new WebSocket(connectionUrl)
connect (connectionUrl, protocol) {
this.WebSocket = new WebSocket(connectionUrl, protocol)
if (this.format === 'json') {
if (!('sendObj' in this.WebSocket)) {
this.WebSocket.sendObj = (obj) => this.WebSocket.send(JSON.stringify(obj))