@fishjam-cloud/react-client 0.7.0 → 0.7.2
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 +33 -17
- package/dist/DeviceManager.d.ts.map +1 -1
- package/dist/DeviceManager.js +126 -97
- package/dist/constraints.d.ts +2 -3
- package/dist/constraints.d.ts.map +1 -1
- package/dist/constraints.js +9 -10
- package/dist/devices/MiddlewareManager.d.ts +9 -0
- package/dist/devices/MiddlewareManager.d.ts.map +1 -0
- package/dist/devices/MiddlewareManager.js +26 -0
- package/dist/fishjamProvider.d.ts +8 -6
- package/dist/fishjamProvider.d.ts.map +1 -1
- package/dist/fishjamProvider.js +27 -11
- package/dist/hooks/deviceManagers/useDeviceManager.d.ts +1 -1
- package/dist/hooks/deviceManagers/useDeviceManager.d.ts.map +1 -1
- package/dist/hooks/deviceManagers/useDeviceManager.js +2 -2
- package/dist/hooks/{useDevices.d.ts → devices.d.ts} +14 -2
- package/dist/hooks/devices.d.ts.map +1 -0
- package/dist/hooks/{useDevices.js → devices.js} +29 -15
- package/dist/hooks/public.d.ts +2 -4
- package/dist/hooks/public.d.ts.map +1 -1
- package/dist/hooks/public.js +2 -4
- package/dist/hooks/useConnection.d.ts +10 -2
- package/dist/hooks/useConnection.d.ts.map +1 -1
- package/dist/hooks/useConnection.js +8 -0
- package/dist/hooks/useFishjamClientState.d.ts +1 -2
- package/dist/hooks/useFishjamClientState.d.ts.map +1 -1
- package/dist/hooks/useFishjamClientState.js +0 -4
- package/dist/hooks/useFishjamClient_DO_NOT_USE.d.ts +6 -1
- package/dist/hooks/useFishjamClient_DO_NOT_USE.d.ts.map +1 -1
- package/dist/hooks/useFishjamClient_DO_NOT_USE.js +5 -0
- package/dist/hooks/useFishjamContext.d.ts +4 -4
- package/dist/hooks/useFishjamContext.d.ts.map +1 -1
- package/dist/hooks/usePeerStatus.d.ts +8 -0
- package/dist/hooks/usePeerStatus.d.ts.map +1 -0
- package/dist/hooks/{useParticipantStatus.js → usePeerStatus.js} +12 -12
- package/dist/hooks/usePeers.d.ts +10 -0
- package/dist/hooks/usePeers.d.ts.map +1 -0
- package/dist/hooks/{useParticipants.js → usePeers.js} +8 -5
- package/dist/hooks/useReconnection.d.ts +4 -0
- package/dist/hooks/useReconnection.d.ts.map +1 -1
- package/dist/hooks/useReconnection.js +4 -0
- package/dist/hooks/useScreenShare.d.ts +13 -1
- package/dist/hooks/useScreenShare.d.ts.map +1 -1
- package/dist/hooks/useScreenShare.js +34 -31
- package/dist/hooks/useStatus.d.ts +5 -1
- package/dist/hooks/useStatus.d.ts.map +1 -1
- package/dist/hooks/useStatus.js +4 -0
- package/dist/hooks/useTrackManager.d.ts +4 -4
- package/dist/hooks/useTrackManager.d.ts.map +1 -1
- package/dist/hooks/useTrackManager.js +32 -47
- package/dist/index.d.ts +3 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/dist/mediaInitializer.d.ts +2 -2
- package/dist/mediaInitializer.d.ts.map +1 -1
- package/dist/mediaInitializer.js +30 -1
- package/dist/types/internal.d.ts +119 -0
- package/dist/types/internal.d.ts.map +1 -0
- package/dist/types/public.d.ts +65 -0
- package/dist/types/public.d.ts.map +1 -0
- package/dist/utils/errors.d.ts +1 -1
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/localStorage.d.ts +3 -4
- package/dist/utils/localStorage.d.ts.map +1 -1
- package/dist/utils/localStorage.js +18 -4
- package/dist/utils/track.d.ts +3 -2
- package/dist/utils/track.d.ts.map +1 -1
- package/dist/utils/track.js +8 -2
- package/package.json +7 -7
- package/readme.md +20 -118
- package/dist/hooks/deviceManagers/useAudioDeviceManager.d.ts +0 -2
- package/dist/hooks/deviceManagers/useAudioDeviceManager.d.ts.map +0 -1
- package/dist/hooks/deviceManagers/useAudioDeviceManager.js +0 -7
- package/dist/hooks/deviceManagers/useVideoDeviceManager.d.ts +0 -2
- package/dist/hooks/deviceManagers/useVideoDeviceManager.d.ts.map +0 -1
- package/dist/hooks/deviceManagers/useVideoDeviceManager.js +0 -7
- package/dist/hooks/useDevices.d.ts.map +0 -1
- package/dist/hooks/useParticipantStatus.d.ts +0 -8
- package/dist/hooks/useParticipantStatus.d.ts.map +0 -1
- package/dist/hooks/useParticipants.d.ts +0 -6
- package/dist/hooks/useParticipants.d.ts.map +0 -1
- package/dist/hooks/useProcessedPreviewStream.d.ts +0 -3
- package/dist/hooks/useProcessedPreviewStream.d.ts.map +0 -1
- package/dist/hooks/useProcessedPreviewStream.js +0 -17
- package/dist/state.types.d.ts +0 -42
- package/dist/state.types.d.ts.map +0 -1
- package/dist/types.d.ts +0 -255
- package/dist/types.d.ts.map +0 -1
- package/dist/utils/media.d.ts +0 -12
- package/dist/utils/media.d.ts.map +0 -1
- package/dist/utils/media.js +0 -64
- /package/dist/{state.types.js → types/internal.js} +0 -0
- /package/dist/{types.js → types/public.js} +0 -0
package/dist/DeviceManager.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DeviceError, DeviceManagerStatus, DeviceState, Media, MediaManager } from "./types/internal";
|
|
2
2
|
import type TypedEmitter from "typed-emitter";
|
|
3
|
+
import type { PersistLastDeviceHandlers, TrackMiddleware } from "./types/public";
|
|
4
|
+
export type DeviceType = "audio" | "video";
|
|
3
5
|
export type DeviceManagerEvents = {
|
|
4
6
|
managerStarted: (event: DeviceState & {
|
|
5
7
|
constraints: MediaTrackConstraints | undefined;
|
|
@@ -18,32 +20,46 @@ export type DeviceManagerEvents = {
|
|
|
18
20
|
deviceStopped: (state: DeviceState) => void;
|
|
19
21
|
deviceEnabled: (state: DeviceState) => void;
|
|
20
22
|
deviceDisabled: (state: DeviceState) => void;
|
|
23
|
+
middlewareSet: (state: DeviceState) => void;
|
|
21
24
|
error: (event: any, state: DeviceState) => void;
|
|
22
25
|
};
|
|
26
|
+
export type DeviceManagerConfig = {
|
|
27
|
+
deviceType: DeviceType;
|
|
28
|
+
defaultConstraints: MediaTrackConstraints;
|
|
29
|
+
userConstraints?: boolean | MediaTrackConstraints;
|
|
30
|
+
storage?: boolean | PersistLastDeviceHandlers;
|
|
31
|
+
};
|
|
23
32
|
declare const DeviceManager_base: new () => TypedEmitter<DeviceManagerEvents>;
|
|
24
33
|
export declare class DeviceManager extends DeviceManager_base implements MediaManager {
|
|
25
|
-
private constraints;
|
|
26
|
-
private storageConfig;
|
|
34
|
+
private readonly constraints;
|
|
27
35
|
private status;
|
|
28
36
|
private readonly deviceType;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
private
|
|
37
|
+
private readonly middlewareManager;
|
|
38
|
+
readonly getLastDevice: () => MediaDeviceInfo | null;
|
|
39
|
+
private readonly saveLastDevice;
|
|
40
|
+
private rawMedia;
|
|
41
|
+
private processedMediaTrack;
|
|
42
|
+
private media;
|
|
43
|
+
private mediaStatus;
|
|
44
|
+
private devices;
|
|
45
|
+
private devicesStatus;
|
|
46
|
+
private error;
|
|
47
|
+
constructor({ deviceType, storage, userConstraints, defaultConstraints }: DeviceManagerConfig);
|
|
48
|
+
getState(): DeviceState;
|
|
32
49
|
getStatus(): DeviceManagerStatus;
|
|
33
|
-
getConstraints(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
initialize: (stream: MediaStream | null, track: MediaStreamTrack | null, devices: MediaDeviceInfo[], requestedMedia: boolean, error?: DeviceError | null) =>
|
|
37
|
-
private setupOnEndedCallback;
|
|
38
|
-
private onTrackEnded;
|
|
39
|
-
getLastDevice(): MediaDeviceInfo | null;
|
|
40
|
-
private saveLastDevice;
|
|
50
|
+
getConstraints(): MediaTrackConstraints | boolean;
|
|
51
|
+
getDeviceType: () => DeviceType;
|
|
52
|
+
getMedia: () => Media | null;
|
|
53
|
+
initialize: (stream: MediaStream | null, track: MediaStreamTrack | null, devices: MediaDeviceInfo[], requestedMedia: boolean, error?: DeviceError | null) => void;
|
|
41
54
|
start(deviceId?: string): Promise<void>;
|
|
42
|
-
|
|
55
|
+
setTrackMiddleware(middleware: TrackMiddleware | null): Promise<void>;
|
|
56
|
+
getMiddleware(): TrackMiddleware | null;
|
|
57
|
+
stop(): void;
|
|
43
58
|
disable(): void;
|
|
44
59
|
enable(): void;
|
|
45
|
-
|
|
46
|
-
|
|
60
|
+
private setEnable;
|
|
61
|
+
private updateMedia;
|
|
62
|
+
private setCurrentMedia;
|
|
47
63
|
}
|
|
48
64
|
export {};
|
|
49
65
|
//# sourceMappingURL=DeviceManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeviceManager.d.ts","sourceRoot":"","sources":["../src/DeviceManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,
|
|
1
|
+
{"version":3,"file":"DeviceManager.d.ts","sourceRoot":"","sources":["../src/DeviceManager.ts"],"names":[],"mappings":"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"}
|
package/dist/DeviceManager.js
CHANGED
|
@@ -1,99 +1,93 @@
|
|
|
1
|
-
import { prepareMediaTrackConstraints
|
|
1
|
+
import { prepareMediaTrackConstraints } from "./constraints";
|
|
2
2
|
import EventEmitter from "events";
|
|
3
|
-
import {
|
|
3
|
+
import { MiddlewareManager } from "./devices/MiddlewareManager";
|
|
4
|
+
import { createStorageConfig } from "./utils/localStorage";
|
|
5
|
+
import { setupOnEndedCallback } from "./utils/track";
|
|
4
6
|
import { parseUserMediaError } from "./utils/errors";
|
|
7
|
+
const NOOP = () => { };
|
|
5
8
|
export class DeviceManager extends EventEmitter {
|
|
6
9
|
constraints;
|
|
7
|
-
storageConfig;
|
|
8
10
|
status = "uninitialized";
|
|
9
11
|
deviceType;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
middlewareManager = new MiddlewareManager();
|
|
13
|
+
getLastDevice = () => null;
|
|
14
|
+
saveLastDevice = NOOP;
|
|
15
|
+
rawMedia = null;
|
|
16
|
+
processedMediaTrack = null;
|
|
17
|
+
media = null;
|
|
18
|
+
mediaStatus = "Not requested";
|
|
19
|
+
devices = null;
|
|
20
|
+
devicesStatus = "Not requested";
|
|
21
|
+
error = null;
|
|
22
|
+
constructor({ deviceType, storage, userConstraints, defaultConstraints }) {
|
|
18
23
|
super();
|
|
19
|
-
|
|
24
|
+
const storageConfig = createStorageConfig(deviceType, storage);
|
|
25
|
+
if (storageConfig) {
|
|
26
|
+
this.getLastDevice = storageConfig.getLastDevice;
|
|
27
|
+
this.saveLastDevice = storageConfig.saveLastDevice;
|
|
28
|
+
}
|
|
20
29
|
this.deviceType = deviceType;
|
|
21
|
-
this.constraints =
|
|
30
|
+
this.constraints = userConstraints ?? defaultConstraints;
|
|
22
31
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
getState() {
|
|
33
|
+
return {
|
|
34
|
+
mediaStatus: this.mediaStatus,
|
|
35
|
+
devices: this.devices,
|
|
36
|
+
devicesStatus: this.devicesStatus,
|
|
37
|
+
error: this.error,
|
|
38
|
+
media: this.media,
|
|
39
|
+
currentMiddleware: this.middlewareManager.getMiddleware(),
|
|
40
|
+
};
|
|
29
41
|
}
|
|
30
42
|
getStatus() {
|
|
31
43
|
return this.status;
|
|
32
44
|
}
|
|
33
|
-
getConstraints(
|
|
34
|
-
|
|
35
|
-
return undefined;
|
|
36
|
-
if (currentConstraints === undefined || currentConstraints === true)
|
|
37
|
-
return this.constraints;
|
|
38
|
-
return currentConstraints ?? this.constraints;
|
|
45
|
+
getConstraints() {
|
|
46
|
+
return this.constraints;
|
|
39
47
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
return stream?.getVideoTracks() ?? [];
|
|
48
|
+
getDeviceType = () => {
|
|
49
|
+
return this.deviceType;
|
|
50
|
+
};
|
|
51
|
+
getMedia = () => {
|
|
52
|
+
return this.media;
|
|
47
53
|
};
|
|
48
54
|
initialize = (stream, track, devices, requestedMedia, error = null) => {
|
|
49
|
-
|
|
50
|
-
const
|
|
55
|
+
const deviceInfo = getDeviceInfo(track?.getSettings()?.deviceId || null, devices);
|
|
56
|
+
const [devicesStatus, newError] = prepareStatus(requestedMedia, track);
|
|
57
|
+
this.devices = devices;
|
|
58
|
+
this.devicesStatus = devicesStatus;
|
|
59
|
+
this.mediaStatus = devicesStatus;
|
|
60
|
+
this.error = newError ?? error;
|
|
61
|
+
this.updateMedia({
|
|
62
|
+
stream: track ? stream : null,
|
|
63
|
+
track,
|
|
64
|
+
deviceInfo,
|
|
65
|
+
enabled: Boolean(track?.enabled),
|
|
66
|
+
});
|
|
51
67
|
if (deviceInfo)
|
|
52
|
-
this.saveLastDevice(deviceInfo);
|
|
68
|
+
this.saveLastDevice?.(deviceInfo);
|
|
53
69
|
this.status = "initialized";
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return this.deviceState;
|
|
57
|
-
};
|
|
58
|
-
setupOnEndedCallback() {
|
|
59
|
-
if (this.deviceState?.media?.track) {
|
|
60
|
-
this.deviceState.media.track.addEventListener("ended", async (event) => await this.onTrackEnded(event.target.id));
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
onTrackEnded = async (trackId) => {
|
|
64
|
-
if (trackId === this?.deviceState.media?.track?.id) {
|
|
65
|
-
await this.stop();
|
|
70
|
+
if (track) {
|
|
71
|
+
setupOnEndedCallback(track, () => this?.rawMedia?.track?.id, async () => this.stop());
|
|
66
72
|
}
|
|
73
|
+
this.emit("managerInitialized", this.getState());
|
|
67
74
|
};
|
|
68
|
-
getLastDevice() {
|
|
69
|
-
return this.storageConfig?.getLastDevice?.() ?? null;
|
|
70
|
-
}
|
|
71
|
-
saveLastDevice(info) {
|
|
72
|
-
if (!this.storageConfig)
|
|
73
|
-
console.warn("Device manager storage has been disabled");
|
|
74
|
-
this.storageConfig?.saveLastDevice(info);
|
|
75
|
-
}
|
|
76
75
|
async start(deviceId) {
|
|
77
|
-
const newDeviceId = deviceId ?? this.getLastDevice()?.deviceId;
|
|
78
|
-
const currentDeviceId = this.
|
|
76
|
+
const newDeviceId = deviceId ?? this.getLastDevice?.()?.deviceId;
|
|
77
|
+
const currentDeviceId = this.rawMedia?.deviceInfo?.deviceId;
|
|
79
78
|
const shouldReplaceDevice = Boolean(currentDeviceId && currentDeviceId !== newDeviceId);
|
|
80
79
|
const isDeviceStopped = currentDeviceId === undefined;
|
|
81
80
|
const shouldProceed = isDeviceStopped || shouldReplaceDevice;
|
|
82
|
-
const
|
|
83
|
-
const exactConstraints = shouldProceed && prepareMediaTrackConstraints(newDeviceId, trackConstraints);
|
|
81
|
+
const exactConstraints = shouldProceed && prepareMediaTrackConstraints(newDeviceId, this.constraints);
|
|
84
82
|
if (!exactConstraints)
|
|
85
83
|
return;
|
|
86
|
-
this.
|
|
87
|
-
this.emit("devicesStarted", {
|
|
84
|
+
this.mediaStatus = "Requesting";
|
|
85
|
+
this.emit("devicesStarted", { restarting: shouldReplaceDevice, constraints: exactConstraints }, this.getState());
|
|
88
86
|
try {
|
|
89
87
|
const stream = await navigator.mediaDevices.getUserMedia({ [this.deviceType]: exactConstraints });
|
|
90
|
-
const
|
|
91
|
-
const tracks = this.deviceType === "audio" ? stream.getAudioTracks() : stream.getVideoTracks();
|
|
92
|
-
return tracks[0] ?? null;
|
|
93
|
-
};
|
|
94
|
-
const track = getTrack();
|
|
88
|
+
const track = getTrack(stream, this.deviceType);
|
|
95
89
|
const currentDeviceId = track?.getSettings()?.deviceId;
|
|
96
|
-
const deviceInfo = currentDeviceId ? getDeviceInfo(currentDeviceId, this.
|
|
90
|
+
const deviceInfo = currentDeviceId ? getDeviceInfo(currentDeviceId, this.devices ?? []) : null;
|
|
97
91
|
if (deviceInfo) {
|
|
98
92
|
this.saveLastDevice?.(deviceInfo);
|
|
99
93
|
}
|
|
@@ -110,17 +104,20 @@ export class DeviceManager extends EventEmitter {
|
|
|
110
104
|
// The ended event in Safari has already been emitted and will be handled in the future.
|
|
111
105
|
// Therefore, in the `onTrackEnded` method, events for already stopped tracks are filtered out to prevent the state from being damaged.
|
|
112
106
|
if (shouldReplaceDevice) {
|
|
113
|
-
this.
|
|
107
|
+
this.rawMedia?.track?.stop();
|
|
108
|
+
this.processedMediaTrack?.stop();
|
|
114
109
|
}
|
|
115
|
-
this.
|
|
110
|
+
this.updateMedia({
|
|
116
111
|
stream,
|
|
117
112
|
track,
|
|
118
113
|
deviceInfo,
|
|
119
|
-
enabled:
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
114
|
+
enabled: Boolean(track?.enabled),
|
|
115
|
+
});
|
|
116
|
+
if (track) {
|
|
117
|
+
setupOnEndedCallback(track, () => this?.rawMedia?.track?.id, async () => this.stop());
|
|
118
|
+
}
|
|
119
|
+
this.mediaStatus = "OK";
|
|
120
|
+
this.emit("devicesReady", { ...this.getState(), restarted: shouldReplaceDevice }, this.getState());
|
|
124
121
|
}
|
|
125
122
|
catch (err) {
|
|
126
123
|
const parsedError = parseUserMediaError(err);
|
|
@@ -129,37 +126,69 @@ export class DeviceManager extends EventEmitter {
|
|
|
129
126
|
constraints: exactConstraints,
|
|
130
127
|
};
|
|
131
128
|
if (exactConstraints) {
|
|
132
|
-
this.
|
|
129
|
+
this.error = parsedError;
|
|
133
130
|
}
|
|
134
|
-
this.emit("error", event, this.
|
|
131
|
+
this.emit("error", event, this.getState());
|
|
135
132
|
}
|
|
136
133
|
}
|
|
137
|
-
async
|
|
138
|
-
this.
|
|
139
|
-
this.
|
|
140
|
-
this.
|
|
134
|
+
async setTrackMiddleware(middleware) {
|
|
135
|
+
const rawTrack = this.rawMedia?.track ?? null;
|
|
136
|
+
const processedMedia = this.middlewareManager.applyMiddleware(rawTrack, middleware);
|
|
137
|
+
this.setCurrentMedia(this.rawMedia, processedMedia);
|
|
138
|
+
this.emit("middlewareSet", this.getState());
|
|
139
|
+
}
|
|
140
|
+
getMiddleware() {
|
|
141
|
+
return this.middlewareManager.getMiddleware();
|
|
142
|
+
}
|
|
143
|
+
stop() {
|
|
144
|
+
this.middlewareManager.clearMiddleware();
|
|
145
|
+
this.processedMediaTrack?.stop();
|
|
146
|
+
this.rawMedia?.track?.stop();
|
|
147
|
+
this.updateMedia(null);
|
|
148
|
+
this.emit("deviceStopped", this.getState());
|
|
141
149
|
}
|
|
142
150
|
disable() {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
this.deviceState.media.track.enabled = false;
|
|
147
|
-
this.deviceState.media.enabled = false;
|
|
148
|
-
this.emit("deviceDisabled", this.deviceState);
|
|
151
|
+
this.setEnable(this.rawMedia?.track ?? null, false);
|
|
152
|
+
this.setEnable(this.processedMediaTrack, false);
|
|
153
|
+
this.emit("deviceDisabled", this.getState());
|
|
149
154
|
}
|
|
150
155
|
enable() {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
this.deviceState.media.track.enabled = true;
|
|
155
|
-
this.deviceState.media.enabled = true;
|
|
156
|
-
this.emit("deviceEnabled", this.deviceState);
|
|
156
|
+
this.setEnable(this.rawMedia?.track ?? null, true);
|
|
157
|
+
this.setEnable(this.processedMediaTrack, true);
|
|
158
|
+
this.emit("deviceEnabled", this.getState());
|
|
157
159
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
+
setEnable = (track, value) => {
|
|
161
|
+
if (!track)
|
|
162
|
+
return;
|
|
163
|
+
track.enabled = value;
|
|
160
164
|
};
|
|
161
|
-
|
|
162
|
-
this.
|
|
163
|
-
|
|
165
|
+
updateMedia(media) {
|
|
166
|
+
this.rawMedia = !media ? null : { ...media };
|
|
167
|
+
const processedMedia = this.middlewareManager.applyMiddleware(media?.track ?? null);
|
|
168
|
+
this.setCurrentMedia(this.rawMedia, processedMedia);
|
|
169
|
+
}
|
|
170
|
+
setCurrentMedia(media, processedTrack) {
|
|
171
|
+
this.processedMediaTrack = processedTrack;
|
|
172
|
+
const streamTrack = processedTrack ? { track: processedTrack, stream: new MediaStream([processedTrack]) } : media;
|
|
173
|
+
this.media = streamTrack
|
|
174
|
+
? {
|
|
175
|
+
...streamTrack,
|
|
176
|
+
enabled: Boolean(streamTrack.track?.enabled),
|
|
177
|
+
deviceInfo: this.rawMedia?.deviceInfo ?? null,
|
|
178
|
+
}
|
|
179
|
+
: null;
|
|
164
180
|
}
|
|
165
181
|
}
|
|
182
|
+
function getDeviceInfo(trackDeviceId, devices) {
|
|
183
|
+
return (trackDeviceId && devices.find(({ deviceId }) => trackDeviceId === deviceId)) || null;
|
|
184
|
+
}
|
|
185
|
+
function getTrack(stream, deviceType) {
|
|
186
|
+
return (deviceType === "audio" ? stream?.getAudioTracks()?.[0] : stream?.getVideoTracks()?.[0]) ?? null;
|
|
187
|
+
}
|
|
188
|
+
function prepareStatus(requested, track) {
|
|
189
|
+
if (!requested)
|
|
190
|
+
return ["Not requested", null];
|
|
191
|
+
if (track)
|
|
192
|
+
return ["OK", null];
|
|
193
|
+
return ["Error", null];
|
|
194
|
+
}
|
package/dist/constraints.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
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
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const prepareConstraints: (deviceIdToStart: string | undefined, constraints: MediaTrackConstraints | undefined) => MediaTrackConstraints | undefined;
|
|
4
|
+
export declare const prepareMediaTrackConstraints: (deviceId: string | undefined, constraints: MediaTrackConstraints | undefined | boolean) => MediaTrackConstraints | boolean;
|
|
5
|
+
export declare const prepareConstraints: (deviceIdToStart: string | undefined, constraints: MediaTrackConstraints | undefined | boolean) => MediaTrackConstraints | undefined | boolean;
|
|
7
6
|
//# 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,
|
|
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,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"}
|
package/dist/constraints.js
CHANGED
|
@@ -24,20 +24,19 @@ export const SCREEN_SHARING_MEDIA_CONSTRAINTS = {
|
|
|
24
24
|
height: { max: 1080, ideal: 1080 },
|
|
25
25
|
},
|
|
26
26
|
};
|
|
27
|
-
export const toMediaTrackConstraints = (constraint) => {
|
|
28
|
-
if (typeof constraint === "boolean") {
|
|
29
|
-
return constraint ? {} : undefined;
|
|
30
|
-
}
|
|
31
|
-
return constraint;
|
|
32
|
-
};
|
|
33
27
|
export const prepareMediaTrackConstraints = (deviceId, constraints) => {
|
|
28
|
+
const trackConstraints = typeof constraints === "boolean" ? {} : constraints;
|
|
34
29
|
if (!deviceId)
|
|
35
|
-
return { ...
|
|
36
|
-
|
|
37
|
-
return { ...constraints, ...exactId };
|
|
30
|
+
return { ...trackConstraints };
|
|
31
|
+
return { ...trackConstraints, deviceId: { exact: deviceId } };
|
|
38
32
|
};
|
|
39
33
|
export const prepareConstraints = (deviceIdToStart, constraints) => {
|
|
40
34
|
if (!deviceIdToStart)
|
|
41
35
|
return constraints;
|
|
42
|
-
|
|
36
|
+
// The resulting stream will not contain a track of this type,
|
|
37
|
+
// which means that the device will not be activated.
|
|
38
|
+
if (constraints === false)
|
|
39
|
+
return false;
|
|
40
|
+
const constraintsObj = constraints === true ? {} : constraints;
|
|
41
|
+
return { ...constraintsObj, deviceId: { ideal: deviceIdToStart } };
|
|
43
42
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TrackMiddleware } from "../types/public";
|
|
2
|
+
export declare class MiddlewareManager {
|
|
3
|
+
private middleware;
|
|
4
|
+
private clearMiddlewareFn;
|
|
5
|
+
getMiddleware(): TrackMiddleware | null;
|
|
6
|
+
clearMiddleware(): void;
|
|
7
|
+
applyMiddleware(rawTrack: MediaStreamTrack | null, middleware?: TrackMiddleware | null): MediaStreamTrack | null;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=MiddlewareManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MiddlewareManager.d.ts","sourceRoot":"","sources":["../../src/devices/MiddlewareManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGvD,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,UAAU,CAAgC;IAClD,OAAO,CAAC,iBAAiB,CAA6B;IAE/C,aAAa,IAAI,eAAe,GAAG,IAAI;IAIvC,eAAe;IAKf,eAAe,CACpB,QAAQ,EAAE,gBAAgB,GAAG,IAAI,EACjC,UAAU,GAAE,eAAe,GAAG,IAAsB,GACnD,gBAAgB,GAAG,IAAI;CAmB3B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { setupOnEndedCallback } from "../utils/track";
|
|
2
|
+
export class MiddlewareManager {
|
|
3
|
+
middleware = null;
|
|
4
|
+
clearMiddlewareFn = null;
|
|
5
|
+
getMiddleware() {
|
|
6
|
+
return this.middleware;
|
|
7
|
+
}
|
|
8
|
+
clearMiddleware() {
|
|
9
|
+
this.clearMiddlewareFn?.();
|
|
10
|
+
this.clearMiddlewareFn = null;
|
|
11
|
+
}
|
|
12
|
+
applyMiddleware(rawTrack, middleware = this.middleware) {
|
|
13
|
+
this.middleware = middleware;
|
|
14
|
+
this.clearMiddleware();
|
|
15
|
+
if (!rawTrack || !middleware)
|
|
16
|
+
return null;
|
|
17
|
+
const { onClear, track } = middleware(rawTrack);
|
|
18
|
+
if (onClear)
|
|
19
|
+
this.clearMiddlewareFn = onClear;
|
|
20
|
+
setupOnEndedCallback(track, () => track.id, async () => {
|
|
21
|
+
this.clearMiddleware();
|
|
22
|
+
track.stop();
|
|
23
|
+
});
|
|
24
|
+
return track;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { type PropsWithChildren } from "react";
|
|
2
|
-
import type { DeviceManagerConfig } from "./types";
|
|
3
2
|
import { type ReconnectConfig } from "@fishjam-cloud/ts-client";
|
|
3
|
+
import type { PersistLastDeviceHandlers } from "./types/public";
|
|
4
4
|
interface FishjamProviderProps extends PropsWithChildren {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
deviceManagerDefaultConfig?: DeviceManagerConfig;
|
|
5
|
+
reconnect?: ReconnectConfig | boolean;
|
|
6
|
+
constraints?: Pick<MediaStreamConstraints, "audio" | "video">;
|
|
7
|
+
persistLastDevice?: boolean | PersistLastDeviceHandlers;
|
|
9
8
|
}
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @category Components
|
|
11
|
+
*/
|
|
12
|
+
export declare function FishjamProvider({ children, reconnect, constraints, persistLastDevice }: FishjamProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
11
13
|
export {};
|
|
12
14
|
//# sourceMappingURL=fishjamProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fishjamProvider.d.ts","sourceRoot":"","sources":["../src/fishjamProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"fishjamProvider.d.ts","sourceRoot":"","sources":["../src/fishjamProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAGvD,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAO/E,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAGhE,UAAU,oBAAqB,SAAQ,iBAAiB;IACtD,SAAS,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC;IACtC,WAAW,CAAC,EAAE,IAAI,CAAC,sBAAsB,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC;IAC9D,iBAAiB,CAAC,EAAE,OAAO,GAAG,yBAAyB,CAAC;CACzD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,iBAAiB,EAAE,EAAE,oBAAoB,2CAuD5G"}
|
package/dist/fishjamProvider.js
CHANGED
|
@@ -1,33 +1,49 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useRef
|
|
2
|
+
import { useRef } from "react";
|
|
3
3
|
import { useTrackManager } from "./hooks/useTrackManager";
|
|
4
4
|
import { FishjamClient } from "@fishjam-cloud/ts-client";
|
|
5
5
|
import { FishjamContext } from "./hooks/useFishjamContext";
|
|
6
6
|
import { DeviceManager } from "./DeviceManager";
|
|
7
|
-
import {
|
|
7
|
+
import { usePeerStatus } from "./hooks/usePeerStatus";
|
|
8
8
|
import { useFishjamClientState } from "./hooks/useFishjamClientState";
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
import { AUDIO_TRACK_CONSTRAINTS, VIDEO_TRACK_CONSTRAINTS } from "./constraints";
|
|
10
|
+
import { useScreenShareManager } from "./hooks/useScreenShare";
|
|
11
|
+
/**
|
|
12
|
+
* @category Components
|
|
13
|
+
*/
|
|
14
|
+
export function FishjamProvider({ children, reconnect, constraints, persistLastDevice }) {
|
|
15
|
+
const fishjamClientRef = useRef(new FishjamClient({ reconnect }));
|
|
11
16
|
const hasDevicesBeenInitializedRef = useRef(false);
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
const storage = persistLastDevice;
|
|
18
|
+
const videoDeviceManagerRef = useRef(new DeviceManager({
|
|
19
|
+
deviceType: "video",
|
|
20
|
+
defaultConstraints: VIDEO_TRACK_CONSTRAINTS,
|
|
21
|
+
userConstraints: constraints?.video,
|
|
22
|
+
storage,
|
|
23
|
+
}));
|
|
24
|
+
const audioDeviceManagerRef = useRef(new DeviceManager({
|
|
25
|
+
deviceType: "audio",
|
|
26
|
+
defaultConstraints: AUDIO_TRACK_CONSTRAINTS,
|
|
27
|
+
userConstraints: constraints?.audio,
|
|
28
|
+
storage,
|
|
29
|
+
}));
|
|
30
|
+
const { peerStatus, getCurrentPeerStatus } = usePeerStatus(fishjamClientRef.current);
|
|
16
31
|
const videoTrackManager = useTrackManager({
|
|
17
32
|
mediaManager: videoDeviceManagerRef.current,
|
|
18
33
|
tsClient: fishjamClientRef.current,
|
|
19
|
-
|
|
34
|
+
getCurrentPeerStatus,
|
|
20
35
|
});
|
|
21
36
|
const audioTrackManager = useTrackManager({
|
|
22
37
|
mediaManager: audioDeviceManagerRef.current,
|
|
23
38
|
tsClient: fishjamClientRef.current,
|
|
24
|
-
|
|
39
|
+
getCurrentPeerStatus,
|
|
25
40
|
});
|
|
41
|
+
const screenShareManager = useScreenShareManager({ fishjamClient: fishjamClientRef.current });
|
|
26
42
|
const clientState = useFishjamClientState(fishjamClientRef.current);
|
|
27
43
|
const context = {
|
|
28
44
|
fishjamClientRef,
|
|
29
45
|
peerStatus,
|
|
30
|
-
|
|
46
|
+
screenShareManager,
|
|
31
47
|
videoTrackManager,
|
|
32
48
|
audioTrackManager,
|
|
33
49
|
videoDeviceManagerRef,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DeviceManagerState } from "../../types";
|
|
1
|
+
import type { DeviceManagerState } from "../../types/internal";
|
|
2
2
|
import type { DeviceManager } from "../../DeviceManager";
|
|
3
3
|
export declare const useDeviceManager: (deviceManager: DeviceManager) => DeviceManagerState;
|
|
4
4
|
//# sourceMappingURL=useDeviceManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDeviceManager.d.ts","sourceRoot":"","sources":["../../../src/hooks/deviceManagers/useDeviceManager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"useDeviceManager.d.ts","sourceRoot":"","sources":["../../../src/hooks/deviceManagers/useDeviceManager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAuB,MAAM,qBAAqB,CAAC;AAe9E,eAAO,MAAM,gBAAgB,kBAAmB,aAAa,uBAmC5D,CAAC"}
|
|
@@ -9,6 +9,7 @@ const eventNames = [
|
|
|
9
9
|
"devicesReady",
|
|
10
10
|
"managerInitialized",
|
|
11
11
|
"error",
|
|
12
|
+
"middlewareSet",
|
|
12
13
|
];
|
|
13
14
|
export const useDeviceManager = (deviceManager) => {
|
|
14
15
|
const mutationRef = useRef(false);
|
|
@@ -26,9 +27,8 @@ export const useDeviceManager = (deviceManager) => {
|
|
|
26
27
|
const getSnapshot = useCallback(() => {
|
|
27
28
|
if (mutationRef.current || lastSnapshotRef.current === null) {
|
|
28
29
|
lastSnapshotRef.current = {
|
|
29
|
-
deviceState: deviceManager.
|
|
30
|
+
deviceState: deviceManager.getState(),
|
|
30
31
|
status: deviceManager.getStatus(),
|
|
31
|
-
tracks: deviceManager.getTracks(),
|
|
32
32
|
};
|
|
33
33
|
mutationRef.current = false;
|
|
34
34
|
}
|
|
@@ -1,7 +1,19 @@
|
|
|
1
|
-
import type { AudioDevice, Device } from "../types";
|
|
1
|
+
import type { AudioDevice, Device } from "../types/public";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @category Devices
|
|
5
|
+
*/
|
|
2
6
|
export declare function useCamera(): Device;
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @category Devices
|
|
10
|
+
*/
|
|
3
11
|
export declare function useMicrophone(): AudioDevice;
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @category Devices
|
|
15
|
+
*/
|
|
4
16
|
export declare const useInitializeDevices: () => {
|
|
5
17
|
initializeDevices: () => Promise<void>;
|
|
6
18
|
};
|
|
7
|
-
//# sourceMappingURL=
|
|
19
|
+
//# sourceMappingURL=devices.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devices.d.ts","sourceRoot":"","sources":["../../src/hooks/devices.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAK3D;;;GAGG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAyBlC;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,WAAW,CA2B3C;AAED;;;GAGG;AACH,eAAO,MAAM,oBAAoB;;CAqDhC,CAAC"}
|