@fishjam-cloud/webrtc-client 0.25.2 → 0.25.3

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.
Files changed (85) hide show
  1. package/package.json +3 -3
  2. package/dist/protobufs/fishjam/media_events/peer/peer.d.ts +0 -130
  3. package/dist/protobufs/fishjam/media_events/peer/peer.js +0 -1283
  4. package/dist/protobufs/fishjam/media_events/server/server.d.ts +0 -197
  5. package/dist/protobufs/fishjam/media_events/server/server.js +0 -2121
  6. package/dist/protobufs/fishjam/media_events/shared.d.ts +0 -48
  7. package/dist/protobufs/fishjam/media_events/shared.js +0 -315
  8. package/dist/webrtc-client/src/CommandsQueue.d.ts +0 -23
  9. package/dist/webrtc-client/src/CommandsQueue.js +0 -87
  10. package/dist/webrtc-client/src/ConnectionManager.d.ts +0 -17
  11. package/dist/webrtc-client/src/ConnectionManager.js +0 -49
  12. package/dist/webrtc-client/src/bitrate.d.ts +0 -12
  13. package/dist/webrtc-client/src/bitrate.js +0 -15
  14. package/dist/webrtc-client/src/dataChannels/DataChannel.d.ts +0 -56
  15. package/dist/webrtc-client/src/dataChannels/DataChannel.js +0 -144
  16. package/dist/webrtc-client/src/dataChannels/DataChannelManager.d.ts +0 -83
  17. package/dist/webrtc-client/src/dataChannels/DataChannelManager.js +0 -184
  18. package/dist/webrtc-client/src/deferred.d.ts +0 -8
  19. package/dist/webrtc-client/src/deferred.js +0 -17
  20. package/dist/webrtc-client/src/index.d.ts +0 -6
  21. package/dist/webrtc-client/src/index.js +0 -4
  22. package/dist/webrtc-client/src/internal.d.ts +0 -27
  23. package/dist/webrtc-client/src/internal.js +0 -18
  24. package/dist/webrtc-client/src/logger.d.ts +0 -5
  25. package/dist/webrtc-client/src/logger.js +0 -15
  26. package/dist/webrtc-client/src/mediaEvent.d.ts +0 -13
  27. package/dist/webrtc-client/src/mediaEvent.js +0 -20
  28. package/dist/webrtc-client/src/tracks/Local.d.ts +0 -49
  29. package/dist/webrtc-client/src/tracks/Local.js +0 -243
  30. package/dist/webrtc-client/src/tracks/LocalTrack.d.ts +0 -61
  31. package/dist/webrtc-client/src/tracks/LocalTrack.js +0 -212
  32. package/dist/webrtc-client/src/tracks/LocalTrackManager.d.ts +0 -39
  33. package/dist/webrtc-client/src/tracks/LocalTrackManager.js +0 -76
  34. package/dist/webrtc-client/src/tracks/Remote.d.ts +0 -32
  35. package/dist/webrtc-client/src/tracks/Remote.js +0 -165
  36. package/dist/webrtc-client/src/tracks/RemoteTrack.d.ts +0 -40
  37. package/dist/webrtc-client/src/tracks/RemoteTrack.js +0 -71
  38. package/dist/webrtc-client/src/tracks/TrackCommon.d.ts +0 -9
  39. package/dist/webrtc-client/src/tracks/TrackCommon.js +0 -1
  40. package/dist/webrtc-client/src/tracks/bandwidth.d.ts +0 -1
  41. package/dist/webrtc-client/src/tracks/bandwidth.js +0 -27
  42. package/dist/webrtc-client/src/tracks/encodings.d.ts +0 -3
  43. package/dist/webrtc-client/src/tracks/encodings.js +0 -11
  44. package/dist/webrtc-client/src/tracks/muteTrackUtils.d.ts +0 -3
  45. package/dist/webrtc-client/src/tracks/muteTrackUtils.js +0 -23
  46. package/dist/webrtc-client/src/tracks/transceivers.d.ts +0 -2
  47. package/dist/webrtc-client/src/tracks/transceivers.js +0 -93
  48. package/dist/webrtc-client/src/types.d.ts +0 -340
  49. package/dist/webrtc-client/src/types.js +0 -1
  50. package/dist/webrtc-client/src/webRTCEndpoint.d.ts +0 -350
  51. package/dist/webrtc-client/src/webRTCEndpoint.js +0 -747
  52. package/dist/webrtc-client/tests/events/bandwidthEstimationEvent.test.d.ts +0 -1
  53. package/dist/webrtc-client/tests/events/bandwidthEstimationEvent.test.js +0 -21
  54. package/dist/webrtc-client/tests/events/connectedEvent.test.d.ts +0 -1
  55. package/dist/webrtc-client/tests/events/connectedEvent.test.js +0 -70
  56. package/dist/webrtc-client/tests/events/encodingSwitchedEvent.test.d.ts +0 -1
  57. package/dist/webrtc-client/tests/events/encodingSwitchedEvent.test.js +0 -60
  58. package/dist/webrtc-client/tests/events/endpointAddedEvent.test.d.ts +0 -1
  59. package/dist/webrtc-client/tests/events/endpointAddedEvent.test.js +0 -57
  60. package/dist/webrtc-client/tests/events/endpointRemovedEvent.test.d.ts +0 -1
  61. package/dist/webrtc-client/tests/events/endpointRemovedEvent.test.js +0 -64
  62. package/dist/webrtc-client/tests/events/endpointUpdatedEvent.test.d.ts +0 -1
  63. package/dist/webrtc-client/tests/events/endpointUpdatedEvent.test.js +0 -78
  64. package/dist/webrtc-client/tests/events/trackAddedEvent.test.d.ts +0 -1
  65. package/dist/webrtc-client/tests/events/trackAddedEvent.test.js +0 -84
  66. package/dist/webrtc-client/tests/events/trackRemovedEvent.test.d.ts +0 -1
  67. package/dist/webrtc-client/tests/events/trackRemovedEvent.test.js +0 -26
  68. package/dist/webrtc-client/tests/events/trackUpdatedEvent.test.d.ts +0 -1
  69. package/dist/webrtc-client/tests/events/trackUpdatedEvent.test.js +0 -77
  70. package/dist/webrtc-client/tests/events/vadNotificationEvent.test.d.ts +0 -1
  71. package/dist/webrtc-client/tests/events/vadNotificationEvent.test.js +0 -42
  72. package/dist/webrtc-client/tests/fixtures.d.ts +0 -27
  73. package/dist/webrtc-client/tests/fixtures.js +0 -172
  74. package/dist/webrtc-client/tests/methods/addTrackMethod.test.d.ts +0 -1
  75. package/dist/webrtc-client/tests/methods/addTrackMethod.test.js +0 -46
  76. package/dist/webrtc-client/tests/methods/cleanUpMethod.test.d.ts +0 -1
  77. package/dist/webrtc-client/tests/methods/cleanUpMethod.test.js +0 -14
  78. package/dist/webrtc-client/tests/methods/connectMethod.test.d.ts +0 -1
  79. package/dist/webrtc-client/tests/methods/connectMethod.test.js +0 -40
  80. package/dist/webrtc-client/tests/methods/disconnectMethod.test.d.ts +0 -1
  81. package/dist/webrtc-client/tests/methods/disconnectMethod.test.js +0 -29
  82. package/dist/webrtc-client/tests/mocks.d.ts +0 -5
  83. package/dist/webrtc-client/tests/mocks.js +0 -80
  84. package/dist/webrtc-client/tests/utils.d.ts +0 -3
  85. package/dist/webrtc-client/tests/utils.js +0 -56
@@ -1,340 +0,0 @@
1
- import type { MediaEvent_Track_SimulcastConfig } from '@fishjam-cloud/protobufs/server';
2
- import type { Variant } from '@fishjam-cloud/protobufs/shared';
3
- import type TypedEmitter from 'typed-emitter';
4
- import type { getLogger } from './logger';
5
- import type { SerializedMediaEvent } from './mediaEvent';
6
- export type LocalTrackId = string;
7
- export type MLineId = string;
8
- export type MediaStreamTrackId = string;
9
- export type RemoteTrackId = string;
10
- export type MetadataJson = string;
11
- export type TrackKind = 'audio' | 'video';
12
- /**
13
- * Type describing Voice Activity Detection statuses.
14
- *
15
- * - `speech` - voice activity has been detected
16
- * - `silence` - lack of voice activity has been detected
17
- */
18
- export type VadStatus = 'speech' | 'silence';
19
- /**
20
- * Type describing maximal bandwidth that can be used, in kbps. 0 is interpreted as unlimited bandwidth.
21
- */
22
- export type BandwidthLimit = number;
23
- /**
24
- * Type describing bandwidth limit for simulcast track.
25
- * It is a mapping (encoding => BandwidthLimit).
26
- * If encoding isn't present in this mapping, it will be assumed that this particular encoding shouldn't have any bandwidth limit
27
- */
28
- export type SimulcastBandwidthLimit = Map<Variant, BandwidthLimit>;
29
- /**
30
- * Type describing bandwidth limitation of a Track, including simulcast and non-simulcast tracks.
31
- * A sum type of `BandwidthLimit` and `SimulcastBandwidthLimit`
32
- */
33
- export type TrackBandwidthLimit = BandwidthLimit | SimulcastBandwidthLimit;
34
- /**
35
- * Type describing possible reasons for currently selected encoding.
36
- * - `other` - the exact reason couldn't be determined
37
- * - `encodingInactive` - previously selected encoding became inactive
38
- * - `lowBandwidth` - there is no longer enough bandwidth to maintain previously selected encoding
39
- */
40
- export type EncodingReason = 'other' | 'encodingInactive' | 'lowBandwidth';
41
- /**
42
- * Track's context i.e. all data that can be useful when operating on track.
43
- */
44
- interface TrackContextFields {
45
- readonly track: MediaStreamTrack | null;
46
- /**
47
- * Stream this track belongs to.
48
- */
49
- readonly stream: MediaStream | null;
50
- /**
51
- * Endpoint this track comes from.
52
- */
53
- readonly endpoint: Endpoint;
54
- /**
55
- * Track id. It is generated by RTC engine and takes form `endpoint_id:<random_uuidv4>`.
56
- * It is WebRTC agnostic i.e. it does not contain `mid` or `stream id`.
57
- */
58
- readonly trackId: string;
59
- /**
60
- * Simulcast configuration.
61
- * Only present for local tracks.
62
- */
63
- readonly simulcastConfig?: MediaEvent_Track_SimulcastConfig;
64
- /**
65
- * Any info that was passed in {@link WebRTCEndpoint.addTrack}.
66
- */
67
- readonly metadata?: unknown;
68
- readonly maxBandwidth?: TrackBandwidthLimit;
69
- readonly vadStatus: VadStatus;
70
- /**
71
- * Encoding that is currently received.
72
- * Only present for remote tracks.
73
- */
74
- readonly encoding?: Variant;
75
- /**
76
- * The reason of currently selected encoding.
77
- * Only present for remote tracks.
78
- */
79
- readonly encodingReason?: EncodingReason;
80
- }
81
- export interface TrackContextEvents {
82
- /**
83
- * Emitted each time track encoding has changed.
84
- *
85
- * Track encoding can change in the following cases:
86
- * - when user requested a change
87
- * - when sender stopped sending some encoding (because of bandwidth change)
88
- * - when receiver doesn't have enough bandwidth
89
- *
90
- * Some of those reasons are indicated in {@link TrackContext.encodingReason}.
91
- */
92
- encodingChanged: (context: TrackContext) => void;
93
- /**
94
- * Emitted every time an update about voice activity is received from the server.
95
- */
96
- voiceActivityChanged: (context: TrackContext) => void;
97
- }
98
- export interface TrackContext extends TrackContextFields, TypedEmitter<Required<TrackContextEvents>> {
99
- }
100
- export type TrackNegotiationStatus = 'awaiting' | 'offered' | 'done';
101
- /**
102
- * Events emitted by the {@link WebRTCEndpoint} instance.
103
- */
104
- export interface WebRTCEndpointEvents {
105
- /**
106
- * Emitted each time WebRTCEndpoint need to send some data to the server.
107
- */
108
- sendMediaEvent: (mediaEvent: SerializedMediaEvent) => void;
109
- /**
110
- * Emitted when endpoint of this {@link WebRTCEndpoint} instance is ready. Triggered by {@link WebRTCEndpoint.connect}
111
- */
112
- connected: (endpointId: string, otherEndpoints: Endpoint[]) => void;
113
- /**
114
- * Emitted when endpoint of this {@link WebRTCEndpoint} instance was removed.
115
- */
116
- disconnected: () => void;
117
- /**
118
- * Emitted when data in a new track arrives.
119
- *
120
- * This event is always emitted after {@link trackAdded}.
121
- * It informs the user that data related to the given track arrives and can be played or displayed.
122
- */
123
- trackReady: (ctx: TrackContext) => void;
124
- /**
125
- * Emitted each time the endpoint which was already in the room, adds new track. Fields track and stream will be set to null.
126
- * These fields will be set to non-null value in {@link trackReady}
127
- */
128
- trackAdded: (ctx: TrackContext) => void;
129
- /**
130
- * Emitted when some track will no longer be sent.
131
- *
132
- * It will also be emitted before {@link endpointRemoved} for each track of this endpoint.
133
- */
134
- trackRemoved: (ctx: TrackContext) => void;
135
- /**
136
- * Emitted each time endpoint has its track metadata updated.
137
- */
138
- trackUpdated: (ctx: TrackContext) => void;
139
- /**
140
- * Emitted each time new endpoint is added to the room.
141
- */
142
- endpointAdded: (endpoint: Endpoint) => void;
143
- /**
144
- * Emitted each time endpoint is removed, emitted only for other endpoints.
145
- */
146
- endpointRemoved: (endpoint: Endpoint) => void;
147
- /**
148
- * Emitted each time endpoint has its metadata updated.
149
- */
150
- endpointUpdated: (endpoint: Endpoint) => void;
151
- /**
152
- * Emitted in case of errors related to multimedia session e.g. ICE connection.
153
- */
154
- connectionError: (error: {
155
- message: string;
156
- event: Event;
157
- }) => void;
158
- /**
159
- * Emitted in case of errors related to multimedia session e.g. ICE connection.
160
- */
161
- signalingError: (error: {
162
- message: string;
163
- }) => void;
164
- /**
165
- * Currently, this event is only emitted when DisplayManager in RTC Engine is
166
- * enabled and simulcast is disabled.
167
- *
168
- * Emitted when priority of video tracks have changed.
169
- * @param enabledTracks - list of tracks which will be sent to client from SFU
170
- * @param disabledTracks - list of tracks which will not be sent to client from SFU
171
- */
172
- tracksPriorityChanged: (enabledTracks: TrackContext[], disabledTracks: TrackContext[]) => void;
173
- /**
174
- * Emitted every time the server estimates client's bandwidth.
175
- *
176
- * @param {bigint} estimation - client's available incoming bitrate estimated
177
- * by the server. It's measured in bits per second.
178
- */
179
- bandwidthEstimationChanged: (estimation: bigint) => void;
180
- /**
181
- * Emitted each time track encoding has been disabled.
182
- */
183
- trackEncodingDisabled: (context: TrackContext, encoding: Variant) => void;
184
- /**
185
- * Emitted each time track encoding has been enabled.
186
- */
187
- trackEncodingEnabled: (context: TrackContext, encoding: Variant) => void;
188
- targetTrackEncodingRequested: (event: {
189
- trackId: string;
190
- variant: Variant;
191
- }) => void;
192
- disconnectRequested: (event: any) => void;
193
- localTrackAdded: (event: {
194
- trackId: string;
195
- track: MediaStreamTrack;
196
- stream: MediaStream;
197
- trackMetadata?: unknown;
198
- simulcastConfig: MediaEvent_Track_SimulcastConfig;
199
- maxBandwidth: TrackBandwidthLimit;
200
- }) => void;
201
- localTrackRemoved: (event: {
202
- trackId: string;
203
- }) => void;
204
- localTrackReplaced: (event: {
205
- trackId: string;
206
- track: MediaStreamTrack | null;
207
- }) => void;
208
- localTrackMuted: (event: {
209
- trackId: string;
210
- }) => void;
211
- localTrackUnmuted: (event: {
212
- trackId: string;
213
- }) => void;
214
- localTrackBandwidthSet: (event: {
215
- trackId: string;
216
- bandwidth: BandwidthLimit;
217
- }) => void;
218
- localTrackEncodingBandwidthSet: (event: {
219
- trackId: string;
220
- rid: Variant;
221
- bandwidth: BandwidthLimit;
222
- }) => void;
223
- localTrackEncodingEnabled: (event: {
224
- trackId: string;
225
- encoding: Variant;
226
- }) => void;
227
- localTrackEncodingDisabled: (event: {
228
- trackId: string;
229
- encoding: Variant;
230
- }) => void;
231
- localEndpointMetadataChanged: (event: {
232
- metadata: unknown;
233
- }) => void;
234
- localTrackMetadataChanged: (event: {
235
- trackId: string;
236
- metadata: unknown;
237
- }) => void;
238
- /**
239
- * Emitted when data channels (for both reliable and lossy) are created and ready to send data.
240
- * This event is fired after calling connectDataChannels().
241
- */
242
- dataChannelsReady: () => void;
243
- /**
244
- * Emitted when data is received on any data channel.
245
- * The payload includes the channel type (reliable/lossy) and the binary data.
246
- */
247
- dataChannelPayload: (payload: DataChannelMessagePayload) => void;
248
- /**
249
- * Emitted when any data channel errors.
250
- */
251
- dataChannelsError: (error: Error) => void;
252
- }
253
- /**
254
- * Interface describing Endpoint.
255
- */
256
- export interface Endpoint {
257
- /**
258
- * Endpoint's id. It is assigned by user in custom logic that use backend API.
259
- */
260
- id: string;
261
- /**
262
- * Type of the endpoint, e.g. "webrtc", "hls" or "rtsp".
263
- */
264
- type: string;
265
- /**
266
- * Any information that was provided in {@link WebRTCEndpoint.connect}.
267
- */
268
- metadata?: unknown;
269
- /**
270
- * List of tracks that are sent by the endpoint.
271
- */
272
- tracks: Map<string, TrackContext>;
273
- }
274
- /**
275
- * Options for publishing or subscribing to data.
276
- */
277
- export interface DataChannelOptions {
278
- /**
279
- * If true, uses the reliable data channel (ordered, guaranteed delivery).
280
- * If false, uses the lossy data channel (unordered, low latency).
281
- */
282
- reliable: boolean;
283
- }
284
- /**
285
- * Callback type for receiving data from a data channel.
286
- * @param data - The received data as a Uint8Array
287
- */
288
- export type DataCallback = (data: Uint8Array) => void;
289
- /**
290
- * Internal type for channel classification
291
- * @internal
292
- */
293
- export type DataChannelType = 'reliable' | 'lossy';
294
- /**
295
- * Internal status tracking for data channels
296
- * @internal
297
- */
298
- export type DataChannelStatus = 'init' | 'creating' | 'open' | 'closed';
299
- /**
300
- * Payload for data received events from data channels.
301
- */
302
- export interface DataChannelMessagePayload {
303
- /**
304
- * The type of channel the data was received on.
305
- */
306
- channelType: DataChannelType;
307
- /**
308
- * The binary payload data.
309
- */
310
- data: Uint8Array;
311
- }
312
- /**
313
- * Events emitted by the DataChannelManager.
314
- */
315
- export interface DataChannelManagerEvents {
316
- /**
317
- * Emitted when both reliable and lossy data channel publishers are ready to send data.
318
- */
319
- ready: () => void;
320
- /**
321
- * Emitted when a data channel is opened.
322
- */
323
- channelOpen: (type: DataChannelType) => void;
324
- /**
325
- * Emitted when a data channel errors.
326
- */
327
- error: (type: DataChannelType, error: Event) => void;
328
- /**
329
- * Emitted when data is received on any data channel.
330
- */
331
- data: (payload: DataChannelMessagePayload) => void;
332
- }
333
- export type WebRTCEndpointProps = {
334
- /**
335
- * Enables Fishjam SDK's debug logs in the console.
336
- */
337
- debug?: boolean;
338
- };
339
- export type Logger = ReturnType<typeof getLogger>;
340
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,350 +0,0 @@
1
- import type { MediaEvent_Track_SimulcastConfig } from '@fishjam-cloud/protobufs/server';
2
- import type { Variant } from '@fishjam-cloud/protobufs/shared';
3
- import type TypedEmitter from 'typed-emitter';
4
- import { ConnectionManager } from './ConnectionManager';
5
- import type { EndpointWithTrackContext } from './internal';
6
- import type { SerializedMediaEvent } from './mediaEvent';
7
- import type { BandwidthLimit, DataChannelOptions, TrackBandwidthLimit, TrackContext, WebRTCEndpointEvents, WebRTCEndpointProps } from './types';
8
- declare const WebRTCEndpoint_base: new () => TypedEmitter<Required<WebRTCEndpointEvents>>;
9
- /**
10
- * Main class that is responsible for connecting to the RTC Engine, sending and receiving media.
11
- */
12
- export declare class WebRTCEndpoint extends WebRTCEndpoint_base {
13
- private readonly localTrackManager;
14
- private readonly remote;
15
- private readonly local;
16
- private readonly commandsQueue;
17
- private readonly dataChannelManager;
18
- private proposedIceServers;
19
- private logger;
20
- bandwidthEstimation: bigint;
21
- connectionManager?: ConnectionManager;
22
- private clearConnectionCallbacks;
23
- constructor(props?: WebRTCEndpointProps);
24
- /**
25
- * Tries to connect to the RTC Engine. If user is successfully connected then {@link WebRTCEndpointEvents.connected}
26
- * will be emitted.
27
- *
28
- * @param metadata - Any information that other endpoints will receive in {@link WebRTCEndpointEvents.endpointAdded}
29
- * after accepting this endpoint
30
- *
31
- * @example
32
- * ```ts
33
- * let webrtc = new WebRTCEndpoint();
34
- * webrtc.connect({displayName: "Bob"});
35
- * ```
36
- */
37
- connect: (metadata: unknown) => void;
38
- /**
39
- * Feeds media event received from RTC Engine to {@link WebRTCEndpoint}.
40
- * This function should be called whenever some media event from RTC Engine
41
- * was received and can result in {@link WebRTCEndpoint} generating some other
42
- * media events.
43
- *
44
- * @param mediaEvent - String data received over custom signalling layer.
45
- *
46
- * @example
47
- * This example assumes phoenix channels as signalling layer.
48
- * As phoenix channels require objects, RTC Engine encapsulates binary data into
49
- * map with one field that is converted to object with one field on the TS side.
50
- * ```ts
51
- * webrtcChannel.on("mediaEvent", (event) => webrtc.receiveMediaEvent(event.data));
52
- * ```
53
- */
54
- receiveMediaEvent: (mediaEvent: SerializedMediaEvent) => Promise<void>;
55
- private getEndpointId;
56
- private onTrackReady;
57
- /**
58
- * Retrieves statistics related to the RTCPeerConnection.
59
- * These statistics provide insights into the performance and status of the connection.
60
- *
61
- * @return {Promise<RTCStatsReport>}
62
- *
63
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/getStats | MDN Web Docs: RTCPeerConnection.getStats()}
64
- */
65
- getStatistics(selector?: MediaStreamTrack | null): Promise<RTCStatsReport>;
66
- /**
67
- * Returns a snapshot of currently received remote tracks.
68
- *
69
- * @example
70
- * if (webRTCEndpoint.getRemoteTracks()[trackId]?.simulcastConfig?.enabled) {
71
- * webRTCEndpoint.setTargetTrackEncoding(trackId, encoding);
72
- * }
73
- */
74
- getRemoteTracks(): Record<string, TrackContext>;
75
- /**
76
- * Returns a snapshot of currently received remote endpoints.
77
- */
78
- getRemoteEndpoints(): Record<string, EndpointWithTrackContext>;
79
- getLocalEndpoint(): EndpointWithTrackContext;
80
- getBandwidthEstimation(): bigint;
81
- getDataChannelsReadiness(): boolean;
82
- private handleMediaEvent;
83
- private onSdpAnswer;
84
- /**
85
- * Adds track that will be sent to the RTC Engine.
86
- * @param track - Audio or video track e.g. from your microphone or camera.
87
- * @param trackMetadata - Any information about this track that other endpoints will
88
- * receive in {@link WebRTCEndpointEvents.endpointAdded}. E.g. this can source of the track - whether it's
89
- * screensharing, webcam or some other media device.
90
- * @param _simulcastConfig - Simulcast configuration parameter. **Currently ignored** - simulcast is disabled
91
- * regardless of the value passed. This is a temporary change until bandwidth estimation is implemented or
92
- * manual track selection support is added. For more information refer to {@link SimulcastConfig}.
93
- * @param _maxBandwidth - maximal bandwidth this track can use. **Currently processed with a threshold check**:
94
- * if the value is a positive number, it will be used; otherwise, it defaults to 0 (unlimited).
95
- * This option has no effect for simulcast and audio tracks.
96
- * For simulcast tracks use `{@link WebRTCEndpoint.setTrackBandwidth}.
97
- * @returns {string} Returns id of added track
98
- * @example
99
- * ```ts
100
- * let localStream: MediaStream = new MediaStream();
101
- * try {
102
- * localAudioStream = await navigator.mediaDevices.getUserMedia(
103
- * AUDIO_CONSTRAINTS
104
- * );
105
- * localAudioStream
106
- * .getTracks()
107
- * .forEach((track) => localStream.addTrack(track));
108
- * } catch (error) {
109
- * this.logger.error("Couldn't get microphone permission:", error);
110
- * }
111
- *
112
- * try {
113
- * localVideoStream = await navigator.mediaDevices.getUserMedia(
114
- * VIDEO_CONSTRAINTS
115
- * );
116
- * localVideoStream
117
- * .getTracks()
118
- * .forEach((track) => localStream.addTrack(track));
119
- * } catch (error) {
120
- * this.logger.error("Couldn't get camera permission:", error);
121
- * }
122
- *
123
- * localStream
124
- * .getTracks()
125
- * .forEach((track) => webrtc.addTrack(track, localStream));
126
- * ```
127
- */
128
- addTrack(track: MediaStreamTrack, trackMetadata?: unknown, _simulcastConfig?: MediaEvent_Track_SimulcastConfig, _maxBandwidth?: TrackBandwidthLimit): Promise<string>;
129
- /**
130
- * Replaces a track that is being sent to the RTC Engine.
131
- * @param trackId - Audio or video track.
132
- * @param {string} trackId - Id of audio or video track to replace.
133
- * @param {MediaStreamTrack} newTrack
134
- * @returns {Promise<boolean>} success
135
- * @example
136
- * ```ts
137
- * // setup camera
138
- * let localStream: MediaStream = new MediaStream();
139
- * try {
140
- * localVideoStream = await navigator.mediaDevices.getUserMedia(
141
- * VIDEO_CONSTRAINTS
142
- * );
143
- * localVideoStream
144
- * .getTracks()
145
- * .forEach((track) => localStream.addTrack(track));
146
- * } catch (error) {
147
- * this.logger.error("Couldn't get camera permission:", error);
148
- * }
149
- * let oldTrackId;
150
- * localStream
151
- * .getTracks()
152
- * .forEach((track) => trackId = webrtc.addTrack(track, localStream));
153
- *
154
- * // change camera
155
- * const oldTrack = localStream.getVideoTracks()[0];
156
- * let videoDeviceId = "abcd-1234";
157
- * navigator.mediaDevices.getUserMedia({
158
- * video: {
159
- * ...(VIDEO_CONSTRAINTS as {}),
160
- * deviceId: {
161
- * exact: videoDeviceId,
162
- * },
163
- * }
164
- * })
165
- * .then((stream) => {
166
- * let videoTrack = stream.getVideoTracks()[0];
167
- * webrtc.replaceTrack(oldTrackId, videoTrack);
168
- * })
169
- * .catch((error) => {
170
- * this.logger.error('Error switching camera', error);
171
- * })
172
- * ```
173
- */
174
- replaceTrack(trackId: string, newTrack: MediaStreamTrack | null): Promise<void>;
175
- /**
176
- * Updates maximum bandwidth for the track identified by trackId.
177
- * This value directly translates to quality of the stream and, in case of video, to the amount of RTP packets being sent.
178
- * In case trackId points at the simulcast track bandwidth is split between all of the variant streams proportionally to their resolution.
179
- *
180
- * @param {string} trackId
181
- * @param {BandwidthLimit} bandwidth in kbps
182
- * @returns {Promise<boolean>} success
183
- */
184
- setTrackBandwidth(trackId: string, bandwidth: BandwidthLimit): Promise<void>;
185
- /**
186
- * Updates maximum bandwidth for the given simulcast encoding of the given track.
187
- *
188
- * @param {string} trackId - id of the track
189
- * @param {string} rid - rid of the encoding
190
- * @param {BandwidthLimit} bandwidth - desired max bandwidth used by the encoding (in kbps)
191
- * @returns
192
- */
193
- setEncodingBandwidth(trackId: string, rid: Variant, bandwidth: BandwidthLimit): Promise<void>;
194
- /**
195
- * Removes a track from connection that was sent to the RTC Engine.
196
- * @param {string} trackId - Id of audio or video track to remove.
197
- * @example
198
- * ```ts
199
- * // setup camera
200
- * let localStream: MediaStream = new MediaStream();
201
- * try {
202
- * localVideoStream = await navigator.mediaDevices.getUserMedia(
203
- * VIDEO_CONSTRAINTS
204
- * );
205
- * localVideoStream
206
- * .getTracks()
207
- * .forEach((track) => localStream.addTrack(track));
208
- * } catch (error) {
209
- * this.logger.error("Couldn't get camera permission:", error);
210
- * }
211
- *
212
- * let trackId
213
- * localStream
214
- * .getTracks()
215
- * .forEach((track) => trackId = webrtc.addTrack(track, localStream));
216
- *
217
- * // remove track
218
- * webrtc.removeTrack(trackId)
219
- * ```
220
- */
221
- removeTrack(trackId: string): Promise<void>;
222
- /**
223
- * Sets track variant that server should send to the client library.
224
- *
225
- * The variant will be sent whenever it is available.
226
- * If chosen variant is temporarily unavailable, some other variant
227
- * will be sent until the chosen variant becomes active again.
228
- *
229
- * @param {string} trackId - id of track
230
- * @param {Encoding} variant - variant to receive
231
- * @example
232
- * ```ts
233
- * webrtc.setTargetTrackEncoding(incomingTrackCtx.trackId, "l")
234
- * ```
235
- */
236
- setTargetTrackEncoding(trackId: string, variant: Variant): void;
237
- /**
238
- * Enables track encoding so that it will be sent to the server.
239
- * @param {string} trackId - id of track
240
- * @param {Encoding} encoding - encoding that will be enabled
241
- * @example
242
- * ```ts
243
- * const trackId = webrtc.addTrack(track, stream, {}, {enabled: true, activeEncodings: ["l", "m", "h"]});
244
- * webrtc.disableTrackEncoding(trackId, "l");
245
- * // wait some time
246
- * webrtc.enableTrackEncoding(trackId, "l");
247
- * ```
248
- */
249
- enableTrackEncoding: (trackId: string, encoding: Variant) => Promise<void>;
250
- /**
251
- * Disables track encoding so that it will be no longer sent to the server.
252
- * @param {string} trackId - id of track
253
- * @param {Encoding} encoding - encoding that will be disabled
254
- * @example
255
- * ```ts
256
- * const trackId = webrtc.addTrack(track, stream, {}, {enabled: true, activeEncodings: ["l", "m", "h"]});
257
- * webrtc.disableTrackEncoding(trackId, "l");
258
- * ```
259
- */
260
- disableTrackEncoding: (trackId: string, encoding: Variant) => Promise<void>;
261
- /**
262
- * Updates the metadata for the current endpoint.
263
- * @param metadata - Data about this endpoint that other endpoints will receive upon being added.
264
- *
265
- * If the metadata is different from what is already tracked in the room, the optional
266
- * event `endpointUpdated` will be emitted for other endpoint in the room.
267
- */
268
- updateEndpointMetadata: (metadata: any) => void;
269
- /**
270
- * Updates the metadata for a specific track.
271
- * @param trackId - trackId (generated in addTrack) of audio or video track.
272
- * @param trackMetadata - Data about this track that other endpoint will receive upon being added.
273
- *
274
- * If the metadata is different from what is already tracked in the room, the optional
275
- * event `trackUpdated` will be emitted for other endpoints in the room.
276
- */
277
- updateTrackMetadata: (trackId: string, trackMetadata: any) => void;
278
- /**
279
- * Disconnects from the room. This function should be called when user disconnects from the room
280
- * in a clean way e.g. by clicking a dedicated, custom button `disconnect`.
281
- * As a result there will be generated one more media event that should be
282
- * sent to the RTC Engine. Thanks to it each other endpoint will be notified
283
- * that endpoint was removed in {@link WebRTCEndpointEvents.endpointRemoved},
284
- */
285
- disconnect: () => void;
286
- /**
287
- * Create both reliable and lossy data channel.
288
- * This method must be called before publishData() can be used.
289
- * Emits the 'dataChannelsReady' event when both channels are open and ready.
290
- *
291
- * @example
292
- * ```ts
293
- * const webrtc = new WebRTCEndpoint();
294
- *
295
- * webrtc.on('dataChannelsReady', () => {
296
- * console.log('Data channels ready, can now send data');
297
- * webrtc.publishData(new TextEncoder().encode('Hello'), { reliable: true });
298
- * });
299
- *
300
- * webrtc.connectDataChannels();
301
- * ```
302
- */
303
- connectDataChannels: () => Promise<void>;
304
- /**
305
- * Publish data through a data channel.
306
- * The data channels must be created first by calling connectDataChannels() or enabling negotiateOnConnect.
307
- * Throws an error if the channel doesn't exist or isn't ready yet.
308
- *
309
- * @param data - The data to send as Uint8Array
310
- * @param options - Options specifying which channel to use (reliable or lossy)
311
- * @throws Error if the channel doesn't exist or isn't ready
312
- *
313
- * @example
314
- * ```ts
315
- * // Subscribe to incoming data
316
- * webrtc.on('dataReceived', ({ channelType, data }) => {
317
- * console.log(`Received on ${channelType}:`, new TextDecoder().decode(data));
318
- * });
319
- *
320
- * webrtc.on('dataChannelsReady', () => {
321
- * // Send reliable data
322
- * const data = new TextEncoder().encode('Hello World');
323
- * webrtc.publishData(data, { reliable: true });
324
- *
325
- * // Send lossy data for low-latency updates
326
- * const gameState = new Uint8Array([1, 2, 3, 4, 5]);
327
- * webrtc.publishData(gameState, { reliable: false });
328
- * });
329
- *
330
- * webrtc.connectDataChannels();
331
- * ```
332
- */
333
- publishData: (data: Uint8Array, options: DataChannelOptions) => void;
334
- /**
335
- * Cleans up {@link WebRTCEndpoint} instance.
336
- */
337
- cleanUp: () => void;
338
- private getTrackId;
339
- private sendMediaEvent;
340
- private createAndSendOffer;
341
- private onOfferData;
342
- private setupConnectionListeners;
343
- private createNewConnection;
344
- private onRemoteCandidate;
345
- private onLocalCandidate;
346
- private onIceCandidateError;
347
- private onConnectionStateChange;
348
- private onIceConnectionStateChange;
349
- }
350
- export {};