@livekit/rtc-node 0.0.7 → 0.2.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/build.rs +4 -0
- package/dist/audio_frame.d.ts +1 -1
- package/dist/audio_frame.d.ts.map +1 -1
- package/dist/audio_frame.js +10 -11
- package/dist/audio_frame.js.map +1 -1
- package/dist/audio_source.d.ts +3 -3
- package/dist/audio_source.d.ts.map +1 -1
- package/dist/audio_source.js +14 -15
- package/dist/audio_source.js.map +1 -1
- package/dist/audio_stream.d.ts +8 -5
- package/dist/audio_stream.d.ts.map +1 -1
- package/dist/audio_stream.js +18 -22
- package/dist/audio_stream.js.map +1 -1
- package/dist/e2ee.d.ts +1 -1
- package/dist/e2ee.d.ts.map +1 -1
- package/dist/e2ee.js +42 -45
- package/dist/e2ee.js.map +1 -1
- package/dist/ffi_client.d.ts +2 -2
- package/dist/ffi_client.d.ts.map +1 -1
- package/dist/ffi_client.js +17 -24
- package/dist/ffi_client.js.map +1 -1
- package/dist/index.d.ts +15 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -70
- package/dist/index.js.map +1 -1
- package/{src/native.js → dist/napi/native.cjs} +12 -0
- package/dist/napi/native.js +15 -0
- package/dist/participant.d.ts +24 -9
- package/dist/participant.d.ts.map +1 -1
- package/dist/participant.js +45 -45
- package/dist/participant.js.map +1 -1
- package/dist/proto/audio_frame_pb.d.ts +0 -46
- package/dist/proto/audio_frame_pb.d.ts.map +1 -1
- package/dist/proto/audio_frame_pb.js +138 -236
- package/dist/proto/audio_frame_pb.js.map +1 -1
- package/dist/proto/e2ee_pb.js +134 -162
- package/dist/proto/e2ee_pb.js.map +1 -1
- package/dist/proto/ffi_pb.d.ts +31 -44
- package/dist/proto/ffi_pb.d.ts.map +1 -1
- package/dist/proto/ffi_pb.js +140 -126
- package/dist/proto/ffi_pb.js.map +1 -1
- package/dist/proto/handle_pb.js +7 -11
- package/dist/proto/handle_pb.js.map +1 -1
- package/dist/proto/participant_pb.js +13 -18
- package/dist/proto/participant_pb.js.map +1 -1
- package/dist/proto/room_pb.d.ts +5 -1
- package/dist/proto/room_pb.d.ts.map +1 -1
- package/dist/proto/room_pb.js +393 -454
- package/dist/proto/room_pb.js.map +1 -1
- package/dist/proto/stats_pb.js +265 -303
- package/dist/proto/stats_pb.js.map +1 -1
- package/dist/proto/track_pb.js +87 -102
- package/dist/proto/track_pb.js.map +1 -1
- package/dist/proto/video_frame_pb.d.ts +124 -390
- package/dist/proto/video_frame_pb.d.ts.map +1 -1
- package/dist/proto/video_frame_pb.js +252 -620
- package/dist/proto/video_frame_pb.js.map +1 -1
- package/dist/room.d.ts +10 -9
- package/dist/room.d.ts.map +1 -1
- package/dist/room.js +74 -76
- package/dist/room.js.map +1 -1
- package/dist/track.d.ts +4 -4
- package/dist/track.d.ts.map +1 -1
- package/dist/track.js +15 -20
- package/dist/track.js.map +1 -1
- package/dist/track_publication.d.ts +4 -4
- package/dist/track_publication.d.ts.map +1 -1
- package/dist/track_publication.js +12 -15
- package/dist/track_publication.js.map +1 -1
- package/dist/video_frame.d.ts +8 -103
- package/dist/video_frame.d.ts.map +1 -1
- package/dist/video_frame.js +161 -341
- package/dist/video_frame.js.map +1 -1
- package/dist/video_source.d.ts +4 -4
- package/dist/video_source.d.ts.map +1 -1
- package/dist/video_source.js +16 -22
- package/dist/video_source.js.map +1 -1
- package/dist/video_stream.d.ts +10 -5
- package/dist/video_stream.d.ts.map +1 -1
- package/dist/video_stream.js +20 -24
- package/dist/video_stream.js.map +1 -1
- package/package.json +14 -14
- package/src/audio_frame.ts +6 -2
- package/src/audio_source.ts +8 -4
- package/src/audio_stream.ts +15 -7
- package/src/e2ee.ts +6 -2
- package/src/ffi_client.ts +6 -2
- package/src/index.ts +19 -28
- package/src/lib.rs +4 -0
- package/src/napi/native.cjs +281 -0
- package/src/napi/native.js +15 -0
- package/src/nodejs.rs +4 -0
- package/src/participant.ts +45 -22
- package/src/proto/audio_frame_pb.ts +1 -91
- package/src/proto/e2ee_pb.ts +1 -1
- package/src/proto/ffi_pb.ts +55 -53
- package/src/proto/handle_pb.ts +1 -1
- package/src/proto/participant_pb.ts +1 -1
- package/src/proto/room_pb.ts +7 -1
- package/src/proto/stats_pb.ts +1 -1
- package/src/proto/track_pb.ts +1 -1
- package/src/proto/video_frame_pb.ts +186 -641
- package/src/room.ts +56 -48
- package/src/track.ts +8 -4
- package/src/track_publication.ts +10 -6
- package/src/video_frame.ts +186 -579
- package/src/video_source.ts +12 -12
- package/src/video_stream.ts +21 -10
- package/dist/native.d.ts.map +0 -1
- package/dist/native.js +0 -297
- package/dist/native.js.map +0 -1
- /package/dist/{native.d.ts → napi/native.d.ts} +0 -0
- /package/src/{native.d.ts → napi/native.d.ts} +0 -0
package/src/room.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
import { FfiClient, FfiClientEvent, FfiHandle } from './ffi_client.js';
|
|
2
6
|
import EventEmitter from 'events';
|
|
3
7
|
import TypedEmitter from 'typed-emitter';
|
|
4
|
-
import { FfiEvent } from './proto/ffi_pb';
|
|
5
|
-
import { LocalParticipant, Participant, RemoteParticipant } from './participant';
|
|
8
|
+
import { FfiEvent } from './proto/ffi_pb.js';
|
|
9
|
+
import { LocalParticipant, Participant, RemoteParticipant } from './participant.js';
|
|
6
10
|
import {
|
|
7
11
|
ConnectCallback,
|
|
8
12
|
ConnectRequest,
|
|
@@ -15,17 +19,17 @@ import {
|
|
|
15
19
|
IceServer,
|
|
16
20
|
IceTransportType,
|
|
17
21
|
RoomInfo,
|
|
18
|
-
} from './proto/room_pb';
|
|
19
|
-
import { E2EEManager, E2EEOptions, defaultE2EEOptions } from './e2ee';
|
|
20
|
-
import { OwnedParticipant } from './proto/participant_pb';
|
|
22
|
+
} from './proto/room_pb.js';
|
|
23
|
+
import { E2EEManager, E2EEOptions, defaultE2EEOptions } from './e2ee.js';
|
|
24
|
+
import { OwnedParticipant } from './proto/participant_pb.js';
|
|
21
25
|
import {
|
|
22
26
|
LocalTrackPublication,
|
|
23
27
|
RemoteTrackPublication,
|
|
24
28
|
TrackPublication,
|
|
25
|
-
} from './track_publication';
|
|
26
|
-
import { LocalTrack, RemoteAudioTrack, RemoteTrack, RemoteVideoTrack } from './track';
|
|
27
|
-
import { TrackKind } from './proto/track_pb';
|
|
28
|
-
import { EncryptionState } from './proto/e2ee_pb';
|
|
29
|
+
} from './track_publication.js';
|
|
30
|
+
import { LocalTrack, RemoteAudioTrack, RemoteTrack, RemoteVideoTrack } from './track.js';
|
|
31
|
+
import { TrackKind } from './proto/track_pb.js';
|
|
32
|
+
import { EncryptionState } from './proto/e2ee_pb.js';
|
|
29
33
|
|
|
30
34
|
export interface RtcConfiguration {
|
|
31
35
|
iceTransportType: IceTransportType;
|
|
@@ -58,19 +62,15 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
58
62
|
private ffiHandle?: FfiHandle;
|
|
59
63
|
|
|
60
64
|
e2eeManager: E2EEManager;
|
|
61
|
-
|
|
65
|
+
connectionState: ConnectionState = ConnectionState.CONN_DISCONNECTED;
|
|
62
66
|
|
|
63
|
-
|
|
67
|
+
remoteParticipants: Map<string, RemoteParticipant> = new Map();
|
|
64
68
|
localParticipant?: LocalParticipant;
|
|
65
69
|
|
|
66
70
|
constructor() {
|
|
67
71
|
super();
|
|
68
72
|
}
|
|
69
73
|
|
|
70
|
-
get sid(): string {
|
|
71
|
-
return this.info.sid;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
74
|
get name(): string {
|
|
75
75
|
return this.info.name;
|
|
76
76
|
}
|
|
@@ -80,9 +80,11 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
get isConnected(): boolean {
|
|
83
|
-
return
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
return this.ffiHandle != undefined && this.connectionState != ConnectionState.CONN_DISCONNECTED;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async getSid(): Promise<string> {
|
|
87
|
+
return this.info.sid; // TODO update this to handle async room updates once rust protocol has been updated
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
async connect(url: string, token: string, opts?: RoomOptions) {
|
|
@@ -125,7 +127,7 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
125
127
|
this.e2eeManager = new E2EEManager(this.ffiHandle.handle, options.e2ee);
|
|
126
128
|
|
|
127
129
|
this.info = cb.room.info;
|
|
128
|
-
this.
|
|
130
|
+
this.connectionState = ConnectionState.CONN_CONNECTED;
|
|
129
131
|
this.localParticipant = new LocalParticipant(cb.localParticipant);
|
|
130
132
|
|
|
131
133
|
for (let pt of cb.participants) {
|
|
@@ -133,7 +135,7 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
133
135
|
|
|
134
136
|
for (let pub of pt.publications) {
|
|
135
137
|
let publication = new RemoteTrackPublication(pub);
|
|
136
|
-
rp.
|
|
138
|
+
rp.trackPublications.set(publication.sid, publication);
|
|
137
139
|
}
|
|
138
140
|
}
|
|
139
141
|
|
|
@@ -166,33 +168,33 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
166
168
|
let ev = ffiEvent.message.value.message;
|
|
167
169
|
if (ev.case == 'participantConnected') {
|
|
168
170
|
let participant = this.createRemoteParticipant(ev.value.info);
|
|
169
|
-
this.
|
|
171
|
+
this.remoteParticipants.set(participant.identity, participant);
|
|
170
172
|
this.emit(RoomEvent.ParticipantConnected, participant);
|
|
171
173
|
} else if (ev.case == 'participantDisconnected') {
|
|
172
|
-
let participant = this.
|
|
173
|
-
this.
|
|
174
|
+
let participant = this.getRemoteParticipantBySid(ev.value.participantSid);
|
|
175
|
+
this.remoteParticipants.delete(participant.identity);
|
|
174
176
|
this.emit(RoomEvent.ParticipantDisconnected, participant);
|
|
175
177
|
} else if (ev.case == 'localTrackPublished') {
|
|
176
|
-
let publication = this.localParticipant.
|
|
178
|
+
let publication = this.localParticipant.trackPublications.get(ev.value.trackSid);
|
|
177
179
|
this.emit(RoomEvent.LocalTrackPublished, publication, publication.track);
|
|
178
180
|
} else if (ev.case == 'localTrackUnpublished') {
|
|
179
|
-
let publication = this.localParticipant.
|
|
180
|
-
this.localParticipant.
|
|
181
|
+
let publication = this.localParticipant.trackPublications.get(ev.value.publicationSid);
|
|
182
|
+
this.localParticipant.trackPublications.delete(ev.value.publicationSid);
|
|
181
183
|
this.emit(RoomEvent.LocalTrackUnpublished, publication);
|
|
182
184
|
} else if (ev.case == 'trackPublished') {
|
|
183
|
-
let participant = this.
|
|
185
|
+
let participant = this.getRemoteParticipantBySid(ev.value.participantSid);
|
|
184
186
|
let publication = new RemoteTrackPublication(ev.value.publication);
|
|
185
|
-
participant.
|
|
187
|
+
participant.trackPublications.set(publication.sid, publication);
|
|
186
188
|
this.emit(RoomEvent.TrackPublished, publication, participant);
|
|
187
189
|
} else if (ev.case == 'trackUnpublished') {
|
|
188
|
-
let participant = this.
|
|
189
|
-
let publication = participant.
|
|
190
|
-
participant.
|
|
190
|
+
let participant = this.getRemoteParticipantBySid(ev.value.participantSid);
|
|
191
|
+
let publication = participant.trackPublications.get(ev.value.publicationSid);
|
|
192
|
+
participant.trackPublications.delete(ev.value.publicationSid);
|
|
191
193
|
this.emit(RoomEvent.TrackUnpublished, publication, participant);
|
|
192
194
|
} else if (ev.case == 'trackSubscribed') {
|
|
193
195
|
let ownedTrack = ev.value.track;
|
|
194
|
-
let participant = this.
|
|
195
|
-
let publication = participant.
|
|
196
|
+
let participant = this.getRemoteParticipantBySid(ev.value.participantSid);
|
|
197
|
+
let publication = participant.trackPublications.get(ownedTrack.info.sid);
|
|
196
198
|
publication.subscribed = true;
|
|
197
199
|
if (ownedTrack.info.kind == TrackKind.KIND_VIDEO) {
|
|
198
200
|
publication.track = new RemoteVideoTrack(ownedTrack);
|
|
@@ -202,17 +204,17 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
202
204
|
|
|
203
205
|
this.emit(RoomEvent.TrackSubscribed, publication.track, publication, participant);
|
|
204
206
|
} else if (ev.case == 'trackUnsubscribed') {
|
|
205
|
-
let participant = this.
|
|
206
|
-
let publication = participant.
|
|
207
|
+
let participant = this.getRemoteParticipantBySid(ev.value.participantSid);
|
|
208
|
+
let publication = participant.trackPublications.get(ev.value.trackSid);
|
|
207
209
|
publication.track = undefined;
|
|
208
210
|
publication.subscribed = false;
|
|
209
211
|
this.emit(RoomEvent.TrackUnsubscribed, publication.track, publication, participant);
|
|
210
212
|
} else if (ev.case == 'trackSubscriptionFailed') {
|
|
211
|
-
let participant = this.
|
|
213
|
+
let participant = this.getRemoteParticipantBySid(ev.value.participantSid);
|
|
212
214
|
this.emit(RoomEvent.TrackSubscriptionFailed, participant, ev.value.trackSid, ev.value.error);
|
|
213
215
|
} else if (ev.case == 'trackMuted') {
|
|
214
216
|
let participant = this.retrieveParticipant(ev.value.participantSid);
|
|
215
|
-
let publication = participant.
|
|
217
|
+
let publication = participant.trackPublications.get(ev.value.trackSid);
|
|
216
218
|
publication.info.muted = true;
|
|
217
219
|
if (publication.track) {
|
|
218
220
|
publication.track.info.muted = true;
|
|
@@ -220,14 +222,16 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
220
222
|
this.emit(RoomEvent.TrackMuted, participant, publication);
|
|
221
223
|
} else if (ev.case == 'trackUnmuted') {
|
|
222
224
|
let participant = this.retrieveParticipant(ev.value.participantSid);
|
|
223
|
-
let publication = participant.
|
|
225
|
+
let publication = participant.trackPublications.get(ev.value.trackSid);
|
|
224
226
|
publication.info.muted = false;
|
|
225
227
|
if (publication.track) {
|
|
226
228
|
publication.track.info.muted = false;
|
|
227
229
|
}
|
|
228
230
|
this.emit(RoomEvent.TrackUnmuted, participant, publication);
|
|
229
231
|
} else if (ev.case == 'activeSpeakersChanged') {
|
|
230
|
-
let activeSpeakers = ev.value.participantSids.map((sid) =>
|
|
232
|
+
let activeSpeakers = ev.value.participantSids.map((sid) =>
|
|
233
|
+
this.getRemoteParticipantBySid(sid),
|
|
234
|
+
);
|
|
231
235
|
this.emit(RoomEvent.ActiveSpeakersChanged, activeSpeakers);
|
|
232
236
|
} else if (ev.case == 'roomMetadataChanged') {
|
|
233
237
|
let oldMetadata = this.info.metadata;
|
|
@@ -253,7 +257,7 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
253
257
|
this.emit(RoomEvent.ConnectionQualityChanged, participant, ev.value.quality);
|
|
254
258
|
} else if (ev.case == 'dataReceived') {
|
|
255
259
|
// Can be undefined if the data is sent from a Server SDK
|
|
256
|
-
let participant = this.
|
|
260
|
+
let participant = this.getRemoteParticipantBySid(ev.value.participantSid);
|
|
257
261
|
let info = ev.value.data;
|
|
258
262
|
let buffer = FfiClient.instance.copyBuffer(info.data.dataPtr, Number(info.data.dataLen));
|
|
259
263
|
new FfiHandle(info.handle.id).dispose();
|
|
@@ -262,8 +266,8 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
262
266
|
let participant = this.retrieveParticipant(ev.value.participantSid);
|
|
263
267
|
this.emit(RoomEvent.E2EEStateChanged, participant, ev.value.state);
|
|
264
268
|
} else if (ev.case == 'connectionStateChanged') {
|
|
265
|
-
this.
|
|
266
|
-
this.emit(RoomEvent.ConenctionStateChanged, this.
|
|
269
|
+
this.connectionState = ev.value.state;
|
|
270
|
+
this.emit(RoomEvent.ConenctionStateChanged, this.connectionState);
|
|
267
271
|
/*} else if (ev.case == 'connected') {
|
|
268
272
|
this.emit(RoomEvent.Connected);*/
|
|
269
273
|
} else if (ev.case == 'disconnected') {
|
|
@@ -273,23 +277,27 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
273
277
|
} else if (ev.case == 'reconnected') {
|
|
274
278
|
this.emit(RoomEvent.Reconnected);
|
|
275
279
|
}
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
getRemoteParticipantBySid(sid: string) {
|
|
283
|
+
return Array.from(this.remoteParticipants.values()).find((p) => p.sid === sid);
|
|
276
284
|
}
|
|
277
285
|
|
|
278
286
|
private retrieveParticipant(sid: string): Participant {
|
|
279
|
-
if (this.localParticipant.sid
|
|
287
|
+
if (this.localParticipant.sid === sid) {
|
|
280
288
|
return this.localParticipant;
|
|
281
289
|
} else {
|
|
282
|
-
return this.
|
|
290
|
+
return this.getRemoteParticipantBySid(sid);
|
|
283
291
|
}
|
|
284
292
|
}
|
|
285
293
|
|
|
286
294
|
private createRemoteParticipant(ownedInfo: OwnedParticipant) {
|
|
287
|
-
if (this.
|
|
295
|
+
if (this.remoteParticipants.has(ownedInfo.info.identity)) {
|
|
288
296
|
throw new Error('Participant already exists');
|
|
289
297
|
}
|
|
290
298
|
|
|
291
|
-
|
|
292
|
-
this.
|
|
299
|
+
const participant = new RemoteParticipant(ownedInfo);
|
|
300
|
+
this.remoteParticipants.set(ownedInfo.info.identity, participant);
|
|
293
301
|
return participant;
|
|
294
302
|
}
|
|
295
303
|
}
|
package/src/track.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
import { AudioSource } from './audio_source.js';
|
|
6
|
+
import { FfiClient, FfiHandle, FfiRequest } from './ffi_client.js';
|
|
3
7
|
import {
|
|
4
8
|
CreateAudioTrackRequest,
|
|
5
9
|
CreateAudioTrackResponse,
|
|
@@ -9,8 +13,8 @@ import {
|
|
|
9
13
|
StreamState,
|
|
10
14
|
TrackInfo,
|
|
11
15
|
TrackKind,
|
|
12
|
-
} from './proto/track_pb';
|
|
13
|
-
import { VideoSource } from './video_source';
|
|
16
|
+
} from './proto/track_pb.js';
|
|
17
|
+
import { VideoSource } from './video_source.js';
|
|
14
18
|
|
|
15
19
|
export abstract class Track {
|
|
16
20
|
/** @internal */
|
package/src/track_publication.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
import { FfiClient, FfiRequest } from './ffi_client.js';
|
|
6
|
+
import { FfiHandle } from './napi/native.js';
|
|
7
|
+
import { EncryptionType } from './proto/e2ee_pb.js';
|
|
8
|
+
import { SetSubscribedRequest, SetSubscribedResponse } from './proto/room_pb.js';
|
|
5
9
|
import {
|
|
6
10
|
OwnedTrackPublication,
|
|
7
11
|
TrackKind,
|
|
8
12
|
TrackPublicationInfo,
|
|
9
13
|
TrackSource,
|
|
10
|
-
} from './proto/track_pb';
|
|
11
|
-
import { Track } from './track';
|
|
14
|
+
} from './proto/track_pb.js';
|
|
15
|
+
import { Track } from './track.js';
|
|
12
16
|
|
|
13
17
|
export abstract class TrackPublication {
|
|
14
18
|
/** @internal */
|