restream-sdk 0.4.0 → 0.4.2

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/package.json +1 -1
  2. package/src/core.js +8 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "restream-sdk",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Plug-and-play headless React hooks to add multi-platform restreaming (connect socials, go live, live chat + viewers, collaborative split-screen) with zero client backend.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/core.js CHANGED
@@ -427,11 +427,14 @@ export class RestreamStudio extends EventTarget {
427
427
  this._emit("job", job);
428
428
  if (job?.id) this.startRealtime(job.id);
429
429
  // Push the initial presence/layout state (explicit `layout`, or whatever was set via
430
- // setStreamState() before we had a job id). Best-effort never block go-live on it.
430
+ // setStreamState() before we had a job id). setStreamState is synchronous (returns the
431
+ // merged state, not a Promise) and its network send is debounced + self-handles errors,
432
+ // so DON'T await/.catch it — doing so threw and made goLive reject after the job had
433
+ // already started. Wrapped defensively so a flush error can never reject go-live.
431
434
  const initialState = { ...(this._pendingState || {}), ...(layout || {}) };
432
435
  if (job?.id && Object.keys(initialState).length) {
433
436
  this._pendingState = null;
434
- this.setStreamState(initialState).catch(() => {});
437
+ try { this.setStreamState(initialState); } catch (e) { this._emit("error", e); }
435
438
  }
436
439
  return job;
437
440
  }
@@ -489,7 +492,9 @@ export class RestreamStudio extends EventTarget {
489
492
  if (this._stateTimer) clearTimeout(this._stateTimer);
490
493
  this._stateTimer = setTimeout(() => {
491
494
  this._stateTimer = null;
492
- this._req("POST", `/api/v1/jobs/${jobId}/state`, this._streamState).catch((e) => this._emit("error", e));
495
+ // _withUser adds clientUserId (pk mode) so the server can attribute this update to the
496
+ // right half of a collab composite (host vs guest); no-op in token mode.
497
+ this._req("POST", `/api/v1/jobs/${jobId}/state`, this._withUser(this._streamState)).catch((e) => this._emit("error", e));
493
498
  }, 150);
494
499
  return this._streamState;
495
500
  }