project method Null safety

dynamic project(
  1. String? sourceId,
  2. List<Map> mapping
)

Start projecting source in selected media ids.

String sourceId - Selected source id. List<Map> mapping - Mapping of the source track ids to the receiver mids String mapping.trackId - Track id from the source (received on the "active" event), if not set the media kind will be used instead. String mapping.media - Track kind of the source ('audio' | 'video'), if not set the trackId will be used instead. String mapping.mediaId - mid value of the rtp receiver in which the media is going to be projected. LayerInfo mapping.layer - Select the simulcast encoding layer and svc layers, only applicable to video tracks.

Implementation

project(String? sourceId, List<Map> mapping) async {
  for (var map in mapping) {
    if (map['trackId'] == null && map['media'] == null) {
      _logger
          .e('Error in projection mapping, trackId and mediaId must be set');
      throw Error();
    }
    if (map['mediaId'] == null) {
      _logger.e('Error in projection mapping, mediaId must be set');
      throw Error();
    }
    RTCPeerConnection? peer = await webRTCPeer.getRTCPeer();
    List<RTCRtpTransceiver> peerTransceiverList =
        await peer.getTransceivers();

    try {
      peerTransceiverList.firstWhere((t) => t.mid == map['mediaId']);
    } catch (e) {
      _logger.e('Error in projection mapping, ${map['mediaId']}'
          'mid not found in local transceivers');
    }
  }
  _logger.i('Viewer project source:$sourceId layer mappings: $mapping');
  Map<String, dynamic> data = {'sourceId': sourceId, 'mapping': mapping};
  await signaling?.cmd('project', data);
  logger.i('Projection done');
}