diff --git a/.changeset/e2ee-local-cryptor-enabled.md b/.changeset/e2ee-local-cryptor-enabled.md new file mode 100644 index 00000000..8f25abcf --- /dev/null +++ b/.changeset/e2ee-local-cryptor-enabled.md @@ -0,0 +1,5 @@ +--- +'@livekit/react-native': patch +--- + +Add `setLocalParticipantCryptorEnabled` to `RNE2EEManager`, deprecate `setParticipantCryptorEnabled`, and set up the sender cryptor from the local E2EE setting diff --git a/src/e2ee/RNE2EEManager.ts b/src/e2ee/RNE2EEManager.ts index ca843bcb..0cb99532 100644 --- a/src/e2ee/RNE2EEManager.ts +++ b/src/e2ee/RNE2EEManager.ts @@ -107,9 +107,8 @@ export default class RNE2EEManager if (!this.room) { throw new TypeError(`expected room to be present on signal connect`); } - this.setParticipantCryptorEnabled( - this.room.localParticipant.isE2EEEnabled, - this.room.localParticipant.identity + this.setLocalParticipantCryptorEnabled( + this.room.localParticipant.isE2EEEnabled ); }); } @@ -118,7 +117,7 @@ export default class RNE2EEManager publication: LocalTrackPublication, participant: LocalParticipant ) { - if (!publication.isEncrypted) { + if (!participant.isE2EEEnabled) { return; } @@ -285,20 +284,27 @@ export default class RNE2EEManager setupEngine(_engine: RTCEngine): void { // No-op } + + /** Sets whether the local participant encrypts. */ + setLocalParticipantCryptorEnabled(enabled: boolean): void { + if (!this.room) { + throw TypeError(`couldn't set encryption status, room not set up`); + } + this.encryptionEnabled = enabled; + this.emit( + EncryptionEvent.ParticipantEncryptionStatusChanged, + enabled, + this.room.localParticipant + ); + } + + /** @deprecated use `setLocalParticipantCryptorEnabled` */ setParticipantCryptorEnabled( enabled: boolean, participantIdentity: string ): void { - if ( - this.encryptionEnabled !== enabled && - participantIdentity === this.room?.localParticipant.identity - ) { - this.encryptionEnabled = enabled; - this.emit( - EncryptionEvent.ParticipantEncryptionStatusChanged, - enabled, - this.room!.localParticipant - ); + if (participantIdentity === this.room?.localParticipant.identity) { + this.setLocalParticipantCryptorEnabled(enabled); } else { const participant = this.room?.getParticipantByIdentity(participantIdentity);