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

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