@fishjam-cloud/react-client 0.13.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.
- package/dist/FishjamProvider.d.ts.map +1 -1
- package/dist/FishjamProvider.js +37 -37
- package/dist/contexts/camera.d.ts +8 -0
- package/dist/contexts/camera.d.ts.map +1 -0
- package/dist/contexts/camera.js +2 -0
- package/dist/contexts/fishjamClient.d.ts +4 -0
- package/dist/contexts/fishjamClient.d.ts.map +1 -0
- package/dist/contexts/fishjamClient.js +2 -0
- package/dist/contexts/fishjamState.d.ts +3 -0
- package/dist/contexts/fishjamState.d.ts.map +1 -0
- package/dist/contexts/fishjamState.js +2 -0
- package/dist/contexts/initDevices.d.ts +3 -0
- package/dist/contexts/initDevices.d.ts.map +1 -0
- package/dist/contexts/initDevices.js +2 -0
- package/dist/contexts/microphone.d.ts +8 -0
- package/dist/contexts/microphone.d.ts.map +1 -0
- package/dist/contexts/microphone.js +2 -0
- package/dist/contexts/peerStatus.d.ts +3 -0
- package/dist/contexts/peerStatus.d.ts.map +1 -0
- package/dist/contexts/peerStatus.js +2 -0
- package/dist/contexts/screenshare.d.ts +3 -0
- package/dist/contexts/screenshare.d.ts.map +1 -0
- package/dist/contexts/screenshare.js +2 -0
- package/dist/debug.d.ts +2 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/debug.js +1 -0
- package/dist/devices/constraints.d.ts.map +1 -1
- package/dist/devices/mediaInitializer.d.ts +7 -6
- package/dist/devices/mediaInitializer.d.ts.map +1 -1
- package/dist/devices/mediaInitializer.js +44 -26
- package/dist/hooks/devices/useCamera.d.ts +2 -2
- package/dist/hooks/devices/useCamera.d.ts.map +1 -1
- package/dist/hooks/devices/useCamera.js +18 -10
- package/dist/hooks/devices/useInitializeDevices.d.ts +1 -1
- package/dist/hooks/devices/useInitializeDevices.d.ts.map +1 -1
- package/dist/hooks/devices/useInitializeDevices.js +5 -34
- package/dist/hooks/devices/useMicrophone.d.ts +2 -2
- package/dist/hooks/devices/useMicrophone.d.ts.map +1 -1
- package/dist/hooks/devices/useMicrophone.js +19 -11
- package/dist/hooks/internal/devices/useDeviceManager.d.ts +29 -0
- package/dist/hooks/internal/devices/useDeviceManager.d.ts.map +1 -0
- package/dist/hooks/internal/devices/useDeviceManager.js +95 -0
- package/dist/hooks/internal/devices/useHandleStreamEnd.d.ts +9 -0
- package/dist/hooks/internal/devices/useHandleStreamEnd.d.ts.map +1 -0
- package/dist/hooks/internal/devices/useHandleStreamEnd.js +13 -0
- package/dist/hooks/internal/devices/useMediaDevices.d.ts +16 -0
- package/dist/hooks/internal/devices/useMediaDevices.d.ts.map +1 -0
- package/dist/hooks/internal/devices/useMediaDevices.js +108 -0
- package/dist/hooks/internal/usePeerStatus.d.ts +1 -4
- package/dist/hooks/internal/usePeerStatus.d.ts.map +1 -1
- package/dist/hooks/internal/usePeerStatus.js +3 -9
- package/dist/hooks/internal/useReconnection.d.ts.map +1 -1
- package/dist/hooks/internal/useReconnection.js +5 -3
- package/dist/hooks/internal/useScreenshareManager.d.ts +3 -3
- package/dist/hooks/internal/useScreenshareManager.d.ts.map +1 -1
- package/dist/hooks/internal/useScreenshareManager.js +25 -9
- package/dist/hooks/internal/useTrackManager.d.ts +6 -4
- package/dist/hooks/internal/useTrackManager.d.ts.map +1 -1
- package/dist/hooks/internal/useTrackManager.js +99 -107
- package/dist/hooks/internal/useTrackMiddleware.d.ts +7 -0
- package/dist/hooks/internal/useTrackMiddleware.d.ts.map +1 -0
- package/dist/hooks/internal/useTrackMiddleware.js +26 -0
- package/dist/hooks/useConnection.d.ts +4 -4
- package/dist/hooks/useConnection.d.ts.map +1 -1
- package/dist/hooks/useConnection.js +10 -6
- package/dist/hooks/usePeers.d.ts.map +1 -1
- package/dist/hooks/usePeers.js +5 -2
- package/dist/hooks/useScreenShare.d.ts.map +1 -1
- package/dist/hooks/useScreenShare.js +5 -2
- package/dist/hooks/useStatistics.d.ts +4 -0
- package/dist/hooks/useStatistics.d.ts.map +1 -0
- package/dist/hooks/useStatistics.js +13 -0
- package/dist/hooks/useUpdatePeerMetadata.d.ts.map +1 -1
- package/dist/hooks/useUpdatePeerMetadata.js +5 -3
- package/dist/hooks/useVAD.d.ts.map +1 -1
- package/dist/hooks/useVAD.js +7 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/types/internal.d.ts +9 -40
- package/dist/types/internal.d.ts.map +1 -1
- package/dist/types/public.d.ts +11 -13
- package/dist/types/public.d.ts.map +1 -1
- package/dist/utils/bandwidth.d.ts.map +1 -1
- package/dist/utils/deferred.d.ts +9 -0
- package/dist/utils/deferred.d.ts.map +1 -0
- package/dist/utils/deferred.js +17 -0
- package/dist/utils/errors.d.ts +1 -1
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +2 -2
- package/dist/utils/localStorage.d.ts +3 -2
- package/dist/utils/localStorage.d.ts.map +1 -1
- package/dist/utils/localStorage.js +3 -14
- package/dist/utils/track.d.ts +3 -1
- package/dist/utils/track.d.ts.map +1 -1
- package/dist/utils/track.js +16 -4
- package/package.json +16 -12
- package/dist/devices/DeviceManager.d.ts +0 -64
- package/dist/devices/DeviceManager.d.ts.map +0 -1
- package/dist/devices/DeviceManager.js +0 -200
- package/dist/devices/MiddlewareManager.d.ts +0 -9
- package/dist/devices/MiddlewareManager.d.ts.map +0 -1
- package/dist/devices/MiddlewareManager.js +0 -26
- package/dist/hooks/internal/device/useDeviceApi.d.ts +0 -8
- package/dist/hooks/internal/device/useDeviceApi.d.ts.map +0 -1
- package/dist/hooks/internal/device/useDeviceApi.js +0 -28
- package/dist/hooks/internal/device/useDeviceManager.d.ts +0 -4
- package/dist/hooks/internal/device/useDeviceManager.d.ts.map +0 -1
- package/dist/hooks/internal/device/useDeviceManager.js +0 -40
- package/dist/hooks/internal/useFishjamClient_DO_NOT_USE.d.ts +0 -7
- package/dist/hooks/internal/useFishjamClient_DO_NOT_USE.d.ts.map +0 -1
- package/dist/hooks/internal/useFishjamClient_DO_NOT_USE.js +0 -11
- package/dist/hooks/internal/useFishjamContext.d.ts +0 -22
- package/dist/hooks/internal/useFishjamContext.d.ts.map +0 -1
- package/dist/hooks/internal/useFishjamContext.js +0 -8
- package/dist/internal.d.ts +0 -2
- package/dist/internal.d.ts.map +0 -1
- 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,
|
|
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"}
|
package/dist/FishjamProvider.js
CHANGED
|
@@ -1,63 +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 {
|
|
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
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const { peerStatus, getCurrentPeerStatus } = usePeerStatus(fishjamClientRef.current);
|
|
33
|
-
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]);
|
|
34
39
|
const videoTrackManager = useTrackManager({
|
|
35
|
-
mediaManager: videoDeviceManagerRef.current,
|
|
36
40
|
tsClient: fishjamClientRef.current,
|
|
37
|
-
|
|
41
|
+
peerStatus,
|
|
42
|
+
deviceManager: cameraManager,
|
|
38
43
|
bandwidthLimits: mergedBandwidthLimits,
|
|
39
44
|
streamConfig: props.videoConfig,
|
|
45
|
+
type: "camera",
|
|
40
46
|
});
|
|
41
47
|
const audioTrackManager = useTrackManager({
|
|
42
|
-
mediaManager: audioDeviceManagerRef.current,
|
|
43
48
|
tsClient: fishjamClientRef.current,
|
|
44
|
-
|
|
49
|
+
peerStatus,
|
|
50
|
+
deviceManager: microphoneManager,
|
|
45
51
|
bandwidthLimits: mergedBandwidthLimits,
|
|
46
52
|
streamConfig: props.audioConfig,
|
|
53
|
+
type: "microphone",
|
|
47
54
|
});
|
|
48
|
-
const screenShareManager = useScreenShareManager({
|
|
49
|
-
|
|
50
|
-
const context = {
|
|
51
|
-
fishjamClientRef,
|
|
55
|
+
const screenShareManager = useScreenShareManager({
|
|
56
|
+
fishjamClient: fishjamClientRef.current,
|
|
52
57
|
peerStatus,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
hasDevicesBeenInitializedRef,
|
|
59
|
-
clientState,
|
|
60
|
-
bandwidthLimits: mergedBandwidthLimits,
|
|
61
|
-
};
|
|
62
|
-
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 }) }) }) }) }) }) }));
|
|
63
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,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,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 @@
|
|
|
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,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 @@
|
|
|
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 @@
|
|
|
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"}
|
package/dist/debug.d.ts
ADDED
|
@@ -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,
|
|
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
|
-
|
|
9
|
-
|
|
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":"
|
|
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"}
|
|
@@ -1,49 +1,67 @@
|
|
|
1
1
|
import { NOT_FOUND_ERROR, OVERCONSTRAINED_ERROR, PERMISSION_DENIED, UNHANDLED_ERROR } from "../utils/errors";
|
|
2
2
|
import { prepareConstraints } from "./constraints";
|
|
3
3
|
const defaultErrors = { audio: null, video: null };
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return getAvailableMedia({ ...constraints, audio: transformConstraint(constraints.audio) }, { ...deviceErrors, video: null });
|
|
4
|
+
const errorMap = {
|
|
5
|
+
NotFoundError: NOT_FOUND_ERROR,
|
|
6
|
+
OverconstrainedError: OVERCONSTRAINED_ERROR,
|
|
7
|
+
NotAllowedError: PERMISSION_DENIED,
|
|
9
8
|
};
|
|
10
|
-
|
|
9
|
+
const getSingleMedia = async (type, constraints) => {
|
|
10
|
+
const baseConstraints = { audio: undefined, video: undefined };
|
|
11
11
|
try {
|
|
12
|
-
|
|
12
|
+
const stream = await navigator.mediaDevices.getUserMedia({ ...baseConstraints, [type]: constraints });
|
|
13
|
+
return [stream, null];
|
|
13
14
|
}
|
|
14
15
|
catch (err) {
|
|
15
16
|
if (!(err instanceof DOMException))
|
|
16
|
-
return [null,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
return [null, UNHANDLED_ERROR];
|
|
18
|
+
return [null, errorMap[err.name] ?? UNHANDLED_ERROR];
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const tryToGetAudioOnlyThenVideoOnly = async (constraints, initialError) => {
|
|
22
|
+
const [audioStream, audioErr] = await getSingleMedia("audio", constraints.audio);
|
|
23
|
+
if (audioStream)
|
|
24
|
+
return { stream: audioStream, errors: { video: initialError, audio: null } };
|
|
25
|
+
const [videoStream, videoErr] = await getSingleMedia("video", constraints.video);
|
|
26
|
+
return { stream: videoStream, errors: { audio: audioErr, video: videoErr } };
|
|
27
|
+
};
|
|
28
|
+
export const getAvailableMedia = async (constraints, errors = defaultErrors) => {
|
|
29
|
+
try {
|
|
30
|
+
return { stream: await navigator.mediaDevices.getUserMedia(constraints), errors };
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
if (err instanceof DOMException) {
|
|
34
|
+
switch (err.name) {
|
|
35
|
+
case errors.audio?.name:
|
|
36
|
+
case errors.video?.name:
|
|
37
|
+
return { stream: null, errors };
|
|
38
|
+
case "NotFoundError":
|
|
39
|
+
return tryToGetAudioOnlyThenVideoOnly(constraints, PERMISSION_DENIED);
|
|
40
|
+
case "OverconstrainedError":
|
|
41
|
+
return getAvailableMedia({ audio: unspecifyDevice(constraints.audio), video: unspecifyDevice(constraints.video) }, { audio: OVERCONSTRAINED_ERROR, video: OVERCONSTRAINED_ERROR });
|
|
42
|
+
case "NotAllowedError":
|
|
43
|
+
return tryToGetAudioOnlyThenVideoOnly(constraints, PERMISSION_DENIED);
|
|
44
|
+
}
|
|
28
45
|
}
|
|
46
|
+
return { stream: null, errors: { audio: UNHANDLED_ERROR, video: UNHANDLED_ERROR } };
|
|
29
47
|
}
|
|
30
48
|
};
|
|
31
49
|
// Safari changes deviceId between sessions, therefore we cannot rely on deviceId for identification purposes.
|
|
32
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.
|
|
33
|
-
export const
|
|
51
|
+
export const correctDevicesOnSafari = async (stream, errors, devices, constraints, previousDevices) => {
|
|
34
52
|
const shouldCorrectDevices = isAnyDeviceDifferentFromLastSession(previousDevices.video, previousDevices.audio, getCurrentDevicesSettings(stream, devices));
|
|
35
53
|
if (!shouldCorrectDevices)
|
|
36
|
-
return
|
|
54
|
+
return { stream, errors };
|
|
37
55
|
const videoIdToStart = devices.find((info) => info.label === previousDevices.video?.label)?.deviceId;
|
|
38
56
|
const audioIdToStart = devices.find((info) => info.label === previousDevices.audio?.label)?.deviceId;
|
|
39
57
|
if (!videoIdToStart && !audioIdToStart)
|
|
40
|
-
return
|
|
58
|
+
return { stream, errors };
|
|
41
59
|
stopTracks(stream);
|
|
42
60
|
const exactConstraints = {
|
|
43
|
-
video: !
|
|
44
|
-
audio: !
|
|
61
|
+
video: !errors.video && prepareConstraints(videoIdToStart, constraints.video),
|
|
62
|
+
audio: !errors.audio && prepareConstraints(audioIdToStart, constraints.audio),
|
|
45
63
|
};
|
|
46
|
-
return await getAvailableMedia(exactConstraints,
|
|
64
|
+
return await getAvailableMedia(exactConstraints, errors);
|
|
47
65
|
};
|
|
48
66
|
const getCurrentDevicesSettings = (requestedDevices, mediaDeviceInfos) => {
|
|
49
67
|
const currentDevices = { videoinput: null, audioinput: null };
|
|
@@ -69,7 +87,7 @@ const stopTracks = (requestedDevices) => {
|
|
|
69
87
|
track.stop();
|
|
70
88
|
}
|
|
71
89
|
};
|
|
72
|
-
const
|
|
90
|
+
const unspecifyDevice = (trackConstraints) => {
|
|
73
91
|
if (typeof trackConstraints === "object") {
|
|
74
92
|
return { ...trackConstraints, deviceId: undefined };
|
|
75
93
|
}
|
|
@@ -6,11 +6,11 @@ export declare function useCamera(): {
|
|
|
6
6
|
/**
|
|
7
7
|
* Toggles current camera on/off
|
|
8
8
|
*/
|
|
9
|
-
toggleCamera: () => Promise<
|
|
9
|
+
toggleCamera: () => Promise<undefined | import("../..").DeviceError>;
|
|
10
10
|
/**
|
|
11
11
|
* Selects the camera device
|
|
12
12
|
*/
|
|
13
|
-
selectCamera: (deviceId?: string) => Promise<
|
|
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":"
|
|
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 {
|
|
2
|
-
import {
|
|
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
|
|
9
|
-
|
|
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:
|
|
30
|
+
activeCamera: cameraManager.activeDevice,
|
|
23
31
|
/**
|
|
24
32
|
* Indicates whether the microphone is streaming video
|
|
25
33
|
*/
|
|
26
|
-
isCameraOn: !!
|
|
34
|
+
isCameraOn: !!cameraStream,
|
|
27
35
|
/**
|
|
28
36
|
* The MediaStream object containing the current stream
|
|
29
37
|
*/
|
|
30
|
-
cameraStream
|
|
38
|
+
cameraStream,
|
|
31
39
|
/**
|
|
32
40
|
* The currently set camera middleware function
|
|
33
41
|
*/
|
|
34
|
-
currentCameraMiddleware:
|
|
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:
|
|
50
|
+
cameraDevices: cameraManager.deviceList,
|
|
43
51
|
/**
|
|
44
52
|
* Possible error thrown while setting up the camera
|
|
45
53
|
*/
|
|
46
|
-
cameraDeviceError:
|
|
54
|
+
cameraDeviceError: cameraManager.deviceError,
|
|
47
55
|
};
|
|
48
56
|
}
|
|
@@ -10,6 +10,6 @@ export declare const useInitializeDevices: () => {
|
|
|
10
10
|
/**
|
|
11
11
|
* Initialize access to the devices before joining the room
|
|
12
12
|
*/
|
|
13
|
-
initializeDevices: (
|
|
13
|
+
initializeDevices: () => Promise<import("../..").InitializeDevicesResult>;
|
|
14
14
|
};
|
|
15
15
|
//# sourceMappingURL=useInitializeDevices.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInitializeDevices.d.ts","sourceRoot":"","sources":["../../../src/hooks/devices/useInitializeDevices.ts"],"names":[],"mappings":"
|
|
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,42 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { getAvailableMedia, getCorrectedResult } from "../../devices/mediaInitializer";
|
|
4
|
-
import { useFishjamContext } from "../internal/useFishjamContext";
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { InitDevicesContext } from "../../contexts/initDevices";
|
|
5
3
|
/**
|
|
6
4
|
* Hook allows you to initialize access to the devices before joining the room.
|
|
7
5
|
* @category Devices
|
|
8
6
|
*/
|
|
9
7
|
export const useInitializeDevices = () => {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return;
|
|
14
|
-
hasDevicesBeenInitializedRef.current = true;
|
|
15
|
-
const videoManager = videoDeviceManagerRef.current;
|
|
16
|
-
const audioManager = audioDeviceManagerRef.current;
|
|
17
|
-
const constraints = {
|
|
18
|
-
video: enableVideo && videoManager.getConstraints(),
|
|
19
|
-
audio: enableAudio && audioManager.getConstraints(),
|
|
20
|
-
};
|
|
21
|
-
const previousDevices = {
|
|
22
|
-
video: videoManager.getLastDevice(),
|
|
23
|
-
audio: audioManager.getLastDevice(),
|
|
24
|
-
};
|
|
25
|
-
// Attempt to start the last selected device to avoid an unnecessary restart.
|
|
26
|
-
// Without this, the first device will start, and `getCorrectedResult` will attempt to fix it.
|
|
27
|
-
let [stream, deviceErrors] = await getAvailableMedia({
|
|
28
|
-
video: enableVideo && prepareConstraints(previousDevices.video?.deviceId, constraints.video),
|
|
29
|
-
audio: enableAudio && prepareConstraints(previousDevices.audio?.deviceId, constraints.audio),
|
|
30
|
-
});
|
|
31
|
-
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
32
|
-
const videoDevices = devices.filter(({ kind }) => kind === "videoinput");
|
|
33
|
-
const audioDevices = devices.filter(({ kind }) => kind === "audioinput");
|
|
34
|
-
if (stream) {
|
|
35
|
-
[stream, deviceErrors] = await getCorrectedResult(stream, deviceErrors, devices, constraints, previousDevices);
|
|
36
|
-
}
|
|
37
|
-
videoManager.initialize(stream, stream?.getVideoTracks()?.[0] ?? null, videoDevices, !!constraints.video, deviceErrors.video);
|
|
38
|
-
audioManager.initialize(stream, stream?.getAudioTracks()?.[0] ?? null, audioDevices, !!constraints.audio, deviceErrors.audio);
|
|
39
|
-
}, [videoDeviceManagerRef, audioDeviceManagerRef, hasDevicesBeenInitializedRef]);
|
|
8
|
+
const initializeDevices = useContext(InitDevicesContext);
|
|
9
|
+
if (!initializeDevices)
|
|
10
|
+
throw Error("useInitializeDevices must be used within FishjamProvider");
|
|
40
11
|
return {
|
|
41
12
|
/**
|
|
42
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<
|
|
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<
|
|
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":"
|
|
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 {
|
|
2
|
-
import {
|
|
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
|
|
9
|
-
|
|
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:
|
|
28
|
+
activeMicrophone: microphoneManager.activeDevice,
|
|
21
29
|
/**
|
|
22
30
|
* Indicates whether the microphone is streaming audio
|
|
23
31
|
*/
|
|
24
|
-
isMicrophoneOn: !!
|
|
32
|
+
isMicrophoneOn: !!microphoneStream,
|
|
25
33
|
/**
|
|
26
34
|
* Indicates whether the microphone is muted
|
|
27
35
|
*/
|
|
28
|
-
isMicrophoneMuted:
|
|
36
|
+
isMicrophoneMuted: !microphoneManager.deviceEnabled,
|
|
29
37
|
/**
|
|
30
38
|
* The MediaStream object containing the current audio stream
|
|
31
39
|
*/
|
|
32
|
-
microphoneStream
|
|
40
|
+
microphoneStream,
|
|
33
41
|
/**
|
|
34
42
|
* The currently set microphone middleware function
|
|
35
43
|
*/
|
|
36
|
-
currentMicrophoneMiddleware:
|
|
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:
|
|
52
|
+
microphoneDevices: microphoneManager.deviceList,
|
|
45
53
|
/**
|
|
46
54
|
* Possible error thrown while setting up the microphone
|
|
47
55
|
*/
|
|
48
|
-
microphoneDeviceError:
|
|
56
|
+
microphoneDeviceError: microphoneManager.deviceError,
|
|
49
57
|
};
|
|
50
58
|
}
|