diff --git a/.changeset/cryptor-error-participant-identity.md b/.changeset/cryptor-error-participant-identity.md new file mode 100644 index 0000000000..8a87ef4b8d --- /dev/null +++ b/.changeset/cryptor-error-participant-identity.md @@ -0,0 +1,5 @@ +--- +"livekit-client": patch +--- + +Include participant identity in CryptoError errors diff --git a/src/e2ee/errors.ts b/src/e2ee/errors.ts index d20c78be67..5ef123d31a 100644 --- a/src/e2ee/errors.ts +++ b/src/e2ee/errors.ts @@ -9,8 +9,15 @@ export enum CryptorErrorReason { export class CryptorError extends LivekitError { reason: CryptorErrorReason; - constructor(message?: string, reason: CryptorErrorReason = CryptorErrorReason.InternalError) { + participantIdentity?: string; + + constructor( + message?: string, + reason: CryptorErrorReason = CryptorErrorReason.InternalError, + participantIdentity?: string, + ) { super(40, message); this.reason = reason; + this.participantIdentity = participantIdentity; } } diff --git a/src/e2ee/index.ts b/src/e2ee/index.ts index 8958a64704..63d0426ec4 100644 --- a/src/e2ee/index.ts +++ b/src/e2ee/index.ts @@ -2,3 +2,4 @@ export * from './KeyProvider'; export * from './utils'; export * from './types'; export * from './events'; +export * from './errors'; diff --git a/src/e2ee/worker/FrameCryptor.ts b/src/e2ee/worker/FrameCryptor.ts index 693d7786c3..bc2d407621 100644 --- a/src/e2ee/worker/FrameCryptor.ts +++ b/src/e2ee/worker/FrameCryptor.ts @@ -183,7 +183,12 @@ export class FrameCryptor extends BaseFrameCryptor { .pipeTo(writable) .catch((e) => { workerLogger.warn(e); - this.emit(CryptorEvent.Error, e instanceof CryptorError ? e : new CryptorError(e.message)); + this.emit( + CryptorEvent.Error, + e instanceof CryptorError + ? e + : new CryptorError(e.message, undefined, this.participantIdentity), + ); }); this.trackId = trackId; } @@ -297,7 +302,11 @@ export class FrameCryptor extends BaseFrameCryptor { workerLogger.debug('failed to decrypt, emitting error', this.logContext); this.emit( CryptorEvent.Error, - new CryptorError(`encryption key missing for encoding`, CryptorErrorReason.MissingKey), + new CryptorError( + `encryption key missing for encoding`, + CryptorErrorReason.MissingKey, + this.participantIdentity, + ), ); } } @@ -367,6 +376,7 @@ export class FrameCryptor extends BaseFrameCryptor { new CryptorError( `missing key at index ${keyIndex} for participant ${this.participantIdentity}`, CryptorErrorReason.MissingKey, + this.participantIdentity, ), ); } @@ -487,12 +497,14 @@ export class FrameCryptor extends BaseFrameCryptor { throw new CryptorError( `valid key missing for participant ${this.participantIdentity}`, CryptorErrorReason.InvalidKey, + this.participantIdentity, ); } } else { throw new CryptorError( `Decryption failed: ${error.message}`, CryptorErrorReason.InvalidKey, + this.participantIdentity, ); } }