onCallAnswer method

Future<void> onCallAnswer(
  1. String roomId,
  2. String senderId,
  3. Map<String, dynamic> content
)

Implementation

Future<void> onCallAnswer(
    String roomId, String senderId, Map<String, dynamic> content) async {
  Logs().v('[VOIP] onCallAnswer => ${content.toString()}');
  final String callId = content['call_id'];
  final String partyId = content['party_id'];

  final call = calls[callId];
  if (call != null) {
    if (senderId == client.userID) {
      // Ignore messages to yourself.
      if (!call.answeredByUs) {
        await delegate.stopRingtone();
      }
      if (call.state == CallState.kRinging) {
        await call.onAnsweredElsewhere();
      }
      return;
    }
    if (call.room.id != roomId) {
      Logs().w(
          'Ignoring call answer for room $roomId claiming to be for call in room ${call.room.id}');
      return;
    }
    call.remotePartyId = partyId;
    call.remoteUser = await call.room.requestUser(senderId);

    final answer = RTCSessionDescription(
        content['answer']['sdp'], content['answer']['type']);

    SDPStreamMetadata? metadata;
    if (content[sdpStreamMetadataKey] != null) {
      metadata = SDPStreamMetadata.fromJson(content[sdpStreamMetadataKey]);
    }
    await call.onAnswerReceived(answer, metadata);
  } else {
    Logs().v('[VOIP] onCallAnswer: Session [$callId] not found!');
  }
}