diff --git a/README.md b/README.md index 714ed2c1..ea92c187 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,8 @@ var eventHandlers = { var options = { 'eventHandlers' : eventHandlers, - 'mediaConstraints' : { 'audio': true, 'video': true } + 'mediaConstraints' : { 'audio': true, 'video': true }, + 'callId' : 'a84b4c76e66710' }; var session = ua.call('sip:bob@example.com', options); diff --git a/lib/Config.js b/lib/Config.js index 46f929e4..7c8daf5f 100644 --- a/lib/Config.js +++ b/lib/Config.js @@ -21,6 +21,8 @@ exports.settings = { // SIP instance id (GRUU). instance_id : null, + // Default Call-ID for REGISTER. + call_id : null, // Preloaded SIP Route header field. use_preloaded_route : false, @@ -204,6 +206,10 @@ const checks = { return instance_id; } }, + call_id(call_id) + { + return String(call_id); + }, no_answer_timeout(no_answer_timeout) { diff --git a/lib/Message.d.ts b/lib/Message.d.ts index 8ee3685c..36315304 100644 --- a/lib/Message.d.ts +++ b/lib/Message.d.ts @@ -27,6 +27,7 @@ export interface SendMessageOptions extends ExtraHeaders { eventHandlers?: Partial; fromUserName?: string; fromDisplayName?: string; + callId?: string; } export class Message extends EventEmitter { diff --git a/lib/Message.js b/lib/Message.js index daadbc5c..2f1cfaf5 100644 --- a/lib/Message.js +++ b/lib/Message.js @@ -67,6 +67,10 @@ module.exports = class Message extends EventEmitter const contentType = options.contentType || 'text/plain'; const requestParams = {}; + if (options.callId !== undefined && options.callId !== null) + { + requestParams.call_id = String(options.callId); + } if (options.fromUserName) { diff --git a/lib/Options.js b/lib/Options.js index 86b28882..0845c561 100644 --- a/lib/Options.js +++ b/lib/Options.js @@ -64,6 +64,12 @@ module.exports = class Options extends EventEmitter const extraHeaders = Utils.cloneArray(options.extraHeaders); const eventHandlers = Utils.cloneObject(options.eventHandlers); const contentType = options.contentType || 'application/sdp'; + const requestParams = {}; + + if (options.callId !== undefined && options.callId !== null) + { + requestParams.call_id = String(options.callId); + } // Set event handlers. for (const event in eventHandlers) @@ -77,7 +83,7 @@ module.exports = class Options extends EventEmitter extraHeaders.push(`Content-Type: ${contentType}`); this._request = new SIPMessage.OutgoingRequest( - JsSIP_C.OPTIONS, target, this._ua, null, extraHeaders); + JsSIP_C.OPTIONS, target, this._ua, requestParams, extraHeaders); if (body) { diff --git a/lib/RTCSession.js b/lib/RTCSession.js index 762555d1..70ecd10a 100644 --- a/lib/RTCSession.js +++ b/lib/RTCSession.js @@ -341,6 +341,10 @@ module.exports = class RTCSession extends EventEmitter const anonymous = options.anonymous || false; const requestParams = { from_tag: this._from_tag }; + if (options.callId !== undefined && options.callId !== null) + { + requestParams.call_id = String(options.callId); + } this._contact = this._ua.contact.toString({ anonymous, diff --git a/lib/Registrator.js b/lib/Registrator.js index 89bcc3fb..9b71f256 100644 --- a/lib/Registrator.js +++ b/lib/Registrator.js @@ -22,7 +22,8 @@ module.exports = class Registrator this._expires = ua.configuration.register_expires; // Call-ID and CSeq values RFC3261 10.2. - this._call_id = Utils.createRandomToken(22); + this._call_id = this._ua.configuration.call_id || + Utils.createRandomToken(22); this._cseq = 0; this._to_uri = ua.configuration.uri; diff --git a/lib/UA.d.ts b/lib/UA.d.ts index 6ee4a788..6de325db 100644 --- a/lib/UA.d.ts +++ b/lib/UA.d.ts @@ -17,6 +17,7 @@ export interface CallOptions extends AnswerOptions { anonymous?: boolean; fromUserName?: string; fromDisplayName?: string; + callId?: string; } export interface UAConfiguration { @@ -41,6 +42,7 @@ export interface UAConfiguration { register?: boolean; register_expires?: number; register_from_tag_trail?: string | (() => string); + call_id?: string; registrar_server?: string; use_preloaded_route?: boolean; user_agent?: string;