@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supraio/client-daemon-js",
3
- "version": "1.0.0-mzbrightsigndecoder.489",
3
+ "version": "1.0.0-mzbrightsigndecoder.490",
4
4
  "description": "",
5
5
  "main": "sdk.js",
6
6
  "types": "sdk.d.ts",
@@ -35,6 +35,7 @@ export interface IScreenOptions {
35
35
  height: number;
36
36
  };
37
37
  geometry?: IScreenGeometry;
38
+ streamProtocol?: string;
38
39
  interactive: boolean;
39
40
  encodingPreferences?: IEncodingPreferences;
40
41
  control?: import('./control').IScreenControl;
package/screen.html CHANGED
@@ -5,6 +5,6 @@
5
5
  <link rel="stylesheet" href="screen.css"></link>
6
6
  </head>
7
7
  <body>
8
- <script type="text/javascript" src="screen.js?v=1.0.0-mzbrightsigndecoder.489"></script>
8
+ <script type="text/javascript" src="screen.js?v=1.0.0-mzbrightsigndecoder.490"></script>
9
9
  </body>
10
10
  </html>
package/screen.js CHANGED
@@ -26280,6 +26280,21 @@
26280
26280
  var import_brightsign_decoder = __toESM(require_dist());
26281
26281
  var BRIGHTSIGN_TCP_DRIVER = "brightsign_tcp";
26282
26282
  var teardownRegistered = false;
26283
+ var backendInitialization;
26284
+ var ownedDecoder;
26285
+ var ownedTCP;
26286
+ var unloading = false;
26287
+ function resolvePlaybackProtocol(streamProtocol) {
26288
+ switch (streamProtocol) {
26289
+ case void 0:
26290
+ case "udp":
26291
+ return "udp";
26292
+ case "http":
26293
+ return "http";
26294
+ default:
26295
+ throw new RangeError(`Unsupported BrightSign playback protocol: ${streamProtocol}`);
26296
+ }
26297
+ }
26283
26298
  function isBrightSignRuntimeAvailable() {
26284
26299
  return (0, import_brightsign_decoder.detectCapabilities)().native;
26285
26300
  }
@@ -26288,7 +26303,8 @@
26288
26303
  return true;
26289
26304
  }
26290
26305
  try {
26291
- window.brightSignTCP = (0, import_brightsign_decoder.createBrightSignTCP)();
26306
+ ownedTCP = (0, import_brightsign_decoder.createBrightSignTCP)();
26307
+ window.brightSignTCP = ownedTCP;
26292
26308
  registerTeardown();
26293
26309
  return true;
26294
26310
  } catch (error) {
@@ -26297,16 +26313,60 @@
26297
26313
  }
26298
26314
  }
26299
26315
  async function initBrightSignBackend(options) {
26300
- var _a;
26301
26316
  if (options.screenDriver !== BRIGHTSIGN_TCP_DRIVER) {
26302
26317
  return false;
26303
26318
  }
26319
+ let streamProtocol;
26320
+ try {
26321
+ streamProtocol = resolvePlaybackProtocol(options.streamProtocol);
26322
+ } catch (error) {
26323
+ console.error("Failed to initialize BrightSign backend", error);
26324
+ return false;
26325
+ }
26326
+ if (backendInitialization) {
26327
+ if (backendInitialization.protocol !== streamProtocol) {
26328
+ console.error(`BrightSign backend is already initializing with protocol ${backendInitialization.protocol}`);
26329
+ return false;
26330
+ }
26331
+ return backendInitialization.promise;
26332
+ }
26333
+ if (ownedTCP && window.brightSignTCP !== ownedTCP || ownedDecoder && window.brightSignDecoder !== ownedDecoder) {
26334
+ console.error("BrightSign backend resources owned by the adapter were externally replaced");
26335
+ return false;
26336
+ }
26304
26337
  if (window.brightSignTCP && window.brightSignDecoder) {
26338
+ let existingProtocol;
26339
+ try {
26340
+ existingProtocol = window.brightSignDecoder.getDiagnostics().protocol;
26341
+ } catch (error) {
26342
+ console.error("Failed to inspect existing BrightSign backend", error);
26343
+ return false;
26344
+ }
26345
+ if (existingProtocol !== streamProtocol) {
26346
+ console.error(`BrightSign backend is already initialized with protocol ${existingProtocol}`);
26347
+ return false;
26348
+ }
26305
26349
  return true;
26306
26350
  }
26351
+ if (window.brightSignDecoder) {
26352
+ console.error("BrightSign decoder exists without its transport");
26353
+ return false;
26354
+ }
26307
26355
  if (!isBrightSignRuntimeAvailable()) {
26308
26356
  return false;
26309
26357
  }
26358
+ const promise = initializeBrightSignBackend(options, streamProtocol);
26359
+ backendInitialization = { protocol: streamProtocol, promise };
26360
+ try {
26361
+ return await promise;
26362
+ } finally {
26363
+ backendInitialization = void 0;
26364
+ }
26365
+ }
26366
+ async function initializeBrightSignBackend(options, streamProtocol) {
26367
+ var _a;
26368
+ let decoder;
26369
+ let createdTCP;
26310
26370
  try {
26311
26371
  const geometry = (_a = options.geometry) != null ? _a : {
26312
26372
  x: 0,
@@ -26314,31 +26374,92 @@
26314
26374
  width: window.innerWidth,
26315
26375
  height: window.innerHeight
26316
26376
  };
26377
+ const existingTCP = window.brightSignTCP;
26317
26378
  if (!initBrightSignTCP()) {
26318
26379
  return false;
26319
26380
  }
26320
- const decoder = (0, import_brightsign_decoder.createBrightSignDecoder)();
26321
- await decoder.initialize(geometry);
26322
- window.brightSignDecoder = decoder;
26381
+ if (!existingTCP) {
26382
+ createdTCP = window.brightSignTCP;
26383
+ }
26384
+ const tcp = window.brightSignTCP;
26385
+ if (!tcp) {
26386
+ throw new Error("BrightSign transport was not created");
26387
+ }
26388
+ decoder = (0, import_brightsign_decoder.createBrightSignDecoder)();
26389
+ ownedDecoder = decoder;
26323
26390
  registerTeardown();
26391
+ await decoder.initialize({
26392
+ ...geometry,
26393
+ streamProtocol
26394
+ });
26395
+ if (window.brightSignTCP !== tcp || window.brightSignDecoder || ownedDecoder !== decoder) {
26396
+ throw new Error("BrightSign backend state changed during initialization");
26397
+ }
26398
+ window.brightSignDecoder = decoder;
26324
26399
  return true;
26325
26400
  } catch (error) {
26326
- window.brightSignDecoder = void 0;
26401
+ if (window.brightSignDecoder === decoder) {
26402
+ window.brightSignDecoder = void 0;
26403
+ }
26404
+ if (createdTCP && window.brightSignTCP === createdTCP) {
26405
+ window.brightSignTCP = void 0;
26406
+ }
26407
+ const destroyDecoder = ownedDecoder === decoder ? decoder : void 0;
26408
+ const destroyTCP = ownedTCP === createdTCP ? createdTCP : void 0;
26409
+ if (destroyDecoder) {
26410
+ ownedDecoder = void 0;
26411
+ }
26412
+ if (destroyTCP) {
26413
+ ownedTCP = void 0;
26414
+ }
26415
+ await destroyAfterInitializationFailure(destroyDecoder, "decoder", () => {
26416
+ ownedDecoder = destroyDecoder;
26417
+ });
26418
+ await destroyAfterInitializationFailure(destroyTCP, "transport", () => {
26419
+ ownedTCP = destroyTCP;
26420
+ });
26327
26421
  console.error("Failed to initialize BrightSign backend", error);
26328
26422
  return false;
26329
26423
  }
26330
26424
  }
26425
+ async function destroyAfterInitializationFailure(resource, resourceName, restoreOwnership) {
26426
+ if (!resource) {
26427
+ return;
26428
+ }
26429
+ const context = { deadlineMs: 1e3 };
26430
+ try {
26431
+ await resource.destroy(context);
26432
+ } catch (cleanupError) {
26433
+ console.error(`Failed to clean up BrightSign ${resourceName} after initialization failure`, cleanupError);
26434
+ if (!unloading) {
26435
+ restoreOwnership();
26436
+ return;
26437
+ }
26438
+ try {
26439
+ await resource.destroy(context);
26440
+ } catch (retryError) {
26441
+ console.error(`Failed to clean up BrightSign ${resourceName} during unload`, retryError);
26442
+ }
26443
+ }
26444
+ }
26331
26445
  function registerTeardown() {
26332
26446
  if (teardownRegistered) {
26333
26447
  return;
26334
26448
  }
26335
26449
  teardownRegistered = true;
26336
26450
  window.addEventListener("unload", () => {
26337
- const decoder = window.brightSignDecoder;
26338
- const tcp = window.brightSignTCP;
26339
- const context = { deadlineMs: Date.now() + 1e3 };
26340
- window.brightSignDecoder = void 0;
26341
- window.brightSignTCP = void 0;
26451
+ unloading = true;
26452
+ const decoder = ownedDecoder;
26453
+ const tcp = ownedTCP;
26454
+ const context = { deadlineMs: 1e3 };
26455
+ if (window.brightSignDecoder === decoder) {
26456
+ window.brightSignDecoder = void 0;
26457
+ }
26458
+ if (window.brightSignTCP === tcp) {
26459
+ window.brightSignTCP = void 0;
26460
+ }
26461
+ ownedDecoder = void 0;
26462
+ ownedTCP = void 0;
26342
26463
  void (decoder == null ? void 0 : decoder.destroy(context).catch((error) => {
26343
26464
  console.error("Failed to destroy BrightSign decoder", error);
26344
26465
  }));
@@ -26713,6 +26834,9 @@ self.onmessage = function(event) {
26713
26834
  interactive: params.interactive === "true",
26714
26835
  netInWorker: params.netInWorker === "true"
26715
26836
  };
26837
+ if (typeof params.streamProtocol === "string") {
26838
+ options.streamProtocol = params.streamProtocol;
26839
+ }
26716
26840
  if (typeof params.forceScreenSize === "string") {
26717
26841
  const sizeParts = params.forceScreenSize.split("x");
26718
26842
  if (sizeParts.length !== 2) {
@@ -26780,7 +26904,7 @@ self.onmessage = function(event) {
26780
26904
  }
26781
26905
 
26782
26906
  // screen/plain.ts
26783
- var SCREEN_JS_URL = "supra-client-screen.js?v=1.0.0-mzbrightsigndecoder.489";
26907
+ var SCREEN_JS_URL = "supra-client-screen.js?v=1.0.0-mzbrightsigndecoder.490";
26784
26908
  async function startPlainScreen(options) {
26785
26909
  var _a, _b, _c;
26786
26910
  console.log("[Supra screen plain] initialization begin");
@@ -26834,7 +26958,7 @@ self.onmessage = function(event) {
26834
26958
  }
26835
26959
 
26836
26960
  // screen/h264decoder.ts
26837
- var H264_DECODER_URL = "h264decoder.js?v=1.0.0-mzbrightsigndecoder.489";
26961
+ var H264_DECODER_URL = "h264decoder.js?v=1.0.0-mzbrightsigndecoder.490";
26838
26962
  async function initH264Decoder() {
26839
26963
  if (window.VideoDecoder !== void 0) {
26840
26964
  return void 0;
@@ -26873,7 +26997,7 @@ self.onmessage = function(event) {
26873
26997
  }
26874
26998
 
26875
26999
  // screen/wasm.ts
26876
- var SCREEN_WASM_URL = "supra-client-screen.wasm?v=1.0.0-mzbrightsigndecoder.489";
27000
+ var SCREEN_WASM_URL = "supra-client-screen.wasm?v=1.0.0-mzbrightsigndecoder.490";
26877
27001
  async function initializePhase(name, initialize) {
26878
27002
  const startedAt = Date.now();
26879
27003
  console.log(`[Supra screen WASM] ${name} begin`);