2
0
mirror of https://github.com/tenrok/vue-native-websocket.git synced 2026-06-06 23:42:26 +03:00

Api updates (#7)

* move all instantiation options into the opts hash

* 2.0.0
This commit is contained in:
Nathan
2017-07-07 09:47:01 -07:00
committed by GitHub
parent b62cc5a27c
commit 46e251dcbc
8 changed files with 68 additions and 21 deletions
+2 -2
View File
@@ -3,10 +3,10 @@ import Emitter from './Emitter'
export default {
install (Vue, connection, protocol = '', store, opts = {}) {
install (Vue, connection, opts = {}) {
if (!connection) { throw new Error('[vue-native-socket] cannot locate connection') }
let observer = new Observer(connection, protocol, store, opts)
let observer = new Observer(connection, opts)
Vue.prototype.$socket = observer.WebSocket
+5 -4
View File
@@ -1,14 +1,15 @@
import Emitter from './Emitter'
export default class {
constructor (connectionUrl, protocol, store, opts = {}) {
constructor (connectionUrl, opts = {}) {
this.format = opts.format && opts.format.toLowerCase()
this.connect(connectionUrl, protocol, opts)
if (store) { this.store = store }
this.connect(connectionUrl, opts)
if (opts.store) { this.store = opts.store }
this.onEvent()
}
connect (connectionUrl, protocol, opts = {}) {
connect (connectionUrl, opts = {}) {
let protocol = opts.protocol || ''
this.WebSocket = opts.WebSocket || new WebSocket(connectionUrl, protocol)
if (this.format === 'json') {
if (!('sendObj' in this.WebSocket)) {