Fork of FusionPBX but with LDAP kinda working
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
186 KiB

  1. /*
  2. * SIP version 0.7.8
  3. * Copyright (c) 2014-2017 Junction Networks, Inc <http://www.onsip.com>
  4. * Homepage: http://sipjs.com
  5. * License: http://sipjs.com/license/
  6. *
  7. *
  8. * ~~~SIP.js contains substantial portions of JsSIP under the following license~~~
  9. * Homepage: http://jssip.net
  10. * Copyright (c) 2012-2013 José Luis Millán - Versatica <http://www.versatica.com>
  11. *
  12. * Permission is hereby granted, free of charge, to any person obtaining
  13. * a copy of this software and associated documentation files (the
  14. * "Software"), to deal in the Software without restriction, including
  15. * without limitation the rights to use, copy, modify, merge, publish,
  16. * distribute, sublicense, and/or sell copies of the Software, and to
  17. * permit persons to whom the Software is furnished to do so, subject to
  18. * the following conditions:
  19. *
  20. * The above copyright notice and this permission notice shall be
  21. * included in all copies or substantial portions of the Software.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. *
  31. * ~~~ end JsSIP license ~~~
  32. */
  33. !function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.SIP=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){function d(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function e(a){return"function"==typeof a}function f(a){return"number"==typeof a}function g(a){return"object"==typeof a&&null!==a}function h(a){return void 0===a}b.exports=d,d.EventEmitter=d,d.prototype._events=void 0,d.prototype._maxListeners=void 0,d.defaultMaxListeners=10,d.prototype.setMaxListeners=function(a){if(!f(a)||0>a||isNaN(a))throw TypeError("n must be a positive number");return this._maxListeners=a,this},d.prototype.emit=function(a){var b,c,d,f,i,j;if(this._events||(this._events={}),"error"===a&&(!this._events.error||g(this._events.error)&&!this._events.error.length)){if(b=arguments[1],b instanceof Error)throw b;throw TypeError('Uncaught, unspecified "error" event.')}if(c=this._events[a],h(c))return!1;if(e(c))switch(arguments.length){case 1:c.call(this);break;case 2:c.call(this,arguments[1]);break;case 3:c.call(this,arguments[1],arguments[2]);break;default:for(d=arguments.length,f=new Array(d-1),i=1;d>i;i++)f[i-1]=arguments[i];c.apply(this,f)}else if(g(c)){for(d=arguments.length,f=new Array(d-1),i=1;d>i;i++)f[i-1]=arguments[i];for(j=c.slice(),d=j.length,i=0;d>i;i++)j[i].apply(this,f)}return!0},d.prototype.addListener=function(a,b){var c;if(!e(b))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",a,e(b.listener)?b.listener:b),this._events[a]?g(this._events[a])?this._events[a].push(b):this._events[a]=[this._events[a],b]:this._events[a]=b,g(this._events[a])&&!this._events[a].warned){var c;c=h(this._maxListeners)?d.defaultMaxListeners:this._maxListeners,c&&c>0&&this._events[a].length>c&&(this._events[a].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[a].length),"function"==typeof console.trace&&console.trace())}return this},d.prototype.on=d.prototype.addListener,d.prototype.once=function(a,b){function c(){this.removeListener(a,c),d||(d=!0,b.apply(this,arguments))}if(!e(b))throw TypeError("listener must be a function");var d=!1;return c.listener=b,this.on(a,c),this},d.prototype.removeListener=function(a,b){var c,d,f,h;if(!e(b))throw TypeError("listener must be a function");if(!this._events||!this._events[a])return this;if(c=this._events[a],f=c.length,d=-1,c===b||e(c.listener)&&c.listener===b)delete this._events[a],this._events.removeListener&&this.emit("removeListener",a,b);else if(g(c)){for(h=f;h-->0;)if(c[h]===b||c[h].listener&&c[h].listener===b){d=h;break}if(0>d)return this;1===c.length?(c.length=0,delete this._events[a]):c.splice(d,1),this._events.removeListener&&this.emit("removeListener",a,b)}return this},d.prototype.removeAllListeners=function(a){var b,c;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[a]&&delete this._events[a],this;if(0===arguments.length){for(b in this._events)"removeListener"!==b&&this.removeAllListeners(b);return this.removeAllListeners("removeListener"),this._events={},this}if(c=this._events[a],e(c))this.removeListener(a,c);else for(;c.length;)this.removeListener(a,c[c.length-1]);return delete this._events[a],this},d.prototype.listeners=function(a){var b;return b=this._events&&this._events[a]?e(t
  34. var a;l.data.multi_header||(l.data.multi_header=[]);try{a=new l.SIP.NameAddrHeader(l.data.uri,l.data.displayName,l.data.params),delete l.data.uri,delete l.data.displayName,delete l.data.params}catch(b){a=null}l.data.multi_header.push({position:r,offset:d(),parsed:a})},function(a){a=c().trim(),'"'===a[0]&&(a=a.substring(1,a.length-1)),l.data.displayName=a},"q",{type:"literal",value:"q",description:'"q"'},function(a){l.data.params||(l.data.params={}),l.data.params.q=a},"expires",{type:"literal",value:"expires",description:'"expires"'},function(a){l.data.params||(l.data.params={}),l.data.params.expires=a},function(a){return parseInt(a.join(""))},"0",{type:"literal",value:"0",description:'"0"'},function(){return parseFloat(c())},function(a,b){l.data.params||(l.data.params={}),b=null===b?void 0:b[1],l.data.params[a.toLowerCase()]=b},"render",{type:"literal",value:"render",description:'"render"'},"session",{type:"literal",value:"session",description:'"session"'},"icon",{type:"literal",value:"icon",description:'"icon"'},"alert",{type:"literal",value:"alert",description:'"alert"'},function(){"Content_Disposition"===l.startRule&&(l.data.type=c().toLowerCase())},"handling",{type:"literal",value:"handling",description:'"handling"'},"optional",{type:"literal",value:"optional",description:'"optional"'},"required",{type:"literal",value:"required",description:'"required"'},function(a){l.data=parseInt(a.join(""))},function(){l.data=c()},"text",{type:"literal",value:"text",description:'"text"'},"image",{type:"literal",value:"image",description:'"image"'},"audio",{type:"literal",value:"audio",description:'"audio"'},"video",{type:"literal",value:"video",description:'"video"'},"application",{type:"literal",value:"application",description:'"application"'},"message",{type:"literal",value:"message",description:'"message"'},"multipart",{type:"literal",value:"multipart",description:'"multipart"'},"x-",{type:"literal",value:"x-",description:'"x-"'},function(a){l.data.value=parseInt(a.join(""))},function(a){l.data=a},function(a){l.data.event=a.toLowerCase()},function(){var a=l.data.tag;l.data=new l.SIP.NameAddrHeader(l.data.uri,l.data.displayName,l.data.params),a&&l.data.setParam("tag",a)},"tag",{type:"literal",value:"tag",description:'"tag"'},function(a){l.data.tag=a},function(a){l.data=parseInt(a.join(""))},function(a){l.data=a},function(){l.data=new l.SIP.NameAddrHeader(l.data.uri,l.data.displayName,l.data.params)},"digest",{type:"literal",value:"Digest",description:'"Digest"'},"realm",{type:"literal",value:"realm",description:'"realm"'},function(a){l.data.realm=a},"domain",{type:"literal",value:"domain",description:'"domain"'},"nonce",{type:"literal",value:"nonce",description:'"nonce"'},function(a){l.data.nonce=a},"opaque",{type:"literal",value:"opaque",description:'"opaque"'},function(a){l.data.opaque=a},"stale",{type:"literal",value:"stale",description:'"stale"'},"true",{type:"literal",value:"true",description:'"true"'},function(){l.data.stale=!0},"false",{type:"literal",value:"false",description:'"false"'},function(){l.data.stale=!1},"algorithm",{type:"literal",value:"algorithm",description:'"algorithm"'},"md5",{type:"literal",value:"MD5",description:'"MD5"'},"md5-sess",{type:"literal",value:"MD5-sess",description:'"MD5-sess"'},function(a){l.data.algorithm=a.toUpperCase()},"qop",{type:"literal",value:"qop",description:'"qop"'},"auth-int",{type:"literal",value:"auth-int",description:'"auth-int"'},"auth",{type:"literal",value:"auth",description:'"auth"'},function(a){l.data.qop||(l.data.qop=[]),l.data.qop.push(a.toLowerCase())},function(a){l.data.value=parseInt(a.join(""))},function(){var a,b;for(b=l.data.multi_header.length,a=0;b>a;a++)if(null===l.data.multi_header[a].parsed){l.data=null;break}null!==l.data?l.data=l.data.multi_header:l.data=-1},function(){var a;l.data.multi_header||(l.data.multi_header=[]);try{a=new l.SIP.NameAddrHeader(l.data.uri,l.data.displayName,l.data.params),delete l.data.uri,delete l.data.displayName,delete l.data.params}catch(b){a=null}l.data.multi_header.push({position:r,offset:d(),parsed:a})},function(){l.data=new
  35. if(i=a.Grammar.parse(l,"Record_Route"),-1===i){i=void 0;break}for(h=i.length,g=0;h>g;g++)f=i[g],b.addHeader("record-route",l.substring(f.position,f.offset)),b.headers["Record-Route"][b.getHeaders("record-route").length-1].parsed=f.parsed;break;case"call-id":case"i":b.setHeader("call-id",l),i=b.parseHeader("call-id"),i&&(b.call_id=l);break;case"contact":case"m":if(i=a.Grammar.parse(l,"Contact"),-1===i){i=void 0;break}for(h=i.length,g=0;h>g;g++)f=i[g],b.addHeader("contact",l.substring(f.position,f.offset)),b.headers.Contact[b.getHeaders("contact").length-1].parsed=f.parsed;break;case"content-length":case"l":b.setHeader("content-length",l),i=b.parseHeader("content-length");break;case"content-type":case"c":b.setHeader("content-type",l),i=b.parseHeader("content-type");break;case"cseq":b.setHeader("cseq",l),i=b.parseHeader("cseq"),i&&(b.cseq=i.value),b instanceof a.IncomingResponse&&(b.method=i.method);break;case"max-forwards":b.setHeader("max-forwards",l),i=b.parseHeader("max-forwards");break;case"www-authenticate":b.setHeader("www-authenticate",l),i=b.parseHeader("www-authenticate");break;case"proxy-authenticate":b.setHeader("proxy-authenticate",l),i=b.parseHeader("proxy-authenticate");break;case"refer-to":case"r":b.setHeader("refer-to",l),i=b.parseHeader("refer-to"),i&&(b.refer_to=i);break;default:b.setHeader(k,l),i=0}return void 0===i?{error:'error parsing header "'+k+'"'}:!0}var d;d={},d.parseMessage=function(d,e){var f,g,h,i,j,k=0,l=d.indexOf("\r\n"),m=e.getLogger("sip.parser");if(-1===l)return void m.warn("no CRLF found, not a SIP message, discarded");if(g=d.substring(0,l),j=a.Grammar.parse(g,"Request_Response"),-1===j)return void m.warn('error parsing first line of SIP message: "'+g+'"');for(j.status_code?(f=new a.IncomingResponse(e),f.status_code=j.status_code,f.reason_phrase=j.reason_phrase):(f=new a.IncomingRequest(e),f.method=j.method,f.ruri=j.uri),f.data=d,k=l+2;;){if(l=b(d,k),-2===l){i=k+2;break}if(-1===l)return void m.error("malformed message");if(j=c(f,d,k,l),j!==!0)return void m.error(j.error);k=l+2}return f.hasHeader("content-length")?(h=f.getHeader("content-length"),f.body=d.substr(i,h)):f.body=d.substring(i),f},a.Parser=d}},{}],17:[function(a,b,c){"use strict";b.exports=function(a){var b;b=function(b){var c={},d=1;this.registrar=b.configuration.registrarServer,this.expires=b.configuration.registerExpires,this.contact=b.contact.toString(),d&&(this.contact+=";reg-id="+d,this.contact+=';+sip.instance="<urn:uuid:'+b.configuration.instanceId+'>"'),this.call_id=a.Utils.createRandomToken(22),this.cseq=80,this.to_uri=b.configuration.uri,c.to_uri=this.to_uri,c.to_displayName=b.configuration.displayName,c.call_id=this.call_id,c.cseq=this.cseq,a.Utils.augment(this,a.ClientContext,[b,"REGISTER",this.registrar,{params:c}]),this.registrationTimer=null,this.registrationExpiredTimer=null,this.registered=!1,this.logger=b.getLogger("sip.registercontext")},b.prototype={register:function(b){var c,d=this;this.options=b||{},c=(this.options.extraHeaders||[]).slice(),c.push("Contact: "+this.contact+";expires="+this.expires),c.push("Allow: "+a.UA.C.ALLOWED_METHODS.toString()),this.closeHeaders=this.options.closeWithHeaders?(this.options.extraHeaders||[]).slice():[],this.receiveResponse=function(b){var c,e,f,g=b.getHeaders("contact").length;if(b.cseq===this.cseq)switch(null!==this.registrationTimer&&(a.Timers.clearTimeout(this.registrationTimer),this.registrationTimer=null),!0){case/^1[0-9]{2}$/.test(b.status_code):this.emit("progress",b);break;case/^2[0-9]{2}$/.test(b.status_code):if(this.emit("accepted",b),b.hasHeader("expires")&&(e=b.getHeader("expires")),null!==this.registrationExpiredTimer&&(a.Timers.clearTimeout(this.registrationExpiredTimer),this.registrationExpiredTimer=null),!g){this.logger.warn("no Contact header in response to REGISTER, response ignored");break}for(;g--;){if(c=b.parseHeader("contact",g),c.uri.user===this.ua.contact.uri.user){e=c.getParam("expires");break}c=null}if(!c){this.logger.warn("no Contact header pointing to us, response ignored");break}e||(e=this.expires),this.registrationTimer=a.Timers.setTimeou
  36. var a=this;this.timers.ackTimer=b.Timers.setTimeout(function(){a.status===h.STATUS_WAITING_FOR_ACK&&(a.logger.log("no ACK received for an extended period of time, terminating the call"),b.Timers.clearTimeout(a.timers.invite2xxTimer),a.sendRequest(b.C.BYE),a.terminated(null,b.C.causes.NO_ACK))},b.Timers.TIMER_H)},onReadyToReinvite:function(){var a=this.pending_actions.shift();a&&this[a.name]&&this[a.name]()},onTransportError:function(){this.status!==h.STATUS_CONFIRMED&&this.status!==h.STATUS_TERMINATED&&this.failed(null,b.C.causes.CONNECTION_ERROR)},onRequestTimeout:function(){this.status===h.STATUS_CONFIRMED?this.terminated(null,b.C.causes.REQUEST_TIMEOUT):this.status!==h.STATUS_TERMINATED&&(this.failed(null,b.C.causes.REQUEST_TIMEOUT),this.terminated(null,b.C.causes.REQUEST_TIMEOUT))},onDialogError:function(a){this.status===h.STATUS_CONFIRMED?this.terminated(a,b.C.causes.DIALOG_ERROR):this.status!==h.STATUS_TERMINATED&&(this.failed(a,b.C.causes.DIALOG_ERROR),this.terminated(a,b.C.causes.DIALOG_ERROR))},onhold:function(a){this["local"===a?"local_hold":"remote_hold"]=!0,this.emit("hold",{originator:a})},onunhold:function(a){this["local"===a?"local_hold":"remote_hold"]=!1,this.emit("unhold",{originator:a})},onmute:function(a){this.emit("muted",{audio:a.audio,video:a.video})},onunmute:function(a){this.emit("unmuted",{audio:a.audio,video:a.video})},failed:function(a,b){return this.status===h.STATUS_TERMINATED?this:(this.emit("failed",a||null,b||null),this)},rejected:function(a,b){return this.emit("rejected",a||null,b||null),this},canceled:function(){return this.emit("cancel"),this},accepted:function(a,c){return c=b.Utils.getReasonPhrase(a&&a.status_code,c),this.startTime=new Date,this.replacee&&(this.replacee.emit("replaced",this),this.replacee.terminate()),this.emit("accepted",a,c),this},terminated:function(a,b){return this.status===h.STATUS_TERMINATED?this:(this.endTime=new Date,this.close(),this.emit("terminated",a||null,b||null),this)},connecting:function(a){return this.emit("connecting",{request:a}),this}},d.desugar=function(a){return c.HTMLMediaElement&&a instanceof c.HTMLMediaElement&&(a={media:{constraints:{audio:!0,video:"VIDEO"===a.tagName},render:{remote:a}}}),a||{}},d.C=h,b.Session=d,e=function(a,c){function d(a,b){c.hasHeader(a)&&c.getHeader(a).toLowerCase().indexOf("100rel")>=0&&(g.rel100=b)}function e(){var a={extraHeaders:["Contact: "+g.contact]};g.rel100!==b.C.supported.REQUIRED&&g.progress(a),g.status=h.STATUS_WAITING_FOR_ANSWER,g.timers.userNoAnswerTimer=b.Timers.setTimeout(function(){c.reply(408),g.failed(c,b.C.causes.NO_ANSWER),g.terminated(c,b.C.causes.NO_ANSWER)},g.ua.configuration.noAnswerTimeout),f&&(g.timers.expiresTimer=b.Timers.setTimeout(function(){g.status===h.STATUS_WAITING_FOR_ANSWER&&(c.reply(487),g.failed(c,b.C.causes.EXPIRES),g.terminated(c,b.C.causes.EXPIRES))},f)),g.emit("invite",c)}var f,g=this,i=c.getHeader("Content-Type"),j=c.parseHeader("Content-Disposition");if(b.Utils.augment(this,b.ServerContext,[a,c]),b.Utils.augment(this,b.Session,[a.configuration.mediaHandlerFactory]),this.mediaHandler=this.mediaHandlerFactory(this,{RTCConstraints:{optional:[{DtlsSrtpKeyAgreement:"true"}]}}),!j&&!this.mediaHandler.hasDescription(c)||j&&"render"===j.type)this.renderbody=c.body,this.rendertype=i;else if(!this.mediaHandler.hasDescription(c)&&j&&"session"===j.type)return void c.reply(415);return this.status=h.STATUS_INVITE_RECEIVED,this.from_tag=c.from_tag,this.id=c.call_id+this.from_tag,this.request=c,this.contact=this.ua.contact.toString(),this.receiveNonInviteResponse=function(){},this.logger=a.getLogger("sip.inviteservercontext",this.id),this.ua.sessions[this.id]=this,c.hasHeader("expires")&&(f=1e3*c.getHeader("expires")),d("require",b.C.supported.REQUIRED),d("supported",b.C.supported.SUPPORTED),c.to_tag=b.Utils.newTag(),this.createDialog(c,"UAS",!0)?(this.mediaHandler&&this.mediaHandler.getRemoteStreams&&(this.getRemoteStreams=this.mediaHandler.getRemoteStreams.bind(this.mediaHandler),this.getLocalStreams=this.mediaHandler.getLocalStreams.bind(this.mediaHandler)),void(!this.mediaHandler.hasDes
  37. TIMER_M:64*d,TIMER_N:64*d,PROVISIONAL_RESPONSE_INTERVAL:6e4};return["setTimeout","clearTimeout","setInterval","clearInterval"].forEach(function(c){b[c]=function(){return a[c].apply(a,arguments)}}),b}},{}],27:[function(a,b,c){"use strict";b.exports=function(a){function b(a,b,c){var d;return d="SIP/2.0/"+(a.ua.configuration.hackViaTcp?"TCP":b.server.scheme),d+=" "+a.ua.configuration.viaHost+";branch="+c,a.ua.configuration.forceRport&&(d+=";rport"),d}var c={STATUS_TRYING:1,STATUS_PROCEEDING:2,STATUS_CALLING:3,STATUS_ACCEPTED:4,STATUS_COMPLETED:5,STATUS_TERMINATED:6,STATUS_CONFIRMED:7,NON_INVITE_CLIENT:"nict",NON_INVITE_SERVER:"nist",INVITE_CLIENT:"ict",INVITE_SERVER:"ist"},d=function(a,d,e){var f;this.type=c.NON_INVITE_CLIENT,this.transport=e,this.id="z9hG4bK"+Math.floor(1e7*Math.random()),this.request_sender=a,this.request=d,this.logger=a.ua.getLogger("sip.transaction.nict",this.id),f=b(a,e,this.id),this.request.setHeader("via",f),this.request_sender.ua.newTransaction(this)};d.prototype=Object.create(a.EventEmitter.prototype),d.prototype.stateChanged=function(a){this.state=a,this.emit("stateChanged")},d.prototype.send=function(){var b=this;this.stateChanged(c.STATUS_TRYING),this.F=a.Timers.setTimeout(b.timer_F.bind(b),a.Timers.TIMER_F),this.transport.send(this.request)||this.onTransportError()},d.prototype.onTransportError=function(){this.logger.log("transport error occurred, deleting non-INVITE client transaction "+this.id),a.Timers.clearTimeout(this.F),a.Timers.clearTimeout(this.K),this.stateChanged(c.STATUS_TERMINATED),this.request_sender.ua.destroyTransaction(this),this.request_sender.onTransportError()},d.prototype.timer_F=function(){this.logger.log("Timer F expired for non-INVITE client transaction "+this.id),this.stateChanged(c.STATUS_TERMINATED),this.request_sender.ua.destroyTransaction(this),this.request_sender.onRequestTimeout()},d.prototype.timer_K=function(){this.stateChanged(c.STATUS_TERMINATED),this.request_sender.ua.destroyTransaction(this)},d.prototype.receiveResponse=function(b){var d=this,e=b.status_code;if(200>e)switch(this.state){case c.STATUS_TRYING:case c.STATUS_PROCEEDING:this.stateChanged(c.STATUS_PROCEEDING),this.request_sender.receiveResponse(b)}else switch(this.state){case c.STATUS_TRYING:case c.STATUS_PROCEEDING:this.stateChanged(c.STATUS_COMPLETED),a.Timers.clearTimeout(this.F),408===e?this.request_sender.onRequestTimeout():this.request_sender.receiveResponse(b),this.K=a.Timers.setTimeout(d.timer_K.bind(d),a.Timers.TIMER_K);break;case c.STATUS_COMPLETED:}};var e=function(a,d,e){var f,g=this;this.type=c.INVITE_CLIENT,this.transport=e,this.id="z9hG4bK"+Math.floor(1e7*Math.random()),this.request_sender=a,this.request=d,this.logger=a.ua.getLogger("sip.transaction.ict",this.id),f=b(a,e,this.id),this.request.setHeader("via",f),this.request_sender.ua.newTransaction(this),this.request.cancel=function(a,b){b=(b||[]).slice();for(var c=b.length,d=null,e=0;c>e;e++)d=(d||"")+b[e].trim()+"\r\n";g.cancel_request(g,a,d)}};e.prototype=Object.create(a.EventEmitter.prototype),e.prototype.stateChanged=function(a){this.state=a,this.emit("stateChanged")},e.prototype.send=function(){var b=this;this.stateChanged(c.STATUS_CALLING),this.B=a.Timers.setTimeout(b.timer_B.bind(b),a.Timers.TIMER_B),this.transport.send(this.request)||this.onTransportError()},e.prototype.onTransportError=function(){this.logger.log("transport error occurred, deleting INVITE client transaction "+this.id),a.Timers.clearTimeout(this.B),a.Timers.clearTimeout(this.D),a.Timers.clearTimeout(this.M),this.stateChanged(c.STATUS_TERMINATED),this.request_sender.ua.destroyTransaction(this),this.state!==c.STATUS_ACCEPTED&&this.request_sender.onTransportError()},e.prototype.timer_M=function(){this.logger.log("Timer M expired for INVITE client transaction "+this.id),this.state===c.STATUS_ACCEPTED&&(a.Timers.clearTimeout(this.B),this.stateChanged(c.STATUS_TERMINATED),this.request_sender.ua.destroyTransaction(this))},e.prototype.timer_B=function(){this.logger.log("Timer B expired for INVITE client transaction "+this.id),this.state===c.STATUS_CALLING&&(this.stat
  38. j.registrarServer||(i=j.uri.clone(),i.user=null,j.registrarServer=i),j.noAnswerTimeout=1e3*j.noAnswerTimeout,j.hackIpInContact&&("boolean"==typeof j.hackIpInContact?j.viaHost=b.Utils.getRandomTestNetIP():"string"==typeof j.hackIpInContact&&(j.viaHost=j.hackIpInContact)),j.hackWssInTransport&&(j.contactTransport="wss"),this.contact={pub_gruu:null,temp_gruu:null,uri:new b.URI("sip",b.Utils.createRandomToken(8),j.viaHost,null,{transport:j.contactTransport}),toString:function(a){a=a||{};var b=a.anonymous||null,c=a.outbound||null,d="<";return d+=b?(this.temp_gruu||"sip:anonymous@anonymous.invalid;transport="+j.contactTransport).toString():(this.pub_gruu||this.uri).toString(),c&&(d+=";ob"),d+=">"}},b.Utils.optionsOverride(j,"media","mediaConstraints",!0,this.logger);var m={};for(e in j)m[e]={value:j[e],writable:"register"===e||"custom"===e,configurable:!1};Object.defineProperties(this.configuration,m),this.logger.log("configuration parameters after validation:");for(e in j)switch(e){case"uri":case"registrarServer":case"mediaHandlerFactory":this.logger.log("\xb7 "+e+": "+j[e]);break;case"password":this.logger.log("\xb7 "+e+": NOT SHOWN");break;default:this.logger.log("\xb7 "+e+": "+JSON.stringify(j[e]))}},e.prototype.getConfigurationCheck=function(){return{mandatory:{},optional:{uri:function(a){var c;return/^sip:/i.test(a)||(a=b.C.SIP+":"+a),c=b.URI.parse(a),c&&c.user?c:void 0},wsServers:function(a){var c,d,e;if("string"==typeof a)a=[{ws_uri:a}];else{if(!(a instanceof Array))return;for(d=a.length,c=0;d>c;c++)"string"==typeof a[c]&&(a[c]={ws_uri:a[c]})}if(0===a.length)return!1;for(d=a.length,c=0;d>c;c++){if(!a[c].ws_uri)return;if(a[c].weight&&!Number(a[c].weight))return;if(e=b.Grammar.parse(a[c].ws_uri,"absoluteURI"),-1===e)return;if(["wss","ws","udp"].indexOf(e.scheme)<0)return;a[c].sip_uri="<sip:"+e.host+(e.port?":"+e.port:"")+";transport="+e.scheme.replace(/^wss$/i,"ws")+";lr>",a[c].weight||(a[c].weight=0),a[c].status=0,a[c].scheme=e.scheme.toUpperCase()}return a},authorizationUser:function(a){return-1===b.Grammar.parse('"'+a+'"',"quoted_string")?void 0:a},connectionRecoveryMaxInterval:function(a){var c;return b.Utils.isDecimal(a)&&(c=Number(a),c>0)?c:void 0},connectionRecoveryMinInterval:function(a){var c;return b.Utils.isDecimal(a)&&(c=Number(a),c>0)?c:void 0},displayName:function(a){return-1===b.Grammar.parse('"'+a+'"',"displayName")?void 0:a},hackViaTcp:function(a){return"boolean"==typeof a?a:void 0},hackIpInContact:function(a){return"boolean"==typeof a?a:"string"==typeof a&&-1!==b.Grammar.parse(a,"host")?a:void 0},iceCheckingTimeout:function(a){return b.Utils.isDecimal(a)?Math.max(500,a):void 0},hackWssInTransport:function(a){return"boolean"==typeof a?a:void 0},hackAllowUnregisteredOptionTags:function(a){return"boolean"==typeof a?a:void 0},hackCleanJitsiSdpImageattr:function(a){return"boolean"==typeof a?a:void 0},hackStripTcp:function(a){return"boolean"==typeof a?a:void 0},contactTransport:function(a){return"string"==typeof a?a:void 0},forceRport:function(a){return"boolean"==typeof a?a:void 0},instanceId:function(a){return"string"==typeof a?(/^uuid:/i.test(a)&&(a=a.substr(5)),-1===b.Grammar.parse(a,"uuid")?void 0:a):void 0},keepAliveInterval:function(a){var c;return b.Utils.isDecimal(a)&&(c=Number(a),c>0)?c:void 0},extraSupported:function(a){var b,c;if(a instanceof Array){for(c=a.length,b=0;c>b;b++)if("string"!=typeof a[b])return;return a}},noAnswerTimeout:function(a){var c;return b.Utils.isDecimal(a)&&(c=Number(a),c>0)?c:void 0},password:function(a){return String(a)},rel100:function(a){return a===b.C.supported.REQUIRED?b.C.supported.REQUIRED:a===b.C.supported.SUPPORTED?b.C.supported.SUPPORTED:b.C.supported.UNSUPPORTED},replaces:function(a){return a===b.C.supported.REQUIRED?b.C.supported.REQUIRED:a===b.C.supported.SUPPORTED?b.C.supported.SUPPORTED:b.C.supported.UNSUPPORTED},register:function(a){return"boolean"==typeof a?a:void 0},registerExpires:function(a){var c;return b.Utils.isDecimal(a)&&(c=Number(a),c>0)?c:void 0},registrarServer:function(a){var c;if("string"==typeof a)return/^sip:/i.test(a)||(a=b.C.SIP+":"+a),c=b.