setupP2PCallWithNewMember method

  1. @override
Future<void> setupP2PCallWithNewMember(
  1. GroupCallSession groupCall,
  2. CallParticipant rp,
  3. CallMembership mem
)
override

Implementation

@override
Future<void> setupP2PCallWithNewMember(
  GroupCallSession groupCall,
  CallParticipant rp,
  CallMembership mem,
) async {
  final existingCall = _getCallForParticipant(groupCall, rp);
  if (existingCall != null) {
    if (existingCall.remoteSessionId != mem.membershipId) {
      await existingCall.hangup(reason: CallErrorCode.unknownError);
    } else {
      Logs().e(
          '[VOIP] onMemberStateChanged Not updating _participants list, already have a ongoing call with ${rp.id}');
      return;
    }
  }

  // Only initiate a call with a participant who has a id that is lexicographically
  // less than your own. Otherwise, that user will call you.
  if (groupCall.localParticipant!.id.compareTo(rp.id) > 0) {
    Logs().i('[VOIP] Waiting for ${rp.id} to send call invite.');
    return;
  }

  final opts = CallOptions(
    callId: genCallID(),
    room: groupCall.room,
    voip: groupCall.voip,
    dir: CallDirection.kOutgoing,
    localPartyId: groupCall.voip.currentSessionId,
    groupCallId: groupCall.groupCallId,
    type: CallType.kVideo,
    iceServers: await groupCall.voip.getIceServers(),
  );
  final newCall = groupCall.voip.createNewCall(opts);

  /// both invitee userId and deviceId are set here because there can be
  /// multiple devices from same user in a call, so we specifiy who the
  /// invite is for
  ///
  /// MOVE TO CREATENEWCALL?
  newCall.remoteUserId = mem.userId;
  newCall.remoteDeviceId = mem.deviceId;
  // party id set to when answered
  newCall.remoteSessionId = mem.membershipId;

  await newCall.placeCallWithStreams(_getLocalStreams(),
      requestScreenSharing: mem.feeds?.any((element) =>
              element['purpose'] == SDPStreamMetadataPurpose.Screenshare) ??
          false);

  await _addCall(groupCall, newCall);
}