@supraio/client-daemon-js 1.0.0-mzbrightsigndecoder.489 → 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
@@ -26293,6 +26293,22 @@ async function initGoEnvironment() {
26293
26293
  var import_brightsign_decoder = __toESM(require_dist());
26294
26294
  var BRIGHTSIGN_TCP_DRIVER = "brightsign_tcp";
26295
26295
  var teardownRegistered = false;
26296
+ var backendInitialization;
26297
+ var ownedDecoder;
26298
+ var ownedTCP;
26299
+ var unloading = false;
26300
+ var teardownPromise;
26301
+ function resolvePlaybackProtocol(streamProtocol) {
26302
+ switch (streamProtocol) {
26303
+ case void 0:
26304
+ case "udp":
26305
+ return "udp";
26306
+ case "http":
26307
+ return "http";
26308
+ default:
26309
+ throw new RangeError(`Unsupported BrightSign playback protocol: ${streamProtocol}`);
26310
+ }
26311
+ }
26296
26312
  function isBrightSignRuntimeAvailable() {
26297
26313
  return (0, import_brightsign_decoder.detectCapabilities)().native;
26298
26314
  }
@@ -26301,7 +26317,8 @@ function initBrightSignTCP() {
26301
26317
  return true;
26302
26318
  }
26303
26319
  try {
26304
- window.brightSignTCP = (0, import_brightsign_decoder.createBrightSignTCP)();
26320
+ ownedTCP = (0, import_brightsign_decoder.createBrightSignTCP)();
26321
+ window.brightSignTCP = ownedTCP;
26305
26322
  registerTeardown();
26306
26323
  return true;
26307
26324
  } catch (error) {
@@ -26310,16 +26327,64 @@ function initBrightSignTCP() {
26310
26327
  }
26311
26328
  }
26312
26329
  async function initBrightSignBackend(options) {
26313
- var _a;
26314
26330
  if (options.screenDriver !== BRIGHTSIGN_TCP_DRIVER) {
26315
26331
  return false;
26316
26332
  }
26333
+ if (unloading) {
26334
+ console.error("BrightSign backend cannot initialize during unload");
26335
+ return false;
26336
+ }
26337
+ let streamProtocol;
26338
+ try {
26339
+ streamProtocol = resolvePlaybackProtocol(options.streamProtocol);
26340
+ } catch (error) {
26341
+ console.error("Failed to initialize BrightSign backend", error);
26342
+ return false;
26343
+ }
26344
+ if (backendInitialization) {
26345
+ if (backendInitialization.protocol !== streamProtocol) {
26346
+ console.error(`BrightSign backend is already initializing with protocol ${backendInitialization.protocol}`);
26347
+ return false;
26348
+ }
26349
+ return backendInitialization.promise;
26350
+ }
26351
+ if (ownedTCP && window.brightSignTCP !== ownedTCP || ownedDecoder && window.brightSignDecoder !== ownedDecoder) {
26352
+ console.error("BrightSign backend resources owned by the adapter were externally replaced");
26353
+ return false;
26354
+ }
26317
26355
  if (window.brightSignTCP && window.brightSignDecoder) {
26356
+ let existingProtocol;
26357
+ try {
26358
+ existingProtocol = window.brightSignDecoder.getDiagnostics().protocol;
26359
+ } catch (error) {
26360
+ console.error("Failed to inspect existing BrightSign backend", error);
26361
+ return false;
26362
+ }
26363
+ if (existingProtocol !== streamProtocol) {
26364
+ console.error(`BrightSign backend is already initialized with protocol ${existingProtocol}`);
26365
+ return false;
26366
+ }
26318
26367
  return true;
26319
26368
  }
26369
+ if (window.brightSignDecoder) {
26370
+ console.error("BrightSign decoder exists without its transport");
26371
+ return false;
26372
+ }
26320
26373
  if (!isBrightSignRuntimeAvailable()) {
26321
26374
  return false;
26322
26375
  }
26376
+ const promise = initializeBrightSignBackend(options, streamProtocol);
26377
+ backendInitialization = { protocol: streamProtocol, promise };
26378
+ try {
26379
+ return await promise;
26380
+ } finally {
26381
+ backendInitialization = void 0;
26382
+ }
26383
+ }
26384
+ async function initializeBrightSignBackend(options, streamProtocol) {
26385
+ var _a;
26386
+ let decoder;
26387
+ let createdTCP;
26323
26388
  try {
26324
26389
  const geometry = (_a = options.geometry) != null ? _a : {
26325
26390
  x: 0,
@@ -26327,37 +26392,132 @@ async function initBrightSignBackend(options) {
26327
26392
  width: window.innerWidth,
26328
26393
  height: window.innerHeight
26329
26394
  };
26395
+ const existingTCP = window.brightSignTCP;
26330
26396
  if (!initBrightSignTCP()) {
26331
26397
  return false;
26332
26398
  }
26333
- const decoder = (0, import_brightsign_decoder.createBrightSignDecoder)();
26334
- await decoder.initialize(geometry);
26335
- window.brightSignDecoder = decoder;
26399
+ if (!existingTCP) {
26400
+ createdTCP = window.brightSignTCP;
26401
+ }
26402
+ const tcp = window.brightSignTCP;
26403
+ if (!tcp) {
26404
+ throw new Error("BrightSign transport was not created");
26405
+ }
26406
+ decoder = (0, import_brightsign_decoder.createBrightSignDecoder)();
26407
+ ownedDecoder = decoder;
26336
26408
  registerTeardown();
26409
+ await decoder.initialize({
26410
+ ...geometry,
26411
+ streamProtocol
26412
+ });
26413
+ if (unloading || window.brightSignTCP !== tcp || window.brightSignDecoder || ownedDecoder !== decoder) {
26414
+ throw new Error("BrightSign backend state changed during initialization");
26415
+ }
26416
+ window.brightSignDecoder = decoder;
26337
26417
  return true;
26338
26418
  } catch (error) {
26339
- window.brightSignDecoder = void 0;
26419
+ if (unloading) {
26420
+ await teardownPromise;
26421
+ console.error("Failed to initialize BrightSign backend", error);
26422
+ return false;
26423
+ }
26424
+ if (window.brightSignDecoder === decoder) {
26425
+ window.brightSignDecoder = void 0;
26426
+ }
26427
+ if (createdTCP && window.brightSignTCP === createdTCP) {
26428
+ window.brightSignTCP = void 0;
26429
+ }
26430
+ const destroyDecoder = ownedDecoder === decoder ? decoder : void 0;
26431
+ const destroyTCP = ownedTCP === createdTCP ? createdTCP : void 0;
26432
+ if (destroyDecoder) {
26433
+ ownedDecoder = void 0;
26434
+ }
26435
+ if (destroyTCP) {
26436
+ ownedTCP = void 0;
26437
+ }
26438
+ await Promise.all([
26439
+ destroyAfterInitializationFailure(destroyDecoder, "decoder", () => {
26440
+ ownedDecoder = destroyDecoder;
26441
+ }),
26442
+ destroyAfterInitializationFailure(destroyTCP, "transport", () => {
26443
+ ownedTCP = destroyTCP;
26444
+ })
26445
+ ]);
26340
26446
  console.error("Failed to initialize BrightSign backend", error);
26341
26447
  return false;
26342
26448
  }
26343
26449
  }
26450
+ async function destroyAfterInitializationFailure(resource, resourceName, restoreOwnership) {
26451
+ if (!resource) {
26452
+ return;
26453
+ }
26454
+ const context = { deadlineMs: 1e3 };
26455
+ try {
26456
+ await resource.destroy(context);
26457
+ } catch (cleanupError) {
26458
+ console.error(`Failed to clean up BrightSign ${resourceName} after initialization failure`, cleanupError);
26459
+ if (!unloading) {
26460
+ restoreOwnership();
26461
+ return;
26462
+ }
26463
+ try {
26464
+ await resource.destroy(context);
26465
+ } catch (retryError) {
26466
+ console.error(`Failed to clean up BrightSign ${resourceName} during unload`, retryError);
26467
+ restoreOwnership();
26468
+ }
26469
+ }
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
+ }
26344
26509
  function registerTeardown() {
26345
26510
  if (teardownRegistered) {
26346
26511
  return;
26347
26512
  }
26348
26513
  teardownRegistered = true;
26349
26514
  window.addEventListener("unload", () => {
26350
- const decoder = window.brightSignDecoder;
26351
- const tcp = window.brightSignTCP;
26352
- const context = { deadlineMs: Date.now() + 1e3 };
26353
- window.brightSignDecoder = void 0;
26354
- window.brightSignTCP = void 0;
26355
- void (decoder == null ? void 0 : decoder.destroy(context).catch((error) => {
26356
- console.error("Failed to destroy BrightSign decoder", error);
26357
- }));
26358
- void (tcp == null ? void 0 : tcp.destroy(context).catch((error) => {
26359
- console.error("Failed to destroy BrightSign transport", error);
26360
- }));
26515
+ unloading = true;
26516
+ if (!teardownPromise) {
26517
+ teardownPromise = destroyOwnedResources().finally(() => {
26518
+ teardownPromise = void 0;
26519
+ });
26520
+ }
26361
26521
  });
26362
26522
  }
26363
26523
 
@@ -26390,7 +26550,7 @@ async function initSamsungWasmTCP() {
26390
26550
  }
26391
26551
 
26392
26552
  // daemon/plain.ts
26393
- var DAEMON_JS_URL = "supra-client-daemon.js?v=1.0.0-mzbrightsigndecoder.489";
26553
+ var DAEMON_JS_URL = "supra-client-daemon.js?v=1.0.0-mzbrightsigndecoder.491";
26394
26554
  async function startPlainDaemon() {
26395
26555
  initBrightSignTCP();
26396
26556
  await initNaClTCP();
@@ -26404,7 +26564,7 @@ async function startPlainDaemon() {
26404
26564
  }
26405
26565
 
26406
26566
  // daemon/wasm.ts
26407
- var DAEMON_WASM_URL = "supra-client-daemon.wasm?v=1.0.0-mzbrightsigndecoder.489";
26567
+ var DAEMON_WASM_URL = "supra-client-daemon.wasm?v=1.0.0-mzbrightsigndecoder.491";
26408
26568
  async function startWasmDaemon() {
26409
26569
  initBrightSignTCP();
26410
26570
  await initNaClTCP();
@@ -26762,6 +26922,9 @@ function parseQueryOptions() {
26762
26922
  interactive: params.interactive === "true",
26763
26923
  netInWorker: params.netInWorker === "true"
26764
26924
  };
26925
+ if (typeof params.streamProtocol === "string") {
26926
+ options.streamProtocol = params.streamProtocol;
26927
+ }
26765
26928
  if (typeof params.forceScreenSize === "string") {
26766
26929
  const sizeParts = params.forceScreenSize.split("x");
26767
26930
  if (sizeParts.length !== 2) {
@@ -26829,7 +26992,7 @@ function getGoArgv2(binFile, options) {
26829
26992
  }
26830
26993
 
26831
26994
  // screen/plain.ts
26832
- var SCREEN_JS_URL = "supra-client-screen.js?v=1.0.0-mzbrightsigndecoder.489";
26995
+ var SCREEN_JS_URL = "supra-client-screen.js?v=1.0.0-mzbrightsigndecoder.491";
26833
26996
  async function startPlainScreen(options) {
26834
26997
  var _a, _b, _c;
26835
26998
  console.log("[Supra screen plain] initialization begin");
@@ -26883,7 +27046,7 @@ async function startPlainScreen(options) {
26883
27046
  }
26884
27047
 
26885
27048
  // screen/h264decoder.ts
26886
- var H264_DECODER_URL = "h264decoder.js?v=1.0.0-mzbrightsigndecoder.489";
27049
+ var H264_DECODER_URL = "h264decoder.js?v=1.0.0-mzbrightsigndecoder.491";
26887
27050
  async function initH264Decoder() {
26888
27051
  if (window.VideoDecoder !== void 0) {
26889
27052
  return void 0;
@@ -26922,7 +27085,7 @@ function getProperty(value, property) {
26922
27085
  }
26923
27086
 
26924
27087
  // screen/wasm.ts
26925
- var SCREEN_WASM_URL = "supra-client-screen.wasm?v=1.0.0-mzbrightsigndecoder.489";
27088
+ var SCREEN_WASM_URL = "supra-client-screen.wasm?v=1.0.0-mzbrightsigndecoder.491";
26926
27089
  async function initializePhase(name, initialize) {
26927
27090
  const startedAt = Date.now();
26928
27091
  console.log(`[Supra screen WASM] ${name} begin`);