scandit-datacapture-frameworks-core 7.6.1 → 8.0.0-beta.1

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.
Files changed (29) hide show
  1. package/dist/dts/camera/Camera.d.ts +7 -5
  2. package/dist/dts/camera/CameraController.d.ts +5 -5
  3. package/dist/dts/camera/VideoResolution.d.ts +1 -0
  4. package/dist/dts/camerahelpers/CameraOwner.d.ts +3 -0
  5. package/dist/dts/camerahelpers/CameraOwnershipHelper.d.ts +42 -0
  6. package/dist/dts/camerahelpers/CameraOwnershipManager.d.ts +24 -0
  7. package/dist/dts/camerahelpers/index.d.ts +3 -0
  8. package/dist/dts/common/Payload.d.ts +2 -0
  9. package/dist/dts/context/DataCaptureContext.d.ts +0 -4
  10. package/dist/dts/frame/ImageFrameSource.d.ts +1 -1
  11. package/dist/dts/frame/ImageFrameSourceController.d.ts +23 -13
  12. package/dist/dts/view/DataCaptureView.d.ts +2 -2
  13. package/dist/dts/view/index.d.ts +1 -1
  14. package/dist/index.js +521 -211
  15. package/dist/index.js.map +1 -1
  16. package/node_modules/eventemitter3/LICENSE +21 -0
  17. package/node_modules/eventemitter3/README.md +94 -0
  18. package/node_modules/eventemitter3/dist/eventemitter3.esm.js +347 -0
  19. package/node_modules/eventemitter3/dist/eventemitter3.esm.min.js +1 -0
  20. package/node_modules/eventemitter3/dist/eventemitter3.esm.min.js.map +1 -0
  21. package/node_modules/eventemitter3/dist/eventemitter3.umd.js +355 -0
  22. package/node_modules/eventemitter3/dist/eventemitter3.umd.min.js +1 -0
  23. package/node_modules/eventemitter3/dist/eventemitter3.umd.min.js.map +1 -0
  24. package/node_modules/eventemitter3/index.d.ts +135 -0
  25. package/node_modules/eventemitter3/index.js +336 -0
  26. package/node_modules/eventemitter3/index.mjs +4 -0
  27. package/node_modules/eventemitter3/package.json +67 -0
  28. package/package.json +4 -4
  29. package/dist/dts/view/ScreenStateManager.d.ts +0 -8
package/dist/index.js CHANGED
@@ -778,13 +778,6 @@ class FrameDataSettingsBuilder {
778
778
  }
779
779
  }
780
780
 
781
- var CameraPosition;
782
- (function (CameraPosition) {
783
- CameraPosition["WorldFacing"] = "worldFacing";
784
- CameraPosition["UserFacing"] = "userFacing";
785
- CameraPosition["Unspecified"] = "unspecified";
786
- })(CameraPosition || (CameraPosition = {}));
787
-
788
781
  var FrameSourceListenerEvents;
789
782
  (function (FrameSourceListenerEvents) {
790
783
  FrameSourceListenerEvents["didChangeState"] = "FrameSourceListener.onStateChanged";
@@ -1532,19 +1525,30 @@ class HTMLElementState {
1532
1525
  }
1533
1526
  }
1534
1527
 
1535
- class ImageFrameSourceController {
1536
- static forImage(imageFrameSource) {
1537
- const controller = new ImageFrameSourceController();
1538
- controller.imageFrameSource = imageFrameSource;
1539
- return controller;
1528
+ class BaseNewController {
1529
+ get _proxy() {
1530
+ return this._cachedProxy;
1540
1531
  }
1541
- constructor() {
1542
- this.eventEmitter = FactoryMaker.getInstance('EventEmitter');
1543
- this._proxy = FactoryMaker.getInstance('ImageFrameSourceProxy');
1532
+ constructor(proxyName) {
1533
+ this._cachedProxy = FactoryMaker.createInstance(proxyName);
1534
+ }
1535
+ }
1536
+
1537
+ class ImageFrameSourceController extends BaseNewController {
1538
+ constructor(imageFrameSource) {
1539
+ super('ImageFrameSourceProxy');
1540
+ this.handleDidChangeStateEventWrapper = (ev) => {
1541
+ return this.handleDidChangeStateEvent(ev);
1542
+ };
1543
+ this.imageFrameSource = imageFrameSource;
1544
+ this.subscribeListener();
1545
+ }
1546
+ get privateImageFrameSource() {
1547
+ return this.imageFrameSource;
1544
1548
  }
1545
1549
  getCurrentState() {
1546
1550
  return __awaiter(this, void 0, void 0, function* () {
1547
- const result = yield this._proxy.getCurrentCameraState(this.imageFrameSource.position);
1551
+ const result = yield this._proxy.$getCurrentCameraState({ position: this.privateImageFrameSource.position });
1548
1552
  if (result == null) {
1549
1553
  return FrameSourceState.Off;
1550
1554
  }
@@ -1552,29 +1556,38 @@ class ImageFrameSourceController {
1552
1556
  });
1553
1557
  }
1554
1558
  switchCameraToDesiredState(desiredStateJson) {
1555
- return this._proxy.switchCameraToDesiredState(desiredStateJson);
1559
+ return this._proxy.$switchCameraToDesiredState({ desiredStateJson });
1556
1560
  }
1557
1561
  subscribeListener() {
1558
- var _a, _b;
1559
- this._proxy.registerListenerForEvents();
1560
- (_b = (_a = this._proxy).subscribeDidChangeState) === null || _b === void 0 ? void 0 : _b.call(_a);
1561
- this.eventEmitter.on(FrameSourceListenerEvents.didChangeState, (data) => {
1562
- const event = EventDataParser.parse(data);
1563
- if (event === null) {
1564
- console.error('ImageFrameSourceController didChangeState payload is null');
1565
- return;
1566
- }
1567
- const newState = event.state;
1568
- this.imageFrameSource.listeners.forEach(listener => {
1569
- if (listener.didChangeState) {
1570
- listener.didChangeState(this.imageFrameSource, newState);
1571
- }
1572
- });
1562
+ return __awaiter(this, void 0, void 0, function* () {
1563
+ yield this._proxy.$registerListenerForCameraEvents();
1564
+ this._proxy.subscribeForEvents([FrameSourceListenerEvents.didChangeState]);
1565
+ this._proxy.eventEmitter.on(FrameSourceListenerEvents.didChangeState, this.handleDidChangeStateEventWrapper);
1573
1566
  });
1574
1567
  }
1575
1568
  unsubscribeListener() {
1576
- this._proxy.unregisterListenerForEvents();
1577
- this.eventEmitter.removeAllListeners(FrameSourceListenerEvents.didChangeState);
1569
+ return __awaiter(this, void 0, void 0, function* () {
1570
+ yield this._proxy.$unregisterListenerForCameraEvents();
1571
+ this._proxy.unsubscribeFromEvents([FrameSourceListenerEvents.didChangeState]);
1572
+ this._proxy.eventEmitter.off(FrameSourceListenerEvents.didChangeState, this.handleDidChangeStateEventWrapper);
1573
+ });
1574
+ }
1575
+ dispose() {
1576
+ this.unsubscribeListener();
1577
+ this._proxy.dispose();
1578
+ }
1579
+ handleDidChangeStateEvent(ev) {
1580
+ const event = EventDataParser.parse(ev.data);
1581
+ if (event === null) {
1582
+ console.error('ImageFrameSourceController didChangeState payload is null');
1583
+ return;
1584
+ }
1585
+ const newState = event.state;
1586
+ this.privateImageFrameSource.listeners.forEach(listener => {
1587
+ if (listener.didChangeState) {
1588
+ listener.didChangeState(this.imageFrameSource, newState);
1589
+ }
1590
+ });
1578
1591
  }
1579
1592
  }
1580
1593
 
@@ -1610,7 +1623,7 @@ class ImageFrameSource extends DefaultSerializeable {
1610
1623
  this._desiredState = FrameSourceState.Off;
1611
1624
  this.listeners = [];
1612
1625
  this._context = null;
1613
- this.controller = ImageFrameSourceController.forImage(this);
1626
+ this.controller = new ImageFrameSourceController(this);
1614
1627
  }
1615
1628
  didChange() {
1616
1629
  if (this.context) {
@@ -1689,95 +1702,12 @@ class PrivateFrameData {
1689
1702
  }
1690
1703
  }
1691
1704
 
1692
- class BaseNewController {
1693
- get _proxy() {
1694
- return this._cachedProxy;
1695
- }
1696
- constructor(proxyName) {
1697
- this._cachedProxy = FactoryMaker.createInstance(proxyName);
1698
- }
1699
- }
1700
-
1701
- class CameraController extends BaseNewController {
1702
- static get _proxy() {
1703
- return FactoryMaker.getInstance('CameraProxy');
1704
- }
1705
- static forCamera(camera) {
1706
- const controller = new CameraController();
1707
- controller.camera = camera;
1708
- return controller;
1709
- }
1710
- constructor() {
1711
- super('CameraProxy');
1712
- }
1713
- get privateCamera() {
1714
- return this.camera;
1715
- }
1716
- static getFrame(frameId) {
1717
- return __awaiter(this, void 0, void 0, function* () {
1718
- const result = yield CameraController._proxy.$getFrame({ frameId });
1719
- if (result == null) {
1720
- return PrivateFrameData.empty();
1721
- }
1722
- const frameDataJSON = JSON.parse(result.data);
1723
- return PrivateFrameData.fromJSON(frameDataJSON);
1724
- });
1725
- }
1726
- static getFrameOrNull(frameId) {
1727
- return __awaiter(this, void 0, void 0, function* () {
1728
- const result = yield CameraController._proxy.$getFrame({ frameId });
1729
- if (result == null) {
1730
- return null;
1731
- }
1732
- const frameDataJSON = JSON.parse(result.data);
1733
- return PrivateFrameData.fromJSON(frameDataJSON);
1734
- });
1735
- }
1736
- getCurrentState() {
1737
- return __awaiter(this, void 0, void 0, function* () {
1738
- const result = yield this._proxy.$getCurrentCameraState({ position: this.privateCamera.position });
1739
- if (result == null) {
1740
- return FrameSourceState.Off;
1741
- }
1742
- return result.data;
1743
- });
1744
- }
1745
- getIsTorchAvailable() {
1746
- return __awaiter(this, void 0, void 0, function* () {
1747
- const result = yield this._proxy.$isTorchAvailable({ position: this.privateCamera.position });
1748
- if (result == null) {
1749
- return false;
1750
- }
1751
- return result.data === 'true';
1752
- });
1753
- }
1754
- switchCameraToDesiredState(desiredState) {
1755
- return this._proxy.$switchCameraToDesiredState({ desiredStateJson: desiredState.toString() });
1756
- }
1757
- subscribeListener() {
1758
- this._proxy.$registerListenerForCameraEvents();
1759
- this._proxy.subscribeForEvents([FrameSourceListenerEvents.didChangeState]);
1760
- this._proxy.eventEmitter.on(FrameSourceListenerEvents.didChangeState, this.handleDidChangeStateEvent.bind(this));
1761
- }
1762
- unsubscribeListener() {
1763
- this._proxy.$unregisterListenerForCameraEvents();
1764
- this._proxy.unsubscribeFromEvents([FrameSourceListenerEvents.didChangeState]);
1765
- this._proxy.eventEmitter.off(FrameSourceListenerEvents.didChangeState, this.handleDidChangeStateEvent.bind(this));
1766
- }
1767
- dispose() {
1768
- this.unsubscribeListener();
1769
- this._proxy.dispose();
1770
- }
1771
- handleDidChangeStateEvent(ev) {
1772
- const event = EventDataParser.parse(ev.data);
1773
- if (event) {
1774
- this.privateCamera.listeners.forEach(listener => {
1775
- var _a;
1776
- (_a = listener === null || listener === void 0 ? void 0 : listener.didChangeState) === null || _a === void 0 ? void 0 : _a.call(listener, this.camera, event.state);
1777
- });
1778
- }
1779
- }
1780
- }
1705
+ var CameraPosition;
1706
+ (function (CameraPosition) {
1707
+ CameraPosition["WorldFacing"] = "worldFacing";
1708
+ CameraPosition["UserFacing"] = "userFacing";
1709
+ CameraPosition["Unspecified"] = "unspecified";
1710
+ })(CameraPosition || (CameraPosition = {}));
1781
1711
 
1782
1712
  var TorchState;
1783
1713
  (function (TorchState) {
@@ -1796,43 +1726,31 @@ class Camera extends DefaultSerializeable {
1796
1726
  get context() {
1797
1727
  return this._context;
1798
1728
  }
1729
+ get isActiveCamera() {
1730
+ return this._context !== null;
1731
+ }
1799
1732
  static get default() {
1800
- if (Camera.coreDefaults.Camera.defaultPosition) {
1801
- const camera = new Camera();
1802
- camera.position = Camera.coreDefaults.Camera.defaultPosition;
1803
- return camera;
1804
- }
1805
- else {
1733
+ const defaultPosition = Camera.coreDefaults.Camera.defaultPosition;
1734
+ if (!defaultPosition) {
1806
1735
  return null;
1807
1736
  }
1737
+ return Camera.atPosition(defaultPosition);
1808
1738
  }
1809
1739
  static withSettings(settings) {
1810
- const camera = Camera.default;
1811
- if (camera) {
1812
- camera.settings = settings;
1813
- }
1814
- return camera;
1740
+ return Camera.create(undefined, settings);
1815
1741
  }
1816
1742
  static asPositionWithSettings(cameraPosition, settings) {
1817
- if (Camera.coreDefaults.Camera.availablePositions.includes(cameraPosition)) {
1818
- const camera = new Camera();
1819
- camera.settings = settings;
1820
- camera.position = cameraPosition;
1821
- return camera;
1822
- }
1823
- else {
1824
- return null;
1825
- }
1743
+ return Camera.create(cameraPosition, settings);
1826
1744
  }
1827
1745
  static atPosition(cameraPosition) {
1828
- if (Camera.coreDefaults.Camera.availablePositions.includes(cameraPosition)) {
1829
- const camera = new Camera();
1830
- camera.position = cameraPosition;
1831
- return camera;
1832
- }
1833
- else {
1746
+ if (!Camera.coreDefaults.Camera.availablePositions.includes(cameraPosition)) {
1834
1747
  return null;
1835
1748
  }
1749
+ const existingCamera = Camera._cameraInstances.get(cameraPosition);
1750
+ if (existingCamera) {
1751
+ return existingCamera;
1752
+ }
1753
+ return Camera.create(cameraPosition);
1836
1754
  }
1837
1755
  get desiredState() {
1838
1756
  return this._desiredState;
@@ -1844,33 +1762,66 @@ class Camera extends DefaultSerializeable {
1844
1762
  get desiredTorchState() {
1845
1763
  return this._desiredTorchState;
1846
1764
  }
1847
- constructor() {
1765
+ constructor(position, settings, desiredTorchState, desiredState) {
1848
1766
  super();
1849
1767
  this.type = 'camera';
1850
1768
  this.settings = null;
1851
1769
  this._desiredTorchState = TorchState.Off;
1852
1770
  this._desiredState = FrameSourceState.Off;
1771
+ this.currentCameraState = FrameSourceState.Off;
1853
1772
  this.listeners = [];
1854
1773
  this._context = null;
1855
- this.controller = CameraController.forCamera(this);
1774
+ this.position = position || Camera.coreDefaults.Camera.defaultPosition;
1775
+ this.settings = settings || null;
1776
+ this._desiredTorchState = desiredTorchState || TorchState.Off;
1777
+ this._desiredState = desiredState || FrameSourceState.Off;
1778
+ this.controller = new CameraController(this);
1779
+ }
1780
+ static create(position, settings, desiredTorchState, desiredState) {
1781
+ const cameraPosition = position || Camera.coreDefaults.Camera.defaultPosition;
1782
+ if (!cameraPosition) {
1783
+ return null;
1784
+ }
1785
+ const existingCamera = Camera._cameraInstances.get(cameraPosition);
1786
+ if (existingCamera) {
1787
+ if (settings !== undefined) {
1788
+ existingCamera.settings = settings;
1789
+ }
1790
+ if (desiredTorchState !== undefined) {
1791
+ existingCamera._desiredTorchState = desiredTorchState;
1792
+ existingCamera.didChange();
1793
+ }
1794
+ if (desiredState !== undefined) {
1795
+ existingCamera._desiredState = desiredState;
1796
+ existingCamera.controller.switchCameraToDesiredState(desiredState);
1797
+ }
1798
+ return existingCamera;
1799
+ }
1800
+ if (!Camera.coreDefaults.Camera.availablePositions.includes(cameraPosition)) {
1801
+ return null;
1802
+ }
1803
+ const camera = new Camera(cameraPosition, settings, desiredTorchState, desiredState);
1804
+ Camera._cameraInstances.set(cameraPosition, camera);
1805
+ return camera;
1856
1806
  }
1857
1807
  switchToDesiredState(state) {
1858
- this._desiredState = state;
1859
- return this.controller.switchCameraToDesiredState(state);
1808
+ return __awaiter(this, void 0, void 0, function* () {
1809
+ if (!this.isActiveCamera) {
1810
+ console.warn('The current camera is not added to the DataCaptureContext. Add camera to the DataCaptureContext first.');
1811
+ return;
1812
+ }
1813
+ if (state !== this.currentCameraState) {
1814
+ this._desiredState = state;
1815
+ return this.controller.switchCameraToDesiredState(state);
1816
+ }
1817
+ });
1860
1818
  }
1861
1819
  getCurrentState() {
1862
- return this.controller.getCurrentState();
1820
+ return Promise.resolve(this.currentCameraState);
1863
1821
  }
1864
1822
  getIsTorchAvailable() {
1865
1823
  return this.controller.getIsTorchAvailable();
1866
1824
  }
1867
- /**
1868
- * @deprecated
1869
- */
1870
- get isTorchAvailable() {
1871
- console.warn('isTorchAvailable is deprecated. Use getIsTorchAvailable instead.');
1872
- return false;
1873
- }
1874
1825
  addListener(listener) {
1875
1826
  if (listener == null) {
1876
1827
  return;
@@ -1891,9 +1842,6 @@ class Camera extends DefaultSerializeable {
1891
1842
  return;
1892
1843
  }
1893
1844
  this.listeners.splice(this.listeners.indexOf(listener), 1);
1894
- if (this.listeners.length === 0) {
1895
- this.controller.unsubscribeListener();
1896
- }
1897
1845
  }
1898
1846
  applySettings(settings) {
1899
1847
  this.settings = settings;
@@ -1907,6 +1855,7 @@ class Camera extends DefaultSerializeable {
1907
1855
  });
1908
1856
  }
1909
1857
  }
1858
+ Camera._cameraInstances = new Map();
1910
1859
  __decorate([
1911
1860
  serializationDefault({})
1912
1861
  ], Camera.prototype, "settings", void 0);
@@ -1914,8 +1863,11 @@ __decorate([
1914
1863
  nameForSerialization('desiredTorchState')
1915
1864
  ], Camera.prototype, "_desiredTorchState", void 0);
1916
1865
  __decorate([
1917
- ignoreFromSerialization
1866
+ nameForSerialization('desiredState')
1918
1867
  ], Camera.prototype, "_desiredState", void 0);
1868
+ __decorate([
1869
+ ignoreFromSerialization
1870
+ ], Camera.prototype, "currentCameraState", void 0);
1919
1871
  __decorate([
1920
1872
  ignoreFromSerialization
1921
1873
  ], Camera.prototype, "listeners", void 0);
@@ -1925,10 +1877,390 @@ __decorate([
1925
1877
  __decorate([
1926
1878
  ignoreFromSerialization
1927
1879
  ], Camera.prototype, "controller", void 0);
1880
+ __decorate([
1881
+ ignoreFromSerialization
1882
+ ], Camera, "_cameraInstances", void 0);
1928
1883
  __decorate([
1929
1884
  ignoreFromSerialization
1930
1885
  ], Camera, "coreDefaults", null);
1931
1886
 
1887
+ class CameraOwnershipManager {
1888
+ constructor() {
1889
+ this.owners = new Map();
1890
+ this.waitingQueue = new Map();
1891
+ this.protectedCameras = new Set();
1892
+ }
1893
+ static getInstance() {
1894
+ if (!CameraOwnershipManager.instance) {
1895
+ CameraOwnershipManager.instance = new CameraOwnershipManager();
1896
+ }
1897
+ return CameraOwnershipManager.instance;
1898
+ }
1899
+ requestOwnership(position, owner) {
1900
+ const currentOwner = this.owners.get(position);
1901
+ if (currentOwner && currentOwner.id !== owner.id) {
1902
+ return false; // Already owned by someone else
1903
+ }
1904
+ this.owners.set(position, owner);
1905
+ this.enableProtectionForOwner(position, owner);
1906
+ return true;
1907
+ }
1908
+ requestOwnershipAsync(position, owner, timeoutMs) {
1909
+ return __awaiter(this, void 0, void 0, function* () {
1910
+ // Try immediate acquisition first
1911
+ if (this.requestOwnership(position, owner)) {
1912
+ return true;
1913
+ }
1914
+ // If not available, wait in queue
1915
+ return new Promise((resolve) => {
1916
+ const request = { owner, resolve };
1917
+ if (!this.waitingQueue.has(position)) {
1918
+ this.waitingQueue.set(position, []);
1919
+ }
1920
+ this.waitingQueue.get(position).push(request);
1921
+ // Optional timeout
1922
+ if (timeoutMs && timeoutMs > 0) {
1923
+ setTimeout(() => {
1924
+ this.removeFromQueue(position, request);
1925
+ resolve(false); // Timeout - ownership not acquired
1926
+ }, timeoutMs);
1927
+ }
1928
+ });
1929
+ });
1930
+ }
1931
+ releaseOwnership(position, owner) {
1932
+ const currentOwner = this.owners.get(position);
1933
+ if (!currentOwner || currentOwner.id !== owner.id) {
1934
+ return false; // Not the owner
1935
+ }
1936
+ this.owners.delete(position);
1937
+ this.disableProtectionForPosition(position);
1938
+ this.processWaitingQueue(position);
1939
+ return true;
1940
+ }
1941
+ isOwner(position, owner) {
1942
+ const currentOwner = this.owners.get(position);
1943
+ return (currentOwner === null || currentOwner === void 0 ? void 0 : currentOwner.id) === owner.id;
1944
+ }
1945
+ getCurrentOwner(position) {
1946
+ return this.owners.get(position) || null;
1947
+ }
1948
+ checkOwnership(position, owner) {
1949
+ return this.isOwner(position, owner);
1950
+ }
1951
+ getOwnedPosition(owner) {
1952
+ for (const [position, currentOwner] of this.owners.entries()) {
1953
+ if (currentOwner.id === owner.id) {
1954
+ return position;
1955
+ }
1956
+ }
1957
+ return null;
1958
+ }
1959
+ getAllOwnedPositions(owner) {
1960
+ const positions = [];
1961
+ for (const [position, currentOwner] of this.owners.entries()) {
1962
+ if (currentOwner.id === owner.id) {
1963
+ positions.push(position);
1964
+ }
1965
+ }
1966
+ return positions;
1967
+ }
1968
+ enableProtectionForOwner(position, owner) {
1969
+ const camera = Camera.atPosition(position);
1970
+ if (!camera || this.protectedCameras.has(camera)) {
1971
+ return; // Camera not available or already protected
1972
+ }
1973
+ this.protectCameraForOwner(camera, position, owner);
1974
+ this.protectedCameras.add(camera);
1975
+ }
1976
+ disableProtectionForPosition(position) {
1977
+ const camera = Camera.atPosition(position);
1978
+ if (!camera || !this.protectedCameras.has(camera)) {
1979
+ return;
1980
+ }
1981
+ this.unprotectCamera(camera);
1982
+ this.protectedCameras.delete(camera);
1983
+ }
1984
+ processWaitingQueue(position) {
1985
+ const queue = this.waitingQueue.get(position);
1986
+ if (!queue || queue.length === 0) {
1987
+ return;
1988
+ }
1989
+ // Give ownership to the first in queue
1990
+ const nextRequest = queue.shift();
1991
+ this.owners.set(position, nextRequest.owner);
1992
+ this.enableProtectionForOwner(position, nextRequest.owner);
1993
+ nextRequest.resolve(true);
1994
+ // Clean up empty queue
1995
+ if (queue.length === 0) {
1996
+ this.waitingQueue.delete(position);
1997
+ }
1998
+ }
1999
+ removeFromQueue(position, requestToRemove) {
2000
+ const queue = this.waitingQueue.get(position);
2001
+ if (!queue)
2002
+ return;
2003
+ const index = queue.indexOf(requestToRemove);
2004
+ if (index > -1) {
2005
+ queue.splice(index, 1);
2006
+ }
2007
+ if (queue.length === 0) {
2008
+ this.waitingQueue.delete(position);
2009
+ }
2010
+ }
2011
+ protectCameraForOwner(camera, position, _owner) {
2012
+ var _a, _b, _c;
2013
+ const originalSwitchToDesiredState = camera.switchToDesiredState.bind(camera);
2014
+ const originalApplySettings = camera.applySettings.bind(camera);
2015
+ const originalSetDesiredTorchState = (_b = (_a = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(camera), 'desiredTorchState')) === null || _a === void 0 ? void 0 : _a.set) === null || _b === void 0 ? void 0 : _b.bind(camera);
2016
+ // Protect switchToDesiredState - only owner can call it
2017
+ camera.switchToDesiredState = (state) => __awaiter(this, void 0, void 0, function* () {
2018
+ const currentOwner = this.getCurrentOwner(position);
2019
+ if (!currentOwner) {
2020
+ throw new Error(`Camera operation denied: No owner for camera at ${position}`);
2021
+ }
2022
+ // Allow operation - the owner is the only one who should have access to this camera instance
2023
+ return originalSwitchToDesiredState(state);
2024
+ });
2025
+ // Protect applySettings - only owner can call it
2026
+ camera.applySettings = (settings) => __awaiter(this, void 0, void 0, function* () {
2027
+ const currentOwner = this.getCurrentOwner(position);
2028
+ if (!currentOwner) {
2029
+ throw new Error(`Camera operation denied: No owner for camera at ${position}`);
2030
+ }
2031
+ return originalApplySettings(settings);
2032
+ });
2033
+ // Protect desiredTorchState setter - only owner can set it
2034
+ if (originalSetDesiredTorchState) {
2035
+ Object.defineProperty(camera, 'desiredTorchState', {
2036
+ set: (value) => {
2037
+ const currentOwner = this.getCurrentOwner(position);
2038
+ if (!currentOwner) {
2039
+ throw new Error(`Camera operation denied: No owner for camera at ${position}`);
2040
+ }
2041
+ originalSetDesiredTorchState(value);
2042
+ },
2043
+ get: (_c = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(camera), 'desiredTorchState')) === null || _c === void 0 ? void 0 : _c.get,
2044
+ configurable: true
2045
+ });
2046
+ }
2047
+ // Store originals for restoration
2048
+ camera.__originalMethods = {
2049
+ switchToDesiredState: originalSwitchToDesiredState,
2050
+ applySettings: originalApplySettings,
2051
+ setDesiredTorchState: originalSetDesiredTorchState
2052
+ };
2053
+ }
2054
+ unprotectCamera(camera) {
2055
+ var _a;
2056
+ const originals = camera.__originalMethods;
2057
+ if (!originals)
2058
+ return;
2059
+ // Restore original methods
2060
+ camera.switchToDesiredState = originals.switchToDesiredState;
2061
+ camera.applySettings = originals.applySettings;
2062
+ if (originals.setDesiredTorchState) {
2063
+ Object.defineProperty(camera, 'desiredTorchState', {
2064
+ set: originals.setDesiredTorchState,
2065
+ get: (_a = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(camera), 'desiredTorchState')) === null || _a === void 0 ? void 0 : _a.get,
2066
+ configurable: true
2067
+ });
2068
+ }
2069
+ delete camera.__originalMethods;
2070
+ }
2071
+ }
2072
+
2073
+ class CameraOwnershipHelper {
2074
+ /**
2075
+ * Get camera instance for the owner (only works if you own it)
2076
+ */
2077
+ static getCamera(position, owner) {
2078
+ // Check ownership
2079
+ if (!this.ownershipManager.checkOwnership(position, owner)) {
2080
+ console.warn(`Camera access denied: ${owner.id} does not own camera at ${position}`);
2081
+ return null;
2082
+ }
2083
+ return Camera.atPosition(position);
2084
+ }
2085
+ /**
2086
+ * Safely execute camera operations (only works if you own the camera)
2087
+ */
2088
+ static withCamera(position, owner, operation) {
2089
+ return __awaiter(this, void 0, void 0, function* () {
2090
+ const camera = this.getCamera(position, owner);
2091
+ if (!camera) {
2092
+ return null;
2093
+ }
2094
+ try {
2095
+ const result = yield operation(camera);
2096
+ return result;
2097
+ }
2098
+ catch (error) {
2099
+ console.error(`Camera operation failed for ${owner.id}:`, error);
2100
+ throw error;
2101
+ }
2102
+ });
2103
+ }
2104
+ /**
2105
+ * Execute camera operations, waiting for ownership if necessary
2106
+ */
2107
+ static withCameraWhenAvailable(position, owner, operation, timeoutMs) {
2108
+ return __awaiter(this, void 0, void 0, function* () {
2109
+ // Try to get ownership, wait if necessary
2110
+ const acquired = yield this.requestOwnership(position, owner, timeoutMs);
2111
+ if (!acquired) {
2112
+ console.warn(`Could not acquire camera ownership for ${owner.id} within timeout`);
2113
+ return null;
2114
+ }
2115
+ const camera = Camera.atPosition(position);
2116
+ if (!camera) {
2117
+ console.warn(`Camera not available at position ${position}`);
2118
+ return null;
2119
+ }
2120
+ try {
2121
+ const result = yield operation(camera);
2122
+ return result;
2123
+ }
2124
+ catch (error) {
2125
+ console.error(`Camera operation failed for ${owner.id}:`, error);
2126
+ throw error;
2127
+ }
2128
+ });
2129
+ }
2130
+ /**
2131
+ * Request ownership and wait if necessary
2132
+ */
2133
+ static requestOwnership(position, owner, timeoutMs) {
2134
+ return __awaiter(this, void 0, void 0, function* () {
2135
+ return this.ownershipManager.requestOwnershipAsync(position, owner, timeoutMs);
2136
+ });
2137
+ }
2138
+ /**
2139
+ * Release ownership
2140
+ */
2141
+ static releaseOwnership(position, owner) {
2142
+ return this.ownershipManager.releaseOwnership(position, owner);
2143
+ }
2144
+ /**
2145
+ * Check if owner has ownership
2146
+ */
2147
+ static hasOwnership(position, owner) {
2148
+ return this.ownershipManager.checkOwnership(position, owner);
2149
+ }
2150
+ /**
2151
+ * Get the camera position currently owned by the owner (if any)
2152
+ */
2153
+ static getOwnedPosition(owner) {
2154
+ return this.ownershipManager.getOwnedPosition(owner);
2155
+ }
2156
+ /**
2157
+ * Get all camera positions currently owned by the owner
2158
+ */
2159
+ static getAllOwnedPositions(owner) {
2160
+ return this.ownershipManager.getAllOwnedPositions(owner);
2161
+ }
2162
+ /**
2163
+ * Release ownership of all cameras owned by the owner
2164
+ */
2165
+ static releaseAllOwnerships(owner) {
2166
+ const ownedPositions = this.getAllOwnedPositions(owner);
2167
+ for (const position of ownedPositions) {
2168
+ this.releaseOwnership(position, owner);
2169
+ }
2170
+ }
2171
+ }
2172
+ CameraOwnershipHelper.ownershipManager = CameraOwnershipManager.getInstance();
2173
+
2174
+ class CameraController extends BaseNewController {
2175
+ static get _proxy() {
2176
+ return FactoryMaker.getInstance('CameraProxy');
2177
+ }
2178
+ constructor(camera) {
2179
+ super('CameraProxy');
2180
+ // Arrow function wrapper to avoid .bind(this) and always use current class state
2181
+ this.handleDidChangeStateEventWrapper = (ev) => {
2182
+ return this.handleDidChangeStateEvent(ev);
2183
+ };
2184
+ this.camera = camera;
2185
+ this.subscribeListener();
2186
+ }
2187
+ get privateCamera() {
2188
+ return this.camera;
2189
+ }
2190
+ static getFrame(frameId) {
2191
+ return __awaiter(this, void 0, void 0, function* () {
2192
+ const result = yield CameraController._proxy.$getFrame({ frameId });
2193
+ if (result == null) {
2194
+ return PrivateFrameData.empty();
2195
+ }
2196
+ const frameDataJSON = JSON.parse(result.data);
2197
+ return PrivateFrameData.fromJSON(frameDataJSON);
2198
+ });
2199
+ }
2200
+ static getFrameOrNull(frameId) {
2201
+ return __awaiter(this, void 0, void 0, function* () {
2202
+ const result = yield CameraController._proxy.$getFrame({ frameId });
2203
+ if (result == null) {
2204
+ return null;
2205
+ }
2206
+ const frameDataJSON = JSON.parse(result.data);
2207
+ return PrivateFrameData.fromJSON(frameDataJSON);
2208
+ });
2209
+ }
2210
+ getCurrentState() {
2211
+ return __awaiter(this, void 0, void 0, function* () {
2212
+ const result = yield this._proxy.$getCurrentCameraState({ position: this.privateCamera.position });
2213
+ if (result == null) {
2214
+ return FrameSourceState.Off;
2215
+ }
2216
+ return result.data;
2217
+ });
2218
+ }
2219
+ getIsTorchAvailable() {
2220
+ return __awaiter(this, void 0, void 0, function* () {
2221
+ const result = yield this._proxy.$isTorchAvailable({ position: this.privateCamera.position });
2222
+ if (result == null) {
2223
+ return false;
2224
+ }
2225
+ return result.data === 'true';
2226
+ });
2227
+ }
2228
+ switchCameraToDesiredState(desiredState) {
2229
+ return this._proxy.$switchCameraToDesiredState({ desiredStateJson: desiredState.toString() });
2230
+ }
2231
+ subscribeListener() {
2232
+ return __awaiter(this, void 0, void 0, function* () {
2233
+ yield this._proxy.$registerListenerForCameraEvents();
2234
+ this._proxy.subscribeForEvents([FrameSourceListenerEvents.didChangeState]);
2235
+ this._proxy.eventEmitter.on(FrameSourceListenerEvents.didChangeState, this.handleDidChangeStateEventWrapper);
2236
+ });
2237
+ }
2238
+ unsubscribeListener() {
2239
+ return __awaiter(this, void 0, void 0, function* () {
2240
+ yield this._proxy.$unregisterListenerForCameraEvents();
2241
+ this._proxy.unsubscribeFromEvents([FrameSourceListenerEvents.didChangeState]);
2242
+ this._proxy.eventEmitter.off(FrameSourceListenerEvents.didChangeState, this.handleDidChangeStateEventWrapper);
2243
+ });
2244
+ }
2245
+ dispose() {
2246
+ this.unsubscribeListener();
2247
+ this._proxy.dispose();
2248
+ }
2249
+ handleDidChangeStateEvent(ev) {
2250
+ const event = EventDataParser.parse(ev.data);
2251
+ if (event) {
2252
+ if (event.cameraPosition !== this.privateCamera.position || !this.privateCamera.isActiveCamera) {
2253
+ return;
2254
+ }
2255
+ this.privateCamera.currentCameraState = event.state;
2256
+ this.privateCamera.listeners.forEach(listener => {
2257
+ var _a;
2258
+ (_a = listener === null || listener === void 0 ? void 0 : listener.didChangeState) === null || _a === void 0 ? void 0 : _a.call(listener, this.camera, this.privateCamera._desiredState);
2259
+ });
2260
+ }
2261
+ }
2262
+ }
2263
+
1932
2264
  class ControlImage extends DefaultSerializeable {
1933
2265
  constructor(type, data, name) {
1934
2266
  super();
@@ -2152,13 +2484,6 @@ class DataCaptureContext extends DefaultSerializeable {
2152
2484
  static get deviceID() {
2153
2485
  return DataCaptureContext.coreDefaults.deviceID;
2154
2486
  }
2155
- /**
2156
- * @deprecated
2157
- */
2158
- get deviceID() {
2159
- console.log('The instance property "deviceID" on the DataCaptureContext is deprecated, please use the static property DataCaptureContext.deviceID instead.');
2160
- return DataCaptureContext.deviceID;
2161
- }
2162
2487
  static forLicenseKey(licenseKey) {
2163
2488
  const instance = DataCaptureContext.create(licenseKey, null, null);
2164
2489
  // Call initialize to ensure the shared instance is updated.
@@ -2266,11 +2591,12 @@ class DataCaptureContext extends DefaultSerializeable {
2266
2591
  }
2267
2592
  removeModeInternal(mode) {
2268
2593
  return __awaiter(this, void 0, void 0, function* () {
2269
- if (this.modes.includes(mode)) {
2270
- this.modes.splice(this.modes.indexOf(mode), 1);
2271
- mode._context = null;
2272
- this.controller.removeModeFromContext(mode);
2594
+ const index = this.modes.indexOf(mode);
2595
+ if (index !== -1) {
2596
+ this.modes.splice(index, 1);
2273
2597
  }
2598
+ mode._context = null;
2599
+ yield this.controller.removeModeFromContext(mode);
2274
2600
  });
2275
2601
  }
2276
2602
  removeAllModes() {
@@ -2522,20 +2848,24 @@ class BaseDataCaptureView extends DefaultSerializeable {
2522
2848
  this.controller = new DataCaptureViewController(this);
2523
2849
  }
2524
2850
  addOverlay(overlay) {
2525
- if (this.overlays.includes(overlay)) {
2526
- return;
2527
- }
2528
- overlay.view = this;
2529
- this.overlays.push(overlay);
2530
- this.controller.updateView();
2851
+ return __awaiter(this, void 0, void 0, function* () {
2852
+ if (this.overlays.includes(overlay)) {
2853
+ return;
2854
+ }
2855
+ overlay.view = this;
2856
+ this.overlays.push(overlay);
2857
+ yield this.controller.updateView();
2858
+ });
2531
2859
  }
2532
2860
  removeOverlay(overlay) {
2533
- if (!this.overlays.includes(overlay)) {
2534
- return;
2535
- }
2536
- overlay.view = null;
2537
- this.overlays.splice(this.overlays.indexOf(overlay), 1);
2538
- this.controller.updateView();
2861
+ return __awaiter(this, void 0, void 0, function* () {
2862
+ if (!this.overlays.includes(overlay)) {
2863
+ return;
2864
+ }
2865
+ overlay.view = null;
2866
+ this.overlays.splice(this.overlays.indexOf(overlay), 1);
2867
+ yield this.controller.updateView();
2868
+ });
2539
2869
  }
2540
2870
  removeAllOverlays() {
2541
2871
  if (this.overlays.length === 0) {
@@ -2683,27 +3013,6 @@ __decorate([
2683
3013
  ignoreFromSerialization
2684
3014
  ], BaseDataCaptureView.prototype, "isViewCreated", void 0);
2685
3015
 
2686
- class ScreenStateManager {
2687
- constructor() {
2688
- this.activeScreenId = null;
2689
- }
2690
- static getInstance() {
2691
- if (!ScreenStateManager.instance) {
2692
- ScreenStateManager.instance = new ScreenStateManager();
2693
- }
2694
- return ScreenStateManager.instance;
2695
- }
2696
- setActiveScreen(screenId) {
2697
- if (this.activeScreenId === screenId) {
2698
- return;
2699
- }
2700
- this.activeScreenId = screenId;
2701
- }
2702
- isScreenActive(screenId) {
2703
- return (this.activeScreenId === null || this.activeScreenId === screenId);
2704
- }
2705
- }
2706
-
2707
3016
  class ZoomSwitchControl extends DefaultSerializeable {
2708
3017
  constructor() {
2709
3018
  super(...arguments);
@@ -2884,6 +3193,7 @@ __decorate([
2884
3193
 
2885
3194
  var VideoResolution;
2886
3195
  (function (VideoResolution) {
3196
+ /** @deprecated Auto is deprecated. Please use the capture mode's recommendedCameraSettings for the best results. */
2887
3197
  VideoResolution["Auto"] = "auto";
2888
3198
  VideoResolution["HD"] = "hd";
2889
3199
  VideoResolution["FullHD"] = "fullHd";
@@ -3700,5 +4010,5 @@ function createNativeProxy(nativeCaller) {
3700
4010
 
3701
4011
  createEventEmitter();
3702
4012
 
3703
- export { AdvancedInstanceAwareNativeProxy, AdvancedNativeProxy, AimerViewfinder, Anchor, BaseController, BaseDataCaptureView, BaseInstanceAwareNativeProxy, BaseNativeProxy, BaseNewController, Brush, Camera, CameraController, CameraPosition, CameraSettings, Color, ContextStatus, ControlImage, DataCaptureContext, DataCaptureContextEvents, DataCaptureContextSettings, DataCaptureViewController, DataCaptureViewEvents, DefaultSerializeable, Direction, EventDataParser, EventEmitter, Expiration, FactoryMaker, Feedback, FocusGestureStrategy, FocusRange, FontFamily, FrameDataSettings, FrameDataSettingsBuilder, FrameSourceListenerEvents, FrameSourceState, HTMLElementState, HtmlElementPosition, HtmlElementSize, ImageBuffer, ImageFrameSource, LaserlineViewfinder, LicenseInfo, LogoStyle, MarginsWithUnit, MeasureUnit, NativeProxy, NoViewfinder, NoneLocationSelection, NumberWithUnit, Observable, OpenSourceSoftwareLicenseInfo, Orientation, Point, PointWithUnit, PrivateFocusGestureDeserializer, PrivateFrameData, PrivateZoomGestureDeserializer, Quadrilateral, RadiusLocationSelection, Rect, RectWithUnit, RectangularLocationSelection, RectangularViewfinder, RectangularViewfinderAnimation, RectangularViewfinderLineStyle, RectangularViewfinderStyle, ScanIntention, ScanditIcon, ScanditIconBuilder, ScanditIconShape, ScanditIconType, ScreenStateManager, Size, SizeWithAspect, SizeWithUnit, SizeWithUnitAndAspect, SizingMode, Sound, SwipeToZoom, TapToFocus, TextAlignment, TorchState, TorchSwitchControl, Vibration, VibrationType, VideoResolution, WaveFormVibration, ZoomSwitchControl, createAdvancedInstanceAwareNativeProxy, createAdvancedNativeFromCtorProxy, createAdvancedNativeProxy, createNativeProxy, getCoreDefaults, ignoreFromSerialization, ignoreFromSerializationIfNull, loadCoreDefaults, nameForSerialization, serializationDefault };
4013
+ export { AdvancedInstanceAwareNativeProxy, AdvancedNativeProxy, AimerViewfinder, Anchor, BaseController, BaseDataCaptureView, BaseInstanceAwareNativeProxy, BaseNativeProxy, BaseNewController, Brush, Camera, CameraController, CameraOwnershipHelper, CameraOwnershipManager, CameraPosition, CameraSettings, Color, ContextStatus, ControlImage, DataCaptureContext, DataCaptureContextEvents, DataCaptureContextSettings, DataCaptureViewController, DataCaptureViewEvents, DefaultSerializeable, Direction, EventDataParser, EventEmitter, Expiration, FactoryMaker, Feedback, FocusGestureStrategy, FocusRange, FontFamily, FrameDataSettings, FrameDataSettingsBuilder, FrameSourceListenerEvents, FrameSourceState, HTMLElementState, HtmlElementPosition, HtmlElementSize, ImageBuffer, ImageFrameSource, LaserlineViewfinder, LicenseInfo, LogoStyle, MarginsWithUnit, MeasureUnit, NativeProxy, NoViewfinder, NoneLocationSelection, NumberWithUnit, Observable, OpenSourceSoftwareLicenseInfo, Orientation, Point, PointWithUnit, PrivateFocusGestureDeserializer, PrivateFrameData, PrivateZoomGestureDeserializer, Quadrilateral, RadiusLocationSelection, Rect, RectWithUnit, RectangularLocationSelection, RectangularViewfinder, RectangularViewfinderAnimation, RectangularViewfinderLineStyle, RectangularViewfinderStyle, ScanIntention, ScanditIcon, ScanditIconBuilder, ScanditIconShape, ScanditIconType, Size, SizeWithAspect, SizeWithUnit, SizeWithUnitAndAspect, SizingMode, Sound, SwipeToZoom, TapToFocus, TextAlignment, TorchState, TorchSwitchControl, Vibration, VibrationType, VideoResolution, WaveFormVibration, ZoomSwitchControl, createAdvancedInstanceAwareNativeProxy, createAdvancedNativeFromCtorProxy, createAdvancedNativeProxy, createNativeProxy, getCoreDefaults, ignoreFromSerialization, ignoreFromSerializationIfNull, loadCoreDefaults, nameForSerialization, serializationDefault };
3704
4014
  //# sourceMappingURL=index.js.map