@eleven-am/pondsocket 0.1.153 → 0.1.154
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -228,12 +228,13 @@ describe('endpoint', () => {
|
|
|
228
228
|
}))
|
|
229
229
|
.close();
|
|
230
230
|
}));
|
|
231
|
-
it('should throw an error if accept, reject
|
|
231
|
+
it('should throw an error if accept, reject is called more than once', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
232
232
|
socket.createEndpoint('/api/:room', (_, res) => {
|
|
233
233
|
res.reply('hello', {
|
|
234
234
|
test: 'test',
|
|
235
235
|
});
|
|
236
|
-
|
|
236
|
+
res.accept();
|
|
237
|
+
expect(() => res.decline()).toThrowError('Cannot execute response more than once');
|
|
237
238
|
});
|
|
238
239
|
yield (0, superwstest_1.default)(server)
|
|
239
240
|
.ws('/api/socket')
|
package/endpoint/response.js
CHANGED
|
@@ -14,6 +14,7 @@ var _ConnectionResponse_instances, _ConnectionResponse_webSocket, _ConnectionRes
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.ConnectionResponse = void 0;
|
|
16
16
|
const pondsocket_common_1 = require("@eleven-am/pondsocket-common");
|
|
17
|
+
const ws_1 = require("ws");
|
|
17
18
|
const pondError_1 = require("../errors/pondError");
|
|
18
19
|
class ConnectionResponse {
|
|
19
20
|
constructor(webSocket, engine, clientId) {
|
|
@@ -85,7 +86,9 @@ class ConnectionResponse {
|
|
|
85
86
|
* @param payload - the payload to send
|
|
86
87
|
*/
|
|
87
88
|
reply(event, payload) {
|
|
88
|
-
__classPrivateFieldGet(this,
|
|
89
|
+
if (__classPrivateFieldGet(this, _ConnectionResponse_webSocket, "f").readyState !== ws_1.WebSocket.OPEN) {
|
|
90
|
+
throw new pondError_1.EndpointError('Socket is not open', 400);
|
|
91
|
+
}
|
|
89
92
|
__classPrivateFieldGet(this, _ConnectionResponse_instances, "m", _ConnectionResponse_sendMessage).call(this, pondsocket_common_1.ServerActions.BROADCAST, event, payload);
|
|
90
93
|
return this;
|
|
91
94
|
}
|