diff --git a/CHANGELOG.md b/CHANGELOG.md index fdd5e085..23ec68e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/api/index.ts b/src/api/index.ts index 27b1cb44..fbad1c00 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -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' @@ -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) { diff --git a/src/api/sip.ts b/src/api/sip.ts index a23a136c..77b1d3b2 100644 --- a/src/api/sip.ts +++ b/src/api/sip.ts @@ -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' @@ -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) diff --git a/src/stores/callStore2.ts b/src/stores/callStore2.ts index df1bff3c..2637fb15 100644 --- a/src/stores/callStore2.ts +++ b/src/stores/callStore2.ts @@ -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 } diff --git a/src/utils/PushNotification-parse.ts b/src/utils/PushNotification-parse.ts index c5ddee01..68ec55c6 100644 --- a/src/utils/PushNotification-parse.ts +++ b/src/utils/PushNotification-parse.ts @@ -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 }, @@ -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()