|
1 | 1 | import EventEmitter from "events"; |
2 | 2 | import type TypedEmitter from "typed-emitter"; |
3 | 3 | import type { |
4 | | - AuthErrorReason, |
5 | 4 | BandwidthLimit, |
6 | | - Component, |
7 | 5 | ConnectConfig, |
8 | | - CreateConfig, |
9 | | - MessageEvents, |
10 | | - Peer, |
11 | 6 | SimulcastConfig, |
12 | 7 | TrackBandwidthLimit, |
13 | 8 | TrackContext, |
14 | 9 | TrackEncoding, |
15 | 10 | } from "@fishjam-dev/ts-client"; |
16 | 11 | import { FishjamClient } from "@fishjam-dev/ts-client"; |
17 | 12 | import type { PeerId, PeerState, PeerStatus, Track, TrackId, TrackWithOrigin } from "./state.types"; |
18 | | -import type { DeviceManagerEvents } from "./DeviceManager"; |
19 | 13 | import { DeviceManager } from "./DeviceManager"; |
20 | | -import type { MediaDeviceType, ScreenShareManagerConfig } from "./ScreenShareManager"; |
| 14 | +import type { ScreenShareManagerConfig } from "./ScreenShareManager"; |
21 | 15 | import { ScreenShareManager } from "./ScreenShareManager"; |
22 | | -import type { DeviceManagerConfig, DeviceManagerInitConfig, Devices, DeviceState, MediaState } from "./types"; |
23 | | - |
24 | | -export type ClientApi<PeerMetadata, TrackMetadata> = { |
25 | | - local: PeerState<PeerMetadata, TrackMetadata> | null; |
26 | | - |
27 | | - peers: Record<PeerId, PeerState<PeerMetadata, TrackMetadata>>; |
28 | | - peersTracks: Record<TrackId, TrackWithOrigin<PeerMetadata, TrackMetadata>>; |
29 | | - |
30 | | - components: Record<PeerId, PeerState<PeerMetadata, TrackMetadata>>; |
31 | | - componentsTracks: Record<TrackId, TrackWithOrigin<PeerMetadata, TrackMetadata>>; |
32 | | - |
33 | | - bandwidthEstimation: bigint; |
34 | | - status: PeerStatus; |
35 | | - media: MediaState | null; |
36 | | - devices: Devices<TrackMetadata>; |
37 | | - deviceManager: DeviceManager; |
38 | | - screenShareManager: ScreenShareManager; |
39 | | -}; |
40 | | - |
41 | | -export interface ClientEvents<PeerMetadata, TrackMetadata> { |
42 | | - /** |
43 | | - * Emitted when the websocket connection is closed |
44 | | - * |
45 | | - * @param {CloseEvent} event - Close event object from the websocket |
46 | | - */ |
47 | | - socketClose: (event: CloseEvent, client: ClientApi<PeerMetadata, TrackMetadata>) => void; |
48 | | - |
49 | | - /** |
50 | | - * Emitted when occurs an error in the websocket connection |
51 | | - * |
52 | | - * @param {Event} event - Event object from the websocket |
53 | | - */ |
54 | | - socketError: (event: Event, client: ClientApi<PeerMetadata, TrackMetadata>) => void; |
55 | | - |
56 | | - /** |
57 | | - * Emitted when the websocket connection is opened |
58 | | - * |
59 | | - * @param {Event} event - Event object from the websocket |
60 | | - */ |
61 | | - socketOpen: (event: Event, client: ClientApi<PeerMetadata, TrackMetadata>) => void; |
62 | | - |
63 | | - /** Emitted when authentication is successful */ |
64 | | - authSuccess: (client: ClientApi<PeerMetadata, TrackMetadata>) => void; |
65 | | - |
66 | | - /** Emitted when authentication fails */ |
67 | | - authError: (reason: AuthErrorReason, client: ClientApi<PeerMetadata, TrackMetadata>) => void; |
68 | | - |
69 | | - /** Emitted when the connection is closed */ |
70 | | - disconnected: (client: ClientApi<PeerMetadata, TrackMetadata>) => void; |
71 | | - |
72 | | - /** |
73 | | - * Called when peer was accepted. |
74 | | - */ |
75 | | - joined: ( |
76 | | - event: { |
77 | | - peerId: string; |
78 | | - peers: Peer<PeerMetadata, TrackMetadata>[]; |
79 | | - components: Component<PeerMetadata, TrackMetadata>[]; |
80 | | - }, |
81 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
82 | | - ) => void; |
83 | | - |
84 | | - /** |
85 | | - * Called when peer was not accepted |
86 | | - * @param metadata - Pass through for client application to communicate further actions to frontend |
87 | | - */ |
88 | | - joinError: (metadata: any, client: ClientApi<PeerMetadata, TrackMetadata>) => void; // eslint-disable-line @typescript-eslint/no-explicit-any |
89 | | - |
90 | | - /** |
91 | | - * Called when data in a new track arrives. |
92 | | - * |
93 | | - * This callback is always called after {@link MessageEvents.trackAdded}. |
94 | | - * It informs user that data related to the given track arrives and can be played or displayed. |
95 | | - */ |
96 | | - trackReady: (ctx: TrackContext<PeerMetadata, TrackMetadata>, client: ClientApi<PeerMetadata, TrackMetadata>) => void; |
97 | | - |
98 | | - /** |
99 | | - * Called each time the peer which was already in the room, adds new track. Fields track and stream will be set to null. |
100 | | - * These fields will be set to non-null value in {@link MessageEvents.trackReady} |
101 | | - */ |
102 | | - trackAdded: (ctx: TrackContext<PeerMetadata, TrackMetadata>, client: ClientApi<PeerMetadata, TrackMetadata>) => void; |
103 | | - |
104 | | - /** |
105 | | - * Called when some track will no longer be sent. |
106 | | - * |
107 | | - * It will also be called before {@link MessageEvents.peerLeft} for each track of this peer. |
108 | | - */ |
109 | | - trackRemoved: ( |
110 | | - ctx: TrackContext<PeerMetadata, TrackMetadata>, |
111 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
112 | | - ) => void; |
113 | | - |
114 | | - /** |
115 | | - * Called each time peer has its track metadata updated. |
116 | | - */ |
117 | | - trackUpdated: ( |
118 | | - ctx: TrackContext<PeerMetadata, TrackMetadata>, |
119 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
120 | | - ) => void; |
121 | | - |
122 | | - /** |
123 | | - * Called each time new peer joins the room. |
124 | | - */ |
125 | | - peerJoined: (peer: Peer<PeerMetadata, TrackMetadata>, client: ClientApi<PeerMetadata, TrackMetadata>) => void; |
126 | | - |
127 | | - /** |
128 | | - * Called each time peer leaves the room. |
129 | | - */ |
130 | | - peerLeft: (peer: Peer<PeerMetadata, TrackMetadata>, client: ClientApi<PeerMetadata, TrackMetadata>) => void; |
131 | | - |
132 | | - /** |
133 | | - * Called each time peer has its metadata updated. |
134 | | - */ |
135 | | - peerUpdated: (peer: Peer<PeerMetadata, TrackMetadata>, client: ClientApi<PeerMetadata, TrackMetadata>) => void; |
136 | | - |
137 | | - /** |
138 | | - * Called each time new Component is added to the room. |
139 | | - */ |
140 | | - componentAdded: ( |
141 | | - peer: Component<PeerMetadata, TrackMetadata>, |
142 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
143 | | - ) => void; |
144 | | - |
145 | | - /** |
146 | | - * Called each time Component is removed from the room. |
147 | | - */ |
148 | | - componentRemoved: ( |
149 | | - peer: Component<PeerMetadata, TrackMetadata>, |
150 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
151 | | - ) => void; |
152 | | - |
153 | | - /** |
154 | | - * Called each time Component has its metadata updated. |
155 | | - */ |
156 | | - componentUpdated: ( |
157 | | - peer: Component<PeerMetadata, TrackMetadata>, |
158 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
159 | | - ) => void; |
160 | | - |
161 | | - /** |
162 | | - * Called in case of errors related to multimedia session e.g. ICE connection. |
163 | | - */ |
164 | | - connectionError: (message: string, client: ClientApi<PeerMetadata, TrackMetadata>) => void; |
165 | | - |
166 | | - /** |
167 | | - * Called every time the server estimates client's bandiwdth. |
168 | | - * |
169 | | - * @param {bigint} estimation - client's available incoming bitrate estimated |
170 | | - * by the server. It's measured in bits per second. |
171 | | - */ |
172 | | - bandwidthEstimationChanged: (estimation: bigint, client: ClientApi<PeerMetadata, TrackMetadata>) => void; |
173 | | - |
174 | | - // track context events |
175 | | - encodingChanged: ( |
176 | | - context: TrackContext<PeerMetadata, TrackMetadata>, |
177 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
178 | | - ) => void; |
179 | | - |
180 | | - /** |
181 | | - * Emitted every time an update about voice activity is received from the server. |
182 | | - */ |
183 | | - voiceActivityChanged: ( |
184 | | - context: TrackContext<PeerMetadata, TrackMetadata>, |
185 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
186 | | - ) => void; |
187 | | - |
188 | | - // device manager events |
189 | | - managerStarted: ( |
190 | | - event: Parameters<DeviceManagerEvents["managerInitialized"]>[0] & { |
191 | | - mediaDeviceType: MediaDeviceType; |
192 | | - }, |
193 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
194 | | - ) => void; |
195 | | - managerInitialized: ( |
196 | | - event: { audio?: DeviceState; video?: DeviceState; mediaDeviceType: MediaDeviceType }, |
197 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
198 | | - ) => void; |
199 | | - deviceReady: ( |
200 | | - event: Parameters<DeviceManagerEvents["deviceReady"]>[0] & { mediaDeviceType: MediaDeviceType }, |
201 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
202 | | - ) => void; |
203 | | - devicesStarted: ( |
204 | | - event: Parameters<DeviceManagerEvents["devicesStarted"]>[0] & { mediaDeviceType: MediaDeviceType }, |
205 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
206 | | - ) => void; |
207 | | - devicesReady: ( |
208 | | - event: Parameters<DeviceManagerEvents["devicesReady"]>[0] & { mediaDeviceType: MediaDeviceType }, |
209 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
210 | | - ) => void; |
211 | | - deviceStopped: ( |
212 | | - event: Parameters<DeviceManagerEvents["deviceStopped"]>[0] & { mediaDeviceType: MediaDeviceType }, |
213 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
214 | | - ) => void; |
215 | | - deviceEnabled: ( |
216 | | - event: Parameters<DeviceManagerEvents["deviceEnabled"]>[0] & { |
217 | | - mediaDeviceType: MediaDeviceType; |
218 | | - }, |
219 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
220 | | - ) => void; |
221 | | - deviceDisabled: ( |
222 | | - event: Parameters<DeviceManagerEvents["deviceDisabled"]>[0] & { |
223 | | - mediaDeviceType: MediaDeviceType; |
224 | | - }, |
225 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
226 | | - ) => void; |
227 | | - // eslint-disable-next-line @typescript-eslint/no-explicit-any |
228 | | - error: (arg: any, client: ClientApi<PeerMetadata, TrackMetadata>) => void; |
229 | | - |
230 | | - targetTrackEncodingRequested: ( |
231 | | - event: Parameters<MessageEvents<PeerMetadata, TrackMetadata>["targetTrackEncodingRequested"]>[0], |
232 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
233 | | - ) => void; |
234 | | - localTrackAdded: ( |
235 | | - event: Parameters<MessageEvents<PeerMetadata, TrackMetadata>["localTrackAdded"]>[0], |
236 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
237 | | - ) => void; |
238 | | - localTrackRemoved: ( |
239 | | - event: Parameters<MessageEvents<PeerMetadata, TrackMetadata>["localTrackRemoved"]>[0], |
240 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
241 | | - ) => void; |
242 | | - localTrackReplaced: ( |
243 | | - event: Parameters<MessageEvents<PeerMetadata, TrackMetadata>["localTrackReplaced"]>[0], |
244 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
245 | | - ) => void; |
246 | | - localTrackMuted: ( |
247 | | - event: Parameters<MessageEvents<PeerMetadata, TrackMetadata>["localTrackMuted"]>[0], |
248 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
249 | | - ) => void; |
250 | | - localTrackUnmuted: ( |
251 | | - event: Parameters<MessageEvents<PeerMetadata, TrackMetadata>["localTrackUnmuted"]>[0], |
252 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
253 | | - ) => void; |
254 | | - localTrackBandwidthSet: ( |
255 | | - event: Parameters<MessageEvents<PeerMetadata, TrackMetadata>["localTrackBandwidthSet"]>[0], |
256 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
257 | | - ) => void; |
258 | | - localTrackEncodingBandwidthSet: ( |
259 | | - event: Parameters<MessageEvents<PeerMetadata, TrackMetadata>["localTrackEncodingBandwidthSet"]>[0], |
260 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
261 | | - ) => void; |
262 | | - localTrackEncodingEnabled: ( |
263 | | - event: Parameters<MessageEvents<PeerMetadata, TrackMetadata>["localTrackEncodingEnabled"]>[0], |
264 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
265 | | - ) => void; |
266 | | - localTrackEncodingDisabled: ( |
267 | | - event: Parameters<MessageEvents<PeerMetadata, TrackMetadata>["localTrackEncodingDisabled"]>[0], |
268 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
269 | | - ) => void; |
270 | | - localEndpointMetadataChanged: ( |
271 | | - event: Parameters<MessageEvents<PeerMetadata, TrackMetadata>["localEndpointMetadataChanged"]>[0], |
272 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
273 | | - ) => void; |
274 | | - localTrackMetadataChanged: ( |
275 | | - event: Parameters<MessageEvents<PeerMetadata, TrackMetadata>["localTrackMetadataChanged"]>[0], |
276 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
277 | | - ) => void; |
278 | | - disconnectRequested: ( |
279 | | - event: Parameters<MessageEvents<PeerMetadata, TrackMetadata>["disconnectRequested"]>[0], |
280 | | - client: ClientApi<PeerMetadata, TrackMetadata>, |
281 | | - ) => void; |
282 | | -} |
| 16 | +import type { DeviceManagerConfig, DeviceManagerInitConfig, Devices, MediaState } from "./types"; |
283 | 17 |
|
284 | | -export type ReactClientCreteConfig<PeerMetadata, TrackMetadata> = { |
285 | | - clientConfig?: CreateConfig<PeerMetadata, TrackMetadata>; |
286 | | - deviceManagerDefaultConfig?: DeviceManagerConfig; |
287 | | - screenShareManagerDefaultConfig?: ScreenShareManagerConfig; |
288 | | -}; |
| 18 | +import type { ClientEvents, ReactClientCreteConfig } from "./Client.types"; |
289 | 19 |
|
290 | 20 | const NOOP = () => {}; |
291 | 21 |
|
|
0 commit comments