Skip to content

Commit 25418c8

Browse files
authored
Data tracks - outgoing manager (#1810)
1 parent 7aed0ba commit 25418c8

File tree

21 files changed

+1208
-51
lines changed

21 files changed

+1208
-51
lines changed

.changeset/thin-jobs-grab.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'livekit-client': patch
3+
---
4+
5+
Adds new OutgoingDataTrackManager to manage sending data track payloads

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import * as attributes from './room/attribute-typings';
1414
// FIXME: remove this import in a follow up data track pull request.
1515
import './room/data-track/depacketizer';
1616
// FIXME: remove this import in a follow up data track pull request.
17-
import './room/data-track/packetizer';
17+
import './room/data-track/outgoing/OutgoingDataTrackManager';
1818
import LocalParticipant from './room/participant/LocalParticipant';
1919
import Participant, {
2020
ConnectionQuality,

src/room/data-track/depacketizer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-unused-vars */
22
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3-
import { DataTrackDepacketizer } from './depacketizer';
3+
import DataTrackDepacketizer from './depacketizer';
44
import { DataTrackHandle } from './handle';
55
import { DataTrackPacket, DataTrackPacketHeader, FrameMarker } from './packet';
66
import { DataTrackTimestamp, WrapAroundUnsignedInt } from './utils';

src/room/data-track/depacketizer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ type PushOptions = {
8585
errorOnPartialFrames: boolean;
8686
};
8787

88-
export class DataTrackDepacketizer {
88+
export default class DataTrackDepacketizer {
8989
/** Maximum number of packets to buffer per frame before dropping. */
9090
static MAX_BUFFER_PACKETS = 128;
9191

src/room/data-track/e2ee.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export type EncryptedPayload = {
2+
payload: Uint8Array;
3+
iv: Uint8Array; // NOTE: should be 12 bytes long
4+
keyIndex: number;
5+
};
6+
7+
export type EncryptionProvider = {
8+
// FIXME: add in explicit `Throws<..., EncryptionError>`?
9+
encrypt(payload: Uint8Array): EncryptedPayload;
10+
};
11+
12+
export type DecryptionProvider = {
13+
decrypt(payload: Uint8Array, senderIdentity: string): Uint8Array;
14+
};

src/room/data-track/frame.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DataTrackExtensions } from './packet/extensions';
2-
import { DataTrackPacketizer } from './packetizer';
2+
import DataTrackPacketizer from './packetizer';
33

44
/** A pair of payload bytes and packet extensions which can be fed into a {@link DataTrackPacketizer}. */
55
export type DataTrackFrame = {

src/room/data-track/handle.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { DataTrackHandle } from './handle';
44

55
describe('DataTrackHandle', () => {
66
it('should parse handle raw inputs', () => {
7-
expect(DataTrackHandle.fromNumber(3).value).toEqual(3);
7+
expect(DataTrackHandle.fromNumber(3)).toEqual(3);
88
expect(() => DataTrackHandle.fromNumber(0)).toThrow('0x0 is a reserved value');
99
expect(() => DataTrackHandle.fromNumber(9999999)).toThrow(
1010
'Value too large to be a valid track handle',

src/room/data-track/handle.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ export class DataTrackHandleError<
4141
}
4242
}
4343

44-
export class DataTrackHandle {
45-
public value: number;
46-
47-
static fromNumber(
44+
export type DataTrackHandle = number;
45+
export const DataTrackHandle = {
46+
fromNumber(
4847
raw: number,
4948
): Throws<
5049
DataTrackHandle,
@@ -57,24 +56,20 @@ export class DataTrackHandle {
5756
if (raw > U16_MAX_SIZE) {
5857
throw DataTrackHandleError.tooLarge();
5958
}
60-
return new DataTrackHandle(raw);
61-
}
62-
63-
constructor(raw: number) {
64-
this.value = raw;
65-
}
66-
}
59+
return raw;
60+
},
61+
};
6762

6863
/** Manage allocating new handles which don't conflict over the lifetime of the client. */
6964
export class DataTrackHandleAllocator {
70-
static value = 0;
65+
value = 0;
7166

7267
/** Returns a unique track handle for the next publication, if one can be obtained. */
73-
static get(): DataTrackHandle | null {
68+
get(): DataTrackHandle | null {
7469
this.value += 1;
7570
if (this.value > U16_MAX_SIZE) {
7671
return null;
7772
}
78-
return new DataTrackHandle(this.value);
73+
return this.value;
7974
}
8075
}

0 commit comments

Comments
 (0)