nope/lib/communication/IoSocketClient.ts
2020-09-12 02:59:30 +02:00

26 lines
696 B
TypeScript

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