@supraio/client-daemon-js 1.0.0-mzbrightsigndecoder.473 → 1.0.0-mzbrightsigndecoder.477

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/daemon.js CHANGED
@@ -19501,13 +19501,13 @@
19501
19501
  }
19502
19502
  }
19503
19503
  /** Start native playback at the given URI and coordinates. */
19504
- async start(uri, coords, options = {}) {
19504
+ async start(uri, coords, protocol, options = {}) {
19505
19505
  if (this.playing) {
19506
19506
  await this.stop();
19507
19507
  }
19508
19508
  this.uri = uri;
19509
19509
  this.coordinates = coords;
19510
- await this.bridge.play(uri, coords.x, coords.y, coords.width, coords.height, { protocol: "HTTP", ...options });
19510
+ await this.bridge.play(uri, coords.x, coords.y, coords.width, coords.height, { protocol, ...options });
19511
19511
  this.playing = true;
19512
19512
  }
19513
19513
  /**
@@ -19535,6 +19535,438 @@
19535
19535
  }
19536
19536
  });
19537
19537
 
19538
+ // node_modules/@signageos/brightsign-decoder/dist/decoder/NativeUdpSender.js
19539
+ var require_NativeUdpSender = __commonJS({
19540
+ "node_modules/@signageos/brightsign-decoder/dist/decoder/NativeUdpSender.js"(exports) {
19541
+ "use strict";
19542
+ Object.defineProperty(exports, "__esModule", { value: true });
19543
+ exports.NativeUdpSender = exports.NativeUdpPreWriteError = void 0;
19544
+ var TS_PACKET_SIZE = 188;
19545
+ var DEFAULT_MAX_DATAGRAM_BYTES = 7 * TS_PACKET_SIZE;
19546
+ var DEFAULT_STARTUP_REPEAT_COUNT = 3;
19547
+ var DEFAULT_STARTUP_REPEAT_INTERVAL_MS = 20;
19548
+ var NativeUdpPreWriteError = class extends Error {
19549
+ constructor(message) {
19550
+ super(message);
19551
+ this.name = "NativeUdpPreWriteError";
19552
+ }
19553
+ };
19554
+ exports.NativeUdpPreWriteError = NativeUdpPreWriteError;
19555
+ var NativeUdpSender = class {
19556
+ constructor(options) {
19557
+ var _a, _b, _c;
19558
+ this.pendingWarmupDelays = /* @__PURE__ */ new Set();
19559
+ this.writeChain = Promise.resolve();
19560
+ this.sourcePort = 0;
19561
+ this.destinationPort = 0;
19562
+ this.datagramsSent = 0;
19563
+ this.bytesSent = 0;
19564
+ this.accessUnitsSent = 0;
19565
+ this.warmupAccessUnits = 0;
19566
+ this.warmupRepeats = 0;
19567
+ this.socketErrors = 0;
19568
+ this.sendErrors = 0;
19569
+ this.destroyed = false;
19570
+ this.teardownComplete = false;
19571
+ this.maxDatagramBytes = (_a = options == null ? void 0 : options.maxDatagramBytes) != null ? _a : DEFAULT_MAX_DATAGRAM_BYTES;
19572
+ this.maxPacketsPerDatagram = Math.floor(this.maxDatagramBytes / TS_PACKET_SIZE);
19573
+ this.startupRepeatCount = (_b = options == null ? void 0 : options.startupRepeatCount) != null ? _b : DEFAULT_STARTUP_REPEAT_COUNT;
19574
+ this.startupRepeatIntervalMs = (_c = options == null ? void 0 : options.startupRepeatIntervalMs) != null ? _c : DEFAULT_STARTUP_REPEAT_INTERVAL_MS;
19575
+ if (!Number.isSafeInteger(this.maxDatagramBytes) || this.maxDatagramBytes < TS_PACKET_SIZE) {
19576
+ throw new RangeError("maxDatagramBytes must be an integer greater than or equal to one TS packet");
19577
+ }
19578
+ if (this.maxPacketsPerDatagram <= 0) {
19579
+ throw new RangeError("maxDatagramBytes must allow at least one 188-byte TS packet");
19580
+ }
19581
+ if (!Number.isSafeInteger(this.startupRepeatCount) || this.startupRepeatCount <= 0) {
19582
+ throw new RangeError("startupRepeatCount must be a positive integer");
19583
+ }
19584
+ if (!Number.isFinite(this.startupRepeatIntervalMs) || this.startupRepeatIntervalMs < 0) {
19585
+ throw new RangeError("startupRepeatIntervalMs must be a finite non-negative number");
19586
+ }
19587
+ }
19588
+ async start(dgramModule) {
19589
+ if (this.destroyed) {
19590
+ throw new Error("NativeUdpSender has been destroyed");
19591
+ }
19592
+ if (this.socket !== void 0 || this.destinationSocket !== void 0) {
19593
+ throw new Error("NativeUdpSender is already started");
19594
+ }
19595
+ let destinationSocket;
19596
+ let socket;
19597
+ try {
19598
+ destinationSocket = narrowToDgramSocketLike(dgramModule.createSocket("udp4"));
19599
+ destinationSocket.on("error", (value) => {
19600
+ this.socketErrors += 1;
19601
+ if (!this.destroyed && this.socketFailure === void 0) {
19602
+ this.socketFailure = toError(value, "Loopback UDP destination reservation error");
19603
+ }
19604
+ });
19605
+ await bindDgramSocket(destinationSocket, 0, "127.0.0.1");
19606
+ const destinationAddress = destinationSocket.address();
19607
+ if (typeof destinationAddress !== "object" || destinationAddress === null || !Number.isInteger(destinationAddress.port)) {
19608
+ throw new Error("Loopback UDP reservation did not report a bound destination port");
19609
+ }
19610
+ socket = narrowToDgramSocketLike(dgramModule.createSocket("udp4"));
19611
+ socket.on("error", (value) => {
19612
+ this.socketErrors += 1;
19613
+ if (!this.destroyed && this.socketFailure === void 0) {
19614
+ this.socketFailure = toError(value, "Loopback UDP sender socket error");
19615
+ }
19616
+ });
19617
+ await bindDgramSocket(socket, 0, "127.0.0.1");
19618
+ if (this.destroyed) {
19619
+ throw new Error("NativeUdpSender was destroyed during initialization");
19620
+ }
19621
+ const address = socket.address();
19622
+ if (typeof address !== "object" || address === null || !Number.isInteger(address.port)) {
19623
+ throw new Error("Loopback UDP sender did not report a bound source port");
19624
+ }
19625
+ this.destinationSocket = destinationSocket;
19626
+ this.socket = socket;
19627
+ this.sourcePort = address.port;
19628
+ this.destinationPort = destinationAddress.port;
19629
+ return this.destinationPort;
19630
+ } catch (error) {
19631
+ if (socket !== void 0) {
19632
+ await closeDgramSocket(socket);
19633
+ }
19634
+ if (destinationSocket !== void 0) {
19635
+ await closeDgramSocket(destinationSocket);
19636
+ }
19637
+ this.sourcePort = 0;
19638
+ this.destinationPort = 0;
19639
+ throw toError(error, "Loopback UDP sender creation failed");
19640
+ }
19641
+ }
19642
+ getDiagnostics() {
19643
+ return {
19644
+ sourcePort: this.sourcePort,
19645
+ destinationPort: this.destinationPort,
19646
+ destinationReserved: this.destinationSocket !== void 0,
19647
+ datagramsSent: this.datagramsSent,
19648
+ bytesSent: this.bytesSent,
19649
+ accessUnitsSent: this.accessUnitsSent,
19650
+ warmupAccessUnits: this.warmupAccessUnits,
19651
+ warmupRepeats: this.warmupRepeats,
19652
+ pendingWarmupDelays: this.pendingWarmupDelays.size,
19653
+ socketErrors: this.socketErrors,
19654
+ sendErrors: this.sendErrors
19655
+ };
19656
+ }
19657
+ async writeAccessUnit(packets) {
19658
+ if (packets.length === 0) {
19659
+ return;
19660
+ }
19661
+ await this.enqueueWrite(async () => {
19662
+ const datagrams = buildDatagrams(packets, this.maxPacketsPerDatagram);
19663
+ await this.performDatagramBurst(datagrams);
19664
+ this.accessUnitsSent += 1;
19665
+ });
19666
+ }
19667
+ async releaseDestinationReservation() {
19668
+ const destinationSocket = this.destinationSocket;
19669
+ if (destinationSocket === void 0) {
19670
+ if (this.destinationPort === 0) {
19671
+ throw new Error("NativeUdpSender is not started");
19672
+ }
19673
+ return;
19674
+ }
19675
+ await closeDgramSocket(destinationSocket);
19676
+ this.destinationSocket = void 0;
19677
+ }
19678
+ async warmupAccessUnit(packets) {
19679
+ if (packets.length === 0) {
19680
+ return;
19681
+ }
19682
+ await this.enqueueWrite(async () => {
19683
+ const datagrams = buildDatagrams(packets, this.maxPacketsPerDatagram);
19684
+ let sentDatagrams = 0;
19685
+ for (let attempt = 0; attempt < this.startupRepeatCount; attempt += 1) {
19686
+ if (this.destroyed) {
19687
+ return;
19688
+ }
19689
+ try {
19690
+ sentDatagrams += await this.performDatagramBurst(datagrams);
19691
+ this.warmupRepeats += 1;
19692
+ } catch (error) {
19693
+ const normalized = toError(error, "Loopback UDP startup warmup failed");
19694
+ if (sentDatagrams === 0) {
19695
+ if (normalized instanceof NativeUdpPreWriteError) {
19696
+ throw normalized;
19697
+ }
19698
+ throw new NativeUdpPreWriteError(normalized.message);
19699
+ }
19700
+ throw normalized;
19701
+ }
19702
+ if (attempt + 1 < this.startupRepeatCount) {
19703
+ await this.waitWarmupInterval();
19704
+ }
19705
+ }
19706
+ this.warmupAccessUnits += 1;
19707
+ });
19708
+ }
19709
+ get uri() {
19710
+ if (this.destinationPort === 0) {
19711
+ throw new Error("NativeUdpSender is not started");
19712
+ }
19713
+ return `udp://127.0.0.1:${this.destinationPort}`;
19714
+ }
19715
+ destroy() {
19716
+ if (this.teardownComplete) {
19717
+ return Promise.resolve();
19718
+ }
19719
+ if (this.teardown !== void 0) {
19720
+ return this.teardown;
19721
+ }
19722
+ this.destroyed = true;
19723
+ for (const pending of this.pendingWarmupDelays) {
19724
+ clearTimeout(pending.timer);
19725
+ pending.resolve();
19726
+ }
19727
+ this.pendingWarmupDelays.clear();
19728
+ const attempt = this.performTeardown();
19729
+ const promise = attempt.then(() => {
19730
+ this.teardownComplete = true;
19731
+ }, (error) => {
19732
+ if (this.teardown === promise) {
19733
+ this.teardown = void 0;
19734
+ }
19735
+ throw error;
19736
+ });
19737
+ this.teardown = promise;
19738
+ return promise;
19739
+ }
19740
+ async performTeardown() {
19741
+ await this.writeChain;
19742
+ const destinationSocket = this.destinationSocket;
19743
+ if (destinationSocket !== void 0) {
19744
+ await closeDgramSocket(destinationSocket);
19745
+ this.destinationSocket = void 0;
19746
+ }
19747
+ const socket = this.socket;
19748
+ if (socket !== void 0) {
19749
+ await closeDgramSocket(socket);
19750
+ this.socket = void 0;
19751
+ }
19752
+ this.sourcePort = 0;
19753
+ this.destinationPort = 0;
19754
+ }
19755
+ enqueueWrite(operation) {
19756
+ const next = this.writeChain.then(operation);
19757
+ this.writeChain = next.catch(() => void 0);
19758
+ return next;
19759
+ }
19760
+ async performDatagramBurst(datagrams) {
19761
+ if (this.destroyed) {
19762
+ return 0;
19763
+ }
19764
+ const socket = this.socket;
19765
+ if (socket === void 0) {
19766
+ throw new NativeUdpPreWriteError("NativeUdpSender is not started");
19767
+ }
19768
+ const initialSocketFailure = this.getSocketFailure();
19769
+ if (initialSocketFailure !== void 0) {
19770
+ throw new NativeUdpPreWriteError(initialSocketFailure.message);
19771
+ }
19772
+ let sent = 0;
19773
+ for (const datagram of datagrams) {
19774
+ if (this.destroyed) {
19775
+ return sent;
19776
+ }
19777
+ const socketFailure = this.getSocketFailure();
19778
+ if (socketFailure !== void 0) {
19779
+ if (sent === 0) {
19780
+ throw new NativeUdpPreWriteError(socketFailure.message);
19781
+ }
19782
+ throw socketFailure;
19783
+ }
19784
+ try {
19785
+ await sendDatagram(socket, datagram, this.destinationPort, () => this.destroyed);
19786
+ if (this.destroyed) {
19787
+ return sent;
19788
+ }
19789
+ this.datagramsSent += 1;
19790
+ this.bytesSent += datagram.byteLength;
19791
+ sent += 1;
19792
+ } catch (error) {
19793
+ const normalized = toError(error, "Loopback UDP datagram send failed");
19794
+ this.sendErrors += 1;
19795
+ if (this.destroyed) {
19796
+ return sent;
19797
+ }
19798
+ if (sent === 0) {
19799
+ throw new NativeUdpPreWriteError(normalized.message);
19800
+ }
19801
+ throw normalized;
19802
+ }
19803
+ }
19804
+ return sent;
19805
+ }
19806
+ async waitWarmupInterval() {
19807
+ if (this.destroyed || this.startupRepeatIntervalMs === 0) {
19808
+ return;
19809
+ }
19810
+ await new Promise((resolve) => {
19811
+ const timer = setTimeout(() => {
19812
+ this.pendingWarmupDelays.delete(pending);
19813
+ resolve();
19814
+ }, this.startupRepeatIntervalMs);
19815
+ const pending = {
19816
+ timer,
19817
+ resolve: () => {
19818
+ this.pendingWarmupDelays.delete(pending);
19819
+ resolve();
19820
+ }
19821
+ };
19822
+ this.pendingWarmupDelays.add(pending);
19823
+ });
19824
+ }
19825
+ getSocketFailure() {
19826
+ return this.socketFailure;
19827
+ }
19828
+ };
19829
+ exports.NativeUdpSender = NativeUdpSender;
19830
+ async function bindDgramSocket(socket, port, address) {
19831
+ await new Promise((resolve, reject) => {
19832
+ let settled = false;
19833
+ const onError = (value) => {
19834
+ if (settled) {
19835
+ return;
19836
+ }
19837
+ settled = true;
19838
+ reject(toError(value, "Loopback UDP bind failed"));
19839
+ };
19840
+ socket.on("error", onError);
19841
+ try {
19842
+ socket.bind(port, address, () => {
19843
+ if (settled) {
19844
+ return;
19845
+ }
19846
+ settled = true;
19847
+ socket.removeListener("error", onError);
19848
+ resolve();
19849
+ });
19850
+ } catch (error) {
19851
+ if (!settled) {
19852
+ settled = true;
19853
+ socket.removeListener("error", onError);
19854
+ reject(toError(error, "Loopback UDP bind failed"));
19855
+ }
19856
+ }
19857
+ });
19858
+ }
19859
+ async function closeDgramSocket(socket) {
19860
+ await new Promise((resolve) => {
19861
+ try {
19862
+ socket.close(resolve);
19863
+ } catch {
19864
+ resolve();
19865
+ }
19866
+ });
19867
+ }
19868
+ async function sendDatagram(socket, datagram, destinationPort, isDestroyed) {
19869
+ if (isDestroyed()) {
19870
+ return;
19871
+ }
19872
+ await new Promise((resolve, reject) => {
19873
+ try {
19874
+ socket.send(datagram, destinationPort, "127.0.0.1", (error) => {
19875
+ if (error === void 0 || error === null || isDestroyed()) {
19876
+ resolve();
19877
+ return;
19878
+ }
19879
+ reject(toError(error, "Loopback UDP datagram send failed"));
19880
+ });
19881
+ } catch (error) {
19882
+ if (isDestroyed()) {
19883
+ resolve();
19884
+ return;
19885
+ }
19886
+ reject(toError(error, "Loopback UDP datagram send failed"));
19887
+ }
19888
+ });
19889
+ }
19890
+ function buildDatagrams(packets, maxPacketsPerDatagram) {
19891
+ if (packets.length === 0) {
19892
+ return [];
19893
+ }
19894
+ for (const packet of packets) {
19895
+ if (packet.byteLength !== TS_PACKET_SIZE || packet[0] !== 71) {
19896
+ throw new NativeUdpPreWriteError("Native UDP transport accepts only aligned 188-byte TS packets");
19897
+ }
19898
+ }
19899
+ const datagrams = [];
19900
+ for (let start = 0; start < packets.length; start += maxPacketsPerDatagram) {
19901
+ const end = Math.min(start + maxPacketsPerDatagram, packets.length);
19902
+ const datagram = new Uint8Array((end - start) * TS_PACKET_SIZE);
19903
+ let offset = 0;
19904
+ for (let index = start; index < end; index += 1) {
19905
+ const packet = packets[index];
19906
+ if (packet === void 0) {
19907
+ continue;
19908
+ }
19909
+ datagram.set(packet, offset);
19910
+ offset += TS_PACKET_SIZE;
19911
+ }
19912
+ datagrams.push(datagram);
19913
+ }
19914
+ return datagrams;
19915
+ }
19916
+ function narrowToDgramSocketLike(value) {
19917
+ if (typeof value !== "object" || value === null) {
19918
+ throw new TypeError("Expected a dgram socket object");
19919
+ }
19920
+ const on = Reflect.get(value, "on");
19921
+ const once = Reflect.get(value, "once");
19922
+ const removeListener = Reflect.get(value, "removeListener");
19923
+ const bind = Reflect.get(value, "bind");
19924
+ const send = Reflect.get(value, "send");
19925
+ const address = Reflect.get(value, "address");
19926
+ const close = Reflect.get(value, "close");
19927
+ if (typeof on !== "function" || typeof once !== "function" || typeof removeListener !== "function" || typeof bind !== "function" || typeof send !== "function" || typeof address !== "function" || typeof close !== "function") {
19928
+ throw new TypeError("Object does not satisfy the UDP socket contract");
19929
+ }
19930
+ return {
19931
+ on(event, listener) {
19932
+ Reflect.apply(on, value, [event, listener]);
19933
+ },
19934
+ once(event, listener) {
19935
+ Reflect.apply(once, value, [event, listener]);
19936
+ },
19937
+ removeListener(event, listener) {
19938
+ Reflect.apply(removeListener, value, [event, listener]);
19939
+ },
19940
+ bind(port, addressValue, callback) {
19941
+ Reflect.apply(bind, value, [port, addressValue, callback]);
19942
+ },
19943
+ send(buffer, port, addressValue, callback) {
19944
+ Reflect.apply(send, value, [buffer, port, addressValue, callback]);
19945
+ },
19946
+ address() {
19947
+ const result = Reflect.apply(address, value, []);
19948
+ if (typeof result === "string" || result === null) {
19949
+ return result;
19950
+ }
19951
+ if (typeof result === "object") {
19952
+ const port = Reflect.get(result, "port");
19953
+ if (typeof port === "number") {
19954
+ return { port };
19955
+ }
19956
+ }
19957
+ return null;
19958
+ },
19959
+ close(callback) {
19960
+ Reflect.apply(close, value, callback === void 0 ? [] : [callback]);
19961
+ }
19962
+ };
19963
+ }
19964
+ function toError(value, fallback) {
19965
+ return value instanceof Error ? value : new Error(fallback);
19966
+ }
19967
+ }
19968
+ });
19969
+
19538
19970
  // node_modules/@signageos/brightsign-decoder/dist/decoder/NativeH264Decoder.js
19539
19971
  var require_NativeH264Decoder = __commonJS({
19540
19972
  "node_modules/@signageos/brightsign-decoder/dist/decoder/NativeH264Decoder.js"(exports) {
@@ -19545,11 +19977,12 @@
19545
19977
  var MpegTsMuxer_1 = require_MpegTsMuxer();
19546
19978
  var NativeHttpServer_1 = require_NativeHttpServer();
19547
19979
  var PlaybackSession_1 = require_PlaybackSession();
19980
+ var NativeUdpSender_1 = require_NativeUdpSender();
19548
19981
  var DEFAULT_MAX_QUEUED_ACCESS_UNITS = 16;
19549
19982
  var DEFAULT_MAX_QUEUED_BYTES = 8 * 1024 * 1024;
19550
19983
  var NativeH264Decoder = class {
19551
19984
  constructor(dependencies) {
19552
- var _a, _b, _c, _d, _e, _f;
19985
+ var _a, _b, _c, _d, _e, _f, _g;
19553
19986
  this.dependencies = dependencies;
19554
19987
  this.queuedAtMs = [];
19555
19988
  this.operationChain = Promise.resolve();
@@ -19563,16 +19996,20 @@
19563
19996
  this.failedAccessUnits = 0;
19564
19997
  this.capacityRejections = 0;
19565
19998
  this.destroyed = false;
19999
+ this.httpServerStarted = false;
19566
20000
  this.httpServerDestroyed = false;
20001
+ this.udpSenderStarted = false;
20002
+ this.udpSenderDestroyed = false;
19567
20003
  this.playbackStopped = false;
19568
20004
  this.initialized = false;
19569
20005
  this.httpServer = (_a = dependencies.httpServer) != null ? _a : new NativeHttpServer_1.NativeHttpServer();
20006
+ this.udpSender = (_b = dependencies.udpSender) != null ? _b : dependencies.dgramModule === void 0 ? void 0 : new NativeUdpSender_1.NativeUdpSender();
19570
20007
  this.playback = new PlaybackSession_1.PlaybackSession(dependencies.streamBridge);
19571
- this.muxer = (_b = dependencies.muxer) != null ? _b : new MpegTsMuxer_1.MpegTsMuxer();
19572
- this.referenceRegistry = (_c = dependencies.refRegistry) != null ? _c : new FrameReferenceRegistry_1.FrameReferenceRegistry();
19573
- this.maxQueuedAccessUnits = (_d = dependencies.maxQueuedAccessUnits) != null ? _d : DEFAULT_MAX_QUEUED_ACCESS_UNITS;
19574
- this.maxQueuedBytes = (_e = dependencies.maxQueuedBytes) != null ? _e : DEFAULT_MAX_QUEUED_BYTES;
19575
- this.now = (_f = dependencies.now) != null ? _f : Date.now;
20008
+ this.muxer = (_c = dependencies.muxer) != null ? _c : new MpegTsMuxer_1.MpegTsMuxer();
20009
+ this.referenceRegistry = (_d = dependencies.refRegistry) != null ? _d : new FrameReferenceRegistry_1.FrameReferenceRegistry();
20010
+ this.maxQueuedAccessUnits = (_e = dependencies.maxQueuedAccessUnits) != null ? _e : DEFAULT_MAX_QUEUED_ACCESS_UNITS;
20011
+ this.maxQueuedBytes = (_f = dependencies.maxQueuedBytes) != null ? _f : DEFAULT_MAX_QUEUED_BYTES;
20012
+ this.now = (_g = dependencies.now) != null ? _g : Date.now;
19576
20013
  if (!Number.isSafeInteger(this.maxQueuedAccessUnits) || this.maxQueuedAccessUnits <= 0) {
19577
20014
  throw new RangeError("maxQueuedAccessUnits must be a positive integer");
19578
20015
  }
@@ -19629,8 +20066,10 @@
19629
20066
  }
19630
20067
  }
19631
20068
  getDiagnostics() {
20069
+ var _a;
19632
20070
  const oldest = this.queuedAtMs[0];
19633
20071
  return {
20072
+ protocol: this.getConfiguredProtocol(),
19634
20073
  queuedAccessUnits: this.queuedAccessUnits,
19635
20074
  queuedBytes: this.queuedBytes,
19636
20075
  highWaterAccessUnits: this.highWaterAccessUnits,
@@ -19641,7 +20080,8 @@
19641
20080
  failedAccessUnits: this.failedAccessUnits,
19642
20081
  capacityRejections: this.capacityRejections,
19643
20082
  pendingError: this.pendingError !== void 0,
19644
- httpTransport: this.httpServer.getDiagnostics()
20083
+ httpTransport: this.httpServer.getDiagnostics(),
20084
+ udpTransport: (_a = this.udpSender) == null ? void 0 : _a.getDiagnostics()
19645
20085
  };
19646
20086
  }
19647
20087
  destroy() {
@@ -19672,7 +20112,7 @@
19672
20112
  } catch {
19673
20113
  }
19674
20114
  }
19675
- if (!this.httpServerDestroyed) {
20115
+ if (this.httpServerStarted && !this.httpServerDestroyed) {
19676
20116
  try {
19677
20117
  await this.httpServer.destroy();
19678
20118
  this.httpServerDestroyed = true;
@@ -19680,6 +20120,14 @@
19680
20120
  firstError = firstError != null ? firstError : toError(error, "HTTP transport teardown failed");
19681
20121
  }
19682
20122
  }
20123
+ if (this.udpSenderStarted && !this.udpSenderDestroyed && this.udpSender !== void 0) {
20124
+ try {
20125
+ await this.udpSender.destroy();
20126
+ this.udpSenderDestroyed = true;
20127
+ } catch (error) {
20128
+ firstError = firstError != null ? firstError : toError(error, "UDP transport teardown failed");
20129
+ }
20130
+ }
19683
20131
  try {
19684
20132
  await this.operationChain;
19685
20133
  } catch (error) {
@@ -19699,22 +20147,28 @@
19699
20147
  }
19700
20148
  }
19701
20149
  async performInitialization() {
19702
- var _a, _b;
19703
20150
  try {
19704
20151
  const options = this.options;
19705
20152
  if (options === void 0) {
19706
20153
  throw new Error("Decoder options are unavailable");
19707
20154
  }
19708
- await this.httpServer.start(this.dependencies.httpModule);
20155
+ if (this.getConfiguredProtocol() === "UDP") {
20156
+ const dgramModule = this.dependencies.dgramModule;
20157
+ if (dgramModule === void 0 || this.udpSender === void 0) {
20158
+ throw new Error("UDP playback requires a dgram module");
20159
+ }
20160
+ await this.udpSender.start(dgramModule);
20161
+ this.udpSenderStarted = true;
20162
+ } else {
20163
+ await this.httpServer.start(this.dependencies.httpModule);
20164
+ this.httpServerStarted = true;
20165
+ }
19709
20166
  if (this.destroyed) {
19710
20167
  throw new Error("Decoder was destroyed during initialization");
19711
20168
  }
19712
- await this.playback.start(this.httpServer.uri, {
19713
- x: (_a = options.x) != null ? _a : 0,
19714
- y: (_b = options.y) != null ? _b : 0,
19715
- width: options.width,
19716
- height: options.height
19717
- }, options.streamOptions);
20169
+ if (this.getConfiguredProtocol() === "HTTP") {
20170
+ await this.startPlayback(this.httpServer.uri, "HTTP");
20171
+ }
19718
20172
  if (this.destroyed) {
19719
20173
  throw new Error("Decoder was destroyed during initialization");
19720
20174
  }
@@ -19722,14 +20176,23 @@
19722
20176
  } catch (error) {
19723
20177
  let result = toError(error, "Decoder initialization failed");
19724
20178
  try {
19725
- await this.httpServer.destroy();
19726
- this.httpServerDestroyed = true;
20179
+ if (this.getConfiguredProtocol() === "HTTP" && !this.httpServerDestroyed) {
20180
+ await this.httpServer.destroy();
20181
+ this.httpServerDestroyed = true;
20182
+ }
19727
20183
  } catch (cleanupError) {
19728
20184
  result = new Error(`${result.message}; HTTP cleanup failed: ${toError(cleanupError, "unknown error").message}`);
19729
20185
  }
20186
+ try {
20187
+ if (this.getConfiguredProtocol() === "UDP" && !this.udpSenderDestroyed && this.udpSender !== void 0) {
20188
+ await this.udpSender.destroy();
20189
+ this.udpSenderDestroyed = true;
20190
+ }
20191
+ } catch (cleanupError) {
20192
+ result = new Error(`${result.message}; UDP cleanup failed: ${toError(cleanupError, "unknown error").message}`);
20193
+ }
19730
20194
  try {
19731
20195
  await this.playback.stop();
19732
- this.playbackStopped = true;
19733
20196
  } catch (cleanupError) {
19734
20197
  result = new Error(`${result.message}; playback cleanup failed: ${toError(cleanupError, "unknown error").message}`);
19735
20198
  }
@@ -19771,10 +20234,10 @@
19771
20234
  const operation = this.operationChain.then(async () => {
19772
20235
  const prepared = this.muxer.prepare(ownedData, ownedTimestamp);
19773
20236
  try {
19774
- await this.httpServer.writeAccessUnit(prepared.packets);
20237
+ await this.deliverAccessUnit(prepared.packets);
19775
20238
  prepared.commit();
19776
20239
  } catch (error) {
19777
- if (error instanceof NativeHttpServer_1.NativeHttpPreWriteError) {
20240
+ if (isPreWriteError(error)) {
19778
20241
  prepared.rejectBeforeWrite();
19779
20242
  } else {
19780
20243
  prepared.commit();
@@ -19800,6 +20263,67 @@
19800
20263
  this.queuedAccessUnits -= 1;
19801
20264
  this.queuedBytes -= byteLength;
19802
20265
  }
20266
+ getConfiguredProtocol() {
20267
+ var _a, _b;
20268
+ return (_b = (_a = this.options) == null ? void 0 : _a.streamProtocol) != null ? _b : "HTTP";
20269
+ }
20270
+ async startPlayback(uri, protocol) {
20271
+ var _a, _b;
20272
+ const options = this.options;
20273
+ if (options === void 0) {
20274
+ throw new Error("Decoder options are unavailable");
20275
+ }
20276
+ await this.playback.start(uri, {
20277
+ x: (_a = options.x) != null ? _a : 0,
20278
+ y: (_b = options.y) != null ? _b : 0,
20279
+ width: options.width,
20280
+ height: options.height
20281
+ }, protocol, options.streamOptions);
20282
+ }
20283
+ async deliverAccessUnit(packets) {
20284
+ if (this.getConfiguredProtocol() === "UDP") {
20285
+ await this.deliverUdpAccessUnit(packets);
20286
+ return;
20287
+ }
20288
+ await this.httpServer.writeAccessUnit(packets);
20289
+ }
20290
+ async deliverUdpAccessUnit(packets) {
20291
+ if (packets.length === 0) {
20292
+ return;
20293
+ }
20294
+ const udpSender = this.udpSender;
20295
+ if (udpSender === void 0) {
20296
+ throw new NativeUdpSender_1.NativeUdpPreWriteError("UDP transport is unavailable");
20297
+ }
20298
+ if (!this.playback.isPlaying) {
20299
+ await this.startUdpPlayback(udpSender, packets);
20300
+ return;
20301
+ }
20302
+ await udpSender.writeAccessUnit(packets);
20303
+ }
20304
+ async startUdpPlayback(udpSender, packets) {
20305
+ let playbackStarted = false;
20306
+ try {
20307
+ await udpSender.releaseDestinationReservation();
20308
+ await this.startPlayback(udpSender.uri, "UDP");
20309
+ playbackStarted = true;
20310
+ await udpSender.warmupAccessUnit(packets);
20311
+ } catch (error) {
20312
+ const preWriteFailure = error instanceof NativeUdpSender_1.NativeUdpPreWriteError || !playbackStarted;
20313
+ let result = toError(error, "UDP startup failed");
20314
+ if (playbackStarted) {
20315
+ try {
20316
+ await this.playback.stop();
20317
+ } catch (cleanupError) {
20318
+ result = new Error(`${result.message}; UDP playback cleanup failed: ${toError(cleanupError, "unknown error").message}`);
20319
+ }
20320
+ }
20321
+ if (preWriteFailure) {
20322
+ throw new NativeUdpSender_1.NativeUdpPreWriteError(result.message);
20323
+ }
20324
+ throw result;
20325
+ }
20326
+ }
19803
20327
  };
19804
20328
  exports.NativeH264Decoder = NativeH264Decoder;
19805
20329
  function validateDecoderOptions(options) {
@@ -19847,6 +20371,9 @@
19847
20371
  function toError(value, fallback) {
19848
20372
  return value instanceof Error ? value : new Error(fallback);
19849
20373
  }
20374
+ function isPreWriteError(error) {
20375
+ return error instanceof NativeHttpServer_1.NativeHttpPreWriteError || error instanceof NativeUdpSender_1.NativeUdpPreWriteError;
20376
+ }
19850
20377
  }
19851
20378
  });
19852
20379
 
@@ -19917,23 +20444,26 @@
19917
20444
  if (typeof globalThis === "undefined") {
19918
20445
  return false;
19919
20446
  }
19920
- const parentWindow = safeGet(globalThis, "parent");
19921
- if (parentWindow === void 0 || parentWindow === null) {
19922
- return false;
19923
- }
19924
- const parentRequire = safeGet(parentWindow, "require");
19925
- if (typeof parentRequire !== "function") {
19926
- return false;
19927
- }
19928
- const http = Reflect.apply(parentRequire, parentWindow, ["http"]);
19929
- if (typeof http !== "object" || http === null) {
19930
- return false;
20447
+ const localRequire = safeGet(globalThis, "require");
20448
+ if (probeHttpModule(localRequire, globalThis)) {
20449
+ return true;
19931
20450
  }
19932
- return typeof Reflect.get(http, "createServer") === "function";
20451
+ const parentWindow = safeGet(globalThis, "parent");
20452
+ return probeHttpModule(safeGet(parentWindow, "require"), parentWindow);
19933
20453
  } catch {
19934
20454
  return false;
19935
20455
  }
19936
20456
  }
20457
+ function probeHttpModule(requireFunction, receiver) {
20458
+ if (typeof requireFunction !== "function") {
20459
+ return false;
20460
+ }
20461
+ const http = Reflect.apply(requireFunction, receiver, ["http"]);
20462
+ if (typeof http !== "object" || http === null) {
20463
+ return false;
20464
+ }
20465
+ return typeof Reflect.get(http, "createServer") === "function";
20466
+ }
19937
20467
  function probeStreamBridge() {
19938
20468
  try {
19939
20469
  if (typeof globalThis === "undefined") {
@@ -19967,6 +20497,7 @@
19967
20497
  exports.discoverParentRequire = discoverParentRequire;
19968
20498
  exports.validateNetModule = validateNetModule;
19969
20499
  exports.validateHttpModule = validateHttpModule;
20500
+ exports.validateDgramModule = validateDgramModule;
19970
20501
  function safeGet(target, key) {
19971
20502
  try {
19972
20503
  if (typeof target !== "object" || target === null) {
@@ -19989,6 +20520,10 @@
19989
20520
  if (typeof globalThis === "undefined") {
19990
20521
  return void 0;
19991
20522
  }
20523
+ const localRequire = safeGet(globalThis, "require");
20524
+ if (typeof localRequire === "function") {
20525
+ return wrapRequire(localRequire, globalThis);
20526
+ }
19992
20527
  const parentWindow = safeGet(globalThis, "parent");
19993
20528
  if (parentWindow !== void 0 && parentWindow !== null) {
19994
20529
  const parentRequire = safeGet(parentWindow, "require");
@@ -20019,6 +20554,13 @@
20019
20554
  const cs = Reflect.get(mod, "createServer");
20020
20555
  return typeof cs === "function";
20021
20556
  }
20557
+ function validateDgramModule(mod) {
20558
+ if (typeof mod !== "object" || mod === null) {
20559
+ return false;
20560
+ }
20561
+ const createSocket = Reflect.get(mod, "createSocket");
20562
+ return typeof createSocket === "function";
20563
+ }
20022
20564
  }
20023
20565
  });
20024
20566
 
@@ -20027,7 +20569,7 @@
20027
20569
  "node_modules/@signageos/brightsign-decoder/dist/index.js"(exports) {
20028
20570
  "use strict";
20029
20571
  Object.defineProperty(exports, "__esModule", { value: true });
20030
- exports.validateHttpModule = exports.validateNetModule = exports.discoverParentRequire = exports.detectCapabilities = exports.isBrightSignDecoderSupported = exports.NativeHttpServer = exports.PlaybackSession = exports.WebCodecsH264Decoder = exports.NativeH264Decoder = exports.parseNalUnits = exports.NalType = exports.inspectAccessUnit = exports.getNalType = exports.findStartCodes = exports.u64Sub = exports.u64ToBigInt = exports.TransportClock = exports.verifyCrc32 = exports.computeCrc32 = exports.MpegTsMuxer = exports.TCP = exports.ConnectionRegistry = exports.FrameReferenceRegistry = exports.FrameCollector = exports.PacketParser = exports.FrameType = exports.ConnectionState = void 0;
20572
+ exports.validateHttpModule = exports.validateNetModule = exports.validateDgramModule = exports.discoverParentRequire = exports.detectCapabilities = exports.isBrightSignDecoderSupported = exports.NativeHttpServer = exports.PlaybackSession = exports.WebCodecsH264Decoder = exports.NativeH264Decoder = exports.parseNalUnits = exports.NalType = exports.inspectAccessUnit = exports.getNalType = exports.findStartCodes = exports.u64Sub = exports.u64ToBigInt = exports.TransportClock = exports.verifyCrc32 = exports.computeCrc32 = exports.MpegTsMuxer = exports.TCP = exports.ConnectionRegistry = exports.FrameReferenceRegistry = exports.FrameCollector = exports.PacketParser = exports.FrameType = exports.ConnectionState = void 0;
20031
20573
  exports.createBrightSignDecoder = createBrightSignDecoder2;
20032
20574
  exports.createBrightSignTCP = createBrightSignTCP2;
20033
20575
  var contracts_1 = require_contracts();
@@ -20120,6 +20662,9 @@
20120
20662
  Object.defineProperty(exports, "discoverParentRequire", { enumerable: true, get: function() {
20121
20663
  return parentNode_1.discoverParentRequire;
20122
20664
  } });
20665
+ Object.defineProperty(exports, "validateDgramModule", { enumerable: true, get: function() {
20666
+ return parentNode_1.validateDgramModule;
20667
+ } });
20123
20668
  Object.defineProperty(exports, "validateNetModule", { enumerable: true, get: function() {
20124
20669
  return parentNode_1.validateNetModule;
20125
20670
  } });
@@ -20134,9 +20679,29 @@
20134
20679
  function createBrightSignDecoder2(deps) {
20135
20680
  var _a;
20136
20681
  const resolved = deps != null ? deps : {};
20682
+ let dgramModule = resolved.dgramModule;
20137
20683
  let httpModule = resolved.httpModule;
20138
20684
  let streamBridge = resolved.streamBridge;
20139
20685
  const refRegistry = (_a = resolved.refRegistry) != null ? _a : new FrameReferenceRegistry_2.FrameReferenceRegistry();
20686
+ if (dgramModule === void 0) {
20687
+ const parentRequire = (0, parentNode_2.discoverParentRequire)();
20688
+ if (parentRequire !== void 0) {
20689
+ try {
20690
+ const dgram = parentRequire("dgram");
20691
+ if ((0, parentNode_2.validateDgramModule)(dgram) && typeof dgram === "object" && dgram !== null) {
20692
+ const createSocket = Reflect.get(dgram, "createSocket");
20693
+ if (typeof createSocket === "function") {
20694
+ dgramModule = {
20695
+ createSocket(type) {
20696
+ return Reflect.apply(createSocket, dgram, [type]);
20697
+ }
20698
+ };
20699
+ }
20700
+ }
20701
+ } catch {
20702
+ }
20703
+ }
20704
+ }
20140
20705
  if (httpModule === void 0) {
20141
20706
  const parentRequire = (0, parentNode_2.discoverParentRequire)();
20142
20707
  if (parentRequire !== void 0) {
@@ -20163,6 +20728,7 @@
20163
20728
  throw new Error("No stream bridge available \u2014 provide streamBridge or ensure sos.stream is accessible");
20164
20729
  }
20165
20730
  const fullDeps = {
20731
+ dgramModule,
20166
20732
  httpModule,
20167
20733
  streamBridge,
20168
20734
  refRegistry
@@ -24278,7 +24844,7 @@
24278
24844
  }
24279
24845
 
24280
24846
  // daemon/plain.ts
24281
- var DAEMON_JS_URL = "supra-client-daemon.js?v=1.0.0-mzbrightsigndecoder.473";
24847
+ var DAEMON_JS_URL = "supra-client-daemon.js?v=1.0.0-mzbrightsigndecoder.477";
24282
24848
  async function startPlainDaemon() {
24283
24849
  initBrightSignTCP();
24284
24850
  await initNaClTCP();
@@ -24292,7 +24858,7 @@
24292
24858
  }
24293
24859
 
24294
24860
  // daemon/wasm.ts
24295
- var DAEMON_WASM_URL = "supra-client-daemon.wasm?v=1.0.0-mzbrightsigndecoder.473";
24861
+ var DAEMON_WASM_URL = "supra-client-daemon.wasm?v=1.0.0-mzbrightsigndecoder.477";
24296
24862
  async function startWasmDaemon() {
24297
24863
  initBrightSignTCP();
24298
24864
  await initNaClTCP();