File size: 610 Bytes
c02f046 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
class IO {
connect(){
let baseURL = location.origin || location.protocol + "//" + location.host;
this.socket = io.connect(baseURL);
this.socket.on("connect", () => {
console.log('CONNECTED!');
});
this.socket.on("disconnect", () => {
console.log('DISCONNECTED!');
});
this.attachEvents();
}
attachEvents(){
this.socket.on('state', state => window.app.setState(state));
this.socket.on('frame', state => window.app.onFrame(state));
}
emit(event, data){
this.socket.emit(event, data)
}
}
const instance = new IO();
export default instance;
|