@eleven-am/pondsocket 0.1.198 → 0.1.200

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/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Server, ServerResponse, IncomingMessage } from 'http';
1
+ import { Server, ServerResponse, IncomingMessage, IncomingHttpHeaders } from 'http';
2
2
 
3
3
  import {
4
4
  IncomingConnection,
@@ -13,6 +13,7 @@ import {
13
13
  UserAssigns,
14
14
  JoinParams,
15
15
  EventParams,
16
+ Params,
16
17
  } from '@eleven-am/pondsocket-common';
17
18
  import { WebSocket, WebSocketServer } from 'ws';
18
19
 
@@ -33,7 +34,7 @@ export type LeaveCallback<EventTypes extends PondEventMap = PondEventMap, Presen
33
34
 
34
35
  export type OutgoingHandler<Event extends string, EventTypes extends PondEventMap = PondEventMap, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> = (event: OutgoingEvent<Event, EventTypes, PresenceType, AssignType>) => PondMessage | Promise<PondMessage> | void | Promise<void>;
35
36
 
36
- export type RequestHandler<Request, Response> = (request: Request, response: Response) => void | Promise<void>;
37
+ export type RequestHandler<Request> = (request: Request) => void | Promise<void>;
37
38
 
38
39
  export interface PondSocketOptions {
39
40
  server?: Server;
@@ -61,18 +62,16 @@ export declare class PondSocket {
61
62
  * @param path - the pattern to accept || can also be a regex
62
63
  * @param handler - the handler function to authenticate the socket
63
64
  * @example
64
- * const endpoint = pond.createEndpoint('/api/socket', (req, res) => {
65
- * const token = req.query.token;
65
+ * const endpoint = pond.createEndpoint('/api/socket', (context) => {
66
+ * const token = context.query.token;
66
67
  * if (!token)
67
- * return res.decline('No token provided');
68
- * res.accept({
69
- * assign: {
70
- * token
71
- * }
72
- * });
68
+ * return context.decline('No token provided');
69
+ * context.assign({
70
+ * token
71
+ * }).accept();
73
72
  * })
74
73
  */
75
- createEndpoint<Path extends string>(path: PondPath<Path>, handler: RequestHandler<IncomingConnection<Path>, ConnectionResponse>): Endpoint;
74
+ createEndpoint<Path extends string>(path: PondPath<Path>, handler: RequestHandler<ConnectionContext<Path>>): Endpoint;
76
75
  }
77
76
 
78
77
  export declare class Endpoint {
@@ -83,15 +82,14 @@ export declare class Endpoint {
83
82
  * @returns {PondChannel} - The PondChannel instance for the new channel
84
83
  *
85
84
  * @example
86
- * const channel = endpoint.createChannel('/chat', (request, response) => {
87
- * if (request.user.assigns.admin)
88
- * response.accept();
89
- *
85
+ * const channel = endpoint.createChannel('/chat', (context) => {
86
+ * if (context.user.assigns.admin)
87
+ * context.accept();
90
88
  * else
91
- * response.decline('You are not an admin', 403);
89
+ * context.decline('You are not an admin', 403);
92
90
  * });
93
91
  */
94
- 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>;
92
+ createChannel<Path extends string, EventType extends PondEventMap = PondEventMap, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns>(path: PondPath<Path>, handler: RequestHandler<JoinContext<Path, EventType, PresenceType, AssignType>>): PondChannel<EventType, PresenceType, AssignType>;
95
93
 
96
94
  /**
97
95
  * @desc Closes specific clients connected to this endpoint
@@ -111,13 +109,13 @@ export declare class PondChannel<EventType extends PondEventMap = PondEventMap,
111
109
  * @param {PondPath<string>} event - The event to handle
112
110
  * @param {RequestHandler} handler - The handlers to execute when the event is received
113
111
  * @example
114
- * pond.onEvent('echo', (request, response) => {
115
- * response.reply('echo', {
116
- * message: request.event.payload,
112
+ * pond.onEvent('echo', (context) => {
113
+ * context.reply('echo', {
114
+ * message: context.event.payload,
117
115
  * });
118
116
  * });
119
117
  */
120
- onEvent<Event extends string>(event: PondPath<Event>, handler: RequestHandler<EventRequest<Event, PresenceType, AssignType>, EventResponse<EventType, PresenceType, AssignType>>): void;
118
+ onEvent<Event extends string>(event: PondPath<Event>, handler: RequestHandler<EventContext<Event, EventType, PresenceType, AssignType>>): void;
121
119
 
122
120
  /**
123
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
@@ -284,72 +282,122 @@ export declare class Channel<EventTypes extends PondEventMap = PondEventMap, Pre
284
282
  upsertPresence(userId: string, presence: PresenceType): Channel<EventTypes, PresenceType, AssignType>;
285
283
  }
286
284
 
287
- export declare class JoinRequest<Path extends string, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> {
288
- get event(): PondEvent<Path>;
289
-
290
- get channelName(): string;
291
-
292
- get channel(): Channel
293
-
294
- get joinParams(): JoinParams;
295
-
296
- get presences(): UserPresences;
285
+ export declare class ConnectionContext<Path extends string> {
286
+ /**
287
+ * @desc Checks if the server has responded to the connection request.
288
+ */
289
+ get hasResponded(): boolean;
297
290
 
298
- get assigns(): UserAssigns;
291
+ /**
292
+ * @desc Get the connection details.
293
+ */
294
+ get connection(): IncomingConnection<Path>;
299
295
 
300
- get user(): UserData<PresenceType, AssignType>;
301
- }
296
+ /**
297
+ * @desc Get the client ID.
298
+ */
299
+ get clientId(): string;
302
300
 
303
- export declare class EventRequest<Path extends string, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> {
304
- get event(): PondEvent<Path>;
301
+ /**
302
+ * @desc Get the request ID.
303
+ */
304
+ get requestId(): string;
305
305
 
306
- get channelName(): string;
306
+ /**
307
+ * @desc Get the request headers.
308
+ */
309
+ get headers(): IncomingHttpHeaders;
307
310
 
308
- get channel(): Channel;
311
+ /**
312
+ * @desc Get the request cookies.
313
+ */
314
+ get cookies(): Record<string, string>;
309
315
 
310
- get presences(): UserPresences;
316
+ /**
317
+ * @desc Get the client address.
318
+ */
319
+ get address(): string;
311
320
 
312
- get assigns(): UserAssigns;
321
+ /**
322
+ * @desc Get the event parameters.
323
+ */
324
+ get event(): EventParams<Path>;
313
325
 
314
- get user(): UserData<PresenceType, AssignType>;
315
- }
326
+ /**
327
+ * @desc Get the query parameters.
328
+ */
329
+ get query(): Record<string, string>;
316
330
 
317
- export declare class ConnectionResponse {
318
331
  /**
319
- * @desc Checks if the server has responded to the connection request.
332
+ * @desc Get the path parameters.
320
333
  */
321
- get hasResponded(): boolean;
334
+ get params(): Params<Path>;
322
335
 
323
336
  /**
324
337
  * @desc Assigns data to the user.
325
338
  * @param {PondAssigns} assigns - The data to assign.
326
- * @returns {ConnectionResponse} - The ConnectionResponse instance for chaining.
339
+ * @returns {ConnectionContext} - The ConnectionContext instance for chaining.
327
340
  */
328
- assign(assigns: PondAssigns): ConnectionResponse;
341
+ assign(assigns: PondAssigns): ConnectionContext<Path>;
329
342
 
330
343
  /**
331
344
  * @desc Accepts the connection request to the endpoint.
332
345
  */
333
- accept(): ConnectionResponse;
346
+ accept(): ConnectionContext<Path>;
334
347
 
335
348
  /**
336
349
  * @desc Rejects the request with the given error message
337
350
  * @param {string} message - The error message
338
351
  * @param {number} errorCode - The error code
339
352
  */
340
- decline(message?: string, errorCode?: number): void;
353
+ decline(message?: string, errorCode?: number): ConnectionContext<Path>;
341
354
 
342
355
  /**
343
356
  * @desc Emits a direct message to the client
344
357
  * @param {string} event - The event name
345
358
  * @param {PondMessage} payload - The payload to send
346
359
  */
347
- reply(event: string, payload: PondMessage): ConnectionResponse;
360
+ reply(event: string, payload: PondMessage): ConnectionContext<Path>;
348
361
  }
349
362
 
350
- export declare class JoinResponse<EventType extends PondEventMap = PondEventMap, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> {
363
+ export declare class JoinContext<Path extends string, EventType extends PondEventMap = PondEventMap, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> {
351
364
  /**
352
- * @desc Checks if the server has responded to the connection request.
365
+ * @desc Get the event information.
366
+ */
367
+ get event(): PondEvent<Path>;
368
+
369
+ /**
370
+ * @desc Get the channel name.
371
+ */
372
+ get channelName(): string;
373
+
374
+ /**
375
+ * @desc Get the channel instance.
376
+ */
377
+ get channel(): Channel;
378
+
379
+ /**
380
+ * @desc Get the join parameters.
381
+ */
382
+ get joinParams(): JoinParams;
383
+
384
+ /**
385
+ * @desc Get all current presences in the channel.
386
+ */
387
+ get presences(): UserPresences;
388
+
389
+ /**
390
+ * @desc Get all current assigns in the channel.
391
+ */
392
+ get assigns(): UserAssigns;
393
+
394
+ /**
395
+ * @desc Get the user data.
396
+ */
397
+ get user(): UserData<PresenceType, AssignType>;
398
+
399
+ /**
400
+ * @desc Checks if the server has responded to the join request.
353
401
  */
354
402
  get hasResponded(): boolean;
355
403
 
@@ -357,42 +405,41 @@ export declare class JoinResponse<EventType extends PondEventMap = PondEventMap,
357
405
  * @desc Assigns data to the client
358
406
  * @param {PondAssigns} assigns - The data to assign
359
407
  */
360
- assign(assigns: AssignType): JoinResponse;
408
+ assign(assigns: AssignType): JoinContext<Path, PresenceType, AssignType>;
361
409
 
362
410
  /**
363
411
  * @desc Accepts the join request to the channel.
364
- * @returns {JoinResponse} - The JoinResponse instance for chaining.
412
+ * @returns {JoinContext} - The JoinContext instance for chaining.
365
413
  */
366
- accept(): JoinResponse;
414
+ accept(): JoinContext<Path, PresenceType, AssignType>;
367
415
 
368
416
  /**
369
417
  * @desc Rejects the request and optionally assigns data to the client
370
418
  * @param {string} message - The error message
371
419
  * @param {number} errorCode - The error code
372
420
  */
373
- decline(message?: string, errorCode?: number): JoinResponse;
421
+ decline(message?: string, errorCode?: number): JoinContext<Path, PresenceType, AssignType>;
374
422
 
375
423
  /**
376
424
  * @desc Emits a direct message to the client
377
425
  * @param {string} event - The event name
378
426
  * @param {PondMessage} payload - The payload to send
379
- * @param {PondAssigns} assigns - The data to assign to the client
380
427
  */
381
- reply<Key extends keyof EventType>(event: Key, payload: EventType[Key], assigns?: AssignType): JoinResponse;
428
+ reply<Key extends keyof EventType>(event: Key, payload: EventType[Key]): JoinContext<Path, PresenceType, AssignType>;
382
429
 
383
430
  /**
384
431
  * @desc Emits a message to all clients in the channel
385
432
  * @param {string} event - The event name
386
433
  * @param {PondMessage} payload - The payload to send
387
434
  */
388
- broadcast<Key extends keyof EventType>(event: Key, payload: EventType[Key]): JoinResponse;
435
+ broadcast<Key extends keyof EventType>(event: Key, payload: EventType[Key]): JoinContext<Path, PresenceType, AssignType>;
389
436
 
390
437
  /**
391
438
  * @desc Emits a message to all clients in the channel except the sender
392
439
  * @param event - the event name
393
440
  * @param payload - the payload to send
394
441
  */
395
- broadcastFrom<Key extends keyof EventType>(event: Key, payload: EventType[Key]): JoinResponse;
442
+ broadcastFrom<Key extends keyof EventType>(event: Key, payload: EventType[Key]): JoinContext<Path, PresenceType, AssignType>;
396
443
 
397
444
  /**
398
445
  * @desc Emits a message to a specific set of clients
@@ -400,89 +447,114 @@ export declare class JoinResponse<EventType extends PondEventMap = PondEventMap,
400
447
  * @param {PondMessage} payload - The payload to send
401
448
  * @param {string | string[]} userIds - The ids of the clients to send the message to
402
449
  */
403
- broadcastTo<Key extends keyof EventType>(event: Key, payload: EventType[Key], userIds: string | string[]): JoinResponse;
450
+ broadcastTo<Key extends keyof EventType>(event: Key, payload: EventType[Key], userIds: string | string[]): JoinContext<Path, PresenceType, AssignType>;
404
451
 
405
452
  /**
406
453
  * @desc tracks the presence of a client
407
454
  * @param {PondPresence} presence - the presence data to track
408
455
  */
409
- trackPresence(presence: PresenceType): JoinResponse;
456
+ trackPresence(presence: PresenceType): JoinContext<Path, PresenceType, AssignType>;
410
457
  }
411
458
 
412
- export declare class EventResponse<EventType extends PondEventMap = PondEventMap, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> {
459
+ export declare class EventContext<Path extends string, EventType extends PondEventMap = PondEventMap, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> {
413
460
  /**
414
- * @desc Checks if the server has responded to the connection request.
461
+ * @desc Get the event information.
415
462
  */
416
- get hasResponded(): boolean;
463
+ get event(): PondEvent<Path>;
464
+
465
+ /**
466
+ * @desc Get the channel name.
467
+ */
468
+ get channelName(): string;
469
+
470
+ /**
471
+ * @desc Get the channel instance.
472
+ */
473
+ get channel(): Channel;
474
+
475
+ /**
476
+ * @desc Get all current presences in the channel.
477
+ */
478
+ get presences(): UserPresences;
479
+
480
+ /**
481
+ * @desc Get all current assigns in the channel.
482
+ */
483
+ get assigns(): UserAssigns;
484
+
485
+ /**
486
+ * @desc Get the user who sent the request.
487
+ */
488
+ get user(): UserData<PresenceType, AssignType>;
417
489
 
418
490
  /**
419
491
  * @desc Assigns data to the client.
420
492
  * @param {PondAssigns} assigns - The data to assign to the client.
421
- * @returns {EventResponse} - The EventResponse instance for chaining.
493
+ * @returns {EventContext} - The EventContext instance for chaining.
422
494
  */
423
- assign(assigns: AssignType): EventResponse<EventType, PresenceType, AssignType>;
495
+ assign(assigns: AssignType): EventContext<Path, EventType, PresenceType, AssignType>;
424
496
 
425
497
  /**
426
498
  * @desc Emits a direct message to the client.
427
499
  * @param {string} event - The event name.
428
500
  * @param {PondMessage} payload - The payload to send.
429
- * @returns {EventResponse} - The EventResponse instance for chaining.
501
+ * @returns {EventContext} - The EventContext instance for chaining.
430
502
  */
431
- reply<Event extends keyof EventType>(event: Event, payload: EventType[Event]): EventResponse<EventType, PresenceType, AssignType>;
503
+ reply<Event extends keyof EventType>(event: Event, payload: EventType[Event]): EventContext<Path, EventType, PresenceType, AssignType>;
432
504
 
433
505
  /**
434
506
  * @desc Sends a message to all clients in the channel.
435
507
  * @param {string} event - The event to send.
436
508
  * @param {PondMessage} payload - The payload to send.
437
- * @returns {EventResponse} - The EventResponse instance for chaining.
509
+ * @returns {EventContext} - The EventContext instance for chaining.
438
510
  */
439
- broadcast<Event extends keyof EventType>(event: Event, payload: EventType[Event]): EventResponse<EventType, PresenceType, AssignType>;
511
+ broadcast<Event extends keyof EventType>(event: Event, payload: EventType[Event]): EventContext<Path, EventType, PresenceType, AssignType>;
440
512
 
441
513
  /**
442
514
  * @desc Sends a message to all clients in the channel except the client making the request.
443
515
  * @param {string} event - The event to send.
444
516
  * @param {PondMessage} payload - The payload to send.
445
- * @returns {EventResponse} - The EventResponse instance for chaining.
517
+ * @returns {EventContext} - The EventContext instance for chaining.
446
518
  */
447
- broadcastFrom<UserEvent extends keyof EventType>(event: UserEvent, payload: EventType[UserEvent]): EventResponse<EventType, PresenceType, AssignType>;
519
+ broadcastFrom<UserEvent extends keyof EventType>(event: UserEvent, payload: EventType[UserEvent]): EventContext<Path, EventType, PresenceType, AssignType>;
448
520
 
449
521
  /**
450
522
  * @desc Sends a message to a set of clients in the channel.
451
523
  * @param {string} event - The event to send.
452
524
  * @param {PondMessage} payload - The payload to send.
453
525
  * @param {string | string[]} userIds - The ids of the clients to send the message to.
454
- * @returns {EventResponse} - The EventResponse instance for chaining.
526
+ * @returns {EventContext} - The EventContext instance for chaining.
455
527
  */
456
- broadcastTo<UserEvent extends keyof EventType>(event: UserEvent, payload: EventType[UserEvent], userIds: string | string[]): EventResponse<EventType, PresenceType, AssignType>;
528
+ broadcastTo<UserEvent extends keyof EventType>(event: UserEvent, payload: EventType[UserEvent], userIds: string | string[]): EventContext<Path, EventType, PresenceType, AssignType>;
457
529
 
458
530
  /**
459
531
  * @desc Tracks a user's presence in the channel.
460
532
  * @param {PondPresence} presence - The initial presence data.
461
533
  * @param {string} userId - The id of the user to track.
462
- * @returns {EventResponse} - The EventResponse instance for chaining.
534
+ * @returns {EventContext} - The EventContext instance for chaining.
463
535
  */
464
- trackPresence(presence: PresenceType, userId?: string): EventResponse<EventType, PresenceType, AssignType>;
536
+ trackPresence(presence: PresenceType, userId?: string): EventContext<Path, EventType, PresenceType, AssignType>;
465
537
 
466
538
  /**
467
539
  * @desc Updates a user's presence in the channel.
468
540
  * @param {PondPresence} presence - The updated presence data.
469
541
  * @param {string} userId - The id of the user to update.
470
- * @returns {EventResponse} - The EventResponse instance for chaining.
542
+ * @returns {EventContext} - The EventContext instance for chaining.
471
543
  */
472
- updatePresence(presence: PresenceType, userId?: string): EventResponse;
544
+ updatePresence(presence: PresenceType, userId?: string): EventContext<Path, EventType, PresenceType, AssignType>;
473
545
 
474
546
  /**
475
547
  * @desc Removes a user's presence from the channel.
476
548
  * @param {string} userId - The id of the user to remove.
477
- * @returns {EventResponse} - The EventResponse instance for chaining.
549
+ * @returns {EventContext} - The EventContext instance for chaining.
478
550
  */
479
- removePresence(userId?: string): EventResponse;
551
+ removePresence(userId?: string): EventContext<Path, EventType, PresenceType, AssignType>;
480
552
 
481
553
  /**
482
554
  * @desc Evicts a user from the channel.
483
555
  * @param {string} reason - The reason for the eviction.
484
556
  * @param {string} userId - The id of the user to evict.
485
- * @returns {EventResponse} - The EventResponse instance for chaining.
557
+ * @returns {EventContext} - The EventContext instance for chaining.
486
558
  */
487
- evictUser(reason: string, userId?: string): EventResponse;
559
+ evictUser(reason: string, userId?: string): EventContext<Path, EventType, PresenceType, AssignType>;
488
560
  }
@@ -1,69 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _EventRequest_event, _EventRequest_engine, _EventRequest_params;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.EventRequest = void 0;
16
- const channel_1 = require("../wrappers/channel");
17
- class EventRequest {
18
- constructor(event, params, engine) {
19
- _EventRequest_event.set(this, void 0);
20
- _EventRequest_engine.set(this, void 0);
21
- _EventRequest_params.set(this, void 0);
22
- __classPrivateFieldSet(this, _EventRequest_event, event, "f");
23
- __classPrivateFieldSet(this, _EventRequest_params, params, "f");
24
- __classPrivateFieldSet(this, _EventRequest_engine, engine, "f");
25
- }
26
- /**
27
- * The event information
28
- */
29
- get event() {
30
- return {
31
- event: __classPrivateFieldGet(this, _EventRequest_event, "f").event,
32
- query: __classPrivateFieldGet(this, _EventRequest_params, "f").query,
33
- params: __classPrivateFieldGet(this, _EventRequest_params, "f").params,
34
- payload: __classPrivateFieldGet(this, _EventRequest_event, "f").payload,
35
- };
36
- }
37
- /**
38
- * The channel name
39
- */
40
- get channelName() {
41
- return __classPrivateFieldGet(this, _EventRequest_engine, "f").name;
42
- }
43
- /**
44
- * The channel instance
45
- */
46
- get channel() {
47
- return new channel_1.Channel(__classPrivateFieldGet(this, _EventRequest_engine, "f"));
48
- }
49
- /**
50
- * All current presences in the channel
51
- */
52
- get presences() {
53
- return __classPrivateFieldGet(this, _EventRequest_engine, "f").getPresence();
54
- }
55
- /**
56
- * All current assigns in the channel
57
- */
58
- get assigns() {
59
- return __classPrivateFieldGet(this, _EventRequest_engine, "f").getAssigns();
60
- }
61
- /**
62
- * The user who sent the request
63
- */
64
- get user() {
65
- return __classPrivateFieldGet(this, _EventRequest_engine, "f").getUserData(__classPrivateFieldGet(this, _EventRequest_event, "f").sender);
66
- }
67
- }
68
- exports.EventRequest = EventRequest;
69
- _EventRequest_event = new WeakMap(), _EventRequest_engine = new WeakMap(), _EventRequest_params = new WeakMap();
@@ -1,56 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _JoinRequest_options, _JoinRequest_engine;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.JoinRequest = void 0;
16
- const channel_1 = require("../wrappers/channel");
17
- class JoinRequest {
18
- constructor(options, channel) {
19
- _JoinRequest_options.set(this, void 0);
20
- _JoinRequest_engine.set(this, void 0);
21
- __classPrivateFieldSet(this, _JoinRequest_options, options, "f");
22
- __classPrivateFieldSet(this, _JoinRequest_engine, channel, "f");
23
- }
24
- get event() {
25
- return {
26
- event: __classPrivateFieldGet(this, _JoinRequest_engine, "f").name,
27
- query: __classPrivateFieldGet(this, _JoinRequest_options, "f").params.query,
28
- params: __classPrivateFieldGet(this, _JoinRequest_options, "f").params.params,
29
- payload: __classPrivateFieldGet(this, _JoinRequest_options, "f").joinParams,
30
- };
31
- }
32
- get channelName() {
33
- return __classPrivateFieldGet(this, _JoinRequest_engine, "f").name;
34
- }
35
- get channel() {
36
- return new channel_1.Channel(__classPrivateFieldGet(this, _JoinRequest_engine, "f"));
37
- }
38
- get presences() {
39
- return __classPrivateFieldGet(this, _JoinRequest_engine, "f").getPresence();
40
- }
41
- get assigns() {
42
- return __classPrivateFieldGet(this, _JoinRequest_engine, "f").getAssigns();
43
- }
44
- get user() {
45
- return {
46
- id: __classPrivateFieldGet(this, _JoinRequest_options, "f").clientId,
47
- assigns: __classPrivateFieldGet(this, _JoinRequest_options, "f").assigns,
48
- presence: {},
49
- };
50
- }
51
- get joinParams() {
52
- return __classPrivateFieldGet(this, _JoinRequest_options, "f").joinParams;
53
- }
54
- }
55
- exports.JoinRequest = JoinRequest;
56
- _JoinRequest_options = new WeakMap(), _JoinRequest_engine = new WeakMap();
@@ -1,92 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _ConnectionResponse_instances, _ConnectionResponse_executed, _ConnectionResponse_assigns, _ConnectionResponse_clientId, _ConnectionResponse_engine, _ConnectionResponse_params, _ConnectionResponse_webSocketServer, _ConnectionResponse_performChecks;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.ConnectionResponse = void 0;
16
- const pondsocket_common_1 = require("@eleven-am/pondsocket-common");
17
- const httpError_1 = require("../errors/httpError");
18
- class ConnectionResponse {
19
- constructor(clientId, { engine, params, webSocketServer }) {
20
- _ConnectionResponse_instances.add(this);
21
- _ConnectionResponse_executed.set(this, void 0);
22
- _ConnectionResponse_assigns.set(this, void 0);
23
- _ConnectionResponse_clientId.set(this, void 0);
24
- _ConnectionResponse_engine.set(this, void 0);
25
- _ConnectionResponse_params.set(this, void 0);
26
- _ConnectionResponse_webSocketServer.set(this, void 0);
27
- __classPrivateFieldSet(this, _ConnectionResponse_webSocketServer, webSocketServer, "f");
28
- __classPrivateFieldSet(this, _ConnectionResponse_clientId, clientId, "f");
29
- __classPrivateFieldSet(this, _ConnectionResponse_executed, false, "f");
30
- __classPrivateFieldSet(this, _ConnectionResponse_engine, engine, "f");
31
- __classPrivateFieldSet(this, _ConnectionResponse_params, params, "f");
32
- __classPrivateFieldSet(this, _ConnectionResponse_assigns, {}, "f");
33
- }
34
- get hasResponded() {
35
- return __classPrivateFieldGet(this, _ConnectionResponse_executed, "f");
36
- }
37
- assign(assigns) {
38
- if (!__classPrivateFieldGet(this, _ConnectionResponse_executed, "f")) {
39
- __classPrivateFieldSet(this, _ConnectionResponse_assigns, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _ConnectionResponse_assigns, "f")), assigns), "f");
40
- }
41
- else {
42
- const user = __classPrivateFieldGet(this, _ConnectionResponse_engine, "f").getUser(__classPrivateFieldGet(this, _ConnectionResponse_clientId, "f"));
43
- user.assigns = Object.assign(Object.assign({}, user.assigns), assigns);
44
- }
45
- return this;
46
- }
47
- accept() {
48
- __classPrivateFieldGet(this, _ConnectionResponse_instances, "m", _ConnectionResponse_performChecks).call(this);
49
- __classPrivateFieldGet(this, _ConnectionResponse_webSocketServer, "f").handleUpgrade(__classPrivateFieldGet(this, _ConnectionResponse_params, "f").request, __classPrivateFieldGet(this, _ConnectionResponse_params, "f").socket, __classPrivateFieldGet(this, _ConnectionResponse_params, "f").head, (ws) => {
50
- const cache = {
51
- clientId: __classPrivateFieldGet(this, _ConnectionResponse_clientId, "f"),
52
- subscriptions: new Set(),
53
- assigns: __classPrivateFieldGet(this, _ConnectionResponse_assigns, "f"),
54
- socket: ws,
55
- };
56
- __classPrivateFieldGet(this, _ConnectionResponse_webSocketServer, "f").emit('connection', ws);
57
- __classPrivateFieldGet(this, _ConnectionResponse_engine, "f").manageSocket(cache);
58
- });
59
- return this;
60
- }
61
- decline(message, errorCode) {
62
- __classPrivateFieldGet(this, _ConnectionResponse_instances, "m", _ConnectionResponse_performChecks).call(this);
63
- const code = errorCode || 400;
64
- const { socket } = __classPrivateFieldGet(this, _ConnectionResponse_params, "f");
65
- const newMessage = message || 'Unauthorized connection';
66
- socket.write(`HTTP/1.1 ${code} ${newMessage}\r\n\r\n`);
67
- socket.destroy();
68
- return this;
69
- }
70
- reply(event, payload) {
71
- if (!__classPrivateFieldGet(this, _ConnectionResponse_executed, "f")) {
72
- throw new httpError_1.HttpError(400, 'Connection has not been accepted');
73
- }
74
- const { socket } = __classPrivateFieldGet(this, _ConnectionResponse_engine, "f").getUser(__classPrivateFieldGet(this, _ConnectionResponse_clientId, "f"));
75
- const message = {
76
- event,
77
- payload,
78
- action: pondsocket_common_1.ServerActions.BROADCAST,
79
- requestId: __classPrivateFieldGet(this, _ConnectionResponse_params, "f").requestId,
80
- channelName: pondsocket_common_1.SystemSender.ENDPOINT,
81
- };
82
- __classPrivateFieldGet(this, _ConnectionResponse_engine, "f").sendMessage(socket, message);
83
- return this;
84
- }
85
- }
86
- exports.ConnectionResponse = ConnectionResponse;
87
- _ConnectionResponse_executed = new WeakMap(), _ConnectionResponse_assigns = new WeakMap(), _ConnectionResponse_clientId = new WeakMap(), _ConnectionResponse_engine = new WeakMap(), _ConnectionResponse_params = new WeakMap(), _ConnectionResponse_webSocketServer = new WeakMap(), _ConnectionResponse_instances = new WeakSet(), _ConnectionResponse_performChecks = function _ConnectionResponse_performChecks() {
88
- if (__classPrivateFieldGet(this, _ConnectionResponse_executed, "f")) {
89
- throw new httpError_1.HttpError(400, 'Response has already been executed');
90
- }
91
- __classPrivateFieldSet(this, _ConnectionResponse_executed, true, "f");
92
- };