@fishjam-cloud/react-client 0.5.5 → 0.7.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/DeviceManager.d.ts +3 -4
- package/dist/DeviceManager.d.ts.map +1 -1
- package/dist/DeviceManager.js +25 -20
- package/dist/constraints.d.ts +2 -21
- package/dist/constraints.d.ts.map +1 -1
- package/dist/constraints.js +3 -7
- package/dist/fishjamProvider.d.ts +12 -0
- package/dist/fishjamProvider.d.ts.map +1 -0
- package/dist/fishjamProvider.js +39 -0
- package/dist/hooks/deviceManagers/useAudioDeviceManager.d.ts +2 -0
- package/dist/hooks/deviceManagers/useAudioDeviceManager.d.ts.map +1 -0
- package/dist/hooks/deviceManagers/useAudioDeviceManager.js +7 -0
- package/dist/hooks/deviceManagers/useDeviceManager.d.ts +4 -0
- package/dist/hooks/deviceManagers/useDeviceManager.d.ts.map +1 -0
- package/dist/hooks/deviceManagers/useDeviceManager.js +39 -0
- package/dist/hooks/deviceManagers/useVideoDeviceManager.d.ts +2 -0
- package/dist/hooks/deviceManagers/useVideoDeviceManager.d.ts.map +1 -0
- package/dist/hooks/deviceManagers/useVideoDeviceManager.js +7 -0
- package/dist/hooks/internal.d.ts +2 -0
- package/dist/hooks/internal.d.ts.map +1 -0
- package/dist/hooks/internal.js +1 -0
- package/dist/hooks/public.d.ts +9 -0
- package/dist/hooks/public.d.ts.map +1 -0
- package/dist/hooks/public.js +8 -0
- package/dist/hooks/useConnection.d.ts +4 -0
- package/dist/hooks/useConnection.d.ts.map +1 -0
- package/dist/hooks/useConnection.js +12 -0
- package/dist/hooks/useDevices.d.ts +7 -0
- package/dist/hooks/useDevices.d.ts.map +1 -0
- package/dist/hooks/useDevices.js +84 -0
- package/dist/hooks/useFishjamClientState.d.ts +11 -0
- package/dist/hooks/useFishjamClientState.d.ts.map +1 -0
- package/dist/hooks/useFishjamClientState.js +100 -0
- package/dist/hooks/useFishjamClient_DO_NOT_USE.d.ts +2 -0
- package/dist/hooks/useFishjamClient_DO_NOT_USE.d.ts.map +1 -0
- package/dist/hooks/useFishjamClient_DO_NOT_USE.js +6 -0
- package/dist/hooks/useFishjamContext.d.ts +20 -0
- package/dist/hooks/useFishjamContext.d.ts.map +1 -0
- package/dist/hooks/useFishjamContext.js +8 -0
- package/dist/hooks/useParticipantStatus.d.ts +8 -0
- package/dist/hooks/useParticipantStatus.d.ts.map +1 -0
- package/dist/hooks/useParticipantStatus.js +39 -0
- package/dist/hooks/useParticipants.d.ts +6 -0
- package/dist/hooks/useParticipants.d.ts.map +1 -0
- package/dist/hooks/useParticipants.js +16 -0
- package/dist/hooks/useProcessedPreviewStream.d.ts +3 -0
- package/dist/hooks/useProcessedPreviewStream.d.ts.map +1 -0
- package/dist/hooks/useProcessedPreviewStream.js +17 -0
- package/dist/hooks/useReconnection.d.ts +3 -0
- package/dist/hooks/useReconnection.d.ts.map +1 -0
- package/dist/hooks/useReconnection.js +27 -0
- package/dist/hooks/useScreenShare.d.ts +3 -0
- package/dist/hooks/useScreenShare.d.ts.map +1 -0
- package/dist/hooks/useScreenShare.js +119 -0
- package/dist/hooks/useStatus.d.ts +2 -0
- package/dist/hooks/useStatus.d.ts.map +1 -0
- package/dist/hooks/useStatus.js +4 -0
- package/dist/hooks/useTrackManager.d.ts +11 -0
- package/dist/hooks/useTrackManager.d.ts.map +1 -0
- package/dist/hooks/useTrackManager.js +176 -0
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/state.types.d.ts +11 -24
- package/dist/state.types.d.ts.map +1 -1
- package/dist/types.d.ts +59 -41
- package/dist/types.d.ts.map +1 -1
- package/package.json +13 -17
- package/dist/Client.d.ts +0 -198
- package/dist/Client.d.ts.map +0 -1
- package/dist/Client.js +0 -461
- package/dist/create.d.ts +0 -10
- package/dist/create.d.ts.map +0 -1
- package/dist/create.js +0 -195
- package/dist/screenShareTrackManager.d.ts +0 -4
- package/dist/screenShareTrackManager.d.ts.map +0 -1
- package/dist/screenShareTrackManager.js +0 -92
- package/dist/trackManager.d.ts +0 -9
- package/dist/trackManager.d.ts.map +0 -1
- package/dist/trackManager.js +0 -116
- package/dist/useSetupMedia.d.ts +0 -3
- package/dist/useSetupMedia.d.ts.map +0 -1
- package/dist/useSetupMedia.js +0 -201
package/dist/DeviceManager.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DeviceManagerConfig, DeviceState, MediaManager, StorageConfig, DeviceError } from "./types";
|
|
1
|
+
import type { DeviceManagerConfig, DeviceState, MediaManager, StorageConfig, DeviceError, DeviceManagerStatus } from "./types";
|
|
2
2
|
import type TypedEmitter from "typed-emitter";
|
|
3
3
|
export type DeviceManagerEvents = {
|
|
4
4
|
managerStarted: (event: DeviceState & {
|
|
@@ -7,7 +7,7 @@ export type DeviceManagerEvents = {
|
|
|
7
7
|
managerInitialized: (state: DeviceState) => void;
|
|
8
8
|
devicesStarted: (event: {
|
|
9
9
|
restarting: boolean;
|
|
10
|
-
constraints?:
|
|
10
|
+
constraints?: MediaTrackConstraints | boolean;
|
|
11
11
|
}, state: DeviceState) => void;
|
|
12
12
|
deviceReady: (event: {
|
|
13
13
|
stream: MediaStream;
|
|
@@ -20,7 +20,6 @@ export type DeviceManagerEvents = {
|
|
|
20
20
|
deviceDisabled: (state: DeviceState) => void;
|
|
21
21
|
error: (event: any, state: DeviceState) => void;
|
|
22
22
|
};
|
|
23
|
-
export type DeviceManagerStatus = "uninitialized" | "initializing" | "initialized" | "error";
|
|
24
23
|
declare const DeviceManager_base: new () => TypedEmitter<DeviceManagerEvents>;
|
|
25
24
|
export declare class DeviceManager extends DeviceManager_base implements MediaManager {
|
|
26
25
|
private constraints;
|
|
@@ -39,7 +38,7 @@ export declare class DeviceManager extends DeviceManager_base implements MediaMa
|
|
|
39
38
|
private onTrackEnded;
|
|
40
39
|
getLastDevice(): MediaDeviceInfo | null;
|
|
41
40
|
private saveLastDevice;
|
|
42
|
-
start(deviceId?: string
|
|
41
|
+
start(deviceId?: string): Promise<void>;
|
|
43
42
|
stop(): Promise<void>;
|
|
44
43
|
disable(): void;
|
|
45
44
|
enable(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeviceManager.d.ts","sourceRoot":"","sources":["../src/DeviceManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"DeviceManager.d.ts","sourceRoot":"","sources":["../src/DeviceManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,WAAW,EACX,YAAY,EACZ,aAAa,EACb,WAAW,EACX,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAKjB,OAAO,KAAK,YAAY,MAAM,eAAe,CAAC;AAI9C,MAAM,MAAM,mBAAmB,GAAG;IAChC,cAAc,EAAE,CACd,KAAK,EAAE,WAAW,GAAG;QACnB,WAAW,EAAE,qBAAqB,GAAG,SAAS,CAAC;KAChD,EACD,KAAK,EAAE,WAAW,KACf,IAAI,CAAC;IACV,kBAAkB,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IACjD,cAAc,EAAE,CACd,KAAK,EAAE;QAAE,UAAU,EAAE,OAAO,CAAC;QAAC,WAAW,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAA;KAAE,EAC7E,KAAK,EAAE,WAAW,KACf,IAAI,CAAC;IACV,WAAW,EAAE,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,WAAW,CAAA;KAAE,EAAE,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IAC1E,YAAY,EAAE,CAAC,KAAK,EAAE,WAAW,GAAG;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,EAAE,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IACxF,aAAa,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IAC5C,aAAa,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IAC5C,cAAc,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IAE7C,KAAK,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;CACjD,CAAC;4CAGmC,YAAY,CAAC,mBAAmB,CAAC;AADtE,qBAAa,aACX,SAAQ,kBACR,YAAW,YAAY;IAEvB,OAAO,CAAC,WAAW,CAAoC;IACvD,OAAO,CAAC,aAAa,CAAuB;IAE5C,OAAO,CAAC,MAAM,CAAwC;IACtD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;IAExC,WAAW,EAAE,WAAW,CAM7B;gBAEU,UAAU,EAAE,OAAO,GAAG,OAAO,EAAE,aAAa,CAAC,EAAE,mBAAmB;IAO9E,OAAO,CAAC,mBAAmB;IAMpB,SAAS,IAAI,mBAAmB;IAIhC,cAAc,CACnB,kBAAkB,EAAE,OAAO,GAAG,qBAAqB,GAAG,SAAS,GAC9D,qBAAqB,GAAG,SAAS;IAO7B,QAAQ,uCAAgC;IAExC,SAAS,2BAMd;IAEK,UAAU,WACP,WAAW,GAAG,IAAI,SACnB,gBAAgB,GAAG,IAAI,WACrB,eAAe,EAAE,kBACV,OAAO,UAChB,WAAW,GAAG,IAAI,iBAazB;IAEF,OAAO,CAAC,oBAAoB;IAS5B,OAAO,CAAC,YAAY,CAIlB;IAEK,aAAa,IAAI,eAAe,GAAG,IAAI;IAI9C,OAAO,CAAC,cAAc;IAKT,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM;IAkFvB,IAAI;IAOV,OAAO;IAWP,MAAM;IAWN,aAAa,0BAElB;IAEK,SAAS,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,aAAa,EAAE,WAAW,CAAC,EAAE,OAAO,GAAG,qBAAqB;CAIlG"}
|
package/dist/DeviceManager.js
CHANGED
|
@@ -16,15 +16,15 @@ export class DeviceManager extends EventEmitter {
|
|
|
16
16
|
};
|
|
17
17
|
constructor(deviceType, defaultConfig) {
|
|
18
18
|
super();
|
|
19
|
-
this.storageConfig = this.createStorageConfig(defaultConfig?.storage);
|
|
19
|
+
this.storageConfig = this.createStorageConfig(deviceType, defaultConfig?.storage);
|
|
20
20
|
this.deviceType = deviceType;
|
|
21
21
|
this.constraints = toMediaTrackConstraints(defaultConfig?.trackConstraints ?? true);
|
|
22
22
|
}
|
|
23
|
-
createStorageConfig(storage) {
|
|
23
|
+
createStorageConfig(deviceType, storage) {
|
|
24
24
|
if (storage === false)
|
|
25
25
|
return null;
|
|
26
26
|
if (storage === true || storage === undefined)
|
|
27
|
-
return getLocalStorageConfig(
|
|
27
|
+
return getLocalStorageConfig(deviceType);
|
|
28
28
|
return storage;
|
|
29
29
|
}
|
|
30
30
|
getStatus() {
|
|
@@ -39,10 +39,11 @@ export class DeviceManager extends EventEmitter {
|
|
|
39
39
|
}
|
|
40
40
|
getMedia = () => this.deviceState.media;
|
|
41
41
|
getTracks = () => {
|
|
42
|
+
const stream = this.deviceState.media?.stream;
|
|
42
43
|
if (this.deviceType === "audio") {
|
|
43
|
-
return
|
|
44
|
+
return stream?.getAudioTracks() ?? [];
|
|
44
45
|
}
|
|
45
|
-
return
|
|
46
|
+
return stream?.getVideoTracks() ?? [];
|
|
46
47
|
};
|
|
47
48
|
initialize = (stream, track, devices, requestedMedia, error = null) => {
|
|
48
49
|
this.deviceState = prepareDeviceState(stream, track, devices, error, requestedMedia);
|
|
@@ -51,6 +52,7 @@ export class DeviceManager extends EventEmitter {
|
|
|
51
52
|
this.saveLastDevice(deviceInfo);
|
|
52
53
|
this.status = "initialized";
|
|
53
54
|
this.setupOnEndedCallback();
|
|
55
|
+
this.emit("managerInitialized", this.deviceState);
|
|
54
56
|
return this.deviceState;
|
|
55
57
|
};
|
|
56
58
|
setupOnEndedCallback() {
|
|
@@ -71,23 +73,26 @@ export class DeviceManager extends EventEmitter {
|
|
|
71
73
|
console.warn("Device manager storage has been disabled");
|
|
72
74
|
this.storageConfig?.saveLastDevice(info);
|
|
73
75
|
}
|
|
74
|
-
// todo `audioDeviceId / videoDeviceId === true` means use last device
|
|
75
76
|
async start(deviceId) {
|
|
76
|
-
const
|
|
77
|
-
const
|
|
77
|
+
const newDeviceId = deviceId ?? this.getLastDevice()?.deviceId;
|
|
78
|
+
const currentDeviceId = this.deviceState.media?.deviceInfo?.deviceId;
|
|
79
|
+
const shouldReplaceDevice = Boolean(currentDeviceId && currentDeviceId !== newDeviceId);
|
|
80
|
+
const isDeviceStopped = currentDeviceId === undefined;
|
|
81
|
+
const shouldProceed = isDeviceStopped || shouldReplaceDevice;
|
|
78
82
|
const trackConstraints = this.constraints;
|
|
79
|
-
const exactConstraints =
|
|
83
|
+
const exactConstraints = shouldProceed && prepareMediaTrackConstraints(newDeviceId, trackConstraints);
|
|
80
84
|
if (!exactConstraints)
|
|
81
85
|
return;
|
|
82
86
|
this.deviceState.mediaStatus = "Requesting";
|
|
83
|
-
this.emit("devicesStarted", { ...this.deviceState, restarting:
|
|
87
|
+
this.emit("devicesStarted", { ...this.deviceState, restarting: shouldReplaceDevice, constraints: exactConstraints }, this.deviceState);
|
|
84
88
|
try {
|
|
85
89
|
const stream = await navigator.mediaDevices.getUserMedia({ [this.deviceType]: exactConstraints });
|
|
86
90
|
const getTrack = () => {
|
|
87
91
|
const tracks = this.deviceType === "audio" ? stream.getAudioTracks() : stream.getVideoTracks();
|
|
88
92
|
return tracks[0] ?? null;
|
|
89
93
|
};
|
|
90
|
-
const
|
|
94
|
+
const track = getTrack();
|
|
95
|
+
const currentDeviceId = track?.getSettings()?.deviceId;
|
|
91
96
|
const deviceInfo = currentDeviceId ? getDeviceInfo(currentDeviceId, this.deviceState.devices ?? []) : null;
|
|
92
97
|
if (deviceInfo) {
|
|
93
98
|
this.saveLastDevice?.(deviceInfo);
|
|
@@ -104,18 +109,18 @@ export class DeviceManager extends EventEmitter {
|
|
|
104
109
|
// Manually stopping tracks on its own does not generate the `ended` event.
|
|
105
110
|
// The ended event in Safari has already been emitted and will be handled in the future.
|
|
106
111
|
// Therefore, in the `onTrackEnded` method, events for already stopped tracks are filtered out to prevent the state from being damaged.
|
|
107
|
-
if (
|
|
112
|
+
if (shouldReplaceDevice) {
|
|
108
113
|
this.deviceState?.media?.track?.stop();
|
|
109
|
-
this.deviceState.media = {
|
|
110
|
-
stream: stream,
|
|
111
|
-
track: getTrack(),
|
|
112
|
-
deviceInfo,
|
|
113
|
-
enabled: true,
|
|
114
|
-
};
|
|
115
114
|
}
|
|
115
|
+
this.deviceState.media = {
|
|
116
|
+
stream,
|
|
117
|
+
track,
|
|
118
|
+
deviceInfo,
|
|
119
|
+
enabled: true,
|
|
120
|
+
};
|
|
116
121
|
this.setupOnEndedCallback();
|
|
117
122
|
this.deviceState.mediaStatus = "OK";
|
|
118
|
-
this.emit("devicesReady", { ...this.deviceState, restarted:
|
|
123
|
+
this.emit("devicesReady", { ...this.deviceState, restarted: shouldReplaceDevice }, this.deviceState);
|
|
119
124
|
}
|
|
120
125
|
catch (err) {
|
|
121
126
|
const parsedError = parseUserMediaError(err);
|
|
@@ -154,7 +159,7 @@ export class DeviceManager extends EventEmitter {
|
|
|
154
159
|
return this.deviceType;
|
|
155
160
|
};
|
|
156
161
|
setConfig(storage, constraints) {
|
|
157
|
-
this.storageConfig = this.createStorageConfig(storage);
|
|
162
|
+
this.storageConfig = this.createStorageConfig(this.deviceType, storage);
|
|
158
163
|
this.constraints = constraints ? toMediaTrackConstraints(constraints) : undefined;
|
|
159
164
|
}
|
|
160
165
|
}
|
package/dist/constraints.d.ts
CHANGED
|
@@ -2,25 +2,6 @@ export declare const AUDIO_TRACK_CONSTRAINTS: MediaTrackConstraints;
|
|
|
2
2
|
export declare const VIDEO_TRACK_CONSTRAINTS: MediaTrackConstraints;
|
|
3
3
|
export declare const SCREEN_SHARING_MEDIA_CONSTRAINTS: MediaStreamConstraints;
|
|
4
4
|
export declare const toMediaTrackConstraints: (constraint?: boolean | MediaTrackConstraints) => MediaTrackConstraints | undefined;
|
|
5
|
-
export declare const prepareMediaTrackConstraints: (deviceId: string | undefined
|
|
6
|
-
export declare const
|
|
7
|
-
deviceId: {
|
|
8
|
-
exact: string | undefined;
|
|
9
|
-
};
|
|
10
|
-
advanced?: MediaTrackConstraintSet[];
|
|
11
|
-
aspectRatio?: ConstrainDouble;
|
|
12
|
-
autoGainControl?: ConstrainBoolean;
|
|
13
|
-
channelCount?: ConstrainULong;
|
|
14
|
-
displaySurface?: ConstrainDOMString;
|
|
15
|
-
echoCancellation?: ConstrainBoolean;
|
|
16
|
-
facingMode?: ConstrainDOMString;
|
|
17
|
-
frameRate?: ConstrainDouble;
|
|
18
|
-
groupId?: ConstrainDOMString;
|
|
19
|
-
height?: ConstrainULong;
|
|
20
|
-
noiseSuppression?: ConstrainBoolean;
|
|
21
|
-
sampleRate?: ConstrainULong;
|
|
22
|
-
sampleSize?: ConstrainULong;
|
|
23
|
-
width?: ConstrainULong;
|
|
24
|
-
};
|
|
25
|
-
export declare const prepareConstraints: (deviceIdToStart: string | undefined, constraints: MediaTrackConstraints | undefined) => MediaTrackConstraints | undefined | boolean;
|
|
5
|
+
export declare const prepareMediaTrackConstraints: (deviceId: string | undefined, constraints: MediaTrackConstraints | undefined) => MediaTrackConstraints | boolean;
|
|
6
|
+
export declare const prepareConstraints: (deviceIdToStart: string | undefined, constraints: MediaTrackConstraints | undefined) => MediaTrackConstraints | undefined;
|
|
26
7
|
//# sourceMappingURL=constraints.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constraints.d.ts","sourceRoot":"","sources":["../src/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,uBAAuB,gBACrB,OAAO,GAAG,qBAAqB,KAC3C,qBAAqB,GAAG,SAK1B,CAAC;AAEF,eAAO,MAAM,4BAA4B,aAC7B,MAAM,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"constraints.d.ts","sourceRoot":"","sources":["../src/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,uBAAuB,gBACrB,OAAO,GAAG,qBAAqB,KAC3C,qBAAqB,GAAG,SAK1B,CAAC;AAEF,eAAO,MAAM,4BAA4B,aAC7B,MAAM,GAAG,SAAS,eACf,qBAAqB,GAAG,SAAS,KAC7C,qBAAqB,GAAG,OAI1B,CAAC;AAEF,eAAO,MAAM,kBAAkB,oBACZ,MAAM,GAAG,SAAS,eACtB,qBAAqB,GAAG,SAAS,KAC7C,qBAAqB,GAAG,SAI1B,CAAC"}
|
package/dist/constraints.js
CHANGED
|
@@ -32,16 +32,12 @@ export const toMediaTrackConstraints = (constraint) => {
|
|
|
32
32
|
};
|
|
33
33
|
export const prepareMediaTrackConstraints = (deviceId, constraints) => {
|
|
34
34
|
if (!deviceId)
|
|
35
|
-
return false;
|
|
36
|
-
if (deviceId === true)
|
|
37
35
|
return { ...constraints };
|
|
38
36
|
const exactId = deviceId ? { deviceId: { exact: deviceId } } : {};
|
|
39
37
|
return { ...constraints, ...exactId };
|
|
40
38
|
};
|
|
41
|
-
export const getExactDeviceConstraint = (constraints, deviceId) => ({
|
|
42
|
-
...constraints,
|
|
43
|
-
deviceId: { exact: deviceId },
|
|
44
|
-
});
|
|
45
39
|
export const prepareConstraints = (deviceIdToStart, constraints) => {
|
|
46
|
-
|
|
40
|
+
if (!deviceIdToStart)
|
|
41
|
+
return constraints;
|
|
42
|
+
return { ...constraints, deviceId: { ideal: deviceIdToStart } };
|
|
47
43
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type PropsWithChildren } from "react";
|
|
2
|
+
import type { DeviceManagerConfig } from "./types";
|
|
3
|
+
import { type ReconnectConfig } from "@fishjam-cloud/ts-client";
|
|
4
|
+
interface FishjamProviderProps extends PropsWithChildren {
|
|
5
|
+
config?: {
|
|
6
|
+
reconnect?: ReconnectConfig | boolean;
|
|
7
|
+
};
|
|
8
|
+
deviceManagerDefaultConfig?: DeviceManagerConfig;
|
|
9
|
+
}
|
|
10
|
+
export declare function FishjamProvider({ children, config, deviceManagerDefaultConfig }: FishjamProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=fishjamProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fishjamProvider.d.ts","sourceRoot":"","sources":["../src/fishjamProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAEjE,OAAO,KAAK,EAAE,mBAAmB,EAAiD,MAAM,SAAS,CAAC;AAClG,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAO/E,UAAU,oBAAqB,SAAQ,iBAAiB;IACtD,MAAM,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,eAAe,GAAG,OAAO,CAAA;KAAE,CAAC;IACnD,0BAA0B,CAAC,EAAE,mBAAmB,CAAC;CAClD;AAED,wBAAgB,eAAe,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,0BAA0B,EAAE,EAAE,oBAAoB,2CAqCrG"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState } from "react";
|
|
3
|
+
import { useTrackManager } from "./hooks/useTrackManager";
|
|
4
|
+
import { FishjamClient } from "@fishjam-cloud/ts-client";
|
|
5
|
+
import { FishjamContext } from "./hooks/useFishjamContext";
|
|
6
|
+
import { DeviceManager } from "./DeviceManager";
|
|
7
|
+
import { useParticipantStatus } from "./hooks/useParticipantStatus";
|
|
8
|
+
import { useFishjamClientState } from "./hooks/useFishjamClientState";
|
|
9
|
+
export function FishjamProvider({ children, config, deviceManagerDefaultConfig }) {
|
|
10
|
+
const fishjamClientRef = useRef(new FishjamClient(config));
|
|
11
|
+
const hasDevicesBeenInitializedRef = useRef(false);
|
|
12
|
+
const videoDeviceManagerRef = useRef(new DeviceManager("video", deviceManagerDefaultConfig));
|
|
13
|
+
const audioDeviceManagerRef = useRef(new DeviceManager("audio", deviceManagerDefaultConfig));
|
|
14
|
+
const screenShareState = useState({ stream: null, trackIds: null });
|
|
15
|
+
const { peerStatus, getCurrentParticipantStatus } = useParticipantStatus(fishjamClientRef.current);
|
|
16
|
+
const videoTrackManager = useTrackManager({
|
|
17
|
+
mediaManager: videoDeviceManagerRef.current,
|
|
18
|
+
tsClient: fishjamClientRef.current,
|
|
19
|
+
getCurrentParticipantStatus,
|
|
20
|
+
});
|
|
21
|
+
const audioTrackManager = useTrackManager({
|
|
22
|
+
mediaManager: audioDeviceManagerRef.current,
|
|
23
|
+
tsClient: fishjamClientRef.current,
|
|
24
|
+
getCurrentParticipantStatus,
|
|
25
|
+
});
|
|
26
|
+
const clientState = useFishjamClientState(fishjamClientRef.current);
|
|
27
|
+
const context = {
|
|
28
|
+
fishjamClientRef,
|
|
29
|
+
peerStatus,
|
|
30
|
+
screenShareState,
|
|
31
|
+
videoTrackManager,
|
|
32
|
+
audioTrackManager,
|
|
33
|
+
videoDeviceManagerRef,
|
|
34
|
+
audioDeviceManagerRef,
|
|
35
|
+
hasDevicesBeenInitializedRef,
|
|
36
|
+
clientState,
|
|
37
|
+
};
|
|
38
|
+
return _jsx(FishjamContext.Provider, { value: context, children: children });
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAudioDeviceManager.d.ts","sourceRoot":"","sources":["../../../src/hooks/deviceManagers/useAudioDeviceManager.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB,gDAKjC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useFishjamContext } from "../useFishjamContext";
|
|
2
|
+
import { useDeviceManager } from "./useDeviceManager";
|
|
3
|
+
export const useAudioDeviceManager = () => {
|
|
4
|
+
const { audioDeviceManagerRef } = useFishjamContext();
|
|
5
|
+
const audioDeviceState = useDeviceManager(audioDeviceManagerRef.current);
|
|
6
|
+
return audioDeviceState;
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDeviceManager.d.ts","sourceRoot":"","sources":["../../../src/hooks/deviceManagers/useDeviceManager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAuB,MAAM,qBAAqB,CAAC;AAc9E,eAAO,MAAM,gBAAgB,kBAAmB,aAAa,uBAoC5D,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useCallback, useRef, useSyncExternalStore } from "react";
|
|
2
|
+
const eventNames = [
|
|
3
|
+
"deviceDisabled",
|
|
4
|
+
"deviceEnabled",
|
|
5
|
+
"managerStarted",
|
|
6
|
+
"deviceStopped",
|
|
7
|
+
"deviceReady",
|
|
8
|
+
"devicesStarted",
|
|
9
|
+
"devicesReady",
|
|
10
|
+
"managerInitialized",
|
|
11
|
+
"error",
|
|
12
|
+
];
|
|
13
|
+
export const useDeviceManager = (deviceManager) => {
|
|
14
|
+
const mutationRef = useRef(false);
|
|
15
|
+
const subscribe = useCallback((subscribeCallback) => {
|
|
16
|
+
const callback = () => {
|
|
17
|
+
mutationRef.current = true;
|
|
18
|
+
subscribeCallback();
|
|
19
|
+
};
|
|
20
|
+
eventNames.forEach((eventName) => deviceManager.on(eventName, callback));
|
|
21
|
+
return () => {
|
|
22
|
+
eventNames.forEach((eventName) => deviceManager.removeListener(eventName, callback));
|
|
23
|
+
};
|
|
24
|
+
}, [deviceManager]);
|
|
25
|
+
const lastSnapshotRef = useRef(null);
|
|
26
|
+
const getSnapshot = useCallback(() => {
|
|
27
|
+
if (mutationRef.current || lastSnapshotRef.current === null) {
|
|
28
|
+
lastSnapshotRef.current = {
|
|
29
|
+
deviceState: deviceManager.deviceState,
|
|
30
|
+
status: deviceManager.getStatus(),
|
|
31
|
+
tracks: deviceManager.getTracks(),
|
|
32
|
+
};
|
|
33
|
+
mutationRef.current = false;
|
|
34
|
+
}
|
|
35
|
+
return lastSnapshotRef.current;
|
|
36
|
+
}, [deviceManager]);
|
|
37
|
+
const deviceState = useSyncExternalStore(subscribe, getSnapshot);
|
|
38
|
+
return deviceState;
|
|
39
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useVideoDeviceManager.d.ts","sourceRoot":"","sources":["../../../src/hooks/deviceManagers/useVideoDeviceManager.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB,gDAKjC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useFishjamContext } from "../useFishjamContext";
|
|
2
|
+
import { useDeviceManager } from "./useDeviceManager";
|
|
3
|
+
export const useVideoDeviceManager = () => {
|
|
4
|
+
const { videoDeviceManagerRef } = useFishjamContext();
|
|
5
|
+
const videoDeviceState = useDeviceManager(videoDeviceManagerRef.current);
|
|
6
|
+
return videoDeviceState;
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/hooks/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useFishjamClient_DO_NOT_USE } from "./useFishjamClient_DO_NOT_USE";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { useConnect, useDisconnect } from "./useConnection";
|
|
2
|
+
export { useReconnection } from "./useReconnection";
|
|
3
|
+
export { useCamera, useMicrophone, useInitializeDevices } from "./useDevices";
|
|
4
|
+
export { useParticipants } from "./useParticipants";
|
|
5
|
+
export { useScreenShare } from "./useScreenShare";
|
|
6
|
+
export { useStatus } from "./useStatus";
|
|
7
|
+
export { useAudioDeviceManager } from "./deviceManagers/useAudioDeviceManager";
|
|
8
|
+
export { useVideoDeviceManager } from "./deviceManagers/useVideoDeviceManager";
|
|
9
|
+
//# sourceMappingURL=public.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../src/hooks/public.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAC/E,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { useConnect, useDisconnect } from "./useConnection";
|
|
2
|
+
export { useReconnection } from "./useReconnection";
|
|
3
|
+
export { useCamera, useMicrophone, useInitializeDevices } from "./useDevices";
|
|
4
|
+
export { useParticipants } from "./useParticipants";
|
|
5
|
+
export { useScreenShare } from "./useScreenShare";
|
|
6
|
+
export { useStatus } from "./useStatus";
|
|
7
|
+
export { useAudioDeviceManager } from "./deviceManagers/useAudioDeviceManager";
|
|
8
|
+
export { useVideoDeviceManager } from "./deviceManagers/useVideoDeviceManager";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConnection.d.ts","sourceRoot":"","sources":["../../src/hooks/useConnection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,UAAU,EAAE,MAAM,UAAU,CAAC;AAI1D,wBAAgB,UAAU,IAAI,UAAU,CAOvC;AAED,wBAAgB,aAAa,eAM5B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { useFishjamContext } from "./useFishjamContext";
|
|
3
|
+
export function useConnect() {
|
|
4
|
+
const client = useFishjamContext().fishjamClientRef.current;
|
|
5
|
+
return useCallback((config) => client.connect({ ...config, peerMetadata: config.peerMetadata ?? {} }), [client]);
|
|
6
|
+
}
|
|
7
|
+
export function useDisconnect() {
|
|
8
|
+
const client = useFishjamContext().fishjamClientRef.current;
|
|
9
|
+
return useCallback(() => {
|
|
10
|
+
client.disconnect();
|
|
11
|
+
}, [client]);
|
|
12
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AudioDevice, Device } from "../types";
|
|
2
|
+
export declare function useCamera(): Device;
|
|
3
|
+
export declare function useMicrophone(): AudioDevice;
|
|
4
|
+
export declare const useInitializeDevices: () => {
|
|
5
|
+
initializeDevices: () => Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=useDevices.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDevices.d.ts","sourceRoot":"","sources":["../../src/hooks/useDevices.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAQpD,wBAAgB,SAAS,IAAI,MAAM,CAuBlC;AAED,wBAAgB,aAAa,IAAI,WAAW,CA0B3C;AAED,eAAO,MAAM,oBAAoB;;CAqDhC,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { useFishjamContext } from "./useFishjamContext";
|
|
2
|
+
import { useVideoDeviceManager } from "./deviceManagers/useVideoDeviceManager";
|
|
3
|
+
import { useAudioDeviceManager } from "./deviceManagers/useAudioDeviceManager";
|
|
4
|
+
import { useCallback } from "react";
|
|
5
|
+
import { getAvailableMedia, getCorrectedResult } from "../mediaInitializer";
|
|
6
|
+
import { useProcessedPreviewStream } from "./useProcessedPreviewStream";
|
|
7
|
+
import { prepareConstraints } from "../constraints";
|
|
8
|
+
export function useCamera() {
|
|
9
|
+
const { videoTrackManager } = useFishjamContext();
|
|
10
|
+
const { deviceState } = useVideoDeviceManager();
|
|
11
|
+
const { currentTrack, ...trackManager } = videoTrackManager;
|
|
12
|
+
const processedPreviewStream = useProcessedPreviewStream(videoTrackManager, deviceState.media?.track);
|
|
13
|
+
const stream = currentTrack?.stream ?? processedPreviewStream ?? deviceState.media?.stream ?? null;
|
|
14
|
+
const isStreaming = Boolean(currentTrack?.stream);
|
|
15
|
+
const track = stream?.getAudioTracks()[0] ?? null;
|
|
16
|
+
const trackId = currentTrack?.trackId ?? null;
|
|
17
|
+
const devices = deviceState.devices ?? [];
|
|
18
|
+
const activeDevice = deviceState.media?.deviceInfo ?? null;
|
|
19
|
+
return {
|
|
20
|
+
...trackManager,
|
|
21
|
+
stream,
|
|
22
|
+
devices,
|
|
23
|
+
activeDevice,
|
|
24
|
+
isStreaming,
|
|
25
|
+
track,
|
|
26
|
+
trackId,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export function useMicrophone() {
|
|
30
|
+
const { audioTrackManager } = useFishjamContext();
|
|
31
|
+
const { deviceState } = useAudioDeviceManager();
|
|
32
|
+
const { currentTrack, ...trackManager } = audioTrackManager;
|
|
33
|
+
const processedPreviewStream = useProcessedPreviewStream(audioTrackManager, deviceState.media?.track);
|
|
34
|
+
const stream = currentTrack?.stream ?? processedPreviewStream ?? deviceState.media?.stream ?? null;
|
|
35
|
+
const isStreaming = Boolean(currentTrack?.stream);
|
|
36
|
+
const track = stream?.getAudioTracks()[0] ?? null;
|
|
37
|
+
const trackId = currentTrack?.trackId ?? null;
|
|
38
|
+
const devices = deviceState.devices ?? [];
|
|
39
|
+
const activeDevice = deviceState.media?.deviceInfo ?? null;
|
|
40
|
+
const isAudioPlaying = currentTrack?.vadStatus === "speech";
|
|
41
|
+
return {
|
|
42
|
+
...trackManager,
|
|
43
|
+
stream,
|
|
44
|
+
isStreaming,
|
|
45
|
+
track,
|
|
46
|
+
trackId,
|
|
47
|
+
devices,
|
|
48
|
+
activeDevice,
|
|
49
|
+
isAudioPlaying,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export const useInitializeDevices = () => {
|
|
53
|
+
const { videoDeviceManagerRef, audioDeviceManagerRef, hasDevicesBeenInitializedRef } = useFishjamContext();
|
|
54
|
+
const initializeDevices = useCallback(async () => {
|
|
55
|
+
if (hasDevicesBeenInitializedRef.current)
|
|
56
|
+
return;
|
|
57
|
+
hasDevicesBeenInitializedRef.current = true;
|
|
58
|
+
const videoManager = videoDeviceManagerRef.current;
|
|
59
|
+
const audioManager = audioDeviceManagerRef.current;
|
|
60
|
+
const constraints = {
|
|
61
|
+
video: videoManager.getConstraints(true),
|
|
62
|
+
audio: audioManager.getConstraints(true),
|
|
63
|
+
};
|
|
64
|
+
const previousDevices = {
|
|
65
|
+
video: videoManager.getLastDevice(),
|
|
66
|
+
audio: audioManager.getLastDevice(),
|
|
67
|
+
};
|
|
68
|
+
// Attempt to start the last selected device to avoid an unnecessary restart.
|
|
69
|
+
// Without this, the first device will start, and `getCorrectedResult` will attempt to fix it.
|
|
70
|
+
let [stream, deviceErrors] = await getAvailableMedia({
|
|
71
|
+
video: prepareConstraints(previousDevices.video?.deviceId, constraints.video),
|
|
72
|
+
audio: prepareConstraints(previousDevices.audio?.deviceId, constraints.audio),
|
|
73
|
+
});
|
|
74
|
+
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
75
|
+
const videoDevices = devices.filter(({ kind }) => kind === "videoinput");
|
|
76
|
+
const audioDevices = devices.filter(({ kind }) => kind === "audioinput");
|
|
77
|
+
if (stream) {
|
|
78
|
+
[stream, deviceErrors] = await getCorrectedResult(stream, deviceErrors, devices, constraints, previousDevices);
|
|
79
|
+
}
|
|
80
|
+
videoManager.initialize(stream, stream?.getVideoTracks()?.[0] ?? null, videoDevices, !!constraints.video, deviceErrors.video);
|
|
81
|
+
audioManager.initialize(stream, stream?.getAudioTracks()?.[0] ?? null, audioDevices, !!constraints.audio, deviceErrors.audio);
|
|
82
|
+
}, [videoDeviceManagerRef, audioDeviceManagerRef, hasDevicesBeenInitializedRef]);
|
|
83
|
+
return { initializeDevices };
|
|
84
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FishjamClient } from "@fishjam-cloud/ts-client";
|
|
2
|
+
import type { PeerMetadata, TrackMetadata } from "../types";
|
|
3
|
+
import type { PeerState } from "../state.types";
|
|
4
|
+
export interface FishjamClientState {
|
|
5
|
+
peers: PeerState[];
|
|
6
|
+
components: PeerState[];
|
|
7
|
+
localPeer: PeerState | null;
|
|
8
|
+
isReconnecting: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function useFishjamClientState(fishjamClient: FishjamClient<PeerMetadata, TrackMetadata>): FishjamClientState;
|
|
11
|
+
//# sourceMappingURL=useFishjamClientState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFishjamClientState.d.ts","sourceRoot":"","sources":["../../src/hooks/useFishjamClientState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA0D,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACtH,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAkB,MAAM,gBAAgB,CAAC;AA0ChE,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC;IAC5B,cAAc,EAAE,OAAO,CAAC;CACzB;AAuCD,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,aAAa,CAAC,YAAY,EAAE,aAAa,CAAC,GAAG,kBAAkB,CAyCnH"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { useCallback, useMemo, useRef, useSyncExternalStore } from "react";
|
|
2
|
+
const eventNames = [
|
|
3
|
+
"socketClose",
|
|
4
|
+
"socketError",
|
|
5
|
+
"socketOpen",
|
|
6
|
+
"authSuccess",
|
|
7
|
+
"authError",
|
|
8
|
+
"disconnected",
|
|
9
|
+
"reconnectionStarted",
|
|
10
|
+
"reconnected",
|
|
11
|
+
"reconnectionRetriesLimitReached",
|
|
12
|
+
"joined",
|
|
13
|
+
"joinError",
|
|
14
|
+
"trackReady",
|
|
15
|
+
"trackAdded",
|
|
16
|
+
"trackRemoved",
|
|
17
|
+
"trackUpdated",
|
|
18
|
+
"peerJoined",
|
|
19
|
+
"peerLeft",
|
|
20
|
+
"peerUpdated",
|
|
21
|
+
"componentAdded",
|
|
22
|
+
"componentRemoved",
|
|
23
|
+
"componentUpdated",
|
|
24
|
+
"connectionError",
|
|
25
|
+
"tracksPriorityChanged",
|
|
26
|
+
"bandwidthEstimationChanged",
|
|
27
|
+
"targetTrackEncodingRequested",
|
|
28
|
+
"localTrackAdded",
|
|
29
|
+
"localTrackRemoved",
|
|
30
|
+
"localTrackReplaced",
|
|
31
|
+
"localTrackMuted",
|
|
32
|
+
"localTrackUnmuted",
|
|
33
|
+
"localTrackBandwidthSet",
|
|
34
|
+
"localTrackEncodingBandwidthSet",
|
|
35
|
+
"localTrackEncodingEnabled",
|
|
36
|
+
"localTrackEncodingDisabled",
|
|
37
|
+
"localPeerMetadataChanged",
|
|
38
|
+
"localTrackMetadataChanged",
|
|
39
|
+
"disconnectRequested",
|
|
40
|
+
];
|
|
41
|
+
function trackContextToTrack(track) {
|
|
42
|
+
return {
|
|
43
|
+
rawMetadata: track.rawMetadata,
|
|
44
|
+
metadata: track.metadata,
|
|
45
|
+
trackId: track.trackId,
|
|
46
|
+
stream: track.stream,
|
|
47
|
+
simulcastConfig: track.simulcastConfig ?? null,
|
|
48
|
+
encoding: track.encoding ?? null,
|
|
49
|
+
vadStatus: track.vadStatus,
|
|
50
|
+
track: track.track,
|
|
51
|
+
metadataParsingError: track.metadataParsingError,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function endpointToPeerState(peer) {
|
|
55
|
+
const tracks = [...peer.tracks].reduce((acc, [, track]) => ({ ...acc, [track.trackId]: trackContextToTrack(track) }), {});
|
|
56
|
+
return {
|
|
57
|
+
rawMetadata: peer.rawMetadata,
|
|
58
|
+
metadata: peer.metadata,
|
|
59
|
+
metadataParsingError: peer.metadataParsingError,
|
|
60
|
+
id: peer.id,
|
|
61
|
+
tracks,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/*
|
|
65
|
+
This is an internally used hook.
|
|
66
|
+
It is not meant to be used by the end user.
|
|
67
|
+
*/
|
|
68
|
+
export function useFishjamClientState(fishjamClient) {
|
|
69
|
+
const client = useMemo(() => fishjamClient, [fishjamClient]);
|
|
70
|
+
const mutationRef = useRef(false);
|
|
71
|
+
const subscribe = useCallback((subscribeCallback) => {
|
|
72
|
+
const callback = () => {
|
|
73
|
+
mutationRef.current = true;
|
|
74
|
+
subscribeCallback();
|
|
75
|
+
};
|
|
76
|
+
eventNames.forEach((eventName) => client.on(eventName, callback));
|
|
77
|
+
return () => {
|
|
78
|
+
eventNames.forEach((eventName) => client.removeListener(eventName, callback));
|
|
79
|
+
};
|
|
80
|
+
}, [client]);
|
|
81
|
+
const lastSnapshotRef = useRef(null);
|
|
82
|
+
const getSnapshot = useCallback(() => {
|
|
83
|
+
if (mutationRef.current || lastSnapshotRef.current === null) {
|
|
84
|
+
const peers = Object.values(client.getRemotePeers()).map(endpointToPeerState);
|
|
85
|
+
const components = Object.values(client.getRemoteComponents()).map(endpointToPeerState);
|
|
86
|
+
const localEndpoint = client.getLocalPeer();
|
|
87
|
+
const localPeer = localEndpoint ? endpointToPeerState(localEndpoint) : null;
|
|
88
|
+
const isReconnecting = client.isReconnecting();
|
|
89
|
+
lastSnapshotRef.current = {
|
|
90
|
+
peers,
|
|
91
|
+
components,
|
|
92
|
+
localPeer,
|
|
93
|
+
isReconnecting,
|
|
94
|
+
};
|
|
95
|
+
mutationRef.current = false;
|
|
96
|
+
}
|
|
97
|
+
return lastSnapshotRef.current;
|
|
98
|
+
}, [client]);
|
|
99
|
+
return useSyncExternalStore(subscribe, getSnapshot);
|
|
100
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFishjamClient_DO_NOT_USE.d.ts","sourceRoot":"","sources":["../../src/hooks/useFishjamClient_DO_NOT_USE.ts"],"names":[],"mappings":"AAGA,wBAAgB,2BAA2B,4GAI1C"}
|