Skip to content

Instantly share code, notes, and snippets.

@hoangsetup
Last active May 30, 2021 08:10
Show Gist options
  • Save hoangsetup/8dc012ef77d104765b6969aaf0311999 to your computer and use it in GitHub Desktop.
Save hoangsetup/8dc012ef77d104765b6969aaf0311999 to your computer and use it in GitHub Desktop.
import { Server as HttpServer } from "http";
import { Server } from "socket.io";
import pm2Lib, { IProcessOutLog } from "./pm2Lib";
class SocketIO {
private io: Server | undefined;
init(httpServer: HttpServer) {
if (this.io !== undefined) {
throw new Error('Socket server already defined!');
}
this.io = new Server(httpServer);
pm2Lib.onLogOut((procLog: IProcessOutLog) => {
this.io?.emit(`${procLog.process.name}:out_log`, procLog);
});
}
}
export default new SocketIO();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment