@eleven-am/pondsocket 0.1.123 → 0.1.125
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/client/channel.js +47 -9
- package/client.js +1 -1
- package/package.json +1 -1
- package/types.d.ts +26 -2
package/client/channel.js
CHANGED
|
@@ -16,7 +16,7 @@ exports.Channel = void 0;
|
|
|
16
16
|
const enums_1 = require("../enums");
|
|
17
17
|
const subject_1 = require("../subjects/subject");
|
|
18
18
|
class Channel {
|
|
19
|
-
constructor(publisher, clientState, name, receiver, params
|
|
19
|
+
constructor(publisher, clientState, name, receiver, params) {
|
|
20
20
|
_Channel_instances.add(this);
|
|
21
21
|
_Channel_name.set(this, void 0);
|
|
22
22
|
_Channel_joinParams.set(this, void 0);
|
|
@@ -37,6 +37,12 @@ class Channel {
|
|
|
37
37
|
__classPrivateFieldSet(this, _Channel_joinState, new subject_1.SimpleBehaviorSubject(enums_1.ChannelState.IDLE), "f");
|
|
38
38
|
__classPrivateFieldSet(this, _Channel_presenceSub, __classPrivateFieldGet(this, _Channel_instances, "m", _Channel_init).call(this, receiver), "f");
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* @desc Gets the current connection state of the channel.
|
|
42
|
+
*/
|
|
43
|
+
get channelState() {
|
|
44
|
+
return __classPrivateFieldGet(this, _Channel_joinState, "f").value;
|
|
45
|
+
}
|
|
40
46
|
/**
|
|
41
47
|
* @desc Connects to the channel.
|
|
42
48
|
*/
|
|
@@ -146,6 +152,21 @@ class Channel {
|
|
|
146
152
|
sendMessage(event, payload, recipient) {
|
|
147
153
|
__classPrivateFieldGet(this, _Channel_instances, "m", _Channel_send).call(this, event, payload, recipient);
|
|
148
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* @desc Sends a message to the server and waits for a response.
|
|
157
|
+
* @param sentEvent - The event to send.
|
|
158
|
+
* @param payload - The message to send.
|
|
159
|
+
* @param responseEvent - The event to wait for.
|
|
160
|
+
*/
|
|
161
|
+
sendForResponse(sentEvent, payload, responseEvent) {
|
|
162
|
+
return new Promise((resolve) => {
|
|
163
|
+
const unsub = this.onMessageEvent(responseEvent, (message) => {
|
|
164
|
+
resolve(message);
|
|
165
|
+
unsub();
|
|
166
|
+
});
|
|
167
|
+
__classPrivateFieldGet(this, _Channel_instances, "m", _Channel_send).call(this, sentEvent, payload);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
149
170
|
/**
|
|
150
171
|
* @desc Broadcasts a message to every other client in the channel except yourself.
|
|
151
172
|
* @param event - The event to send.
|
|
@@ -162,12 +183,6 @@ class Channel {
|
|
|
162
183
|
broadcast(event, payload) {
|
|
163
184
|
__classPrivateFieldGet(this, _Channel_instances, "m", _Channel_send).call(this, event, payload);
|
|
164
185
|
}
|
|
165
|
-
/**
|
|
166
|
-
* @desc Gets the current connection state of the channel.
|
|
167
|
-
*/
|
|
168
|
-
get channelState() {
|
|
169
|
-
return __classPrivateFieldGet(this, _Channel_joinState, "f").value;
|
|
170
|
-
}
|
|
171
186
|
/**
|
|
172
187
|
* @desc Gets the current presence of the channel.
|
|
173
188
|
*/
|
|
@@ -182,11 +197,23 @@ class Channel {
|
|
|
182
197
|
return __classPrivateFieldGet(this, _Channel_instances, "m", _Channel_subscribeToPresence).call(this, (_event, payload) => callback(payload.presence));
|
|
183
198
|
}
|
|
184
199
|
/**
|
|
185
|
-
* @desc
|
|
200
|
+
* @desc Checks if the channel is connected.
|
|
186
201
|
*/
|
|
187
202
|
isConnected() {
|
|
188
203
|
return __classPrivateFieldGet(this, _Channel_joinState, "f").value === enums_1.ChannelState.JOINED || __classPrivateFieldGet(this, _Channel_joinState, "f").value === enums_1.ChannelState.STALLED;
|
|
189
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* @desc Checks if the channel is stalled.
|
|
207
|
+
*/
|
|
208
|
+
isStalled() {
|
|
209
|
+
return __classPrivateFieldGet(this, _Channel_joinState, "f").value === enums_1.ChannelState.STALLED;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* @desc Checks if the channel is closed.
|
|
213
|
+
*/
|
|
214
|
+
isClosed() {
|
|
215
|
+
return __classPrivateFieldGet(this, _Channel_joinState, "f").value === enums_1.ChannelState.CLOSED;
|
|
216
|
+
}
|
|
190
217
|
/**
|
|
191
218
|
* @desc Monitors the connection state of the channel.
|
|
192
219
|
* @param callback - The callback to call when the connection state changes.
|
|
@@ -196,6 +223,18 @@ class Channel {
|
|
|
196
223
|
callback(state === enums_1.ChannelState.JOINED || state === enums_1.ChannelState.STALLED);
|
|
197
224
|
});
|
|
198
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* @desc Gets the first response from the channel.
|
|
228
|
+
* @param event - The event to monitor.
|
|
229
|
+
*/
|
|
230
|
+
getFirstResponse(event) {
|
|
231
|
+
return new Promise((resolve) => {
|
|
232
|
+
const unsub = this.onMessageEvent(event, (message) => {
|
|
233
|
+
resolve(message);
|
|
234
|
+
unsub();
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
}
|
|
199
238
|
}
|
|
200
239
|
exports.Channel = Channel;
|
|
201
240
|
_Channel_name = new WeakMap(), _Channel_joinParams = new WeakMap(), _Channel_receiver = new WeakMap(), _Channel_clientState = new WeakMap(), _Channel_joinState = new WeakMap(), _Channel_publisher = new WeakMap(), _Channel_queue = new WeakMap(), _Channel_presence = new WeakMap(), _Channel_presenceSub = new WeakMap(), _Channel_instances = new WeakSet(), _Channel_send = function _Channel_send(event, payload, receivers = enums_1.ChannelReceiver.ALL_USERS) {
|
|
@@ -261,6 +300,5 @@ _Channel_name = new WeakMap(), _Channel_joinParams = new WeakMap(), _Channel_rec
|
|
|
261
300
|
.forEach((message) => {
|
|
262
301
|
__classPrivateFieldGet(this, _Channel_publisher, "f").call(this, message);
|
|
263
302
|
});
|
|
264
|
-
__classPrivateFieldGet(this, _Channel_joinState, "f").publish(enums_1.ChannelState.JOINED);
|
|
265
303
|
__classPrivateFieldSet(this, _Channel_queue, [], "f");
|
|
266
304
|
};
|
package/client.js
CHANGED
|
@@ -85,7 +85,7 @@ class PondClient {
|
|
|
85
85
|
return __classPrivateFieldGet(this, _PondClient_channels, "f")[name];
|
|
86
86
|
}
|
|
87
87
|
const publisher = __classPrivateFieldGet(this, _PondClient_instances, "m", _PondClient_createPublisher).call(this);
|
|
88
|
-
const channel = new channel_1.Channel(publisher, this._connectionState, name, this._broadcaster, params);
|
|
88
|
+
const channel = new channel_1.Channel(publisher, this._connectionState, name, this._broadcaster, params || {});
|
|
89
89
|
__classPrivateFieldGet(this, _PondClient_channels, "f")[name] = channel;
|
|
90
90
|
return channel;
|
|
91
91
|
}
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -380,6 +380,14 @@ export declare class ClientChannel<EventType extends PondEvenType = PondEvenType
|
|
|
380
380
|
*/
|
|
381
381
|
sendMessage <Key extends keyof EventType> (event: Key, payload: EventType[Key], recipient: string[]): void;
|
|
382
382
|
|
|
383
|
+
/**
|
|
384
|
+
* @desc Sends a message to the server and waits for a response.
|
|
385
|
+
* @param sentEvent - The event to send.
|
|
386
|
+
* @param payload - The message to send.
|
|
387
|
+
* @param responseEvent - The event to wait for.
|
|
388
|
+
*/
|
|
389
|
+
sendForResponse <ResponseKey extends keyof EventType, SentKey extends keyof EventType> (sentEvent: SentKey, payload: EventType[SentKey], responseEvent: ResponseKey): Promise<EventType[ResponseKey]>;
|
|
390
|
+
|
|
383
391
|
/**
|
|
384
392
|
* @desc Broadcasts a message to every other client in the channel except yourself.
|
|
385
393
|
* @param event - The event to send.
|
|
@@ -406,15 +414,31 @@ export declare class ClientChannel<EventType extends PondEvenType = PondEvenType
|
|
|
406
414
|
onUsersChange (callback: (users: PondPresence[]) => void): Unsubscribe;
|
|
407
415
|
|
|
408
416
|
/**
|
|
409
|
-
* @desc
|
|
417
|
+
* @desc Checks if the channel is connected.
|
|
410
418
|
*/
|
|
411
419
|
isConnected (): boolean;
|
|
412
420
|
|
|
421
|
+
/**
|
|
422
|
+
* @desc Checks if the channel is stalled.
|
|
423
|
+
*/
|
|
424
|
+
isStalled (): boolean;
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* @desc Checks if the channel is closed.
|
|
428
|
+
*/
|
|
429
|
+
isClosed (): boolean;
|
|
430
|
+
|
|
413
431
|
/**
|
|
414
432
|
* @desc Monitors the connection state of the channel.
|
|
415
433
|
* @param callback - The callback to call when the connection state changes.
|
|
416
434
|
*/
|
|
417
435
|
onConnectionChange (callback: (connected: boolean) => void): Unsubscribe;
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* @desc Gets the first response from the channel.
|
|
439
|
+
* @param event - The event to monitor.
|
|
440
|
+
*/
|
|
441
|
+
getFirstResponse <Key extends keyof EventType> (event: Key): Promise<EventType[Key]>;
|
|
418
442
|
}
|
|
419
443
|
|
|
420
444
|
declare class Endpoint {
|
|
@@ -737,7 +761,7 @@ declare class PondClient {
|
|
|
737
761
|
* @param name - The name of the channel.
|
|
738
762
|
* @param params - The params to send to the server.
|
|
739
763
|
*/
|
|
740
|
-
createChannel (name: string, params?: JoinParams): ClientChannel
|
|
764
|
+
createChannel <EventType extends PondEvenType = PondEvenType> (name: string, params?: JoinParams): ClientChannel<EventType>;
|
|
741
765
|
|
|
742
766
|
/**
|
|
743
767
|
* @desc Subscribes to the connection state.
|