@eleven-am/pondsocket 0.1.126 → 0.1.127
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/README.md +5 -15
- package/abstracts/abstractRequest.test.js +42 -0
- package/abstracts/middleware.test.js +70 -0
- package/channel/channel.js +18 -20
- package/channel/channel.test.js +415 -0
- package/channel/eventRequest.test.js +30 -0
- package/channel/eventResponse.js +7 -7
- package/channel/eventResponse.test.js +197 -0
- package/endpoint/endpoint.js +16 -19
- package/endpoint/endpoint.test.js +297 -0
- package/endpoint/response.js +5 -6
- package/index.d.ts +2 -0
- package/lobby/JoinRequest.test.js +40 -0
- package/lobby/JoinResponse.test.js +145 -0
- package/lobby/joinResponse.js +9 -9
- package/lobby/lobby.js +3 -4
- package/matcher/matcher.test.js +90 -0
- package/package.json +32 -13
- package/presence/presence.js +8 -9
- package/presence/presenceEngine.test.js +128 -0
- package/schema.js +3 -3
- package/server/pondSocket.js +5 -4
- package/types.d.ts +0 -496
- package/types.js +2 -0
- package/client/channel.js +0 -305
- package/client.d.ts +0 -5
- package/client.js +0 -107
- package/enums.js +0 -56
- package/express.d.ts +0 -3
- package/express.js +0 -17
- package/misc/uuid.js +0 -12
- package/nest.d.ts +0 -19
- package/nest.js +0 -769
- package/node.d.ts +0 -3
- package/node.js +0 -30
- package/subjects/subject.js +0 -137
package/client/channel.js
DELETED
|
@@ -1,305 +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 _Channel_instances, _Channel_name, _Channel_queue, _Channel_presence, _Channel_publisher, _Channel_joinParams, _Channel_presenceSub, _Channel_receiver, _Channel_clientState, _Channel_joinState, _Channel_send, _Channel_publish, _Channel_subscribeToPresence, _Channel_init, _Channel_emptyQueue, _Channel_buildJoinMessage, _Channel_onMessage;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.Channel = void 0;
|
|
16
|
-
const enums_1 = require("../enums");
|
|
17
|
-
const uuid_1 = require("../misc/uuid");
|
|
18
|
-
const subject_1 = require("../subjects/subject");
|
|
19
|
-
class Channel {
|
|
20
|
-
constructor(publisher, clientState, name, receiver, params) {
|
|
21
|
-
_Channel_instances.add(this);
|
|
22
|
-
_Channel_name.set(this, void 0);
|
|
23
|
-
_Channel_queue.set(this, void 0);
|
|
24
|
-
_Channel_presence.set(this, void 0);
|
|
25
|
-
_Channel_publisher.set(this, void 0);
|
|
26
|
-
_Channel_joinParams.set(this, void 0);
|
|
27
|
-
_Channel_presenceSub.set(this, void 0);
|
|
28
|
-
_Channel_receiver.set(this, void 0);
|
|
29
|
-
_Channel_clientState.set(this, void 0);
|
|
30
|
-
_Channel_joinState.set(this, void 0);
|
|
31
|
-
__classPrivateFieldSet(this, _Channel_name, name, "f");
|
|
32
|
-
__classPrivateFieldSet(this, _Channel_queue, [], "f");
|
|
33
|
-
__classPrivateFieldSet(this, _Channel_presence, [], "f");
|
|
34
|
-
__classPrivateFieldSet(this, _Channel_joinParams, params, "f");
|
|
35
|
-
__classPrivateFieldSet(this, _Channel_publisher, publisher, "f");
|
|
36
|
-
__classPrivateFieldSet(this, _Channel_clientState, clientState, "f");
|
|
37
|
-
__classPrivateFieldSet(this, _Channel_receiver, new subject_1.SimpleSubject(), "f");
|
|
38
|
-
__classPrivateFieldSet(this, _Channel_joinState, new subject_1.SimpleBehaviorSubject(enums_1.ChannelState.IDLE), "f");
|
|
39
|
-
__classPrivateFieldSet(this, _Channel_presenceSub, __classPrivateFieldGet(this, _Channel_instances, "m", _Channel_init).call(this, receiver), "f");
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* @desc Gets the current connection state of the channel.
|
|
43
|
-
*/
|
|
44
|
-
get channelState() {
|
|
45
|
-
return __classPrivateFieldGet(this, _Channel_joinState, "f").value;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* @desc Connects to the channel.
|
|
49
|
-
*/
|
|
50
|
-
join() {
|
|
51
|
-
if (__classPrivateFieldGet(this, _Channel_joinState, "f").value === enums_1.ChannelState.CLOSED) {
|
|
52
|
-
throw new Error('This channel has been closed');
|
|
53
|
-
}
|
|
54
|
-
const joinMessage = __classPrivateFieldGet(this, _Channel_instances, "m", _Channel_buildJoinMessage).call(this);
|
|
55
|
-
__classPrivateFieldGet(this, _Channel_joinState, "f").publish(enums_1.ChannelState.JOINING);
|
|
56
|
-
if (__classPrivateFieldGet(this, _Channel_clientState, "f").value) {
|
|
57
|
-
__classPrivateFieldGet(this, _Channel_publisher, "f").call(this, joinMessage);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
__classPrivateFieldGet(this, _Channel_joinState, "f").publish(enums_1.ChannelState.STALLED);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* @desc Disconnects from the channel.
|
|
65
|
-
*/
|
|
66
|
-
leave() {
|
|
67
|
-
const leaveMessage = {
|
|
68
|
-
addresses: enums_1.ChannelReceiver.ALL_USERS,
|
|
69
|
-
action: enums_1.ClientActions.LEAVE_CHANNEL,
|
|
70
|
-
event: enums_1.ClientActions.LEAVE_CHANNEL,
|
|
71
|
-
channelName: __classPrivateFieldGet(this, _Channel_name, "f"),
|
|
72
|
-
requestId: (0, uuid_1.uuid)(),
|
|
73
|
-
payload: {},
|
|
74
|
-
};
|
|
75
|
-
__classPrivateFieldGet(this, _Channel_instances, "m", _Channel_publish).call(this, leaveMessage);
|
|
76
|
-
__classPrivateFieldGet(this, _Channel_joinState, "f").publish(enums_1.ChannelState.CLOSED);
|
|
77
|
-
__classPrivateFieldGet(this, _Channel_presenceSub, "f").call(this);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* @desc Monitors the channel for messages.
|
|
81
|
-
* @param callback - The callback to call when a message is received.
|
|
82
|
-
*/
|
|
83
|
-
onMessage(callback) {
|
|
84
|
-
return __classPrivateFieldGet(this, _Channel_instances, "m", _Channel_onMessage).call(this, (event, message) => {
|
|
85
|
-
callback(event, message);
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* @desc Monitors the channel for messages.
|
|
90
|
-
* @param event - The event to monitor.
|
|
91
|
-
* @param callback - The callback to call when a message is received.
|
|
92
|
-
*/
|
|
93
|
-
onMessageEvent(event, callback) {
|
|
94
|
-
return this.onMessage((eventReceived, message) => {
|
|
95
|
-
if (eventReceived === event) {
|
|
96
|
-
return callback(message);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* @desc Monitors the channel state of the channel.
|
|
102
|
-
* @param callback - The callback to call when the connection state changes.
|
|
103
|
-
*/
|
|
104
|
-
onChannelStateChange(callback) {
|
|
105
|
-
return __classPrivateFieldGet(this, _Channel_joinState, "f").subscribe((data) => {
|
|
106
|
-
callback(data);
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* @desc Detects when clients join the channel.
|
|
111
|
-
* @param callback - The callback to call when a client joins the channel.
|
|
112
|
-
*/
|
|
113
|
-
onJoin(callback) {
|
|
114
|
-
return __classPrivateFieldGet(this, _Channel_instances, "m", _Channel_subscribeToPresence).call(this, (event, payload) => {
|
|
115
|
-
if (event === enums_1.PresenceEventTypes.JOIN) {
|
|
116
|
-
return callback(payload.changed);
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* @desc Detects when clients leave the channel.
|
|
122
|
-
* @param callback - The callback to call when a client leaves the channel.
|
|
123
|
-
*/
|
|
124
|
-
onLeave(callback) {
|
|
125
|
-
return __classPrivateFieldGet(this, _Channel_instances, "m", _Channel_subscribeToPresence).call(this, (event, payload) => {
|
|
126
|
-
if (event === enums_1.PresenceEventTypes.LEAVE) {
|
|
127
|
-
return callback(payload.changed);
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* @desc Detects when clients change their presence in the channel.
|
|
133
|
-
* @param callback - The callback to call when a client changes their presence in the channel.
|
|
134
|
-
*/
|
|
135
|
-
onPresenceChange(callback) {
|
|
136
|
-
return __classPrivateFieldGet(this, _Channel_instances, "m", _Channel_subscribeToPresence).call(this, (event, payload) => {
|
|
137
|
-
if (event === enums_1.PresenceEventTypes.UPDATE) {
|
|
138
|
-
return callback(payload);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* @desc Sends a message to specific clients in the channel.
|
|
144
|
-
* @param event - The event to send.
|
|
145
|
-
* @param payload - The message to send.
|
|
146
|
-
* @param recipient - The clients to send the message to.
|
|
147
|
-
*/
|
|
148
|
-
sendMessage(event, payload, recipient) {
|
|
149
|
-
const requestId = (0, uuid_1.uuid)();
|
|
150
|
-
__classPrivateFieldGet(this, _Channel_instances, "m", _Channel_send).call(this, event, requestId, payload, recipient);
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* @desc Sends a message to the server and waits for a response.
|
|
154
|
-
* @param sentEvent - The event to send.
|
|
155
|
-
* @param payload - The message to send.
|
|
156
|
-
* @param responseEvent - The event to wait for.
|
|
157
|
-
*/
|
|
158
|
-
sendForResponse(sentEvent, payload, responseEvent) {
|
|
159
|
-
const requestId = (0, uuid_1.uuid)();
|
|
160
|
-
return new Promise((resolve) => {
|
|
161
|
-
const unsub = __classPrivateFieldGet(this, _Channel_instances, "m", _Channel_onMessage).call(this, (event, message, responseId) => {
|
|
162
|
-
if (event === responseEvent && requestId === responseId) {
|
|
163
|
-
resolve(message);
|
|
164
|
-
unsub();
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
__classPrivateFieldGet(this, _Channel_instances, "m", _Channel_send).call(this, sentEvent, requestId, payload);
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* @desc Broadcasts a message to every other client in the channel except yourself.
|
|
172
|
-
* @param event - The event to send.
|
|
173
|
-
* @param payload - The message to send.
|
|
174
|
-
*/
|
|
175
|
-
broadcastFrom(event, payload) {
|
|
176
|
-
const requestId = (0, uuid_1.uuid)();
|
|
177
|
-
__classPrivateFieldGet(this, _Channel_instances, "m", _Channel_send).call(this, event, requestId, payload, enums_1.ChannelReceiver.ALL_EXCEPT_SENDER);
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* @desc Broadcasts a message to the channel, including yourself.
|
|
181
|
-
* @param event - The event to send.
|
|
182
|
-
* @param payload - The message to send.
|
|
183
|
-
*/
|
|
184
|
-
broadcast(event, payload) {
|
|
185
|
-
const requestId = (0, uuid_1.uuid)();
|
|
186
|
-
__classPrivateFieldGet(this, _Channel_instances, "m", _Channel_send).call(this, event, requestId, payload);
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* @desc Gets the current presence of the channel.
|
|
190
|
-
*/
|
|
191
|
-
getPresence() {
|
|
192
|
-
return __classPrivateFieldGet(this, _Channel_presence, "f");
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* @desc Monitors the presence of the channel.
|
|
196
|
-
* @param callback - The callback to call when the presence changes.
|
|
197
|
-
*/
|
|
198
|
-
onUsersChange(callback) {
|
|
199
|
-
return __classPrivateFieldGet(this, _Channel_instances, "m", _Channel_subscribeToPresence).call(this, (_event, payload) => callback(payload.presence));
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* @desc Checks if the channel is connected.
|
|
203
|
-
*/
|
|
204
|
-
isConnected() {
|
|
205
|
-
return __classPrivateFieldGet(this, _Channel_joinState, "f").value === enums_1.ChannelState.JOINED || __classPrivateFieldGet(this, _Channel_joinState, "f").value === enums_1.ChannelState.STALLED;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* @desc Checks if the channel is stalled.
|
|
209
|
-
*/
|
|
210
|
-
isStalled() {
|
|
211
|
-
return __classPrivateFieldGet(this, _Channel_joinState, "f").value === enums_1.ChannelState.STALLED;
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* @desc Checks if the channel is closed.
|
|
215
|
-
*/
|
|
216
|
-
isClosed() {
|
|
217
|
-
return __classPrivateFieldGet(this, _Channel_joinState, "f").value === enums_1.ChannelState.CLOSED;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* @desc Monitors the connection state of the channel.
|
|
221
|
-
* @param callback - The callback to call when the connection state changes.
|
|
222
|
-
*/
|
|
223
|
-
onConnectionChange(callback) {
|
|
224
|
-
return this.onChannelStateChange((state) => {
|
|
225
|
-
callback(state === enums_1.ChannelState.JOINED || state === enums_1.ChannelState.STALLED);
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
exports.Channel = Channel;
|
|
230
|
-
_Channel_name = new WeakMap(), _Channel_queue = new WeakMap(), _Channel_presence = new WeakMap(), _Channel_publisher = new WeakMap(), _Channel_joinParams = new WeakMap(), _Channel_presenceSub = new WeakMap(), _Channel_receiver = new WeakMap(), _Channel_clientState = new WeakMap(), _Channel_joinState = new WeakMap(), _Channel_instances = new WeakSet(), _Channel_send = function _Channel_send(event, requestId, payload, receivers = enums_1.ChannelReceiver.ALL_USERS) {
|
|
231
|
-
const message = {
|
|
232
|
-
action: enums_1.ClientActions.BROADCAST,
|
|
233
|
-
channelName: __classPrivateFieldGet(this, _Channel_name, "f"),
|
|
234
|
-
addresses: receivers,
|
|
235
|
-
requestId,
|
|
236
|
-
event,
|
|
237
|
-
payload,
|
|
238
|
-
};
|
|
239
|
-
__classPrivateFieldGet(this, _Channel_instances, "m", _Channel_publish).call(this, message);
|
|
240
|
-
}, _Channel_publish = function _Channel_publish(data) {
|
|
241
|
-
if (__classPrivateFieldGet(this, _Channel_clientState, "f").value) {
|
|
242
|
-
if (__classPrivateFieldGet(this, _Channel_joinState, "f").value === enums_1.ChannelState.JOINED) {
|
|
243
|
-
__classPrivateFieldGet(this, _Channel_publisher, "f").call(this, data);
|
|
244
|
-
}
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
__classPrivateFieldGet(this, _Channel_queue, "f").push(data);
|
|
248
|
-
}, _Channel_subscribeToPresence = function _Channel_subscribeToPresence(callback) {
|
|
249
|
-
return __classPrivateFieldGet(this, _Channel_receiver, "f").subscribe((data) => {
|
|
250
|
-
if (data.action === enums_1.ServerActions.PRESENCE) {
|
|
251
|
-
return callback(data.event, data.payload);
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
}, _Channel_init = function _Channel_init(receiver) {
|
|
255
|
-
const unsubMessages = receiver.subscribe((data) => {
|
|
256
|
-
if (data.channelName === __classPrivateFieldGet(this, _Channel_name, "f")) {
|
|
257
|
-
if (data.event === enums_1.Events.ACKNOWLEDGE) {
|
|
258
|
-
__classPrivateFieldGet(this, _Channel_joinState, "f").publish(enums_1.ChannelState.JOINED);
|
|
259
|
-
__classPrivateFieldGet(this, _Channel_instances, "m", _Channel_emptyQueue).call(this);
|
|
260
|
-
}
|
|
261
|
-
else {
|
|
262
|
-
__classPrivateFieldGet(this, _Channel_receiver, "f").publish(data);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
const unsubStateChange = __classPrivateFieldGet(this, _Channel_clientState, "f").subscribe((state) => {
|
|
267
|
-
if (state && __classPrivateFieldGet(this, _Channel_joinState, "f").value === enums_1.ChannelState.STALLED) {
|
|
268
|
-
const joinMessage = __classPrivateFieldGet(this, _Channel_instances, "m", _Channel_buildJoinMessage).call(this);
|
|
269
|
-
__classPrivateFieldGet(this, _Channel_publisher, "f").call(this, joinMessage);
|
|
270
|
-
}
|
|
271
|
-
else if (!state && __classPrivateFieldGet(this, _Channel_joinState, "f").value === enums_1.ChannelState.JOINED) {
|
|
272
|
-
__classPrivateFieldGet(this, _Channel_joinState, "f").publish(enums_1.ChannelState.STALLED);
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
const unsubPresence = __classPrivateFieldGet(this, _Channel_instances, "m", _Channel_subscribeToPresence).call(this, (_, payload) => {
|
|
276
|
-
__classPrivateFieldSet(this, _Channel_presence, payload.presence, "f");
|
|
277
|
-
});
|
|
278
|
-
return () => {
|
|
279
|
-
unsubMessages();
|
|
280
|
-
unsubStateChange();
|
|
281
|
-
unsubPresence();
|
|
282
|
-
};
|
|
283
|
-
}, _Channel_emptyQueue = function _Channel_emptyQueue() {
|
|
284
|
-
__classPrivateFieldGet(this, _Channel_queue, "f")
|
|
285
|
-
.filter((message) => message.action !== enums_1.ClientActions.JOIN_CHANNEL)
|
|
286
|
-
.forEach((message) => {
|
|
287
|
-
__classPrivateFieldGet(this, _Channel_publisher, "f").call(this, message);
|
|
288
|
-
});
|
|
289
|
-
__classPrivateFieldSet(this, _Channel_queue, [], "f");
|
|
290
|
-
}, _Channel_buildJoinMessage = function _Channel_buildJoinMessage() {
|
|
291
|
-
return {
|
|
292
|
-
addresses: enums_1.ChannelReceiver.ALL_USERS,
|
|
293
|
-
action: enums_1.ClientActions.JOIN_CHANNEL,
|
|
294
|
-
event: enums_1.ClientActions.JOIN_CHANNEL,
|
|
295
|
-
payload: __classPrivateFieldGet(this, _Channel_joinParams, "f"),
|
|
296
|
-
channelName: __classPrivateFieldGet(this, _Channel_name, "f"),
|
|
297
|
-
requestId: (0, uuid_1.uuid)(),
|
|
298
|
-
};
|
|
299
|
-
}, _Channel_onMessage = function _Channel_onMessage(callback) {
|
|
300
|
-
return __classPrivateFieldGet(this, _Channel_receiver, "f").subscribe((data) => {
|
|
301
|
-
if (data.action !== enums_1.ServerActions.PRESENCE) {
|
|
302
|
-
return callback(data.event, data.payload, data.requestId);
|
|
303
|
-
}
|
|
304
|
-
});
|
|
305
|
-
};
|
package/client.d.ts
DELETED
package/client.js
DELETED
|
@@ -1,107 +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 _PondClient_instances, _PondClient_channels, _PondClient_createPublisher;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.ChannelState = void 0;
|
|
16
|
-
const channel_1 = require("./client/channel");
|
|
17
|
-
const enums_1 = require("./enums");
|
|
18
|
-
Object.defineProperty(exports, "ChannelState", { enumerable: true, get: function () { return enums_1.ChannelState; } });
|
|
19
|
-
const subject_1 = require("./subjects/subject");
|
|
20
|
-
class PondClient {
|
|
21
|
-
constructor(endpoint, params = {}) {
|
|
22
|
-
_PondClient_instances.add(this);
|
|
23
|
-
_PondClient_channels.set(this, void 0);
|
|
24
|
-
let address;
|
|
25
|
-
try {
|
|
26
|
-
address = new URL(endpoint);
|
|
27
|
-
}
|
|
28
|
-
catch (e) {
|
|
29
|
-
address = new URL(window.location.toString());
|
|
30
|
-
address.pathname = endpoint;
|
|
31
|
-
}
|
|
32
|
-
const query = new URLSearchParams(params);
|
|
33
|
-
address.search = query.toString();
|
|
34
|
-
const protocol = address.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
35
|
-
if (address.protocol !== 'wss:' && address.protocol !== 'ws:') {
|
|
36
|
-
address.protocol = protocol;
|
|
37
|
-
}
|
|
38
|
-
this._address = address;
|
|
39
|
-
__classPrivateFieldSet(this, _PondClient_channels, {}, "f");
|
|
40
|
-
this._broadcaster = new subject_1.SimpleSubject();
|
|
41
|
-
this._connectionState = new subject_1.SimpleBehaviorSubject(false);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* @desc Connects to the server and returns the socket.
|
|
45
|
-
*/
|
|
46
|
-
connect(backoff = 1) {
|
|
47
|
-
const socket = new WebSocket(this._address.toString());
|
|
48
|
-
socket.onopen = () => {
|
|
49
|
-
this._connectionState.publish(true);
|
|
50
|
-
};
|
|
51
|
-
socket.onmessage = (message) => {
|
|
52
|
-
const data = JSON.parse(message.data);
|
|
53
|
-
this._broadcaster.publish(data);
|
|
54
|
-
};
|
|
55
|
-
socket.onerror = () => {
|
|
56
|
-
this._connectionState.publish(false);
|
|
57
|
-
setTimeout(() => {
|
|
58
|
-
this.connect(backoff * 2);
|
|
59
|
-
}, backoff * 1000);
|
|
60
|
-
};
|
|
61
|
-
this._socket = socket;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* @desc Returns the current state of the socket.
|
|
65
|
-
*/
|
|
66
|
-
getState() {
|
|
67
|
-
return this._connectionState.value;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* @desc Disconnects the socket.
|
|
71
|
-
*/
|
|
72
|
-
disconnect() {
|
|
73
|
-
var _a;
|
|
74
|
-
Object.values(__classPrivateFieldGet(this, _PondClient_channels, "f")).forEach((channel) => channel.leave());
|
|
75
|
-
(_a = this._socket) === null || _a === void 0 ? void 0 : _a.close();
|
|
76
|
-
__classPrivateFieldSet(this, _PondClient_channels, {}, "f");
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* @desc Creates a channel with the given name and params.
|
|
80
|
-
* @param name - The name of the channel.
|
|
81
|
-
* @param params - The params to send to the server.
|
|
82
|
-
*/
|
|
83
|
-
createChannel(name, params) {
|
|
84
|
-
if (__classPrivateFieldGet(this, _PondClient_channels, "f")[name] && __classPrivateFieldGet(this, _PondClient_channels, "f")[name].channelState !== enums_1.ChannelState.CLOSED) {
|
|
85
|
-
return __classPrivateFieldGet(this, _PondClient_channels, "f")[name];
|
|
86
|
-
}
|
|
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 || {});
|
|
89
|
-
__classPrivateFieldGet(this, _PondClient_channels, "f")[name] = channel;
|
|
90
|
-
return channel;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* @desc Subscribes to the connection state.
|
|
94
|
-
* @param callback - The callback to call when the state changes.
|
|
95
|
-
*/
|
|
96
|
-
onConnectionChange(callback) {
|
|
97
|
-
return this._connectionState.subscribe(callback);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
_PondClient_channels = new WeakMap(), _PondClient_instances = new WeakSet(), _PondClient_createPublisher = function _PondClient_createPublisher() {
|
|
101
|
-
return (message) => {
|
|
102
|
-
if (this._connectionState.value) {
|
|
103
|
-
this._socket.send(JSON.stringify(message));
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
exports.default = PondClient;
|
package/enums.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Events = exports.ChannelReceiver = exports.SystemSender = exports.ErrorTypes = exports.ChannelState = exports.ClientActions = exports.ServerActions = exports.PresenceEventTypes = void 0;
|
|
4
|
-
var PresenceEventTypes;
|
|
5
|
-
(function (PresenceEventTypes) {
|
|
6
|
-
PresenceEventTypes["JOIN"] = "JOIN";
|
|
7
|
-
PresenceEventTypes["LEAVE"] = "LEAVE";
|
|
8
|
-
PresenceEventTypes["UPDATE"] = "UPDATE";
|
|
9
|
-
})(PresenceEventTypes || (exports.PresenceEventTypes = PresenceEventTypes = {}));
|
|
10
|
-
var ServerActions;
|
|
11
|
-
(function (ServerActions) {
|
|
12
|
-
ServerActions["PRESENCE"] = "PRESENCE";
|
|
13
|
-
ServerActions["SYSTEM"] = "SYSTEM";
|
|
14
|
-
ServerActions["BROADCAST"] = "BROADCAST";
|
|
15
|
-
ServerActions["ERROR"] = "ERROR";
|
|
16
|
-
})(ServerActions || (exports.ServerActions = ServerActions = {}));
|
|
17
|
-
var ClientActions;
|
|
18
|
-
(function (ClientActions) {
|
|
19
|
-
ClientActions["JOIN_CHANNEL"] = "JOIN_CHANNEL";
|
|
20
|
-
ClientActions["LEAVE_CHANNEL"] = "LEAVE_CHANNEL";
|
|
21
|
-
ClientActions["BROADCAST"] = "BROADCAST";
|
|
22
|
-
})(ClientActions || (exports.ClientActions = ClientActions = {}));
|
|
23
|
-
var ChannelState;
|
|
24
|
-
(function (ChannelState) {
|
|
25
|
-
ChannelState["IDLE"] = "IDLE";
|
|
26
|
-
ChannelState["JOINING"] = "JOINING";
|
|
27
|
-
ChannelState["JOINED"] = "JOINED";
|
|
28
|
-
ChannelState["STALLED"] = "STALLED";
|
|
29
|
-
ChannelState["CLOSED"] = "CLOSED";
|
|
30
|
-
})(ChannelState || (exports.ChannelState = ChannelState = {}));
|
|
31
|
-
var ErrorTypes;
|
|
32
|
-
(function (ErrorTypes) {
|
|
33
|
-
ErrorTypes["UNAUTHORIZED_CONNECTION"] = "UNAUTHORIZED_CONNECTION";
|
|
34
|
-
ErrorTypes["UNAUTHORIZED_JOIN_REQUEST"] = "UNAUTHORIZED_JOIN_REQUEST";
|
|
35
|
-
ErrorTypes["UNAUTHORIZED_BROADCAST"] = "UNAUTHORIZED_BROADCAST";
|
|
36
|
-
ErrorTypes["INVALID_MESSAGE"] = "INVALID_MESSAGE";
|
|
37
|
-
ErrorTypes["HANDLER_NOT_FOUND"] = "HANDLER_NOT_FOUND";
|
|
38
|
-
ErrorTypes["PRESENCE_ERROR"] = "PRESENCE_ERROR";
|
|
39
|
-
ErrorTypes["CHANNEL_ERROR"] = "CHANNEL_ERROR";
|
|
40
|
-
ErrorTypes["ENDPOINT_ERROR"] = "ENDPOINT_ERROR";
|
|
41
|
-
ErrorTypes["INTERNAL_SERVER_ERROR"] = "INTERNAL_SERVER_ERROR";
|
|
42
|
-
})(ErrorTypes || (exports.ErrorTypes = ErrorTypes = {}));
|
|
43
|
-
var SystemSender;
|
|
44
|
-
(function (SystemSender) {
|
|
45
|
-
SystemSender["ENDPOINT"] = "ENDPOINT";
|
|
46
|
-
SystemSender["CHANNEL"] = "CHANNEL";
|
|
47
|
-
})(SystemSender || (exports.SystemSender = SystemSender = {}));
|
|
48
|
-
var ChannelReceiver;
|
|
49
|
-
(function (ChannelReceiver) {
|
|
50
|
-
ChannelReceiver["ALL_USERS"] = "ALL_USERS";
|
|
51
|
-
ChannelReceiver["ALL_EXCEPT_SENDER"] = "ALL_EXCEPT_SENDER";
|
|
52
|
-
})(ChannelReceiver || (exports.ChannelReceiver = ChannelReceiver = {}));
|
|
53
|
-
var Events;
|
|
54
|
-
(function (Events) {
|
|
55
|
-
Events["ACKNOWLEDGE"] = "ACKNOWLEDGE";
|
|
56
|
-
})(Events || (exports.Events = Events = {}));
|
package/express.d.ts
DELETED
package/express.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const http_1 = require("http");
|
|
4
|
-
const pondSocket_1 = require("./server/pondSocket");
|
|
5
|
-
/**
|
|
6
|
-
* @desc Creates a pond socket server
|
|
7
|
-
* @param app - The Express app to be used by the server
|
|
8
|
-
* @constructor
|
|
9
|
-
*/
|
|
10
|
-
const pondSocket = (app) => {
|
|
11
|
-
const server = (0, http_1.createServer)(app);
|
|
12
|
-
const pondSocket = new pondSocket_1.PondSocket(server);
|
|
13
|
-
app.upgrade = (path, handler) => pondSocket.createEndpoint(path, handler);
|
|
14
|
-
app.listen = (...args) => pondSocket.listen(...args);
|
|
15
|
-
return app;
|
|
16
|
-
};
|
|
17
|
-
exports.default = pondSocket;
|
package/misc/uuid.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uuid = void 0;
|
|
4
|
-
function uuid() {
|
|
5
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
|
|
6
|
-
.replace(/[xy]/g, (c) => {
|
|
7
|
-
const r = Math.random() * 16 | 0;
|
|
8
|
-
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
9
|
-
return v.toString(16);
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
exports.uuid = uuid;
|
package/nest.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
GetChannel,
|
|
3
|
-
OnJoinRequest,
|
|
4
|
-
ChannelInstance,
|
|
5
|
-
EndpointInstance,
|
|
6
|
-
DChannel as Channel,
|
|
7
|
-
OnConnectionRequest,
|
|
8
|
-
DEndpoint as Endpoint,
|
|
9
|
-
OnEvent, PondSocketModule,
|
|
10
|
-
GetLeaveEvent, OnLeaveEvent,
|
|
11
|
-
GetEventParams, GetEventQuery,
|
|
12
|
-
GetEventRequest, GetEventResponse,
|
|
13
|
-
GetJoinResponse, GetConnectionParams,
|
|
14
|
-
GetConnectionQuery, GetConnectionHeaders,
|
|
15
|
-
GetConnectionRequest, GetConnectionResponse,
|
|
16
|
-
GetUserData, GetUserPresences, GetInternalChannel,
|
|
17
|
-
GetConnectionRequestId, GetEventPayload, PondGuards,
|
|
18
|
-
GetJoinParams, GetJoinRequest, createParamDecorator,
|
|
19
|
-
} from './types';
|