@livekit/rtc-node 0.12.2 → 0.13.1
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 +2 -3
- package/dist/audio_frame.d.ts +2 -3
- 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 +2 -3
- package/dist/audio_resampler.d.ts +2 -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 +3 -3
- package/dist/audio_source.d.ts +3 -3
- 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 +2 -3
- package/dist/audio_stream.d.ts +2 -3
- 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 +5 -6
- package/dist/e2ee.d.ts +5 -6
- 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 +10 -10
- package/dist/ffi_client.d.ts +10 -10
- 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 +6 -35
- package/dist/index.d.ts +6 -35
- 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.ts +5 -5
- package/dist/native.d.ts +5 -5
- package/dist/participant.cjs +60 -36
- package/dist/participant.cjs.map +1 -1
- package/dist/participant.d.cts +11 -11
- package/dist/participant.d.ts +11 -11
- package/dist/participant.d.ts.map +1 -1
- package/dist/participant.js +78 -52
- 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 +502 -417
- package/dist/proto/audio_frame_pb.d.ts +502 -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 +331 -263
- package/dist/proto/e2ee_pb.d.ts +331 -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 +156 -109
- package/dist/proto/ffi_pb.d.ts +156 -109
- 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 +13 -15
- package/dist/proto/handle_pb.d.ts +13 -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 +140 -52
- package/dist/proto/participant_pb.d.ts +140 -52
- 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 +1265 -862
- package/dist/proto/room_pb.d.ts +1265 -862
- 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 +138 -108
- package/dist/proto/rpc_pb.d.ts +138 -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 +803 -692
- package/dist/proto/stats_pb.d.ts +803 -692
- 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 +250 -218
- package/dist/proto/track_pb.d.ts +250 -218
- 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 +371 -328
- package/dist/proto/video_frame_pb.d.ts +371 -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 +85 -125
- package/dist/room.cjs.map +1 -1
- package/dist/room.d.cts +6 -17
- package/dist/room.d.ts +6 -17
- package/dist/room.d.ts.map +1 -1
- package/dist/room.js +85 -123
- package/dist/room.js.map +1 -1
- package/dist/rpc.cjs.map +1 -1
- package/dist/rpc.d.cts +0 -1
- package/dist/rpc.d.ts +0 -1
- 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 +8 -9
- package/dist/track.d.ts +8 -9
- 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 +12 -13
- package/dist/track_publication.d.ts +12 -13
- 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/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.d.cts +1 -1
- package/dist/version.d.ts +1 -1
- 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 +2 -3
- package/dist/video_frame.d.ts +2 -3
- 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 +4 -4
- package/dist/video_source.d.ts +4 -4
- 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 +3 -4
- package/dist/video_stream.d.ts +3 -4
- 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 +9 -9
- 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 +41 -42
- 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 +102 -73
- 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 +137 -189
- 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,30 +1,28 @@
|
|
|
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';
|
|
8
|
-
import { E2EEManager } from './e2ee.js';
|
|
7
|
+
import { E2EEManager, defaultE2EEOptions } from './e2ee.js';
|
|
9
8
|
import { FfiClient, FfiClientEvent, FfiHandle } from './ffi_client.js';
|
|
10
9
|
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,15 @@ 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 };
|
|
97
|
+
options.e2ee = { ...defaultE2EEOptions, ...options.e2ee };
|
|
117
98
|
|
|
118
|
-
const req =
|
|
99
|
+
const req = new ConnectRequest({
|
|
119
100
|
url: url,
|
|
120
101
|
token: token,
|
|
121
102
|
options,
|
|
@@ -132,35 +113,34 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
132
113
|
return ev.message.case == 'connect' && ev.message.value.asyncId == res.asyncId;
|
|
133
114
|
});
|
|
134
115
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const { room, localParticipant, participants } = cb.message.value;
|
|
116
|
+
switch (cb.message.case) {
|
|
117
|
+
case 'result':
|
|
118
|
+
this.ffiHandle = new FfiHandle(cb.message.value.room!.handle!.id!);
|
|
119
|
+
this.e2eeManager = new E2EEManager(this.ffiHandle.handle, options.e2ee);
|
|
140
120
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
121
|
+
this.info = cb.message.value.room!.info;
|
|
122
|
+
this.connectionState = ConnectionState.CONN_CONNECTED;
|
|
123
|
+
this.localParticipant = new LocalParticipant(cb.message.value.localParticipant!);
|
|
145
124
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
this.localParticipant = new LocalParticipant(localParticipant!);
|
|
125
|
+
for (const pt of cb.message.value.participants) {
|
|
126
|
+
const rp = this.createRemoteParticipant(pt.participant!);
|
|
149
127
|
|
|
150
|
-
|
|
151
|
-
|
|
128
|
+
for (const pub of pt.publications) {
|
|
129
|
+
const publication = new RemoteTrackPublication(pub);
|
|
130
|
+
rp.trackPublications.set(publication.sid!, publication);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
152
133
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
134
|
+
FfiClient.instance.on(FfiClientEvent.FfiEvent, this.onFfiEvent);
|
|
135
|
+
break;
|
|
136
|
+
case 'error':
|
|
137
|
+
default:
|
|
138
|
+
throw new ConnectError(cb.message.value || '');
|
|
157
139
|
}
|
|
158
|
-
|
|
159
|
-
FfiClient.instance.on(FfiClientEvent.FfiEvent, this.onFfiEvent);
|
|
160
140
|
}
|
|
161
141
|
|
|
162
142
|
async disconnect() {
|
|
163
|
-
if (!this.isConnected
|
|
143
|
+
if (!this.isConnected) {
|
|
164
144
|
return;
|
|
165
145
|
}
|
|
166
146
|
|
|
@@ -168,7 +148,7 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
168
148
|
message: {
|
|
169
149
|
case: 'disconnect',
|
|
170
150
|
value: {
|
|
171
|
-
roomHandle: this.ffiHandle
|
|
151
|
+
roomHandle: this.ffiHandle?.handle,
|
|
172
152
|
},
|
|
173
153
|
},
|
|
174
154
|
});
|
|
@@ -178,27 +158,9 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
178
158
|
}
|
|
179
159
|
|
|
180
160
|
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 (
|
|
161
|
+
if (
|
|
200
162
|
ffiEvent.message.case != 'roomEvent' ||
|
|
201
|
-
ffiEvent.message.value.roomHandle != this.ffiHandle
|
|
163
|
+
ffiEvent.message.value.roomHandle != this.ffiHandle?.handle
|
|
202
164
|
) {
|
|
203
165
|
return;
|
|
204
166
|
}
|
|
@@ -206,136 +168,125 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
206
168
|
const ev = ffiEvent.message.value.message;
|
|
207
169
|
if (ev.case == 'participantConnected') {
|
|
208
170
|
const participant = this.createRemoteParticipant(ev.value.info!);
|
|
209
|
-
this.remoteParticipants.set(participant.identity
|
|
171
|
+
this.remoteParticipants.set(participant.identity!, participant);
|
|
210
172
|
this.emit(RoomEvent.ParticipantConnected, participant);
|
|
211
173
|
} else if (ev.case == 'participantDisconnected') {
|
|
212
|
-
const participant = this.remoteParticipants.get(ev.value.participantIdentity);
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
this.emit(RoomEvent.ParticipantDisconnected, participant);
|
|
216
|
-
}
|
|
174
|
+
const participant = this.remoteParticipants.get(ev.value.participantIdentity!);
|
|
175
|
+
this.remoteParticipants.delete(participant!.identity!);
|
|
176
|
+
this.emit(RoomEvent.ParticipantDisconnected, participant!);
|
|
217
177
|
} 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);
|
|
178
|
+
const publication = this.localParticipant!.trackPublications.get(ev.value.trackSid!);
|
|
179
|
+
this.emit(RoomEvent.LocalTrackPublished, publication!, this.localParticipant!);
|
|
223
180
|
} else if (ev.case == 'localTrackUnpublished') {
|
|
224
|
-
const publication = this.localParticipant
|
|
225
|
-
this.localParticipant
|
|
226
|
-
|
|
227
|
-
this.emit(RoomEvent.LocalTrackUnpublished, publication, this.localParticipant);
|
|
228
|
-
}
|
|
181
|
+
const publication = this.localParticipant!.trackPublications.get(ev.value.publicationSid!);
|
|
182
|
+
this.localParticipant!.trackPublications.delete(ev.value.publicationSid!);
|
|
183
|
+
this.emit(RoomEvent.LocalTrackUnpublished, publication!, this.localParticipant!);
|
|
229
184
|
} else if (ev.case == 'localTrackSubscribed') {
|
|
230
|
-
const publication = this.localParticipant
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
publication.resolveFirstSubscription();
|
|
235
|
-
this.emit(RoomEvent.LocalTrackSubscribed, publication.track!);
|
|
185
|
+
const publication = this.localParticipant!.trackPublications.get(ev.value.trackSid!);
|
|
186
|
+
publication!.resolveFirstSubscription();
|
|
187
|
+
this.emit(RoomEvent.LocalTrackSubscribed, publication!.track!);
|
|
236
188
|
} else if (ev.case == 'trackPublished') {
|
|
237
|
-
const participant = this.
|
|
189
|
+
const participant = this.remoteParticipants.get(ev.value.participantIdentity!);
|
|
238
190
|
const publication = new RemoteTrackPublication(ev.value.publication!);
|
|
239
|
-
participant
|
|
240
|
-
this.emit(RoomEvent.TrackPublished, publication, participant);
|
|
191
|
+
participant!.trackPublications.set(publication.sid!, publication);
|
|
192
|
+
this.emit(RoomEvent.TrackPublished, publication, participant!);
|
|
241
193
|
} else if (ev.case == 'trackUnpublished') {
|
|
242
|
-
const participant = this.
|
|
243
|
-
const publication = participant
|
|
244
|
-
participant
|
|
245
|
-
|
|
246
|
-
this.emit(RoomEvent.TrackUnpublished, publication, participant);
|
|
247
|
-
}
|
|
194
|
+
const participant = this.remoteParticipants.get(ev.value.participantIdentity!);
|
|
195
|
+
const publication = participant!.trackPublications.get(ev.value.publicationSid!);
|
|
196
|
+
participant!.trackPublications.delete(ev.value.publicationSid!);
|
|
197
|
+
this.emit(RoomEvent.TrackUnpublished, publication!, participant!);
|
|
248
198
|
} 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);
|
|
199
|
+
const ownedTrack = ev.value.track;
|
|
200
|
+
const participant = this.remoteParticipants.get(ev.value.participantIdentity!);
|
|
201
|
+
const publication = participant!.trackPublications.get(ownedTrack!.info!.sid!);
|
|
202
|
+
publication!.subscribed = true;
|
|
203
|
+
if (ownedTrack!.info!.kind == TrackKind.KIND_VIDEO) {
|
|
204
|
+
publication!.track = new RemoteVideoTrack(ownedTrack!);
|
|
205
|
+
} else if (ownedTrack!.info!.kind == TrackKind.KIND_AUDIO) {
|
|
206
|
+
publication!.track = new RemoteAudioTrack(ownedTrack!);
|
|
260
207
|
}
|
|
261
208
|
|
|
262
|
-
this.emit(RoomEvent.TrackSubscribed, publication
|
|
209
|
+
this.emit(RoomEvent.TrackSubscribed, publication!.track!, publication!, participant!);
|
|
263
210
|
} 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);
|
|
211
|
+
const participant = this.remoteParticipants.get(ev.value.participantIdentity!);
|
|
212
|
+
const publication = participant!.trackPublications.get(ev.value.trackSid!);
|
|
213
|
+
publication!.track = undefined;
|
|
214
|
+
publication!.subscribed = false;
|
|
215
|
+
this.emit(RoomEvent.TrackUnsubscribed, publication!.track!, publication!, participant!);
|
|
272
216
|
} else if (ev.case == 'trackSubscriptionFailed') {
|
|
273
|
-
const participant = this.
|
|
274
|
-
this.emit(
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
ev.value.
|
|
217
|
+
const participant = this.remoteParticipants.get(ev.value.participantIdentity!);
|
|
218
|
+
this.emit(
|
|
219
|
+
RoomEvent.TrackSubscriptionFailed,
|
|
220
|
+
ev.value.trackSid!,
|
|
221
|
+
participant!,
|
|
222
|
+
ev.value.error,
|
|
279
223
|
);
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
224
|
+
} else if (ev.case == 'trackMuted') {
|
|
225
|
+
const participant = this.remoteParticipants.get(ev.value.participantIdentity!);
|
|
226
|
+
const publication = participant!.trackPublications.get(ev.value.trackSid!);
|
|
227
|
+
publication!.info!.muted = true;
|
|
228
|
+
if (publication!.track) {
|
|
229
|
+
publication!.track.info!.muted = true;
|
|
283
230
|
}
|
|
284
|
-
this.emit(RoomEvent.TrackMuted, publication
|
|
231
|
+
this.emit(RoomEvent.TrackMuted, publication!, participant!);
|
|
285
232
|
} else if (ev.case == 'trackUnmuted') {
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
)
|
|
290
|
-
|
|
291
|
-
if (publication.track) {
|
|
292
|
-
publication.track.info.muted = false;
|
|
233
|
+
const participant = this.retrieveParticipantByIdentity(ev.value.participantIdentity!);
|
|
234
|
+
const publication = participant!.trackPublications.get(ev.value.trackSid!);
|
|
235
|
+
publication!.info!.muted = false;
|
|
236
|
+
if (publication!.track) {
|
|
237
|
+
publication!.track.info!.muted = false;
|
|
293
238
|
}
|
|
294
|
-
this.emit(RoomEvent.TrackUnmuted, publication
|
|
239
|
+
this.emit(RoomEvent.TrackUnmuted, publication!, participant!);
|
|
295
240
|
} else if (ev.case == 'activeSpeakersChanged') {
|
|
296
241
|
const activeSpeakers = ev.value.participantIdentities.map((identity) =>
|
|
297
|
-
this.
|
|
242
|
+
this.retrieveParticipantByIdentity(identity),
|
|
243
|
+
);
|
|
244
|
+
this.emit(
|
|
245
|
+
RoomEvent.ActiveSpeakersChanged,
|
|
246
|
+
activeSpeakers.map((s) => s!),
|
|
298
247
|
);
|
|
299
|
-
this.emit(RoomEvent.ActiveSpeakersChanged, activeSpeakers);
|
|
300
248
|
} else if (ev.case == 'roomMetadataChanged') {
|
|
301
|
-
this.info
|
|
302
|
-
this.emit(RoomEvent.RoomMetadataChanged, this.info
|
|
249
|
+
this.info!.metadata = ev.value.metadata;
|
|
250
|
+
this.emit(RoomEvent.RoomMetadataChanged, this.info!.metadata!);
|
|
303
251
|
} else if (ev.case == 'participantMetadataChanged') {
|
|
304
|
-
const participant = this.
|
|
305
|
-
participant
|
|
306
|
-
this.emit(RoomEvent.ParticipantMetadataChanged, participant
|
|
252
|
+
const participant = this.retrieveParticipantByIdentity(ev.value.participantIdentity!);
|
|
253
|
+
participant!.info!.metadata = ev.value.metadata;
|
|
254
|
+
this.emit(RoomEvent.ParticipantMetadataChanged, participant!.metadata, participant!);
|
|
307
255
|
} else if (ev.case == 'participantNameChanged') {
|
|
308
|
-
const participant = this.
|
|
309
|
-
participant
|
|
310
|
-
this.emit(RoomEvent.ParticipantNameChanged, participant
|
|
256
|
+
const participant = this.retrieveParticipantByIdentity(ev.value.participantIdentity!);
|
|
257
|
+
participant!.info!.name = ev.value.name;
|
|
258
|
+
this.emit(RoomEvent.ParticipantNameChanged, participant!.name!, participant!);
|
|
311
259
|
} else if (ev.case == 'participantAttributesChanged') {
|
|
312
|
-
const participant = this.
|
|
313
|
-
participant
|
|
314
|
-
(
|
|
315
|
-
|
|
316
|
-
return
|
|
260
|
+
const participant = this.retrieveParticipantByIdentity(ev.value.participantIdentity!);
|
|
261
|
+
participant!.info!.attributes = ev.value.attributes.reduce(
|
|
262
|
+
(obj, item) => {
|
|
263
|
+
obj[item.key!] = item.value!;
|
|
264
|
+
return obj;
|
|
317
265
|
},
|
|
318
266
|
{} as Record<string, string>,
|
|
319
267
|
);
|
|
320
268
|
if (Object.keys(ev.value.changedAttributes).length > 0) {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
269
|
+
this.emit(
|
|
270
|
+
RoomEvent.ParticipantAttributesChanged,
|
|
271
|
+
ev.value.changedAttributes.reduce(
|
|
272
|
+
(obj, item) => {
|
|
273
|
+
obj[item.key!] = item.value!;
|
|
274
|
+
return obj;
|
|
275
|
+
},
|
|
276
|
+
{} as Record<string, string>,
|
|
277
|
+
),
|
|
278
|
+
participant!,
|
|
327
279
|
);
|
|
328
|
-
this.emit(RoomEvent.ParticipantAttributesChanged, changedAttributes, participant);
|
|
329
280
|
}
|
|
330
281
|
} else if (ev.case == 'connectionQualityChanged') {
|
|
331
|
-
const participant = this.
|
|
332
|
-
this.emit(RoomEvent.ConnectionQualityChanged, ev.value.quality
|
|
282
|
+
const participant = this.retrieveParticipantByIdentity(ev.value.participantIdentity!);
|
|
283
|
+
this.emit(RoomEvent.ConnectionQualityChanged, ev.value.quality!, participant!);
|
|
333
284
|
} else if (ev.case == 'chatMessage') {
|
|
334
|
-
const participant = this.retrieveParticipantByIdentity(ev.value.participantIdentity);
|
|
285
|
+
const participant = this.retrieveParticipantByIdentity(ev.value.participantIdentity!);
|
|
335
286
|
const { id, message: messageText, timestamp, editTimestamp, generated } = ev.value.message!;
|
|
336
287
|
const message: ChatMessage = {
|
|
337
|
-
id
|
|
338
|
-
message: messageText
|
|
288
|
+
id: id!,
|
|
289
|
+
message: messageText!,
|
|
339
290
|
timestamp: Number(timestamp),
|
|
340
291
|
editTimestamp: Number(editTimestamp),
|
|
341
292
|
generated,
|
|
@@ -343,13 +294,15 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
343
294
|
this.emit(RoomEvent.ChatMessage, message, participant);
|
|
344
295
|
} else if (ev.case == 'dataPacketReceived') {
|
|
345
296
|
// Can be undefined if the data is sent from a Server SDK
|
|
346
|
-
const participant = this.remoteParticipants.get(ev.value.participantIdentity);
|
|
297
|
+
const participant = this.remoteParticipants.get(ev.value.participantIdentity!);
|
|
347
298
|
const dataPacket = ev.value.value;
|
|
348
299
|
switch (dataPacket.case) {
|
|
349
300
|
case 'user':
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
|
|
301
|
+
const buffer = FfiClient.instance.copyBuffer(
|
|
302
|
+
dataPacket.value.data!.data!.dataPtr!,
|
|
303
|
+
Number(dataPacket.value.data!.data!.dataLen),
|
|
304
|
+
);
|
|
305
|
+
new FfiHandle(dataPacket.value.data!.handle!.id!).dispose();
|
|
353
306
|
this.emit(
|
|
354
307
|
RoomEvent.DataReceived,
|
|
355
308
|
buffer,
|
|
@@ -360,7 +313,7 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
360
313
|
break;
|
|
361
314
|
case 'sipDtmf':
|
|
362
315
|
const { code, digit } = dataPacket.value;
|
|
363
|
-
this.emit(RoomEvent.DtmfReceived, code
|
|
316
|
+
this.emit(RoomEvent.DtmfReceived, code!, digit!, participant!);
|
|
364
317
|
break;
|
|
365
318
|
default:
|
|
366
319
|
break;
|
|
@@ -371,18 +324,16 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
371
324
|
this.emit(RoomEvent.EncryptionError, new Error('internal server error'));
|
|
372
325
|
}
|
|
373
326
|
} else if (ev.case == 'connectionStateChanged') {
|
|
374
|
-
this.connectionState = ev.value.state
|
|
327
|
+
this.connectionState = ev.value.state!;
|
|
375
328
|
this.emit(RoomEvent.ConnectionStateChanged, this.connectionState);
|
|
376
329
|
/*} else if (ev.case == 'connected') {
|
|
377
330
|
this.emit(RoomEvent.Connected);*/
|
|
378
331
|
} else if (ev.case == 'disconnected') {
|
|
379
|
-
this.emit(RoomEvent.Disconnected, ev.value.reason);
|
|
332
|
+
this.emit(RoomEvent.Disconnected, ev.value.reason!);
|
|
380
333
|
} else if (ev.case == 'reconnecting') {
|
|
381
334
|
this.emit(RoomEvent.Reconnecting);
|
|
382
335
|
} else if (ev.case == 'reconnected') {
|
|
383
336
|
this.emit(RoomEvent.Reconnected);
|
|
384
|
-
} else if (ev.case == 'roomSidChanged') {
|
|
385
|
-
this.emit(RoomEvent.RoomSidChanged, ev.value.sid);
|
|
386
337
|
}
|
|
387
338
|
};
|
|
388
339
|
|
|
@@ -431,12 +382,12 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
|
|
|
431
382
|
}
|
|
432
383
|
|
|
433
384
|
private createRemoteParticipant(ownedInfo: OwnedParticipant) {
|
|
434
|
-
if (this.remoteParticipants.has(ownedInfo.info!.identity)) {
|
|
385
|
+
if (this.remoteParticipants.has(ownedInfo.info!.identity!)) {
|
|
435
386
|
throw new Error('Participant already exists');
|
|
436
387
|
}
|
|
437
388
|
|
|
438
389
|
const participant = new RemoteParticipant(ownedInfo);
|
|
439
|
-
this.remoteParticipants.set(ownedInfo.info!.identity
|
|
390
|
+
this.remoteParticipants.set(ownedInfo.info!.identity!, participant);
|
|
440
391
|
return participant;
|
|
441
392
|
}
|
|
442
393
|
}
|
|
@@ -477,7 +428,6 @@ export type RoomCallbacks = {
|
|
|
477
428
|
trackUnmuted: (publication: TrackPublication, participant: Participant) => void;
|
|
478
429
|
activeSpeakersChanged: (speakers: Participant[]) => void;
|
|
479
430
|
roomMetadataChanged: (metadata: string) => void;
|
|
480
|
-
roomInfoUpdated: (info: RoomInfo) => void;
|
|
481
431
|
participantMetadataChanged: (metadata: string | undefined, participant: Participant) => void;
|
|
482
432
|
participantNameChanged: (name: string, participant: Participant) => void;
|
|
483
433
|
participantAttributesChanged: (
|
|
@@ -492,14 +442,13 @@ export type RoomCallbacks = {
|
|
|
492
442
|
topic?: string,
|
|
493
443
|
) => void;
|
|
494
444
|
chatMessage: (message: ChatMessage, participant?: Participant) => void;
|
|
495
|
-
dtmfReceived: (code: number, digit: string, participant
|
|
445
|
+
dtmfReceived: (code: number, digit: string, participant: RemoteParticipant) => void;
|
|
496
446
|
encryptionError: (error: Error) => void;
|
|
497
447
|
connectionStateChanged: (state: ConnectionState) => void;
|
|
498
448
|
connected: () => void;
|
|
499
449
|
disconnected: (reason: DisconnectReason) => void;
|
|
500
450
|
reconnecting: () => void;
|
|
501
451
|
reconnected: () => void;
|
|
502
|
-
roomSidChanged: (sid: string) => void;
|
|
503
452
|
};
|
|
504
453
|
|
|
505
454
|
export enum RoomEvent {
|
|
@@ -517,7 +466,6 @@ export enum RoomEvent {
|
|
|
517
466
|
TrackUnmuted = 'trackUnmuted',
|
|
518
467
|
ActiveSpeakersChanged = 'activeSpeakersChanged',
|
|
519
468
|
RoomMetadataChanged = 'roomMetadataChanged',
|
|
520
|
-
RoomSidChanged = 'roomSidChanged',
|
|
521
469
|
ParticipantMetadataChanged = 'participantMetadataChanged',
|
|
522
470
|
ParticipantNameChanged = 'participantNameChanged',
|
|
523
471
|
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
|
});
|