answer method
Implementation
Future<void> answer() async {
if (inviteOrAnswerSent) {
return;
}
// stop play ringtone
await voip.delegate.stopRingtone();
if (direction == CallDirection.kIncoming) {
setCallState(CallState.kCreateAnswer);
final answer = await pc!.createAnswer({});
for (final candidate in remoteCandidates) {
await pc!.addCandidate(candidate);
}
final callCapabilities = CallCapabilities()
..dtmf = false
..transferee = false;
final metadata = SDPStreamMetadata({
if (localUserMediaStream != null)
localUserMediaStream!.stream!.id: SDPStreamPurpose(
purpose: SDPStreamMetadataPurpose.Usermedia,
audio_muted: localUserMediaStream!.audioMuted,
video_muted: localUserMediaStream!.videoMuted),
if (localScreenSharingStream != null)
localScreenSharingStream!.stream!.id: SDPStreamPurpose(
purpose: SDPStreamMetadataPurpose.Screenshare,
audio_muted: localScreenSharingStream!.audioMuted,
video_muted: localScreenSharingStream!.videoMuted),
});
await pc!.setLocalDescription(answer);
setCallState(CallState.kConnecting);
// Allow a short time for initial candidates to be gathered
await Future.delayed(Duration(milliseconds: 200));
final res = await sendAnswerCall(room, callId, answer.sdp!, localPartyId,
type: answer.type!,
capabilities: callCapabilities,
metadata: metadata);
Logs().v('[VOIP] answer res => $res');
inviteOrAnswerSent = true;
_answeredByUs = true;
}
}