playsocketjs 3.1.0 → 3.1.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/dist/playsocket-client.js +10 -10
- package/dist/playsocket-server.js +1 -1
- package/package.json +1 -1
|
@@ -2180,7 +2180,7 @@ class PlaySocket {
|
|
|
2180
2180
|
*/
|
|
2181
2181
|
#createTimeout(name) {
|
|
2182
2182
|
return new Promise((_, reject) =>
|
|
2183
|
-
setTimeout(() => reject(new Error(`${name} timed out
|
|
2183
|
+
setTimeout(() => reject(new Error(`${name} timed out.`)), TIMEOUT_MS)
|
|
2184
2184
|
);
|
|
2185
2185
|
}
|
|
2186
2186
|
|
|
@@ -2220,8 +2220,8 @@ class PlaySocket {
|
|
|
2220
2220
|
* @returns {Promise} Resolves when connection is established
|
|
2221
2221
|
*/
|
|
2222
2222
|
async init() {
|
|
2223
|
-
if (this.#initialized) return Promise.reject(new Error("Already initialized"));
|
|
2224
|
-
if (!this.#endpoint) return Promise.reject(new Error("No websocket endpoint provided"));
|
|
2223
|
+
if (this.#initialized) return Promise.reject(new Error("Already initialized!"));
|
|
2224
|
+
if (!this.#endpoint) return Promise.reject(new Error("No websocket endpoint provided!"));
|
|
2225
2225
|
this.#triggerEvent("status", "Initializing...");
|
|
2226
2226
|
|
|
2227
2227
|
// Connect to WS server
|
|
@@ -2400,7 +2400,7 @@ class PlaySocket {
|
|
|
2400
2400
|
// Handle socket errors
|
|
2401
2401
|
this.#socket.onerror = () => {
|
|
2402
2402
|
this.#triggerEvent("error", "WebSocket error.");
|
|
2403
|
-
if (this.#pendingConnect) this.#pendingConnect.reject(new Error("WebSocket error"));
|
|
2403
|
+
if (this.#pendingConnect) this.#pendingConnect.reject(new Error("WebSocket error!"));
|
|
2404
2404
|
};
|
|
2405
2405
|
|
|
2406
2406
|
// Handle socket close & attempt reconnect
|
|
@@ -2467,7 +2467,7 @@ class PlaySocket {
|
|
|
2467
2467
|
*/
|
|
2468
2468
|
#sendToServer(data) {
|
|
2469
2469
|
if (!this.#socket || this.#socket?.readyState !== WebSocket.OPEN) {
|
|
2470
|
-
console.warn(WARNING_PREFIX + "
|
|
2470
|
+
console.warn(WARNING_PREFIX + "Failed to send message - not connected.");
|
|
2471
2471
|
return;
|
|
2472
2472
|
}
|
|
2473
2473
|
try {
|
|
@@ -2486,8 +2486,8 @@ class PlaySocket {
|
|
|
2486
2486
|
*/
|
|
2487
2487
|
async createRoom(initialStorage = {}, size) {
|
|
2488
2488
|
if (!this.#initialized) {
|
|
2489
|
-
this.#triggerEvent("error", "
|
|
2490
|
-
return Promise.reject(new Error("Not initialized"));
|
|
2489
|
+
this.#triggerEvent("error", "Failed to create room - not initialized");
|
|
2490
|
+
return Promise.reject(new Error("Not initialized!"));
|
|
2491
2491
|
}
|
|
2492
2492
|
|
|
2493
2493
|
return Promise.race([
|
|
@@ -2513,8 +2513,8 @@ class PlaySocket {
|
|
|
2513
2513
|
*/
|
|
2514
2514
|
async joinRoom(roomId) {
|
|
2515
2515
|
if (!this.#initialized) {
|
|
2516
|
-
this.#triggerEvent("error", "
|
|
2517
|
-
return Promise.reject(new Error("Not initialized"));
|
|
2516
|
+
this.#triggerEvent("error", "Failed to join room - not initialized");
|
|
2517
|
+
return Promise.reject(new Error("Not initialized!"));
|
|
2518
2518
|
}
|
|
2519
2519
|
|
|
2520
2520
|
return Promise.race([
|
|
@@ -2543,7 +2543,7 @@ class PlaySocket {
|
|
|
2543
2543
|
*/
|
|
2544
2544
|
updateStorage(key, type, value, updateValue) {
|
|
2545
2545
|
if (!this.#inRoom) {
|
|
2546
|
-
this.#triggerEvent("error", "
|
|
2546
|
+
this.#triggerEvent("error", "Failed to update storage - not in a room.");
|
|
2547
2547
|
return;
|
|
2548
2548
|
} if (this.#debug) console.log(LOG_PREFIX + `Property update for key ${key}, operation ${type}, value ${value} and updateValue ${updateValue}.`);
|
|
2549
2549
|
const propUpdate = this.#crdtManager.updateProperty(key, type, value, updateValue);
|
|
@@ -2334,7 +2334,7 @@ class PlaySocketServer {
|
|
|
2334
2334
|
|
|
2335
2335
|
const newRoom = this.createRoom(data.initialStorage, data.size, ws.clientId); // Create room
|
|
2336
2336
|
|
|
2337
|
-
// Check if client/creator is still connected
|
|
2337
|
+
// Check if client/creator is still connected and abort if not
|
|
2338
2338
|
if (!this.#clients.has(ws.clientId)) {
|
|
2339
2339
|
this.destroyRoom(newRoom.id);
|
|
2340
2340
|
if (this.#debug) console.log(`Room creation cancelled - client ${ws.clientId} disconnected during event callback.`);
|