fix: Ensures that p2p/group calls are in progress to reject new call invitations, and emits a call reject events.
This commit is contained in:
parent
b203b5dacb
commit
62cca99edd
|
|
@ -932,17 +932,16 @@ class CallSession {
|
||||||
/// This used to be done by calling hangup, but is a separate method and protocol
|
/// This used to be done by calling hangup, but is a separate method and protocol
|
||||||
/// event as of MSC2746.
|
/// event as of MSC2746.
|
||||||
///
|
///
|
||||||
Future<void> reject() async {
|
Future<void> reject({String? reason, bool shouldEmit = true}) async {
|
||||||
// stop play ringtone
|
// stop play ringtone
|
||||||
voip.delegate.stopRingtone();
|
voip.delegate.stopRingtone();
|
||||||
|
if (state != CallState.kRinging && state != CallState.kFledgling) {
|
||||||
if (state != CallState.kRinging) {
|
Logs().e('[VOIP] Call must be in \'ringing|fledgling\' state to reject!');
|
||||||
Logs().e('[VOIP] Call must be in \'ringing\' state to reject!');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Logs().d('[VOIP] Rejecting call: $callId');
|
Logs().d('[VOIP] Rejecting call: $callId');
|
||||||
await terminate(CallParty.kLocal, CallErrorCode.UserHangup, true);
|
await terminate(CallParty.kLocal, CallErrorCode.UserHangup, shouldEmit);
|
||||||
await sendCallReject(room, callId, lifetimeMs, localPartyId);
|
await sendCallReject(room, callId, lifetimeMs, localPartyId, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> hangup([String? reason, bool suppressEvent = true]) async {
|
Future<void> hangup([String? reason, bool suppressEvent = true]) async {
|
||||||
|
|
@ -987,15 +986,15 @@ class CallSession {
|
||||||
hangupParty = party;
|
hangupParty = party;
|
||||||
hangupReason = reason;
|
hangupReason = reason;
|
||||||
|
|
||||||
setCallState(CallState.kEnded);
|
if (shouldEmit) {
|
||||||
|
setCallState(CallState.kEnded);
|
||||||
|
}
|
||||||
voip.currentCID = null;
|
voip.currentCID = null;
|
||||||
voip.calls.remove(callId);
|
voip.calls.remove(callId);
|
||||||
await cleanUp();
|
await cleanUp();
|
||||||
|
|
||||||
onCallHangup.add(this);
|
|
||||||
|
|
||||||
voip.delegate.handleCallEnded(this);
|
|
||||||
if (shouldEmit) {
|
if (shouldEmit) {
|
||||||
|
onCallHangup.add(this);
|
||||||
|
voip.delegate.handleCallEnded(this);
|
||||||
fireCallEvent(CallEvent.kHangup);
|
fireCallEvent(CallEvent.kHangup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1432,7 +1431,7 @@ class CallSession {
|
||||||
/// [version] is the version of the VoIP specification this message adheres to. This specification is version 1.
|
/// [version] is the version of the VoIP specification this message adheres to. This specification is version 1.
|
||||||
/// [party_id] The party ID for call, Can be set to client.deviceId.
|
/// [party_id] The party ID for call, Can be set to client.deviceId.
|
||||||
Future<String?> sendCallReject(
|
Future<String?> sendCallReject(
|
||||||
Room room, String callId, int lifetime, String party_id,
|
Room room, String callId, int lifetime, String party_id, String? reason,
|
||||||
{String version = voipProtoVersion, String? txid}) async {
|
{String version = voipProtoVersion, String? txid}) async {
|
||||||
txid ??= 'txid${DateTime.now().millisecondsSinceEpoch}';
|
txid ??= 'txid${DateTime.now().millisecondsSinceEpoch}';
|
||||||
|
|
||||||
|
|
@ -1440,6 +1439,7 @@ class CallSession {
|
||||||
'call_id': callId,
|
'call_id': callId,
|
||||||
'party_id': party_id,
|
'party_id': party_id,
|
||||||
if (groupCallId != null) 'conf_id': groupCallId,
|
if (groupCallId != null) 'conf_id': groupCallId,
|
||||||
|
if (reason != null) 'reason': reason,
|
||||||
'version': version,
|
'version': version,
|
||||||
'lifetime': lifetime,
|
'lifetime': lifetime,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,12 @@ abstract class WebRTCDelegate {
|
||||||
void stopRingtone();
|
void stopRingtone();
|
||||||
void handleNewCall(CallSession session);
|
void handleNewCall(CallSession session);
|
||||||
void handleCallEnded(CallSession session);
|
void handleCallEnded(CallSession session);
|
||||||
|
void handleMissedCall(CallSession session);
|
||||||
void handleNewGroupCall(GroupCall groupCall);
|
void handleNewGroupCall(GroupCall groupCall);
|
||||||
void handleGroupCallEnded(GroupCall groupCall);
|
void handleGroupCallEnded(GroupCall groupCall);
|
||||||
|
|
||||||
bool get isBackgroud;
|
bool get isBackgroud;
|
||||||
bool get isWeb;
|
bool get isWeb;
|
||||||
|
bool get canHandleNewCall => true;
|
||||||
}
|
}
|
||||||
|
|
||||||
class VoIP {
|
class VoIP {
|
||||||
|
|
@ -200,10 +200,20 @@ class VoIP {
|
||||||
newCall.opponentDeviceId = deviceId;
|
newCall.opponentDeviceId = deviceId;
|
||||||
newCall.opponentSessionId = content['sender_session_id'];
|
newCall.opponentSessionId = content['sender_session_id'];
|
||||||
|
|
||||||
|
if (!delegate.canHandleNewCall &&
|
||||||
|
(confId == null || confId != currentGroupCID)) {
|
||||||
|
Logs().v(
|
||||||
|
'[VOIP] onCallInvite: canRespondNewCalls is false, maybe user is busy.');
|
||||||
|
await newCall.reject(reason: 'busy', shouldEmit: false);
|
||||||
|
delegate.handleMissedCall(newCall);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final offer = RTCSessionDescription(
|
final offer = RTCSessionDescription(
|
||||||
content['offer']['sdp'],
|
content['offer']['sdp'],
|
||||||
content['offer']['type'],
|
content['offer']['type'],
|
||||||
);
|
);
|
||||||
|
|
||||||
await newCall.initWithInvite(
|
await newCall.initWithInvite(
|
||||||
callType, offer, sdpStreamMetadata, lifetime, confId != null);
|
callType, offer, sdpStreamMetadata, lifetime, confId != null);
|
||||||
|
|
||||||
|
|
@ -223,7 +233,9 @@ class VoIP {
|
||||||
///TODO: notify the callkeep that the call is incoming.
|
///TODO: notify the callkeep that the call is incoming.
|
||||||
}
|
}
|
||||||
// Play ringtone
|
// Play ringtone
|
||||||
delegate.playRingtone();
|
if (confId == null) {
|
||||||
|
delegate.playRingtone();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> onCallAnswer(
|
Future<void> onCallAnswer(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue