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