@eleven-am/pondsocket 0.1.61 → 0.1.62
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 +6 -0
- package/lobby/lobby.js +18 -2
- package/package.json +1 -1
- package/types.d.ts +15 -6
package/channel/channel.js
CHANGED
|
@@ -70,6 +70,12 @@ class ChannelEngine {
|
|
|
70
70
|
__classPrivateFieldGet(this, _ChannelEngine_users, "f").delete(userId);
|
|
71
71
|
__classPrivateFieldGet(this, _ChannelEngine_receiver, "f").unsubscribe(userId);
|
|
72
72
|
(_a = __classPrivateFieldGet(this, _ChannelEngine_presenceEngine, "f")) === null || _a === void 0 ? void 0 : _a.removePresence(userId, graceful);
|
|
73
|
+
if (__classPrivateFieldGet(this, _ChannelEngine_parentEngine, "f").leaveCallback) {
|
|
74
|
+
__classPrivateFieldGet(this, _ChannelEngine_parentEngine, "f").leaveCallback({
|
|
75
|
+
userId,
|
|
76
|
+
assigns: user,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
73
79
|
if (__classPrivateFieldGet(this, _ChannelEngine_users, "f").size === 0) {
|
|
74
80
|
__classPrivateFieldGet(this, _ChannelEngine_parentEngine, "f").destroyChannel();
|
|
75
81
|
}
|
package/lobby/lobby.js
CHANGED
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _LobbyEngine_channels, _LobbyEngine_middleware, _PondChannel_lobby;
|
|
13
|
+
var _LobbyEngine_channels, _LobbyEngine_middleware, _LobbyEngine_leaveCallback, _PondChannel_lobby;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.PondChannel = exports.LobbyEngine = void 0;
|
|
16
16
|
const middleware_1 = require("../abstracts/middleware");
|
|
@@ -20,6 +20,7 @@ class LobbyEngine {
|
|
|
20
20
|
constructor() {
|
|
21
21
|
_LobbyEngine_channels.set(this, void 0);
|
|
22
22
|
_LobbyEngine_middleware.set(this, void 0);
|
|
23
|
+
_LobbyEngine_leaveCallback.set(this, void 0);
|
|
23
24
|
__classPrivateFieldSet(this, _LobbyEngine_channels, new Set(), "f");
|
|
24
25
|
__classPrivateFieldSet(this, _LobbyEngine_middleware, new middleware_1.Middleware(), "f");
|
|
25
26
|
}
|
|
@@ -42,6 +43,13 @@ class LobbyEngine {
|
|
|
42
43
|
next();
|
|
43
44
|
});
|
|
44
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* @desc Handles the leave event for a user, can occur when a user disconnects or leaves a channel, use this to clean up any resources
|
|
48
|
+
* @param callback - The callback to execute when a user leaves
|
|
49
|
+
*/
|
|
50
|
+
onLeave(callback) {
|
|
51
|
+
__classPrivateFieldSet(this, _LobbyEngine_leaveCallback, callback, "f");
|
|
52
|
+
}
|
|
45
53
|
/**
|
|
46
54
|
* @desc Broadcasts a message to all users in a channel
|
|
47
55
|
* @param event - The event to broadcast
|
|
@@ -127,6 +135,7 @@ class LobbyEngine {
|
|
|
127
135
|
const parentEngine = {
|
|
128
136
|
execute,
|
|
129
137
|
destroyChannel,
|
|
138
|
+
leaveCallback: __classPrivateFieldGet(this, _LobbyEngine_leaveCallback, "f"),
|
|
130
139
|
};
|
|
131
140
|
const newChannel = new channel_1.ChannelEngine(channelName, parentEngine);
|
|
132
141
|
__classPrivateFieldGet(this, _LobbyEngine_channels, "f").add(newChannel);
|
|
@@ -134,7 +143,7 @@ class LobbyEngine {
|
|
|
134
143
|
}
|
|
135
144
|
}
|
|
136
145
|
exports.LobbyEngine = LobbyEngine;
|
|
137
|
-
_LobbyEngine_channels = new WeakMap(), _LobbyEngine_middleware = new WeakMap();
|
|
146
|
+
_LobbyEngine_channels = new WeakMap(), _LobbyEngine_middleware = new WeakMap(), _LobbyEngine_leaveCallback = new WeakMap();
|
|
138
147
|
class PondChannel {
|
|
139
148
|
constructor(lobby) {
|
|
140
149
|
_PondChannel_lobby.set(this, void 0);
|
|
@@ -169,6 +178,13 @@ class PondChannel {
|
|
|
169
178
|
broadcast(event, payload, channelName) {
|
|
170
179
|
__classPrivateFieldGet(this, _PondChannel_lobby, "f").broadcast(event, payload, channelName);
|
|
171
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* @desc Handles the leave event for a user, can occur when a user disconnects or leaves a channel, use this to clean up any resources
|
|
183
|
+
* @param callback - The callback to execute when a user leaves
|
|
184
|
+
*/
|
|
185
|
+
onLeave(callback) {
|
|
186
|
+
__classPrivateFieldGet(this, _PondChannel_lobby, "f").onLeave(callback);
|
|
187
|
+
}
|
|
172
188
|
}
|
|
173
189
|
exports.PondChannel = PondChannel;
|
|
174
190
|
_PondChannel_lobby = new WeakMap();
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { WebSocketServer } from 'ws';
|
|
|
4
4
|
|
|
5
5
|
type Unsubscribe = () => void;
|
|
6
6
|
|
|
7
|
+
export type default_t<T = any> = Record<string, T>;
|
|
7
8
|
type IsParam<Path> = Path extends `:${infer Param}` ? Param : never;
|
|
8
9
|
|
|
9
10
|
type FilteredParams<Path> = Path extends `${infer First}/${infer Second}`
|
|
@@ -21,12 +22,7 @@ type EventParams<Path> = {
|
|
|
21
22
|
params: Params<Path>;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
type
|
|
25
|
-
|
|
26
|
-
type PondObject = {
|
|
27
|
-
[key: string]: Primitives | PondObject | PondObject[];
|
|
28
|
-
}
|
|
29
|
-
|
|
25
|
+
type PondObject = default_t;
|
|
30
26
|
type PondPresence = PondObject;
|
|
31
27
|
type PondMessage = PondObject;
|
|
32
28
|
type PondAssigns = PondObject;
|
|
@@ -56,6 +52,13 @@ type IncomingConnection<Path> = EventParams<Path> & {
|
|
|
56
52
|
address: string;
|
|
57
53
|
}
|
|
58
54
|
|
|
55
|
+
interface LeaveEvent {
|
|
56
|
+
userId: string;
|
|
57
|
+
assigns: PondAssigns;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
type LeaveCallback = (event: LeaveEvent) => void;
|
|
61
|
+
|
|
59
62
|
interface UserData {
|
|
60
63
|
assigns: PondAssigns;
|
|
61
64
|
presence: PondPresence;
|
|
@@ -479,6 +482,12 @@ export declare class PondChannel {
|
|
|
479
482
|
*});
|
|
480
483
|
*/
|
|
481
484
|
broadcast (event: string, payload: PondMessage, channelName?: string): void;
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* @desc Handles the leave event for a user, can occur when a user disconnects or leaves a channel, use this to clean up any resources
|
|
488
|
+
* @param callback - The callback to execute when a user leaves
|
|
489
|
+
*/
|
|
490
|
+
public onLeave (callback: LeaveCallback): void;
|
|
482
491
|
}
|
|
483
492
|
|
|
484
493
|
declare class PondSocket {
|