2
0
mirror of https://github.com/tenrok/vue-native-websocket.git synced 2026-06-13 11:42:26 +03:00
This commit is contained in:
Metin Seylan
2016-10-29 00:47:04 +03:00
parent 88d8479209
commit 7f5fac27d0
16 changed files with 198 additions and 440 deletions
+33
View File
@@ -0,0 +1,33 @@
import Emitter from './Emitter'
import Socket from 'socket.io-client'
export default class{
constructor(connection) {
if(typeof connection == 'string'){
this.Socket = Socket(connection);
}else{
this.Socket = connection
}
this.onEvent()
}
onEvent(){
this.Socket.onevent = (packet) => {
Emitter.emit(packet.data[0], packet.data[1])
}
let _this = this;
["connect", "error", "disconnect", "reconnect", "reconnect_attempt", "reconnecting", "reconnect_error", "reconnect_failed"]
.forEach((value) => {
_this.Socket.on(value, (data) => {
Emitter.emit(value, data)
})
})
}
}