playsocketjs 4.1.1 → 4.2.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playsocketjs",
3
- "version": "4.1.1",
3
+ "version": "4.2.1",
4
4
  "description": "WebSocket wrapper for creating simple multiplayer systems with ease.",
5
5
  "type": "module",
6
6
  "module": "./src/client/client.js",
@@ -1,5 +1,6 @@
1
1
  import { encode, decode } from "@msgpack/msgpack";
2
2
  import CRDTManager from "../universal/crdtManager.js";
3
+ import { VERSION } from "../universal/constants.js";
3
4
 
4
5
  const ERROR_PREFIX = "PlaySocket error: ";
5
6
  const WARNING_PREFIX = "PlaySocket warning: ";
@@ -160,6 +161,7 @@ export default class PlaySocket {
160
161
  this.#sendToServer({
161
162
  type: "register",
162
163
  id: this.#id,
164
+ version: VERSION,
163
165
  customData: this.#customData || undefined
164
166
  });
165
167
  }),
@@ -2,7 +2,7 @@ import { WebSocketServer } from "ws";
2
2
  import { createServer } from "node:http";
3
3
  import { encode, decode } from "@msgpack/msgpack";
4
4
  import CRDTManager, { getUpdateDetails } from "../universal/crdtManager.js";
5
- import { HEARTBEAT_INTERVAL } from "../universal/constants.js";
5
+ import { HEARTBEAT_INTERVAL, VERSION } from "../universal/constants.js";
6
6
 
7
7
  const MAX_ROOM_SIZE = 500;
8
8
  export const RECONNECT_GRACE_PERIOD = 5000; // Exported for use in tests
@@ -145,6 +145,12 @@ export default class PlaySocketServer {
145
145
 
146
146
  switch (data.type) {
147
147
  case "register": {
148
+ // Ensure client uses the same version as server
149
+ if (data.version !== VERSION) {
150
+ ws.send(encode({ type: "registration_failed", reason: `Version mismatch (client ${data.version ? "v" + data.version : "legacy"}, server v${VERSION}). Please reload the page, an update may have been released.` }), { binary: true });
151
+ return;
152
+ }
153
+
148
154
  // Register client ID if provided & check for a duplicate
149
155
  if (data.id && (this.#clients.get(data.id) || data.id === "server")) {
150
156
  ws.send(encode({ type: "registration_failed", reason: "ID is taken." }), { binary: true });
@@ -5,3 +5,8 @@
5
5
  * be desynced as a result of gc
6
6
  */
7
7
  export const HEARTBEAT_INTERVAL = 5000;
8
+
9
+ /**
10
+ * Library version, must match package.json
11
+ */
12
+ export const VERSION = "4.2.1";
@@ -5,3 +5,7 @@
5
5
  * be desynced as a result of gc
6
6
  */
7
7
  export declare const HEARTBEAT_INTERVAL = 5000;
8
+ /**
9
+ * Library version, must match package.json
10
+ */
11
+ export declare const VERSION = "4.2.1";