nope/lib/communication/socketClient.ts

19 lines
516 B
TypeScript

import { CommunicationEvents, ICommunicationInterface } from "../dispatcher/nopeDispatcher";
import { Socket, connect } from 'socket.io-client';
export class SocketClient implements ICommunicationInterface{
protected _socket: typeof Socket;
constructor(public uri: string){
this._socket = connect(uri);
}
on(event: CommunicationEvents, cb: (...args: any[]) => void) {
this._socket.on('event', cb);
}
send(data: any): void {
this._socket.emit(data);
}
}