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

Merge pull request #47 from NaughtyMC/master

Improvement: Allow user to manually connect and disconnect
This commit is contained in:
Viktor
2018-04-03 17:57:46 +03:00
committed by GitHub
5 changed files with 35 additions and 4 deletions
+3
View File
@@ -2,6 +2,9 @@
This package is [semantic versioned](http://semver.org/)
## 2.0.7
- [feature]: manual connect/disconnect
## 2.0.6
- [bugfix]: reconnection thx [@weglov](https://github.com/weglov)
+12
View File
@@ -61,6 +61,18 @@ Vue.use(VueNativeSock, 'ws://localhost:9090', {
})
```
Manage connection manually:
``` js
Vue.use(VueNativeSock, 'ws://localhost:9090', {
connectManually: true,
})
const vm = new Vue()
vm.$connect()
// do stuff with WebSockets
vm.$disconnect()
```
#### On Vuejs instance usage
``` js
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "vue-native-websocket",
"version": "2.0.6",
"version": "2.0.7",
"description": "native websocket implemantation for vuejs and vuex",
"main": "dist/build.js",
"scripts": {
+18 -2
View File
@@ -6,9 +6,25 @@ export default {
install (Vue, connection, opts = {}) {
if (!connection) { throw new Error('[vue-native-socket] cannot locate connection') }
let observer = new Observer(connection, opts)
let observer = null
Vue.prototype.$socket = observer.WebSocket
if (opts.connectManually) {
Vue.prototype.$connect = () => {
observer = new Observer(connection, opts)
Vue.prototype.$socket = observer.WebSocket
}
Vue.prototype.$disconnect = () => {
if (observer && observer.reconnection) { observer.reconnection = false }
if (Vue.prototype.$socket) {
Vue.prototype.$socket.close()
delete Vue.prototype.$socket
}
}
} else {
observer = new Observer(connection, opts)
Vue.prototype.$socket = observer.WebSockekt
}
Vue.mixin({
created () {