fix: prevent duplicate SIP registration (module-level guard), extract real caller number from X-CALLERNO header

This commit is contained in:
2026-03-18 08:33:45 +05:30
parent dfc4a0cd44
commit 125aeae41c
2 changed files with 17 additions and 12 deletions

View File

@@ -223,10 +223,17 @@ export class SIPClient {
}
private extractCallerNumber(session: RTCSession): string {
// Try P-Asserted-Identity header first (most reliable for real caller ID)
try {
const request = session.direction === 'incoming' ? (session as any)._request : null;
if (request) {
// Ozonetel sends the real caller number in X-CALLERNO header
const xCallerNo = request.getHeader('X-CALLERNO');
if (xCallerNo) {
// Remove leading 0s or country code prefix (00919... → 919...)
const cleaned = xCallerNo.replace(/^0+/, '');
return cleaned;
}
// Check P-Asserted-Identity
const pai = request.getHeader('P-Asserted-Identity');
if (pai) {
@@ -241,11 +248,11 @@ export class SIPClient {
if (match) return match[1];
}
// Check X-Original-CallerID (custom header some PBX systems use)
// Check X-Original-CallerID
const xCid = request.getHeader('X-Original-CallerID');
if (xCid) return xCid;
// Check From header display name (sometimes contains the real number)
// Check From header display name
const fromDisplay = request.from?.display_name;
if (fromDisplay && /^\+?\d{7,}$/.test(fromDisplay)) {
return fromDisplay;