Skip to content

Commit

Permalink
Cleanup sockets and fix socket rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
tagyoureit committed Apr 22, 2021
1 parent 8ad1e40 commit 73fe7eb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# nodejs-poolController - Version 7.0.0
# nodejs-poolController - Version 7.0.1

## What is nodejs-poolController

Expand Down
8 changes: 3 additions & 5 deletions web/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,24 +229,23 @@ interface ClientToServerEvents {

interface ServerToClientEvents {
withAck: (d: string, cb: (e: number) => void) => void;
[event: string]: (...args: any[]) => void;
}
export class HttpServer extends ProtoServer {
// Http protocol
public app: express.Application;
public server: http.Server;
public sockServer: SocketIoServer<ClientToServerEvents, ServerToClientEvents>;
private _nameSpace: Namespace;
private _sockets: RemoteSocket<ServerToClientEvents>[] = [];
public emitToClients(evt: string, ...data: any) {
if (this.isRunning) {
this._nameSpace.emit(evt, ...data);
this.sockServer.emit(evt, ...data);
}
}
public emitToChannel(channel: string, evt: string, ...data: any) {
//console.log(`Emitting to channel ${channel} - ${evt}`)
if (this.isRunning) {
let _nameSpace: Namespace = this.sockServer.of(channel);
_nameSpace.emit(evt, ...data);
this.sockServer.to(channel).emit(evt, ...data);
}
}
public get isConnected() { return typeof this.sockServer !== 'undefined' && this._sockets.length > 0; }
Expand All @@ -260,7 +259,6 @@ export class HttpServer extends ProtoServer {
}
}
this.sockServer = new SocketIoServer(this.server, options);
this._nameSpace = this.sockServer.of('/');
this.sockServer.on("connection", (sock: Socket) => {
logger.info(`New socket client connected ${sock.id} -- ${sock.client.conn.remoteAddress}`);
this.socketHandler(sock);
Expand Down

0 comments on commit 73fe7eb

Please sign in to comment.