adding communication backends
This commit is contained in:
parent
4f21b42013
commit
123495b654
@ -1,6 +1,9 @@
|
||||
import { EventEmitter } from "events";
|
||||
import { CommunicationEvents, ICommunicationInterface } from "../callDispatcher";
|
||||
import { CommunicationEvents, ICommunicationInterface } from "../dispatcher/nopeDispatcher";
|
||||
|
||||
/**
|
||||
* Event Layer.
|
||||
*/
|
||||
export class EventLayer implements ICommunicationInterface {
|
||||
protected _emitter = new EventEmitter();
|
||||
on(event: CommunicationEvents, cb: (...args: any[]) => void) {
|
||||
|
27
lib/communication/socketBackend.ts
Normal file
27
lib/communication/socketBackend.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { CommunicationEvents, ICommunicationInterface } from "../dispatcher/nopeDispatcher";
|
||||
import * as io from 'socket.io';
|
||||
import { Server } from "http";
|
||||
|
||||
const server = require('http').createServer();
|
||||
export class SocketBackend implements ICommunicationInterface{
|
||||
|
||||
protected _socket: io.Server
|
||||
|
||||
constructor(public port: number, server?: Server){
|
||||
if (server){
|
||||
this._socket = (io as any)(server);
|
||||
} else {
|
||||
this._socket = (io as any)();
|
||||
}
|
||||
|
||||
this._socket.listen(port);
|
||||
}
|
||||
|
||||
on(event: CommunicationEvents, cb: (...args: any[]) => void) {
|
||||
this._socket.on('event', cb);
|
||||
}
|
||||
|
||||
send(data: any): void {
|
||||
this._socket.emit(data);
|
||||
}
|
||||
}
|
19
lib/communication/socketClient.ts
Normal file
19
lib/communication/socketClient.ts
Normal file
@ -0,0 +1,19 @@
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user