UNPKG

@ovotech/genesys-web-messaging-tester

Version:
26 lines (25 loc) 894 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WebMessageServerFixture = void 0; const ws_1 = require("ws"); const WebMessageServerConnectionFixture_1 = require("./WebMessageServerConnectionFixture"); class WebMessageServerFixture { constructor(port) { this.port = port; this.wss = new ws_1.WebSocketServer({ port }); this.connections = []; this.wss.on('connection', (ws) => { this.connections.push(ws); }); } async waitForConnection() { return new Promise((resolve) => { this.wss.on('connection', (ws) => resolve(new WebMessageServerConnectionFixture_1.WebMessageServerConnectionFixture(ws))); }); } close() { this.connections.forEach((c) => c.close()); this.wss.close(); } } exports.WebMessageServerFixture = WebMessageServerFixture;