@eleven-am/pondsocket 0.1.147 → 0.1.148
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.
package/channel/channel.js
CHANGED
|
@@ -76,7 +76,9 @@ class ChannelEngine {
|
|
|
76
76
|
throw new pondError_1.ChannelError(message, code, this.name);
|
|
77
77
|
}
|
|
78
78
|
__classPrivateFieldGet(this, _ChannelEngine_users, "f").set(userId, assigns);
|
|
79
|
-
|
|
79
|
+
const subscription = __classPrivateFieldGet(this, _ChannelEngine_instances, "m", _ChannelEngine_subscribe).call(this, userId, onMessage);
|
|
80
|
+
this.sendMessage(pondsocket_common_1.SystemSender.CHANNEL, [userId], pondsocket_common_1.ServerActions.SYSTEM, pondsocket_common_1.Events.ACKNOWLEDGE, {});
|
|
81
|
+
return subscription;
|
|
80
82
|
}
|
|
81
83
|
/**
|
|
82
84
|
* @desc Kicks a user from the channel
|
package/channel/channel.test.js
CHANGED
|
@@ -159,7 +159,7 @@ describe('ChannelEngine', () => {
|
|
|
159
159
|
test: { test: 2 },
|
|
160
160
|
test2: { test: 3 },
|
|
161
161
|
});
|
|
162
|
-
expect(onMessage).toHaveBeenCalledTimes(
|
|
162
|
+
expect(onMessage).toHaveBeenCalledTimes(5);
|
|
163
163
|
});
|
|
164
164
|
it('should update a users presence', () => {
|
|
165
165
|
var _a;
|
|
@@ -259,6 +259,7 @@ describe('ChannelEngine', () => {
|
|
|
259
259
|
const channelEngine = new channel_1.ChannelEngine('test', parentEngine);
|
|
260
260
|
channelEngine.addUser('test1', { test: 1 }, onMessage);
|
|
261
261
|
const unsub = channelEngine.addUser('test2', { test: 1 }, onMessage);
|
|
262
|
+
onMessage.mockClear();
|
|
262
263
|
socket.subscriptions.set('test', unsub);
|
|
263
264
|
channelEngine.kickUser('test1', 'test reason');
|
|
264
265
|
expect(channelEngine.size).toEqual(1);
|
|
@@ -298,6 +299,7 @@ describe('ChannelEngine', () => {
|
|
|
298
299
|
const channelEngine = new channel_1.ChannelEngine('test', parentEngine);
|
|
299
300
|
channelEngine.addUser('test', { test: 1 }, onMessage);
|
|
300
301
|
channelEngine.addUser('test2', { test: 1 }, onMessage);
|
|
302
|
+
onMessage.mockClear();
|
|
301
303
|
channelEngine.sendMessage(pondsocket_common_1.SystemSender.CHANNEL, pondsocket_common_1.ChannelReceiver.ALL_USERS, pondsocket_common_1.ServerActions.BROADCAST, 'test', { test: 2 });
|
|
302
304
|
expect(onMessage.mock.calls[0][0]).toStrictEqual(expect.objectContaining({
|
|
303
305
|
action: pondsocket_common_1.ServerActions.BROADCAST,
|
|
@@ -326,6 +328,7 @@ describe('ChannelEngine', () => {
|
|
|
326
328
|
const channelEngine = new channel_1.ChannelEngine('test', parentEngine);
|
|
327
329
|
channelEngine.addUser('test', { test: 1 }, onMessage);
|
|
328
330
|
channelEngine.addUser('test2', { test: 1 }, onMessage);
|
|
331
|
+
onMessage.mockClear();
|
|
329
332
|
channelEngine.sendMessage('test2', pondsocket_common_1.ChannelReceiver.ALL_EXCEPT_SENDER, pondsocket_common_1.ServerActions.BROADCAST, 'test', { test: 2 });
|
|
330
333
|
expect(onMessage.mock.calls[0][0]).toStrictEqual(expect.objectContaining({
|
|
331
334
|
action: pondsocket_common_1.ServerActions.BROADCAST,
|
|
@@ -355,6 +358,7 @@ describe('ChannelEngine', () => {
|
|
|
355
358
|
channelEngine.addUser('test', { test: 1 }, onMessage);
|
|
356
359
|
channelEngine.addUser('test2', { test: 1 }, onMessage);
|
|
357
360
|
channelEngine.addUser('test3', { test: 1 }, onMessage);
|
|
361
|
+
onMessage.mockClear();
|
|
358
362
|
channelEngine.sendMessage('test2', ['test', 'test3'], pondsocket_common_1.ServerActions.BROADCAST, 'test', { test: 2 });
|
|
359
363
|
expect(onMessage.mock.calls[0][0]).toStrictEqual(expect.objectContaining({
|
|
360
364
|
action: pondsocket_common_1.ServerActions.BROADCAST,
|
|
@@ -398,6 +402,7 @@ describe('ChannelEngine', () => {
|
|
|
398
402
|
requestId: (0, pondsocket_common_1.uuid)(),
|
|
399
403
|
})).toThrow('ChannelEngine: User with id test2 does not exist in channel test');
|
|
400
404
|
channelEngine.addUser('test2', { test: 1 }, onMessage);
|
|
405
|
+
onMessage.mockClear();
|
|
401
406
|
channelEngine.broadcastMessage('test2', {
|
|
402
407
|
action: pondsocket_common_1.ClientActions.BROADCAST,
|
|
403
408
|
channelName: 'test',
|
|
@@ -52,6 +52,8 @@ describe('JoinResponse', () => {
|
|
|
52
52
|
const { response, channelEngine, socket } = createPondResponse();
|
|
53
53
|
// spy on the channelEngine to see if the user was added
|
|
54
54
|
jest.spyOn(channelEngine, 'addUser');
|
|
55
|
+
const endpoint = channelEngine.parent.parent;
|
|
56
|
+
jest.spyOn(endpoint, 'sendMessage');
|
|
55
57
|
response
|
|
56
58
|
.accept()
|
|
57
59
|
.reply('POND_MESSAGE', { message: 'message' })
|
|
@@ -68,11 +70,17 @@ describe('JoinResponse', () => {
|
|
|
68
70
|
// also check if the socket was sent a message
|
|
69
71
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
70
72
|
// @ts-expect-error - we are mocking the socket
|
|
71
|
-
const first =
|
|
73
|
+
const first = endpoint.sendMessage.mock.calls[0][1];
|
|
72
74
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
73
75
|
// @ts-expect-error - we are mocking the socket
|
|
74
|
-
const params =
|
|
75
|
-
expect(
|
|
76
|
+
const params = endpoint.sendMessage.mock.calls[1][1];
|
|
77
|
+
expect(first).toEqual(expect.objectContaining({
|
|
78
|
+
channelName: 'test',
|
|
79
|
+
action: pondsocket_common_1.ServerActions.SYSTEM,
|
|
80
|
+
payload: {},
|
|
81
|
+
event: pondsocket_common_1.Events.ACKNOWLEDGE,
|
|
82
|
+
}));
|
|
83
|
+
expect(params).toEqual(expect.objectContaining({
|
|
76
84
|
channelName: 'test',
|
|
77
85
|
action: pondsocket_common_1.ServerActions.SYSTEM,
|
|
78
86
|
payload: {
|
|
@@ -80,12 +88,6 @@ describe('JoinResponse', () => {
|
|
|
80
88
|
},
|
|
81
89
|
event: 'POND_MESSAGE',
|
|
82
90
|
}));
|
|
83
|
-
expect(JSON.parse(first)).toEqual(expect.objectContaining({
|
|
84
|
-
channelName: 'test',
|
|
85
|
-
action: pondsocket_common_1.ServerActions.SYSTEM,
|
|
86
|
-
payload: {},
|
|
87
|
-
event: pondsocket_common_1.Events.ACKNOWLEDGE,
|
|
88
|
-
}));
|
|
89
91
|
});
|
|
90
92
|
// auxiliary functions
|
|
91
93
|
it('should send messages to different users', () => {
|
package/lobby/joinResponse.js
CHANGED
|
@@ -53,14 +53,6 @@ class JoinResponse {
|
|
|
53
53
|
*/
|
|
54
54
|
accept() {
|
|
55
55
|
__classPrivateFieldGet(this, _JoinResponse_instances, "m", _JoinResponse_performChecks).call(this);
|
|
56
|
-
const acknowledgement = {
|
|
57
|
-
action: pondsocket_common_1.ServerActions.SYSTEM,
|
|
58
|
-
channelName: __classPrivateFieldGet(this, _JoinResponse_engine, "f").name,
|
|
59
|
-
event: pondsocket_common_1.Events.ACKNOWLEDGE,
|
|
60
|
-
requestId: __classPrivateFieldGet(this, _JoinResponse_user, "f").requestId,
|
|
61
|
-
payload: {},
|
|
62
|
-
};
|
|
63
|
-
__classPrivateFieldGet(this, _JoinResponse_instances, "m", _JoinResponse_directMessage).call(this, acknowledgement);
|
|
64
56
|
const onMessage = __classPrivateFieldGet(this, _JoinResponse_instances, "m", _JoinResponse_directMessage).bind(this);
|
|
65
57
|
const unsubscribe = __classPrivateFieldGet(this, _JoinResponse_engine, "f").addUser(__classPrivateFieldGet(this, _JoinResponse_user, "f").clientId, __classPrivateFieldGet(this, _JoinResponse_newAssigns, "f"), onMessage);
|
|
66
58
|
__classPrivateFieldGet(this, _JoinResponse_user, "f").subscriptions.set(__classPrivateFieldGet(this, _JoinResponse_engine, "f").name, unsubscribe);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eleven-am/pondsocket",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.148",
|
|
4
4
|
"description": "PondSocket is a fast simple socket server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"socket",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/jest": "^29.5.12",
|
|
42
|
-
"@types/node": "^20.11.
|
|
42
|
+
"@types/node": "^20.11.24",
|
|
43
43
|
"@types/websocket": "^1.0.10",
|
|
44
44
|
"@types/ws": "^8.5.10",
|
|
45
45
|
"@typescript-eslint/eslint-plugin": "^7.1.0",
|
|
@@ -84,6 +84,7 @@ describe('PresenceEngine', () => {
|
|
|
84
84
|
channel.addUser('presenceKey2', { assign: 'assign' }, () => {
|
|
85
85
|
// do nothing
|
|
86
86
|
});
|
|
87
|
+
listener.mockClear();
|
|
87
88
|
presenceEngine.trackPresence(presenceKey, presence);
|
|
88
89
|
presenceEngine.trackPresence('presenceKey2', Object.assign(Object.assign({}, presence), { key: 'presence2' }));
|
|
89
90
|
expect(listener).toHaveBeenCalledTimes(2);
|