26 lines
696 B
TypeScript
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);
|
|
}
|
|
} |