playsocketjs 5.3.0 → 5.3.1
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/package.json
CHANGED
package/src/server/server.js
CHANGED
|
@@ -213,9 +213,11 @@ export default class PlaySocketServer {
|
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
case "reconnect": {
|
|
216
|
-
// If user is pending disconnect, respond (otherwise it's too late)
|
|
217
|
-
const
|
|
218
|
-
|
|
216
|
+
// If user is pending disconnect or still on a dropped connection, respond (otherwise it's too late)
|
|
217
|
+
const pendingDisconnect = this.#pendingDisconnects.get(data.id);
|
|
218
|
+
const staleSocket = this.#clients.get(data.id); // Client requests reconnect even though the server thinks they are still connected
|
|
219
|
+
|
|
220
|
+
if ((pendingDisconnect || staleSocket) && data.sessionToken) {
|
|
219
221
|
if (data.sessionToken !== this.#clientTokens.get(data.id)) {
|
|
220
222
|
ws.send(encode({
|
|
221
223
|
type: "reconnection_failed",
|
|
@@ -223,9 +225,15 @@ export default class PlaySocketServer {
|
|
|
223
225
|
}), { binary: true });
|
|
224
226
|
return;
|
|
225
227
|
}
|
|
226
|
-
clearTimeout(
|
|
228
|
+
clearTimeout(pendingDisconnect?.timeout);
|
|
227
229
|
this.#pendingDisconnects.delete(data.id);
|
|
228
230
|
|
|
231
|
+
// Only terminate if it's a different connection sending the reconnect
|
|
232
|
+
if (staleSocket && staleSocket !== ws) {
|
|
233
|
+
staleSocket.clientId = null; // So the close skips disconnection (handleDisconnection exits if the client ID is falsy)
|
|
234
|
+
staleSocket.terminate();
|
|
235
|
+
}
|
|
236
|
+
|
|
229
237
|
// Re-assign old client ID to the new ws connection
|
|
230
238
|
ws.clientId = data.id;
|
|
231
239
|
this.#clients.set(data.id, ws);
|
|
@@ -416,9 +424,7 @@ export default class PlaySocketServer {
|
|
|
416
424
|
* @returns {string} Token
|
|
417
425
|
*/
|
|
418
426
|
#generateSessionToken() {
|
|
419
|
-
|
|
420
|
-
for (let i = 0; i < 16; i++) token += Math.floor(Math.random() * 16).toString(16);
|
|
421
|
-
return token;
|
|
427
|
+
return crypto.randomUUID();
|
|
422
428
|
}
|
|
423
429
|
|
|
424
430
|
/**
|