Skip to content

Commit

Permalink
Fix it should answer incoming PN call after reconnecting due to PBX r…
Browse files Browse the repository at this point in the history
…estart
  • Loading branch information
tatthangcntt authored Oct 7, 2024
1 parent 86beb60 commit 38b5493
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Fix ios it should keep the call when screen is off by proximity sensor for 90 seconds (issue 891)
- Fix it should be touchable to toggle buttons in video calls (issue 897)
- Fix android it should answer call immediately with x_autoanswer (issue 908)
- Fix it should answer incoming PN call after reconnecting due to PBX restart (issue 909)
- Fix it should display call duration correctly after manually allow Notification permissions (issue 918)
- Fix it should load video when turning it on from a voice call (issue 934)
- Fix it should play RBT when make call without SDP (issue 964)
Expand Down
2 changes: 2 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { contactStore, getPartyName } from '../stores/contactStore'
import { intl } from '../stores/intl'
import { sipErrorEmitter } from '../stores/sipErrorEmitter'
import { userStore } from '../stores/userStore'
import { resetProcessedPn } from '../utils/PushNotification-parse'
import { toBoolean } from '../utils/string'
import { pbx } from './pbx'
import { sip } from './sip'
Expand Down Expand Up @@ -141,6 +142,7 @@ class Api {
onSIPConnectionStopped = (e: { reason: string; response: string }) => {
const s = getAuthStore()
console.log('SIP PN debug: set sipState failure stopped')
resetProcessedPn()
s.sipState = 'failure'
s.sipTotalFailure += 1
if (s.sipTotalFailure > 3) {
Expand Down
2 changes: 2 additions & 0 deletions src/api/sip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { getCallStore } from '../stores/callStore'
import { cancelRecentPn } from '../stores/cancelRecentPn'
import { chatStore } from '../stores/chatStore'
import type { ParsedPn } from '../utils/PushNotification-parse'
import { resetProcessedPn } from '../utils/PushNotification-parse'
import { toBoolean } from '../utils/string'
import { waitTimeout } from '../utils/waitTimeout'
import { getCameraSourceIds } from './getCameraSourceId'
Expand Down Expand Up @@ -277,6 +278,7 @@ export class SIP extends EventEmitter {

connect = async (o: SipLoginOption, a: AccountUnique) => {
console.log('SIP PN debug: call sip.stopWebRTC in sip.connect')
resetProcessedPn()
this.phone?._removeEventListenerPhoneStatusChange?.()
this.stopWebRTC()
const phone = await this.init(o)
Expand Down
5 changes: 5 additions & 0 deletions src/stores/callStore2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,11 @@ export class CallStore {
}
private callkeepUuidPending = ''
startCall: MakeCallFn = async (number: string, ...args) => {
// Make sure sip is ready before make call
if (getAuthStore().sipState !== 'success') {
return
}

if (!(await permForCall())) {
return
}
Expand Down
12 changes: 10 additions & 2 deletions src/utils/PushNotification-parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,14 @@ export const parseNotificationData = (raw?: object) => {
}

const isNoU = (v: unknown) => v === null || v === undefined
const androidAlreadyProccessedPn: { [k: string]: boolean } = {}
let androidAlreadyProccessedPn: { [k: string]: boolean } = {}

// after pbx server reset, call id (number) on the server side will be reset to 1, 2, 3...
// if the cache contain those ids previously, the new calls will be rejected
export const resetProcessedPn = () => {
getCallStore().callkeepActionMap = {}
androidAlreadyProccessedPn = {}
}

export const parse = async (
raw?: { [k: string]: unknown },
Expand Down Expand Up @@ -301,9 +308,10 @@ export const parse = async (
// also we forked fcm to insert callkeepUuid there as well
// then this should not happen
if (!n.callkeepUuid) {
console.log(
console.error(
`SIP PN debug: PushNotification-parse got pnId=${n.id} without callkeepUuid`,
)
return
}
const cs = getCallStore()

Expand Down

0 comments on commit 38b5493

Please sign in to comment.