@supraio/client-daemon-js 1.0.0-mzbrightsigndecoder.490 → 1.0.0-mzbrightsigndecoder.491

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/sdk.js CHANGED
@@ -26297,6 +26297,7 @@ var backendInitialization;
26297
26297
  var ownedDecoder;
26298
26298
  var ownedTCP;
26299
26299
  var unloading = false;
26300
+ var teardownPromise;
26300
26301
  function resolvePlaybackProtocol(streamProtocol) {
26301
26302
  switch (streamProtocol) {
26302
26303
  case void 0:
@@ -26329,6 +26330,10 @@ async function initBrightSignBackend(options) {
26329
26330
  if (options.screenDriver !== BRIGHTSIGN_TCP_DRIVER) {
26330
26331
  return false;
26331
26332
  }
26333
+ if (unloading) {
26334
+ console.error("BrightSign backend cannot initialize during unload");
26335
+ return false;
26336
+ }
26332
26337
  let streamProtocol;
26333
26338
  try {
26334
26339
  streamProtocol = resolvePlaybackProtocol(options.streamProtocol);
@@ -26405,12 +26410,17 @@ async function initializeBrightSignBackend(options, streamProtocol) {
26405
26410
  ...geometry,
26406
26411
  streamProtocol
26407
26412
  });
26408
- if (window.brightSignTCP !== tcp || window.brightSignDecoder || ownedDecoder !== decoder) {
26413
+ if (unloading || window.brightSignTCP !== tcp || window.brightSignDecoder || ownedDecoder !== decoder) {
26409
26414
  throw new Error("BrightSign backend state changed during initialization");
26410
26415
  }
26411
26416
  window.brightSignDecoder = decoder;
26412
26417
  return true;
26413
26418
  } catch (error) {
26419
+ if (unloading) {
26420
+ await teardownPromise;
26421
+ console.error("Failed to initialize BrightSign backend", error);
26422
+ return false;
26423
+ }
26414
26424
  if (window.brightSignDecoder === decoder) {
26415
26425
  window.brightSignDecoder = void 0;
26416
26426
  }
@@ -26425,12 +26435,14 @@ async function initializeBrightSignBackend(options, streamProtocol) {
26425
26435
  if (destroyTCP) {
26426
26436
  ownedTCP = void 0;
26427
26437
  }
26428
- await destroyAfterInitializationFailure(destroyDecoder, "decoder", () => {
26429
- ownedDecoder = destroyDecoder;
26430
- });
26431
- await destroyAfterInitializationFailure(destroyTCP, "transport", () => {
26432
- ownedTCP = destroyTCP;
26433
- });
26438
+ await Promise.all([
26439
+ destroyAfterInitializationFailure(destroyDecoder, "decoder", () => {
26440
+ ownedDecoder = destroyDecoder;
26441
+ }),
26442
+ destroyAfterInitializationFailure(destroyTCP, "transport", () => {
26443
+ ownedTCP = destroyTCP;
26444
+ })
26445
+ ]);
26434
26446
  console.error("Failed to initialize BrightSign backend", error);
26435
26447
  return false;
26436
26448
  }
@@ -26452,9 +26464,48 @@ async function destroyAfterInitializationFailure(resource, resourceName, restore
26452
26464
  await resource.destroy(context);
26453
26465
  } catch (retryError) {
26454
26466
  console.error(`Failed to clean up BrightSign ${resourceName} during unload`, retryError);
26467
+ restoreOwnership();
26455
26468
  }
26456
26469
  }
26457
26470
  }
26471
+ async function destroyOwnedResources() {
26472
+ const context = { deadlineMs: 1e3 };
26473
+ const decoder = ownedDecoder;
26474
+ const destroyDecoder = async () => {
26475
+ if (!decoder) {
26476
+ return;
26477
+ }
26478
+ try {
26479
+ await decoder.destroy(context);
26480
+ if (ownedDecoder === decoder) {
26481
+ ownedDecoder = void 0;
26482
+ }
26483
+ if (window.brightSignDecoder === decoder) {
26484
+ window.brightSignDecoder = void 0;
26485
+ }
26486
+ } catch (error) {
26487
+ console.error("Failed to destroy BrightSign decoder", error);
26488
+ }
26489
+ };
26490
+ const tcp = ownedTCP;
26491
+ const destroyTCP = async () => {
26492
+ if (!tcp) {
26493
+ return;
26494
+ }
26495
+ try {
26496
+ await tcp.destroy(context);
26497
+ if (ownedTCP === tcp) {
26498
+ ownedTCP = void 0;
26499
+ }
26500
+ if (window.brightSignTCP === tcp) {
26501
+ window.brightSignTCP = void 0;
26502
+ }
26503
+ } catch (error) {
26504
+ console.error("Failed to destroy BrightSign transport", error);
26505
+ }
26506
+ };
26507
+ await Promise.all([destroyDecoder(), destroyTCP()]);
26508
+ }
26458
26509
  function registerTeardown() {
26459
26510
  if (teardownRegistered) {
26460
26511
  return;
@@ -26462,23 +26513,11 @@ function registerTeardown() {
26462
26513
  teardownRegistered = true;
26463
26514
  window.addEventListener("unload", () => {
26464
26515
  unloading = true;
26465
- const decoder = ownedDecoder;
26466
- const tcp = ownedTCP;
26467
- const context = { deadlineMs: 1e3 };
26468
- if (window.brightSignDecoder === decoder) {
26469
- window.brightSignDecoder = void 0;
26470
- }
26471
- if (window.brightSignTCP === tcp) {
26472
- window.brightSignTCP = void 0;
26516
+ if (!teardownPromise) {
26517
+ teardownPromise = destroyOwnedResources().finally(() => {
26518
+ teardownPromise = void 0;
26519
+ });
26473
26520
  }
26474
- ownedDecoder = void 0;
26475
- ownedTCP = void 0;
26476
- void (decoder == null ? void 0 : decoder.destroy(context).catch((error) => {
26477
- console.error("Failed to destroy BrightSign decoder", error);
26478
- }));
26479
- void (tcp == null ? void 0 : tcp.destroy(context).catch((error) => {
26480
- console.error("Failed to destroy BrightSign transport", error);
26481
- }));
26482
26521
  });
26483
26522
  }
26484
26523
 
@@ -26511,7 +26550,7 @@ async function initSamsungWasmTCP() {
26511
26550
  }
26512
26551
 
26513
26552
  // daemon/plain.ts
26514
- var DAEMON_JS_URL = "supra-client-daemon.js?v=1.0.0-mzbrightsigndecoder.490";
26553
+ var DAEMON_JS_URL = "supra-client-daemon.js?v=1.0.0-mzbrightsigndecoder.491";
26515
26554
  async function startPlainDaemon() {
26516
26555
  initBrightSignTCP();
26517
26556
  await initNaClTCP();
@@ -26525,7 +26564,7 @@ async function startPlainDaemon() {
26525
26564
  }
26526
26565
 
26527
26566
  // daemon/wasm.ts
26528
- var DAEMON_WASM_URL = "supra-client-daemon.wasm?v=1.0.0-mzbrightsigndecoder.490";
26567
+ var DAEMON_WASM_URL = "supra-client-daemon.wasm?v=1.0.0-mzbrightsigndecoder.491";
26529
26568
  async function startWasmDaemon() {
26530
26569
  initBrightSignTCP();
26531
26570
  await initNaClTCP();
@@ -26953,7 +26992,7 @@ function getGoArgv2(binFile, options) {
26953
26992
  }
26954
26993
 
26955
26994
  // screen/plain.ts
26956
- var SCREEN_JS_URL = "supra-client-screen.js?v=1.0.0-mzbrightsigndecoder.490";
26995
+ var SCREEN_JS_URL = "supra-client-screen.js?v=1.0.0-mzbrightsigndecoder.491";
26957
26996
  async function startPlainScreen(options) {
26958
26997
  var _a, _b, _c;
26959
26998
  console.log("[Supra screen plain] initialization begin");
@@ -27007,7 +27046,7 @@ async function startPlainScreen(options) {
27007
27046
  }
27008
27047
 
27009
27048
  // screen/h264decoder.ts
27010
- var H264_DECODER_URL = "h264decoder.js?v=1.0.0-mzbrightsigndecoder.490";
27049
+ var H264_DECODER_URL = "h264decoder.js?v=1.0.0-mzbrightsigndecoder.491";
27011
27050
  async function initH264Decoder() {
27012
27051
  if (window.VideoDecoder !== void 0) {
27013
27052
  return void 0;
@@ -27046,7 +27085,7 @@ function getProperty(value, property) {
27046
27085
  }
27047
27086
 
27048
27087
  // screen/wasm.ts
27049
- var SCREEN_WASM_URL = "supra-client-screen.wasm?v=1.0.0-mzbrightsigndecoder.490";
27088
+ var SCREEN_WASM_URL = "supra-client-screen.wasm?v=1.0.0-mzbrightsigndecoder.491";
27050
27089
  async function initializePhase(name, initialize) {
27051
27090
  const startedAt = Date.now();
27052
27091
  console.log(`[Supra screen WASM] ${name} begin`);