@livekit/rtc-node 0.3.0 → 0.4.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/Cargo.toml +2 -1
- package/dist/audio_frame.d.ts +2 -1
- package/dist/audio_frame.d.ts.map +1 -1
- package/dist/audio_frame.js +3 -3
- package/dist/audio_frame.js.map +1 -1
- package/dist/audio_source.d.ts +2 -2
- package/dist/audio_source.d.ts.map +1 -1
- package/dist/audio_source.js +6 -9
- package/dist/audio_source.js.map +1 -1
- package/dist/audio_stream.d.ts +3 -3
- package/dist/audio_stream.d.ts.map +1 -1
- package/dist/audio_stream.js +6 -6
- package/dist/audio_stream.js.map +1 -1
- package/dist/e2ee.d.ts.map +1 -1
- package/dist/e2ee.js +16 -16
- package/dist/e2ee.js.map +1 -1
- package/dist/ffi_client.d.ts +4 -3
- package/dist/ffi_client.d.ts.map +1 -1
- package/dist/ffi_client.js +11 -11
- package/dist/ffi_client.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/napi/native.cjs +9 -2
- package/dist/napi/native.d.ts +1 -0
- package/dist/napi/native.js +2 -2
- package/dist/participant.d.ts +5 -4
- package/dist/participant.d.ts.map +1 -1
- package/dist/participant.js +15 -15
- package/dist/participant.js.map +1 -1
- package/dist/room.d.ts +25 -22
- package/dist/room.d.ts.map +1 -1
- package/dist/room.js +58 -55
- package/dist/room.js.map +1 -1
- package/dist/track.d.ts +3 -3
- package/dist/track.d.ts.map +1 -1
- package/dist/track.js +5 -8
- package/dist/track.js.map +1 -1
- package/dist/track_publication.d.ts +3 -3
- package/dist/track_publication.d.ts.map +1 -1
- package/dist/track_publication.js +1 -1
- package/dist/track_publication.js.map +1 -1
- package/dist/video_frame.d.ts +2 -1
- package/dist/video_frame.d.ts.map +1 -1
- package/dist/video_frame.js +1 -1
- package/dist/video_frame.js.map +1 -1
- package/dist/video_source.d.ts +3 -2
- package/dist/video_source.d.ts.map +1 -1
- package/dist/video_source.js +3 -3
- package/dist/video_source.js.map +1 -1
- package/dist/video_stream.d.ts +3 -3
- package/dist/video_stream.d.ts.map +1 -1
- package/dist/video_stream.js +8 -8
- package/dist/video_stream.js.map +1 -1
- package/package.json +8 -8
- package/src/audio_frame.ts +5 -5
- package/src/audio_source.ts +13 -14
- package/src/audio_stream.ts +13 -17
- package/src/e2ee.ts +25 -24
- package/src/ffi_client.ts +15 -11
- package/src/index.ts +1 -3
- package/src/napi/native.cjs +9 -2
- package/src/napi/native.d.ts +1 -0
- package/src/napi/native.js +2 -2
- package/src/nodejs.rs +5 -0
- package/src/participant.ts +27 -29
- package/src/room.ts +94 -91
- package/src/track.ts +9 -11
- package/src/track_publication.ts +7 -7
- package/src/video_frame.ts +9 -16
- package/src/video_source.ts +10 -9
- package/src/video_stream.ts +17 -18
package/src/napi/native.cjs
CHANGED
|
@@ -271,10 +271,17 @@ if (!nativeBinding) {
|
|
|
271
271
|
throw new Error(`Failed to load native binding`);
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
-
const {
|
|
275
|
-
|
|
274
|
+
const {
|
|
275
|
+
livekitInitialize,
|
|
276
|
+
livekitDispose,
|
|
277
|
+
livekitFfiRequest,
|
|
278
|
+
livekitRetrievePtr,
|
|
279
|
+
livekitCopyBuffer,
|
|
280
|
+
FfiHandle,
|
|
281
|
+
} = nativeBinding;
|
|
276
282
|
|
|
277
283
|
module.exports.livekitInitialize = livekitInitialize;
|
|
284
|
+
module.exports.livekitDispose = livekitDispose;
|
|
278
285
|
module.exports.livekitFfiRequest = livekitFfiRequest;
|
|
279
286
|
module.exports.livekitRetrievePtr = livekitRetrievePtr;
|
|
280
287
|
module.exports.livekitCopyBuffer = livekitCopyBuffer;
|
package/src/napi/native.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
/* auto-generated by NAPI-RS */
|
|
5
5
|
|
|
6
6
|
export function livekitInitialize(callback: (data: Uint8Array) => void, captureLogs: boolean): void;
|
|
7
|
+
export function livekitDispose(): Promise<void>;
|
|
7
8
|
export function livekitFfiRequest(data: Uint8Array): Uint8Array;
|
|
8
9
|
export function livekitRetrievePtr(handle: Uint8Array): bigint;
|
|
9
10
|
export function livekitCopyBuffer(ptr: bigint, len: number): Uint8Array;
|
package/src/napi/native.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
|
|
5
4
|
// this file exists to smoothly translate the autogenerated CommonJS code
|
|
6
5
|
// to an ES module that plays better with TypeScript.
|
|
7
|
-
|
|
8
6
|
import native from './native.cjs';
|
|
7
|
+
|
|
9
8
|
export const {
|
|
10
9
|
livekitInitialize,
|
|
10
|
+
livekitDispose,
|
|
11
11
|
livekitCopyBuffer,
|
|
12
12
|
livekitRetrievePtr,
|
|
13
13
|
livekitFfiRequest,
|
package/src/nodejs.rs
CHANGED
|
@@ -36,6 +36,11 @@ fn livekit_initialize(cb: JsFunction, capture_logs: bool) {
|
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
#[napi]
|
|
40
|
+
async fn livekit_dispose() {
|
|
41
|
+
FFI_SERVER.dispose().await;
|
|
42
|
+
}
|
|
43
|
+
|
|
39
44
|
#[napi]
|
|
40
45
|
fn livekit_ffi_request(data: Uint8Array) -> Uint8Array {
|
|
41
46
|
let data = data.to_vec();
|
package/src/participant.ts
CHANGED
|
@@ -1,34 +1,32 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
DataPacketKind,
|
|
4
|
+
import { FfiClient, FfiHandle } from './ffi_client.js';
|
|
5
|
+
import type { OwnedParticipant, ParticipantInfo } from './proto/participant_pb.js';
|
|
6
|
+
import type {
|
|
9
7
|
PublishDataCallback,
|
|
10
|
-
PublishDataRequest,
|
|
11
8
|
PublishDataResponse,
|
|
12
9
|
PublishTrackCallback,
|
|
13
|
-
PublishTrackRequest,
|
|
14
10
|
PublishTrackResponse,
|
|
15
11
|
TrackPublishOptions,
|
|
16
12
|
UnpublishTrackCallback,
|
|
17
|
-
UnpublishTrackRequest,
|
|
18
13
|
UnpublishTrackResponse,
|
|
19
14
|
UpdateLocalMetadataCallback,
|
|
20
|
-
UpdateLocalMetadataRequest,
|
|
21
15
|
UpdateLocalMetadataResponse,
|
|
22
16
|
UpdateLocalNameCallback,
|
|
23
|
-
UpdateLocalNameRequest,
|
|
24
17
|
UpdateLocalNameResponse,
|
|
25
18
|
} from './proto/room_pb.js';
|
|
26
19
|
import {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
DataPacketKind,
|
|
21
|
+
PublishDataRequest,
|
|
22
|
+
PublishTrackRequest,
|
|
23
|
+
UnpublishTrackRequest,
|
|
24
|
+
UpdateLocalMetadataRequest,
|
|
25
|
+
UpdateLocalNameRequest,
|
|
26
|
+
} from './proto/room_pb.js';
|
|
27
|
+
import type { LocalTrack } from './track.js';
|
|
28
|
+
import type { RemoteTrackPublication, TrackPublication } from './track_publication.js';
|
|
29
|
+
import { LocalTrackPublication } from './track_publication.js';
|
|
32
30
|
|
|
33
31
|
export abstract class Participant {
|
|
34
32
|
/** @internal */
|
|
@@ -81,7 +79,7 @@ export class LocalParticipant extends Participant {
|
|
|
81
79
|
trackPublications: Map<string, LocalTrackPublication> = new Map();
|
|
82
80
|
|
|
83
81
|
async publishData(data: Uint8Array, options: DataPublishOptions) {
|
|
84
|
-
|
|
82
|
+
const req = new PublishDataRequest({
|
|
85
83
|
localParticipantHandle: this.ffi_handle.handle,
|
|
86
84
|
dataPtr: FfiClient.instance.retrievePtr(data),
|
|
87
85
|
dataLen: BigInt(data.byteLength),
|
|
@@ -97,11 +95,11 @@ export class LocalParticipant extends Participant {
|
|
|
97
95
|
req.destinationSids = sids;
|
|
98
96
|
}
|
|
99
97
|
|
|
100
|
-
|
|
98
|
+
const res = FfiClient.instance.request<PublishDataResponse>({
|
|
101
99
|
message: { case: 'publishData', value: req },
|
|
102
100
|
});
|
|
103
101
|
|
|
104
|
-
|
|
102
|
+
const cb = await FfiClient.instance.waitFor<PublishDataCallback>((ev) => {
|
|
105
103
|
return ev.message.case == 'publishData' && ev.message.value.asyncId == res.asyncId;
|
|
106
104
|
});
|
|
107
105
|
|
|
@@ -111,12 +109,12 @@ export class LocalParticipant extends Participant {
|
|
|
111
109
|
}
|
|
112
110
|
|
|
113
111
|
async updateMetadata(metadata: string) {
|
|
114
|
-
|
|
112
|
+
const req = new UpdateLocalMetadataRequest({
|
|
115
113
|
localParticipantHandle: this.ffi_handle.handle,
|
|
116
114
|
metadata: metadata,
|
|
117
115
|
});
|
|
118
116
|
|
|
119
|
-
|
|
117
|
+
const res = FfiClient.instance.request<UpdateLocalMetadataResponse>({
|
|
120
118
|
message: { case: 'updateLocalMetadata', value: req },
|
|
121
119
|
});
|
|
122
120
|
|
|
@@ -126,12 +124,12 @@ export class LocalParticipant extends Participant {
|
|
|
126
124
|
}
|
|
127
125
|
|
|
128
126
|
async updateName(name: string) {
|
|
129
|
-
|
|
127
|
+
const req = new UpdateLocalNameRequest({
|
|
130
128
|
localParticipantHandle: this.ffi_handle.handle,
|
|
131
129
|
name: name,
|
|
132
130
|
});
|
|
133
131
|
|
|
134
|
-
|
|
132
|
+
const res = FfiClient.instance.request<UpdateLocalNameResponse>({
|
|
135
133
|
message: { case: 'updateLocalName', value: req },
|
|
136
134
|
});
|
|
137
135
|
|
|
@@ -144,21 +142,21 @@ export class LocalParticipant extends Participant {
|
|
|
144
142
|
track: LocalTrack,
|
|
145
143
|
options: TrackPublishOptions,
|
|
146
144
|
): Promise<LocalTrackPublication> {
|
|
147
|
-
|
|
145
|
+
const req = new PublishTrackRequest({
|
|
148
146
|
localParticipantHandle: this.ffi_handle.handle,
|
|
149
147
|
trackHandle: track.ffi_handle.handle,
|
|
150
148
|
options: options,
|
|
151
149
|
});
|
|
152
150
|
|
|
153
|
-
|
|
151
|
+
const res = FfiClient.instance.request<PublishTrackResponse>({
|
|
154
152
|
message: { case: 'publishTrack', value: req },
|
|
155
153
|
});
|
|
156
154
|
|
|
157
|
-
|
|
155
|
+
const cb = await FfiClient.instance.waitFor<PublishTrackCallback>((ev) => {
|
|
158
156
|
return ev.message.case == 'publishTrack' && ev.message.value.asyncId == res.asyncId;
|
|
159
157
|
});
|
|
160
158
|
|
|
161
|
-
|
|
159
|
+
const track_publication = new LocalTrackPublication(cb.publication);
|
|
162
160
|
track_publication.track = track;
|
|
163
161
|
this.trackPublications.set(track_publication.sid, track_publication);
|
|
164
162
|
|
|
@@ -166,12 +164,12 @@ export class LocalParticipant extends Participant {
|
|
|
166
164
|
}
|
|
167
165
|
|
|
168
166
|
async unpublishTrack(trackSid: string) {
|
|
169
|
-
|
|
167
|
+
const req = new UnpublishTrackRequest({
|
|
170
168
|
localParticipantHandle: this.ffi_handle.handle,
|
|
171
169
|
trackSid: trackSid,
|
|
172
170
|
});
|
|
173
171
|
|
|
174
|
-
|
|
172
|
+
const res = FfiClient.instance.request<UnpublishTrackResponse>({
|
|
175
173
|
message: { case: 'unpublishTrack', value: req },
|
|
176
174
|
});
|
|
177
175
|
|
|
@@ -179,7 +177,7 @@ export class LocalParticipant extends Participant {
|
|
|
179
177
|
return ev.message.case == 'unpublishTrack' && ev.message.value.asyncId == res.asyncId;
|
|
180
178
|
});
|
|
181
179
|
|
|
182
|
-
|
|
180
|
+
const pub = this.trackPublications.get(trackSid);
|
|
183
181
|
pub.track = undefined;
|
|
184
182
|
this.trackPublications.delete(trackSid);
|
|
185
183
|
}
|
package/src/room.ts
CHANGED
|
@@ -1,35 +1,36 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
|
|
5
|
-
import { FfiClient, FfiClientEvent, FfiHandle } from './ffi_client.js';
|
|
6
4
|
import EventEmitter from 'events';
|
|
7
|
-
import TypedEmitter from 'typed-emitter';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
5
|
+
import type TypedEmitter from 'typed-emitter';
|
|
6
|
+
import type { E2EEOptions } from './e2ee.js';
|
|
7
|
+
import { E2EEManager } from './e2ee.js';
|
|
8
|
+
import { FfiClient, FfiClientEvent, FfiHandle } from './ffi_client.js';
|
|
9
|
+
import type { Participant } from './participant.js';
|
|
10
|
+
import { LocalParticipant, RemoteParticipant } from './participant.js';
|
|
11
|
+
import { EncryptionState } from './proto/e2ee_pb.js';
|
|
12
|
+
import type { FfiEvent } from './proto/ffi_pb.js';
|
|
13
|
+
import type { OwnedParticipant } from './proto/participant_pb.js';
|
|
14
|
+
import type {
|
|
11
15
|
ConnectCallback,
|
|
12
|
-
ConnectRequest,
|
|
13
16
|
ConnectResponse,
|
|
14
17
|
ConnectionQuality,
|
|
15
|
-
ConnectionState,
|
|
16
|
-
ContinualGatheringPolicy,
|
|
17
18
|
DataPacketKind,
|
|
18
19
|
DisconnectResponse,
|
|
19
20
|
IceServer,
|
|
20
|
-
IceTransportType,
|
|
21
21
|
RoomInfo,
|
|
22
22
|
} from './proto/room_pb.js';
|
|
23
|
-
import { E2EEManager, E2EEOptions, defaultE2EEOptions } from './e2ee.js';
|
|
24
|
-
import { OwnedParticipant } from './proto/participant_pb.js';
|
|
25
23
|
import {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
ConnectRequest,
|
|
25
|
+
ConnectionState,
|
|
26
|
+
ContinualGatheringPolicy,
|
|
27
|
+
IceTransportType,
|
|
28
|
+
} from './proto/room_pb.js';
|
|
31
29
|
import { TrackKind } from './proto/track_pb.js';
|
|
32
|
-
import {
|
|
30
|
+
import type { RemoteTrack } from './track.js';
|
|
31
|
+
import { RemoteAudioTrack, RemoteVideoTrack } from './track.js';
|
|
32
|
+
import type { LocalTrackPublication, TrackPublication } from './track_publication.js';
|
|
33
|
+
import { RemoteTrackPublication } from './track_publication.js';
|
|
33
34
|
|
|
34
35
|
export interface RtcConfiguration {
|
|
35
36
|
iceTransportType: IceTransportType;
|
|
@@ -90,7 +91,7 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
90
91
|
async connect(url: string, token: string, opts?: RoomOptions) {
|
|
91
92
|
const options = { ...defaultRoomOptions, ...opts };
|
|
92
93
|
|
|
93
|
-
|
|
94
|
+
const req = new ConnectRequest({
|
|
94
95
|
url: url,
|
|
95
96
|
token: token,
|
|
96
97
|
options: {
|
|
@@ -108,14 +109,14 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
108
109
|
},
|
|
109
110
|
});
|
|
110
111
|
|
|
111
|
-
|
|
112
|
+
const res = FfiClient.instance.request<ConnectResponse>({
|
|
112
113
|
message: {
|
|
113
114
|
case: 'connect',
|
|
114
115
|
value: req,
|
|
115
116
|
},
|
|
116
117
|
});
|
|
117
118
|
|
|
118
|
-
|
|
119
|
+
const cb = await FfiClient.instance.waitFor<ConnectCallback>((ev: FfiEvent) => {
|
|
119
120
|
return ev.message.case == 'connect' && ev.message.value.asyncId == res.asyncId;
|
|
120
121
|
});
|
|
121
122
|
|
|
@@ -130,11 +131,11 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
130
131
|
this.connectionState = ConnectionState.CONN_CONNECTED;
|
|
131
132
|
this.localParticipant = new LocalParticipant(cb.localParticipant);
|
|
132
133
|
|
|
133
|
-
for (
|
|
134
|
-
|
|
134
|
+
for (const pt of cb.participants) {
|
|
135
|
+
const rp = this.createRemoteParticipant(pt.participant);
|
|
135
136
|
|
|
136
|
-
for (
|
|
137
|
-
|
|
137
|
+
for (const pub of pt.publications) {
|
|
138
|
+
const publication = new RemoteTrackPublication(pub);
|
|
138
139
|
rp.trackPublications.set(publication.sid, publication);
|
|
139
140
|
}
|
|
140
141
|
}
|
|
@@ -155,6 +156,10 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
155
156
|
},
|
|
156
157
|
},
|
|
157
158
|
});
|
|
159
|
+
|
|
160
|
+
FfiClient.instance.removeAllListeners();
|
|
161
|
+
await FfiClient.instance.dispose();
|
|
162
|
+
this.removeAllListeners();
|
|
158
163
|
}
|
|
159
164
|
|
|
160
165
|
private onFfiEvent = (ffiEvent: FfiEvent) => {
|
|
@@ -165,36 +170,36 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
165
170
|
return;
|
|
166
171
|
}
|
|
167
172
|
|
|
168
|
-
|
|
173
|
+
const ev = ffiEvent.message.value.message;
|
|
169
174
|
if (ev.case == 'participantConnected') {
|
|
170
|
-
|
|
175
|
+
const participant = this.createRemoteParticipant(ev.value.info);
|
|
171
176
|
this.remoteParticipants.set(participant.identity, participant);
|
|
172
177
|
this.emit(RoomEvent.ParticipantConnected, participant);
|
|
173
178
|
} else if (ev.case == 'participantDisconnected') {
|
|
174
|
-
|
|
179
|
+
const participant = this.getRemoteParticipantBySid(ev.value.participantSid);
|
|
175
180
|
this.remoteParticipants.delete(participant.identity);
|
|
176
181
|
this.emit(RoomEvent.ParticipantDisconnected, participant);
|
|
177
182
|
} else if (ev.case == 'localTrackPublished') {
|
|
178
|
-
|
|
179
|
-
this.emit(RoomEvent.LocalTrackPublished, publication,
|
|
183
|
+
const publication = this.localParticipant.trackPublications.get(ev.value.trackSid);
|
|
184
|
+
this.emit(RoomEvent.LocalTrackPublished, publication, this.localParticipant);
|
|
180
185
|
} else if (ev.case == 'localTrackUnpublished') {
|
|
181
|
-
|
|
186
|
+
const publication = this.localParticipant.trackPublications.get(ev.value.publicationSid);
|
|
182
187
|
this.localParticipant.trackPublications.delete(ev.value.publicationSid);
|
|
183
|
-
this.emit(RoomEvent.LocalTrackUnpublished, publication);
|
|
188
|
+
this.emit(RoomEvent.LocalTrackUnpublished, publication, this.localParticipant);
|
|
184
189
|
} else if (ev.case == 'trackPublished') {
|
|
185
|
-
|
|
186
|
-
|
|
190
|
+
const participant = this.getRemoteParticipantBySid(ev.value.participantSid);
|
|
191
|
+
const publication = new RemoteTrackPublication(ev.value.publication);
|
|
187
192
|
participant.trackPublications.set(publication.sid, publication);
|
|
188
193
|
this.emit(RoomEvent.TrackPublished, publication, participant);
|
|
189
194
|
} else if (ev.case == 'trackUnpublished') {
|
|
190
|
-
|
|
191
|
-
|
|
195
|
+
const participant = this.getRemoteParticipantBySid(ev.value.participantSid);
|
|
196
|
+
const publication = participant.trackPublications.get(ev.value.publicationSid);
|
|
192
197
|
participant.trackPublications.delete(ev.value.publicationSid);
|
|
193
198
|
this.emit(RoomEvent.TrackUnpublished, publication, participant);
|
|
194
199
|
} else if (ev.case == 'trackSubscribed') {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
200
|
+
const ownedTrack = ev.value.track;
|
|
201
|
+
const participant = this.getRemoteParticipantBySid(ev.value.participantSid);
|
|
202
|
+
const publication = participant.trackPublications.get(ownedTrack.info.sid);
|
|
198
203
|
publication.subscribed = true;
|
|
199
204
|
if (ownedTrack.info.kind == TrackKind.KIND_VIDEO) {
|
|
200
205
|
publication.track = new RemoteVideoTrack(ownedTrack);
|
|
@@ -204,70 +209,64 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
204
209
|
|
|
205
210
|
this.emit(RoomEvent.TrackSubscribed, publication.track, publication, participant);
|
|
206
211
|
} else if (ev.case == 'trackUnsubscribed') {
|
|
207
|
-
|
|
208
|
-
|
|
212
|
+
const participant = this.getRemoteParticipantBySid(ev.value.participantSid);
|
|
213
|
+
const publication = participant.trackPublications.get(ev.value.trackSid);
|
|
209
214
|
publication.track = undefined;
|
|
210
215
|
publication.subscribed = false;
|
|
211
216
|
this.emit(RoomEvent.TrackUnsubscribed, publication.track, publication, participant);
|
|
212
217
|
} else if (ev.case == 'trackSubscriptionFailed') {
|
|
213
|
-
|
|
214
|
-
this.emit(RoomEvent.TrackSubscriptionFailed,
|
|
218
|
+
const participant = this.getRemoteParticipantBySid(ev.value.participantSid);
|
|
219
|
+
this.emit(RoomEvent.TrackSubscriptionFailed, ev.value.trackSid, participant, ev.value.error);
|
|
215
220
|
} else if (ev.case == 'trackMuted') {
|
|
216
|
-
|
|
217
|
-
|
|
221
|
+
const participant = this.retrieveParticipant(ev.value.participantSid);
|
|
222
|
+
const publication = participant.trackPublications.get(ev.value.trackSid);
|
|
218
223
|
publication.info.muted = true;
|
|
219
224
|
if (publication.track) {
|
|
220
225
|
publication.track.info.muted = true;
|
|
221
226
|
}
|
|
222
|
-
this.emit(RoomEvent.TrackMuted,
|
|
227
|
+
this.emit(RoomEvent.TrackMuted, publication, participant);
|
|
223
228
|
} else if (ev.case == 'trackUnmuted') {
|
|
224
|
-
|
|
225
|
-
|
|
229
|
+
const participant = this.retrieveParticipant(ev.value.participantSid);
|
|
230
|
+
const publication = participant.trackPublications.get(ev.value.trackSid);
|
|
226
231
|
publication.info.muted = false;
|
|
227
232
|
if (publication.track) {
|
|
228
233
|
publication.track.info.muted = false;
|
|
229
234
|
}
|
|
230
|
-
this.emit(RoomEvent.TrackUnmuted,
|
|
235
|
+
this.emit(RoomEvent.TrackUnmuted, publication, participant);
|
|
231
236
|
} else if (ev.case == 'activeSpeakersChanged') {
|
|
232
|
-
|
|
237
|
+
const activeSpeakers = ev.value.participantSids.map((sid) =>
|
|
233
238
|
this.getRemoteParticipantBySid(sid),
|
|
234
239
|
);
|
|
235
240
|
this.emit(RoomEvent.ActiveSpeakersChanged, activeSpeakers);
|
|
236
241
|
} else if (ev.case == 'roomMetadataChanged') {
|
|
237
|
-
let oldMetadata = this.info.metadata;
|
|
238
242
|
this.info.metadata = ev.value.metadata;
|
|
239
|
-
this.emit(RoomEvent.RoomMetadataChanged,
|
|
243
|
+
this.emit(RoomEvent.RoomMetadataChanged, this.info.metadata);
|
|
240
244
|
} else if (ev.case == 'participantMetadataChanged') {
|
|
241
|
-
|
|
242
|
-
let oldMetadata = participant.metadata;
|
|
245
|
+
const participant = this.retrieveParticipant(ev.value.participantSid);
|
|
243
246
|
participant.info.metadata = ev.value.metadata;
|
|
244
|
-
this.emit(
|
|
245
|
-
RoomEvent.ParticipantMetadataChanged,
|
|
246
|
-
participant,
|
|
247
|
-
oldMetadata,
|
|
248
|
-
participant.metadata,
|
|
249
|
-
);
|
|
247
|
+
this.emit(RoomEvent.ParticipantMetadataChanged, participant.metadata, participant);
|
|
250
248
|
} else if (ev.case == 'participantNameChanged') {
|
|
251
|
-
|
|
252
|
-
let oldName = participant.name;
|
|
249
|
+
const participant = this.retrieveParticipant(ev.value.participantSid);
|
|
253
250
|
participant.info.name = ev.value.name;
|
|
254
|
-
this.emit(RoomEvent.ParticipantNameChanged, participant,
|
|
251
|
+
this.emit(RoomEvent.ParticipantNameChanged, participant.name, participant);
|
|
255
252
|
} else if (ev.case == 'connectionQualityChanged') {
|
|
256
|
-
|
|
257
|
-
this.emit(RoomEvent.ConnectionQualityChanged,
|
|
253
|
+
const participant = this.retrieveParticipant(ev.value.participantSid);
|
|
254
|
+
this.emit(RoomEvent.ConnectionQualityChanged, ev.value.quality, participant);
|
|
258
255
|
} else if (ev.case == 'dataReceived') {
|
|
259
256
|
// Can be undefined if the data is sent from a Server SDK
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
257
|
+
const participant = this.getRemoteParticipantBySid(ev.value.participantSid);
|
|
258
|
+
const info = ev.value.data;
|
|
259
|
+
const buffer = FfiClient.instance.copyBuffer(info.data.dataPtr, Number(info.data.dataLen));
|
|
263
260
|
new FfiHandle(info.handle.id).dispose();
|
|
264
|
-
this.emit(RoomEvent.DataReceived, buffer, ev.value.kind,
|
|
261
|
+
this.emit(RoomEvent.DataReceived, buffer, participant, ev.value.kind, ev.value.topic);
|
|
265
262
|
} else if (ev.case == 'e2eeStateChanged') {
|
|
266
|
-
|
|
267
|
-
|
|
263
|
+
if (ev.value.state == EncryptionState.INTERNAL_ERROR) {
|
|
264
|
+
// throw generic error until Rust SDK is updated to supply the error alongside INTERNAL_ERROR
|
|
265
|
+
this.emit(RoomEvent.EncryptionError, new Error('internal server error'));
|
|
266
|
+
}
|
|
268
267
|
} else if (ev.case == 'connectionStateChanged') {
|
|
269
268
|
this.connectionState = ev.value.state;
|
|
270
|
-
this.emit(RoomEvent.
|
|
269
|
+
this.emit(RoomEvent.ConnectionStateChanged, this.connectionState);
|
|
271
270
|
/*} else if (ev.case == 'connected') {
|
|
272
271
|
this.emit(RoomEvent.Connected);*/
|
|
273
272
|
} else if (ev.case == 'disconnected') {
|
|
@@ -311,8 +310,11 @@ export class ConnectError extends Error {
|
|
|
311
310
|
export type RoomCallbacks = {
|
|
312
311
|
participantConnected: (participant: RemoteParticipant) => void;
|
|
313
312
|
participantDisconnected: (participant: RemoteParticipant) => void;
|
|
314
|
-
localTrackPublished: (publication: LocalTrackPublication,
|
|
315
|
-
localTrackUnpublished: (
|
|
313
|
+
localTrackPublished: (publication: LocalTrackPublication, participant: LocalParticipant) => void;
|
|
314
|
+
localTrackUnpublished: (
|
|
315
|
+
publication: LocalTrackPublication,
|
|
316
|
+
participant: LocalParticipant,
|
|
317
|
+
) => void;
|
|
316
318
|
trackPublished: (publication: RemoteTrackPublication, participant: RemoteParticipant) => void;
|
|
317
319
|
trackUnpublished: (publication: RemoteTrackPublication, participant: RemoteParticipant) => void;
|
|
318
320
|
trackSubscribed: (
|
|
@@ -326,26 +328,27 @@ export type RoomCallbacks = {
|
|
|
326
328
|
participant: RemoteParticipant,
|
|
327
329
|
) => void;
|
|
328
330
|
trackSubscriptionFailed: (
|
|
331
|
+
trackSid: string,
|
|
329
332
|
participant: RemoteParticipant,
|
|
330
|
-
|
|
331
|
-
error: string,
|
|
333
|
+
reason?: string,
|
|
332
334
|
) => void;
|
|
333
|
-
trackMuted: (
|
|
334
|
-
trackUnmuted: (
|
|
335
|
-
activeSpeakersChanged: (speakers:
|
|
336
|
-
roomMetadataChanged: (
|
|
337
|
-
participantMetadataChanged: (
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
335
|
+
trackMuted: (publication: TrackPublication, participant: Participant) => void;
|
|
336
|
+
trackUnmuted: (publication: TrackPublication, participant: Participant) => void;
|
|
337
|
+
activeSpeakersChanged: (speakers: Participant[]) => void;
|
|
338
|
+
roomMetadataChanged: (metadata: string) => void;
|
|
339
|
+
participantMetadataChanged: (metadata: string | undefined, participant: Participant) => void;
|
|
340
|
+
participantNameChanged: (name: string, participant: Participant) => void;
|
|
341
|
+
connectionQualityChanged: (quality: ConnectionQuality, participant: Participant) => void;
|
|
342
|
+
dataReceived: (
|
|
343
|
+
payload: Uint8Array,
|
|
344
|
+
participant?: RemoteParticipant,
|
|
345
|
+
kind?: DataPacketKind,
|
|
346
|
+
topic?: string,
|
|
341
347
|
) => void;
|
|
342
|
-
|
|
343
|
-
connectionQualityChanged: (participant: Participant, quality: ConnectionQuality) => void;
|
|
344
|
-
dataReceived: (data: Uint8Array, kind: DataPacketKind, participant?: RemoteParticipant) => void;
|
|
345
|
-
e2eeStateChanged: (participant: Participant, state: EncryptionState) => void;
|
|
348
|
+
encryptionError: (error: Error) => void;
|
|
346
349
|
connectionStateChanged: (state: ConnectionState) => void;
|
|
347
350
|
connected: () => void;
|
|
348
|
-
disconnected: () => void;
|
|
351
|
+
disconnected: (reason?: string) => void;
|
|
349
352
|
reconnecting: () => void;
|
|
350
353
|
reconnected: () => void;
|
|
351
354
|
};
|
|
@@ -368,8 +371,8 @@ export enum RoomEvent {
|
|
|
368
371
|
ParticipantNameChanged = 'participantNameChanged',
|
|
369
372
|
ConnectionQualityChanged = 'connectionQualityChanged',
|
|
370
373
|
DataReceived = 'dataReceived',
|
|
371
|
-
|
|
372
|
-
|
|
374
|
+
EncryptionError = 'encryptionError',
|
|
375
|
+
ConnectionStateChanged = 'connectionStateChanged',
|
|
373
376
|
Connected = 'connected',
|
|
374
377
|
Disconnected = 'disconnected',
|
|
375
378
|
Reconnecting = 'reconnecting',
|
package/src/track.ts
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
CreateAudioTrackRequest,
|
|
4
|
+
import type { AudioSource } from './audio_source.js';
|
|
5
|
+
import { FfiClient, FfiHandle } from './ffi_client.js';
|
|
6
|
+
import type {
|
|
9
7
|
CreateAudioTrackResponse,
|
|
10
|
-
CreateVideoTrackRequest,
|
|
11
8
|
CreateVideoTrackResponse,
|
|
12
9
|
OwnedTrack,
|
|
13
10
|
StreamState,
|
|
14
11
|
TrackInfo,
|
|
15
12
|
TrackKind,
|
|
16
13
|
} from './proto/track_pb.js';
|
|
17
|
-
import {
|
|
14
|
+
import { CreateAudioTrackRequest, CreateVideoTrackRequest } from './proto/track_pb.js';
|
|
15
|
+
import type { VideoSource } from './video_source.js';
|
|
18
16
|
|
|
19
17
|
export abstract class Track {
|
|
20
18
|
/** @internal */
|
|
@@ -55,12 +53,12 @@ export class LocalAudioTrack extends Track {
|
|
|
55
53
|
}
|
|
56
54
|
|
|
57
55
|
static createAudioTrack(name: string, source: AudioSource): LocalAudioTrack {
|
|
58
|
-
|
|
56
|
+
const req = new CreateAudioTrackRequest({
|
|
59
57
|
name: name,
|
|
60
58
|
sourceHandle: source.ffiHandle.handle,
|
|
61
59
|
});
|
|
62
60
|
|
|
63
|
-
|
|
61
|
+
const res = FfiClient.instance.request<CreateAudioTrackResponse>({
|
|
64
62
|
message: { case: 'createAudioTrack', value: req },
|
|
65
63
|
});
|
|
66
64
|
|
|
@@ -74,12 +72,12 @@ export class LocalVideoTrack extends Track {
|
|
|
74
72
|
}
|
|
75
73
|
|
|
76
74
|
static createVideoTrack(name: string, source: VideoSource): LocalVideoTrack {
|
|
77
|
-
|
|
75
|
+
const req = new CreateVideoTrackRequest({
|
|
78
76
|
name: name,
|
|
79
77
|
sourceHandle: source.ffiHandle.handle,
|
|
80
78
|
});
|
|
81
79
|
|
|
82
|
-
|
|
80
|
+
const res = FfiClient.instance.request<CreateVideoTrackResponse>({
|
|
83
81
|
message: { case: 'createVideoTrack', value: req },
|
|
84
82
|
});
|
|
85
83
|
|
package/src/track_publication.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
|
|
5
|
-
import { FfiClient, FfiRequest } from './ffi_client.js';
|
|
4
|
+
import { FfiClient } from './ffi_client.js';
|
|
6
5
|
import { FfiHandle } from './napi/native.js';
|
|
7
|
-
import { EncryptionType } from './proto/e2ee_pb.js';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
6
|
+
import type { EncryptionType } from './proto/e2ee_pb.js';
|
|
7
|
+
import type { SetSubscribedResponse } from './proto/room_pb.js';
|
|
8
|
+
import { SetSubscribedRequest } from './proto/room_pb.js';
|
|
9
|
+
import type {
|
|
10
10
|
OwnedTrackPublication,
|
|
11
11
|
TrackKind,
|
|
12
12
|
TrackPublicationInfo,
|
|
13
13
|
TrackSource,
|
|
14
14
|
} from './proto/track_pb.js';
|
|
15
|
-
import { Track } from './track.js';
|
|
15
|
+
import type { Track } from './track.js';
|
|
16
16
|
|
|
17
17
|
export abstract class TrackPublication {
|
|
18
18
|
/** @internal */
|
|
@@ -82,7 +82,7 @@ export class RemoteTrackPublication extends TrackPublication {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
setSubscribed(subscribed: boolean) {
|
|
85
|
-
|
|
85
|
+
const req = new SetSubscribedRequest({
|
|
86
86
|
subscribe: subscribed,
|
|
87
87
|
publicationHandle: this.ffiHandle.handle,
|
|
88
88
|
});
|