@dialtribe/react-sdk 0.1.0-alpha.12 → 0.1.0-alpha.15

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.
@@ -310,7 +310,10 @@ var WebSocketStreamer = class {
310
310
  this.websocket = null;
311
311
  this.mediaRecorder = null;
312
312
  this.bytesSent = 0;
313
+ this.chunksSent = 0;
313
314
  this.userStopped = false;
315
+ // Track if user initiated the stop
316
+ this.startTime = 0;
314
317
  this.streamKey = options.streamKey;
315
318
  this.mediaStream = options.mediaStream;
316
319
  this.isVideo = options.isVideo;
@@ -401,10 +404,12 @@ Please check encoder server logs and DATABASE_URL configuration.`
401
404
  console.log("\u2705 WebSocket connected");
402
405
  this.setupWebSocketHandlers();
403
406
  const recorderOptions = getMediaRecorderOptions(this.isVideo);
407
+ this.mimeType = recorderOptions.mimeType;
404
408
  this.mediaRecorder = new MediaRecorder(this.mediaStream, recorderOptions);
405
409
  console.log("\u{1F399}\uFE0F MediaRecorder created with options:", recorderOptions);
406
410
  this.setupMediaRecorderHandlers();
407
411
  this.mediaRecorder.start(300);
412
+ this.startTime = Date.now();
408
413
  console.log("\u{1F534} Recording started");
409
414
  this.onStateChange?.("live");
410
415
  } catch (error) {
@@ -449,6 +454,19 @@ Please check encoder server logs and DATABASE_URL configuration.`
449
454
  getBytesSent() {
450
455
  return this.bytesSent;
451
456
  }
457
+ /**
458
+ * Get current diagnostics
459
+ */
460
+ getDiagnostics(closeCode, closeReason) {
461
+ return {
462
+ mimeType: this.mimeType,
463
+ chunksSent: this.chunksSent,
464
+ bytesSent: this.bytesSent,
465
+ elapsedMs: this.startTime ? Date.now() - this.startTime : 0,
466
+ closeCode,
467
+ closeReason
468
+ };
469
+ }
452
470
  /**
453
471
  * Update the media stream (e.g., when flipping camera)
454
472
  * This keeps the WebSocket connection alive while swapping the media source
@@ -478,9 +496,22 @@ Please check encoder server logs and DATABASE_URL configuration.`
478
496
  this.websocket.addEventListener("close", (event) => {
479
497
  console.log("\u{1F50C} WebSocket closed", { code: event.code, reason: event.reason });
480
498
  if (!this.userStopped) {
481
- console.warn("\u26A0\uFE0F Stream was terminated remotely (not user-initiated)");
499
+ const diagnostics = this.getDiagnostics(event.code, event.reason);
500
+ console.warn("\u26A0\uFE0F Stream ended unexpectedly", diagnostics);
501
+ let errorMessage;
502
+ if (event.code === 1e3) {
503
+ errorMessage = event.reason || "Stream ended by server";
504
+ } else if (event.code === 1001) {
505
+ errorMessage = "Connection closed - server going away";
506
+ } else if (event.code === 1006) {
507
+ errorMessage = "Connection lost unexpectedly";
508
+ } else if (event.code >= 4e3 && event.code < 5e3) {
509
+ errorMessage = event.reason || "Stream terminated by server";
510
+ } else {
511
+ errorMessage = `Connection closed (code: ${event.code})`;
512
+ }
482
513
  this.onStateChange?.("terminated");
483
- this.onError?.("Your stream was terminated by an administrator");
514
+ this.onError?.(errorMessage, diagnostics);
484
515
  }
485
516
  if (this.mediaRecorder && this.mediaRecorder.state !== "inactive") {
486
517
  this.mediaRecorder.stop();
@@ -501,8 +532,9 @@ Please check encoder server logs and DATABASE_URL configuration.`
501
532
  if (event.data.size > 0 && this.websocket?.readyState === WebSocket.OPEN) {
502
533
  this.websocket.send(event.data);
503
534
  this.bytesSent += event.data.size;
535
+ this.chunksSent += 1;
504
536
  this.onBytesUpdate?.(this.bytesSent);
505
- console.log(`\u{1F4E4} Sent ${(event.data.size / 1024).toFixed(2)} KB (Total: ${(this.bytesSent / 1024 / 1024).toFixed(2)} MB)`);
537
+ console.log(`\u{1F4E4} Sent chunk #${this.chunksSent}: ${(event.data.size / 1024).toFixed(2)} KB (Total: ${(this.bytesSent / 1024 / 1024).toFixed(2)} MB)`);
506
538
  }
507
539
  });
508
540
  this.mediaRecorder.addEventListener("error", (event) => {
@@ -1499,6 +1531,7 @@ function DialtribeStreamer({
1499
1531
  }
1500
1532
  }, [initialStreamKey]);
1501
1533
  const [error, setError] = useState(null);
1534
+ const [diagnostics, setDiagnostics] = useState(null);
1502
1535
  const [mediaStream, setMediaStream] = useState(null);
1503
1536
  const [streamer, setStreamer] = useState(null);
1504
1537
  const [bytesSent, setBytesSent] = useState(0);
@@ -1695,9 +1728,11 @@ function DialtribeStreamer({
1695
1728
  setState("error");
1696
1729
  }
1697
1730
  },
1698
- onError: (errorMsg) => {
1731
+ onError: (errorMsg, diag) => {
1699
1732
  setError(errorMsg);
1700
- setState("error");
1733
+ if (diag) {
1734
+ setDiagnostics(diag);
1735
+ }
1701
1736
  }
1702
1737
  });
1703
1738
  await newStreamer.start();
@@ -1982,13 +2017,37 @@ function DialtribeStreamer({
1982
2017
  )
1983
2018
  }
1984
2019
  ) }),
1985
- /* @__PURE__ */ jsx("h2", { className: "text-xl font-bold text-black dark:text-white mb-2", children: "Stream Terminated" }),
1986
- /* @__PURE__ */ jsx("p", { className: "text-gray-600 dark:text-gray-400 mb-2", children: error || "Your broadcast was terminated by an administrator." }),
1987
- /* @__PURE__ */ jsxs("p", { className: "text-sm text-gray-500 dark:text-gray-400 mb-6", children: [
2020
+ /* @__PURE__ */ jsx("h2", { className: "text-xl font-bold text-black dark:text-white mb-2", children: "Stream Ended" }),
2021
+ /* @__PURE__ */ jsx("p", { className: "text-gray-600 dark:text-gray-400 mb-2", children: error || "Connection closed unexpectedly" }),
2022
+ /* @__PURE__ */ jsxs("p", { className: "text-sm text-gray-500 dark:text-gray-400 mb-2", children: [
1988
2023
  "Total sent: ",
1989
2024
  (bytesSent / 1024 / 1024).toFixed(2),
1990
2025
  " MB"
1991
2026
  ] }),
2027
+ diagnostics && /* @__PURE__ */ jsxs("div", { className: "text-xs text-gray-400 dark:text-gray-500 mb-6 font-mono bg-gray-100 dark:bg-zinc-800 rounded p-2 text-left", children: [
2028
+ /* @__PURE__ */ jsxs("div", { children: [
2029
+ "Codec: ",
2030
+ diagnostics.mimeType || "unknown"
2031
+ ] }),
2032
+ /* @__PURE__ */ jsxs("div", { children: [
2033
+ "Chunks: ",
2034
+ diagnostics.chunksSent,
2035
+ " (",
2036
+ (diagnostics.bytesSent / 1024).toFixed(1),
2037
+ " KB)"
2038
+ ] }),
2039
+ /* @__PURE__ */ jsxs("div", { children: [
2040
+ "Duration: ",
2041
+ (diagnostics.elapsedMs / 1e3).toFixed(1),
2042
+ "s"
2043
+ ] }),
2044
+ /* @__PURE__ */ jsxs("div", { children: [
2045
+ "Close code: ",
2046
+ diagnostics.closeCode ?? "N/A",
2047
+ diagnostics.closeReason ? ` (${diagnostics.closeReason})` : ""
2048
+ ] })
2049
+ ] }),
2050
+ !diagnostics && /* @__PURE__ */ jsx("div", { className: "mb-6" }),
1992
2051
  /* @__PURE__ */ jsx(
1993
2052
  "button",
1994
2053
  {