Improved handling of call auto-rejection

This commit is contained in:
Juha Heinanen
2022-02-22 10:14:50 +02:00
parent 7594834254
commit cab84308a3
2 changed files with 32 additions and 11 deletions

View File

@ -175,7 +175,13 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev,
len = re_snprintf(event_buf, sizeof event_buf, "registering failed,%s", prm);
break;
case UA_EVENT_CALL_INCOMING:
len = re_snprintf(event_buf, sizeof event_buf, "call incoming");
if (uag_call_count() > 1) {
LOGD("auto-rejecting call from %s\n", prm);
ua_hangup(ua, call, 486, "Busy Here");
len = re_snprintf(event_buf, sizeof event_buf, "call rejected,%s", prm);
} else {
len = re_snprintf(event_buf, sizeof event_buf, "call incoming,%s", prm);
}
break;
case UA_EVENT_CALL_OUTGOING:
len = re_snprintf(event_buf, sizeof event_buf, "call outgoing");

View File

@ -565,7 +565,7 @@ class BaresipService: Service() {
}
val call = Call.ofCallp(callp)
if (call == null && callp != "0" && ev[0] != "call incoming") {
if (call == null && callp != "0" && ev[0] != "call incoming" && ev[0] != "call rejected") {
Log.w(TAG, "uaEvent $event did not find call $callp")
return
}
@ -635,15 +635,17 @@ class BaresipService: Service() {
return
}
"call incoming" -> {
val peerUri = Api.call_peeruri(callp)
if (Call.calls().size > 0 ||
!Utils.checkPermissions(this, arrayOf(Manifest.permission.RECORD_AUDIO))) {
Log.d(TAG, "Auto-rejecting incoming call $uap/$callp/$peerUri")
Api.ua_hangup(uap, callp, 486, "Busy Here")
playUnInterrupted(R.raw.callwaiting, 1)
if (!Utils.isVisible())
return
newEvent = "call rejected"
val peerUri = ev[1]
if (!Utils.checkPermissions(this, arrayOf(Manifest.permission.RECORD_AUDIO))) {
toast(getString(R.string.no_calls))
if (ua.account.callHistory) {
NewCallHistory.add(NewCallHistory(aor, peerUri, "in"))
NewCallHistory.save()
ua.account.missedCalls = true
}
if (!isMainVisible)
return
newEvent = "call rejected"
} else {
Log.d(TAG, "Incoming call $uap/$callp/$peerUri")
Call(callp, ua, peerUri, "in", "incoming",
@ -724,6 +726,19 @@ class BaresipService: Service() {
return
}
}
"call rejected" -> {
playUnInterrupted(R.raw.callwaiting, 1)
if (ua.account.callHistory) {
NewCallHistory.add(NewCallHistory(aor, ev[1], "in"))
NewCallHistory.save()
ua.account.missedCalls = true
if (!isMainVisible)
return
newEvent = "call rejected"
} else {
return
}
}
"call answered" -> {
stopMediaPlayer()
if (call!!.status == "incoming")