livekit-client 2.17.3 → 2.18.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/livekit-client.e2ee.worker.js +1 -1
- package/dist/livekit-client.e2ee.worker.js.map +1 -1
- package/dist/livekit-client.e2ee.worker.mjs +8 -7
- package/dist/livekit-client.e2ee.worker.mjs.map +1 -1
- package/dist/livekit-client.esm.mjs +7823 -5772
- package/dist/livekit-client.esm.mjs.map +1 -1
- package/dist/livekit-client.umd.js +1 -1
- package/dist/livekit-client.umd.js.map +1 -1
- package/dist/src/api/SignalClient.d.ts +12 -4
- package/dist/src/api/SignalClient.d.ts.map +1 -1
- package/dist/src/e2ee/constants.d.ts.map +1 -1
- package/dist/src/e2ee/types.d.ts +6 -0
- package/dist/src/e2ee/types.d.ts.map +1 -1
- package/dist/src/e2ee/utils.d.ts +2 -1
- package/dist/src/e2ee/utils.d.ts.map +1 -1
- package/dist/src/e2ee/worker/DataCryptor.d.ts.map +1 -1
- package/dist/src/e2ee/worker/FrameCryptor.d.ts.map +1 -1
- package/dist/src/index.d.ts +5 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/room/PCTransport.d.ts +5 -0
- package/dist/src/room/PCTransport.d.ts.map +1 -1
- package/dist/src/room/PCTransportManager.d.ts +1 -1
- package/dist/src/room/PCTransportManager.d.ts.map +1 -1
- package/dist/src/room/RTCEngine.d.ts +27 -9
- package/dist/src/room/RTCEngine.d.ts.map +1 -1
- package/dist/src/room/Room.d.ts +13 -3
- package/dist/src/room/Room.d.ts.map +1 -1
- package/dist/src/room/data-stream/outgoing/OutgoingDataStreamManager.d.ts.map +1 -1
- package/dist/src/room/data-track/LocalDataTrack.d.ts +48 -0
- package/dist/src/room/data-track/LocalDataTrack.d.ts.map +1 -0
- package/dist/src/room/data-track/RemoteDataTrack.d.ts +46 -0
- package/dist/src/room/data-track/RemoteDataTrack.d.ts.map +1 -0
- package/dist/src/room/data-track/depacketizer.d.ts +6 -6
- package/dist/src/room/data-track/depacketizer.d.ts.map +1 -1
- package/dist/src/room/data-track/frame.d.ts +14 -0
- package/dist/src/room/data-track/frame.d.ts.map +1 -1
- package/dist/src/room/data-track/handle.d.ts +2 -2
- package/dist/src/room/data-track/handle.d.ts.map +1 -1
- package/dist/src/room/data-track/incoming/IncomingDataTrackManager.d.ts +104 -0
- package/dist/src/room/data-track/incoming/IncomingDataTrackManager.d.ts.map +1 -0
- package/dist/src/room/data-track/incoming/errors.d.ts +24 -0
- package/dist/src/room/data-track/incoming/errors.d.ts.map +1 -0
- package/dist/src/room/data-track/incoming/pipeline.d.ts +38 -0
- package/dist/src/room/data-track/incoming/pipeline.d.ts.map +1 -0
- package/dist/src/room/data-track/incoming/types.d.ts +20 -0
- package/dist/src/room/data-track/incoming/types.d.ts.map +1 -0
- package/dist/src/room/data-track/outgoing/OutgoingDataTrackManager.d.ts +63 -28
- package/dist/src/room/data-track/outgoing/OutgoingDataTrackManager.d.ts.map +1 -1
- package/dist/src/room/data-track/outgoing/errors.d.ts +20 -10
- package/dist/src/room/data-track/outgoing/errors.d.ts.map +1 -1
- package/dist/src/room/data-track/outgoing/pipeline.d.ts +9 -8
- package/dist/src/room/data-track/outgoing/pipeline.d.ts.map +1 -1
- package/dist/src/room/data-track/outgoing/types.d.ts +16 -7
- package/dist/src/room/data-track/outgoing/types.d.ts.map +1 -1
- package/dist/src/room/data-track/packet/errors.d.ts +2 -4
- package/dist/src/room/data-track/packet/errors.d.ts.map +1 -1
- package/dist/src/room/data-track/packet/extensions.d.ts +4 -4
- package/dist/src/room/data-track/packet/extensions.d.ts.map +1 -1
- package/dist/src/room/data-track/packet/index.d.ts +5 -5
- package/dist/src/room/data-track/packet/index.d.ts.map +1 -1
- package/dist/src/room/data-track/packet/serializable.d.ts +4 -4
- package/dist/src/room/data-track/packet/serializable.d.ts.map +1 -1
- package/dist/src/room/data-track/packetizer.d.ts +6 -6
- package/dist/src/room/data-track/packetizer.d.ts.map +1 -1
- package/dist/src/room/data-track/track-interfaces.d.ts +23 -0
- package/dist/src/room/data-track/track-interfaces.d.ts.map +1 -0
- package/dist/src/room/data-track/types.d.ts +15 -0
- package/dist/src/room/data-track/types.d.ts.map +1 -0
- package/dist/src/room/events.d.ts +24 -3
- package/dist/src/room/events.d.ts.map +1 -1
- package/dist/src/room/participant/LocalParticipant.d.ts +11 -1
- package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
- package/dist/src/room/participant/RemoteParticipant.d.ts +14 -1
- package/dist/src/room/participant/RemoteParticipant.d.ts.map +1 -1
- package/dist/src/room/token-source/TokenSource.d.ts +1 -1
- package/dist/src/room/token-source/TokenSource.d.ts.map +1 -1
- package/dist/src/room/token-source/types.d.ts +1 -0
- package/dist/src/room/token-source/types.d.ts.map +1 -1
- package/dist/src/room/utils.d.ts +2 -1
- package/dist/src/room/utils.d.ts.map +1 -1
- package/dist/src/utils/abort-signal-polyfill.d.ts +13 -0
- package/dist/src/utils/abort-signal-polyfill.d.ts.map +1 -0
- package/dist/src/utils/deferrable-map.d.ts +32 -0
- package/dist/src/utils/deferrable-map.d.ts.map +1 -0
- package/dist/src/utils/subscribeToEvents.d.ts +3 -0
- package/dist/src/utils/subscribeToEvents.d.ts.map +1 -1
- package/dist/ts4.2/api/SignalClient.d.ts +12 -4
- package/dist/ts4.2/e2ee/types.d.ts +6 -0
- package/dist/ts4.2/e2ee/utils.d.ts +2 -1
- package/dist/ts4.2/index.d.ts +5 -4
- package/dist/ts4.2/room/PCTransport.d.ts +5 -0
- package/dist/ts4.2/room/PCTransportManager.d.ts +1 -1
- package/dist/ts4.2/room/RTCEngine.d.ts +27 -9
- package/dist/ts4.2/room/Room.d.ts +13 -3
- package/dist/ts4.2/room/data-track/LocalDataTrack.d.ts +48 -0
- package/dist/ts4.2/room/data-track/RemoteDataTrack.d.ts +46 -0
- package/dist/ts4.2/room/data-track/depacketizer.d.ts +6 -6
- package/dist/ts4.2/room/data-track/frame.d.ts +14 -0
- package/dist/ts4.2/room/data-track/handle.d.ts +2 -2
- package/dist/ts4.2/room/data-track/incoming/IncomingDataTrackManager.d.ts +110 -0
- package/dist/ts4.2/room/data-track/incoming/errors.d.ts +24 -0
- package/dist/ts4.2/room/data-track/incoming/pipeline.d.ts +38 -0
- package/dist/ts4.2/room/data-track/incoming/types.d.ts +20 -0
- package/dist/ts4.2/room/data-track/outgoing/OutgoingDataTrackManager.d.ts +63 -29
- package/dist/ts4.2/room/data-track/outgoing/errors.d.ts +20 -10
- package/dist/ts4.2/room/data-track/outgoing/pipeline.d.ts +9 -8
- package/dist/ts4.2/room/data-track/outgoing/types.d.ts +16 -7
- package/dist/ts4.2/room/data-track/packet/errors.d.ts +2 -4
- package/dist/ts4.2/room/data-track/packet/extensions.d.ts +4 -4
- package/dist/ts4.2/room/data-track/packet/index.d.ts +5 -6
- package/dist/ts4.2/room/data-track/packet/serializable.d.ts +4 -4
- package/dist/ts4.2/room/data-track/packetizer.d.ts +6 -6
- package/dist/ts4.2/room/data-track/track-interfaces.d.ts +23 -0
- package/dist/ts4.2/room/data-track/types.d.ts +15 -0
- package/dist/ts4.2/room/events.d.ts +24 -3
- package/dist/ts4.2/room/participant/LocalParticipant.d.ts +11 -1
- package/dist/ts4.2/room/participant/RemoteParticipant.d.ts +14 -1
- package/dist/ts4.2/room/token-source/TokenSource.d.ts +1 -1
- package/dist/ts4.2/room/token-source/types.d.ts +1 -0
- package/dist/ts4.2/room/utils.d.ts +2 -1
- package/dist/ts4.2/utils/abort-signal-polyfill.d.ts +13 -0
- package/dist/ts4.2/utils/deferrable-map.d.ts +32 -0
- package/dist/ts4.2/utils/subscribeToEvents.d.ts +3 -0
- package/package.json +4 -2
- package/src/api/SignalClient.test.ts +9 -4
- package/src/api/SignalClient.ts +116 -9
- package/src/e2ee/constants.ts +1 -0
- package/src/e2ee/types.ts +6 -0
- package/src/e2ee/utils.ts +4 -3
- package/src/e2ee/worker/DataCryptor.ts +1 -4
- package/src/e2ee/worker/FrameCryptor.ts +1 -4
- package/src/e2ee/worker/ParticipantKeyHandler.ts +1 -1
- package/src/index.ts +6 -4
- package/src/room/PCTransport.ts +41 -1
- package/src/room/PCTransportManager.ts +1 -1
- package/src/room/RTCEngine.ts +274 -112
- package/src/room/Room.ts +152 -15
- package/src/room/data-stream/outgoing/OutgoingDataStreamManager.ts +9 -9
- package/src/room/data-track/LocalDataTrack.ts +126 -0
- package/src/room/data-track/RemoteDataTrack.ts +80 -0
- package/src/room/data-track/depacketizer.ts +23 -26
- package/src/room/data-track/frame.ts +28 -2
- package/src/room/data-track/handle.ts +2 -8
- package/src/room/data-track/incoming/IncomingDataTrackManager.test.ts +555 -0
- package/src/room/data-track/incoming/IncomingDataTrackManager.ts +589 -0
- package/src/room/data-track/incoming/errors.ts +57 -0
- package/src/room/data-track/incoming/pipeline.ts +121 -0
- package/src/room/data-track/incoming/types.ts +22 -0
- package/src/room/data-track/outgoing/OutgoingDataTrackManager.test.ts +240 -27
- package/src/room/data-track/outgoing/OutgoingDataTrackManager.ts +165 -84
- package/src/room/data-track/outgoing/errors.ts +40 -11
- package/src/room/data-track/outgoing/pipeline.ts +25 -23
- package/src/room/data-track/outgoing/types.ts +14 -6
- package/src/room/data-track/packet/errors.ts +2 -14
- package/src/room/data-track/packet/extensions.ts +21 -26
- package/src/room/data-track/packet/index.test.ts +22 -33
- package/src/room/data-track/packet/index.ts +4 -6
- package/src/room/data-track/packet/serializable.ts +4 -4
- package/src/room/data-track/packetizer.test.ts +2 -2
- package/src/room/data-track/packetizer.ts +7 -10
- package/src/room/data-track/track-interfaces.ts +53 -0
- package/src/room/data-track/types.ts +31 -0
- package/src/room/events.ts +26 -1
- package/src/room/participant/LocalParticipant.ts +57 -6
- package/src/room/participant/RemoteParticipant.ts +26 -1
- package/src/room/token-source/TokenSource.ts +8 -2
- package/src/room/token-source/types.ts +4 -0
- package/src/room/utils.ts +5 -1
- package/src/utils/abort-signal-polyfill.ts +63 -0
- package/src/utils/deferrable-map.ts +109 -0
- package/src/utils/subscribeToEvents.ts +18 -1
- package/dist/src/room/data-track/e2ee.d.ts +0 -12
- package/dist/src/room/data-track/e2ee.d.ts.map +0 -1
- package/dist/src/room/data-track/track.d.ts +0 -30
- package/dist/src/room/data-track/track.d.ts.map +0 -1
- package/dist/src/utils/throws.d.ts +0 -36
- package/dist/src/utils/throws.d.ts.map +0 -1
- package/dist/ts4.2/room/data-track/e2ee.d.ts +0 -12
- package/dist/ts4.2/room/data-track/track.d.ts +0 -30
- package/dist/ts4.2/utils/throws.d.ts +0 -39
- package/src/room/data-track/e2ee.ts +0 -14
- package/src/room/data-track/track.ts +0 -50
- package/src/utils/throws.ts +0 -42
|
@@ -11,7 +11,7 @@ export enum DataTrackDeserializeErrorReason {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export class DataTrackDeserializeError<
|
|
14
|
-
Reason extends DataTrackDeserializeErrorReason,
|
|
14
|
+
Reason extends DataTrackDeserializeErrorReason = DataTrackDeserializeErrorReason,
|
|
15
15
|
> extends LivekitReasonedError<DataTrackDeserializeErrorReason> {
|
|
16
16
|
readonly name = 'DataTrackDeserializeError';
|
|
17
17
|
|
|
@@ -73,21 +73,13 @@ export class DataTrackDeserializeError<
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
export type DataTrackDeserializeErrorAll =
|
|
77
|
-
| DataTrackDeserializeError<DataTrackDeserializeErrorReason.TooShort>
|
|
78
|
-
| DataTrackDeserializeError<DataTrackDeserializeErrorReason.HeaderOverrun>
|
|
79
|
-
| DataTrackDeserializeError<DataTrackDeserializeErrorReason.MissingExtWords>
|
|
80
|
-
| DataTrackDeserializeError<DataTrackDeserializeErrorReason.UnsupportedVersion>
|
|
81
|
-
| DataTrackDeserializeError<DataTrackDeserializeErrorReason.InvalidHandle>
|
|
82
|
-
| DataTrackDeserializeError<DataTrackDeserializeErrorReason.MalformedExt>;
|
|
83
|
-
|
|
84
76
|
export enum DataTrackSerializeErrorReason {
|
|
85
77
|
TooSmallForHeader = 0,
|
|
86
78
|
TooSmallForPayload = 1,
|
|
87
79
|
}
|
|
88
80
|
|
|
89
81
|
export class DataTrackSerializeError<
|
|
90
|
-
Reason extends DataTrackSerializeErrorReason,
|
|
82
|
+
Reason extends DataTrackSerializeErrorReason = DataTrackSerializeErrorReason,
|
|
91
83
|
> extends LivekitReasonedError<DataTrackSerializeErrorReason> {
|
|
92
84
|
readonly name = 'DataTrackSerializeError';
|
|
93
85
|
|
|
@@ -115,7 +107,3 @@ export class DataTrackSerializeError<
|
|
|
115
107
|
);
|
|
116
108
|
}
|
|
117
109
|
}
|
|
118
|
-
|
|
119
|
-
export type DataTrackSerializeErrorAll =
|
|
120
|
-
| DataTrackSerializeError<DataTrackSerializeErrorReason.TooSmallForHeader>
|
|
121
|
-
| DataTrackSerializeError<DataTrackSerializeErrorReason.TooSmallForPayload>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type Throws } from '
|
|
1
|
+
import { type Throws } from '@livekit/throws-transformer/throws';
|
|
2
2
|
import { coerceToDataView } from '../utils';
|
|
3
|
-
import { EXT_TAG_PADDING, U8_LENGTH_BYTES,
|
|
3
|
+
import { EXT_TAG_PADDING, U8_LENGTH_BYTES, U64_LENGTH_BYTES } from './constants';
|
|
4
4
|
import { DataTrackDeserializeError, DataTrackDeserializeErrorReason } from './errors';
|
|
5
5
|
import Serializable from './serializable';
|
|
6
6
|
|
|
@@ -20,7 +20,7 @@ export class DataTrackUserTimestampExtension extends DataTrackExtension {
|
|
|
20
20
|
|
|
21
21
|
static lengthBytes = 8;
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
timestamp: bigint;
|
|
24
24
|
|
|
25
25
|
constructor(timestamp: bigint) {
|
|
26
26
|
super();
|
|
@@ -29,8 +29,8 @@ export class DataTrackUserTimestampExtension extends DataTrackExtension {
|
|
|
29
29
|
|
|
30
30
|
toBinaryLengthBytes(): number {
|
|
31
31
|
return (
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
U8_LENGTH_BYTES /* tag */ +
|
|
33
|
+
U8_LENGTH_BYTES /* length */ +
|
|
34
34
|
DataTrackUserTimestampExtension.lengthBytes
|
|
35
35
|
);
|
|
36
36
|
}
|
|
@@ -38,12 +38,11 @@ export class DataTrackUserTimestampExtension extends DataTrackExtension {
|
|
|
38
38
|
toBinaryInto(dataView: DataView): Throws<number, never> {
|
|
39
39
|
let byteIndex = 0;
|
|
40
40
|
|
|
41
|
-
dataView.
|
|
42
|
-
byteIndex +=
|
|
41
|
+
dataView.setUint8(byteIndex, DataTrackUserTimestampExtension.tag);
|
|
42
|
+
byteIndex += U8_LENGTH_BYTES;
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
byteIndex += U16_LENGTH_BYTES;
|
|
44
|
+
dataView.setUint8(byteIndex, DataTrackUserTimestampExtension.lengthBytes);
|
|
45
|
+
byteIndex += U8_LENGTH_BYTES;
|
|
47
46
|
|
|
48
47
|
dataView.setBigUint64(byteIndex, this.timestamp);
|
|
49
48
|
byteIndex += U64_LENGTH_BYTES;
|
|
@@ -74,9 +73,9 @@ export class DataTrackE2eeExtension extends DataTrackExtension {
|
|
|
74
73
|
|
|
75
74
|
static lengthBytes = 13;
|
|
76
75
|
|
|
77
|
-
|
|
76
|
+
keyIndex: number;
|
|
78
77
|
|
|
79
|
-
|
|
78
|
+
iv: Uint8Array; /* NOTE: According to the rust implementation, this should be 12 bytes long. */
|
|
80
79
|
|
|
81
80
|
constructor(keyIndex: number, iv: Uint8Array) {
|
|
82
81
|
super();
|
|
@@ -86,21 +85,18 @@ export class DataTrackE2eeExtension extends DataTrackExtension {
|
|
|
86
85
|
|
|
87
86
|
toBinaryLengthBytes(): number {
|
|
88
87
|
return (
|
|
89
|
-
|
|
90
|
-
U16_LENGTH_BYTES /* length */ +
|
|
91
|
-
DataTrackE2eeExtension.lengthBytes
|
|
88
|
+
U8_LENGTH_BYTES /* tag */ + U8_LENGTH_BYTES /* length */ + DataTrackE2eeExtension.lengthBytes
|
|
92
89
|
);
|
|
93
90
|
}
|
|
94
91
|
|
|
95
92
|
toBinaryInto(dataView: DataView): Throws<number, never> {
|
|
96
93
|
let byteIndex = 0;
|
|
97
94
|
|
|
98
|
-
dataView.
|
|
99
|
-
byteIndex +=
|
|
95
|
+
dataView.setUint8(byteIndex, DataTrackE2eeExtension.tag);
|
|
96
|
+
byteIndex += U8_LENGTH_BYTES;
|
|
100
97
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
byteIndex += U16_LENGTH_BYTES;
|
|
98
|
+
dataView.setUint8(byteIndex, DataTrackE2eeExtension.lengthBytes);
|
|
99
|
+
byteIndex += U8_LENGTH_BYTES;
|
|
104
100
|
|
|
105
101
|
dataView.setUint8(byteIndex, this.keyIndex);
|
|
106
102
|
byteIndex += U8_LENGTH_BYTES;
|
|
@@ -194,13 +190,12 @@ export class DataTrackExtensions extends Serializable {
|
|
|
194
190
|
let e2ee: DataTrackE2eeExtension | undefined;
|
|
195
191
|
|
|
196
192
|
let byteIndex = 0;
|
|
197
|
-
while (dataView.byteLength - byteIndex >=
|
|
198
|
-
const tag = dataView.
|
|
199
|
-
byteIndex +=
|
|
193
|
+
while (dataView.byteLength - byteIndex >= U8_LENGTH_BYTES + U8_LENGTH_BYTES) {
|
|
194
|
+
const tag = dataView.getUint8(byteIndex);
|
|
195
|
+
byteIndex += U8_LENGTH_BYTES;
|
|
200
196
|
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
byteIndex += U16_LENGTH_BYTES;
|
|
197
|
+
const lengthBytes = dataView.getUint8(byteIndex);
|
|
198
|
+
byteIndex += U8_LENGTH_BYTES;
|
|
204
199
|
|
|
205
200
|
if (tag === EXT_TAG_PADDING) {
|
|
206
201
|
// Skip padding
|
|
@@ -72,7 +72,7 @@ describe('DataTrackPacket', () => {
|
|
|
72
72
|
|
|
73
73
|
const packet = new DataTrackPacket(header, payloadBytes);
|
|
74
74
|
|
|
75
|
-
expect(packet.toBinaryLengthBytes()).toStrictEqual(
|
|
75
|
+
expect(packet.toBinaryLengthBytes()).toStrictEqual(74);
|
|
76
76
|
expect(packet.toBinary()).toStrictEqual(
|
|
77
77
|
new Uint8Array([
|
|
78
78
|
0xc, // Version 0, final, extension
|
|
@@ -88,13 +88,11 @@ describe('DataTrackPacket', () => {
|
|
|
88
88
|
17,
|
|
89
89
|
136,
|
|
90
90
|
0, // Rtp oriented extension words (big endian)
|
|
91
|
-
|
|
91
|
+
6,
|
|
92
92
|
|
|
93
93
|
// E2ee extension
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
0, // Length 12 (big endian)
|
|
97
|
-
12,
|
|
94
|
+
1, // ID 1
|
|
95
|
+
13, // Length 13
|
|
98
96
|
0xfa, // Key index
|
|
99
97
|
0x3c, // Iv array
|
|
100
98
|
0x3c,
|
|
@@ -110,10 +108,8 @@ describe('DataTrackPacket', () => {
|
|
|
110
108
|
0x3c,
|
|
111
109
|
|
|
112
110
|
// User timestamp extension
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
0, // Length 7 (big endian)
|
|
116
|
-
7,
|
|
111
|
+
2, // ID 2
|
|
112
|
+
8, // Length 8
|
|
117
113
|
68, // Timestamp value (big endian)
|
|
118
114
|
17,
|
|
119
115
|
34,
|
|
@@ -178,7 +174,7 @@ describe('DataTrackPacket', () => {
|
|
|
178
174
|
|
|
179
175
|
const packet = new DataTrackPacket(header, payloadBytes);
|
|
180
176
|
|
|
181
|
-
expect(packet.toBinaryLengthBytes()).toStrictEqual(
|
|
177
|
+
expect(packet.toBinaryLengthBytes()).toStrictEqual(62);
|
|
182
178
|
expect(packet.toBinary()).toStrictEqual(
|
|
183
179
|
new Uint8Array([
|
|
184
180
|
0x14, // Version 0, start, extension
|
|
@@ -194,13 +190,11 @@ describe('DataTrackPacket', () => {
|
|
|
194
190
|
0,
|
|
195
191
|
104,
|
|
196
192
|
0, // RTP oriented extension words (big endian)
|
|
197
|
-
|
|
193
|
+
3,
|
|
198
194
|
|
|
199
195
|
// E2ee extension
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
0, // Length 12 (big endian)
|
|
203
|
-
12,
|
|
196
|
+
1, // ID 1
|
|
197
|
+
13, // Length 13
|
|
204
198
|
0xfa, // Key index
|
|
205
199
|
0x3c, // Iv array
|
|
206
200
|
0x3c,
|
|
@@ -216,8 +210,6 @@ describe('DataTrackPacket', () => {
|
|
|
216
210
|
0x3c,
|
|
217
211
|
|
|
218
212
|
0, // Extension padding
|
|
219
|
-
0,
|
|
220
|
-
0,
|
|
221
213
|
|
|
222
214
|
0xfa, // Payload
|
|
223
215
|
0xfa,
|
|
@@ -431,13 +423,11 @@ describe('DataTrackPacket', () => {
|
|
|
431
423
|
...VALID_PACKET_BYTES,
|
|
432
424
|
|
|
433
425
|
0, // RTP oriented extension words (big endian)
|
|
434
|
-
|
|
426
|
+
3,
|
|
435
427
|
|
|
436
428
|
// E2ee extension
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
0, // Length 12 (big endian)
|
|
440
|
-
12,
|
|
429
|
+
1, // ID 1
|
|
430
|
+
12, // Length 12
|
|
441
431
|
0xfa, // Key index
|
|
442
432
|
0x3c, // Iv array
|
|
443
433
|
0x3c,
|
|
@@ -453,8 +443,6 @@ describe('DataTrackPacket', () => {
|
|
|
453
443
|
0x3c,
|
|
454
444
|
|
|
455
445
|
0, // Padding
|
|
456
|
-
0,
|
|
457
|
-
0,
|
|
458
446
|
]);
|
|
459
447
|
packetBytes[0] |= 1 << EXT_FLAG_SHIFT; // Extension flag
|
|
460
448
|
|
|
@@ -476,10 +464,8 @@ describe('DataTrackPacket', () => {
|
|
|
476
464
|
2,
|
|
477
465
|
|
|
478
466
|
// User timestamp extension
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
0, // Length 7 (big endian)
|
|
482
|
-
7,
|
|
467
|
+
2, // ID 2
|
|
468
|
+
7, // Length 7
|
|
483
469
|
0x44, // Timestamp (big endian)
|
|
484
470
|
0x11,
|
|
485
471
|
0x22,
|
|
@@ -488,6 +474,9 @@ describe('DataTrackPacket', () => {
|
|
|
488
474
|
0x11,
|
|
489
475
|
0x88,
|
|
490
476
|
0x11,
|
|
477
|
+
|
|
478
|
+
0, // Padding
|
|
479
|
+
0,
|
|
491
480
|
]);
|
|
492
481
|
packetBytes[0] |= 1 << EXT_FLAG_SHIFT; // Extension flag
|
|
493
482
|
|
|
@@ -508,19 +497,19 @@ describe('DataTrackPacket', () => {
|
|
|
508
497
|
2,
|
|
509
498
|
|
|
510
499
|
// Unknown / potential future extension
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
0, // Length 12 (big endian)
|
|
514
|
-
6,
|
|
500
|
+
8, // ID 8
|
|
501
|
+
6, // Length 6
|
|
515
502
|
0x1, // Payload
|
|
516
503
|
0x2,
|
|
517
504
|
0x3,
|
|
518
505
|
0x4,
|
|
519
506
|
0x5,
|
|
520
507
|
0x6,
|
|
508
|
+
0x0,
|
|
521
509
|
|
|
522
510
|
0x0, // Padding
|
|
523
511
|
0x0,
|
|
512
|
+
0x0,
|
|
524
513
|
]);
|
|
525
514
|
packetBytes[0] |= 1 << EXT_FLAG_SHIFT; // Extension flag
|
|
526
515
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Throws } from '
|
|
1
|
+
import { type Throws } from '@livekit/throws-transformer/throws';
|
|
2
2
|
import { DataTrackHandle, DataTrackHandleError, DataTrackHandleErrorReason } from '../handle';
|
|
3
3
|
import {
|
|
4
4
|
DataTrackTimestamp,
|
|
@@ -26,9 +26,7 @@ import {
|
|
|
26
26
|
} from './constants';
|
|
27
27
|
import {
|
|
28
28
|
DataTrackDeserializeError,
|
|
29
|
-
type DataTrackDeserializeErrorAll,
|
|
30
29
|
DataTrackSerializeError,
|
|
31
|
-
type DataTrackSerializeErrorAll,
|
|
32
30
|
DataTrackSerializeErrorReason,
|
|
33
31
|
} from './errors';
|
|
34
32
|
import { DataTrackExtensions } from './extensions';
|
|
@@ -167,7 +165,7 @@ export class DataTrackPacketHeader extends Serializable {
|
|
|
167
165
|
|
|
168
166
|
static fromBinary<Input extends DataView | ArrayBuffer | Uint8Array>(
|
|
169
167
|
input: Input,
|
|
170
|
-
): Throws<[header: DataTrackPacketHeader, byteLength: number],
|
|
168
|
+
): Throws<[header: DataTrackPacketHeader, byteLength: number], DataTrackDeserializeError> {
|
|
171
169
|
const dataView = coerceToDataView(input);
|
|
172
170
|
|
|
173
171
|
if (dataView.byteLength < BASE_HEADER_LEN) {
|
|
@@ -314,7 +312,7 @@ export class DataTrackPacket extends Serializable {
|
|
|
314
312
|
return this.header.toBinaryLengthBytes() + this.payload.byteLength;
|
|
315
313
|
}
|
|
316
314
|
|
|
317
|
-
toBinaryInto(dataView: DataView): Throws<number,
|
|
315
|
+
toBinaryInto(dataView: DataView): Throws<number, DataTrackSerializeError> {
|
|
318
316
|
let byteIndex = 0;
|
|
319
317
|
const headerLengthBytes = this.header.toBinaryInto(dataView);
|
|
320
318
|
byteIndex += headerLengthBytes;
|
|
@@ -341,7 +339,7 @@ export class DataTrackPacket extends Serializable {
|
|
|
341
339
|
|
|
342
340
|
static fromBinary<Input extends DataView | ArrayBuffer | Uint8Array>(
|
|
343
341
|
input: Input,
|
|
344
|
-
): Throws<[packet: DataTrackPacket, byteLength: number],
|
|
342
|
+
): Throws<[packet: DataTrackPacket, byteLength: number], DataTrackDeserializeError> {
|
|
345
343
|
const dataView = coerceToDataView(input);
|
|
346
344
|
|
|
347
345
|
const [header, headerByteLength] = DataTrackPacketHeader.fromBinary(dataView);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type Throws } from '
|
|
2
|
-
import {
|
|
1
|
+
import { type Throws } from '@livekit/throws-transformer/throws';
|
|
2
|
+
import { DataTrackSerializeError } from './errors';
|
|
3
3
|
|
|
4
4
|
/** An abstract class implementing common behavior related to data track binary serialization. */
|
|
5
5
|
export default abstract class Serializable {
|
|
@@ -7,10 +7,10 @@ export default abstract class Serializable {
|
|
|
7
7
|
abstract toBinaryLengthBytes(): number;
|
|
8
8
|
|
|
9
9
|
/** Given a DataView, serialize the instance inside and return the number of bytes written. */
|
|
10
|
-
abstract toBinaryInto(dataView: DataView): Throws<number,
|
|
10
|
+
abstract toBinaryInto(dataView: DataView): Throws<number, DataTrackSerializeError>;
|
|
11
11
|
|
|
12
12
|
/** Encodes the instance as binary and returns the data as a Uint8Array. */
|
|
13
|
-
toBinary(): Throws<Uint8Array,
|
|
13
|
+
toBinary(): Throws<Uint8Array, DataTrackSerializeError> {
|
|
14
14
|
const lengthBytes = this.toBinaryLengthBytes();
|
|
15
15
|
const output = new ArrayBuffer(lengthBytes);
|
|
16
16
|
const view = new DataView(output);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
-
import {
|
|
3
|
+
import { DataTrackFrameInternal } from './frame';
|
|
4
4
|
import { DataTrackHandle } from './handle';
|
|
5
5
|
import { FrameMarker } from './packet';
|
|
6
6
|
import { DataTrackExtensions } from './packet/extensions';
|
|
@@ -90,7 +90,7 @@ describe('DataTrackPacketizer', () => {
|
|
|
90
90
|
])('should test packetizer edge cases', (payloadSizeBytes, mtuSizeBytes, label) => {
|
|
91
91
|
const packetizer = new DataTrackPacketizer(DataTrackHandle.fromNumber(1), mtuSizeBytes);
|
|
92
92
|
|
|
93
|
-
const frame:
|
|
93
|
+
const frame: DataTrackFrameInternal = {
|
|
94
94
|
payload: new Uint8Array(payloadSizeBytes).fill(0xab),
|
|
95
95
|
extensions: new DataTrackExtensions(),
|
|
96
96
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Throws } from '
|
|
1
|
+
import type { Throws } from '@livekit/throws-transformer/throws';
|
|
2
2
|
import { LivekitReasonedError } from '../errors';
|
|
3
|
-
import { type
|
|
3
|
+
import { type DataTrackFrameInternal } from './frame';
|
|
4
4
|
import { DataTrackHandle } from './handle';
|
|
5
5
|
import { DataTrackPacket, DataTrackPacketHeader, FrameMarker } from './packet';
|
|
6
6
|
import { DataTrackClock, DataTrackTimestamp, WrapAroundUnsignedInt } from './utils';
|
|
@@ -12,7 +12,7 @@ type PacketizeOptions = {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
export class DataTrackPacketizerError<
|
|
15
|
-
Reason extends DataTrackPacketizerReason,
|
|
15
|
+
Reason extends DataTrackPacketizerReason = DataTrackPacketizerReason,
|
|
16
16
|
> extends LivekitReasonedError<Reason> {
|
|
17
17
|
readonly name = 'DataTrackPacketizerError';
|
|
18
18
|
|
|
@@ -38,7 +38,7 @@ export enum DataTrackPacketizerReason {
|
|
|
38
38
|
MtuTooShort = 0,
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
/** A packetizer takes a {@link
|
|
41
|
+
/** A packetizer takes a {@link DataTrackFrameInternal} as input and generates a series
|
|
42
42
|
* of {@link DataTrackPacket}s for transmission to other clients over webrtc. */
|
|
43
43
|
export default class DataTrackPacketizer {
|
|
44
44
|
private handle: DataTrackHandle;
|
|
@@ -70,18 +70,15 @@ export default class DataTrackPacketizer {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
/** Generates a series of packets for the specified {@link
|
|
73
|
+
/** Generates a series of packets for the specified {@link DataTrackFrameInternal}.
|
|
74
74
|
*
|
|
75
75
|
* NOTE: The return value of this function is a generator, so it can be lazily ran if desired,
|
|
76
76
|
* or converted to an array with {@link Array.from}.
|
|
77
77
|
*/
|
|
78
78
|
*packetize(
|
|
79
|
-
frame:
|
|
79
|
+
frame: DataTrackFrameInternal,
|
|
80
80
|
options?: PacketizeOptions,
|
|
81
|
-
): Throws<
|
|
82
|
-
Generator<DataTrackPacket>,
|
|
83
|
-
DataTrackPacketizerError<DataTrackPacketizerReason.MtuTooShort>
|
|
84
|
-
> {
|
|
81
|
+
): Throws<Generator<DataTrackPacket>, DataTrackPacketizerError> {
|
|
85
82
|
const frameNumber = this.frameNumber.getThenIncrement();
|
|
86
83
|
const headerParams = {
|
|
87
84
|
marker: FrameMarker.Inter,
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { DataTrackInfo } from './types';
|
|
2
|
+
|
|
3
|
+
function isObject(subject: unknown): subject is object {
|
|
4
|
+
return subject !== null && typeof subject === 'object';
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const TrackSymbol: symbol = Symbol.for('lk.track');
|
|
8
|
+
|
|
9
|
+
export interface ITrack {
|
|
10
|
+
readonly trackSymbol: typeof TrackSymbol;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function isTrack(subject: unknown): subject is ITrack {
|
|
14
|
+
return isObject(subject) && 'trackSymbol' in subject && subject.trackSymbol === TrackSymbol;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** An interface representing a track (of any type) which is local and sending data to the SFU. */
|
|
18
|
+
export interface ILocalTrack extends ITrack {
|
|
19
|
+
readonly isLocal: true;
|
|
20
|
+
|
|
21
|
+
isPublished(): boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// @ts-ignore - Export this in the future when cutting over to new track interfaces more widely
|
|
25
|
+
function isLocalTrack(subject: unknown): subject is ILocalTrack {
|
|
26
|
+
return isTrack(subject) && 'isLocal' in subject && subject.isLocal === true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const RemoteTrackSymbol: symbol = Symbol.for('lk.remote-track');
|
|
30
|
+
|
|
31
|
+
/** An interface representing a track (of any type) which is remote and receiving data from the SFU. */
|
|
32
|
+
export interface IRemoteTrack extends ITrack {
|
|
33
|
+
readonly isLocal: false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// @ts-ignore - Export this in the future when cutting over to new track interfaces more widely
|
|
37
|
+
function isRemoteTrack(subject: unknown): subject is IRemoteTrack {
|
|
38
|
+
return (
|
|
39
|
+
isTrack(subject) && 'localitySymbol' in subject && subject.localitySymbol === RemoteTrackSymbol
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const DataTrackSymbol: symbol = Symbol.for('lk.data-track');
|
|
44
|
+
/** An interface representing a data track, either local or remote. */
|
|
45
|
+
export interface IDataTrack extends ITrack {
|
|
46
|
+
readonly typeSymbol: typeof DataTrackSymbol;
|
|
47
|
+
|
|
48
|
+
readonly info?: DataTrackInfo;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function isDataTrack(subject: unknown): subject is IDataTrack {
|
|
52
|
+
return isTrack(subject) && 'typeSymbol' in subject && subject.typeSymbol === DataTrackSymbol;
|
|
53
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Encryption_Type, DataTrackInfo as ProtocolDataTrackInfo } from '@livekit/protocol';
|
|
2
|
+
import { type DataTrackHandle } from './handle';
|
|
3
|
+
|
|
4
|
+
export type DataTrackSid = string;
|
|
5
|
+
|
|
6
|
+
/** Information about a published data track. */
|
|
7
|
+
export type DataTrackInfo = {
|
|
8
|
+
sid: DataTrackSid;
|
|
9
|
+
pubHandle: DataTrackHandle;
|
|
10
|
+
name: string;
|
|
11
|
+
usesE2ee: boolean;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const DataTrackInfo = {
|
|
15
|
+
from(protocolInfo: ProtocolDataTrackInfo): DataTrackInfo {
|
|
16
|
+
return {
|
|
17
|
+
sid: protocolInfo.sid,
|
|
18
|
+
pubHandle: protocolInfo.pubHandle,
|
|
19
|
+
name: protocolInfo.name,
|
|
20
|
+
usesE2ee: protocolInfo.encryption !== Encryption_Type.NONE,
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
toProtobuf(info: DataTrackInfo): ProtocolDataTrackInfo {
|
|
24
|
+
return new ProtocolDataTrackInfo({
|
|
25
|
+
sid: info.sid,
|
|
26
|
+
pubHandle: info.pubHandle,
|
|
27
|
+
name: info.name,
|
|
28
|
+
encryption: info.usesE2ee ? Encryption_Type.GCM : Encryption_Type.NONE,
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
};
|
package/src/room/events.ts
CHANGED
|
@@ -332,7 +332,7 @@ export enum RoomEvent {
|
|
|
332
332
|
EncryptionError = 'encryptionError',
|
|
333
333
|
/**
|
|
334
334
|
* Emits whenever the current buffer status of a data channel changes
|
|
335
|
-
* args: (isLow: boolean, kind: [[
|
|
335
|
+
* args: (isLow: boolean, kind: [[DataChannelKind]])
|
|
336
336
|
*/
|
|
337
337
|
DCBufferStatusChanged = 'dcBufferStatusChanged',
|
|
338
338
|
|
|
@@ -352,6 +352,26 @@ export enum RoomEvent {
|
|
|
352
352
|
* fired when the client receives connection metrics from other participants
|
|
353
353
|
*/
|
|
354
354
|
MetricsReceived = 'metricsReceived',
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Emits when a new data track has been published by a downstream participant.
|
|
358
|
+
*/
|
|
359
|
+
DataTrackPublished = 'dataTrackPublished',
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Emits when a new data track has been unpublished by a downstream participant.
|
|
363
|
+
*/
|
|
364
|
+
DataTrackUnpublished = 'dataTrackUnpublished',
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Emits when a new data track has been published locally.
|
|
368
|
+
*/
|
|
369
|
+
LocalDataTrackPublished = 'localDataTrackPublished',
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Emits when a new data track has been unpublished locally.
|
|
373
|
+
*/
|
|
374
|
+
LocalDataTrackUnpublished = 'localDataTrackUnpublished',
|
|
355
375
|
}
|
|
356
376
|
|
|
357
377
|
export enum ParticipantEvent {
|
|
@@ -606,6 +626,11 @@ export enum EngineEvent {
|
|
|
606
626
|
SignalRequestResponse = 'signalRequestResponse',
|
|
607
627
|
SignalConnected = 'signalConnected',
|
|
608
628
|
RoomMoved = 'roomMoved',
|
|
629
|
+
PublishDataTrackResponse = 'publishDataTrackResponse',
|
|
630
|
+
UnPublishDataTrackResponse = 'unPublishDataTrackResponse',
|
|
631
|
+
DataTrackSubscriberHandles = 'dataTrackSubscriberHandles',
|
|
632
|
+
DataTrackPacketReceived = 'dataTrackPacketReceived',
|
|
633
|
+
Joined = 'joined',
|
|
609
634
|
}
|
|
610
635
|
|
|
611
636
|
export enum TrackEvent {
|