@eleven-am/pondsocket 0.1.213 → 0.1.215

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.
@@ -10,90 +10,46 @@ 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 _EventContext_instances, _EventContext_event, _EventContext_requestId, _EventContext_sendMessage;
13
+ var _EventContext_event, _EventContext_requestId;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.EventContext = void 0;
16
16
  const pondsocket_common_1 = require("@eleven-am/pondsocket-common");
17
17
  const baseContext_1 = require("./baseContext");
18
- /**
19
- * EventContext combines the functionality of EventRequest and EventResponse
20
- * to provide a unified interface for handling events in a channel.
21
- */
22
18
  class EventContext extends baseContext_1.BaseContext {
23
19
  constructor(event, params, engine) {
24
20
  super(engine, params, event.event, event.payload, event.sender);
25
- _EventContext_instances.add(this);
26
21
  _EventContext_event.set(this, void 0);
27
22
  _EventContext_requestId.set(this, void 0);
28
23
  __classPrivateFieldSet(this, _EventContext_event, event, "f");
29
24
  __classPrivateFieldSet(this, _EventContext_requestId, event.requestId, "f");
30
25
  }
31
- /**
32
- * Assigns data to the client
33
- */
34
26
  assign(assigns) {
35
27
  this.channel.updateAssigns(__classPrivateFieldGet(this, _EventContext_event, "f").sender, assigns);
36
28
  return this;
37
29
  }
38
- /**
39
- * Sends a direct reply to the client
40
- */
41
30
  reply(event, payload) {
42
31
  this.engine.sendMessage(pondsocket_common_1.SystemSender.CHANNEL, [__classPrivateFieldGet(this, _EventContext_event, "f").sender], pondsocket_common_1.ServerActions.SYSTEM, event, payload, __classPrivateFieldGet(this, _EventContext_requestId, "f"));
43
32
  return this;
44
33
  }
45
- /**
46
- * Broadcasts a message to all users in the channel
47
- */
48
- broadcast(event, payload) {
49
- __classPrivateFieldGet(this, _EventContext_instances, "m", _EventContext_sendMessage).call(this, pondsocket_common_1.ChannelReceiver.ALL_USERS, event, payload);
50
- return this;
51
- }
52
- /**
53
- * Broadcasts a message to all users except the sender
54
- */
55
- broadcastFrom(event, payload) {
56
- __classPrivateFieldGet(this, _EventContext_instances, "m", _EventContext_sendMessage).call(this, pondsocket_common_1.ChannelReceiver.ALL_EXCEPT_SENDER, event, payload);
57
- return this;
58
- }
59
- /**
60
- * Broadcasts a message to specific users
61
- */
62
- broadcastTo(event, payload, userIds) {
63
- const ids = Array.isArray(userIds) ? userIds : [userIds];
64
- __classPrivateFieldGet(this, _EventContext_instances, "m", _EventContext_sendMessage).call(this, ids, event, payload);
65
- return this;
66
- }
67
- /**
68
- * Tracks a user's presence
69
- */
70
34
  trackPresence(presence, userId = __classPrivateFieldGet(this, _EventContext_event, "f").sender) {
71
35
  this.channel.trackPresence(userId, presence);
72
36
  return this;
73
37
  }
74
- /**
75
- * Updates a user's presence
76
- */
77
38
  updatePresence(presence, userId = __classPrivateFieldGet(this, _EventContext_event, "f").sender) {
78
39
  this.channel.updatePresence(userId, presence);
79
40
  return this;
80
41
  }
81
- /**
82
- * Kicks a user from the channel
83
- */
84
42
  evictUser(reason, userId = __classPrivateFieldGet(this, _EventContext_event, "f").sender) {
85
43
  this.channel.evictUser(userId, reason);
86
44
  return this;
87
45
  }
88
- /**
89
- * Removes a user's presence
90
- */
91
46
  removePresence(userId = __classPrivateFieldGet(this, _EventContext_event, "f").sender) {
92
47
  this.channel.removePresence(userId);
93
48
  return this;
94
49
  }
50
+ _sendMessageToRecipients(recipient, event, payload) {
51
+ this.engine.sendMessage(__classPrivateFieldGet(this, _EventContext_event, "f").sender, recipient, pondsocket_common_1.ServerActions.BROADCAST, event, payload, __classPrivateFieldGet(this, _EventContext_requestId, "f"));
52
+ }
95
53
  }
96
54
  exports.EventContext = EventContext;
97
- _EventContext_event = new WeakMap(), _EventContext_requestId = new WeakMap(), _EventContext_instances = new WeakSet(), _EventContext_sendMessage = function _EventContext_sendMessage(recipient, event, payload) {
98
- this.engine.sendMessage(__classPrivateFieldGet(this, _EventContext_event, "f").sender, recipient, pondsocket_common_1.ServerActions.BROADCAST, event, payload, __classPrivateFieldGet(this, _EventContext_requestId, "f"));
99
- };
55
+ _EventContext_event = new WeakMap(), _EventContext_requestId = new WeakMap();
@@ -0,0 +1,17 @@
1
+ import { ChannelReceivers, JoinParams, PondAssigns, PondMessage, PondObject, PondPresence, UserData } from '@eleven-am/pondsocket-common';
2
+ import { BaseContext } from './baseContext';
3
+ import { JoinRequestOptions, RequestCache } from '../abstracts/types';
4
+ import { ChannelEngine } from '../engines/channelEngine';
5
+ export declare class JoinContext<Path extends string> extends BaseContext<Path> {
6
+ #private;
7
+ constructor(options: JoinRequestOptions<Path>, engine: ChannelEngine, user: RequestCache);
8
+ get user(): UserData;
9
+ get joinParams(): JoinParams;
10
+ get hasResponded(): boolean;
11
+ accept(): JoinContext<Path>;
12
+ decline(message?: string, errorCode?: number): JoinContext<Path>;
13
+ assign(assigns: PondAssigns): JoinContext<Path>;
14
+ reply(event: string, payload: PondMessage): JoinContext<Path>;
15
+ trackPresence(presence: PondPresence): JoinContext<Path>;
16
+ protected _sendMessageToRecipients(recipient: ChannelReceivers, event: string, payload: PondObject): void;
17
+ }
@@ -10,16 +10,12 @@ 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 _JoinContext_instances, _JoinContext_options, _JoinContext_user, _JoinContext_newAssigns, _JoinContext_executed, _JoinContext_accepted, _JoinContext_sendMessage, _JoinContext_directMessage, _JoinContext_performChecks;
13
+ var _JoinContext_instances, _JoinContext_options, _JoinContext_user, _JoinContext_newAssigns, _JoinContext_executed, _JoinContext_accepted, _JoinContext_directMessage, _JoinContext_performChecks;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.JoinContext = void 0;
16
16
  const pondsocket_common_1 = require("@eleven-am/pondsocket-common");
17
17
  const baseContext_1 = require("./baseContext");
18
18
  const httpError_1 = require("../errors/httpError");
19
- /**
20
- * JoinContext combines the functionality of JoinRequest and JoinResponse
21
- * to provide a unified interface for handling join events in a channel.
22
- */
23
19
  class JoinContext extends baseContext_1.BaseContext {
24
20
  constructor(options, engine, user) {
25
21
  super(engine, options.params, engine.name, options.joinParams, user.clientId);
@@ -35,9 +31,6 @@ class JoinContext extends baseContext_1.BaseContext {
35
31
  __classPrivateFieldSet(this, _JoinContext_accepted, false, "f");
36
32
  __classPrivateFieldSet(this, _JoinContext_newAssigns, Object.assign({}, user.assigns), "f");
37
33
  }
38
- /**
39
- * The user who sent the request
40
- */
41
34
  get user() {
42
35
  return {
43
36
  id: __classPrivateFieldGet(this, _JoinContext_options, "f").clientId,
@@ -45,21 +38,12 @@ class JoinContext extends baseContext_1.BaseContext {
45
38
  presence: {},
46
39
  };
47
40
  }
48
- /**
49
- * The join parameters
50
- */
51
41
  get joinParams() {
52
42
  return __classPrivateFieldGet(this, _JoinContext_options, "f").joinParams;
53
43
  }
54
- /**
55
- * Whether the request has been handled
56
- */
57
44
  get hasResponded() {
58
45
  return __classPrivateFieldGet(this, _JoinContext_executed, "f");
59
46
  }
60
- /**
61
- * Accepts the join request
62
- */
63
47
  accept() {
64
48
  __classPrivateFieldGet(this, _JoinContext_instances, "m", _JoinContext_performChecks).call(this);
65
49
  const onMessage = this.engine.parent.parent.sendMessage.bind(this.engine.parent.parent, __classPrivateFieldGet(this, _JoinContext_user, "f").socket);
@@ -68,9 +52,6 @@ class JoinContext extends baseContext_1.BaseContext {
68
52
  __classPrivateFieldSet(this, _JoinContext_accepted, true, "f");
69
53
  return this;
70
54
  }
71
- /**
72
- * Declines the join request
73
- */
74
55
  decline(message, errorCode) {
75
56
  __classPrivateFieldGet(this, _JoinContext_instances, "m", _JoinContext_performChecks).call(this);
76
57
  const errorMessage = {
@@ -86,9 +67,6 @@ class JoinContext extends baseContext_1.BaseContext {
86
67
  __classPrivateFieldGet(this, _JoinContext_instances, "m", _JoinContext_directMessage).call(this, errorMessage);
87
68
  return this;
88
69
  }
89
- /**
90
- * Assigns data to the user
91
- */
92
70
  assign(assigns) {
93
71
  if (__classPrivateFieldGet(this, _JoinContext_accepted, "f")) {
94
72
  this.engine.updateAssigns(__classPrivateFieldGet(this, _JoinContext_user, "f").clientId, assigns);
@@ -98,9 +76,6 @@ class JoinContext extends baseContext_1.BaseContext {
98
76
  }
99
77
  return this;
100
78
  }
101
- /**
102
- * Sends a direct reply to the user
103
- */
104
79
  reply(event, payload) {
105
80
  const message = {
106
81
  action: pondsocket_common_1.ServerActions.SYSTEM,
@@ -112,40 +87,16 @@ class JoinContext extends baseContext_1.BaseContext {
112
87
  __classPrivateFieldGet(this, _JoinContext_instances, "m", _JoinContext_directMessage).call(this, message);
113
88
  return this;
114
89
  }
115
- /**
116
- * Broadcasts a message to specific users
117
- */
118
- broadcastTo(event, payload, userIds) {
119
- const ids = Array.isArray(userIds) ? userIds : [userIds];
120
- __classPrivateFieldGet(this, _JoinContext_instances, "m", _JoinContext_sendMessage).call(this, ids, event, payload);
121
- return this;
122
- }
123
- /**
124
- * Broadcasts a message to all users in the channel
125
- */
126
- broadcast(event, payload) {
127
- __classPrivateFieldGet(this, _JoinContext_instances, "m", _JoinContext_sendMessage).call(this, pondsocket_common_1.ChannelReceiver.ALL_USERS, event, payload);
128
- return this;
129
- }
130
- /**
131
- * Broadcasts a message to all users except the sender
132
- */
133
- broadcastFrom(event, payload) {
134
- __classPrivateFieldGet(this, _JoinContext_instances, "m", _JoinContext_sendMessage).call(this, pondsocket_common_1.ChannelReceiver.ALL_EXCEPT_SENDER, event, payload);
135
- return this;
136
- }
137
- /**
138
- * Tracks the user's presence
139
- */
140
90
  trackPresence(presence) {
141
91
  this.engine.trackPresence(__classPrivateFieldGet(this, _JoinContext_user, "f").clientId, presence);
142
92
  return this;
143
93
  }
94
+ _sendMessageToRecipients(recipient, event, payload) {
95
+ this.engine.sendMessage(__classPrivateFieldGet(this, _JoinContext_user, "f").clientId, recipient, pondsocket_common_1.ServerActions.BROADCAST, event, payload, __classPrivateFieldGet(this, _JoinContext_user, "f").requestId);
96
+ }
144
97
  }
145
98
  exports.JoinContext = JoinContext;
146
- _JoinContext_options = new WeakMap(), _JoinContext_user = new WeakMap(), _JoinContext_newAssigns = new WeakMap(), _JoinContext_executed = new WeakMap(), _JoinContext_accepted = new WeakMap(), _JoinContext_instances = new WeakSet(), _JoinContext_sendMessage = function _JoinContext_sendMessage(recipient, event, payload) {
147
- this.engine.sendMessage(__classPrivateFieldGet(this, _JoinContext_user, "f").clientId, recipient, pondsocket_common_1.ServerActions.BROADCAST, event, payload, __classPrivateFieldGet(this, _JoinContext_user, "f").requestId);
148
- }, _JoinContext_directMessage = function _JoinContext_directMessage(event) {
99
+ _JoinContext_options = new WeakMap(), _JoinContext_user = new WeakMap(), _JoinContext_newAssigns = new WeakMap(), _JoinContext_executed = new WeakMap(), _JoinContext_accepted = new WeakMap(), _JoinContext_instances = new WeakSet(), _JoinContext_directMessage = function _JoinContext_directMessage(event) {
149
100
  this.engine.parent.parent.sendMessage(__classPrivateFieldGet(this, _JoinContext_user, "f").socket, event);
150
101
  }, _JoinContext_performChecks = function _JoinContext_performChecks() {
151
102
  if (__classPrivateFieldGet(this, _JoinContext_executed, "f")) {
@@ -0,0 +1,28 @@
1
+ import { ChannelReceivers, Event, EventParams, PondMessage, PondObject } from '@eleven-am/pondsocket-common';
2
+ import { BaseContext } from './baseContext';
3
+ import { ChannelEngine } from '../engines/channelEngine';
4
+ export declare class OutgoingContext<Path extends string> extends BaseContext<Path> {
5
+ #private;
6
+ constructor(event: Event, params: EventParams<Path>, engine: ChannelEngine, userid: string);
7
+ get payload(): PondMessage;
8
+ /**
9
+ * Blocks the outgoing context, preventing further processing of the event.
10
+ */
11
+ block(): this;
12
+ /**
13
+ * Checks if the outgoing context is blocked.
14
+ * @returns {boolean} - True if blocked, false otherwise.
15
+ */
16
+ isBlocked(): boolean;
17
+ /**
18
+ * Transforms the outgoing context with a new payload.
19
+ * @param payload - The new payload to set for the context.
20
+ */
21
+ transform(payload: PondMessage): this;
22
+ /**
23
+ * Updates the parameters of the outgoing context.
24
+ * @param params - The new parameters to set for the context.
25
+ */
26
+ updateParams(params: EventParams<Path>): void;
27
+ protected _sendMessageToRecipients(_recipient: ChannelReceivers, _event: string, _payload: PondObject): void;
28
+ }
@@ -54,6 +54,9 @@ class OutgoingContext extends baseContext_1.BaseContext {
54
54
  updateParams(params) {
55
55
  super.updateParams(params);
56
56
  }
57
+ _sendMessageToRecipients(_recipient, _event, _payload) {
58
+ void 0;
59
+ }
57
60
  }
58
61
  exports.OutgoingContext = OutgoingContext;
59
62
  _OutgoingContext_payload = new WeakMap(), _OutgoingContext_isBlocked = new WeakMap();
@@ -0,0 +1,26 @@
1
+ import { ChannelEvent, ChannelReceivers, ClientMessage, PondAssigns, PondMessage, PondPresence, ServerActions, Unsubscribe, UserAssigns, UserData, UserPresences } from '@eleven-am/pondsocket-common';
2
+ import { LobbyEngine } from './lobbyEngine';
3
+ import { type ChannelSenders } from '../abstracts/types';
4
+ import { type IDistributedBackend } from '../types';
5
+ export declare class ChannelEngine {
6
+ #private;
7
+ parent: LobbyEngine;
8
+ constructor(parent: LobbyEngine, name: string, backend?: IDistributedBackend | null);
9
+ get name(): string;
10
+ get users(): Set<string>;
11
+ addUser(userId: string, assigns: PondAssigns, onMessage: (event: ChannelEvent) => void): Unsubscribe;
12
+ sendMessage(sender: ChannelSenders, recipient: ChannelReceivers, action: ServerActions, event: string, payload: PondMessage, requestId?: string): void;
13
+ broadcastMessage(userId: string, message: ClientMessage): void;
14
+ trackPresence(userId: string, presence: PondPresence): void;
15
+ updatePresence(userId: string, presence: PondPresence): void;
16
+ removePresence(userId: string): void;
17
+ upsertPresence(userId: string, presence: PondPresence): void;
18
+ updateAssigns(userId: string, assigns: PondMessage): void;
19
+ kickUser(userId: string, reason: string): void;
20
+ getAssigns(): UserAssigns;
21
+ getPresence(): UserPresences;
22
+ destroy(reason?: string): void;
23
+ removeUser(userId: string, skipDistributedBroadcast?: boolean): void;
24
+ getUserData(userId: string): UserData;
25
+ close(): void;
26
+ }