@genex-ai/multiplayer 0.8.5 → 0.8.7

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.
Files changed (2) hide show
  1. package/dist/index.js +18 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -189,6 +189,7 @@ function attachSession(client, initialRoom) {
189
189
  const objOwners = /* @__PURE__ */ new Map();
190
190
  const objRaw = /* @__PURE__ */ new Map();
191
191
  const localObjState = /* @__PURE__ */ new Map();
192
+ const pendingBridge = /* @__PURE__ */ new Map();
192
193
  let hostId;
193
194
  const testSkew = typeof globalThis !== "undefined" && globalThis.__GENEX_MP_TEST_SKEW__ || 0;
194
195
  const now = testSkew ? () => nowMs() + testSkew : nowMs;
@@ -223,6 +224,12 @@ function attachSession(client, initialRoom) {
223
224
  }
224
225
  let buf = buffers.get(id);
225
226
  if (!buf) buffers.set(id, buf = []);
227
+ const bridge = pendingBridge.get(id);
228
+ if (bridge && buf.length === 0 && sendTime != null) {
229
+ const delay = autoDelayById.get(id) ?? INTERP_MIN_MS;
230
+ buf.push({ t: t - Math.max(1, delay), state: bridge });
231
+ }
232
+ pendingBridge.delete(id);
226
233
  buf.push({ t, state });
227
234
  const cutoff = t - 1500;
228
235
  while (buf.length > 2 && buf[0].t < cutoff) buf.shift();
@@ -255,6 +262,7 @@ function attachSession(client, initialRoom) {
255
262
  smoothedAt.delete(streamKey);
256
263
  intervalsById.delete(streamKey);
257
264
  autoDelayById.delete(streamKey);
265
+ pendingBridge.delete(streamKey);
258
266
  };
259
267
  const clearStreamClock = (streamKey) => {
260
268
  buffers.delete(streamKey);
@@ -311,7 +319,13 @@ function attachSession(client, initialRoom) {
311
319
  }
312
320
  if (blob.d && typeof blob.d === "object" && Object.keys(blob.d).length > 0) {
313
321
  objRaw.set(id, blob.d);
314
- if (owner !== room.sessionId) pushSnap(key, blob.d, blob.t);
322
+ if (owner !== room.sessionId) {
323
+ if (ownerChanged) {
324
+ pendingBridge.set(key, smoothed.get(key) ?? blob.d);
325
+ } else {
326
+ pushSnap(key, blob.d, blob.t);
327
+ }
328
+ }
315
329
  }
316
330
  if (ownerChanged) emit("object", id);
317
331
  return;
@@ -493,6 +507,7 @@ function attachSession(client, initialRoom) {
493
507
  const key = String(id);
494
508
  localObjState.delete(key);
495
509
  if (objOwners.get(key) === room.sessionId) objOwners.delete(key);
510
+ clearStreamClock(OBJ_PREFIX + key);
496
511
  send0("release", { id: key });
497
512
  },
498
513
  remove(id) {
@@ -522,6 +537,8 @@ function attachSession(client, initialRoom) {
522
537
  if (isMine && mine) {
523
538
  state = mine;
524
539
  raw = mine;
540
+ smoothed.set(OBJ_PREFIX + key, mine);
541
+ smoothedAt.set(OBJ_PREFIX + key, now());
525
542
  } else {
526
543
  raw = objRaw.get(key) ?? {};
527
544
  state = sampleSmoothed(OBJ_PREFIX + key, now()) ?? raw;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genex-ai/multiplayer",
3
- "version": "0.8.5",
3
+ "version": "0.8.7",
4
4
  "description": "The multiplayer client wrapper + shared room schema for genex.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",