@fishjam-cloud/react-client 0.12.0 → 0.13.0
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/hooks/devices/useMicrophone.d.ts +2 -1
- package/dist/hooks/devices/useMicrophone.d.ts.map +1 -1
- package/dist/hooks/devices/useMicrophone.js +2 -1
- package/dist/hooks/internal/useTrackManager.d.ts.map +1 -1
- package/dist/hooks/internal/useTrackManager.js +31 -25
- package/dist/types/internal.d.ts +1 -2
- package/dist/types/internal.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -19,7 +19,8 @@ export declare function useMicrophone(): {
|
|
|
19
19
|
isMicrophoneOn: boolean;
|
|
20
20
|
/**
|
|
21
21
|
* Indicates whether the microphone is muted
|
|
22
|
-
*/
|
|
22
|
+
*/
|
|
23
|
+
isMicrophoneMuted: boolean;
|
|
23
24
|
/**
|
|
24
25
|
* The MediaStream object containing the current audio stream
|
|
25
26
|
*/
|
|
@@ -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
|
|
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"}
|
|
@@ -24,7 +24,8 @@ export function useMicrophone() {
|
|
|
24
24
|
isMicrophoneOn: !!deviceApi.mediaStream,
|
|
25
25
|
/**
|
|
26
26
|
* Indicates whether the microphone is muted
|
|
27
|
-
*/
|
|
27
|
+
*/
|
|
28
|
+
isMicrophoneMuted: audioTrackManager.paused,
|
|
28
29
|
/**
|
|
29
30
|
* The MediaStream object containing the current audio stream
|
|
30
31
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTrackManager.d.ts","sourceRoot":"","sources":["../../../src/hooks/internal/useTrackManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAA+B,MAAM,0BAA0B,CAAC;AAG3F,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAmB,MAAM,oBAAoB,CAAC;AAGrG,UAAU,kBAAkB;IAC1B,YAAY,EAAE,YAAY,CAAC;IAC3B,QAAQ,EAAE,aAAa,CAAC;IACxB,oBAAoB,EAAE,MAAM,UAAU,CAAC;IACvC,eAAe,EAAE,eAAe,CAAC;IACjC,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;AAWD,eAAO,MAAM,eAAe,qFAMzB,kBAAkB,KAAG,
|
|
1
|
+
{"version":3,"file":"useTrackManager.d.ts","sourceRoot":"","sources":["../../../src/hooks/internal/useTrackManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAA+B,MAAM,0BAA0B,CAAC;AAG3F,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAmB,MAAM,oBAAoB,CAAC;AAGrG,UAAU,kBAAkB;IAC1B,YAAY,EAAE,YAAY,CAAC;IAC3B,QAAQ,EAAE,aAAa,CAAC;IACxB,oBAAoB,EAAE,MAAM,UAAU,CAAC;IACvC,eAAe,EAAE,eAAe,CAAC;IACjC,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;AAWD,eAAO,MAAM,eAAe,qFAMzB,kBAAkB,KAAG,YA8KvB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Variant } from "@fishjam-cloud/ts-client";
|
|
2
|
-
import { useCallback, useEffect,
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
3
|
import { getConfigAndBandwidthFromProps, getRemoteOrLocalTrack } from "../../utils/track";
|
|
4
4
|
const TRACK_TYPE_TO_DEVICE = {
|
|
5
5
|
video: "camera",
|
|
@@ -7,21 +7,23 @@ const TRACK_TYPE_TO_DEVICE = {
|
|
|
7
7
|
};
|
|
8
8
|
const getDeviceType = (mediaManager) => TRACK_TYPE_TO_DEVICE[mediaManager.getDeviceType()];
|
|
9
9
|
export const useTrackManager = ({ mediaManager, tsClient, getCurrentPeerStatus, bandwidthLimits, streamConfig, }) => {
|
|
10
|
-
const
|
|
10
|
+
const currentTrackIdRef = useRef(null);
|
|
11
11
|
const [paused, setPaused] = useState(false);
|
|
12
|
-
const currentTrack = useMemo(() => getRemoteOrLocalTrack(tsClient, currentTrackId), [tsClient, currentTrackId]);
|
|
13
12
|
async function setTrackMiddleware(middleware) {
|
|
14
13
|
mediaManager.setTrackMiddleware(middleware);
|
|
15
14
|
await refreshStreamedTrack();
|
|
16
15
|
}
|
|
17
16
|
async function selectDevice(deviceId) {
|
|
18
17
|
await mediaManager?.start(deviceId);
|
|
18
|
+
const currentTrackId = currentTrackIdRef.current;
|
|
19
19
|
if (!currentTrackId)
|
|
20
20
|
return;
|
|
21
21
|
const newTrack = mediaManager.getMedia()?.track ?? null;
|
|
22
22
|
await tsClient.replaceTrack(currentTrackId, newTrack);
|
|
23
23
|
}
|
|
24
|
+
const getCurrentTrackId = useCallback(() => getRemoteOrLocalTrack(tsClient, currentTrackIdRef.current)?.trackId, [tsClient]);
|
|
24
25
|
const startStreaming = useCallback(async (props = { simulcast: [Variant.VARIANT_LOW, Variant.VARIANT_MEDIUM, Variant.VARIANT_HIGH] }) => {
|
|
26
|
+
const currentTrackId = currentTrackIdRef.current;
|
|
25
27
|
if (currentTrackId)
|
|
26
28
|
throw Error("Track already added");
|
|
27
29
|
const media = mediaManager.getMedia();
|
|
@@ -31,7 +33,7 @@ export const useTrackManager = ({ mediaManager, tsClient, getCurrentPeerStatus,
|
|
|
31
33
|
if (track)
|
|
32
34
|
return track.trackId;
|
|
33
35
|
// see `getRemoteOrLocalTrackContext()` explanation
|
|
34
|
-
|
|
36
|
+
currentTrackIdRef.current = media.track.id;
|
|
35
37
|
const deviceType = getDeviceType(mediaManager);
|
|
36
38
|
const trackMetadata = { type: deviceType, paused: false };
|
|
37
39
|
const displayName = tsClient.getLocalPeer()?.metadata?.peer?.displayName;
|
|
@@ -40,56 +42,61 @@ export const useTrackManager = ({ mediaManager, tsClient, getCurrentPeerStatus,
|
|
|
40
42
|
}
|
|
41
43
|
const [maxBandwidth, simulcastConfig] = getConfigAndBandwidthFromProps(props.simulcast, bandwidthLimits);
|
|
42
44
|
const remoteTrackId = await tsClient.addTrack(media.track, trackMetadata, simulcastConfig, maxBandwidth);
|
|
43
|
-
|
|
45
|
+
currentTrackIdRef.current = remoteTrackId;
|
|
44
46
|
setPaused(false);
|
|
45
47
|
return remoteTrackId;
|
|
46
|
-
}, [
|
|
48
|
+
}, [mediaManager, tsClient, bandwidthLimits]);
|
|
47
49
|
const refreshStreamedTrack = useCallback(async () => {
|
|
48
|
-
|
|
50
|
+
const trackId = getCurrentTrackId();
|
|
51
|
+
if (!trackId)
|
|
49
52
|
return;
|
|
50
53
|
const newTrack = mediaManager.getMedia()?.track ?? null;
|
|
51
54
|
if (!newTrack)
|
|
52
55
|
throw Error("New track is empty");
|
|
53
|
-
return tsClient.replaceTrack(
|
|
54
|
-
}, [
|
|
56
|
+
return tsClient.replaceTrack(trackId, newTrack);
|
|
57
|
+
}, [getCurrentTrackId, mediaManager, tsClient]);
|
|
55
58
|
const pauseStreaming = useCallback(async () => {
|
|
56
|
-
|
|
59
|
+
const trackId = getCurrentTrackId();
|
|
60
|
+
if (!trackId)
|
|
57
61
|
return;
|
|
58
62
|
setPaused(true);
|
|
59
|
-
await tsClient.replaceTrack(
|
|
63
|
+
await tsClient.replaceTrack(trackId, null);
|
|
60
64
|
const deviceType = getDeviceType(mediaManager);
|
|
61
65
|
const trackMetadata = { type: deviceType, paused: true };
|
|
62
|
-
return tsClient.updateTrackMetadata(
|
|
63
|
-
}, [
|
|
66
|
+
return tsClient.updateTrackMetadata(trackId, trackMetadata);
|
|
67
|
+
}, [mediaManager, getCurrentTrackId, tsClient]);
|
|
64
68
|
const resumeStreaming = useCallback(async () => {
|
|
65
|
-
|
|
69
|
+
const trackId = getCurrentTrackId();
|
|
70
|
+
if (!trackId)
|
|
66
71
|
return;
|
|
67
72
|
const media = mediaManager.getMedia();
|
|
68
73
|
const deviceType = getDeviceType(mediaManager);
|
|
69
74
|
if (!media)
|
|
70
75
|
throw Error("Device is unavailable");
|
|
71
76
|
setPaused(false);
|
|
72
|
-
await tsClient.replaceTrack(
|
|
77
|
+
await tsClient.replaceTrack(trackId, media.track);
|
|
73
78
|
const trackMetadata = { type: deviceType, paused: false };
|
|
74
|
-
return tsClient.updateTrackMetadata(
|
|
75
|
-
}, [
|
|
79
|
+
return tsClient.updateTrackMetadata(trackId, trackMetadata);
|
|
80
|
+
}, [mediaManager, tsClient, getCurrentTrackId]);
|
|
76
81
|
const stream = useCallback(async () => {
|
|
77
82
|
if (getCurrentPeerStatus() !== "connected")
|
|
78
83
|
return;
|
|
79
|
-
|
|
84
|
+
const trackId = getRemoteOrLocalTrack(tsClient, currentTrackIdRef.current)?.trackId;
|
|
85
|
+
if (trackId) {
|
|
80
86
|
await resumeStreaming();
|
|
81
87
|
}
|
|
82
88
|
else {
|
|
83
89
|
await startStreaming();
|
|
84
90
|
}
|
|
85
|
-
}, [
|
|
91
|
+
}, [tsClient, getCurrentPeerStatus, resumeStreaming, startStreaming]);
|
|
86
92
|
const toggle = useCallback(async (mode) => {
|
|
87
93
|
const mediaStream = mediaManager.getMedia()?.stream;
|
|
88
94
|
const track = mediaManager.getMedia()?.track ?? null;
|
|
89
95
|
const enabled = Boolean(track?.enabled);
|
|
96
|
+
const trackId = getRemoteOrLocalTrack(tsClient, currentTrackIdRef.current)?.trackId;
|
|
90
97
|
if (mediaStream && enabled) {
|
|
91
98
|
mediaManager.disable();
|
|
92
|
-
if (
|
|
99
|
+
if (trackId) {
|
|
93
100
|
await pauseStreaming();
|
|
94
101
|
}
|
|
95
102
|
if (mode === "hard") {
|
|
@@ -104,7 +111,7 @@ export const useTrackManager = ({ mediaManager, tsClient, getCurrentPeerStatus,
|
|
|
104
111
|
await mediaManager.start();
|
|
105
112
|
await stream();
|
|
106
113
|
}
|
|
107
|
-
}, [
|
|
114
|
+
}, [tsClient, mediaManager, pauseStreaming, stream]);
|
|
108
115
|
/**
|
|
109
116
|
* @see {@link TrackManager#toggleMute} for more details.
|
|
110
117
|
*/
|
|
@@ -121,7 +128,7 @@ export const useTrackManager = ({ mediaManager, tsClient, getCurrentPeerStatus,
|
|
|
121
128
|
};
|
|
122
129
|
const onLeftRoom = () => {
|
|
123
130
|
setPaused(true);
|
|
124
|
-
|
|
131
|
+
currentTrackIdRef.current = null;
|
|
125
132
|
};
|
|
126
133
|
tsClient.on("joined", onJoinedRoom);
|
|
127
134
|
tsClient.on("disconnected", onLeftRoom);
|
|
@@ -129,11 +136,10 @@ export const useTrackManager = ({ mediaManager, tsClient, getCurrentPeerStatus,
|
|
|
129
136
|
tsClient.off("joined", onJoinedRoom);
|
|
130
137
|
tsClient.off("disconnected", onLeftRoom);
|
|
131
138
|
};
|
|
132
|
-
}, [mediaManager, startStreaming, tsClient, streamConfig
|
|
139
|
+
}, [mediaManager, startStreaming, tsClient, streamConfig]);
|
|
133
140
|
return {
|
|
134
|
-
currentTrack,
|
|
135
|
-
setTrackMiddleware,
|
|
136
141
|
paused,
|
|
142
|
+
setTrackMiddleware,
|
|
137
143
|
selectDevice,
|
|
138
144
|
toggleMute,
|
|
139
145
|
toggleDevice,
|
package/dist/types/internal.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Peer } from "@fishjam-cloud/ts-client";
|
|
2
|
-
import type { DeviceError, DeviceType, PeerId,
|
|
2
|
+
import type { DeviceError, DeviceType, PeerId, TrackMiddleware, TracksMiddleware } from "./public";
|
|
3
3
|
export type DevicesStatus = "OK" | "Error" | "Not requested" | "Requesting";
|
|
4
4
|
export type MediaStatus = "OK" | "Error" | "Not requested" | "Requesting";
|
|
5
5
|
export type DeviceManagerStatus = "uninitialized" | "initializing" | "initialized" | "error";
|
|
@@ -56,7 +56,6 @@ export interface TrackManager {
|
|
|
56
56
|
selectDevice: (deviceId?: string) => Promise<void>;
|
|
57
57
|
paused: boolean;
|
|
58
58
|
setTrackMiddleware: (middleware: TrackMiddleware | null) => Promise<void>;
|
|
59
|
-
currentTrack: Track | null;
|
|
60
59
|
/**
|
|
61
60
|
* Either enables or disables the stream.
|
|
62
61
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/types/internal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAErD,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/types/internal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAErD,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEnG,MAAM,MAAM,aAAa,GAAG,IAAI,GAAG,OAAO,GAAG,eAAe,GAAG,YAAY,CAAC;AAC5E,MAAM,MAAM,WAAW,GAAG,IAAI,GAAG,OA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M,EAAE,WAAW,GAAG,IAAI,CAAC;QAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IACxG,aAAa,EAAE,MAAM,UAAU,CAAC;CACjC;AAED,MAAM,MAAM,gBAAgB,GAAG,CAC3B;IACE,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACjD,GACD;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,IAAI,CAAA;CAAE,CACnC,GAAG;IAAE,gBAAgB,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAAA;CAAE,CAAC;AAEnD,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,MAAM,EAAE,OAAO,CAAC;IAChB,kBAAkB,EAAE,CAAC,UAAU,EAAE,eAAe,GAAG,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1E;;;;;;;OAOG;IACH,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC;;;;;;OAMG;IACH,YAAY,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACnC;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fishjam-cloud/react-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "React client library for Fishjam",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Fishjam Team",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"typescript": "^5.7.3"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@fishjam-cloud/ts-client": "0.
|
|
53
|
+
"@fishjam-cloud/ts-client": "0.13.0",
|
|
54
54
|
"events": "3.3.0",
|
|
55
55
|
"lodash.isequal": "4.5.0"
|
|
56
56
|
},
|