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
+7 -1
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); len = re_snprintf(event_buf, sizeof event_buf, "registering failed,%s", prm);
break; break;
case UA_EVENT_CALL_INCOMING: 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; break;
case UA_EVENT_CALL_OUTGOING: case UA_EVENT_CALL_OUTGOING:
len = re_snprintf(event_buf, sizeof event_buf, "call outgoing"); len = re_snprintf(event_buf, sizeof event_buf, "call outgoing");
@@ -565,7 +565,7 @@ class BaresipService: Service() {
} }
val call = Call.ofCallp(callp) 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") Log.w(TAG, "uaEvent $event did not find call $callp")
return return
} }
@@ -635,13 +635,15 @@ class BaresipService: Service() {
return return
} }
"call incoming" -> { "call incoming" -> {
val peerUri = Api.call_peeruri(callp) val peerUri = ev[1]
if (Call.calls().size > 0 || if (!Utils.checkPermissions(this, arrayOf(Manifest.permission.RECORD_AUDIO))) {
!Utils.checkPermissions(this, arrayOf(Manifest.permission.RECORD_AUDIO))) { toast(getString(R.string.no_calls))
Log.d(TAG, "Auto-rejecting incoming call $uap/$callp/$peerUri") if (ua.account.callHistory) {
Api.ua_hangup(uap, callp, 486, "Busy Here") NewCallHistory.add(NewCallHistory(aor, peerUri, "in"))
playUnInterrupted(R.raw.callwaiting, 1) NewCallHistory.save()
if (!Utils.isVisible()) ua.account.missedCalls = true
}
if (!isMainVisible)
return return
newEvent = "call rejected" newEvent = "call rejected"
} else { } else {
@@ -724,6 +726,19 @@ class BaresipService: Service() {
return 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" -> { "call answered" -> {
stopMediaPlayer() stopMediaPlayer()
if (call!!.status == "incoming") if (call!!.status == "incoming")