diff --git a/lib/Config.js b/lib/Config.js index 67ae638a8..18fcdbc1a 100644 --- a/lib/Config.js +++ b/lib/Config.js @@ -32,9 +32,10 @@ exports.settings = { no_answer_timeout : 60, // Registration parameters. - register : true, - register_expires : 600, - registrar_server : null, + register : true, + register_expires : 600, + register_from_tag_trail : '', + registrar_server : null, // Connection options. sockets : null, @@ -282,6 +283,16 @@ const checks = { } }, + register_from_tag_trail(register_from_tag_trail) + { + if (typeof register_from_tag_trail === 'function') + { + return register_from_tag_trail; + } + + return String(register_from_tag_trail); + }, + registrar_server(registrar_server) { if (!/^sip:/i.test(registrar_server)) diff --git a/lib/Registrator.js b/lib/Registrator.js index 2c889741e..f47114902 100644 --- a/lib/Registrator.js +++ b/lib/Registrator.js @@ -49,7 +49,7 @@ module.exports = class Registrator // Contents of the sip.instance Contact header parameter. this._sipInstance = `""`; - + this._contact += `;reg-id=${this._reg_id}`; this._contact += `;+sip.instance=${this._sipInstance}`; } @@ -109,11 +109,26 @@ module.exports = class Registrator ${this._contact};expires=${this._expires}${this._extraContactParams}`); extraHeaders.push(`Expires: ${this._expires}`); + let fromTag = Utils.newTag(); + + if (this._ua.configuration.register_from_tag_trail) + { + if (typeof this._ua.configuration.register_from_tag_trail === 'function') + { + fromTag += this._ua.configuration.register_from_tag_trail(); + } + else + { + fromTag += this._ua.configuration.register_from_tag_trail; + } + } + const request = new SIPMessage.OutgoingRequest( JsSIP_C.REGISTER, this._registrar, this._ua, { - 'to_uri' : this._to_uri, - 'call_id' : this._call_id, - 'cseq' : (this._cseq += 1) + 'to_uri' : this._to_uri, + 'call_id' : this._call_id, + 'cseq' : (this._cseq += 1), + 'from_tag' : fromTag }, extraHeaders); const request_sender = new RequestSender(this._ua, request, { diff --git a/lib/UA.d.ts b/lib/UA.d.ts index b7db28e83..efc451ba1 100644 --- a/lib/UA.d.ts +++ b/lib/UA.d.ts @@ -40,6 +40,7 @@ export interface UAConfiguration { ha1?: string; register?: boolean; register_expires?: number; + register_from_tag_trail?: string | function() : string; registrar_server?: string; use_preloaded_route?: boolean; user_agent?: string;