@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/Client.js
DELETED
|
@@ -1,461 +0,0 @@
|
|
|
1
|
-
import EventEmitter from "events";
|
|
2
|
-
import { FishjamClient } from "@fishjam-cloud/ts-client";
|
|
3
|
-
import { DeviceManager } from "./DeviceManager";
|
|
4
|
-
import { getAvailableMedia, getCorrectedResult } from "./mediaInitializer";
|
|
5
|
-
export class Client extends EventEmitter {
|
|
6
|
-
tsClient;
|
|
7
|
-
local = null;
|
|
8
|
-
peers = {};
|
|
9
|
-
components = {};
|
|
10
|
-
peersTracks = {};
|
|
11
|
-
componentsTracks = {};
|
|
12
|
-
bandwidthEstimation = BigInt(0);
|
|
13
|
-
status = null;
|
|
14
|
-
media = null;
|
|
15
|
-
devices;
|
|
16
|
-
reconnectionStatus = "idle";
|
|
17
|
-
videoDeviceManager;
|
|
18
|
-
audioDeviceManager;
|
|
19
|
-
initialized = false;
|
|
20
|
-
constructor(config) {
|
|
21
|
-
super();
|
|
22
|
-
this.tsClient = new FishjamClient(config?.clientConfig);
|
|
23
|
-
this.videoDeviceManager = new DeviceManager("video", config?.deviceManagerDefaultConfig);
|
|
24
|
-
this.audioDeviceManager = new DeviceManager("audio", config?.deviceManagerDefaultConfig);
|
|
25
|
-
this.devices = {
|
|
26
|
-
camera: {
|
|
27
|
-
status: null,
|
|
28
|
-
stream: null,
|
|
29
|
-
track: null,
|
|
30
|
-
enabled: false,
|
|
31
|
-
mediaStatus: null,
|
|
32
|
-
deviceInfo: null,
|
|
33
|
-
error: null,
|
|
34
|
-
devices: null,
|
|
35
|
-
},
|
|
36
|
-
microphone: {
|
|
37
|
-
status: null,
|
|
38
|
-
stream: null,
|
|
39
|
-
track: null,
|
|
40
|
-
enabled: false,
|
|
41
|
-
mediaStatus: null,
|
|
42
|
-
deviceInfo: null,
|
|
43
|
-
error: null,
|
|
44
|
-
devices: null,
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
this.stateToSnapshot();
|
|
48
|
-
this.tsClient.on("disconnected", () => {
|
|
49
|
-
this.status = null;
|
|
50
|
-
this.stateToSnapshot();
|
|
51
|
-
this.emit("disconnected", this);
|
|
52
|
-
});
|
|
53
|
-
this.tsClient.on("socketOpen", (event) => {
|
|
54
|
-
this.status = "connected";
|
|
55
|
-
this.stateToSnapshot();
|
|
56
|
-
this.emit("socketOpen", event, this);
|
|
57
|
-
});
|
|
58
|
-
this.tsClient.on("socketError", (event) => {
|
|
59
|
-
this.stateToSnapshot();
|
|
60
|
-
this.emit("socketError", event, this);
|
|
61
|
-
});
|
|
62
|
-
this.tsClient.on("socketClose", (event) => {
|
|
63
|
-
this.stateToSnapshot();
|
|
64
|
-
this.emit("socketClose", event, this);
|
|
65
|
-
});
|
|
66
|
-
this.tsClient.on("authSuccess", () => {
|
|
67
|
-
this.status = "authenticated";
|
|
68
|
-
this.stateToSnapshot();
|
|
69
|
-
this.emit("authSuccess", this);
|
|
70
|
-
});
|
|
71
|
-
this.tsClient.on("authError", (reason) => {
|
|
72
|
-
this.stateToSnapshot();
|
|
73
|
-
this.status = "error";
|
|
74
|
-
this.emit("authError", reason, this);
|
|
75
|
-
});
|
|
76
|
-
this.tsClient.on("joined", (peerId, peers, components) => {
|
|
77
|
-
this.status = "joined";
|
|
78
|
-
this.stateToSnapshot();
|
|
79
|
-
this.emit("joined", { peerId, peers, components }, this);
|
|
80
|
-
});
|
|
81
|
-
this.tsClient.on("joinError", (metadata) => {
|
|
82
|
-
this.status = "error";
|
|
83
|
-
this.stateToSnapshot();
|
|
84
|
-
this.emit("joinError", metadata, this);
|
|
85
|
-
});
|
|
86
|
-
this.tsClient.on("reconnectionStarted", () => {
|
|
87
|
-
this.reconnectionStatus = "reconnecting";
|
|
88
|
-
this.stateToSnapshot();
|
|
89
|
-
this.emit("reconnectionStarted", this);
|
|
90
|
-
});
|
|
91
|
-
this.tsClient.on("reconnected", () => {
|
|
92
|
-
this.reconnectionStatus = "idle";
|
|
93
|
-
this.stateToSnapshot();
|
|
94
|
-
this.emit("reconnected", this);
|
|
95
|
-
});
|
|
96
|
-
this.tsClient.on("reconnectionRetriesLimitReached", () => {
|
|
97
|
-
this.reconnectionStatus = "error";
|
|
98
|
-
this.stateToSnapshot();
|
|
99
|
-
this.emit("reconnectionRetriesLimitReached", this);
|
|
100
|
-
});
|
|
101
|
-
this.tsClient.on("connectionError", (metadata) => {
|
|
102
|
-
this.status = "error";
|
|
103
|
-
this.stateToSnapshot();
|
|
104
|
-
this.emit("connectionError", metadata, this);
|
|
105
|
-
});
|
|
106
|
-
this.tsClient.on("peerJoined", (peer) => {
|
|
107
|
-
this.stateToSnapshot();
|
|
108
|
-
this.emit("peerJoined", peer, this);
|
|
109
|
-
});
|
|
110
|
-
this.tsClient.on("peerUpdated", (peer) => {
|
|
111
|
-
this.stateToSnapshot();
|
|
112
|
-
this.emit("peerUpdated", peer, this);
|
|
113
|
-
});
|
|
114
|
-
this.tsClient.on("peerLeft", (peer) => {
|
|
115
|
-
this.stateToSnapshot();
|
|
116
|
-
this.emit("peerLeft", peer, this);
|
|
117
|
-
});
|
|
118
|
-
this.tsClient.on("componentAdded", (component) => {
|
|
119
|
-
this.stateToSnapshot();
|
|
120
|
-
this.emit("componentAdded", component, this);
|
|
121
|
-
});
|
|
122
|
-
this.tsClient.on("componentUpdated", (component) => {
|
|
123
|
-
this.stateToSnapshot();
|
|
124
|
-
this.emit("componentUpdated", component, this);
|
|
125
|
-
});
|
|
126
|
-
this.tsClient.on("componentRemoved", (component) => {
|
|
127
|
-
this.stateToSnapshot();
|
|
128
|
-
this.emit("componentRemoved", component, this);
|
|
129
|
-
});
|
|
130
|
-
this.tsClient.on("trackReady", (ctx) => {
|
|
131
|
-
this.stateToSnapshot();
|
|
132
|
-
this.emit("trackReady", ctx, this);
|
|
133
|
-
});
|
|
134
|
-
this.tsClient.on("trackAdded", (ctx) => {
|
|
135
|
-
this.stateToSnapshot();
|
|
136
|
-
this.emit("trackAdded", ctx, this);
|
|
137
|
-
ctx.on("encodingChanged", () => {
|
|
138
|
-
this.stateToSnapshot();
|
|
139
|
-
this.emit("encodingChanged", ctx, this);
|
|
140
|
-
});
|
|
141
|
-
ctx.on("voiceActivityChanged", () => {
|
|
142
|
-
this.stateToSnapshot();
|
|
143
|
-
this.emit("voiceActivityChanged", ctx, this);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
this.tsClient.on("trackRemoved", (ctx) => {
|
|
147
|
-
this.stateToSnapshot();
|
|
148
|
-
this.emit("trackRemoved", ctx, this);
|
|
149
|
-
ctx.removeAllListeners();
|
|
150
|
-
});
|
|
151
|
-
this.tsClient.on("trackUpdated", (ctx) => {
|
|
152
|
-
this.stateToSnapshot();
|
|
153
|
-
this.emit("trackUpdated", ctx, this);
|
|
154
|
-
});
|
|
155
|
-
this.tsClient.on("bandwidthEstimationChanged", (estimation) => {
|
|
156
|
-
this.stateToSnapshot();
|
|
157
|
-
this.emit("bandwidthEstimationChanged", estimation, this);
|
|
158
|
-
});
|
|
159
|
-
this.videoDeviceManager.on("deviceDisabled", (state) => {
|
|
160
|
-
this.stateToSnapshot();
|
|
161
|
-
this.emit("deviceDisabled", { ...state, trackType: "video", mediaDeviceType: "userMedia" }, this);
|
|
162
|
-
});
|
|
163
|
-
this.videoDeviceManager.on("deviceEnabled", (state) => {
|
|
164
|
-
this.stateToSnapshot();
|
|
165
|
-
this.emit("deviceEnabled", { ...state, trackType: "video", mediaDeviceType: "userMedia" }, this);
|
|
166
|
-
});
|
|
167
|
-
this.videoDeviceManager.on("managerStarted", (state) => {
|
|
168
|
-
this.stateToSnapshot();
|
|
169
|
-
this.emit("managerStarted", { ...state, trackType: "video", mediaDeviceType: "userMedia" }, this);
|
|
170
|
-
});
|
|
171
|
-
this.videoDeviceManager.on("deviceStopped", (state) => {
|
|
172
|
-
this.stateToSnapshot();
|
|
173
|
-
this.emit("deviceStopped", { ...state, trackType: "video", mediaDeviceType: "userMedia" }, this);
|
|
174
|
-
});
|
|
175
|
-
this.videoDeviceManager.on("deviceReady", ({ stream }) => {
|
|
176
|
-
this.stateToSnapshot();
|
|
177
|
-
this.emit("deviceReady", { trackType: "video", stream, mediaDeviceType: "userMedia" }, this);
|
|
178
|
-
});
|
|
179
|
-
this.videoDeviceManager.on("devicesStarted", (event) => {
|
|
180
|
-
this.stateToSnapshot();
|
|
181
|
-
this.emit("devicesStarted", { ...event, trackType: "video", mediaDeviceType: "userMedia" }, this);
|
|
182
|
-
});
|
|
183
|
-
this.videoDeviceManager.on("devicesReady", (event) => {
|
|
184
|
-
this.stateToSnapshot();
|
|
185
|
-
this.emit("devicesReady", { ...event, trackType: "video", mediaDeviceType: "userMedia" }, this);
|
|
186
|
-
});
|
|
187
|
-
this.videoDeviceManager.on("error", (event) => {
|
|
188
|
-
this.stateToSnapshot();
|
|
189
|
-
this.emit("error", event, this);
|
|
190
|
-
});
|
|
191
|
-
this.audioDeviceManager.on("deviceDisabled", (state) => {
|
|
192
|
-
this.stateToSnapshot();
|
|
193
|
-
this.emit("deviceDisabled", { ...state, trackType: "audio", mediaDeviceType: "userMedia" }, this);
|
|
194
|
-
});
|
|
195
|
-
this.audioDeviceManager.on("deviceEnabled", (state) => {
|
|
196
|
-
this.stateToSnapshot();
|
|
197
|
-
this.emit("deviceEnabled", { ...state, trackType: "audio", mediaDeviceType: "userMedia" }, this);
|
|
198
|
-
});
|
|
199
|
-
this.audioDeviceManager.on("managerStarted", (state) => {
|
|
200
|
-
this.stateToSnapshot();
|
|
201
|
-
this.emit("managerStarted", { ...state, trackType: "audio", mediaDeviceType: "userMedia" }, this);
|
|
202
|
-
});
|
|
203
|
-
this.audioDeviceManager.on("deviceStopped", (state) => {
|
|
204
|
-
this.stateToSnapshot();
|
|
205
|
-
this.emit("deviceStopped", { ...state, trackType: "audio", mediaDeviceType: "userMedia" }, this);
|
|
206
|
-
});
|
|
207
|
-
this.audioDeviceManager.on("deviceReady", ({ stream }) => {
|
|
208
|
-
this.stateToSnapshot();
|
|
209
|
-
this.emit("deviceReady", { trackType: "audio", stream, mediaDeviceType: "userMedia" }, this);
|
|
210
|
-
});
|
|
211
|
-
this.audioDeviceManager.on("devicesStarted", (event) => {
|
|
212
|
-
this.stateToSnapshot();
|
|
213
|
-
this.emit("devicesStarted", { ...event, trackType: "audio", mediaDeviceType: "userMedia" }, this);
|
|
214
|
-
});
|
|
215
|
-
this.audioDeviceManager.on("devicesReady", (event) => {
|
|
216
|
-
this.stateToSnapshot();
|
|
217
|
-
this.emit("devicesReady", { ...event, trackType: "audio", mediaDeviceType: "userMedia" }, this);
|
|
218
|
-
});
|
|
219
|
-
this.audioDeviceManager.on("error", (event) => {
|
|
220
|
-
this.stateToSnapshot();
|
|
221
|
-
this.emit("error", event, this);
|
|
222
|
-
});
|
|
223
|
-
this.tsClient?.on("targetTrackEncodingRequested", (event) => {
|
|
224
|
-
this.stateToSnapshot();
|
|
225
|
-
this.emit("targetTrackEncodingRequested", event, this);
|
|
226
|
-
});
|
|
227
|
-
this.tsClient?.on("localTrackAdded", (event) => {
|
|
228
|
-
this.stateToSnapshot();
|
|
229
|
-
this.emit("localTrackAdded", event, this);
|
|
230
|
-
});
|
|
231
|
-
this.tsClient?.on("localTrackRemoved", (event) => {
|
|
232
|
-
this.stateToSnapshot();
|
|
233
|
-
this.emit("localTrackRemoved", event, this);
|
|
234
|
-
});
|
|
235
|
-
this.tsClient?.on("localTrackReplaced", (event) => {
|
|
236
|
-
this.stateToSnapshot();
|
|
237
|
-
this.emit("localTrackReplaced", event, this);
|
|
238
|
-
});
|
|
239
|
-
this.tsClient?.on("localTrackMuted", (event) => {
|
|
240
|
-
this.stateToSnapshot();
|
|
241
|
-
this.emit("localTrackMuted", event, this);
|
|
242
|
-
});
|
|
243
|
-
this.tsClient?.on("localTrackUnmuted", (event) => {
|
|
244
|
-
this.stateToSnapshot();
|
|
245
|
-
this.emit("localTrackUnmuted", event, this);
|
|
246
|
-
});
|
|
247
|
-
this.tsClient?.on("localTrackBandwidthSet", (event) => {
|
|
248
|
-
this.stateToSnapshot();
|
|
249
|
-
this.emit("localTrackBandwidthSet", event, this);
|
|
250
|
-
});
|
|
251
|
-
this.tsClient?.on("localTrackEncodingBandwidthSet", (event) => {
|
|
252
|
-
this.stateToSnapshot();
|
|
253
|
-
this.emit("localTrackEncodingBandwidthSet", event, this);
|
|
254
|
-
});
|
|
255
|
-
this.tsClient?.on("localTrackEncodingEnabled", (event) => {
|
|
256
|
-
this.stateToSnapshot();
|
|
257
|
-
this.emit("localTrackEncodingEnabled", event, this);
|
|
258
|
-
});
|
|
259
|
-
this.tsClient?.on("localTrackEncodingDisabled", (event) => {
|
|
260
|
-
this.stateToSnapshot();
|
|
261
|
-
this.emit("localTrackEncodingDisabled", event, this);
|
|
262
|
-
});
|
|
263
|
-
this.tsClient?.on("localPeerMetadataChanged", (event) => {
|
|
264
|
-
this.stateToSnapshot();
|
|
265
|
-
this.emit("localPeerMetadataChanged", event, this);
|
|
266
|
-
});
|
|
267
|
-
this.tsClient?.on("localTrackMetadataChanged", (event) => {
|
|
268
|
-
this.stateToSnapshot();
|
|
269
|
-
this.emit("localTrackMetadataChanged", event, this);
|
|
270
|
-
});
|
|
271
|
-
this.tsClient?.on("disconnectRequested", (event) => {
|
|
272
|
-
this.stateToSnapshot();
|
|
273
|
-
this.emit("disconnectRequested", event, this);
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
setDeviceManagerConfig(config) {
|
|
277
|
-
this.videoDeviceManager.setConfig(config.storage, config.trackConstraints);
|
|
278
|
-
this.audioDeviceManager.setConfig(config.storage, config.trackConstraints);
|
|
279
|
-
}
|
|
280
|
-
trackContextToTrack(track) {
|
|
281
|
-
return {
|
|
282
|
-
rawMetadata: track.rawMetadata,
|
|
283
|
-
metadata: track.metadata,
|
|
284
|
-
trackId: track.trackId,
|
|
285
|
-
stream: track.stream,
|
|
286
|
-
simulcastConfig: track.simulcastConfig || null,
|
|
287
|
-
encoding: track.encoding || null,
|
|
288
|
-
vadStatus: track.vadStatus,
|
|
289
|
-
track: track.track,
|
|
290
|
-
metadataParsingError: track.metadataParsingError,
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
getTsClient = () => this.tsClient;
|
|
294
|
-
connect(config) {
|
|
295
|
-
this.status = "connecting";
|
|
296
|
-
this.tsClient.connect({ ...config, peerMetadata: config?.peerMetadata ?? {} });
|
|
297
|
-
}
|
|
298
|
-
disconnect() {
|
|
299
|
-
this.status = null;
|
|
300
|
-
this.tsClient.disconnect();
|
|
301
|
-
}
|
|
302
|
-
addTrack(track, simulcastConfig = { enabled: false, activeEncodings: [], disabledEncodings: [] }, maxBandwidth = 0) {
|
|
303
|
-
return this.tsClient.addTrack(track, undefined, simulcastConfig, maxBandwidth);
|
|
304
|
-
}
|
|
305
|
-
removeTrack(trackId) {
|
|
306
|
-
return this.tsClient.removeTrack(trackId);
|
|
307
|
-
}
|
|
308
|
-
replaceTrack(trackId, newTrack) {
|
|
309
|
-
return this.tsClient.replaceTrack(trackId, newTrack);
|
|
310
|
-
}
|
|
311
|
-
getStatistics(selector) {
|
|
312
|
-
return this.tsClient.getStatistics(selector);
|
|
313
|
-
}
|
|
314
|
-
getBandwidthEstimation() {
|
|
315
|
-
return this.tsClient.getBandwidthEstimation();
|
|
316
|
-
}
|
|
317
|
-
setTrackBandwidth(trackId, bandwidth) {
|
|
318
|
-
return this.tsClient.setTrackBandwidth(trackId, bandwidth);
|
|
319
|
-
}
|
|
320
|
-
setEncodingBandwidth(trackId, rid, bandwidth) {
|
|
321
|
-
return this.tsClient.setEncodingBandwidth(trackId, rid, bandwidth);
|
|
322
|
-
}
|
|
323
|
-
setTargetTrackEncoding(trackId, encoding) {
|
|
324
|
-
return this.tsClient.setTargetTrackEncoding(trackId, encoding);
|
|
325
|
-
}
|
|
326
|
-
enableTrackEncoding(trackId, encoding) {
|
|
327
|
-
return this.tsClient.enableTrackEncoding(trackId, encoding);
|
|
328
|
-
}
|
|
329
|
-
disableTrackEncoding(trackId, encoding) {
|
|
330
|
-
return this.tsClient.disableTrackEncoding(trackId, encoding);
|
|
331
|
-
}
|
|
332
|
-
isReconnecting = () => {
|
|
333
|
-
return this.tsClient.isReconnecting();
|
|
334
|
-
};
|
|
335
|
-
initializeDevices = async (config) => {
|
|
336
|
-
// This function should be called only once.
|
|
337
|
-
// Any subsequent calls to this function will be ignored.
|
|
338
|
-
if (this.initialized)
|
|
339
|
-
return;
|
|
340
|
-
this.initialized = true;
|
|
341
|
-
const constraints = {
|
|
342
|
-
video: this.videoDeviceManager.getConstraints(config?.videoTrackConstraints),
|
|
343
|
-
audio: this.audioDeviceManager.getConstraints(config?.audioTrackConstraints),
|
|
344
|
-
};
|
|
345
|
-
const previousDevices = {
|
|
346
|
-
video: this.videoDeviceManager.getLastDevice(),
|
|
347
|
-
audio: this.audioDeviceManager.getLastDevice(),
|
|
348
|
-
};
|
|
349
|
-
let [stream, deviceErrors] = await getAvailableMedia(constraints);
|
|
350
|
-
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
351
|
-
const videoDevices = devices.filter(({ kind }) => kind === "videoinput");
|
|
352
|
-
const audioDevices = devices.filter(({ kind }) => kind === "audioinput");
|
|
353
|
-
if (stream) {
|
|
354
|
-
[stream, deviceErrors] = await getCorrectedResult(stream, deviceErrors, devices, constraints, previousDevices);
|
|
355
|
-
}
|
|
356
|
-
const state = {
|
|
357
|
-
video: this.videoDeviceManager.initialize(stream, stream?.getVideoTracks()?.[0] ?? null, videoDevices, !!constraints.video, deviceErrors.video),
|
|
358
|
-
audio: this.audioDeviceManager.initialize(stream, stream?.getAudioTracks()?.[0] ?? null, audioDevices, !!constraints.audio, deviceErrors.audio),
|
|
359
|
-
};
|
|
360
|
-
this.stateToSnapshot();
|
|
361
|
-
this.emit("managerInitialized", state, this);
|
|
362
|
-
};
|
|
363
|
-
startDevices = async (config) => {
|
|
364
|
-
this.videoDeviceManager.start(config?.videoDeviceId);
|
|
365
|
-
this.audioDeviceManager.start(config?.audioDeviceId);
|
|
366
|
-
};
|
|
367
|
-
stateToSnapshot() {
|
|
368
|
-
const deviceManagerSnapshot = {
|
|
369
|
-
audio: this?.audioDeviceManager?.deviceState,
|
|
370
|
-
video: this?.videoDeviceManager?.deviceState,
|
|
371
|
-
};
|
|
372
|
-
const localEndpoint = this.tsClient.getLocalPeer();
|
|
373
|
-
const localTracks = {};
|
|
374
|
-
(localEndpoint?.tracks || new Map()).forEach((track) => {
|
|
375
|
-
localTracks[track.trackId] = this.trackContextToTrack(track);
|
|
376
|
-
});
|
|
377
|
-
const devices = {
|
|
378
|
-
camera: {
|
|
379
|
-
status: deviceManagerSnapshot?.video?.devicesStatus || null,
|
|
380
|
-
stream: deviceManagerSnapshot?.video.media?.stream || null,
|
|
381
|
-
track: deviceManagerSnapshot?.video.media?.track || null,
|
|
382
|
-
enabled: deviceManagerSnapshot?.video.media?.enabled || false,
|
|
383
|
-
deviceInfo: deviceManagerSnapshot?.video.media?.deviceInfo || null,
|
|
384
|
-
mediaStatus: deviceManagerSnapshot?.video.mediaStatus || null,
|
|
385
|
-
error: deviceManagerSnapshot?.video?.error || null,
|
|
386
|
-
devices: deviceManagerSnapshot?.video?.devices || null,
|
|
387
|
-
},
|
|
388
|
-
microphone: {
|
|
389
|
-
status: deviceManagerSnapshot?.audio?.devicesStatus || null,
|
|
390
|
-
stream: deviceManagerSnapshot?.audio.media?.stream || null,
|
|
391
|
-
track: deviceManagerSnapshot?.audio.media?.track || null,
|
|
392
|
-
enabled: deviceManagerSnapshot?.audio.media?.enabled || false,
|
|
393
|
-
deviceInfo: deviceManagerSnapshot?.audio.media?.deviceInfo || null,
|
|
394
|
-
mediaStatus: deviceManagerSnapshot?.video.mediaStatus || null,
|
|
395
|
-
error: deviceManagerSnapshot?.audio?.error || null,
|
|
396
|
-
devices: deviceManagerSnapshot?.audio?.devices || null,
|
|
397
|
-
},
|
|
398
|
-
};
|
|
399
|
-
if (!this.tsClient["webrtc"]) {
|
|
400
|
-
this.media = deviceManagerSnapshot || null;
|
|
401
|
-
this.peersTracks = {};
|
|
402
|
-
this.componentsTracks = {};
|
|
403
|
-
this.devices = devices;
|
|
404
|
-
this.peers = {};
|
|
405
|
-
this.components = {};
|
|
406
|
-
this.local = null;
|
|
407
|
-
this.bandwidthEstimation = 0n;
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
const peers = {};
|
|
411
|
-
const components = {};
|
|
412
|
-
const peersTracks = {};
|
|
413
|
-
const componentTracks = {};
|
|
414
|
-
Object.values(this.tsClient.getRemotePeers()).forEach((remotePeer) => {
|
|
415
|
-
const tracks = {};
|
|
416
|
-
remotePeer.tracks.forEach((track) => {
|
|
417
|
-
const mappedTrack = this.trackContextToTrack(track);
|
|
418
|
-
tracks[track.trackId] = mappedTrack;
|
|
419
|
-
peersTracks[track.trackId] = { ...mappedTrack, origin: remotePeer };
|
|
420
|
-
});
|
|
421
|
-
peers[remotePeer.id] = {
|
|
422
|
-
rawMetadata: remotePeer.rawMetadata,
|
|
423
|
-
metadata: remotePeer.metadata,
|
|
424
|
-
metadataParsingError: remotePeer.metadataParsingError,
|
|
425
|
-
id: remotePeer.id,
|
|
426
|
-
tracks,
|
|
427
|
-
};
|
|
428
|
-
});
|
|
429
|
-
Object.values(this.tsClient.getRemoteComponents()).forEach((remotePeer) => {
|
|
430
|
-
const tracks = {};
|
|
431
|
-
remotePeer.tracks.forEach((track) => {
|
|
432
|
-
const mappedTrack = this.trackContextToTrack(track);
|
|
433
|
-
tracks[track.trackId] = mappedTrack;
|
|
434
|
-
componentTracks[track.trackId] = { ...mappedTrack, origin: remotePeer };
|
|
435
|
-
});
|
|
436
|
-
components[remotePeer.id] = {
|
|
437
|
-
rawMetadata: remotePeer.rawMetadata,
|
|
438
|
-
metadata: remotePeer.metadata,
|
|
439
|
-
metadataParsingError: remotePeer.metadataParsingError,
|
|
440
|
-
id: remotePeer.id,
|
|
441
|
-
tracks,
|
|
442
|
-
};
|
|
443
|
-
});
|
|
444
|
-
this.peersTracks = peersTracks;
|
|
445
|
-
this.componentsTracks = componentTracks;
|
|
446
|
-
this.media = deviceManagerSnapshot || null;
|
|
447
|
-
this.local = localEndpoint
|
|
448
|
-
? {
|
|
449
|
-
id: localEndpoint.id,
|
|
450
|
-
metadata: localEndpoint.metadata,
|
|
451
|
-
metadataParsingError: localEndpoint.metadataParsingError,
|
|
452
|
-
rawMetadata: localEndpoint.rawMetadata,
|
|
453
|
-
tracks: localTracks, // to record
|
|
454
|
-
}
|
|
455
|
-
: null;
|
|
456
|
-
this.peers = peers;
|
|
457
|
-
this.components = components;
|
|
458
|
-
this.bandwidthEstimation = this.tsClient.getBandwidthEstimation();
|
|
459
|
-
this.devices = devices;
|
|
460
|
-
}
|
|
461
|
-
}
|
package/dist/create.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { CreateFishjamClient, DeviceManagerConfig, PeerMetadata, TrackMetadata } from "./types";
|
|
2
|
-
import type { CreateConfig } from "@fishjam-cloud/ts-client";
|
|
3
|
-
/**
|
|
4
|
-
* Create a client that can be used with a context.
|
|
5
|
-
* Returns context provider, and two hooks to interact with the context.
|
|
6
|
-
*
|
|
7
|
-
* @returns ContextProvider, useSelector, useConnect
|
|
8
|
-
*/
|
|
9
|
-
export declare function create(config?: CreateConfig<PeerMetadata, TrackMetadata>, deviceManagerDefaultConfig?: DeviceManagerConfig): CreateFishjamClient;
|
|
10
|
-
//# sourceMappingURL=create.d.ts.map
|
package/dist/create.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,mBAAmB,EACnB,mBAAmB,EAGnB,YAAY,EAIZ,aAAa,EAGd,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAuD7D;;;;;GAKG;AACH,wBAAgB,MAAM,CACpB,MAAM,CAAC,EAAE,YAAY,CAAC,YAAY,EAAE,aAAa,CAAC,EAClD,0BAA0B,CAAC,EAAE,mBAAmB,GAC/C,mBAAmB,CA+KrB"}
|
package/dist/create.js
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, useCallback, useContext, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
3
|
-
import { Client } from "./Client";
|
|
4
|
-
import { createUseSetupMediaHook } from "./useSetupMedia";
|
|
5
|
-
import { useScreenShare as _useScreenShare } from "./screenShareTrackManager";
|
|
6
|
-
import { useTrackManager } from "./trackManager";
|
|
7
|
-
const eventNames = [
|
|
8
|
-
"socketOpen",
|
|
9
|
-
"socketError",
|
|
10
|
-
"socketClose",
|
|
11
|
-
"authSuccess",
|
|
12
|
-
"authError",
|
|
13
|
-
"disconnected",
|
|
14
|
-
"joined",
|
|
15
|
-
"joinError",
|
|
16
|
-
"peerJoined",
|
|
17
|
-
"peerUpdated",
|
|
18
|
-
"peerLeft",
|
|
19
|
-
"reconnected",
|
|
20
|
-
"reconnectionRetriesLimitReached",
|
|
21
|
-
"reconnectionStarted",
|
|
22
|
-
"componentAdded",
|
|
23
|
-
"componentUpdated",
|
|
24
|
-
"componentRemoved",
|
|
25
|
-
"trackReady",
|
|
26
|
-
"trackAdded",
|
|
27
|
-
"trackRemoved",
|
|
28
|
-
"trackUpdated",
|
|
29
|
-
"bandwidthEstimationChanged",
|
|
30
|
-
"encodingChanged",
|
|
31
|
-
"voiceActivityChanged",
|
|
32
|
-
"deviceDisabled",
|
|
33
|
-
"deviceEnabled",
|
|
34
|
-
"managerInitialized",
|
|
35
|
-
"managerStarted",
|
|
36
|
-
"deviceStopped",
|
|
37
|
-
"deviceReady",
|
|
38
|
-
"devicesStarted",
|
|
39
|
-
"devicesReady",
|
|
40
|
-
"error",
|
|
41
|
-
"targetTrackEncodingRequested",
|
|
42
|
-
"localTrackAdded",
|
|
43
|
-
"localTrackRemoved",
|
|
44
|
-
"localTrackReplaced",
|
|
45
|
-
"localTrackMuted",
|
|
46
|
-
"localTrackUnmuted",
|
|
47
|
-
"localTrackBandwidthSet",
|
|
48
|
-
"localTrackEncodingBandwidthSet",
|
|
49
|
-
"localTrackEncodingEnabled",
|
|
50
|
-
"localTrackEncodingDisabled",
|
|
51
|
-
"localPeerMetadataChanged",
|
|
52
|
-
"localTrackMetadataChanged",
|
|
53
|
-
"disconnectRequested",
|
|
54
|
-
];
|
|
55
|
-
/**
|
|
56
|
-
* Create a client that can be used with a context.
|
|
57
|
-
* Returns context provider, and two hooks to interact with the context.
|
|
58
|
-
*
|
|
59
|
-
* @returns ContextProvider, useSelector, useConnect
|
|
60
|
-
*/
|
|
61
|
-
export function create(config, deviceManagerDefaultConfig) {
|
|
62
|
-
const FishjamContext = createContext(undefined);
|
|
63
|
-
function FishjamContextProvider({ children }) {
|
|
64
|
-
const memoClient = useMemo(() => new Client({ clientConfig: config, deviceManagerDefaultConfig }), []);
|
|
65
|
-
const clientRef = useRef(memoClient);
|
|
66
|
-
const mutationRef = useRef(false);
|
|
67
|
-
const subscribe = useCallback((subscribeCallback) => {
|
|
68
|
-
const client = clientRef.current;
|
|
69
|
-
const callback = () => {
|
|
70
|
-
mutationRef.current = true;
|
|
71
|
-
subscribeCallback();
|
|
72
|
-
};
|
|
73
|
-
eventNames.forEach((eventName) => client.on(eventName, callback));
|
|
74
|
-
return () => {
|
|
75
|
-
eventNames.forEach((eventName) => client.removeListener(eventName, callback));
|
|
76
|
-
};
|
|
77
|
-
}, []);
|
|
78
|
-
const lastSnapshotRef = useRef(null);
|
|
79
|
-
const getSnapshot = useCallback(() => {
|
|
80
|
-
if (mutationRef.current || lastSnapshotRef.current === null) {
|
|
81
|
-
lastSnapshotRef.current = {
|
|
82
|
-
remote: clientRef.current.peers,
|
|
83
|
-
media: clientRef.current.media,
|
|
84
|
-
bandwidthEstimation: clientRef.current.bandwidthEstimation,
|
|
85
|
-
tracks: clientRef.current.peersTracks,
|
|
86
|
-
local: clientRef.current.local,
|
|
87
|
-
status: clientRef.current.status,
|
|
88
|
-
devices: clientRef.current.devices,
|
|
89
|
-
client: clientRef.current,
|
|
90
|
-
reconnectionStatus: clientRef.current.reconnectionStatus,
|
|
91
|
-
};
|
|
92
|
-
mutationRef.current = false;
|
|
93
|
-
}
|
|
94
|
-
return lastSnapshotRef.current;
|
|
95
|
-
}, []);
|
|
96
|
-
const state = useSyncExternalStore(subscribe, getSnapshot);
|
|
97
|
-
const tsClient = state.client.getTsClient();
|
|
98
|
-
const screenshareState = useState(null);
|
|
99
|
-
const videoTrackManager = useTrackManager({
|
|
100
|
-
mediaManager: state.client.videoDeviceManager,
|
|
101
|
-
tsClient,
|
|
102
|
-
});
|
|
103
|
-
const audioTrackManager = useTrackManager({
|
|
104
|
-
mediaManager: state.client.audioDeviceManager,
|
|
105
|
-
tsClient,
|
|
106
|
-
});
|
|
107
|
-
return (_jsx(FishjamContext.Provider, { value: { state, screenshareState, videoTrackManager, audioTrackManager }, children: children }));
|
|
108
|
-
}
|
|
109
|
-
function useFishjamContext() {
|
|
110
|
-
const context = useContext(FishjamContext);
|
|
111
|
-
if (!context)
|
|
112
|
-
throw new Error("useFishjamContext must be used within a FishjamContextProvider");
|
|
113
|
-
return context;
|
|
114
|
-
}
|
|
115
|
-
function useSelector(selector) {
|
|
116
|
-
const { state } = useFishjamContext();
|
|
117
|
-
return useMemo(() => selector(state), [selector, state]);
|
|
118
|
-
}
|
|
119
|
-
function useConnect() {
|
|
120
|
-
const { state } = useFishjamContext();
|
|
121
|
-
return useMemo(() => {
|
|
122
|
-
return (config) => {
|
|
123
|
-
state.client.connect(config);
|
|
124
|
-
return () => {
|
|
125
|
-
state.client.disconnect();
|
|
126
|
-
};
|
|
127
|
-
};
|
|
128
|
-
}, [state.client]);
|
|
129
|
-
}
|
|
130
|
-
function useDisconnect() {
|
|
131
|
-
const { state } = useFishjamContext();
|
|
132
|
-
return useCallback(() => {
|
|
133
|
-
state.client.disconnect();
|
|
134
|
-
}, [state.client]);
|
|
135
|
-
}
|
|
136
|
-
function useStatus() {
|
|
137
|
-
return useSelector((s) => s.status);
|
|
138
|
-
}
|
|
139
|
-
function useTracks() {
|
|
140
|
-
return useSelector((s) => s.tracks);
|
|
141
|
-
}
|
|
142
|
-
function useClient() {
|
|
143
|
-
return useSelector((s) => s.client);
|
|
144
|
-
}
|
|
145
|
-
function useCamera() {
|
|
146
|
-
const { state, videoTrackManager } = useFishjamContext();
|
|
147
|
-
return { ...state.devices.camera, ...videoTrackManager };
|
|
148
|
-
}
|
|
149
|
-
function useMicrophone() {
|
|
150
|
-
const { state, audioTrackManager } = useFishjamContext();
|
|
151
|
-
return { ...state.devices.microphone, ...audioTrackManager };
|
|
152
|
-
}
|
|
153
|
-
function useReconnection() {
|
|
154
|
-
const { state } = useFishjamContext();
|
|
155
|
-
return {
|
|
156
|
-
status: state.reconnectionStatus,
|
|
157
|
-
isReconnecting: state.reconnectionStatus === "reconnecting",
|
|
158
|
-
isError: state.reconnectionStatus === "error",
|
|
159
|
-
isIdle: state.reconnectionStatus === "idle",
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
function getPeerWithDistinguishedTracks(peerState) {
|
|
163
|
-
const localTracks = Object.values(peerState.tracks ?? {});
|
|
164
|
-
const videoTracks = localTracks.filter(({ track }) => track?.kind === "video");
|
|
165
|
-
const audioTracks = localTracks.filter(({ track }) => track?.kind === "audio");
|
|
166
|
-
return { ...peerState, videoTracks, audioTracks };
|
|
167
|
-
}
|
|
168
|
-
function useParticipants() {
|
|
169
|
-
const { state } = useFishjamContext();
|
|
170
|
-
const localParticipant = state.local
|
|
171
|
-
? getPeerWithDistinguishedTracks(state.local)
|
|
172
|
-
: null;
|
|
173
|
-
const participants = Object.values(state.remote).map(getPeerWithDistinguishedTracks);
|
|
174
|
-
return { localParticipant, participants };
|
|
175
|
-
}
|
|
176
|
-
function useScreenShare() {
|
|
177
|
-
const { state, screenshareState } = useFishjamContext();
|
|
178
|
-
return _useScreenShare(screenshareState, state.client.getTsClient());
|
|
179
|
-
}
|
|
180
|
-
return {
|
|
181
|
-
FishjamContextProvider,
|
|
182
|
-
useSelector,
|
|
183
|
-
useConnect,
|
|
184
|
-
useDisconnect,
|
|
185
|
-
useStatus,
|
|
186
|
-
useTracks,
|
|
187
|
-
useSetupMedia: createUseSetupMediaHook(useFishjamContext),
|
|
188
|
-
useParticipants,
|
|
189
|
-
useScreenShare,
|
|
190
|
-
useCamera,
|
|
191
|
-
useMicrophone,
|
|
192
|
-
useClient,
|
|
193
|
-
useReconnection,
|
|
194
|
-
};
|
|
195
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { FishjamClient } from "@fishjam-cloud/ts-client";
|
|
2
|
-
import type { PeerMetadata, ScreenshareApi, ScreenshareState, TrackMetadata } from "./types";
|
|
3
|
-
export declare const useScreenShare: ([state, setState]: [ScreenshareState, React.Dispatch<React.SetStateAction<ScreenshareState>>], tsClient: FishjamClient<PeerMetadata, TrackMetadata>) => ScreenshareApi;
|
|
4
|
-
//# sourceMappingURL=screenShareTrackManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"screenShareTrackManager.d.ts","sourceRoot":"","sources":["../src/screenShareTrackManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAG9D,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,EAAoB,MAAM,SAAS,CAAC;AAS/G,eAAO,MAAM,cAAc,sBAEN,CAAC,gBAAgB,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC,CAAC,YACnF,aAAa,CAAC,YAAY,EAAE,aAAa,CAAC,KACnD,cAmGF,CAAC"}
|