enableDecryption method

Future<void> enableDecryption({
  1. required RTCPeerConnection peerConnection,
  2. required WebRTCCodec codec,
  3. required bool enabled,
})

Implementation

Future<void> enableDecryption({
  required RTCPeerConnection peerConnection,
  required WebRTCCodec codec,
  required bool enabled,
}) async {
  if (!codec.isSFrameSuported) return;

  final List<RTCRtpReceiver> receivers = await peerConnection.receivers;

  for (final receiver in receivers) {
    final String trackId = receiver.track?.id ?? '';
    final String id = '${receiver.track?.kind}_${trackId}_receiver';
    if (!_frameCyrptors.containsKey(id)) {
      final frameCyrptor =
          await _frameCyrptorFactory.createFrameCryptorForRtpReceiver(
        participantId: id,
        receiver: receiver,
        algorithm: Algorithm.kAesGcm,
        keyProvider: _keyProvider!,
      );

      frameCyrptor.onFrameCryptorStateChanged = (participantId, state) {
        _logger.log('Decryption: $participantId $state');
      };

      _frameCyrptors[id] = frameCyrptor;
      await frameCyrptor.setKeyIndex(0);
    }

    final frameCyrptor0 = _frameCyrptors[id];

    if (enabled) {
      await frameCyrptor0?.setEnabled(true);
      await _keyProvider?.setKey(participantId: id, index: 0, key: aesKey);
    } else {
      await frameCyrptor0?.setEnabled(false);
    }

    await frameCyrptor0?.updateCodec(
      receiver.track?.kind == 'video'
          ? codec.codec.toUpperCase()
          : audioCodec,
    );
  }
}