@eleven-am/pondsocket 0.1.163 → 0.1.164
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/endpoint/endpoint.js +1 -1
- package/lobby/lobby.js +11 -3
- package/package.json +1 -1
- package/types.d.ts +25 -19
package/endpoint/endpoint.js
CHANGED
|
@@ -55,7 +55,7 @@ class EndpointEngine {
|
|
|
55
55
|
* });
|
|
56
56
|
*/
|
|
57
57
|
createChannel(path, handler) {
|
|
58
|
-
const pondChannel = new lobby_1.LobbyEngine(this);
|
|
58
|
+
const pondChannel = new lobby_1.LobbyEngine(this, path);
|
|
59
59
|
__classPrivateFieldGet(this, _EndpointEngine_middleware, "f").use((user, joinParams, next) => {
|
|
60
60
|
const event = (0, matcher_1.parseAddress)(path, user.channelName);
|
|
61
61
|
if (event) {
|
package/lobby/lobby.js
CHANGED
|
@@ -10,22 +10,26 @@ 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_instances, _LobbyEngine_channels, _LobbyEngine_middleware, _LobbyEngine_leaveCallback, _LobbyEngine_parentEngine, _LobbyEngine_performAction, _PondChannel_lobby;
|
|
13
|
+
var _LobbyEngine_instances, _LobbyEngine_channels, _LobbyEngine_middleware, _LobbyEngine_leaveCallback, _LobbyEngine_parentEngine, _LobbyEngine_path, _LobbyEngine_performAction, _PondChannel_lobby;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.PondChannel = exports.LobbyEngine = void 0;
|
|
16
16
|
const pondsocket_common_1 = require("@eleven-am/pondsocket-common");
|
|
17
17
|
const middleware_1 = require("../abstracts/middleware");
|
|
18
18
|
const channel_1 = require("../channel/channel");
|
|
19
|
+
const pondError_1 = require("../errors/pondError");
|
|
20
|
+
const matcher_1 = require("../matcher/matcher");
|
|
19
21
|
class LobbyEngine {
|
|
20
|
-
constructor(endpointEngine) {
|
|
22
|
+
constructor(endpointEngine, path) {
|
|
21
23
|
_LobbyEngine_instances.add(this);
|
|
22
24
|
_LobbyEngine_channels.set(this, void 0);
|
|
23
25
|
_LobbyEngine_middleware.set(this, void 0);
|
|
24
26
|
_LobbyEngine_leaveCallback.set(this, void 0);
|
|
25
27
|
_LobbyEngine_parentEngine.set(this, void 0);
|
|
28
|
+
_LobbyEngine_path.set(this, void 0);
|
|
26
29
|
__classPrivateFieldSet(this, _LobbyEngine_parentEngine, endpointEngine, "f");
|
|
27
30
|
__classPrivateFieldSet(this, _LobbyEngine_channels, new Set(), "f");
|
|
28
31
|
__classPrivateFieldSet(this, _LobbyEngine_middleware, new middleware_1.Middleware(), "f");
|
|
32
|
+
__classPrivateFieldSet(this, _LobbyEngine_path, path, "f");
|
|
29
33
|
}
|
|
30
34
|
/**
|
|
31
35
|
* @desc The parent engine
|
|
@@ -138,7 +142,11 @@ class LobbyEngine {
|
|
|
138
142
|
}
|
|
139
143
|
}
|
|
140
144
|
exports.LobbyEngine = LobbyEngine;
|
|
141
|
-
_LobbyEngine_channels = new WeakMap(), _LobbyEngine_middleware = new WeakMap(), _LobbyEngine_leaveCallback = new WeakMap(), _LobbyEngine_parentEngine = new WeakMap(), _LobbyEngine_instances = new WeakSet(), _LobbyEngine_performAction = function _LobbyEngine_performAction(channelName, handler) {
|
|
145
|
+
_LobbyEngine_channels = new WeakMap(), _LobbyEngine_middleware = new WeakMap(), _LobbyEngine_leaveCallback = new WeakMap(), _LobbyEngine_parentEngine = new WeakMap(), _LobbyEngine_path = new WeakMap(), _LobbyEngine_instances = new WeakSet(), _LobbyEngine_performAction = function _LobbyEngine_performAction(channelName, handler) {
|
|
146
|
+
const matches = (0, matcher_1.parseAddress)(__classPrivateFieldGet(this, _LobbyEngine_path, "f"), channelName);
|
|
147
|
+
if (matches === null) {
|
|
148
|
+
throw new pondError_1.EndpointError('Invalid channel name', 402);
|
|
149
|
+
}
|
|
142
150
|
const channel = this.getChannel(channelName) || this.createChannel(channelName);
|
|
143
151
|
const assigns = channel.getAssigns();
|
|
144
152
|
handler(channel);
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -54,7 +54,7 @@ export declare class PondSocket {
|
|
|
54
54
|
* const endpoint = pond.createEndpoint('/api/socket', (req, res) => {
|
|
55
55
|
* const token = req.query.token;
|
|
56
56
|
* if (!token)
|
|
57
|
-
* return res.
|
|
57
|
+
* return res.decline('No token provided');
|
|
58
58
|
* res.accept({
|
|
59
59
|
* assign: {
|
|
60
60
|
* token
|
|
@@ -78,7 +78,7 @@ export declare class Endpoint {
|
|
|
78
78
|
* response.accept();
|
|
79
79
|
*
|
|
80
80
|
* else
|
|
81
|
-
* response.
|
|
81
|
+
* response.decline('You are not an admin', 403);
|
|
82
82
|
* });
|
|
83
83
|
*/
|
|
84
84
|
createChannel<Path extends string, EventType extends PondEventMap = PondEventMap, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns>(path: PondPath<Path>, handler: RequestHandler<JoinRequest<Path, PresenceType, AssignType>, JoinResponse<EventType, PresenceType, AssignType>>): PondChannel<EventType, PresenceType, AssignType>;
|
|
@@ -117,20 +117,6 @@ export declare class PondChannel<EventType extends PondEventMap = PondEventMap,
|
|
|
117
117
|
*/
|
|
118
118
|
onEvent<Event extends string>(event: PondPath<Event>, handler: RequestHandler<EventRequest<Event, PresenceType, AssignType>, EventResponse<EventType, PresenceType, AssignType>>): void;
|
|
119
119
|
|
|
120
|
-
/**
|
|
121
|
-
* @desc Broadcasts a message to all users in a channel
|
|
122
|
-
* @param event - The event to broadcast
|
|
123
|
-
* @param payload - The payload to send
|
|
124
|
-
* @param channelName - The channel to broadcast to (if not specified, broadcast to all channels)
|
|
125
|
-
* @example
|
|
126
|
-
* pond.broadcast('echo', {
|
|
127
|
-
* message: 'Hello World',
|
|
128
|
-
* timestamp: Date.now(),
|
|
129
|
-
* channel: 'my_channel',
|
|
130
|
-
*});
|
|
131
|
-
*/
|
|
132
|
-
broadcast<Key extends keyof EventType>(event: Key, payload: EventType[Key], channelName?: string): void;
|
|
133
|
-
|
|
134
120
|
/**
|
|
135
121
|
* @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
|
|
136
122
|
* @param {LeaveCallback} callback - The callback to execute when a user leaves
|
|
@@ -147,6 +133,11 @@ export declare class PondChannel<EventType extends PondEventMap = PondEventMap,
|
|
|
147
133
|
* @returns {Channel} - The channel instance
|
|
148
134
|
* @example
|
|
149
135
|
* const channel = pond.getChannel('my_channel')!;
|
|
136
|
+
*
|
|
137
|
+
* if (channel === null) {
|
|
138
|
+
* console.log('Channel not found');
|
|
139
|
+
* return;
|
|
140
|
+
* }
|
|
150
141
|
*/
|
|
151
142
|
getChannel(channelName: string): Channel<EventType, PresenceType, AssignType> | null;
|
|
152
143
|
|
|
@@ -155,16 +146,26 @@ export declare class PondChannel<EventType extends PondEventMap = PondEventMap,
|
|
|
155
146
|
* @param channelName - The name of the channel to broadcast to
|
|
156
147
|
* @param event - The event to send
|
|
157
148
|
* @param payload - The payload to send
|
|
149
|
+
* @example
|
|
150
|
+
*
|
|
151
|
+
* pond.broadcast('my_channel', 'message', {
|
|
152
|
+
* text: 'Hello, world!'
|
|
153
|
+
* });
|
|
158
154
|
*/
|
|
159
|
-
broadcast (channelName: string, event:
|
|
155
|
+
broadcast <Key extends keyof EventType>(channelName: string, event: Key, payload: EventType[Key]): void;
|
|
160
156
|
|
|
161
157
|
/**
|
|
162
158
|
* Broadcasts a message to all clients in the channel except the sender
|
|
163
159
|
* @param channelName - The name of the channel to broadcast to
|
|
164
160
|
* @param event - The event to send
|
|
165
161
|
* @param payload - The payload to send
|
|
162
|
+
* @example
|
|
163
|
+
*
|
|
164
|
+
* pond.broadcastFrom('my_channel', 'message', {
|
|
165
|
+
* text: 'Hello, everyone but me!'
|
|
166
|
+
* });
|
|
166
167
|
*/
|
|
167
|
-
broadcastFrom (channelName: string, event:
|
|
168
|
+
broadcastFrom <Key extends keyof EventType> (channelName: string, event: Key, payload: EventType[Key]): void
|
|
168
169
|
|
|
169
170
|
/**
|
|
170
171
|
* Broadcasts a message to a specific set of clients
|
|
@@ -172,8 +173,13 @@ export declare class PondChannel<EventType extends PondEventMap = PondEventMap,
|
|
|
172
173
|
* @param event - The event to send
|
|
173
174
|
* @param payload - The payload to send
|
|
174
175
|
* @param userIds - The ids of the clients to send the message to
|
|
176
|
+
* @example
|
|
177
|
+
*
|
|
178
|
+
* pond.broadcastTo('my_channel', 'message', {
|
|
179
|
+
* text: 'Hello, specific people!'
|
|
180
|
+
* }, ['user1', 'user2']);
|
|
175
181
|
*/
|
|
176
|
-
broadcastTo (channelName: string, event:
|
|
182
|
+
broadcastTo <Key extends keyof EventType> (channelName: string, event: Key, payload: EventType[Key], userIds: string | string[]): void;
|
|
177
183
|
}
|
|
178
184
|
|
|
179
185
|
export declare class Channel<EventType extends PondEventMap = PondEventMap, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> {
|