StreamEncryptionManager

The SDK's default E2EEManager, backed by WebRTC's framed AES-GCM encryption. Frames are encrypted before they leave the device and decrypted after they arrive, so the SFU forwards media it cannot read.

Typical use, matching the JavaScript and iOS SDKs:

StreamEncryptionManager.create(myUserId).onSuccess { e2ee ->
e2ee.setSharedKey(keyIndex = 0, key = myKeyBytes)
call.setE2EEManager(e2ee)
call.join()
}

You own the instance you create: keep it for as long as you need to rotate keys, and call dispose when you are done with it. The SDK does not dispose managers it did not create, since the same manager is usually reused across rejoins and often across calls.

Instances are safe to use from any thread. Key changes take effect on the frames encrypted after they are applied.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The AES-GCM variant this manager encrypts with.

Link copied to clipboard

The local user these keys and outgoing frames belong to.

Functions

Link copied to clipboard
open override fun decrypt(receiver: RtpReceiver, userId: String, trackType: E2EETrackType?): Result<Unit>

Called once per incoming track, when the subscriber learns which participant it belongs to. The implementation is expected to install a frame decryptor on receiver.

Link copied to clipboard
fun dispose()

Releases the native manager and wipes its keys. Drops the setEventListener observer first so a listener that captured a ViewModel or Activity is not kept alive by native. Subsequent key operations are ignored; attempting to attach an encryptor or decryptor returns a failure so the SDK cannot treat an unprotected track as configured. Dispose only once you are done with every call that uses it.

Link copied to clipboard

Turns on periodic E2EEEventType.PERF_REPORT events carrying per-track crypto timings. Off by default; it costs a timing measurement per frame, so leave it off outside diagnostics.

Link copied to clipboard
open override fun encrypt(sender: RtpSender, codec: String?, trackType: E2EETrackType?): Result<Unit>

Called once per outgoing track, right after the publisher adds its transceiver. The implementation is expected to install a frame encryptor on sender.

Link copied to clipboard
fun removeAllKeys(userId: String)

Drops every key held for userId, at every index, falling back to the shared key for that participant. Shared keys are untouched — use removeSharedKey for those.

Link copied to clipboard
fun removeKey(userId: String, keyIndex: Int)

Drops userId's key at keyIndex, falling back to the shared key for that participant.

Link copied to clipboard
fun removeSharedKey(keyIndex: Int)

Drops the shared key at keyIndex.

Link copied to clipboard

Asks for a E2EEEventType.KEY_STATE event describing the keys currently held. Answered asynchronously through the listener registered with setEventListener, so register first.

Link copied to clipboard

Observes encryption state changes, most importantly decryption failures. Pass null to stop observing. The listener is invoked on a WebRTC internal thread, so hop to your own dispatcher before touching UI state.

Link copied to clipboard
fun setKey(userId: String, keyIndex: Int, key: ByteArray)

Sets the key for a single participant, which takes precedence over the shared key. Use this when each participant publishes under their own key. See setSharedKey for rotation.

Link copied to clipboard
fun setSharedKey(keyIndex: Int, key: ByteArray)

Sets the key used for every participant that has no per-user key, including your own outgoing media. Use this when everyone in the call shares one passphrase-derived key.