nope/lib/communication/socketClient.ts

22 lines
602 B
TypeScript
Raw Normal View History

2020-09-10 16:21:01 +00:00
import { connect, Socket } from 'socket.io-client';
2020-08-23 07:21:03 +00:00
import { CommunicationEvents, ICommunicationInterface } from "../dispatcher/nopeDispatcher";
2020-09-10 16:21:01 +00:00
export class SocketClient implements ICommunicationInterface {
2020-08-23 07:21:03 +00:00
protected _socket: typeof Socket;
2020-09-10 16:21:01 +00:00
constructor(public uri: string) {
this._socket = connect(uri);
this._socket.on('connect', () => {
console.log('connected')
})
2020-08-23 07:21:03 +00:00
}
on(event: CommunicationEvents, cb: (...args: any[]) => void) {
this._socket.on('event', cb);
}
send(data: any): void {
this._socket.emit(data);
}
}