onIncomingCall method
Implementation
Future<void> onIncomingCall(CallSession newCall) async {
// The incoming calls may be for another room, which we will ignore.
if (newCall.room.id != room.id) {
return;
}
if (newCall.state != CallState.kRinging) {
Logs().w('Incoming call no longer in ringing state. Ignoring.');
return;
}
if (newCall.groupCallId == null || newCall.groupCallId != groupCallId) {
Logs().v(
'Incoming call with groupCallId ${newCall.groupCallId} ignored because it doesn\'t match the current group call');
await newCall.reject();
return;
}
final opponentMemberId = newCall.remoteUser!.id;
final existingCall = getCallByUserId(opponentMemberId);
if (existingCall != null && existingCall.callId == newCall.callId) {
return;
}
Logs().v('GroupCall: incoming call from: $opponentMemberId');
// Check if the user calling has an existing call and use this call instead.
if (existingCall != null) {
await replaceCall(existingCall, newCall);
} else {
await addCall(newCall);
}
await newCall.answerWithStreams(getLocalStreams());
}