@fishjam-cloud/react-client 0.14.0 → 0.14.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 (115) hide show
  1. package/dist/FishjamProvider.d.ts.map +1 -1
  2. package/dist/FishjamProvider.js +37 -41
  3. package/dist/contexts/camera.d.ts +8 -0
  4. package/dist/contexts/camera.d.ts.map +1 -0
  5. package/dist/contexts/camera.js +2 -0
  6. package/dist/contexts/fishjamClient.d.ts +4 -0
  7. package/dist/contexts/fishjamClient.d.ts.map +1 -0
  8. package/dist/contexts/fishjamClient.js +2 -0
  9. package/dist/contexts/fishjamState.d.ts +3 -0
  10. package/dist/contexts/fishjamState.d.ts.map +1 -0
  11. package/dist/contexts/fishjamState.js +2 -0
  12. package/dist/contexts/initDevices.d.ts +3 -0
  13. package/dist/contexts/initDevices.d.ts.map +1 -0
  14. package/dist/contexts/initDevices.js +2 -0
  15. package/dist/contexts/microphone.d.ts +8 -0
  16. package/dist/contexts/microphone.d.ts.map +1 -0
  17. package/dist/contexts/microphone.js +2 -0
  18. package/dist/contexts/peerStatus.d.ts +3 -0
  19. package/dist/contexts/peerStatus.d.ts.map +1 -0
  20. package/dist/contexts/peerStatus.js +2 -0
  21. package/dist/contexts/screenshare.d.ts +3 -0
  22. package/dist/contexts/screenshare.d.ts.map +1 -0
  23. package/dist/contexts/screenshare.js +2 -0
  24. package/dist/debug.d.ts +2 -0
  25. package/dist/debug.d.ts.map +1 -0
  26. package/dist/debug.js +1 -0
  27. package/dist/devices/constraints.d.ts.map +1 -1
  28. package/dist/devices/mediaInitializer.d.ts +7 -6
  29. package/dist/devices/mediaInitializer.d.ts.map +1 -1
  30. package/dist/devices/mediaInitializer.js +14 -15
  31. package/dist/hooks/devices/useCamera.d.ts +2 -2
  32. package/dist/hooks/devices/useCamera.d.ts.map +1 -1
  33. package/dist/hooks/devices/useCamera.js +18 -10
  34. package/dist/hooks/devices/useInitializeDevices.d.ts +1 -6
  35. package/dist/hooks/devices/useInitializeDevices.d.ts.map +1 -1
  36. package/dist/hooks/devices/useInitializeDevices.js +5 -45
  37. package/dist/hooks/devices/useMicrophone.d.ts +2 -2
  38. package/dist/hooks/devices/useMicrophone.d.ts.map +1 -1
  39. package/dist/hooks/devices/useMicrophone.js +19 -11
  40. package/dist/hooks/internal/devices/useDeviceManager.d.ts +29 -0
  41. package/dist/hooks/internal/devices/useDeviceManager.d.ts.map +1 -0
  42. package/dist/hooks/internal/devices/useDeviceManager.js +95 -0
  43. package/dist/hooks/internal/devices/useHandleStreamEnd.d.ts +9 -0
  44. package/dist/hooks/internal/devices/useHandleStreamEnd.d.ts.map +1 -0
  45. package/dist/hooks/internal/devices/useHandleStreamEnd.js +13 -0
  46. package/dist/hooks/internal/devices/useMediaDevices.d.ts +16 -0
  47. package/dist/hooks/internal/devices/useMediaDevices.d.ts.map +1 -0
  48. package/dist/hooks/internal/devices/useMediaDevices.js +108 -0
  49. package/dist/hooks/internal/usePeerStatus.d.ts +1 -4
  50. package/dist/hooks/internal/usePeerStatus.d.ts.map +1 -1
  51. package/dist/hooks/internal/usePeerStatus.js +3 -9
  52. package/dist/hooks/internal/useReconnection.d.ts.map +1 -1
  53. package/dist/hooks/internal/useReconnection.js +5 -3
  54. package/dist/hooks/internal/useScreenshareManager.d.ts +3 -3
  55. package/dist/hooks/internal/useScreenshareManager.d.ts.map +1 -1
  56. package/dist/hooks/internal/useScreenshareManager.js +25 -9
  57. package/dist/hooks/internal/useTrackManager.d.ts +6 -6
  58. package/dist/hooks/internal/useTrackManager.d.ts.map +1 -1
  59. package/dist/hooks/internal/useTrackManager.js +99 -108
  60. package/dist/hooks/internal/useTrackMiddleware.d.ts +7 -0
  61. package/dist/hooks/internal/useTrackMiddleware.d.ts.map +1 -0
  62. package/dist/hooks/internal/useTrackMiddleware.js +26 -0
  63. package/dist/hooks/useConnection.d.ts +4 -4
  64. package/dist/hooks/useConnection.d.ts.map +1 -1
  65. package/dist/hooks/useConnection.js +10 -6
  66. package/dist/hooks/usePeers.d.ts.map +1 -1
  67. package/dist/hooks/usePeers.js +5 -2
  68. package/dist/hooks/useScreenShare.d.ts.map +1 -1
  69. package/dist/hooks/useScreenShare.js +5 -2
  70. package/dist/hooks/useStatistics.d.ts +4 -0
  71. package/dist/hooks/useStatistics.d.ts.map +1 -0
  72. package/dist/hooks/useStatistics.js +13 -0
  73. package/dist/hooks/useUpdatePeerMetadata.d.ts.map +1 -1
  74. package/dist/hooks/useUpdatePeerMetadata.js +5 -3
  75. package/dist/hooks/useVAD.d.ts.map +1 -1
  76. package/dist/hooks/useVAD.js +7 -7
  77. package/dist/index.d.ts +2 -2
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +1 -1
  80. package/dist/types/internal.d.ts +9 -40
  81. package/dist/types/internal.d.ts.map +1 -1
  82. package/dist/types/public.d.ts +11 -13
  83. package/dist/types/public.d.ts.map +1 -1
  84. package/dist/utils/bandwidth.d.ts.map +1 -1
  85. package/dist/utils/errors.d.ts +1 -1
  86. package/dist/utils/errors.d.ts.map +1 -1
  87. package/dist/utils/errors.js +2 -2
  88. package/dist/utils/localStorage.d.ts +3 -2
  89. package/dist/utils/localStorage.d.ts.map +1 -1
  90. package/dist/utils/localStorage.js +3 -14
  91. package/dist/utils/track.d.ts +3 -1
  92. package/dist/utils/track.d.ts.map +1 -1
  93. package/dist/utils/track.js +16 -4
  94. package/package.json +11 -11
  95. package/dist/devices/DeviceManager.d.ts +0 -65
  96. package/dist/devices/DeviceManager.d.ts.map +0 -1
  97. package/dist/devices/DeviceManager.js +0 -188
  98. package/dist/devices/MiddlewareManager.d.ts +0 -9
  99. package/dist/devices/MiddlewareManager.d.ts.map +0 -1
  100. package/dist/devices/MiddlewareManager.js +0 -26
  101. package/dist/hooks/internal/device/useDeviceApi.d.ts +0 -8
  102. package/dist/hooks/internal/device/useDeviceApi.d.ts.map +0 -1
  103. package/dist/hooks/internal/device/useDeviceApi.js +0 -28
  104. package/dist/hooks/internal/device/useDeviceManager.d.ts +0 -4
  105. package/dist/hooks/internal/device/useDeviceManager.d.ts.map +0 -1
  106. package/dist/hooks/internal/device/useDeviceManager.js +0 -41
  107. package/dist/hooks/internal/useFishjamClient_DO_NOT_USE.d.ts +0 -7
  108. package/dist/hooks/internal/useFishjamClient_DO_NOT_USE.d.ts.map +0 -1
  109. package/dist/hooks/internal/useFishjamClient_DO_NOT_USE.js +0 -11
  110. package/dist/hooks/internal/useFishjamContext.d.ts +0 -22
  111. package/dist/hooks/internal/useFishjamContext.d.ts.map +0 -1
  112. package/dist/hooks/internal/useFishjamContext.js +0 -8
  113. package/dist/internal.d.ts +0 -2
  114. package/dist/internal.d.ts.map +0 -1
  115. package/dist/internal.js +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"FishjamProvider.d.ts","sourceRoot":"","sources":["../src/FishjamProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAE,KAAK,iBAAiB,EAAU,MAAM,OAAO,CAAC;AAUvD,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAyB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG/F;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC7D;;;OAGG;IACH,SAAS,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC;IACtC;;;;OAIG;IACH,WAAW,CAAC,EAAE,IAAI,CAAC,sBAAsB,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC;IAC9D;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,GAAG,yBAAyB,CAAC;IACxD;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAC3C;;OAEG;IACH,WAAW,CAAC,EAAE,YAAY,CAAC;IAC3B;;OAEG;IACH,WAAW,CAAC,EAAE,YAAY,CAAC;CAC5B;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,2CAmE1D"}
1
+ {"version":3,"file":"FishjamProvider.d.ts","sourceRoot":"","sources":["../src/FishjamProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAE,KAAK,iBAAiB,EAAmB,MAAM,OAAO,CAAC;AAehE,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAyB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI/F;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC7D;;;OAGG;IACH,SAAS,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC;IACtC;;;;OAIG;IACH,WAAW,CAAC,EAAE,IAAI,CAAC,sBAAsB,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC;IAC9D;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,GAAG,yBAAyB,CAAC;IACxD;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAC3C;;OAEG;IACH,WAAW,CAAC,EAAE,YAAY,CAAC;IAC3B;;OAEG;IACH,WAAW,CAAC,EAAE,YAAY,CAAC;CAC5B;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,2CAsE1D"}
@@ -1,67 +1,63 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { FishjamClient } from "@fishjam-cloud/ts-client";
3
- import { useRef } from "react";
3
+ import { useMemo, useRef } from "react";
4
+ import { CameraContext } from "./contexts/camera";
5
+ import { FishjamClientContext } from "./contexts/fishjamClient";
6
+ import { FishjamClientStateContext } from "./contexts/fishjamState";
7
+ import { InitDevicesContext } from "./contexts/initDevices";
8
+ import { MicrophoneContext } from "./contexts/microphone";
9
+ import { PeerStatusContext } from "./contexts/peerStatus";
10
+ import { ScreenshareContext } from "./contexts/screenshare";
4
11
  import { AUDIO_TRACK_CONSTRAINTS, VIDEO_TRACK_CONSTRAINTS } from "./devices/constraints";
5
- import { DeviceManager } from "./devices/DeviceManager";
12
+ import { useMediaDevices } from "./hooks/internal/devices/useMediaDevices";
6
13
  import { useFishjamClientState } from "./hooks/internal/useFishjamClientState";
7
- import { FishjamContext } from "./hooks/internal/useFishjamContext";
8
14
  import { usePeerStatus } from "./hooks/internal/usePeerStatus";
9
15
  import { useScreenShareManager } from "./hooks/internal/useScreenshareManager";
10
16
  import { useTrackManager } from "./hooks/internal/useTrackManager";
11
17
  import { mergeWithDefaultBandwitdthLimits } from "./utils/bandwidth";
18
+ import { getLastDevice, saveLastDevice } from "./utils/localStorage";
12
19
  /**
13
20
  * Provides the Fishjam Context
14
21
  * @category Components
15
22
  */
16
23
  export function FishjamProvider(props) {
17
24
  const fishjamClientRef = useRef(new FishjamClient({ reconnect: props.reconnect }));
18
- // HACK: This is a workaround to prevent multiple device initialization calls.
19
- // TODO to be removed in FCE-1278
20
- const devicesInitializationRef = useRef(null);
21
- const storage = props.persistLastDevice;
22
- const videoDeviceManagerRef = useRef(new DeviceManager({
23
- deviceType: "video",
24
- defaultConstraints: VIDEO_TRACK_CONSTRAINTS,
25
- userConstraints: props.constraints?.video,
26
- storage,
27
- }));
28
- const audioDeviceManagerRef = useRef(new DeviceManager({
29
- deviceType: "audio",
30
- defaultConstraints: AUDIO_TRACK_CONSTRAINTS,
31
- userConstraints: props.constraints?.audio,
32
- storage,
33
- }));
34
- const { peerStatus, getCurrentPeerStatus } = usePeerStatus(fishjamClientRef.current);
35
- const mergedBandwidthLimits = mergeWithDefaultBandwitdthLimits(props.bandwidthLimits);
25
+ const persistHandlers = useMemo(() => {
26
+ if (props.persistLastDevice === false)
27
+ return undefined;
28
+ if (typeof props.persistLastDevice === "object")
29
+ return props.persistLastDevice;
30
+ return { getLastDevice, saveLastDevice };
31
+ }, [props.persistLastDevice]);
32
+ const { cameraManager, microphoneManager, initializeDevices } = useMediaDevices({
33
+ videoConstraints: props.constraints?.video ?? VIDEO_TRACK_CONSTRAINTS,
34
+ audioConstraints: props.constraints?.audio ?? AUDIO_TRACK_CONSTRAINTS,
35
+ persistHandlers,
36
+ });
37
+ const peerStatus = usePeerStatus(fishjamClientRef.current);
38
+ const mergedBandwidthLimits = useMemo(() => mergeWithDefaultBandwitdthLimits(props.bandwidthLimits), [props.bandwidthLimits]);
36
39
  const videoTrackManager = useTrackManager({
37
- mediaManager: videoDeviceManagerRef.current,
38
40
  tsClient: fishjamClientRef.current,
39
- getCurrentPeerStatus,
41
+ peerStatus,
42
+ deviceManager: cameraManager,
40
43
  bandwidthLimits: mergedBandwidthLimits,
41
44
  streamConfig: props.videoConfig,
42
- devicesInitializationRef,
45
+ type: "camera",
43
46
  });
44
47
  const audioTrackManager = useTrackManager({
45
- mediaManager: audioDeviceManagerRef.current,
46
48
  tsClient: fishjamClientRef.current,
47
- getCurrentPeerStatus,
49
+ peerStatus,
50
+ deviceManager: microphoneManager,
48
51
  bandwidthLimits: mergedBandwidthLimits,
49
52
  streamConfig: props.audioConfig,
50
- devicesInitializationRef,
53
+ type: "microphone",
51
54
  });
52
- const screenShareManager = useScreenShareManager({ fishjamClient: fishjamClientRef.current, getCurrentPeerStatus });
53
- const clientState = useFishjamClientState(fishjamClientRef.current);
54
- const context = {
55
- fishjamClientRef,
55
+ const screenShareManager = useScreenShareManager({
56
+ fishjamClient: fishjamClientRef.current,
56
57
  peerStatus,
57
- screenShareManager,
58
- videoTrackManager,
59
- audioTrackManager,
60
- videoDeviceManagerRef,
61
- audioDeviceManagerRef,
62
- devicesInitializationRef,
63
- clientState,
64
- bandwidthLimits: mergedBandwidthLimits,
65
- };
66
- return _jsx(FishjamContext.Provider, { value: context, children: props.children });
58
+ });
59
+ const cameraContext = useMemo(() => ({ videoTrackManager, cameraManager }), [videoTrackManager, cameraManager]);
60
+ const microphoneContext = useMemo(() => ({ audioTrackManager, microphoneManager }), [audioTrackManager, microphoneManager]);
61
+ const fishjamClientState = useFishjamClientState(fishjamClientRef.current);
62
+ return (_jsx(FishjamClientContext.Provider, { value: fishjamClientRef, children: _jsx(FishjamClientStateContext.Provider, { value: fishjamClientState, children: _jsx(InitDevicesContext.Provider, { value: initializeDevices, children: _jsx(PeerStatusContext.Provider, { value: peerStatus, children: _jsx(CameraContext.Provider, { value: cameraContext, children: _jsx(MicrophoneContext.Provider, { value: microphoneContext, children: _jsx(ScreenshareContext.Provider, { value: screenShareManager, children: props.children }) }) }) }) }) }) }));
67
63
  }
@@ -0,0 +1,8 @@
1
+ import type { DeviceManager } from "../hooks/internal/devices/useDeviceManager";
2
+ import type { TrackManager } from "../types/internal";
3
+ export type CameraContextType = {
4
+ videoTrackManager: TrackManager;
5
+ cameraManager: DeviceManager;
6
+ };
7
+ export declare const CameraContext: import("react").Context<CameraContextType | null>;
8
+ //# sourceMappingURL=camera.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"camera.d.ts","sourceRoot":"","sources":["../../src/contexts/camera.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAChF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,iBAAiB,EAAE,YAAY,CAAC;IAChC,aAAa,EAAE,aAAa,CAAC;CAC9B,CAAC;AAEF,eAAO,MAAM,aAAa,mDAAgD,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { createContext } from "react";
2
+ export const CameraContext = createContext(null);
@@ -0,0 +1,4 @@
1
+ import type { FishjamClient } from "@fishjam-cloud/ts-client";
2
+ import { type RefObject } from "react";
3
+ export declare const FishjamClientContext: import("react").Context<RefObject<FishjamClient<import("@fishjam-cloud/ts-client").GenericMetadata, import("@fishjam-cloud/ts-client").GenericMetadata>> | null>;
4
+ //# sourceMappingURL=fishjamClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fishjamClient.d.ts","sourceRoot":"","sources":["../../src/contexts/fishjamClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAiB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEtD,eAAO,MAAM,oBAAoB,kKAAuD,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { createContext } from "react";
2
+ export const FishjamClientContext = createContext(null);
@@ -0,0 +1,3 @@
1
+ import type { FishjamClientState } from "../hooks/internal/useFishjamClientState";
2
+ export declare const FishjamClientStateContext: import("react").Context<FishjamClientState<import("@fishjam-cloud/ts-client").GenericMetadata, import("@fishjam-cloud/ts-client").GenericMetadata> | null>;
3
+ //# sourceMappingURL=fishjamState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fishjamState.d.ts","sourceRoot":"","sources":["../../src/contexts/fishjamState.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAElF,eAAO,MAAM,yBAAyB,4JAAiD,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { createContext } from "react";
2
+ export const FishjamClientStateContext = createContext(null);
@@ -0,0 +1,3 @@
1
+ import type { InitializeDevicesResult } from "../types/public";
2
+ export declare const InitDevicesContext: import("react").Context<(() => Promise<InitializeDevicesResult>) | null>;
3
+ //# sourceMappingURL=initDevices.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initDevices.d.ts","sourceRoot":"","sources":["../../src/contexts/initDevices.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE/D,eAAO,MAAM,kBAAkB,iCAAwB,OAAO,CAAC,uBAAuB,CAAC,SAAe,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { createContext } from "react";
2
+ export const InitDevicesContext = createContext(null);
@@ -0,0 +1,8 @@
1
+ import type { DeviceManager } from "../hooks/internal/devices/useDeviceManager";
2
+ import type { TrackManager } from "../types/internal";
3
+ export type MicrophoneContextType = {
4
+ audioTrackManager: TrackManager;
5
+ microphoneManager: DeviceManager;
6
+ };
7
+ export declare const MicrophoneContext: import("react").Context<MicrophoneContextType | null>;
8
+ //# sourceMappingURL=microphone.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"microphone.d.ts","sourceRoot":"","sources":["../../src/contexts/microphone.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAChF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,MAAM,MAAM,qBAAqB,GAAG;IAClC,iBAAiB,EAAE,YAAY,CAAC;IAChC,iBAAiB,EAAE,aAAa,CAAC;CAClC,CAAC;AAEF,eAAO,MAAM,iBAAiB,uDAAoD,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { createContext } from "react";
2
+ export const MicrophoneContext = createContext(null);
@@ -0,0 +1,3 @@
1
+ import type { PeerStatus } from "../types/public";
2
+ export declare const PeerStatusContext: import("react").Context<PeerStatus>;
3
+ //# sourceMappingURL=peerStatus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"peerStatus.d.ts","sourceRoot":"","sources":["../../src/contexts/peerStatus.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,eAAO,MAAM,iBAAiB,qCAAoC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { createContext } from "react";
2
+ export const PeerStatusContext = createContext("idle");
@@ -0,0 +1,3 @@
1
+ import type { UseScreenshareResult } from "../hooks/internal/useScreenshareManager";
2
+ export declare const ScreenshareContext: import("react").Context<UseScreenshareResult | null>;
3
+ //# sourceMappingURL=screenshare.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screenshare.d.ts","sourceRoot":"","sources":["../../src/contexts/screenshare.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAEpF,eAAO,MAAM,kBAAkB,sDAAmD,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { createContext } from "react";
2
+ export const ScreenshareContext = createContext(null);
@@ -0,0 +1,2 @@
1
+ export { useStatistics } from "./hooks/useStatistics";
2
+ //# sourceMappingURL=debug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC"}
package/dist/debug.js ADDED
@@ -0,0 +1 @@
1
+ export { useStatistics } from "./hooks/useStatistics";
@@ -1 +1 @@
1
- {"version":3,"file":"constraints.d.ts","sourceRoot":"","sources":["../../src/devices/constraints.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,EAAE,qBAErC,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,qBAerC,CAAC;AAEF,eAAO,MAAM,gCAAgC,EAAE,sBAM9C,CAAC;AAEF,eAAO,MAAM,4BAA4B,aAC7B,MAAM,GAAG,SAAS,eACf,qBAAqB,GAAG,SAAS,GAAG,OAAO,KACvD,qBAAqB,GAAG,OAM1B,CAAC;AAEF,eAAO,MAAM,kBAAkB,oBACZ,MAAM,GAAG,SAAS,eACtB,qBAAqB,GAAG,SAAS,GAAG,OAAO,KACvD,qBAAqB,GAAG,SAAS,GAAG,OAUtC,CAAC"}
1
+ {"version":3,"file":"constraints.d.ts","sourceRoot":"","sources":["../../src/devices/constraints.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,EAAE,qBAErC,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,qBAerC,CAAC;AAEF,eAAO,MAAM,gCAAgC,EAAE,sBAM9C,CAAC;AAEF,eAAO,MAAM,4BAA4B,GACvC,UAAU,MAAM,GAAG,SAAS,EAC5B,aAAa,qBAAqB,GAAG,SAAS,GAAG,OAAO,KACvD,qBAAqB,GAAG,OAM1B,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,iBAAiB,MAAM,GAAG,SAAS,EACnC,aAAa,qBAAqB,GAAG,SAAS,GAAG,OAAO,KACvD,qBAAqB,GAAG,SAAS,GAAG,OAUtC,CAAC"}
@@ -1,11 +1,12 @@
1
+ import type { AudioVideo } from "../types/internal";
1
2
  import type { DeviceError } from "../types/public";
2
- type AudioVideo<T> = {
3
- audio: T;
4
- video: T;
5
- };
6
3
  type MediaConstraints = AudioVideo<MediaTrackConstraints | undefined | boolean>;
7
4
  type PreviousDevices = AudioVideo<MediaDeviceInfo | null>;
8
- export declare const getAvailableMedia: (constraints: MediaStreamConstraints, deviceErrors?: AudioVideo<DeviceError | null>) => Promise<[MediaStream | null, AudioVideo<DeviceError | null>]>;
9
- export declare const correctDevicesOnSafari: (stream: MediaStream, deviceErrors: AudioVideo<DeviceError | null>, devices: MediaDeviceInfo[], constraints: MediaConstraints, previousDevices: PreviousDevices) => Promise<[MediaStream | null, AudioVideo<DeviceError | null>]>;
5
+ type GetMediaResult = {
6
+ stream: MediaStream | null;
7
+ errors: AudioVideo<DeviceError | null>;
8
+ };
9
+ export declare const getAvailableMedia: (constraints: MediaStreamConstraints, errors?: AudioVideo<DeviceError | null>) => Promise<GetMediaResult>;
10
+ export declare const correctDevicesOnSafari: (stream: MediaStream, errors: AudioVideo<DeviceError | null>, devices: MediaDeviceInfo[], constraints: MediaConstraints, previousDevices: PreviousDevices) => Promise<GetMediaResult>;
10
11
  export {};
11
12
  //# sourceMappingURL=mediaInitializer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mediaInitializer.d.ts","sourceRoot":"","sources":["../../src/devices/mediaInitializer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAInD,KAAK,UAAU,CAAC,CAAC,IAAI;IAAE,KAAK,EAAE,CAAC,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAE5C,KAAK,gBAAgB,GAAG,UAAU,CAAC,qBAAqB,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC;AAChF,KAAK,eAAe,GAAG,UAAU,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;AAqC1D,eAAO,MAAM,iBAAiB,gBACf,sBAAsB,iBACrB,UAAU,CAAC,WAAW,GAAG,IAAI,CAAC,KAC3C,OAAO,CAAC,CAAC,WAAW,GAAG,IAAI,EAAE,UAAU,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC,CAwB9D,CAAC;AAIF,eAAO,MAAM,sBAAsB,WACzB,WAAW,gBACL,UAAU,CAAC,WAAW,GAAG,IAAI,CAAC,WACnC,eAAe,EAAE,eACb,gBAAgB,mBACZ,eAAe,KAC/B,OAAO,CAAC,CAAC,WAAW,GAAG,IAAI,EAAE,UAAU,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC,CAsB9D,CAAC"}
1
+ {"version":3,"file":"mediaInitializer.d.ts","sourceRoot":"","sources":["../../src/devices/mediaInitializer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,mBAAmB,CAAC;AACpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAInD,KAAK,gBAAgB,GAAG,UAAU,CAAC,qBAAqB,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC;AAChF,KAAK,eAAe,GAAG,UAAU,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;AAE1D,KAAK,cAAc,GAAG;IAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;IAAC,MAAM,EAAE,UAAU,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;CAAE,CAAC;AAqC7F,eAAO,MAAM,iBAAiB,GAC5B,aAAa,sBAAsB,EACnC,SAAQ,UAAU,CAAC,WAAW,GAAG,IAAI,CAAiB,KACrD,OAAO,CAAC,cAAc,CAsBxB,CAAC;AAIF,eAAO,MAAM,sBAAsB,GACjC,QAAQ,WAAW,EACnB,QAAQ,UAAU,CAAC,WAAW,GAAG,IAAI,CAAC,EACtC,SAAS,eAAe,EAAE,EAC1B,aAAa,gBAAgB,EAC7B,iBAAiB,eAAe,KAC/B,OAAO,CAAC,cAAc,CAsBxB,CAAC"}
@@ -21,21 +21,20 @@ const getSingleMedia = async (type, constraints) => {
21
21
  const tryToGetAudioOnlyThenVideoOnly = async (constraints, initialError) => {
22
22
  const [audioStream, audioErr] = await getSingleMedia("audio", constraints.audio);
23
23
  if (audioStream)
24
- return [audioStream, { video: initialError, audio: null }];
24
+ return { stream: audioStream, errors: { video: initialError, audio: null } };
25
25
  const [videoStream, videoErr] = await getSingleMedia("video", constraints.video);
26
- return [videoStream, { audio: audioErr, video: videoErr }];
26
+ return { stream: videoStream, errors: { audio: audioErr, video: videoErr } };
27
27
  };
28
- export const getAvailableMedia = async (constraints, deviceErrors = defaultErrors) => {
28
+ export const getAvailableMedia = async (constraints, errors = defaultErrors) => {
29
29
  try {
30
- return [await navigator.mediaDevices.getUserMedia(constraints), deviceErrors];
30
+ return { stream: await navigator.mediaDevices.getUserMedia(constraints), errors };
31
31
  }
32
32
  catch (err) {
33
- const unhandledErr = { audio: UNHANDLED_ERROR, video: UNHANDLED_ERROR };
34
33
  if (err instanceof DOMException) {
35
34
  switch (err.name) {
36
- case deviceErrors.audio?.name:
37
- case deviceErrors.video?.name:
38
- return [null, deviceErrors];
35
+ case errors.audio?.name:
36
+ case errors.video?.name:
37
+ return { stream: null, errors };
39
38
  case "NotFoundError":
40
39
  return tryToGetAudioOnlyThenVideoOnly(constraints, PERMISSION_DENIED);
41
40
  case "OverconstrainedError":
@@ -44,25 +43,25 @@ export const getAvailableMedia = async (constraints, deviceErrors = defaultError
44
43
  return tryToGetAudioOnlyThenVideoOnly(constraints, PERMISSION_DENIED);
45
44
  }
46
45
  }
47
- return [null, unhandledErr];
46
+ return { stream: null, errors: { audio: UNHANDLED_ERROR, video: UNHANDLED_ERROR } };
48
47
  }
49
48
  };
50
49
  // Safari changes deviceId between sessions, therefore we cannot rely on deviceId for identification purposes.
51
50
  // We can switch a random device that comes from safari to one that has the same label as the one used in the previous session.
52
- export const correctDevicesOnSafari = async (stream, deviceErrors, devices, constraints, previousDevices) => {
51
+ export const correctDevicesOnSafari = async (stream, errors, devices, constraints, previousDevices) => {
53
52
  const shouldCorrectDevices = isAnyDeviceDifferentFromLastSession(previousDevices.video, previousDevices.audio, getCurrentDevicesSettings(stream, devices));
54
53
  if (!shouldCorrectDevices)
55
- return [stream, deviceErrors];
54
+ return { stream, errors };
56
55
  const videoIdToStart = devices.find((info) => info.label === previousDevices.video?.label)?.deviceId;
57
56
  const audioIdToStart = devices.find((info) => info.label === previousDevices.audio?.label)?.deviceId;
58
57
  if (!videoIdToStart && !audioIdToStart)
59
- return [stream, deviceErrors];
58
+ return { stream, errors };
60
59
  stopTracks(stream);
61
60
  const exactConstraints = {
62
- video: !deviceErrors.video && prepareConstraints(videoIdToStart, constraints.video),
63
- audio: !deviceErrors.audio && prepareConstraints(audioIdToStart, constraints.audio),
61
+ video: !errors.video && prepareConstraints(videoIdToStart, constraints.video),
62
+ audio: !errors.audio && prepareConstraints(audioIdToStart, constraints.audio),
64
63
  };
65
- return await getAvailableMedia(exactConstraints, deviceErrors);
64
+ return await getAvailableMedia(exactConstraints, errors);
66
65
  };
67
66
  const getCurrentDevicesSettings = (requestedDevices, mediaDeviceInfos) => {
68
67
  const currentDevices = { videoinput: null, audioinput: null };
@@ -6,11 +6,11 @@ export declare function useCamera(): {
6
6
  /**
7
7
  * Toggles current camera on/off
8
8
  */
9
- toggleCamera: () => Promise<void>;
9
+ toggleCamera: () => Promise<undefined | import("../..").DeviceError>;
10
10
  /**
11
11
  * Selects the camera device
12
12
  */
13
- selectCamera: (deviceId?: string) => Promise<void>;
13
+ selectCamera: (deviceId?: string) => Promise<undefined | import("../..").DeviceError>;
14
14
  /**
15
15
  * Indicates which camera is now turned on and streaming
16
16
  */
@@ -1 +1 @@
1
- {"version":3,"file":"useCamera.d.ts","sourceRoot":"","sources":["../../../src/hooks/devices/useCamera.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,SAAS;IAKrB;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;EAGN"}
1
+ {"version":3,"file":"useCamera.d.ts","sourceRoot":"","sources":["../../../src/hooks/devices/useCamera.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAgB,SAAS;IAarB;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;EAGN"}
@@ -1,12 +1,20 @@
1
- import { useDeviceApi } from "../internal/device/useDeviceApi";
2
- import { useFishjamContext } from "../internal/useFishjamContext";
1
+ import { useContext, useMemo } from "react";
2
+ import { CameraContext } from "../../contexts/camera";
3
3
  /**
4
4
  * This hook can toggle camera on/off, change camera, provides current camera and other.
5
5
  * @category Devices
6
6
  */
7
7
  export function useCamera() {
8
- const { videoTrackManager, videoDeviceManagerRef } = useFishjamContext();
9
- const deviceApi = useDeviceApi({ deviceManager: videoDeviceManagerRef.current });
8
+ const cameraCtx = useContext(CameraContext);
9
+ if (!cameraCtx)
10
+ throw Error("useCamera must be used within CameraProvider");
11
+ const { videoTrackManager, cameraManager } = cameraCtx;
12
+ const cameraStream = useMemo(() => {
13
+ const track = videoTrackManager.deviceTrack;
14
+ if (!track)
15
+ return null;
16
+ return new MediaStream([track]);
17
+ }, [videoTrackManager.deviceTrack]);
10
18
  return {
11
19
  /**
12
20
  * Toggles current camera on/off
@@ -19,19 +27,19 @@ export function useCamera() {
19
27
  /**
20
28
  * Indicates which camera is now turned on and streaming
21
29
  */
22
- activeCamera: deviceApi.activeDevice,
30
+ activeCamera: cameraManager.activeDevice,
23
31
  /**
24
32
  * Indicates whether the microphone is streaming video
25
33
  */
26
- isCameraOn: !!deviceApi.mediaStream,
34
+ isCameraOn: !!cameraStream,
27
35
  /**
28
36
  * The MediaStream object containing the current stream
29
37
  */
30
- cameraStream: deviceApi.mediaStream,
38
+ cameraStream,
31
39
  /**
32
40
  * The currently set camera middleware function
33
41
  */
34
- currentCameraMiddleware: deviceApi.currentMiddleware,
42
+ currentCameraMiddleware: videoTrackManager.currentMiddleware,
35
43
  /**
36
44
  * Sets the camera middleware
37
45
  */
@@ -39,10 +47,10 @@ export function useCamera() {
39
47
  /**
40
48
  * List of available camera devices
41
49
  */
42
- cameraDevices: deviceApi.devices,
50
+ cameraDevices: cameraManager.deviceList,
43
51
  /**
44
52
  * Possible error thrown while setting up the camera
45
53
  */
46
- cameraDeviceError: deviceApi.deviceError,
54
+ cameraDeviceError: cameraManager.deviceError,
47
55
  };
48
56
  }
@@ -1,12 +1,7 @@
1
- import { type DeviceError } from "../../types/public";
2
1
  export type UseInitializeDevicesParams = {
3
2
  enableVideo?: boolean;
4
3
  enableAudio?: boolean;
5
4
  };
6
- export type InitializeDevicesErrors = {
7
- audio: DeviceError | null;
8
- video: DeviceError | null;
9
- };
10
5
  /**
11
6
  * Hook allows you to initialize access to the devices before joining the room.
12
7
  * @category Devices
@@ -15,6 +10,6 @@ export declare const useInitializeDevices: () => {
15
10
  /**
16
11
  * Initialize access to the devices before joining the room
17
12
  */
18
- initializeDevices: (params?: UseInitializeDevicesParams) => Promise<null | InitializeDevicesErrors>;
13
+ initializeDevices: () => Promise<import("../..").InitializeDevicesResult>;
19
14
  };
20
15
  //# sourceMappingURL=useInitializeDevices.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useInitializeDevices.d.ts","sourceRoot":"","sources":["../../../src/hooks/devices/useInitializeDevices.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAItD,MAAM,MAAM,0BAA0B,GAAG;IACvC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IAAE,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAAA;CAAE,CAAC;AAE/F;;;GAGG;AACH,eAAO,MAAM,oBAAoB;IA4E7B;;OAEG;iCA3E8B,0BAA0B,KAAK,OAAO,CAAC,IAAI,GAAG,uBAAuB,CAAC;CA8E1G,CAAC"}
1
+ {"version":3,"file":"useInitializeDevices.d.ts","sourceRoot":"","sources":["../../../src/hooks/devices/useInitializeDevices.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,0BAA0B,GAAG;IACvC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,oBAAoB;IAK7B;;OAEG;;CAGN,CAAC"}
@@ -1,53 +1,13 @@
1
- import { useCallback } from "react";
2
- import { prepareConstraints } from "../../devices/constraints";
3
- import { correctDevicesOnSafari, getAvailableMedia } from "../../devices/mediaInitializer";
4
- import { Deferred } from "../../utils/deferred";
5
- import { useFishjamContext } from "../internal/useFishjamContext";
1
+ import { useContext } from "react";
2
+ import { InitDevicesContext } from "../../contexts/initDevices";
6
3
  /**
7
4
  * Hook allows you to initialize access to the devices before joining the room.
8
5
  * @category Devices
9
6
  */
10
7
  export const useInitializeDevices = () => {
11
- const { videoDeviceManagerRef, audioDeviceManagerRef, devicesInitializationRef } = useFishjamContext();
12
- const initializeDevices = useCallback(async ({ enableVideo = true, enableAudio = true } = {}) => {
13
- if (devicesInitializationRef.current)
14
- return null;
15
- const deferred = new Deferred();
16
- devicesInitializationRef.current = deferred.promise;
17
- try {
18
- const videoManager = videoDeviceManagerRef.current;
19
- const audioManager = audioDeviceManagerRef.current;
20
- const constraints = {
21
- video: enableVideo && videoManager.getConstraints(),
22
- audio: enableAudio && audioManager.getConstraints(),
23
- };
24
- const previousDevices = {
25
- video: videoManager.getLastDevice(),
26
- audio: audioManager.getLastDevice(),
27
- };
28
- // Attempt to start the last selected device to avoid an unnecessary restart.
29
- // Without this, the first device will start, and `correctDevicesOnSafari` will attempt to fix it.
30
- let [stream, deviceErrors] = await getAvailableMedia({
31
- video: enableVideo && prepareConstraints(previousDevices.video?.deviceId, constraints.video),
32
- audio: enableAudio && prepareConstraints(previousDevices.audio?.deviceId, constraints.audio),
33
- });
34
- const devices = await navigator.mediaDevices.enumerateDevices();
35
- const videoDevices = devices.filter(({ kind }) => kind === "videoinput");
36
- const audioDevices = devices.filter(({ kind }) => kind === "audioinput");
37
- if (stream) {
38
- [stream, deviceErrors] = await correctDevicesOnSafari(stream, deviceErrors, devices, constraints, previousDevices);
39
- }
40
- videoManager.initialize(stream, stream?.getVideoTracks()?.[0] ?? null, videoDevices, !!constraints.video, deviceErrors.video);
41
- audioManager.initialize(stream, stream?.getAudioTracks()?.[0] ?? null, audioDevices, !!constraints.audio, deviceErrors.audio);
42
- deferred.resolve();
43
- if (deviceErrors.video || deviceErrors.audio)
44
- return deviceErrors;
45
- }
46
- catch {
47
- deferred.reject();
48
- }
49
- return null;
50
- }, [videoDeviceManagerRef, audioDeviceManagerRef, devicesInitializationRef]);
8
+ const initializeDevices = useContext(InitDevicesContext);
9
+ if (!initializeDevices)
10
+ throw Error("useInitializeDevices must be used within FishjamProvider");
51
11
  return {
52
12
  /**
53
13
  * Initialize access to the devices before joining the room
@@ -4,11 +4,11 @@
4
4
  */
5
5
  export declare function useMicrophone(): {
6
6
  /** Toggles current microphone on/off */
7
- toggleMicrophone: () => Promise<void>;
7
+ toggleMicrophone: () => Promise<undefined | import("../..").DeviceError>;
8
8
  /** Mutes/unmutes the microphone */
9
9
  toggleMicrophoneMute: () => Promise<void>;
10
10
  /** Selects the microphone device */
11
- selectMicrophone: (deviceId?: string) => Promise<void>;
11
+ selectMicrophone: (deviceId?: string) => Promise<undefined | import("../..").DeviceError>;
12
12
  /**
13
13
  * Indicates which microphone is now turned on and streaming audio
14
14
  */
@@ -1 +1 @@
1
- {"version":3,"file":"useMicrophone.d.ts","sourceRoot":"","sources":["../../../src/hooks/devices/useMicrophone.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,aAAa;IAKzB,wCAAwC;;IAExC,mCAAmC;;IAEnC,oCAAoC;;IAEpC;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;EAGN"}
1
+ {"version":3,"file":"useMicrophone.d.ts","sourceRoot":"","sources":["../../../src/hooks/devices/useMicrophone.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAgB,aAAa;IAazB,wCAAwC;;IAExC,mCAAmC;;IAEnC,oCAAoC;;IAEpC;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;EAGN"}
@@ -1,12 +1,20 @@
1
- import { useDeviceApi } from "../internal/device/useDeviceApi";
2
- import { useFishjamContext } from "../internal/useFishjamContext";
1
+ import { useContext, useMemo } from "react";
2
+ import { MicrophoneContext } from "../../contexts/microphone";
3
3
  /**
4
4
  * Manage microphone
5
5
  * @category Devices
6
6
  */
7
7
  export function useMicrophone() {
8
- const { audioTrackManager, audioDeviceManagerRef } = useFishjamContext();
9
- const deviceApi = useDeviceApi({ deviceManager: audioDeviceManagerRef.current });
8
+ const microphoneCtx = useContext(MicrophoneContext);
9
+ if (!microphoneCtx)
10
+ throw Error("useMicrophone must be used within FishjamProvider");
11
+ const { audioTrackManager, microphoneManager } = microphoneCtx;
12
+ const microphoneStream = useMemo(() => {
13
+ const track = audioTrackManager.deviceTrack;
14
+ if (!track)
15
+ return null;
16
+ return new MediaStream([track]);
17
+ }, [audioTrackManager.deviceTrack]);
10
18
  return {
11
19
  /** Toggles current microphone on/off */
12
20
  toggleMicrophone: audioTrackManager.toggleDevice,
@@ -17,23 +25,23 @@ export function useMicrophone() {
17
25
  /**
18
26
  * Indicates which microphone is now turned on and streaming audio
19
27
  */
20
- activeMicrophone: deviceApi.activeDevice,
28
+ activeMicrophone: microphoneManager.activeDevice,
21
29
  /**
22
30
  * Indicates whether the microphone is streaming audio
23
31
  */
24
- isMicrophoneOn: !!deviceApi.mediaStream,
32
+ isMicrophoneOn: !!microphoneStream,
25
33
  /**
26
34
  * Indicates whether the microphone is muted
27
35
  */
28
- isMicrophoneMuted: audioTrackManager.paused,
36
+ isMicrophoneMuted: !microphoneManager.deviceEnabled,
29
37
  /**
30
38
  * The MediaStream object containing the current audio stream
31
39
  */
32
- microphoneStream: deviceApi.mediaStream,
40
+ microphoneStream,
33
41
  /**
34
42
  * The currently set microphone middleware function
35
43
  */
36
- currentMicrophoneMiddleware: deviceApi.currentMiddleware,
44
+ currentMicrophoneMiddleware: audioTrackManager.currentMiddleware,
37
45
  /**
38
46
  * Sets the microphone middleware
39
47
  */
@@ -41,10 +49,10 @@ export function useMicrophone() {
41
49
  /**
42
50
  * List of available microphone devices
43
51
  */
44
- microphoneDevices: deviceApi.devices,
52
+ microphoneDevices: microphoneManager.deviceList,
45
53
  /**
46
54
  * Possible error thrown while setting up the microphone
47
55
  */
48
- microphoneDeviceError: deviceApi.deviceError,
56
+ microphoneDeviceError: microphoneManager.deviceError,
49
57
  };
50
58
  }
@@ -0,0 +1,29 @@
1
+ import type { SetStateAction } from "react";
2
+ import type { DeviceError, DeviceItem, TrackMiddleware } from "../../../types/public";
3
+ type DeviceManagerProps = {
4
+ mediaStream: MediaStream | null;
5
+ setMediaStream: (action: SetStateAction<MediaStream | null>) => void;
6
+ deviceError: DeviceError | null;
7
+ setDeviceError: (action: SetStateAction<DeviceError | null>) => void;
8
+ getInitialStream: () => Promise<MediaStream | null>;
9
+ deviceType: "audio" | "video";
10
+ allDevicesList: MediaDeviceInfo[];
11
+ constraints?: MediaTrackConstraints | boolean;
12
+ saveUsedDevice: (device: MediaDeviceInfo) => void;
13
+ };
14
+ export type DeviceManager = {
15
+ startDevice: (deviceId?: string) => Promise<[MediaStreamTrack, null] | [null, DeviceError]>;
16
+ stopDevice: () => void;
17
+ activeDevice: DeviceItem | null;
18
+ deviceTrack: MediaStreamTrack | null;
19
+ deviceList: DeviceItem[];
20
+ deviceEnabled: boolean;
21
+ enableDevice: () => void;
22
+ disableDevice: () => void;
23
+ currentMiddleware: TrackMiddleware;
24
+ applyMiddleware: (middleware: TrackMiddleware) => MediaStreamTrack | null;
25
+ deviceError: DeviceError | null;
26
+ };
27
+ export declare const useDeviceManager: ({ mediaStream, getInitialStream, deviceType, allDevicesList, setMediaStream, constraints, saveUsedDevice, deviceError, setDeviceError, }: DeviceManagerProps) => DeviceManager;
28
+ export {};
29
+ //# sourceMappingURL=useDeviceManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDeviceManager.d.ts","sourceRoot":"","sources":["../../../../src/hooks/internal/devices/useDeviceManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAG5C,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAKtF,KAAK,kBAAkB,GAAG;IACxB,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IAChC,cAAc,EAAE,CAAC,MAAM,EAAE,cAAc,CAAC,WAAW,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC;IACrE,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IAChC,cAAc,EAAE,CAAC,MAAM,EAAE,cAAc,CAAC,WAAW,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC;IACrE,gBAAgB,EAAE,MAAM,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IACpD,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC;IAC9B,cAAc,EAAE,eAAe,EAAE,CAAC;IAClC,WAAW,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC;IAC9C,cAAc,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,IAAI,CAAC;CACnD,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,gBAAgB,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC;IAC5F,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,YAAY,EAAE,UAAU,GAAG,IAAI,CAAC;IAChC,WAAW,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACrC,UAAU,EAAE,UAAU,EAAE,CAAC;IACzB,aAAa,EAAE,OAAO,CAAC;IACvB,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,iBAAiB,EAAE,eAAe,CAAC;IACnC,eAAe,EAAE,CAAC,UAAU,EAAE,eAAe,KAAK,gBAAgB,GAAG,IAAI,CAAC;IAC1E,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;CACjC,CAAC;AAsCF,eAAO,MAAM,gBAAgB,GAAI,0IAU9B,kBAAkB,KAAG,aAuFvB,CAAC"}