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:
+2
-2
@@ -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
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user