@livekit/rtc-node 0.12.1 → 0.13.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/dist/audio_frame.cjs +2 -2
- package/dist/audio_frame.cjs.map +1 -1
- package/dist/audio_frame.d.cts +31 -0
- package/dist/audio_frame.d.ts +11 -5
- 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_resampler.cjs +10 -7
- package/dist/audio_resampler.cjs.map +1 -1
- package/dist/audio_resampler.d.cts +59 -0
- package/dist/audio_resampler.d.ts +11 -3
- package/dist/audio_resampler.d.ts.map +1 -1
- package/dist/audio_resampler.js +13 -10
- package/dist/audio_resampler.js.map +1 -1
- package/dist/audio_source.cjs +6 -4
- package/dist/audio_source.cjs.map +1 -1
- package/dist/audio_source.d.cts +37 -0
- package/dist/audio_source.d.ts +13 -5
- package/dist/audio_source.d.ts.map +1 -1
- package/dist/audio_source.js +9 -7
- package/dist/audio_source.js.map +1 -1
- package/dist/audio_stream.cjs +1 -2
- package/dist/audio_stream.cjs.map +1 -1
- package/dist/audio_stream.d.cts +37 -0
- package/dist/audio_stream.d.ts +16 -5
- package/dist/audio_stream.d.ts.map +1 -1
- package/dist/audio_stream.js +2 -3
- package/dist/audio_stream.js.map +1 -1
- package/dist/e2ee.cjs +19 -20
- package/dist/e2ee.cjs.map +1 -1
- package/dist/e2ee.d.cts +47 -0
- package/dist/e2ee.d.ts +11 -8
- package/dist/e2ee.d.ts.map +1 -1
- package/dist/e2ee.js +29 -30
- package/dist/e2ee.js.map +1 -1
- package/dist/ffi_client.cjs +6 -5
- package/dist/ffi_client.cjs.map +1 -1
- package/dist/ffi_client.d.cts +35 -0
- package/dist/ffi_client.d.ts +23 -11
- package/dist/ffi_client.d.ts.map +1 -1
- package/dist/ffi_client.js +6 -10
- package/dist/ffi_client.js.map +1 -1
- package/dist/index.cjs +16 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +28 -0
- package/dist/index.d.ts +20 -41
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -46
- package/dist/index.js.map +1 -1
- package/dist/napi/native.d.cjs.map +1 -1
- package/dist/napi/native.d.d.cts +21 -0
- package/dist/napi/native.d.d.ts +21 -0
- package/dist/napi/native.d.ts +5 -5
- package/dist/native.d.ts +5 -5
- package/dist/participant.cjs +57 -34
- package/dist/participant.cjs.map +1 -1
- package/dist/participant.d.cts +126 -0
- package/dist/participant.d.ts +34 -20
- package/dist/participant.d.ts.map +1 -1
- package/dist/participant.js +75 -50
- package/dist/participant.js.map +1 -1
- package/dist/proto/audio_frame_pb.cjs +977 -125
- package/dist/proto/audio_frame_pb.cjs.map +1 -1
- package/dist/proto/audio_frame_pb.d.cts +898 -0
- package/dist/proto/audio_frame_pb.d.ts +506 -417
- package/dist/proto/audio_frame_pb.d.ts.map +1 -1
- package/dist/proto/audio_frame_pb.js +943 -85
- package/dist/proto/audio_frame_pb.js.map +1 -1
- package/dist/proto/e2ee_pb.cjs +700 -85
- package/dist/proto/e2ee_pb.cjs.map +1 -1
- package/dist/proto/e2ee_pb.d.cts +653 -0
- package/dist/proto/e2ee_pb.d.ts +333 -263
- package/dist/proto/e2ee_pb.d.ts.map +1 -1
- package/dist/proto/e2ee_pb.js +675 -57
- package/dist/proto/e2ee_pb.js.map +1 -1
- package/dist/proto/ffi_pb.cjs +369 -36
- package/dist/proto/ffi_pb.cjs.map +1 -1
- package/dist/proto/ffi_pb.d.cts +898 -0
- package/dist/proto/ffi_pb.d.ts +164 -112
- package/dist/proto/ffi_pb.d.ts.map +1 -1
- package/dist/proto/ffi_pb.js +364 -29
- package/dist/proto/ffi_pb.js.map +1 -1
- package/dist/proto/handle_pb.cjs +27 -7
- package/dist/proto/handle_pb.cjs.map +1 -1
- package/dist/proto/handle_pb.d.cts +31 -0
- package/dist/proto/handle_pb.d.ts +15 -15
- package/dist/proto/handle_pb.d.ts.map +1 -1
- package/dist/proto/handle_pb.js +26 -5
- package/dist/proto/handle_pb.js.map +1 -1
- package/dist/proto/participant_pb.cjs +112 -15
- package/dist/proto/participant_pb.cjs.map +1 -1
- package/dist/proto/participant_pb.d.cts +181 -0
- package/dist/proto/participant_pb.d.ts +143 -53
- package/dist/proto/participant_pb.d.ts.map +1 -1
- package/dist/proto/participant_pb.js +109 -11
- package/dist/proto/participant_pb.js.map +1 -1
- package/dist/proto/room_pb.cjs +2693 -302
- package/dist/proto/room_pb.cjs.map +1 -1
- package/dist/proto/room_pb.d.cts +2475 -0
- package/dist/proto/room_pb.d.ts +1269 -864
- package/dist/proto/room_pb.d.ts.map +1 -1
- package/dist/proto/room_pb.js +2603 -210
- package/dist/proto/room_pb.js.map +1 -1
- package/dist/proto/rpc_pb.cjs +302 -37
- package/dist/proto/rpc_pb.cjs.map +1 -1
- package/dist/proto/rpc_pb.d.cts +267 -0
- package/dist/proto/rpc_pb.d.ts +140 -108
- package/dist/proto/rpc_pb.d.ts.map +1 -1
- package/dist/proto/rpc_pb.js +291 -25
- package/dist/proto/rpc_pb.js.map +1 -1
- package/dist/proto/stats_pb.cjs +1253 -139
- package/dist/proto/stats_pb.cjs.map +1 -1
- package/dist/proto/stats_pb.d.cts +1764 -0
- package/dist/proto/stats_pb.d.ts +806 -693
- package/dist/proto/stats_pb.d.ts.map +1 -1
- package/dist/proto/stats_pb.js +1216 -93
- package/dist/proto/stats_pb.js.map +1 -1
- package/dist/proto/track_pb.cjs +462 -64
- package/dist/proto/track_pb.cjs.map +1 -1
- package/dist/proto/track_pb.d.cts +434 -0
- package/dist/proto/track_pb.d.ts +254 -220
- package/dist/proto/track_pb.d.ts.map +1 -1
- package/dist/proto/track_pb.js +447 -45
- package/dist/proto/track_pb.js.map +1 -1
- package/dist/proto/track_publication_pb.cjs +130 -0
- package/dist/proto/track_publication_pb.cjs.map +1 -0
- package/dist/proto/track_publication_pb.d.cts +80 -0
- package/dist/proto/track_publication_pb.d.ts +80 -0
- package/dist/proto/track_publication_pb.d.ts.map +1 -0
- package/dist/proto/track_publication_pb.js +103 -0
- package/dist/proto/track_publication_pb.js.map +1 -0
- package/dist/proto/video_frame_pb.cjs +648 -88
- package/dist/proto/video_frame_pb.cjs.map +1 -1
- package/dist/proto/video_frame_pb.d.cts +660 -0
- package/dist/proto/video_frame_pb.d.ts +375 -328
- package/dist/proto/video_frame_pb.d.ts.map +1 -1
- package/dist/proto/video_frame_pb.js +626 -60
- package/dist/proto/video_frame_pb.js.map +1 -1
- package/dist/room.cjs +93 -125
- package/dist/room.cjs.map +1 -1
- package/dist/room.d.cts +123 -0
- package/dist/room.d.ts +37 -34
- package/dist/room.d.ts.map +1 -1
- package/dist/room.js +92 -122
- package/dist/room.js.map +1 -1
- package/dist/rpc.cjs.map +1 -1
- package/dist/rpc.d.cts +81 -0
- package/dist/rpc.d.ts +10 -7
- package/dist/rpc.js.map +1 -1
- package/dist/track.cjs +12 -8
- package/dist/track.cjs.map +1 -1
- package/dist/track.d.cts +45 -0
- package/dist/track.d.ts +30 -20
- package/dist/track.d.ts.map +1 -1
- package/dist/track.js +13 -9
- package/dist/track.js.map +1 -1
- package/dist/track_publication.cjs +21 -12
- package/dist/track_publication.cjs.map +1 -1
- package/dist/track_publication.d.cts +47 -0
- package/dist/track_publication.d.ts +30 -19
- package/dist/track_publication.d.ts.map +1 -1
- package/dist/track_publication.js +22 -13
- package/dist/track_publication.js.map +1 -1
- package/dist/transcription.d.cts +15 -0
- package/dist/transcription.d.ts +4 -3
- package/dist/types.d.cts +9 -0
- package/dist/types.d.ts +3 -2
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.d.cts +3 -0
- package/dist/version.d.ts +3 -2
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/dist/video_frame.cjs +26 -45
- package/dist/video_frame.cjs.map +1 -1
- package/dist/video_frame.d.cts +24 -0
- package/dist/video_frame.d.ts +10 -4
- package/dist/video_frame.d.ts.map +1 -1
- package/dist/video_frame.js +29 -48
- package/dist/video_frame.js.map +1 -1
- package/dist/video_source.cjs +7 -4
- package/dist/video_source.cjs.map +1 -1
- package/dist/video_source.d.cts +22 -0
- package/dist/video_source.d.ts +14 -7
- package/dist/video_source.d.ts.map +1 -1
- package/dist/video_source.js +9 -6
- package/dist/video_source.js.map +1 -1
- package/dist/video_stream.cjs +16 -5
- package/dist/video_stream.cjs.map +1 -1
- package/dist/video_stream.d.cts +40 -0
- package/dist/video_stream.d.ts +18 -7
- package/dist/video_stream.d.ts.map +1 -1
- package/dist/video_stream.js +17 -6
- package/dist/video_stream.js.map +1 -1
- package/package.json +17 -12
- package/src/audio_frame.ts +10 -10
- package/src/audio_resampler.ts +15 -13
- package/src/audio_source.ts +11 -8
- package/src/audio_stream.ts +3 -4
- package/src/e2ee.ts +36 -37
- package/src/ffi_client.ts +8 -16
- package/src/index.ts +5 -68
- package/src/napi/native.d.ts +5 -5
- package/src/participant.ts +100 -72
- package/src/proto/audio_frame_pb.ts +1220 -496
- package/src/proto/e2ee_pb.ts +858 -337
- package/src/proto/ffi_pb.ts +442 -135
- package/src/proto/handle_pb.ts +33 -19
- package/src/proto/participant_pb.ts +225 -60
- package/src/proto/room_pb.ts +3149 -1013
- package/src/proto/rpc_pb.ts +358 -129
- package/src/proto/stats_pb.ts +1891 -877
- package/src/proto/track_pb.ts +587 -253
- package/src/proto/track_publication_pb.ts +180 -0
- package/src/proto/video_frame_pb.ts +861 -394
- package/src/room.ts +143 -188
- package/src/rpc.ts +1 -1
- package/src/track.ts +16 -17
- package/src/track_publication.ts +25 -26
- package/src/version.ts +1 -1
- package/src/video_frame.ts +48 -72
- package/src/video_source.ts +11 -8
- package/src/video_stream.ts +18 -8
package/src/room.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
import { create } from '@bufbuild/protobuf';
|
|
5
4
|
import type { TypedEventEmitter as TypedEmitter } from '@livekit/typed-emitter';
|
|
6
5
|
import EventEmitter from 'events';
|
|
7
6
|
import type { E2EEOptions } from './e2ee.js';
|
|
@@ -11,20 +10,19 @@ import type { Participant } from './participant.js';
|
|
|
11
10
|
import { LocalParticipant, RemoteParticipant } from './participant.js';
|
|
12
11
|
import { EncryptionState } from './proto/e2ee_pb.js';
|
|
13
12
|
import type { FfiEvent } from './proto/ffi_pb.js';
|
|
14
|
-
import type { OwnedParticipant } from './proto/participant_pb.js';
|
|
15
|
-
import
|
|
16
|
-
ConnectCallback,
|
|
17
|
-
ConnectResponse,
|
|
18
|
-
ConnectionQuality,
|
|
19
|
-
DataPacketKind,
|
|
20
|
-
|
|
21
|
-
DisconnectResponse,
|
|
13
|
+
import type { DisconnectReason, OwnedParticipant } from './proto/participant_pb.js';
|
|
14
|
+
import {
|
|
15
|
+
type ConnectCallback,
|
|
16
|
+
type ConnectResponse,
|
|
17
|
+
type ConnectionQuality,
|
|
18
|
+
type DataPacketKind,
|
|
19
|
+
type DisconnectResponse,
|
|
22
20
|
RoomOptions as FfiRoomOptions,
|
|
23
|
-
IceServer,
|
|
24
|
-
RoomInfo,
|
|
21
|
+
type IceServer,
|
|
22
|
+
type RoomInfo,
|
|
25
23
|
} from './proto/room_pb.js';
|
|
26
24
|
import {
|
|
27
|
-
|
|
25
|
+
ConnectRequest,
|
|
28
26
|
ConnectionState,
|
|
29
27
|
ContinualGatheringPolicy,
|
|
30
28
|
IceTransportType,
|
|
@@ -55,14 +53,14 @@ export interface RoomOptions {
|
|
|
55
53
|
rtcConfig?: RtcConfiguration;
|
|
56
54
|
}
|
|
57
55
|
|
|
58
|
-
export const defaultRoomOptions = {
|
|
56
|
+
export const defaultRoomOptions = new FfiRoomOptions({
|
|
59
57
|
autoSubscribe: true,
|
|
60
58
|
dynacast: false,
|
|
61
59
|
e2ee: undefined,
|
|
62
60
|
rtcConfig: undefined,
|
|
63
61
|
adaptiveStream: false,
|
|
64
62
|
joinRetries: 1,
|
|
65
|
-
}
|
|
63
|
+
});
|
|
66
64
|
|
|
67
65
|
export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>) {
|
|
68
66
|
private info?: RoomInfo;
|
|
@@ -90,32 +88,14 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
90
88
|
return this.ffiHandle != undefined && this.connectionState != ConnectionState.CONN_DISCONNECTED;
|
|
91
89
|
}
|
|
92
90
|
|
|
93
|
-
async getSid(): Promise<string> {
|
|
94
|
-
|
|
95
|
-
return '';
|
|
96
|
-
}
|
|
97
|
-
if (this.info && this.info.sid !== '') {
|
|
98
|
-
return this.info.sid;
|
|
99
|
-
}
|
|
100
|
-
return new Promise((resolve, reject) => {
|
|
101
|
-
const handleRoomUpdate = (sid: string) => {
|
|
102
|
-
if (sid !== '') {
|
|
103
|
-
this.off(RoomEvent.RoomSidChanged, handleRoomUpdate);
|
|
104
|
-
resolve(sid);
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
this.on(RoomEvent.RoomSidChanged, handleRoomUpdate);
|
|
108
|
-
this.once(RoomEvent.Disconnected, () => {
|
|
109
|
-
this.off(RoomEvent.RoomSidChanged, handleRoomUpdate);
|
|
110
|
-
reject('Room disconnected before room server id was available');
|
|
111
|
-
});
|
|
112
|
-
});
|
|
91
|
+
async getSid(): Promise<string | undefined> {
|
|
92
|
+
return this.info?.sid; // TODO update this to handle async room updates once rust protocol has been updated
|
|
113
93
|
}
|
|
114
94
|
|
|
115
95
|
async connect(url: string, token: string, opts?: RoomOptions) {
|
|
116
96
|
const options = { ...defaultRoomOptions, ...opts };
|
|
117
97
|
|
|
118
|
-
const req =
|
|
98
|
+
const req = new ConnectRequest({
|
|
119
99
|
url: url,
|
|
120
100
|
token: token,
|
|
121
101
|
options,
|
|
@@ -132,35 +112,42 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
132
112
|
return ev.message.case == 'connect' && ev.message.value.asyncId == res.asyncId;
|
|
133
113
|
});
|
|
134
114
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
115
|
+
switch (cb.message.case) {
|
|
116
|
+
case 'result':
|
|
117
|
+
this.ffiHandle = new FfiHandle(cb.message.value.room!.handle!.id!);
|
|
118
|
+
this.e2eeManager = new E2EEManager(this.ffiHandle.handle, {
|
|
119
|
+
keyProviderOptions: {
|
|
120
|
+
sharedKey: options.e2ee?.keyProviderOptions?.sharedKey,
|
|
121
|
+
ratchetSalt: options.e2ee!.keyProviderOptions!.ratchetSalt!,
|
|
122
|
+
ratchetWindowSize: options.e2ee!.keyProviderOptions!.ratchetWindowSize!,
|
|
123
|
+
failureTolerance: options.e2ee!.keyProviderOptions!.failureTolerance!,
|
|
124
|
+
},
|
|
125
|
+
encryptionType: options.e2ee!.encryptionType!,
|
|
126
|
+
});
|
|
140
127
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
128
|
+
this.info = cb.message.value.room!.info;
|
|
129
|
+
this.connectionState = ConnectionState.CONN_CONNECTED;
|
|
130
|
+
this.localParticipant = new LocalParticipant(cb.message.value.localParticipant!);
|
|
145
131
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
this.localParticipant = new LocalParticipant(localParticipant!);
|
|
132
|
+
for (const pt of cb.message.value.participants) {
|
|
133
|
+
const rp = this.createRemoteParticipant(pt.participant!);
|
|
149
134
|
|
|
150
|
-
|
|
151
|
-
|
|
135
|
+
for (const pub of pt.publications) {
|
|
136
|
+
const publication = new RemoteTrackPublication(pub);
|
|
137
|
+
rp.trackPublications.set(publication.sid!, publication);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
152
140
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
141
|
+
FfiClient.instance.on(FfiClientEvent.FfiEvent, this.onFfiEvent);
|
|
142
|
+
break;
|
|
143
|
+
case 'error':
|
|
144
|
+
default:
|
|
145
|
+
throw new ConnectError(cb.message.value || '');
|
|
157
146
|
}
|
|
158
|
-
|
|
159
|
-
FfiClient.instance.on(FfiClientEvent.FfiEvent, this.onFfiEvent);
|
|
160
147
|
}
|
|
161
148
|
|
|
162
149
|
async disconnect() {
|
|
163
|
-
if (!this.isConnected
|
|
150
|
+
if (!this.isConnected) {
|
|
164
151
|
return;
|
|
165
152
|
}
|
|
166
153
|
|
|
@@ -168,7 +155,7 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
168
155
|
message: {
|
|
169
156
|
case: 'disconnect',
|
|
170
157
|
value: {
|
|
171
|
-
roomHandle: this.ffiHandle
|
|
158
|
+
roomHandle: this.ffiHandle?.handle,
|
|
172
159
|
},
|
|
173
160
|
},
|
|
174
161
|
});
|
|
@@ -178,27 +165,9 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
178
165
|
}
|
|
179
166
|
|
|
180
167
|
private onFfiEvent = (ffiEvent: FfiEvent) => {
|
|
181
|
-
if (
|
|
182
|
-
throw TypeError('cannot handle ffi events before connectCallback');
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (ffiEvent.message.case == 'rpcMethodInvocation') {
|
|
186
|
-
if (
|
|
187
|
-
ffiEvent.message.value.localParticipantHandle == this.localParticipant.ffi_handle.handle
|
|
188
|
-
) {
|
|
189
|
-
this.localParticipant.handleRpcMethodInvocation(
|
|
190
|
-
ffiEvent.message.value.invocationId,
|
|
191
|
-
ffiEvent.message.value.method,
|
|
192
|
-
ffiEvent.message.value.requestId,
|
|
193
|
-
ffiEvent.message.value.callerIdentity,
|
|
194
|
-
ffiEvent.message.value.payload,
|
|
195
|
-
ffiEvent.message.value.responseTimeoutMs,
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
return;
|
|
199
|
-
} else if (
|
|
168
|
+
if (
|
|
200
169
|
ffiEvent.message.case != 'roomEvent' ||
|
|
201
|
-
ffiEvent.message.value.roomHandle != this.ffiHandle
|
|
170
|
+
ffiEvent.message.value.roomHandle != this.ffiHandle?.handle
|
|
202
171
|
) {
|
|
203
172
|
return;
|
|
204
173
|
}
|
|
@@ -206,136 +175,125 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
206
175
|
const ev = ffiEvent.message.value.message;
|
|
207
176
|
if (ev.case == 'participantConnected') {
|
|
208
177
|
const participant = this.createRemoteParticipant(ev.value.info!);
|
|
209
|
-
this.remoteParticipants.set(participant.identity
|
|
178
|
+
this.remoteParticipants.set(participant.identity!, participant);
|
|
210
179
|
this.emit(RoomEvent.ParticipantConnected, participant);
|
|
211
180
|
} else if (ev.case == 'participantDisconnected') {
|
|
212
|
-
const participant = this.remoteParticipants.get(ev.value.participantIdentity);
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
this.emit(RoomEvent.ParticipantDisconnected, participant);
|
|
216
|
-
}
|
|
181
|
+
const participant = this.remoteParticipants.get(ev.value.participantIdentity!);
|
|
182
|
+
this.remoteParticipants.delete(participant!.identity!);
|
|
183
|
+
this.emit(RoomEvent.ParticipantDisconnected, participant!);
|
|
217
184
|
} else if (ev.case == 'localTrackPublished') {
|
|
218
|
-
const publication = this.localParticipant
|
|
219
|
-
|
|
220
|
-
throw new TypeError('local track publication not found');
|
|
221
|
-
}
|
|
222
|
-
this.emit(RoomEvent.LocalTrackPublished, publication, this.localParticipant);
|
|
185
|
+
const publication = this.localParticipant!.trackPublications.get(ev.value.trackSid!);
|
|
186
|
+
this.emit(RoomEvent.LocalTrackPublished, publication!, this.localParticipant!);
|
|
223
187
|
} else if (ev.case == 'localTrackUnpublished') {
|
|
224
|
-
const publication = this.localParticipant
|
|
225
|
-
this.localParticipant
|
|
226
|
-
|
|
227
|
-
this.emit(RoomEvent.LocalTrackUnpublished, publication, this.localParticipant);
|
|
228
|
-
}
|
|
188
|
+
const publication = this.localParticipant!.trackPublications.get(ev.value.publicationSid!);
|
|
189
|
+
this.localParticipant!.trackPublications.delete(ev.value.publicationSid!);
|
|
190
|
+
this.emit(RoomEvent.LocalTrackUnpublished, publication!, this.localParticipant!);
|
|
229
191
|
} else if (ev.case == 'localTrackSubscribed') {
|
|
230
|
-
const publication = this.localParticipant
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
publication.resolveFirstSubscription();
|
|
235
|
-
this.emit(RoomEvent.LocalTrackSubscribed, publication.track!);
|
|
192
|
+
const publication = this.localParticipant!.trackPublications.get(ev.value.trackSid!);
|
|
193
|
+
publication!.resolveFirstSubscription();
|
|
194
|
+
this.emit(RoomEvent.LocalTrackSubscribed, publication!.track!);
|
|
236
195
|
} else if (ev.case == 'trackPublished') {
|
|
237
|
-
const participant = this.
|
|
196
|
+
const participant = this.remoteParticipants.get(ev.value.participantIdentity!);
|
|
238
197
|
const publication = new RemoteTrackPublication(ev.value.publication!);
|
|
239
|
-
participant
|
|
240
|
-
this.emit(RoomEvent.TrackPublished, publication, participant);
|
|
198
|
+
participant!.trackPublications.set(publication.sid!, publication);
|
|
199
|
+
this.emit(RoomEvent.TrackPublished, publication, participant!);
|
|
241
200
|
} else if (ev.case == 'trackUnpublished') {
|
|
242
|
-
const participant = this.
|
|
243
|
-
const publication = participant
|
|
244
|
-
participant
|
|
245
|
-
|
|
246
|
-
this.emit(RoomEvent.TrackUnpublished, publication, participant);
|
|
247
|
-
}
|
|
201
|
+
const participant = this.remoteParticipants.get(ev.value.participantIdentity!);
|
|
202
|
+
const publication = participant!.trackPublications.get(ev.value.publicationSid!);
|
|
203
|
+
participant!.trackPublications.delete(ev.value.publicationSid!);
|
|
204
|
+
this.emit(RoomEvent.TrackUnpublished, publication!, participant!);
|
|
248
205
|
} else if (ev.case == 'trackSubscribed') {
|
|
249
|
-
const ownedTrack = ev.value.track
|
|
250
|
-
const
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
publication.track = new RemoteVideoTrack(ownedTrack);
|
|
258
|
-
} else if (trackInfo.kind == TrackKind.KIND_AUDIO) {
|
|
259
|
-
publication.track = new RemoteAudioTrack(ownedTrack);
|
|
206
|
+
const ownedTrack = ev.value.track;
|
|
207
|
+
const participant = this.remoteParticipants.get(ev.value.participantIdentity!);
|
|
208
|
+
const publication = participant!.trackPublications.get(ownedTrack!.info!.sid!);
|
|
209
|
+
publication!.subscribed = true;
|
|
210
|
+
if (ownedTrack!.info!.kind == TrackKind.KIND_VIDEO) {
|
|
211
|
+
publication!.track = new RemoteVideoTrack(ownedTrack!);
|
|
212
|
+
} else if (ownedTrack!.info!.kind == TrackKind.KIND_AUDIO) {
|
|
213
|
+
publication!.track = new RemoteAudioTrack(ownedTrack!);
|
|
260
214
|
}
|
|
261
215
|
|
|
262
|
-
this.emit(RoomEvent.TrackSubscribed, publication
|
|
216
|
+
this.emit(RoomEvent.TrackSubscribed, publication!.track!, publication!, participant!);
|
|
263
217
|
} else if (ev.case == 'trackUnsubscribed') {
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
publication.track = undefined;
|
|
270
|
-
publication.subscribed = false;
|
|
271
|
-
this.emit(RoomEvent.TrackUnsubscribed, track, publication, participant);
|
|
218
|
+
const participant = this.remoteParticipants.get(ev.value.participantIdentity!);
|
|
219
|
+
const publication = participant!.trackPublications.get(ev.value.trackSid!);
|
|
220
|
+
publication!.track = undefined;
|
|
221
|
+
publication!.subscribed = false;
|
|
222
|
+
this.emit(RoomEvent.TrackUnsubscribed, publication!.track!, publication!, participant!);
|
|
272
223
|
} else if (ev.case == 'trackSubscriptionFailed') {
|
|
273
|
-
const participant = this.
|
|
274
|
-
this.emit(
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
ev.value.
|
|
224
|
+
const participant = this.remoteParticipants.get(ev.value.participantIdentity!);
|
|
225
|
+
this.emit(
|
|
226
|
+
RoomEvent.TrackSubscriptionFailed,
|
|
227
|
+
ev.value.trackSid!,
|
|
228
|
+
participant!,
|
|
229
|
+
ev.value.error,
|
|
279
230
|
);
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
231
|
+
} else if (ev.case == 'trackMuted') {
|
|
232
|
+
const participant = this.remoteParticipants.get(ev.value.participantIdentity!);
|
|
233
|
+
const publication = participant!.trackPublications.get(ev.value.trackSid!);
|
|
234
|
+
publication!.info!.muted = true;
|
|
235
|
+
if (publication!.track) {
|
|
236
|
+
publication!.track.info!.muted = true;
|
|
283
237
|
}
|
|
284
|
-
this.emit(RoomEvent.TrackMuted, publication
|
|
238
|
+
this.emit(RoomEvent.TrackMuted, publication!, participant!);
|
|
285
239
|
} else if (ev.case == 'trackUnmuted') {
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
)
|
|
290
|
-
|
|
291
|
-
if (publication.track) {
|
|
292
|
-
publication.track.info.muted = false;
|
|
240
|
+
const participant = this.retrieveParticipantByIdentity(ev.value.participantIdentity!);
|
|
241
|
+
const publication = participant!.trackPublications.get(ev.value.trackSid!);
|
|
242
|
+
publication!.info!.muted = false;
|
|
243
|
+
if (publication!.track) {
|
|
244
|
+
publication!.track.info!.muted = false;
|
|
293
245
|
}
|
|
294
|
-
this.emit(RoomEvent.TrackUnmuted, publication
|
|
246
|
+
this.emit(RoomEvent.TrackUnmuted, publication!, participant!);
|
|
295
247
|
} else if (ev.case == 'activeSpeakersChanged') {
|
|
296
248
|
const activeSpeakers = ev.value.participantIdentities.map((identity) =>
|
|
297
|
-
this.
|
|
249
|
+
this.retrieveParticipantByIdentity(identity),
|
|
250
|
+
);
|
|
251
|
+
this.emit(
|
|
252
|
+
RoomEvent.ActiveSpeakersChanged,
|
|
253
|
+
activeSpeakers.map((s) => s!),
|
|
298
254
|
);
|
|
299
|
-
this.emit(RoomEvent.ActiveSpeakersChanged, activeSpeakers);
|
|
300
255
|
} else if (ev.case == 'roomMetadataChanged') {
|
|
301
|
-
this.info
|
|
302
|
-
this.emit(RoomEvent.RoomMetadataChanged, this.info
|
|
256
|
+
this.info!.metadata = ev.value.metadata;
|
|
257
|
+
this.emit(RoomEvent.RoomMetadataChanged, this.info!.metadata!);
|
|
303
258
|
} else if (ev.case == 'participantMetadataChanged') {
|
|
304
|
-
const participant = this.
|
|
305
|
-
participant
|
|
306
|
-
this.emit(RoomEvent.ParticipantMetadataChanged, participant
|
|
259
|
+
const participant = this.retrieveParticipantByIdentity(ev.value.participantIdentity!);
|
|
260
|
+
participant!.info!.metadata = ev.value.metadata;
|
|
261
|
+
this.emit(RoomEvent.ParticipantMetadataChanged, participant!.metadata, participant!);
|
|
307
262
|
} else if (ev.case == 'participantNameChanged') {
|
|
308
|
-
const participant = this.
|
|
309
|
-
participant
|
|
310
|
-
this.emit(RoomEvent.ParticipantNameChanged, participant
|
|
263
|
+
const participant = this.retrieveParticipantByIdentity(ev.value.participantIdentity!);
|
|
264
|
+
participant!.info!.name = ev.value.name;
|
|
265
|
+
this.emit(RoomEvent.ParticipantNameChanged, participant!.name!, participant!);
|
|
311
266
|
} else if (ev.case == 'participantAttributesChanged') {
|
|
312
|
-
const participant = this.
|
|
313
|
-
participant
|
|
314
|
-
(
|
|
315
|
-
|
|
316
|
-
return
|
|
267
|
+
const participant = this.retrieveParticipantByIdentity(ev.value.participantIdentity!);
|
|
268
|
+
participant!.info!.attributes = ev.value.attributes.reduce(
|
|
269
|
+
(obj, item) => {
|
|
270
|
+
obj[item.key!] = item.value!;
|
|
271
|
+
return obj;
|
|
317
272
|
},
|
|
318
273
|
{} as Record<string, string>,
|
|
319
274
|
);
|
|
320
275
|
if (Object.keys(ev.value.changedAttributes).length > 0) {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
276
|
+
this.emit(
|
|
277
|
+
RoomEvent.ParticipantAttributesChanged,
|
|
278
|
+
ev.value.changedAttributes.reduce(
|
|
279
|
+
(obj, item) => {
|
|
280
|
+
obj[item.key!] = item.value!;
|
|
281
|
+
return obj;
|
|
282
|
+
},
|
|
283
|
+
{} as Record<string, string>,
|
|
284
|
+
),
|
|
285
|
+
participant!,
|
|
327
286
|
);
|
|
328
|
-
this.emit(RoomEvent.ParticipantAttributesChanged, changedAttributes, participant);
|
|
329
287
|
}
|
|
330
288
|
} else if (ev.case == 'connectionQualityChanged') {
|
|
331
|
-
const participant = this.
|
|
332
|
-
this.emit(RoomEvent.ConnectionQualityChanged, ev.value.quality
|
|
289
|
+
const participant = this.retrieveParticipantByIdentity(ev.value.participantIdentity!);
|
|
290
|
+
this.emit(RoomEvent.ConnectionQualityChanged, ev.value.quality!, participant!);
|
|
333
291
|
} else if (ev.case == 'chatMessage') {
|
|
334
|
-
const participant = this.retrieveParticipantByIdentity(ev.value.participantIdentity);
|
|
292
|
+
const participant = this.retrieveParticipantByIdentity(ev.value.participantIdentity!);
|
|
335
293
|
const { id, message: messageText, timestamp, editTimestamp, generated } = ev.value.message!;
|
|
336
294
|
const message: ChatMessage = {
|
|
337
|
-
id
|
|
338
|
-
message: messageText
|
|
295
|
+
id: id!,
|
|
296
|
+
message: messageText!,
|
|
339
297
|
timestamp: Number(timestamp),
|
|
340
298
|
editTimestamp: Number(editTimestamp),
|
|
341
299
|
generated,
|
|
@@ -343,13 +301,15 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
343
301
|
this.emit(RoomEvent.ChatMessage, message, participant);
|
|
344
302
|
} else if (ev.case == 'dataPacketReceived') {
|
|
345
303
|
// Can be undefined if the data is sent from a Server SDK
|
|
346
|
-
const participant = this.remoteParticipants.get(ev.value.participantIdentity);
|
|
304
|
+
const participant = this.remoteParticipants.get(ev.value.participantIdentity!);
|
|
347
305
|
const dataPacket = ev.value.value;
|
|
348
306
|
switch (dataPacket.case) {
|
|
349
307
|
case 'user':
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
|
|
308
|
+
const buffer = FfiClient.instance.copyBuffer(
|
|
309
|
+
dataPacket.value.data!.data!.dataPtr!,
|
|
310
|
+
Number(dataPacket.value.data!.data!.dataLen),
|
|
311
|
+
);
|
|
312
|
+
new FfiHandle(dataPacket.value.data!.handle!.id!).dispose();
|
|
353
313
|
this.emit(
|
|
354
314
|
RoomEvent.DataReceived,
|
|
355
315
|
buffer,
|
|
@@ -360,7 +320,7 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
360
320
|
break;
|
|
361
321
|
case 'sipDtmf':
|
|
362
322
|
const { code, digit } = dataPacket.value;
|
|
363
|
-
this.emit(RoomEvent.DtmfReceived, code
|
|
323
|
+
this.emit(RoomEvent.DtmfReceived, code!, digit!, participant!);
|
|
364
324
|
break;
|
|
365
325
|
default:
|
|
366
326
|
break;
|
|
@@ -371,18 +331,16 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
371
331
|
this.emit(RoomEvent.EncryptionError, new Error('internal server error'));
|
|
372
332
|
}
|
|
373
333
|
} else if (ev.case == 'connectionStateChanged') {
|
|
374
|
-
this.connectionState = ev.value.state
|
|
334
|
+
this.connectionState = ev.value.state!;
|
|
375
335
|
this.emit(RoomEvent.ConnectionStateChanged, this.connectionState);
|
|
376
336
|
/*} else if (ev.case == 'connected') {
|
|
377
337
|
this.emit(RoomEvent.Connected);*/
|
|
378
338
|
} else if (ev.case == 'disconnected') {
|
|
379
|
-
this.emit(RoomEvent.Disconnected, ev.value.reason);
|
|
339
|
+
this.emit(RoomEvent.Disconnected, ev.value.reason!);
|
|
380
340
|
} else if (ev.case == 'reconnecting') {
|
|
381
341
|
this.emit(RoomEvent.Reconnecting);
|
|
382
342
|
} else if (ev.case == 'reconnected') {
|
|
383
343
|
this.emit(RoomEvent.Reconnected);
|
|
384
|
-
} else if (ev.case == 'roomSidChanged') {
|
|
385
|
-
this.emit(RoomEvent.RoomSidChanged, ev.value.sid);
|
|
386
344
|
}
|
|
387
345
|
};
|
|
388
346
|
|
|
@@ -431,12 +389,12 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
431
389
|
}
|
|
432
390
|
|
|
433
391
|
private createRemoteParticipant(ownedInfo: OwnedParticipant) {
|
|
434
|
-
if (this.remoteParticipants.has(ownedInfo.info!.identity)) {
|
|
392
|
+
if (this.remoteParticipants.has(ownedInfo.info!.identity!)) {
|
|
435
393
|
throw new Error('Participant already exists');
|
|
436
394
|
}
|
|
437
395
|
|
|
438
396
|
const participant = new RemoteParticipant(ownedInfo);
|
|
439
|
-
this.remoteParticipants.set(ownedInfo.info!.identity
|
|
397
|
+
this.remoteParticipants.set(ownedInfo.info!.identity!, participant);
|
|
440
398
|
return participant;
|
|
441
399
|
}
|
|
442
400
|
}
|
|
@@ -477,7 +435,6 @@ export type RoomCallbacks = {
|
|
|
477
435
|
trackUnmuted: (publication: TrackPublication, participant: Participant) => void;
|
|
478
436
|
activeSpeakersChanged: (speakers: Participant[]) => void;
|
|
479
437
|
roomMetadataChanged: (metadata: string) => void;
|
|
480
|
-
roomInfoUpdated: (info: RoomInfo) => void;
|
|
481
438
|
participantMetadataChanged: (metadata: string | undefined, participant: Participant) => void;
|
|
482
439
|
participantNameChanged: (name: string, participant: Participant) => void;
|
|
483
440
|
participantAttributesChanged: (
|
|
@@ -492,14 +449,13 @@ export type RoomCallbacks = {
|
|
|
492
449
|
topic?: string,
|
|
493
450
|
) => void;
|
|
494
451
|
chatMessage: (message: ChatMessage, participant?: Participant) => void;
|
|
495
|
-
dtmfReceived: (code: number, digit: string, participant
|
|
452
|
+
dtmfReceived: (code: number, digit: string, participant: RemoteParticipant) => void;
|
|
496
453
|
encryptionError: (error: Error) => void;
|
|
497
454
|
connectionStateChanged: (state: ConnectionState) => void;
|
|
498
455
|
connected: () => void;
|
|
499
456
|
disconnected: (reason: DisconnectReason) => void;
|
|
500
457
|
reconnecting: () => void;
|
|
501
458
|
reconnected: () => void;
|
|
502
|
-
roomSidChanged: (sid: string) => void;
|
|
503
459
|
};
|
|
504
460
|
|
|
505
461
|
export enum RoomEvent {
|
|
@@ -517,7 +473,6 @@ export enum RoomEvent {
|
|
|
517
473
|
TrackUnmuted = 'trackUnmuted',
|
|
518
474
|
ActiveSpeakersChanged = 'activeSpeakersChanged',
|
|
519
475
|
RoomMetadataChanged = 'roomMetadataChanged',
|
|
520
|
-
RoomSidChanged = 'roomSidChanged',
|
|
521
476
|
ParticipantMetadataChanged = 'participantMetadataChanged',
|
|
522
477
|
ParticipantNameChanged = 'participantNameChanged',
|
|
523
478
|
ParticipantAttributesChanged = 'participantAttributesChanged',
|
package/src/rpc.ts
CHANGED
package/src/track.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
import { create } from '@bufbuild/protobuf';
|
|
5
4
|
import type { AudioSource } from './audio_source.js';
|
|
6
5
|
import { FfiClient, FfiHandle } from './ffi_client.js';
|
|
7
6
|
import type {
|
|
@@ -12,39 +11,39 @@ import type {
|
|
|
12
11
|
TrackInfo,
|
|
13
12
|
TrackKind,
|
|
14
13
|
} from './proto/track_pb.js';
|
|
15
|
-
import {
|
|
14
|
+
import { CreateAudioTrackRequest, CreateVideoTrackRequest } from './proto/track_pb.js';
|
|
16
15
|
import type { VideoSource } from './video_source.js';
|
|
17
16
|
|
|
18
17
|
export abstract class Track {
|
|
19
18
|
/** @internal */
|
|
20
|
-
info
|
|
19
|
+
info?: TrackInfo;
|
|
21
20
|
|
|
22
21
|
/** @internal */
|
|
23
22
|
ffi_handle: FfiHandle;
|
|
24
23
|
|
|
25
24
|
constructor(owned: OwnedTrack) {
|
|
26
|
-
this.info = owned.info
|
|
27
|
-
this.ffi_handle = new FfiHandle(owned.handle!.id);
|
|
25
|
+
this.info = owned.info;
|
|
26
|
+
this.ffi_handle = new FfiHandle(owned.handle!.id!);
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
get sid(): string {
|
|
31
|
-
return this.info
|
|
29
|
+
get sid(): string | undefined {
|
|
30
|
+
return this.info?.sid;
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
get name(): string {
|
|
35
|
-
return this.info
|
|
33
|
+
get name(): string | undefined {
|
|
34
|
+
return this.info?.name;
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
get kind(): TrackKind {
|
|
39
|
-
return this.info
|
|
37
|
+
get kind(): TrackKind | undefined {
|
|
38
|
+
return this.info?.kind;
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
get stream_state(): StreamState {
|
|
43
|
-
return this.info
|
|
41
|
+
get stream_state(): StreamState | undefined {
|
|
42
|
+
return this.info?.streamState;
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
get muted(): boolean {
|
|
47
|
-
return this.info
|
|
45
|
+
get muted(): boolean | undefined {
|
|
46
|
+
return this.info?.muted;
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
49
|
|
|
@@ -54,7 +53,7 @@ export class LocalAudioTrack extends Track {
|
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
static createAudioTrack(name: string, source: AudioSource): LocalAudioTrack {
|
|
57
|
-
const req =
|
|
56
|
+
const req = new CreateAudioTrackRequest({
|
|
58
57
|
name: name,
|
|
59
58
|
sourceHandle: source.ffiHandle.handle,
|
|
60
59
|
});
|
|
@@ -73,7 +72,7 @@ export class LocalVideoTrack extends Track {
|
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
static createVideoTrack(name: string, source: VideoSource): LocalVideoTrack {
|
|
76
|
-
const req =
|
|
75
|
+
const req = new CreateVideoTrackRequest({
|
|
77
76
|
name: name,
|
|
78
77
|
sourceHandle: source.ffiHandle.handle,
|
|
79
78
|
});
|