Skip to content

Commit

Permalink
fix(e2ee): fix types (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbsp authored Jan 7, 2025
1 parent 81b2d3c commit aca0c42
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-starfishes-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@livekit/rtc-node": patch
---

e2ee: types can include undefined
10 changes: 5 additions & 5 deletions packages/livekit-rtc/src/e2ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const DEFAULT_FAILURE_TOLERANCE = -1;

export interface KeyProviderOptions {
sharedKey?: Uint8Array;
ratchetSalt: Uint8Array;
ratchetWindowSize: number;
failureTolerance: number;
ratchetSalt?: Uint8Array;
ratchetWindowSize?: number;
failureTolerance?: number;
}

export const defaultKeyProviderOptions: KeyProviderOptions = {
Expand All @@ -43,7 +43,7 @@ export const defaultKeyProviderOptions: KeyProviderOptions = {

export interface E2EEOptions {
keyProviderOptions: KeyProviderOptions;
encryptionType: EncryptionType;
encryptionType?: EncryptionType;
}

export const defaultE2EEOptions: E2EEOptions = {
Expand Down Expand Up @@ -247,7 +247,7 @@ export class FrameCryptor {
export class E2EEManager {
private roomHandle = BigInt(0);
private options: E2EEOptions;
private keyProvider?: KeyProvider;
private keyProvider: KeyProvider;

enabled: boolean;

Expand Down
13 changes: 3 additions & 10 deletions packages/livekit-rtc/src/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import type { TypedEventEmitter as TypedEmitter } from '@livekit/typed-emitter';
import EventEmitter from 'events';
import type { E2EEOptions } from './e2ee.js';
import { E2EEManager } from './e2ee.js';
import { E2EEManager, defaultE2EEOptions } from './e2ee.js';
import { FfiClient, FfiClientEvent, FfiHandle } from './ffi_client.js';
import type { Participant } from './participant.js';
import { LocalParticipant, RemoteParticipant } from './participant.js';
Expand Down Expand Up @@ -94,6 +94,7 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>

async connect(url: string, token: string, opts?: RoomOptions) {
const options = { ...defaultRoomOptions, ...opts };
options.e2ee = { ...defaultE2EEOptions, ...options.e2ee };

const req = new ConnectRequest({
url: url,
Expand All @@ -115,15 +116,7 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
switch (cb.message.case) {
case 'result':
this.ffiHandle = new FfiHandle(cb.message.value.room!.handle!.id!);
this.e2eeManager = new E2EEManager(this.ffiHandle.handle, {
keyProviderOptions: {
sharedKey: options.e2ee?.keyProviderOptions?.sharedKey,
ratchetSalt: options.e2ee!.keyProviderOptions!.ratchetSalt!,
ratchetWindowSize: options.e2ee!.keyProviderOptions!.ratchetWindowSize!,
failureTolerance: options.e2ee!.keyProviderOptions!.failureTolerance!,
},
encryptionType: options.e2ee!.encryptionType!,
});
this.e2eeManager = new E2EEManager(this.ffiHandle.handle, options.e2ee);

this.info = cb.message.value.room!.info;
this.connectionState = ConnectionState.CONN_CONNECTED;
Expand Down

0 comments on commit aca0c42

Please sign in to comment.