Spaces:
Sleeping
Sleeping
Download dist/websocket/wsServer.js from sardarbipul/test: direct link, hf CLI and curl.
- Browser
- Download file 1.53 kB
-
https://huggingface.co/spaces/sardarbipul/test/resolve/main/dist/websocket/wsServer.js
- Command line
-
hf download hf://spaces/sardarbipul/test/dist/websocket/wsServer.js
-
curl -L -o wsServer.js https://huggingface.co/spaces/sardarbipul/test/resolve/main/dist/websocket/wsServer.js
1.53 kB
| ; | |
| Object.defineProperty(exports, "__esModule", { value: true }); | |
| exports.TaskBrokerWebSocketServer = void 0; | |
| const ws_1 = require("ws"); | |
| const app_config_1 = require("../config/app.config"); | |
| const logger_1 = require("../utils/logger"); | |
| class TaskBrokerWebSocketServer { | |
| wss; | |
| handler; | |
| constructor(server, handler) { | |
| this.handler = handler; | |
| this.wss = new ws_1.WebSocketServer({ server, path: app_config_1.CONFIG.WS.PATH }); | |
| this.init(); | |
| } | |
| init() { | |
| logger_1.logger.info(`WebSocket Server initialized on endpoint path [${app_config_1.CONFIG.WS.PATH}]`); | |
| this.wss.on('connection', (ws) => { | |
| this.handler.handleConnection(ws); | |
| }); | |
| // Send periodic pings to keep connections alive through cloud proxies/load balancers | |
| const pingInterval = setInterval(() => { | |
| this.wss.clients.forEach((client) => { | |
| if (client.readyState === ws_1.WebSocket.OPEN) { | |
| client.ping(); | |
| } | |
| }); | |
| }, app_config_1.CONFIG.WS.PING_INTERVAL_MS); | |
| this.wss.on('close', () => { | |
| clearInterval(pingInterval); | |
| }); | |
| } | |
| sendToWorker(workerId, message) { | |
| const ws = this.handler.getSocketForWorker(workerId); | |
| if (ws && ws.readyState === ws_1.WebSocket.OPEN) { | |
| ws.send(JSON.stringify(message)); | |
| return true; | |
| } | |
| return false; | |
| } | |
| } | |
| exports.TaskBrokerWebSocketServer = TaskBrokerWebSocketServer; | |