mirror of
https://github.com/tenrok/vue-native-websocket.git
synced 2026-06-11 15:42:25 +03:00
v2
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
||||
import Observer from './Observer'
|
||||
import Emitter from './Emitter'
|
||||
|
||||
export default {
|
||||
|
||||
install(Vue, connection){
|
||||
|
||||
if(!connection) throw new Error("[Vue-Socket.io] cannot locate connection")
|
||||
|
||||
let observer = new Observer(connection)
|
||||
|
||||
Vue.prototype.$socket = observer.Socket;
|
||||
|
||||
Vue.mixin({
|
||||
beforeCreate(){
|
||||
let _this = this;
|
||||
let sockets = this.$options['sockets']
|
||||
|
||||
if(sockets){
|
||||
Object.keys(sockets).forEach(function(key) {
|
||||
Emitter.addListener(key, sockets[key], _this)
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
beforeDestroy(){
|
||||
let _this = this;
|
||||
let sockets = this.$options['sockets']
|
||||
|
||||
if(sockets){
|
||||
Object.keys(sockets).forEach(function(key) {
|
||||
Emitter.removeListener(key, sockets[key], _this)
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user