/*! twilio-video.js 1.2.2

The following license applies to all parts of this software except as
documented below.

    Copyright (c) 2015, Twilio, inc.
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are
    met:

      1. Redistributions of source code must retain the above copyright
         notice, this list of conditions and the following disclaimer.

      2. Redistributions in binary form must reproduce the above copyright
         notice, this list of conditions and the following disclaimer in
         the documentation and/or other materials provided with the
         distribution.

      3. Neither the name of Twilio nor the names of its contributors may
         be used to endorse or promote products derived from this software
         without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

This software includes SIP.js under the following license.

    Copyright (c) 2014 Junction Networks, Inc. <http://www.onsip.com>

    License: The MIT License

    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
    "Software"), to deal in the Software without restriction, including
    without limitation the rights to use, copy, modify, merge, publish,
    distribute, sublicense, and/or sell copies of the Software, and to
    permit persons to whom the Software is furnished to do so, subject to
    the following conditions:

    The above copyright notice and this permission notice shall be
    included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
    LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
    OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

SIP.js contains substantial portions of the JsSIP software under the following
license.

    Copyright (c) 2012-2013 José Luis Millán - Versatica <http://www.versatica.com>

    License: The MIT License

    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
    "Software"), to deal in the Software without restriction, including
    without limitation the rights to use, copy, modify, merge, publish,
    distribute, sublicense, and/or sell copies of the Software, and to
    permit persons to whom the Software is furnished to do so, subject to
    the following conditions:

    The above copyright notice and this permission notice shall be
    included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
    LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
    OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 */
(function(root){var bundle=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";var CancelablePromise=require("./util/cancelablepromise");function createCancelableRoomPromise(getLocalTracks,createLocalParticipant,createRoomSignaling,createRoom){var cancelableRoomSignalingPromise;var cancelationError=new Error("Canceled");return new CancelablePromise(function onCreate(resolve,reject,isCanceled){var localParticipant;getLocalTracks(function getLocalTracksSucceeded(localTracks){if(isCanceled()){return CancelablePromise.reject(cancelationError)}localParticipant=createLocalParticipant(localTracks);return createRoomSignaling(localParticipant).then(function createRoomSignalingSucceeded(getCancelableRoomSignalingPromise){if(isCanceled()){throw cancelationError}cancelableRoomSignalingPromise=getCancelableRoomSignalingPromise();return cancelableRoomSignalingPromise})}).then(function roomSignalingConnected(roomSignaling){if(isCanceled()){roomSignaling.disconnect();throw cancelationError}resolve(createRoom(localParticipant,roomSignaling))}).catch(function onError(error){reject(error)})},function onCancel(){if(cancelableRoomSignalingPromise){cancelableRoomSignalingPromise.cancel()}})}module.exports=createCancelableRoomPromise},{"./util/cancelablepromise":49}],2:[function(require,module,exports){"use strict";var CancelablePromise=require("./util/cancelablepromise");var createCancelableRoomPromise=require("./cancelableroompromise");var createLocalTracks=require("./createlocaltracks");var ConstantIceServerSource=require("./iceserversource/constant");var constants=require("./util/constants");var Room=require("./room");var E=require("./util/constants").typeErrors;var guessBrowser=require("./util").guessBrowser;var LocalAudioTrack=require("./media/track/localaudiotrack");var LocalParticipant=require("./localparticipant");var LocalVideoTrack=require("./media/track/localvideotrack");var Log=require("./util/log");var MediaStreamTrack=require("@twilio/webrtc").MediaStreamTrack;var NTSIceServerSource=require("./iceserversource/nts");var SignalingV2=require("./signaling/v2");var util=require("./util");var connectCalls=0;var didPrintSafariWarning=false;function connect(token,options){options=Object.assign({createLocalTracks:createLocalTracks,environment:constants.DEFAULT_ENVIRONMENT,insights:true,LocalAudioTrack:LocalAudioTrack,LocalParticipant:LocalParticipant,LocalVideoTrack:LocalVideoTrack,MediaStreamTrack:MediaStreamTrack,logLevel:constants.DEFAULT_LOG_LEVEL,name:null,realm:constants.DEFAULT_REALM,signaling:SignalingV2},options);options=Object.assign({wsServer:constants.WS_SERVER(options.environment,options.realm)},options);var logLevels=util.buildLogLevels(options.logLevel);var logComponentName="[connect #"+ ++connectCalls+"]";try{var log=new Log("default",logComponentName,logLevels)}catch(error){return CancelablePromise.reject(error)}options.log=log;if(guessBrowser()==="safari"&&!didPrintSafariWarning&&(log.logLevel!=="error"&&log.logLevel!=="off")){didPrintSafariWarning=true;log.warn(["This release of twilio-video.js includes experimental support for",'Safari 11 and newer. Support for Safari is "experimental" because,',"at the time of writing, Safari does not support VP8. This means you","may experience codec issues in Group Rooms. You may also experience","codec issues in Peer-to-Peer (P2P) Rooms containing Android- or","iOS-based Participants who do not support H.264. However, P2P Rooms","with browser-based Participants should work. Please test this release","and report any issues to https://github.com/twilio/twilio-video.js"].join(" "))}if(typeof token!=="string"){return CancelablePromise.reject(new E.INVALID_TYPE("token","string"))}if("tracks"in options){if(!Array.isArray(options.tracks)){return CancelablePromise.reject(new E.INVALID_TYPE("options.tracks","Array of LocalAudioTrack, LocalVideoTrack or MediaStreamTrack"))}try{options.tracks=options.tracks.map(function(track){return util.asLocalTrack(track,options)})}catch(error){return CancelablePromise.reject(error)}}var Signaling=options.signaling;var signaling=new Signaling(options.wsServer,options);log.info("Connecting to a Room");log.debug("Options:",options);var iceServerSource=Array.isArray(options.iceServers)?new ConstantIceServerSource(options.iceServers):typeof options.iceServers==="object"?options.iceServers:new NTSIceServerSource(token,options);var cancelableRoomPromise=createCancelableRoomPromise(getLocalTracks.bind(null,options),createLocalParticipant.bind(null,signaling,log,options),createRoomSignaling.bind(null,token,options,signaling,iceServerSource),createRoom.bind(null,options));cancelableRoomPromise.then(function(room){log.info("Connected to Room:",room.toString());log.info("Room name:",room.name);log.debug("Room:",room);return room},function(error){if(iceServerSource.isStarted){iceServerSource.stop()}if(cancelableRoomPromise._isCanceled){log.info("Attempt to connect to a Room was canceled")}else{log.info("Error while connecting to a Room:",error)}});return cancelableRoomPromise}var LogLevel={debug:"debug",info:"info",warn:"warn",error:"error",off:"off"};function createLocalParticipant(signaling,log,options,localTracks){var localParticipantSignaling=signaling.createLocalParticipantSignaling();log.debug("Creating a new LocalParticipant:",localParticipantSignaling);return new options.LocalParticipant(localParticipantSignaling,localTracks,options)}function createRoom(options,localParticipant,roomSignaling){var room=new Room(localParticipant,roomSignaling,options);var log=options.log;log.debug("Creating a new Room:",room);roomSignaling.on("stateChanged",function stateChanged(){log.info("Disconnected from Room:",room.toString());roomSignaling.removeListener("stateChanged",stateChanged)});return room}function createRoomSignaling(token,options,signaling,iceServerSource,localParticipant){var log=options.log;log.info("Getting ICE servers");log.debug("Options:",options);return iceServerSource.start().then(function(iceServers){var roomSignalingParams={token:token};log.info("Got ICE servers");log.debug("ICE servers:",iceServers);options.iceServers=iceServers;log.debug("Creating a new RoomSignaling");log.debug("RoomSignaling params:",roomSignalingParams);return signaling.connect(localParticipant._signaling,token,iceServerSource,options)})}function getLocalTracks(options,handleLocalTracks){var log=options.log;options.shouldStopLocalTracks=!options.tracks;if(options.shouldStopLocalTracks){log.info("LocalTracks were not provided, so they will be acquired "+"automatically before connecting to the Room. LocalTracks will "+"be released if connecting to the Room fails or if the Room "+"is disconnected")}else{log.info("Getting LocalTracks");log.debug("Options:",options)}return options.createLocalTracks(options).then(function getLocalTracksSucceeded(localTracks){var promise=handleLocalTracks(localTracks);promise.catch(function handleLocalTracksFailed(){if(options.shouldStopLocalTracks){log.info("The automatically acquired LocalTracks will now be stopped");localTracks.forEach(function(track){track.stop()})}});return promise})}module.exports=connect},{"./cancelableroompromise":1,"./createlocaltracks":4,"./iceserversource/constant":6,"./iceserversource/nts":7,"./localparticipant":9,"./media/track/localaudiotrack":12,"./media/track/localvideotrack":14,"./room":19,"./signaling/v2":29,"./util":52,"./util/cancelablepromise":49,"./util/constants":50,"./util/log":55,"@twilio/webrtc":95}],3:[function(require,module,exports){"use strict";var defaultCreateLocalTracks=require("./createlocaltracks");var DEFAULT_LOG_LEVEL=require("./util/constants").DEFAULT_LOG_LEVEL;function createLocalTrack(kind,options){options=Object.assign({createLocalTracks:defaultCreateLocalTracks,logLevel:DEFAULT_LOG_LEVEL},options);var createOptions={};createOptions.logLevel=options.logLevel;delete options.logLevel;var createLocalTracks=options.createLocalTracks;delete options.createLocalTracks;createOptions[kind]=Object.keys(options).length>0?options:true;return createLocalTracks(createOptions).then(function(localTracks){return localTracks[0]})}function createLocalAudioTrack(options){return createLocalTrack("audio",options)}function createLocalVideoTrack(options){return createLocalTrack("video",options)}module.exports={audio:createLocalAudioTrack,video:createLocalVideoTrack}},{"./createlocaltracks":4,"./util/constants":50}],4:[function(require,module,exports){"use strict";var asLocalTrack=require("./util").asLocalTrack;var buildLogLevels=require("./util").buildLogLevels;var getUserMedia=require("@twilio/webrtc").getUserMedia;var LocalAudioTrack=require("./media/track/localaudiotrack");var LocalVideoTrack=require("./media/track/localvideotrack");var MediaStreamTrack=require("@twilio/webrtc").MediaStreamTrack;var Log=require("./util/log");var DEFAULT_LOG_LEVEL=require("./util/constants").DEFAULT_LOG_LEVEL;var createLocalTrackCalls=0;function createLocalTracks(options){var isAudioVideoAbsent=!(options&&("audio"in options||"video"in options));options=Object.assign({audio:isAudioVideoAbsent,getUserMedia:getUserMedia,logLevel:DEFAULT_LOG_LEVEL,LocalAudioTrack:LocalAudioTrack,LocalVideoTrack:LocalVideoTrack,MediaStreamTrack:MediaStreamTrack,Log:Log,video:isAudioVideoAbsent},options);var logComponentName="[createLocalTracks #"+ ++createLocalTrackCalls+"]";var logLevels=buildLogLevels(options.logLevel);var log=new options.Log("default",logComponentName,logLevels);if(options.audio===false&&options.video===false){log.info("Neither audio nor video requested, so returning empty LocalTracks");return Promise.resolve([])}if(options.tracks){log.info("Adding user-provided LocalTracks");log.debug("LocalTracks:",options.tracks);return Promise.resolve(options.tracks)}return options.getUserMedia({audio:options.audio,video:options.video}).then(function(mediaStream){var mediaStreamTracks=mediaStream.getAudioTracks().concat(mediaStream.getVideoTracks());log.info("Call to getUserMedia successful; got MediaStreamTracks:",mediaStreamTracks);return mediaStreamTracks.map(function(mediaStreamTrack){return asLocalTrack(mediaStreamTrack,Object.assign({log:log},options))})},function(error){log.warn("Call to getUserMedia failed:",error);throw error})}module.exports=createLocalTracks},{"./media/track/localaudiotrack":12,"./media/track/localvideotrack":14,"./util":52,"./util/constants":50,"./util/log":55,"@twilio/webrtc":95}],5:[function(require,module,exports){"use strict";var request=require("./request");var createTwilioError=require("./util/twilio-video-errors").createTwilioError;var ConfigurationAcquireFailedError=require("./util/twilio-video-errors").ConfigurationAcquireFailedError;var CONFIG_URL="https://ecs.us1.twilio.com/v1/Configuration";function getConfiguration(token,options){if(!token){throw new Error("<String>token is a required argument.")}options=Object.assign({configUrl:CONFIG_URL},options);var postData={url:options.configUrl,headers:{"X-Twilio-Token":token,"Content-Type":"application/x-www-form-urlencoded"}};if(options.body){postData.body=toQueryString(options.body)}return request.post(postData).then(function(responseText){return parseJsonTextFromECS(responseText)},function(errorText){var error=parseJsonTextFromECS(errorText);throw createTwilioError(error.code,error.message)})}function parseJsonTextFromECS(jsonText){var json=null;try{json=JSON.parse(jsonText)}catch(error){throw new ConfigurationAcquireFailedError}return json}function toQueryString(params){return Object.keys(params||{}).map(function(key){return encodeURIComponent(key)+"="+encodeURIComponent(params[key])}).join("&")}module.exports.getConfiguration=getConfiguration},{"./request":18,"./util/twilio-video-errors":57}],6:[function(require,module,exports){"use strict";var EventEmitter=require("events").EventEmitter;var inherits=require("util").inherits;var instances=0;function ConstantIceServerSource(iceServers){EventEmitter.call(this);Object.defineProperties(this,{_instance:{value:++instances},_iceServers:{enumerable:true,value:iceServers,writable:true},_isStarted:{value:false,writable:true},isStarted:{enumerable:true,get:function(){return this._isStarted}}})}inherits(ConstantIceServerSource,EventEmitter);ConstantIceServerSource.prototype.start=function start(){this._isStarted=true;return Promise.resolve(this._iceServers)};ConstantIceServerSource.prototype.stop=function stop(){this._isStarted=false};ConstantIceServerSource.prototype.toString=function toString(){return"[ConstantIceServerSource #"+this._instance+"]"};module.exports=ConstantIceServerSource},{events:112,util:116}],7:[function(require,module,exports){"use strict";var constants=require("../util/constants");var ECS=require("../ecs");var EventEmitter=require("events").EventEmitter;var inherits=require("util").inherits;var Log=require("../util/log");var TimeoutPromise=require("../util/timeoutpromise");var util=require("../util");var version=require("../../package.json").version;var instances=0;function NTSIceServerSource(token,options){EventEmitter.call(this);options=Object.assign({defaultTTL:constants.ICE_SERVERS_DEFAULT_TTL,environment:constants.DEFAULT_ENVIRONMENT,getConfiguration:ECS.getConfiguration,realm:constants.DEFAULT_REALM,timeout:constants.ICE_SERVERS_TIMEOUT_MS},options);var defaultIceServers=constants.DEFAULT_ICE_SERVERS(options.environment);var ecsServer=options.ecsServer||constants.ECS_SERVER(options.environment,options.realm);var log=options.log?options.log.createLog("default",this):new Log("default",this,util.buildLogLevels("off"));Object.defineProperties(this,{_currentPoll:{value:null,writable:true},_defaultIceServers:{value:defaultIceServers},_defaultTTL:{value:options.defaultTTL},_ecsServer:{value:ecsServer},_getConfiguration:{value:options.getConfiguration},_instance:{value:++instances},_nextPoll:{value:null,writable:true},_log:{value:log},_stopped:{value:util.defer(),writable:true},_timeout:{value:options.timeout},_token:{value:token},isStarted:{enumerable:true,get:function(){return!!this._currentPoll}}});this._log.info("Created a new NTSIceServerSource");this._log.debug("ECS server:",this._ecsServer)}inherits(NTSIceServerSource,EventEmitter);NTSIceServerSource.prototype.start=function start(){if(!this.isStarted){this._log.info("Starting");this._currentPoll=poll(this)}else{this._log.warn("Already started")}return this._currentPoll};NTSIceServerSource.prototype.stop=function stop(){if(!this.isStarted){this._log.warn("Already stopped");return}this._log.info("Stopping");this._currentPoll=null;clearTimeout(this._nextPoll);this._stopped.resolve();this._stopped=util.defer();this._log.debug("Stopped")};NTSIceServerSource.prototype.toString=function toString(){return"[NTSIceServerSource #"+this._instance+"]"};function parseECSConfig(client,config){var nts=util.getOrNull(config,"video.network_traversal_service");if(!nts){throw new Error("network_traversal_service not available")}else if(nts.warning){client._log.warn(nts.warning)}var iceServers=nts.ice_servers;if(!iceServers){throw new Error("ice_servers not available")}client._log.info("Got ICE servers: "+JSON.stringify(iceServers));var ttl=nts.ttl||client._defaultTTL;return[iceServers,ttl]}function poll(client){client._log.debug("Getting ECS configuration");var options={configUrl:client._ecsServer+"/v1/Configuration",body:{service:"video",sdk_version:version}};var alreadyStopped=new Error("Already stopped");var config=client._getConfiguration(client._token,options);var configWithTimeout=new TimeoutPromise(config,client._timeout);return Promise.race([configWithTimeout,client._stopped.promise]).then(function(config){if(!config){throw alreadyStopped}return parseECSConfig(client,config)}).catch(function(error){if(!client.isStarted){throw alreadyStopped}else if(configWithTimeout.isTimedOut){client._log.warn("Getting ICE servers took too long (using defaults)")}else{if(error.code&&Math.floor(error.code/1e4)===2){client.stop()}client._log.warn("Failed to get ICE servers (using defaults):",error)}return[client._defaultIceServers,client._defaultTTL]}).then(function(iceServersAndTTL){var iceServers=iceServersAndTTL[0];var ttl=iceServersAndTTL[1];if(client.isStarted){client._log.info("Getting ICE servers again in "+ttl+" seconds");client._nextPoll=setTimeout(function nextPoll(){if(client.isStarted){client._currentPoll=poll(client)}},(ttl-constants.ECS_TIMEOUT)*1e3)}client._iceServers=iceServers;try{client.emit("iceServers",iceServers)}catch(error){}return iceServers})}module.exports=NTSIceServerSource},{"../../package.json":117,"../ecs":5,"../util":52,"../util/constants":50,"../util/log":55,"../util/timeoutpromise":56,events:112,util:116}],8:[function(require,module,exports){"use strict";var version=require("../package.json").version;var Video={};Object.defineProperties(Video,{connect:{enumerable:true,value:require("./connect")},createLocalAudioTrack:{enumerable:true,value:require("./createlocaltrack").audio},createLocalTracks:{enumerable:true,value:require("./createlocaltracks")},createLocalVideoTrack:{enumerable:true,value:require("./createlocaltrack").video},LocalAudioTrack:{enumerable:true,value:require("./media/track/localaudiotrack")},LocalVideoTrack:{enumerable:true,value:require("./media/track/localvideotrack")},version:{enumerable:true,value:version}});module.exports=Video},{"../package.json":117,"./connect":2,"./createlocaltrack":3,"./createlocaltracks":4,"./media/track/localaudiotrack":12,"./media/track/localvideotrack":14}],9:[function(require,module,exports){"use strict";var util=require("./util");var inherits=require("util").inherits;var E=require("./util/constants").typeErrors;var LocalAudioTrack=require("./media/track/localaudiotrack");var LocalVideoTrack=require("./media/track/localvideotrack");var MediaStreamTrack=require("@twilio/webrtc").MediaStreamTrack;var Participant=require("./participant");function LocalParticipant(signaling,localTracks,options){if(!(this instanceof LocalParticipant)){return new LocalParticipant(signaling,localTracks,options)}options=Object.assign({LocalAudioTrack:LocalAudioTrack,LocalVideoTrack:LocalVideoTrack,MediaStreamTrack:MediaStreamTrack,shouldStopLocalTracks:false,tracks:localTracks},options);var tracksToStop=options.shouldStopLocalTracks?new Set(localTracks):new Set;Participant.call(this,signaling,options);Object.defineProperties(this,{_LocalAudioTrack:{value:options.LocalAudioTrack},_LocalVideoTrack:{value:options.LocalVideoTrack},_MediaStreamTrack:{value:options.MediaStreamTrack},_tracksToStop:{value:tracksToStop}})}inherits(LocalParticipant,Participant);LocalParticipant.prototype._getTrackEvents=function _getTrackEvents(){return Participant.prototype._getTrackEvents.call(this).concat([["stopped","trackStopped"]])};LocalParticipant.prototype.toString=function toString(){return"[LocalParticipant #"+this._instanceId+(this.sid?": "+this.sid:"")+"]"};LocalParticipant.prototype._handleTrackSignalingEvents=function _handleTrackSignalingEvents(){var log=this._log;if(this.state==="disconnected"){return}var signaling=this._signaling;function localTrackAdded(localTrack){signaling.addTrack(localTrack._signaling);log.info("Added a new "+util.trackClass(localTrack,true)+":",localTrack.id);log.debug(util.trackClass(localTrack,true)+":",localTrack)}function localTrackRemoved(localTrack){signaling.removeTrack(localTrack._signaling);log.info("Removed a "+util.trackClass(localTrack,true)+":",localTrack.id);log.debug(util.trackClass(localTrack,true)+":",localTrack)}this.on("trackAdded",localTrackAdded);this.on("trackRemoved",localTrackRemoved);this.tracks.forEach(localTrackAdded);var self=this;signaling.on("stateChanged",function stateChanged(state){log.debug("Transitioned to state:",state);if(state==="disconnected"){log.debug("Removing LocalTrack event listeners");signaling.removeListener("stateChanged",stateChanged);self.removeListener("trackAdded",localTrackAdded);self.removeListener("trackRemoved",localTrackRemoved);log.info("LocalParticipant disconnected. Stopping "+self._tracksToStop.size+" automatically-acquired LocalTracks");self._tracksToStop.forEach(function(track){track.stop()})}})};LocalParticipant.prototype.addTrack=function addTrack(track){return this._addTrack(util.asLocalTrack(track,{log:this._log,LocalAudioTrack:this._LocalAudioTrack,LocalVideoTrack:this._LocalVideoTrack,MediaStreamTrack:this._MediaStreamTrack}))};LocalParticipant.prototype.addTracks=function addTracks(tracks){if(!Array.isArray(tracks)){throw new E.INVALID_TYPE("tracks","Array of LocalAudioTrack, LocalVideoTrack or MediaStreamTrack")}var self=this;return tracks.reduce(function(addedTracks,track){var addedTrack=self.addTrack(track);return addedTrack?addedTracks.concat(addedTrack):addedTracks},[])};LocalParticipant.prototype.removeTrack=function removeTrack(track,stop){track=this._removeTrack(util.asLocalTrack(track,{log:this._log,LocalAudioTrack:this._LocalAudioTrack,LocalVideoTrack:this._LocalVideoTrack,MediaStreamTrack:this._MediaStreamTrack}));stop=typeof stop==="boolean"?stop:true;if(track&&stop){track.stop();this._log.info("Stopped LocalTrack:",track)}return track};LocalParticipant.prototype.removeTracks=function removeTracks(tracks,stop){if(!Array.isArray(tracks)){throw new E.INVALID_TYPE("tracks","Array of LocalAudioTrack, LocalVideoTrack or MediaStreamTrack")}var self=this;return tracks.reduce(function(removedTracks,track){var removedTrack=self.removeTrack(track,stop);return removedTrack?removedTracks.concat(removedTrack):removedTracks},[])};module.exports=LocalParticipant},{"./media/track/localaudiotrack":12,"./media/track/localvideotrack":14,"./participant":16,"./util":52,"./util/constants":50,"@twilio/webrtc":95,util:116}],10:[function(require,module,exports){"use strict";var inherits=require("util").inherits;var Track=require("./");function AudioTrack(mediaStreamTrack,signaling,options){Track.call(this,mediaStreamTrack,signaling,options)}inherits(AudioTrack,Track);AudioTrack.prototype.toString=function toString(){return"[AudioTrack #"+this._instanceId+": "+this.id+"]"};AudioTrack.prototype.attach=Track.prototype.attach;AudioTrack.prototype.detach=Track.prototype.detach;module.exports=AudioTrack},{"./":11,util:116}],11:[function(require,module,exports){"use strict";var EventEmitter=require("events").EventEmitter;var MediaStream=require("@twilio/webrtc").MediaStream;var inherits=require("util").inherits;var nInstances=0;function Track(mediaStreamTrack,signaling,options){EventEmitter.call(this);var isStarted=false;options=Object.assign({MediaStream:MediaStream},options);Object.defineProperties(this,{_attachments:{value:new Set},_instanceId:{value:++nInstances},_isStarted:{get:function(){return isStarted},set:function(_isStarted){isStarted=_isStarted}},_log:{value:options.log.createLog("media",this)},_signaling:{value:signaling},_MediaStream:{value:options.MediaStream},id:{enumerable:true,value:mediaStreamTrack.id},isEnabled:{enumerable:true,get:function(){return signaling.isEnabled}},isStarted:{get:function(){return isStarted}},kind:{enumerable:true,value:mediaStreamTrack.kind},mediaStreamTrack:{enumerable:true,value:mediaStreamTrack}});this._initialize()}Track.DISABLED="disabled";Track.ENABLED="enabled";var STARTED=Track.STARTED="started";inherits(Track,EventEmitter);Track.prototype._start=function _start(){this._log.debug("Started");this._isStarted=true;this._detachElement(this._dummyEl);this._dummyEl.oncanplay=null;this.emit(STARTED,this)};Track.prototype._initialize=function _initialize(){var self=this;this._log.debug("Initializing");this._dummyEl=this._createElement();this.mediaStreamTrack.addEventListener("ended",function onended(){self._end();self.mediaStreamTrack.removeEventListener("ended",onended)});this._dummyEl.muted=true;this._dummyEl.oncanplay=this._start.bind(this,this._dummyEl);this._reemit=function reemmit(){self.emit(self.isEnabled?"enabled":"disabled",self)};this._signaling.on("updated",this._reemit);this._attach(this._dummyEl);this._attachments.delete(this._dummyEl)};Track.prototype._end=function _end(){this._log.debug("Ended");this._signaling.removeListener("updated",this._reemit);this._detachElement(this._dummyEl);this._dummyEl.oncanplay=null};Track.prototype.attach=function attach(el){if(typeof el==="string"){el=this._selectElement(el)}else if(!el){el=this._createElement()}this._log.debug("Attempting to attach to element:",el);el=this._attach(el);return el};Track.prototype._attach=function _attach(el){var mediaStream=el.srcObject;if(!(mediaStream instanceof this._MediaStream)){mediaStream=new this._MediaStream}var getTracks=this.mediaStreamTrack.kind==="audio"?"getAudioTracks":"getVideoTracks";mediaStream[getTracks]().forEach(function(mediaStreamTrack){mediaStream.removeTrack(mediaStreamTrack)});mediaStream.addTrack(this.mediaStreamTrack);el.srcObject=mediaStream;el.autoplay=true;if(!this._attachments.has(el)){this._attachments.add(el)}return el};Track.prototype._selectElement=function _selectElement(selector){var el=document.querySelector(selector);if(!el){throw new Error("Selector matched no element: "+selector)}return el};Track.prototype._createElement=function _createElement(){return document.createElement(this.kind)};Track.prototype.detach=function _detach(el){var els;if(typeof el==="string"){els=[this._selectElement(el)]}else if(!el){els=this._getAllAttachedElements()}else{els=[el]}this._log.debug("Attempting to detach from elements:",els);this._detachElements(els);return el?els[0]:els};Track.prototype._detachElements=function _detachElements(elements){return elements.map(this._detachElement.bind(this))};Track.prototype._detachElement=function _detachElement(el){if(!this._attachments.has(el)){return el}var mediaStream=el.srcObject;if(mediaStream instanceof this._MediaStream){mediaStream.removeTrack(this.mediaStreamTrack);el.srcObject=mediaStream}this._attachments.delete(el);return el};Track.prototype._getAllAttachedElements=function _getAllAttachedElements(){var els=[];this._attachments.forEach(function(el){els.push(el)});return els};module.exports=Track},{"@twilio/webrtc":95,events:112,util:116}],12:[function(require,module,exports){"use strict";var AudioTrack=require("./audiotrack");var inherits=require("util").inherits;var LocalTrack=require("./localtrack");function LocalAudioTrack(mediaStreamTrack,options){if(!(this instanceof LocalAudioTrack)){return new LocalAudioTrack(mediaStreamTrack,options)}LocalTrack.call(this,AudioTrack,mediaStreamTrack,options)}inherits(LocalAudioTrack,AudioTrack);LocalAudioTrack.prototype._end=LocalTrack.prototype._end;LocalAudioTrack.prototype.toString=function toString(){return"[LocalAudioTrack #"+this._instanceId+": "+this.id+"]"};LocalAudioTrack.prototype.attach=function attach(el){el=AudioTrack.prototype.attach.call(this,el);el.muted=true;return el};LocalAudioTrack.prototype.disable=LocalTrack.prototype.disable;LocalAudioTrack.prototype.enable=LocalTrack.prototype.enable;LocalAudioTrack.prototype.stop=LocalTrack.prototype.stop;module.exports=LocalAudioTrack},{"./audiotrack":10,"./localtrack":13,util:116}],13:[function(require,module,exports){"use strict";var buildLogLevels=require("../../util").buildLogLevels;var LocalTrackSignaling=require("../../signaling/localtrack");var Log=require("../../util/log");var DEFAULT_LOG_LEVEL=require("../../util/constants").DEFAULT_LOG_LEVEL;var Track=require("./");function LocalTrack(Track,mediaStreamTrack,options){var signaling=new LocalTrackSignaling(mediaStreamTrack);options=Object.assign({logLevel:DEFAULT_LOG_LEVEL},options);var logLevels=buildLogLevels(options.logLevel);options.log=options.log||new Log("default",this,logLevels);Track.call(this,mediaStreamTrack,signaling,options);Object.defineProperties(this,{_didCallEnd:{value:false,writable:true},isStopped:{get:function(){return this.mediaStreamTrack.readyState==="ended"}}})}LocalTrack.prototype._end=function _end(){if(this._didCallEnd){return}Track.prototype._end.call(this);this._didCallEnd=true;this.emit("stopped",this)};LocalTrack.prototype.toString=function toString(){return"[LocalTrack #"+this._instanceId+": "+this.id+"]"};LocalTrack.prototype.enable=function enable(enabled){enabled=typeof enabled==="boolean"?enabled:true;this._log.info((enabled?"En":"Dis")+"abling");this.mediaStreamTrack.enabled=enabled;this._signaling.enable(enabled);return this};LocalTrack.prototype.disable=function disable(){return this.enable(false)};LocalTrack.prototype.stop=function stop(){this._log.info("Stopping");this.mediaStreamTrack.stop();this._end();return this};module.exports=LocalTrack},{"../../signaling/localtrack":21,"../../util":52,"../../util/constants":50,"../../util/log":55,"./":11}],14:[function(require,module,exports){"use strict";var inherits=require("util").inherits;var LocalTrack=require("./localtrack");var VideoTrack=require("./videotrack");function LocalVideoTrack(mediaStreamTrack,options){if(!(this instanceof LocalVideoTrack)){return new LocalVideoTrack(mediaStreamTrack,options)}LocalTrack.call(this,VideoTrack,mediaStreamTrack,options)}inherits(LocalVideoTrack,VideoTrack);LocalVideoTrack.prototype._end=LocalTrack.prototype._end;LocalVideoTrack.prototype.toString=function toString(){return"[LocalVideoTrack #"+this._instanceId+": "+this.id+"]"};LocalVideoTrack.prototype.enable=LocalTrack.prototype.enable;LocalVideoTrack.prototype.disable=LocalTrack.prototype.disable;LocalVideoTrack.prototype.stop=LocalTrack.prototype.stop;module.exports=LocalVideoTrack},{"./localtrack":13,"./videotrack":15,util:116}],15:[function(require,module,exports){"use strict";var inherits=require("util").inherits;var Track=require("./");function VideoTrack(mediaStreamTrack,signaling,options){Track.call(this,mediaStreamTrack,signaling,options);Object.defineProperties(this,{dimensions:{enumerable:true,value:{width:null,height:null}}});Object.defineProperty(this,"_dimensionsChangedElem",{value:emitDimensionsChangedEvents(this)});return this}var DIMENSIONS_CHANGED=VideoTrack.DIMENSIONS_CHANGED="dimensionsChanged";function emitDimensionsChangedEvents(track){if(typeof document==="undefined"){throw new Error("document is undefined")}var elem=document.createElement(track.kind);elem.muted=true;elem.onloadedmetadata=function onloadedmetadata(){if(dimensionsChanged(track,elem)){track.dimensions.width=elem.videoWidth;track.dimensions.height=elem.videoHeight}};elem.onresize=function onresize(){if(dimensionsChanged(track,elem)){track.dimensions.width=elem.videoWidth;track.dimensions.height=elem.videoHeight;if(track.isStarted){track._log.debug("Dimensions changed:",track.dimensions);track.emit(DIMENSIONS_CHANGED,track)}}};elem=track.attach(elem);track._attachments.delete(elem);return elem}function dimensionsChanged(track,elem){return track.dimensions.width!==elem.videoWidth||track.dimensions.height!==elem.videoHeight}inherits(VideoTrack,Track);VideoTrack.prototype.toString=function toString(){return"[VideoTrack #"+this._instanceId+": "+this.id+"]"};VideoTrack.prototype._start=function _start(dummyEl){this.dimensions.width=dummyEl.videoWidth;this.dimensions.height=dummyEl.videoHeight;this._log.debug("Dimensions:",this.dimensions);return Track.prototype._start.call(this,dummyEl)};VideoTrack.prototype.attach=function attach(el){el=Track.prototype.attach.call(this,el);el.muted=true;return el};module.exports=VideoTrack},{"./":11,util:116}],16:[function(require,module,exports){"use strict";var DefaultAudioTrack=require("./media/track/audiotrack");var DefaultVideoTrack=require("./media/track/videotrack");var EventEmitter=require("events").EventEmitter;var inherits=require("util").inherits;var util=require("./util");var nInstances=0;function Participant(signaling,options){
if(!(this instanceof Participant)){return new Participant(signaling,options)}EventEmitter.call(this);options=Object.assign({AudioTrack:DefaultAudioTrack,VideoTrack:DefaultVideoTrack,tracks:[]},options);var indexed=indexTracksById(options.tracks);Object.defineProperties(this,{_AudioTrack:{value:options.AudioTrack},_instanceId:{value:++nInstances},_log:{value:options.log.createLog("default",this)},_signaling:{value:signaling},_trackEventReemitters:{value:new Map},_VideoTrack:{value:options.VideoTrack},audioTracks:{enumerable:true,value:new Map(indexed.audioTracks)},identity:{enumerable:true,get:function(){return signaling.identity}},sid:{enumerable:true,get:function(){return signaling.sid}},state:{enumerable:true,get:function(){return signaling.state}},tracks:{enumerable:true,value:new Map(indexed.tracks)},videoTracks:{enumerable:true,value:new Map(indexed.videoTracks)}});this.tracks.forEach(reemitTrackEvents.bind(null,this));reemitSignalingStateChangedEvents(this,signaling);this._handleTrackSignalingEvents();var log=this._log;log.info("Created a new Participant"+(this.identity?": "+this.identity:""))}inherits(Participant,EventEmitter);Participant.prototype._getTrackEvents=function _getTrackEvents(){return[["dimensionsChanged","trackDimensionsChanged"],["disabled","trackDisabled"],["enabled","trackEnabled"],["started","trackStarted"]]};Participant.prototype.toString=function toString(){return"[Participant #"+this._instanceId+": "+this.sid+"]"};Participant.prototype._addTrack=function _addTrack(track){var log=this._log;if(this.tracks.has(track.id)){return null}this.tracks.set(track.id,track);if(track.kind==="audio"){this.audioTracks.set(track.id,track)}else{this.videoTracks.set(track.id,track)}reemitTrackEvents(this,track);log.info("Added a new "+util.trackClass(track)+":",track.id);log.debug(util.trackClass(track)+":",track);this.emit("trackAdded",track);return track};Participant.prototype._handleTrackSignalingEvents=function _handleTrackSignalingEvents(){var log=this._log;var self=this;if(this.state==="disconnected"){return}var AudioTrack=this._AudioTrack;var signaling=this._signaling;var VideoTrack=this._VideoTrack;function trackSignalingAdded(signaling){signaling.getMediaStreamTrack().then(function(mediaStreamTrack){var Track=signaling.kind==="audio"?AudioTrack:VideoTrack;var track=new Track(mediaStreamTrack,signaling,{log:log});self._addTrack(track)})}function trackSignalingRemoved(signaling){signaling.getMediaStreamTrack().then(function(){var track=self.tracks.get(signaling.id);if(track){self._removeTrack(track)}})}signaling.on("trackAdded",trackSignalingAdded);signaling.on("trackRemoved",trackSignalingRemoved);signaling.tracks.forEach(trackSignalingAdded);signaling.on("stateChanged",function stateChanged(state){if(state==="disconnected"){log.debug("Removing TrackSignaling listeners");signaling.removeListener("stateChanged",stateChanged);signaling.removeListener("trackAdded",trackSignalingAdded);signaling.removeListener("trackRemoved",trackSignalingRemoved)}})};Participant.prototype._removeTrack=function _removeTrack(track){if(!this.tracks.has(track.id)){return null}track=this.tracks.get(track.id);this.tracks.delete(track.id);var tracks=track.kind==="audio"?this.audioTracks:this.videoTracks;tracks.delete(track.id);var reemitters=this._trackEventReemitters.get(track.id)||new Map;reemitters.forEach(function(reemitter,event){track.removeListener(event,reemitter)});var log=this._log;log.info("Removed a "+util.trackClass(track)+":",track.id);log.debug(util.trackClass(track)+":",track);this.emit("trackRemoved",track);return track};function indexTracksById(tracks){var indexedTracks=tracks.map(function(track){return[track.id,track]});var indexedAudioTracks=indexedTracks.filter(function(keyValue){return keyValue[1].kind==="audio"});var indexedVideoTracks=indexedTracks.filter(function(keyValue){return keyValue[1].kind==="video"});return{audioTracks:indexedAudioTracks,tracks:indexedTracks,videoTracks:indexedVideoTracks}}function reemitSignalingStateChangedEvents(participant,signaling){var log=participant._log;if(participant.state==="disconnected"){return}signaling.on("stateChanged",function stateChanged(state){log.debug("Transitioned to state:",state);participant.emit(state,participant);if(state==="disconnected"){log.debug("Removing Track event reemitters");signaling.removeListener("stateChanged",stateChanged);participant.tracks.forEach(function(track){participant._trackEventReemitters.get(track.id).forEach(function(reemitter,event){track.removeListener(event,reemitter)})});participant._trackEventReemitters.clear()}})}function reemitTrackEvents(participant,track){var trackEventReemitters=new Map;if(participant.state==="disconnected"){return}participant._getTrackEvents().forEach(function(eventPair){var trackEvent=eventPair[0];var participantEvent=eventPair[1];trackEventReemitters.set(trackEvent,function(){var args=[participantEvent].concat([].slice.call(arguments));return participant.emit.apply(participant,args)});track.on(trackEvent,trackEventReemitters.get(trackEvent))});participant._trackEventReemitters.set(track.id,trackEventReemitters)}module.exports=Participant},{"./media/track/audiotrack":10,"./media/track/videotrack":15,"./util":52,events:112,util:116}],17:[function(require,module,exports){"use strict";var EventEmitter=require("events").EventEmitter;var inherits=require("util").inherits;function QueueingEventEmitter(){EventEmitter.call(this);Object.defineProperties(this,{_queuedEvents:{value:new Map}})}inherits(QueueingEventEmitter,EventEmitter);QueueingEventEmitter.prototype.dequeue=function dequeue(event){var result=true;if(!event){this._queuedEvents.forEach(function(_,queuedEvent){result=this.dequeue(queuedEvent)&&result},this);return result}var queue=this._queuedEvents.get(event)||[];this._queuedEvents.delete(event);var self=this;return queue.reduce(function(result,args){return self.emit.apply(self,[event].concat(args))&&result},result)};QueueingEventEmitter.prototype.queue=function queue(){var args=[].slice.call(arguments);if(this.emit.apply(this,args)){return true}var event=args[0];if(!this._queuedEvents.has(event)){this._queuedEvents.set(event,[])}this._queuedEvents.get(event).push(args.slice(1));return false};module.exports=QueueingEventEmitter},{events:112,util:116}],18:[function(require,module,exports){"use strict";var XHR=require("xmlhttprequest").XMLHttpRequest;function request(method,params){return new Promise(function(resolve,reject){if(typeof method!=="string"||!params){throw new Error("<String>method and <Object>params are required args.")}var xhr=new XHR;xhr.open(method.toUpperCase(),params.url,true);xhr.withCredentials=!!params.withCredentials;xhr.onreadystatechange=function onreadystatechange(){if(xhr.readyState!==4){return}if(200<=xhr.status&&xhr.status<300){resolve(xhr.responseText)}else{reject(xhr.responseText)}};for(var headerName in params.headers){xhr.setRequestHeader(headerName,params.headers[headerName])}xhr.send(params.body)})}request.get=request.bind(null,"GET");request.post=request.bind(null,"POST");module.exports=request},{xmlhttprequest:119}],19:[function(require,module,exports){"use strict";var EventEmitter=require("events").EventEmitter;var inherits=require("util").inherits;var Participant=require("./participant");var nInstances=0;function Room(localParticipant,signaling,options){if(!(this instanceof Room)){return new Room(localParticipant,signaling,options)}EventEmitter.call(this);var log=options.log.createLog("default",this);var participants=new Map;Object.defineProperties(this,{_log:{value:log},_instanceId:{value:++nInstances},_options:{value:options},_participants:{value:participants},_signaling:{value:signaling},isRecording:{enumerable:true,get:function(){return signaling.recording.isEnabled||false}},localParticipant:{enumerable:true,value:localParticipant},name:{enumerable:true,value:signaling.name},participants:{enumerable:true,value:participants},sid:{enumerable:true,value:signaling.sid},state:{enumerable:true,get:function(){return signaling.state}}});handleRecordingEvents(this,signaling.recording);handleSignalingEvents(this,signaling);log.info("Created a new Room:",this.name);log.debug("Initial Participants:",Array.from(this._participants.values()))}inherits(Room,EventEmitter);Room.prototype.toString=function toString(){return"[Room #"+this._instanceId+": "+this.sid+"]"};Room.prototype.disconnect=function disconnect(){this._log.info("Disconnecting");this._signaling.disconnect();return this};Room.prototype.getStats=function getStats(){return this._signaling.getStats()};function connectParticipant(room,participantSignaling){var log=room._log;var participant=new Participant(participantSignaling,{log:log});log.info("A new Participant connected:",participant);room._participants.set(participant.sid,participant);room.emit("participantConnected",participant);var eventListeners=["trackAdded","trackDimensionsChanged","trackDisabled","trackEnabled","trackRemoved","trackStarted"].map(function(event){function reemit(){var args=[].slice.call(arguments);args.unshift(event);args.push(participant);room.emit.apply(room,args)}participant.on(event,reemit);return[event,reemit]});participant.once("disconnected",function participantDisconnected(){log.info("Participant disconnected:",participant);room._participants.delete(participant.sid);eventListeners.forEach(function(args){participant.removeListener(args[0],args[1])});room.emit("participantDisconnected",participant)})}function handleRecordingEvents(room,recording){recording.on("updated",function updated(){var started=recording.isEnabled;room._log.info("Recording "+(started?"started":"stopped"));room.emit("recording"+(started?"Started":"Stopped"))})}function handleSignalingEvents(room,signaling){var log=room._log;log.debug("Creating a new Participant for each ParticipantSignaling "+"in the RoomSignaling");signaling.participants.forEach(connectParticipant.bind(null,room));log.debug("Setting up Participant creation for all subsequent "+"ParticipantSignalings that connect to the RoomSignaling");signaling.on("participantConnected",connectParticipant.bind(null,room));signaling.on("stateChanged",function stateChanged(state,error){log.info("Transitioned to state:",state);room.emit(state,room,error)})}module.exports=Room},{"./participant":16,events:112,util:116}],20:[function(require,module,exports){"use strict";var inherits=require("util").inherits;var ParticipantSignaling=require("./participant");var RoomSignaling=require("./room");var StateMachine=require("../statemachine");var states={closed:["opening"],opening:["closed","open"],open:["closed","closing"],closing:["closed","open"]};function Signaling(){StateMachine.call(this,"closed",states)}inherits(Signaling,StateMachine);Signaling.prototype._close=function _close(key){this.transition("closing",key);this.transition("closed",key);return Promise.resolve(this)};Signaling.prototype._connect=function _connect(localParticipant,token,iceServerSource,options){localParticipant.connect("PA00000000000000000000000000000000","test");var sid="RM00000000000000000000000000000000";var promise=Promise.resolve(new RoomSignaling(localParticipant,sid,options));promise.cancel=function cancel(){};return promise};Signaling.prototype._open=function _open(key){this.transition("opening",key);this.transition("open",key);return Promise.resolve(this)};Signaling.prototype.close=function close(){var self=this;return this.bracket("close",function transition(key){switch(self.state){case"closed":return self;case"open":return self._close(key);default:throw new Error('Unexpected Signaling state "'+self.state+'"')}})};Signaling.prototype.connect=function connect(localParticipant,token,iceServerSource,options){var self=this;return this.bracket("connect",function transition(key){switch(self.state){case"closed":return self._open(key).then(transition.bind(null,key));case"open":self.releaseLockCompletely(key);return self._connect(localParticipant,token,iceServerSource,options);default:throw new Error('Unexpected Signaling state "'+self.state+'"')}})};Signaling.prototype.createLocalParticipantSignaling=function createLocalParticipantSignaling(){return new ParticipantSignaling};Signaling.prototype.open=function open(){var self=this;return this.bracket("open",function transition(key){switch(self.state){case"closed":return self._open(key);case"open":return self;default:throw new Error('Unexpected Signaling state "'+self.state+'"')}})};module.exports=Signaling},{"../statemachine":40,"./participant":22,"./room":25,util:116}],21:[function(require,module,exports){"use strict";var inherits=require("util").inherits;var TrackSignaling=require("./track");function LocalTrackSignaling(mediaStreamTrack){TrackSignaling.call(this,mediaStreamTrack.id,mediaStreamTrack.kind,mediaStreamTrack.enabled);this.setMediaStreamTrack(mediaStreamTrack)}inherits(LocalTrackSignaling,TrackSignaling);module.exports=LocalTrackSignaling},{"./track":26,util:116}],22:[function(require,module,exports){"use strict";var inherits=require("util").inherits;var StateMachine=require("../statemachine");var states={connecting:["connected"],connected:["disconnected"],disconnected:[]};function ParticipantSignaling(){StateMachine.call(this,"connecting",states);Object.defineProperties(this,{_identity:{writable:true,value:null},_sid:{writable:true,value:null},identity:{enumerable:true,get:function(){return this._identity}},sid:{enumerable:true,get:function(){return this._sid}},tracks:{enumerable:true,value:new Map}})}inherits(ParticipantSignaling,StateMachine);ParticipantSignaling.prototype.addTrack=function addTrack(track){this.tracks.set(track.id,track);this.emit("trackAdded",track);return this};ParticipantSignaling.prototype.disconnect=function disconnect(){if(this.state!=="disconnected"){this.preempt("disconnected");return true}return false};ParticipantSignaling.prototype.removeTrack=function removeTrack(track){var didDelete=this.tracks.delete(track.id);if(didDelete){this.emit("trackRemoved",track)}return didDelete};ParticipantSignaling.prototype.connect=function connect(sid,identity){if(this.state==="connecting"){this._sid=sid;this._identity=identity;this.preempt("connected");return true}return false};module.exports=ParticipantSignaling},{"../statemachine":40,util:116}],23:[function(require,module,exports){"use strict";var EventEmitter=require("events").EventEmitter;var inherits=require("util").inherits;function RecordingSignaling(){EventEmitter.call(this);Object.defineProperties(this,{_isEnabled:{value:null,writable:true},isEnabled:{enumerable:true,get:function(){return this._isEnabled}}})}inherits(RecordingSignaling,EventEmitter);RecordingSignaling.prototype.disable=function disable(){return this.enable(false)};RecordingSignaling.prototype.enable=function enable(enabled){enabled=typeof enabled==="boolean"?enabled:true;if(this.isEnabled!==enabled){this._isEnabled=enabled;this.emit("updated")}return this};module.exports=RecordingSignaling},{events:112,util:116}],24:[function(require,module,exports){"use strict";var inherits=require("util").inherits;var ParticipantSignaling=require("./participant");function RemoteParticipantSignaling(sid,identity){ParticipantSignaling.call(this);this.connect(sid,identity)}inherits(RemoteParticipantSignaling,ParticipantSignaling);module.exports=RemoteParticipantSignaling},{"./participant":22,util:116}],25:[function(require,module,exports){"use strict";var inherits=require("util").inherits;var DefaultRecordingSignaling=require("./recording");var StateMachine=require("../statemachine");var states={connected:["disconnected"],disconnected:[]};function RoomSignaling(localParticipant,sid,name,options){options=Object.assign({RecordingSignaling:DefaultRecordingSignaling},options);StateMachine.call(this,"connected",states);var RecordingSignaling=options.RecordingSignaling;Object.defineProperties(this,{_options:{value:options},localParticipant:{enumerable:true,value:localParticipant},name:{enumerable:true,value:name},participants:{enumerable:true,value:new Map},recording:{enumerable:true,value:new RecordingSignaling},sid:{enumerable:true,value:sid}})}inherits(RoomSignaling,StateMachine);RoomSignaling.prototype._disconnect=function _disconnect(error){if(this.state==="connected"){this.preempt("disconnected",null,[error]);return true}return false};RoomSignaling.prototype.connectParticipant=function connectParticipant(participant){var self=this;if(participant.state==="disconnected"){return false}if(this.participants.has(participant.sid)){return false}this.participants.set(participant.sid,participant);participant.on("stateChanged",function stateChanged(state){if(state==="disconnected"){participant.removeListener("stateChanged",stateChanged);self.participants.delete(participant.sid);self.emit("participantDisconnected",participant)}});this.emit("participantConnected",participant);return true};RoomSignaling.prototype.disconnect=function disconnect(){return this._disconnect()};module.exports=RoomSignaling},{"../statemachine":40,"./recording":23,util:116}],26:[function(require,module,exports){"use strict";var EventEmitter=require("events").EventEmitter;var inherits=require("util").inherits;var util=require("../util");function TrackSignaling(id,kind,isEnabled){EventEmitter.call(this);var mediaStreamTrack;Object.defineProperties(this,{_isEnabled:{value:isEnabled,writable:true},_mediaStreamTrack:{get:function(){return mediaStreamTrack},set:function(_mediaStreamTrack){mediaStreamTrack=_mediaStreamTrack;this._mediaStreamTrackDeferred.resolve(mediaStreamTrack)}},_mediaStreamTrackDeferred:{value:util.defer()},id:{enumerable:true,value:id},isEnabled:{enumerable:true,get:function(){return this._isEnabled}},kind:{enumerable:true,value:kind},mediaStreamTrack:{enumerable:true,get:function(){return mediaStreamTrack}}})}inherits(TrackSignaling,EventEmitter);TrackSignaling.prototype.disable=function disable(){return this.enable(false)};TrackSignaling.prototype.enable=function enable(enabled){enabled=typeof enabled==="boolean"?enabled:true;if(this.isEnabled!==enabled){this._isEnabled=enabled;this.emit("updated")}return this};TrackSignaling.prototype.getMediaStreamTrack=function getMediaStreamTrack(){return this._mediaStreamTrackDeferred.promise};TrackSignaling.prototype.setMediaStreamTrack=function setMediaStreamTrack(mediaStreamTrack){this._mediaStreamTrack=mediaStreamTrack;return this};module.exports=TrackSignaling},{"../util":52,events:112,util:116}],27:[function(require,module,exports){"use strict";var CancelablePromise=require("../../util/cancelablepromise");var DefaultPeerConnectionManager=require("./peerconnectionmanager");var DefaultRoomV2=require("./room");var DefaultTransport=require("./transport");var SignalingConnectionDisconnectedError=require("../../util/twilio-video-errors").SignalingConnectionDisconnectedError;var SignalingIncomingMessageInvalidError=require("../../util/twilio-video-errors").SignalingIncomingMessageInvalidError;var flatMap=require("../../util").flatMap;function createCancelableRoomSignalingPromise(token,ua,localParticipant,iceServerSource,options){options=Object.assign({PeerConnectionManager:DefaultPeerConnectionManager,RoomV2:DefaultRoomV2,Transport:DefaultTransport},options);var transport;var PeerConnectionManager=options.PeerConnectionManager;var RoomV2=options.RoomV2;var peerConnectionManager=new PeerConnectionManager(iceServerSource);var mediaStreamTracks=flatMap(localParticipant.tracks,function(track){return[track.mediaStreamTrack]});peerConnectionManager.setConfiguration(options);peerConnectionManager.setMediaStreamTracks(mediaStreamTracks);var cancelationError=new Error("Canceled");return new CancelablePromise(function onCreate(resolve,reject,isCanceled){peerConnectionManager.createAndOffer().then(function createAndOfferSucceeded(){peerConnectionManager.dequeue("description");return new Promise(function(resolve,reject){if(isCanceled()){reject(cancelationError);return}var transportOptions=typeof options.wsServerInsights==="string"?{wsServerInsights:options.wsServerInsights}:{};if(options.InsightsPublisher){transportOptions.InsightsPublisher=options.InsightsPublisher}if(options.NullInsightsPublisher){transportOptions.NullInsightsPublisher=options.NullInsightsPublisher}transportOptions=Object.assign({environment:options.environment,insights:options.insights,realm:options.realm},transportOptions);var Transport=options.Transport;transport=new Transport(options.name,token,localParticipant,peerConnectionManager,ua,transportOptions);transport.once("connected",function connected(initialState){if(isCanceled()){reject(cancelationError);return}var localParticipantState=initialState.participant;if(!localParticipantState){reject(new SignalingIncomingMessageInvalidError);return}localParticipant.connect(localParticipantState.sid,localParticipantState.identity);resolve(new RoomV2(localParticipant,initialState,transport,peerConnectionManager,options))});transport.once("stateChanged",function stateChanged(state,error){if(state==="disconnected"){error=error||new SignalingConnectionDisconnectedError;transport=null;reject(error)}})})}).then(function createRoomSignalingSucceeded(roomSignaling){if(isCanceled()){peerConnectionManager.close();roomSignaling.disconnect();reject(cancelationError);return}resolve(roomSignaling)}).catch(function onError(error){if(transport){transport.disconnect();transport=null}peerConnectionManager.close();reject(error)})},function onCancel(){if(transport){transport.disconnect();transport=null}})}module.exports=createCancelableRoomSignalingPromise},{"../../util":52,"../../util/cancelablepromise":49,"../../util/twilio-video-errors":57,"./peerconnectionmanager":32,"./room":35,"./transport":38}],28:[function(require,module,exports){"use strict";var Filter=require("../../util/filter");function IceBox(){if(!(this instanceof IceBox)){return new IceBox}Object.defineProperties(this,{_filter:{value:new Filter({getKey:function getKey(iceState){return iceState.ufrag},isLessThanOrEqualTo:function isLessThanOrEqualTo(a,b){return a.revision<=b.revision}})},_ufrag:{writable:true,value:null},ufrag:{enumerable:true,get:function(){return this._ufrag}}})}IceBox.prototype.setUfrag=function setUfrag(ufrag){this._ufrag=ufrag;var ice=this._filter.toMap().get(ufrag);return ice?ice.candidates:[]};IceBox.prototype.update=function update(iceState){iceState.candidates=iceState.candidates||[];var oldIceState=this._filter.toMap().get(iceState.ufrag);var oldCandidates=oldIceState?oldIceState.candidates:[];return this._filter.update(iceState)&&this._ufrag===iceState.ufrag?iceState.candidates.slice(oldCandidates.length):[]};module.exports=IceBox},{"../../util/filter":51}],29:[function(require,module,exports){"use strict";var constants=require("../../util/constants");var defaultCreateCancelableRoomSignalingPromise=require("./cancelableroomsignalingpromise");var inherits=require("util").inherits;var LocalParticipantV2=require("./localparticipant");var Signaling=require("../");var SIP=require("../../sip");var SIPJSMediaHandler=require("./sipjsmediahandler");var util=require("../../util");function SignalingV2(wsServer,options){var uri=util.makeClientSIPURI();options=Object.assign({createCancelableRoomSignalingPromise:defaultCreateCancelableRoomSignalingPromise,registrarServer:constants.REGISTRAR_SERVER,UA:SIP.UA},options);var debug=options.logLevel==="debug";var useWssHack=wsServer.startsWith("wss://");var UA=options.UA;var ua=new UA({autostart:false,log:{builtinEnabled:debug},extraSupported:["room-signaling","timer"],hackAllowUnregisteredOptionTags:true,keepAliveInterval:30,mediaHandlerFactory:SIPJSMediaHandler.defaultFactory,register:false,registrarServer:options.registrarServer,traceSip:debug,uri:uri,wsServers:wsServer,hackWssInTransport:useWssHack});Signaling.call(this);Object.defineProperties(this,{_createCancelableRoomSignalingPromise:{value:options.createCancelableRoomSignalingPromise},_options:{value:options},_ua:{value:ua}})}inherits(SignalingV2,Signaling);SignalingV2.prototype._close=function _close(key){this.transition("closing",key);this._ua.stop();this._ua.transport.disconnect();this.transition("closed",key);return Promise.resolve(this)};SignalingV2.prototype._open=function _open(key){var self=this;function startUA(){self._ua.start()}this.transition("opening",key);return util.promiseFromEvents(startUA,this._ua,"connected","disconnected").then(function(){self.transition("open",key);return self},function(){self.transition("closed",key);throw new Error("Open failed")})};SignalingV2.prototype._connect=function _connect(localParticipant,token,iceServerSource,options){options=Object.assign({},this._options,options);var ua=this._ua;return this._createCancelableRoomSignalingPromise.bind(null,token,ua,localParticipant,iceServerSource,options)};SignalingV2.prototype.createLocalParticipantSignaling=function createLocalParticipantSignaling(){return new LocalParticipantV2};module.exports=SignalingV2},{"../":20,"../../sip":39,"../../util":52,"../../util/constants":50,"./cancelableroomsignalingpromise":27,"./localparticipant":30,"./sipjsmediahandler":36,util:116}],30:[function(require,module,exports){"use strict";var getTrackState=require("./track").getState;var inherits=require("util").inherits;var ParticipantSignaling=require("../participant");function LocalParticipantV2(){if(!(this instanceof LocalParticipantV2)){return new LocalParticipantV2}ParticipantSignaling.call(this);Object.defineProperties(this,{_revision:{writable:true,value:1},revision:{enumerable:true,get:function(){return this._revision}}})}inherits(LocalParticipantV2,ParticipantSignaling);LocalParticipantV2.prototype.update=function update(){this._revision++;return this};LocalParticipantV2.prototype.getState=function getState(){return{revision:this.revision,tracks:Array.from(this.tracks.values()).map(getTrackState)}};module.exports=LocalParticipantV2},{"../participant":22,"./track":37,util:116}],31:[function(require,module,exports){"use strict";var WebRTC=require("@twilio/webrtc");var DefaultRTCIceCandidate=WebRTC.RTCIceCandidate;var DefaultRTCPeerConnection=WebRTC.RTCPeerConnection;var DefaultRTCSessionDescription=WebRTC.RTCSessionDescription;var flatMap=require("../../util").flatMap;var getStatistics=WebRTC.getStats;var guessBrowser=require("../../util").guessBrowser;var IceBox=require("./icebox");var inherits=require("util").inherits;var MediaClientLocalDescFailedError=require("../../util/twilio-video-errors").MediaClientLocalDescFailedError;var MediaClientRemoteDescFailedError=require("../../util/twilio-video-errors").MediaClientRemoteDescFailedError;var StateMachine=require("../../../lib/statemachine");var StatsReport=require("../../stats/statsreport");var defaults={iceServers:[],offerOptions:{},RTCIceCandidate:DefaultRTCIceCandidate,RTCPeerConnection:DefaultRTCPeerConnection,RTCSessionDescription:DefaultRTCSessionDescription};var isFirefox=guessBrowser()==="firefox";var states={open:["closed","updating"],updating:["closed","open"],closed:[]};function PeerConnectionV2(id,options){if(!(this instanceof PeerConnectionV2)){return new PeerConnectionV2(id,options)}StateMachine.call(this,"open",states);options=Object.assign(defaults,options);var configuration=getConfiguration(options);var RTCPeerConnection=options.RTCPeerConnection;var peerConnection=new RTCPeerConnection(configuration);Object.defineProperties(this,{_descriptionRevision:{writable:true,value:0},_lastStableDescriptionRevision:{writable:true,value:0},_localCandidates:{writable:true,value:[]},_localCandidatesRevision:{writable:true,value:1},_localDescription:{writable:true,value:null},_localUfrag:{writable:true,value:null},_needsInitialAnswer:{writable:true,value:false},_negotiationRole:{writable:true,value:null},_offerOptions:{writable:true,value:options.offerOptions},_peerConnection:{value:peerConnection},_queuedDescription:{writable:true,value:null},_remoteCandidates:{writable:true,value:new IceBox},_RTCIceCandidate:{value:options.RTCIceCandidate},_RTCPeerConnection:{value:options.RTCPeerConnection},_RTCSessionDescription:{value:options.RTCSessionDescription},_shouldOffer:{writable:true,value:false},id:{enumerable:true,value:id}});peerConnection.addEventListener("icecandidate",this._handleIceCandidateEvent.bind(this));peerConnection.addEventListener("signalingstatechange",this._handleSignalingStateChange.bind(this));peerConnection.addEventListener("track",this._handleTrackEvent.bind(this))}inherits(PeerConnectionV2,StateMachine);PeerConnectionV2.prototype._addIceCandidate=function _addIceCandidate(candidate){var self=this;return Promise.resolve().then(function(){candidate=new self._RTCIceCandidate(candidate);return self._peerConnection.addIceCandidate(candidate)})};PeerConnectionV2.prototype._addIceCandidates=function _addIceCandidates(candidates){return Promise.all(candidates.map(this._addIceCandidate,this)).then(function(){})};PeerConnectionV2.prototype._checkIceBox=function checkIceBox(description){var ufrag=getUfrag(description);if(!ufrag){return Promise.resolve()}var candidates=this._remoteCandidates.setUfrag(ufrag);return this._addIceCandidates(candidates)};PeerConnectionV2.prototype._answer=function _answer(offer){var self=this;return Promise.resolve().then(function(){offer=new self._RTCSessionDescription(offer);if(!self._negotiationRole){self._negotiationRole="answerer"}return self._peerConnection.setRemoteDescription(offer)}).catch(function(){throw new MediaClientRemoteDescFailedError}).then(function(){return self._peerConnection.createAnswer()}).then(function(answer){return self._setLocalDescription(answer)}).then(function(){return self._checkIceBox(offer)}).then(function(){return self._maybeReoffer(offer)}).catch(function(error){throw error instanceof MediaClientRemoteDescFailedError?error:new MediaClientLocalDescFailedError})};PeerConnectionV2.prototype._close=function _close(){if(this._peerConnection.signalingState!=="closed"){this._peerConnection.close();return true}return false};PeerConnectionV2.prototype._handleGlare=function _handleGlare(offer){var self=this;return Promise.resolve().then(function(){var rollback=new self._RTCSessionDescription({type:"rollback"});return self._setLocalDescription(rollback)}).then(function(){return self._answer(offer)}).then(function(){return self._offer()})};PeerConnectionV2.prototype._handleIceCandidateEvent=function _handleIceCandidateEvent(event){if(event.candidate){this._localCandidates.push(event.candidate)}var peerConnectionState={ice:{candidates:this._localCandidates.slice(),revision:this._localCandidatesRevision++,ufrag:this._localUfrag},id:this.id};if(!event.candidate){peerConnectionState.ice.complete=true}this.emit("candidates",peerConnectionState)};PeerConnectionV2.prototype._handleSignalingStateChange=function _handleSignalingStateChange(){if(this._peerConnection.signalingState==="closed"&&this.state!=="closed"){this.preempt("closed")}};PeerConnectionV2.prototype._handleTrackEvent=function _handleTrackEvent(event){var mediaStreamTrack=event.track;this.emit("trackAdded",mediaStreamTrack)};PeerConnectionV2.prototype._maybeReoffer=function _maybeReoffer(offer){var self=this;var promise=Promise.resolve();if(isFirefox){var senders=this._peerConnection.getSenders();promise=promise.then(function(){self._shouldOffer=["audio","video"].reduce(function(shouldOffer,kind){var mediaSections=getMediaSections(offer.sdp,kind,"send(only|recv)");var sendersOfKind=senders.filter(isSenderOfKind.bind(null,kind));return shouldOffer||mediaSections.length<sendersOfKind.length},self._shouldOffer);return self._shouldOffer&&self._offer()}).then(function(){self._shouldOffer=false})}return promise};PeerConnectionV2.prototype._offer=function _offer(){var self=this;return Promise.resolve().then(function(){return self._peerConnection.createOffer(self._offerOptions)}).catch(function(){throw new MediaClientLocalDescFailedError}).then(function(offer){if(!self._negotiationRole){self._negotiationRole="offerer";self._needsInitialAnswer=true}return self._setLocalDescription(offer)})}
;PeerConnectionV2.prototype._setLocalDescription=function _setLocalDescription(description){var revision=description.revision;var self=this;return Promise.resolve().then(function(){description=new self._RTCSessionDescription(description);if(description.type==="answer"){self._lastStableDescriptionRevision=revision}return self._peerConnection.setLocalDescription(description)}).catch(function(){throw new MediaClientLocalDescFailedError}).then(function setLocalDescriptionSucceeded(){if(description.type!=="rollback"){self._localDescription=description;self._localCandidates=[];if(description.type==="offer"){self._descriptionRevision++}self._localUfrag=getUfrag(description);self.emit("description",self.getState())}})};PeerConnectionV2.prototype._updateDescription=function _updateDescription(description){switch(description.type){case"answer":case"pranswer":if(description.revision!==this._descriptionRevision||this._peerConnection.signalingState!=="have-local-offer"){return Promise.resolve()}this._descriptionRevision=description.revision;break;case"close":return this._close();case"create-offer":if(description.revision<=this._lastStableDescriptionRevision){return Promise.resolve()}else if(this._needsInitialAnswer){this._queuedDescription=description;return Promise.resolve()}this._descriptionRevision=description.revision;return this._offer();case"offer":if(description.revision<=this._lastStableDescriptionRevision||this._peerConnection.signalingState==="closed"){return Promise.resolve()}if(this._peerConnection.signalingState==="have-local-offer"){if(this._needsInitialAnswer){this._queuedDescription=description;return Promise.resolve()}this._descriptionRevision=description.revision;return this._handleGlare(description)}this._descriptionRevision=description.revision;return this._answer(description);default:}var revision=description.revision;var self=this;return Promise.resolve().then(function(){description=new self._RTCSessionDescription(description);if(description.type==="answer"){self._lastStableDescriptionRevision=revision}return self._peerConnection.setRemoteDescription(description)}).catch(function(){throw new MediaClientRemoteDescFailedError}).then(function(){if(description.type==="answer"){self._needsInitialAnswer=false}return self._checkIceBox(description)}).then(function(){return self._queuedDescription&&self._updateDescription(self._queuedDescription)}).then(function(){self._queuedDescription=null;return self._shouldOffer&&self._offer()}).then(function(){self._shouldOffer=false})};PeerConnectionV2.prototype._updateIce=function _updateIce(iceState){var candidates=this._remoteCandidates.update(iceState);return this._addIceCandidates(candidates)};PeerConnectionV2.prototype.addMediaStream=function addMediaStream(mediaStream){this._peerConnection.addStream(mediaStream)};PeerConnectionV2.prototype.close=function close(){if(this._close()){this._descriptionRevision++;this._localDescription={type:"close"};this.emit("description",this.getState())}};PeerConnectionV2.prototype.getRemoteMediaStreamTracks=function getRemoteMediaStreamTracks(){return flatMap(this._peerConnection.getRemoteStreams(),function(mediaStream){return mediaStream.getTracks()})};PeerConnectionV2.prototype.getState=function getState(){if(!this._localDescription){return null}var localDescription={type:this._localDescription.type,revision:this._descriptionRevision};if(this._localDescription.sdp){localDescription.sdp=this._localDescription.sdp}return{description:localDescription,id:this.id}};PeerConnectionV2.prototype.offer=function offer(){if(this._needsInitialAnswer){this._shouldOffer=true;return Promise.resolve()}var self=this;return this.bracket("offering",function transition(key){self.transition("updating",key);return self._offer().then(function offerSucceeded(){self.tryTransition("open",key)},function offerFailed(error){self.tryTransition("open",key);throw error})})};PeerConnectionV2.prototype.removeMediaStream=function removeMediaStream(mediaStream){this._peerConnection.removeStream(mediaStream)};PeerConnectionV2.prototype.setConfiguration=function setConfiguration(configuration){if(typeof this._peerConnection.setConfiguration==="function"){this._peerConnection.setConfiguration(getConfiguration(configuration))}};PeerConnectionV2.prototype.update=function update(peerConnectionState){var self=this;return this.bracket("updating",function transition(key){if(self.state==="closed"){return Promise.resolve()}self.transition("updating",key);var updates=[];if(peerConnectionState.ice){updates.push(self._updateIce(peerConnectionState.ice))}if(peerConnectionState.description){updates.push(self._updateDescription(peerConnectionState.description))}return Promise.all(updates).then(function updatesSucceeded(){self.tryTransition("open",key)},function updatesFailed(error){self.tryTransition("open",key);throw error})})};PeerConnectionV2.prototype.getStats=function getStats(){var self=this;return getStatistics(this._peerConnection).then(function(statsResponse){return new StatsReport(self.id,statsResponse)})};function getUfrag(description){if(description.sdp){var match=description.sdp.match(/^a=ice-ufrag:([a-zA-Z0-9+\/]+)/m);if(match){return match[1]}}return null}function getConfiguration(configuration){return Object.assign({bundlePolicy:"max-bundle",rtcpMuxPolicy:"require"},configuration)}function getMediaSections(sdp,kind,direction){kind=kind||".*";direction=direction||".*";return sdp.split("\r\nm=").slice(1).map(function(mediaSection){return"m="+mediaSection}).filter(function(mediaSection){var kindPattern=new RegExp("m="+kind,"gm");var directionPattern=new RegExp("a="+direction,"gm");return kindPattern.test(mediaSection)&&directionPattern.test(mediaSection)})}function isSenderOfKind(kind,sender){var track=sender.track;return track&&track.kind===kind&&track.readyState!=="ended"}module.exports=PeerConnectionV2},{"../../../lib/statemachine":40,"../../stats/statsreport":47,"../../util":52,"../../util/twilio-video-errors":57,"./icebox":28,"@twilio/webrtc":95,util:116}],32:[function(require,module,exports){"use strict";var inherits=require("util").inherits;var PeerConnectionV2=require("./peerconnection");var MediaStream=require("@twilio/webrtc").MediaStream;var QueueingEventEmitter=require("../../queueingeventemitter");var util=require("../../util");function PeerConnectionManager(iceServerSource,options){if(!(this instanceof PeerConnectionManager)){return new PeerConnectionManager(options)}QueueingEventEmitter.call(this);options=Object.assign({audioContextFactory:null,MediaStream:MediaStream,PeerConnectionV2:PeerConnectionV2},options);var audioContext=options.audioContextFactory?options.audioContextFactory.getOrCreate(this):null;var offerOptions=audioContext?{offerToReceiveVideo:true}:{offerToReceiveAudio:true,offerToReceiveVideo:true};Object.defineProperties(this,{_audioContextFactory:{value:options.audioContextFactory},_closedPeerConnectionIds:{value:new Set},_configuration:{writable:true,value:null},_configurationDeferred:{writable:true,value:util.defer()},_dummyAudioMediaStreamTrack:{value:audioContext?createDummyAudioMediaStreamTrack(audioContext):null},_iceServerSource:{value:iceServerSource},_localMediaStream:{value:new options.MediaStream},_offerOptions:{value:offerOptions},_peerConnections:{value:new Map},_PeerConnectionV2:{value:options.PeerConnectionV2}});if(this._dummyAudioMediaStreamTrack){this._localMediaStream.addTrack(this._dummyAudioMediaStreamTrack)}}inherits(PeerConnectionManager,QueueingEventEmitter);PeerConnectionManager.prototype._getConfiguration=function _getConfiguration(){return this._configurationDeferred.promise};PeerConnectionManager.prototype._getOrCreate=function _getOrCreate(id,configuration){var self=this;var peerConnection=this._peerConnections.get(id);if(!peerConnection){var PeerConnectionV2=this._PeerConnectionV2;var options=Object.assign({offerOptions:this._offerOptions},configuration);peerConnection=new PeerConnectionV2(id,options);this._peerConnections.set(peerConnection.id,peerConnection);peerConnection.on("candidates",this.queue.bind(this,"candidates"));peerConnection.on("description",this.queue.bind(this,"description"));peerConnection.on("trackAdded",this.queue.bind(this,"trackAdded"));peerConnection.on("stateChanged",function stateChanged(state){if(state==="closed"){peerConnection.removeListener("stateChanged",stateChanged);self._peerConnections.delete(peerConnection.id);self._closedPeerConnectionIds.add(peerConnection.id)}});peerConnection.addMediaStream(this._localMediaStream)}return peerConnection};PeerConnectionManager.prototype.close=function close(){if(this._iceServerSource.isStarted){this._iceServerSource.stop()}this._peerConnections.forEach(function(peerConnection){peerConnection.close()});if(this._dummyAudioMediaStreamTrack){this._dummyAudioMediaStreamTrack.stop()}if(this._audioContextFactory){this._audioContextFactory.release(this)}return this};PeerConnectionManager.prototype.createAndOffer=function createAndOffer(){var self=this;return this._getConfiguration().then(function getConfigurationSucceeded(configuration){var id;do{id=util.makeUUID()}while(self._peerConnections.has(id));return self._getOrCreate(id,configuration)}).then(function createSucceeded(peerConnection){return peerConnection.offer()}).then(function offerSucceeded(){return self})};PeerConnectionManager.prototype.getRemoteMediaStreamTracks=function getRemoteMediaStreamTracks(){return util.flatMap(this._peerConnections,function(peerConnection){return peerConnection.getRemoteMediaStreamTracks()})};PeerConnectionManager.prototype.getStates=function getStates(){var peerConnectionStates=[];this._peerConnections.forEach(function(peerConnection){var peerConnectionState=peerConnection.getState();if(peerConnectionState){peerConnectionStates.push(peerConnectionState)}});return peerConnectionStates};PeerConnectionManager.prototype.setConfiguration=function setConfiguration(configuration){if(this._configuration){this._configurationDeferred=util.defer();this._peerConnections.forEach(function(peerConnection){peerConnection.setConfiguration(configuration)})}this._configuration=configuration;this._configurationDeferred.resolve(configuration);return this};PeerConnectionManager.prototype.setMediaStreamTracks=function setMediaStreamTracks(mediaStreamTracks){if(this._dummyAudioMediaStreamTrack){mediaStreamTracks.push(this._dummyAudioMediaStreamTrack)}var tracksToRemove=util.difference(this._localMediaStream.getTracks(),mediaStreamTracks);var tracksToAdd=util.difference(mediaStreamTracks,this._localMediaStream.getTracks());if(tracksToRemove.size||tracksToAdd.size){tracksToRemove.forEach(this._localMediaStream.removeTrack,this._localMediaStream);tracksToAdd.forEach(this._localMediaStream.addTrack,this._localMediaStream);this._peerConnections.forEach(function(peerConnection){peerConnection.removeMediaStream(this._localMediaStream);peerConnection.addMediaStream(this._localMediaStream);peerConnection.offer()},this)}return this};PeerConnectionManager.prototype.update=function update(peerConnectionStates){var self=this;return this._getConfiguration().then(function getConfigurationSucceeded(configuration){return Promise.all(peerConnectionStates.map(function(peerConnectionState){if(self._closedPeerConnectionIds.has(peerConnectionState.id)){return null}var peerConnection=self._getOrCreate(peerConnectionState.id,configuration);return peerConnection.update(peerConnectionState)}))}).then(function updatesSucceeded(){return self})};PeerConnectionManager.prototype.getStats=function getStats(){var peerConnections=Array.from(this._peerConnections.values());return Promise.all(peerConnections.map(function(peerConnection){return peerConnection.getStats()}))};function createDummyAudioMediaStreamTrack(audioContext){var mediaStreamDestination=audioContext.createMediaStreamDestination();return mediaStreamDestination.stream.getAudioTracks()[0]}module.exports=PeerConnectionManager},{"../../queueingeventemitter":17,"../../util":52,"./peerconnection":31,"@twilio/webrtc":95,util:116}],33:[function(require,module,exports){"use strict";var inherits=require("util").inherits;var RecordingSignaling=require("../recording");function RecordingV2(){RecordingSignaling.call(this);Object.defineProperties(this,{_revision:{value:1,writable:true}})}inherits(RecordingV2,RecordingSignaling);RecordingV2.prototype.update=function update(recording){if(recording.revision<this._revision){return this}this._revision=recording.revision;return this.enable(recording.enabled)};module.exports=RecordingV2},{"../recording":23,util:116}],34:[function(require,module,exports){"use strict";var inherits=require("util").inherits;var RemoteParticipantSignaling=require("../remoteparticipant");var TrackV2=require("./track");function RemoteParticipantV2(participantState,getMediaStreamTrack,options){if(!(this instanceof RemoteParticipantV2)){return new RemoteParticipantV2(participantState,getMediaStreamTrack,options)}RemoteParticipantSignaling.call(this,participantState.sid,participantState.identity);options=Object.assign({TrackV2:TrackV2},options);Object.defineProperties(this,{_revision:{writable:true,value:null},_TrackV2:{value:options.TrackV2},_getMediaStreamTrack:{value:getMediaStreamTrack},revision:{enumerable:true,get:function(){return this._revision}}});return this.update(participantState)}inherits(RemoteParticipantV2,RemoteParticipantSignaling);RemoteParticipantV2.prototype._getOrCreateTrack=function _getOrCreateTrack(trackState){var TrackV2=this._TrackV2;var track=this.tracks.get(trackState.id);if(!track){track=new TrackV2(trackState);this.addTrack(track)}return track};RemoteParticipantV2.prototype.update=function update(participantState){if(this.revision!==null&&participantState.revision<=this.revision){return this}this._revision=participantState.revision;var tracksToKeep=new Set;participantState.tracks.forEach(function(trackState){var track=this._getOrCreateTrack(trackState);track.update(trackState);tracksToKeep.add(track)},this);this.tracks.forEach(function(track){if(!tracksToKeep.has(track)){this.removeTrack(track)}},this);if(participantState.state==="disconnected"&&this.state==="connected"){this.preempt("disconnected")}return this};RemoteParticipantV2.prototype.addTrack=function addTrack(track){RemoteParticipantSignaling.prototype.addTrack.call(this,track);this._getMediaStreamTrack(track.id).then(function(mediaStreamTrack){track.setMediaStreamTrack(mediaStreamTrack)});return this};module.exports=RemoteParticipantV2},{"../remoteparticipant":24,"./track":37,util:116}],35:[function(require,module,exports){"use strict";var inherits=require("util").inherits;var RecordingV2=require("./recording");var RoomSignaling=require("../room");var RemoteParticipantV2=require("./remoteparticipant");var util=require("../../util");var STATS_PUBLISH_INTERVAL_MS=1e3;function RoomV2(localParticipant,initialState,transport,peerConnectionManager,options){if(!(this instanceof RoomV2)){return new RoomV2(localParticipant,initialState,transport,peerConnectionManager,options)}options=Object.assign({RecordingSignaling:RecordingV2,RemoteParticipantV2:RemoteParticipantV2,statsPublishIntervalMs:STATS_PUBLISH_INTERVAL_MS},options);RoomSignaling.call(this,localParticipant,initialState.sid,initialState.name,options);Object.defineProperties(this,{_disconnectedParticipantSids:{value:new Set},_peerConnectionManager:{value:peerConnectionManager},_RemoteParticipantV2:{value:options.RemoteParticipantV2},_transport:{value:transport},_trackIdToParticipants:{value:new Map},_mediaStreamTrackDeferreds:{value:new Map}});handleLocalParticipantEvents(this,localParticipant);handlePeerConnectionEvents(this,peerConnectionManager);handleTransportEvents(this,transport);periodicallyPublishStats(this,localParticipant,transport,options.statsPublishIntervalMs);this._update(initialState)}inherits(RoomV2,RoomSignaling);RoomV2.prototype._deleteMediaStreamTrackDeferred=function _deleteMediaStreamTrackDeferred(id){return this._mediaStreamTrackDeferreds.delete(id)};RoomV2.prototype._getOrCreateMediaStreamTrackDeferred=function _getOrCreateMediaStreamTrackDeferred(id){var deferred=this._mediaStreamTrackDeferreds.get(id)||util.defer();var remoteMediaStreamTracks=this._peerConnectionManager.getRemoteMediaStreamTracks();var mediaStreamTrack=remoteMediaStreamTracks.find(function(track){return track.id===id&&track.readyState!=="ended"});if(mediaStreamTrack){deferred.resolve(mediaStreamTrack)}else{this._mediaStreamTrackDeferreds.set(id,deferred)}return deferred};RoomV2.prototype._addMediaStreamTrack=function _addMediaStreamTrack(mediaStreamTrack){var deferred=this._getOrCreateMediaStreamTrackDeferred(mediaStreamTrack.id);deferred.resolve(mediaStreamTrack);return this};RoomV2.prototype._disconnect=function _disconnect(error){var didDisconnect=RoomSignaling.prototype._disconnect.call(this,error);if(didDisconnect){this._transport.disconnect();this._peerConnectionManager.close()}return didDisconnect};RoomV2.prototype._getMediaStreamTrack=function _getMediaStreamTrack(id){var self=this;return this._getOrCreateMediaStreamTrackDeferred(id).promise.then(function(mediaStreamTrack){self._deleteMediaStreamTrackDeferred(id);return mediaStreamTrack})};RoomV2.prototype._getOrCreateRemoteParticipant=function _getOrCreateRemoteParticipant(participantState){var RemoteParticipantV2=this._RemoteParticipantV2;var participant=this.participants.get(participantState.sid);var self=this;if(!participant){participant=new RemoteParticipantV2(participantState,this._getMediaStreamTrack.bind(this));participant.on("stateChanged",function stateChanged(state){if(state==="disconnected"){participant.removeListener("stateChanged",stateChanged);self.participants.delete(participant.sid);self._disconnectedParticipantSids.add(participant.sid)}});this.connectParticipant(participant)}return participant};RoomV2.prototype._getState=function _getState(){return{participant:this.localParticipant.getState()}};RoomV2.prototype._publishNewLocalParticipantState=function _publishNewLocalParticipantState(){this.localParticipant.update();this._transport.publish(this._getState())};RoomV2.prototype._publishPeerConnectionState=function _publishPeerConnectionState(peerConnectionState){this._transport.publish(Object.assign({peer_connections:[peerConnectionState]},this._getState()))};RoomV2.prototype._update=function _update(roomState){var participantsToKeep=new Set;(roomState.participants||[]).forEach(function(participantState){if(participantState.sid===this.localParticipant.sid||this._disconnectedParticipantSids.has(participantState.sid)){return}var participant=this._getOrCreateRemoteParticipant(participantState);participant.update(participantState);participantsToKeep.add(participant)},this);if(roomState.peer_connections){this._peerConnectionManager.update(roomState.peer_connections)}if(roomState.recording){this.recording.update(roomState.recording)}return this};RoomV2.prototype.getStats=function getStats(){return this._peerConnectionManager.getStats()};function handleLocalParticipantEvents(roomV2,localParticipant){var removeListeners=new Map;var peerConnectionManager=roomV2._peerConnectionManager;var updateLocalParticipantStateAndRenegotiate=util.oncePerTick(function(){roomV2._publishNewLocalParticipantState();renegotiate()});function renegotiate(){var mediaStreamTracks=util.flatMap(localParticipant.tracks,function(track){return track.mediaStreamTrack});peerConnectionManager.setMediaStreamTracks(mediaStreamTracks)}function addListener(track){function updated(){roomV2._publishNewLocalParticipantState()}track.on("updated",updated);removeListener(track);removeListeners.set(track,track.removeListener.bind(track,"updated",updated))}function removeListener(track){var removeListener=removeListeners.get(track);if(removeListener){removeListener()}}function trackAdded(track){addListener(track);updateLocalParticipantStateAndRenegotiate()}function trackRemoved(track){removeListener(track);updateLocalParticipantStateAndRenegotiate()}localParticipant.on("trackAdded",trackAdded);localParticipant.on("trackRemoved",trackRemoved);localParticipant.tracks.forEach(addListener);roomV2.on("stateChanged",function stateChanged(state){if(state==="disconnected"){localParticipant.removeListener("trackAdded",trackAdded);localParticipant.removeListener("trackRemoved",trackRemoved);roomV2.removeListener("stateChanged",stateChanged);localParticipant.disconnect()}})}function handlePeerConnectionEvents(roomV2,peerConnectionManager){peerConnectionManager.on("description",function onDescription(description){roomV2._publishPeerConnectionState(description)});peerConnectionManager.dequeue("description");peerConnectionManager.on("candidates",function onCandidates(candidates){roomV2._publishPeerConnectionState(candidates)});peerConnectionManager.dequeue("candidates");peerConnectionManager.on("trackAdded",roomV2._addMediaStreamTrack.bind(roomV2));peerConnectionManager.dequeue("trackAdded");peerConnectionManager.getRemoteMediaStreamTracks().forEach(function(mediaStreamTrack){roomV2._addMediaStreamTrack(mediaStreamTrack)})}function handleTransportEvents(roomV2,transport){transport.on("message",roomV2._update.bind(roomV2));transport.on("stateChanged",function stateChanged(state,error){if(state==="disconnected"){if(roomV2.state==="connected"){roomV2._disconnect(error)}transport.removeListener("stateChanged",stateChanged)}})}function periodicallyPublishStats(roomV2,localParticipant,transport,intervalMs){var interval=setInterval(function(){roomV2.getStats().then(function(stats){stats.forEach(function(report){transport.publishEvent("quality","stats-report",{audioTrackStats:report.remoteAudioTrackStats,localAudioTrackStats:report.localAudioTrackStats,localVideoTrackStats:report.localVideoTrackStats,participantSid:localParticipant.sid,peerConnectionId:report.peerConnectionId,roomSid:roomV2.sid,videoTrackStats:report.remoteVideoTrackStats})})},function(){})},intervalMs);roomV2.on("stateChanged",function onStateChanged(state){if(state==="disconnected"){clearInterval(interval);roomV2.removeListener("stateChanged",onStateChanged)}})}module.exports=RoomV2},{"../../util":52,"../room":25,"./recording":33,"./remoteparticipant":34,util:116}],36:[function(require,module,exports){"use strict";var SIP=require("../../sip");function SIPJSMediaHandler(peerConnectionManager,createMessage){if(!(this instanceof SIPJSMediaHandler)){return new SIPJSMediaHandler(peerConnectionManager)}Object.defineProperties(this,{createMessage:{enumerable:true,value:createMessage},peerConnectionManager:{enumerable:true,value:peerConnectionManager}})}SIPJSMediaHandler.defaultFactory=function defaultFactory(){};SIPJSMediaHandler.defaultFactory.isSupported=function isSupported(){return SIP.WebRTC.isSupported()};SIPJSMediaHandler.prototype.close=function close(){this.peerConnectionManager.close()};SIPJSMediaHandler.prototype.getDescription=function getDescription(){var connectMessage=Object.assign({peer_connections:this.peerConnectionManager.getStates()},this.createMessage());return Promise.resolve({body:JSON.stringify(connectMessage),contentType:"application/room-signaling+json"})};SIPJSMediaHandler.prototype.hasDescription=function hasDescription(){return true};SIPJSMediaHandler.prototype.hold=function hold(){};SIPJSMediaHandler.prototype.isReady=function isReady(){return true};SIPJSMediaHandler.prototype.isMuted=function isMuted(){return{audio:false,video:false}};SIPJSMediaHandler.prototype.mute=function mute(){};SIPJSMediaHandler.prototype.render=function render(){};SIPJSMediaHandler.prototype.setDescription=function setDescription(message){var roomState=getRoomState(message);if(roomState){var peerConnectionStates=roomState.peer_connections;if(peerConnectionStates){return this.peerConnectionManager.update(peerConnectionStates)}}return Promise.resolve()};SIPJSMediaHandler.prototype.unhold=function unhold(){};SIPJSMediaHandler.prototype.unmute=function unmute(){};SIPJSMediaHandler.prototype.updateIceServers=function updateIceServers(){};function getRoomState(message){try{return JSON.parse(message.body)}catch(error){return null}}module.exports=SIPJSMediaHandler},{"../../sip":39}],37:[function(require,module,exports){"use strict";var inherits=require("util").inherits;var TrackSignaling=require("../track");function TrackV2(track){TrackSignaling.call(this,track.id,track.kind,track.enabled)}inherits(TrackV2,TrackSignaling);TrackV2.getState=function getState(track){return{enabled:track.isEnabled,id:track.id,kind:track.kind}};TrackV2.prototype.update=function update(track){this.enable(track.enabled);return this};module.exports=TrackV2},{"../track":26,util:116}],38:[function(require,module,exports){"use strict";var constants=require("../../util/constants");var inherits=require("util").inherits;var packageInfo=require("../../../package.json");var InsightsPublisher=require("../../util/insightspublisher");var NullInsightsPublisher=require("../../util/insightspublisher/null");var SIP=require("../../sip");var DefaultSIPJSMediaHandler=require("./sipjsmediahandler");var StateMachine=require("../../statemachine");var util=require("../../util");var TwilioErrors=require("../../util/twilio-video-errors");var createTwilioError=TwilioErrors.createTwilioError;var SignalingConnectionError=TwilioErrors.SignalingConnectionError;var SignalingConnectionTimeoutError=TwilioErrors.SignalingConnectionTimeoutError;var SignalingIncomingMessageInvalidError=TwilioErrors.SignalingIncomingMessageInvalidError;var SDK_NAME=packageInfo.name+".js";var SDK_VERSION=packageInfo.version;var VERSION=1;var states={connecting:["connected","disconnected"],connected:["disconnected","syncing"],syncing:["connected","disconnected"],disconnected:[]};function Transport(name,accessToken,localParticipant,peerConnectionManager,ua,options){if(!(this instanceof Transport)){return new Transport(name,accessToken,localParticipant,peerConnectionManager,ua,options)}options=Object.assign({InsightsPublisher:InsightsPublisher,NullInsightsPublisher:NullInsightsPublisher,SIPJSMediaHandler:DefaultSIPJSMediaHandler},options);StateMachine.call(this,"connecting",states);var eventPublisherOptions={};if(options.wsServerInsights){eventPublisherOptions.gateway=options.wsServerInsights}var session=createSession(this,name,accessToken,localParticipant,peerConnectionManager,ua,options.SIPJSMediaHandler);var EventPublisher=options.insights?options.InsightsPublisher:options.NullInsightsPublisher;Object.defineProperties(this,{_eventPublisher:{value:new EventPublisher(accessToken,SDK_NAME,SDK_VERSION,options.environment,options.realm,eventPublisherOptions)},_session:{value:session},_updatesReceived:{value:[]},_updatesToSend:{value:[]}});setupEventListeners(this,session,ua)}inherits(Transport,StateMachine);Transport.prototype.disconnect=function disconnect(error){if(this.state!=="disconnected"){this.preempt("disconnected",null,[error]);this._session.terminate({body:JSON.stringify({type:"disconnect",version:VERSION}),extraHeaders:["Content-Type: application/room-signaling+json"]});this._eventPublisher.disconnect();return true}return false};Transport.prototype.publish=function publish(update){update=Object.assign({type:"update",version:VERSION},update);switch(this.state){case"connected":publishWithRetries(this,this._session,update);return true;case"connecting":case"syncing":this._updatesToSend.push(update);return true;case"disconnected":default:return false}};Transport.prototype.publishEvent=function publishEvent(groupName,eventName,payload){return this._eventPublisher.publish(groupName,eventName,payload)};Transport.prototype.sync=function sync(){if(this.state==="connected"){this.preempt("syncing");this._session.sendReinvite();return true}return false};function createSession(transport,name,accessToken,localParticipant,peerConnectionManager,ua,SIPJSMediaHandler){var target="sip:"+util.makeServerSIPURI();return ua.invite(target,{extraHeaders:[constants.headers.X_TWILIO_ACCESSTOKEN+": "+accessToken,"Session-Expires: 120"],media:{stream:{}},mediaHandlerFactory:function mediaHandlerFactory(){return new SIPJSMediaHandler(peerConnectionManager,function createMessage(){if(transport.state==="disconnected"){return{type:"disconnect",version:VERSION}}var type={connecting:"connect",syncing:"sync"}[transport.state]||"update";var message={name:name,participant:localParticipant.getState(),type:type,version:VERSION};var sdpFormat=util.getSdpFormat();if(type==="connect"&&sdpFormat){message.format=sdpFormat}return message})},onInfo:function onInfo(request){this.emit("info",request);request.reply(200)}})}function withJitter(value,jitter){var rand=Math.random();return value-jitter+Math.floor(2*jitter*rand+.5)}function publishWithRetries(transport,session,payload,attempts){attempts=attempts||0;return new Promise(function(resolve,reject){function receiveResponse(response){switch(Math.floor(response.status_code/100)){case 2:resolve();break;case 5:if(attempts<constants.PUBLISH_MAX_ATTEMPTS){resolve(publishWithRetries(transport,session,payload,++attempts))}else{reject(new Error("Transport failed to send a message even "+"after "+constants.PUBLISH_MAX_ATTEMPTS+" attempts"))}break;default:reject(response)}}function sendRequest(){if(transport.state==="disconnected"){return}session.sendRequest("INFO",{body:JSON.stringify(payload),extraHeaders:["Content-Type: application/room-signaling+json","Event: room-signaling","Info-Package: room-signaling"],receiveResponse:receiveResponse})}if(attempts===0){sendRequest();return}var backOffMs=(1<<attempts-1)*constants.PUBLISH_BACKOFF_MS;setTimeout(sendRequest,withJitter(backOffMs,constants.PUBLISH_BACKOFF_JITTER))})}function reducePeerConnections(peerConnections){return Array.from(peerConnections.reduce(function(peerConnectionsById,update){var reduced=peerConnectionsById.get(update.id)||update;if(!reduced.description&&update.description){reduced.description=update.description}else if(reduced.description&&update.description){if(update.description.revision>reduced.description.revision){reduced.description=update.description}}if(!reduced.ice&&update.ice){reduced.ice=update.ice}else if(reduced.ice&&update.ice){if(update.ice.revision>reduced.ice.revision){reduced.ice=update.ice}}peerConnectionsById.set(reduced.id,reduced);return peerConnectionsById},new Map).values())}function reduceUpdates(updates){return updates.reduce(function(reduced,update){if(!reduced.participant&&update.participant){reduced.participant=update.participant}else if(reduced.participant&&update.participant){if(update.participant.revision>reduced.participant.revision){reduced.participant=update.participant}}if(!reduced.peer_connections&&update.peer_connections){reduced.peer_connections=reducePeerConnections(update.peer_connections)}else if(reduced.peer_connections&&update.peer_connections){reduced.peer_connections=reducePeerConnections(reduced.peer_connections.concat(update.peer_connections))}return reduced},{type:"update",version:VERSION})}function parseRequestOrResponseBody(requestOrResponse){if(requestOrResponse.body){try{return JSON.parse(requestOrResponse.body)}catch(e){throw new SignalingIncomingMessageInvalidError}}return null}function getTwilioErrorFromRequestOrResponseBody(requestOrResponse){try{var message=parseRequestOrResponseBody(requestOrResponse);return message&&message.type==="error"?createTwilioError(message.code,message.message):null}catch(error){return error}}function getTwilioErrorFromRequestOrResponseHeaders(requestOrResponse){var headers=requestOrResponse.headers;if(headers&&headers["X-Twilio-Error"]){var twilioErrorHeader=headers["X-Twilio-Error"][0].raw.split(" ");var code=parseInt(twilioErrorHeader[0],10);var message=twilioErrorHeader.slice(1).join(" ");return createTwilioError(code,message)}return null}function getTwilioErrorFromRequestOrResponse(requestOrResponse){return getTwilioErrorFromRequestOrResponseHeaders(requestOrResponse)||getTwilioErrorFromRequestOrResponseBody(requestOrResponse)}function setupEventListeners(transport,session,ua){function disconnect(requestOrResponse,cause){var twilioError
;if(requestOrResponse&&!(requestOrResponse instanceof SIP.OutgoingRequest)){twilioError=getTwilioErrorFromRequestOrResponse(requestOrResponse)}if(!twilioError){switch(cause){case SIP.C.causes.REQUEST_TIMEOUT:twilioError=new SignalingConnectionTimeoutError;break;case SIP.C.causes.CONNECTION_ERROR:twilioError=new SignalingConnectionError;break}}transport.disconnect(twilioError)}function handleRequestOrResponse(requestOrResponse){if(requestOrResponse instanceof SIP.OutgoingRequest){return}var error;try{error=getTwilioErrorFromRequestOrResponse(requestOrResponse)}catch(e){if(e instanceof SignalingIncomingMessageInvalidError){return}error=e}if(error){transport.disconnect(error);return}var message;try{message=parseRequestOrResponseBody(requestOrResponse)}catch(e){}if(!message){return}switch(transport.state){case"connected":switch(message.type){case"connected":case"synced":case"update":transport.emit("message",message);return;case"disconnected":transport.preempt("disconnected");return;default:return}case"connecting":switch(message.type){case"connected":transport.emit("connected",message);transport.preempt("connected");return;case"synced":case"update":transport._updatesReceived.push(message);return;case"disconnected":transport.preempt("disconnected");return;default:return}case"disconnected":return;case"syncing":switch(message.type){case"connected":case"update":transport._updatesReceived.push(message);return;case"synced":transport.emit("message",message);transport.preempt("connected");return;case"disconnected":transport.preempt("disconnected");return;default:return}default:return}}session.on("info",handleRequestOrResponse);session.once("bye",disconnect);session.once("accepted",handleRequestOrResponse);session.once("failed",disconnect);transport.on("stateChanged",function stateChanged(state){switch(state){case"connected":session.removeListener("accepted",handleRequestOrResponse);session.removeListener("failed",disconnect);var updates=transport._updatesToSend.splice(0);if(updates.length){transport.publish(reduceUpdates(updates))}transport._updatesReceived.splice(0).forEach(transport.emit.bind(transport,"message"));return;case"disconnected":session.removeListener("accepted",handleRequestOrResponse);session.removeListener("failed",disconnect);session.removeListener("info",handleRequestOrResponse);session.removeListener("bye",disconnect);transport.removeListener("stateChanged",stateChanged);ua.stop();return;case"syncing":return;default:return}});ua.once("disconnected",disconnect)}module.exports=Transport},{"../../../package.json":117,"../../sip":39,"../../statemachine":40,"../../util":52,"../../util/constants":50,"../../util/insightspublisher":53,"../../util/insightspublisher/null":54,"../../util/twilio-video-errors":57,"./sipjsmediahandler":36,util:116}],39:[function(require,module,exports){(function(global){"use strict";var toplevel=global.window||global;var Transport=require("@twilio/sip.js/src/Transport");var WebSocket=toplevel.WebSocket?toplevel.WebSocket:require("ws");var addEventListener=toplevel.addEventListener?toplevel.addEventListener.bind(toplevel):null;module.exports=require("@twilio/sip.js/src/SIP")({addEventListener:addEventListener,console:toplevel.console,Promise:toplevel.Promise,WebSocket:WebSocket,timers:toplevel,Transport:Transport})}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"@twilio/sip.js/src/SIP":77,"@twilio/sip.js/src/Transport":86,ws:118}],40:[function(require,module,exports){"use strict";var EventEmitter=require("events").EventEmitter;var inherits=require("util").inherits;var util=require("./util");function StateMachine(initialState,states){EventEmitter.call(this);var lock=null;var state=initialState;states=transformStates(states);Object.defineProperties(this,{_lock:{get:function(){return lock},set:function(_lock){lock=_lock}},_reachableStates:{value:reachable(states)},_state:{get:function(){return state},set:function(_state){state=_state}},_states:{value:states},_whenDeferreds:{value:new Set},isLocked:{enumerable:true,get:function(){return lock!==null}},state:{enumerable:true,get:function(){return state}}});var self=this;this.on("stateChanged",function(state){self._whenDeferreds.forEach(function(deferred){deferred.when(state,deferred.resolve,deferred.reject)})})}inherits(StateMachine,EventEmitter);StateMachine.prototype._whenPromise=function _whenPromise(when){if(typeof when!=="function"){return Promise.reject(new Error("when() executor must be a function"))}var deferred=util.defer();var self=this;deferred.when=when;this._whenDeferreds.add(deferred);return deferred.promise.then(function(payload){self._whenDeferreds.delete(deferred);return payload},function(error){self._whenDeferreds.delete(deferred);throw error})};StateMachine.prototype.bracket=function bracket(name,transitionFunction){var key;var self=this;function releaseLock(error){if(self.hasLock(key)){self.releaseLockCompletely(key)}if(error){throw error}}return this.takeLock(name).then(function gotKey(_key){key=_key;return transitionFunction(key)}).then(function success(result){releaseLock();return result},releaseLock)};StateMachine.prototype.hasLock=function hasLock(key){return this._lock===key};StateMachine.prototype.preempt=function preempt(newState,name,payload){if(!isValidTransition(this._states,this.state,newState)){throw new Error('Cannot transition from "'+this.state+'" to "'+newState+'"')}var oldLock;if(this.isLocked){oldLock=this._lock;this._lock=null}var key=null;if(name){key=this.takeLockSync(name)}var preemptionKey=key?null:this.takeLockSync("preemption");this.transition(newState,key||preemptionKey,payload);if(oldLock){oldLock.resolve()}if(preemptionKey){this.releaseLock(preemptionKey)}return key};StateMachine.prototype.releaseLock=function releaseLock(key){if(!this.isLocked){throw new Error("Could not release the lock for "+key.name+" because the StateMachine is not locked")}else if(!this.hasLock(key)){throw new Error("Could not release the lock for "+key.name+" because "+this._lock.name+" has the lock")}if(key.depth===0){this._lock=null;key.resolve()}else{key.depth--}};StateMachine.prototype.releaseLockCompletely=function releaseLockCompletely(key){if(!this.isLocked){throw new Error("Could not release the lock for "+key.name+" because the StateMachine is not locked")}else if(!this.hasLock(key)){throw new Error("Could not release the lock for "+key.name+" because "+this._lock.name+" has the lock")}key.depth=0;this._lock=null;key.resolve()};StateMachine.prototype.takeLock=function takeLock(nameOrKey){if(typeof nameOrKey==="object"){var key=nameOrKey;var self=this;return new Promise(function takeReentrantLock(resolve){resolve(self.takeLockSync(key))})}var name=nameOrKey;if(this.isLocked){var takeLock=this.takeLock.bind(this,name);return this._lock.promise.then(takeLock)}return Promise.resolve(this.takeLockSync(name))};StateMachine.prototype.takeLockSync=function takeLockSync(nameOrKey){var key=typeof nameOrKey==="string"?null:nameOrKey;var name=key?key.name:nameOrKey;if(key&&!this.hasLock(key)||!key&&this.isLocked){throw new Error("Could not take the lock for "+name+" "+"because the lock for "+this._lock.name+" was not released")}if(key){key.depth++;return key}var lock=makeLock(name);this._lock=lock;return lock};StateMachine.prototype.transition=function transition(newState,key,payload){payload=payload||[];if(this.isLocked){if(!key){throw new Error("You must provide the key in order to "+"transition")}else if(!this.hasLock(key)){throw new Error("Could not transition using the key for "+key.name+" because "+this._lock.name+" has the lock")}}else if(key){throw new Error("Key provided for "+key.name+", but the "+"StateMachine was not locked (possibly due to preemption)")}if(!isValidTransition(this._states,this.state,newState)){throw new Error('Cannot transition from "'+this.state+'" to "'+newState+'"')}this._state=newState;this.emit.apply(this,["stateChanged",newState].concat(payload))};StateMachine.prototype.tryTransition=function tryTransition(newState,key,payload){try{this.transition(newState,key,payload)}catch(error){return false}return true};StateMachine.prototype.when=function when(state){var self=this;if(this.state===state){return Promise.resolve(this)}else if(!isValidTransition(this._reachableStates,this.state,state)){return Promise.reject(createUnreachableError(this.state,state))}return this._whenPromise(function when(newState,resolve,reject){if(newState===state){resolve(self)}else if(!isValidTransition(self._reachableStates,newState,state)){reject(createUnreachableError(newState,state))}})};function isValidTransition(graph,from,to){return graph.get(from).has(to)}function makeLock(name){var lock=util.defer();lock.name=name;lock.depth=0;return lock}function reachable(graph){return Array.from(graph.keys()).reduce(function(newGraph,from){return newGraph.set(from,reachableFrom(graph,from))},new Map)}function reachableFrom(graph,from,to){to=to||new Set;graph.get(from).forEach(function(node){if(!to.has(node)){to.add(node);reachableFrom(graph,node,to).forEach(to.add,to)}});return to}function transformStates(states){var newStates=new Map;for(var key in states){newStates.set(key,new Set(states[key]))}return newStates}function createUnreachableError(here,there){return new Error('"'+there+'" cannot be reached from "'+here+'"')}module.exports=StateMachine},{"./util":52,events:112,util:116}],41:[function(require,module,exports){"use strict";var inherits=require("util").inherits;var LocalTrackStats=require("./localtrackstats");function LocalAudioTrackStats(trackId,statsReport){LocalTrackStats.call(this,trackId,statsReport);Object.defineProperties(this,{audioLevel:{value:typeof statsReport.audioInputLevel==="number"?statsReport.audioInputLevel:null,enumerable:true},jitter:{value:typeof statsReport.jitter==="number"?statsReport.jitter:null,enumerable:true}})}inherits(LocalAudioTrackStats,LocalTrackStats);module.exports=LocalAudioTrackStats},{"./localtrackstats":42,util:116}],42:[function(require,module,exports){"use strict";var inherits=require("util").inherits;var TrackStats=require("./trackstats");function LocalTrackStats(trackId,statsReport){TrackStats.call(this,trackId,statsReport);Object.defineProperties(this,{bytesSent:{value:typeof statsReport.bytesSent==="number"?statsReport.bytesSent:null,enumerable:true},packetsSent:{value:typeof statsReport.packetsSent==="number"?statsReport.packetsSent:null,enumerable:true},roundTripTime:{value:typeof statsReport.roundTripTime==="number"?statsReport.roundTripTime:null,enumerable:true}})}inherits(LocalTrackStats,TrackStats);module.exports=LocalTrackStats},{"./trackstats":48,util:116}],43:[function(require,module,exports){"use strict";var inherits=require("util").inherits;var LocalTrackStats=require("./localtrackstats");function LocalVideoTrackStats(trackId,statsReport){LocalTrackStats.call(this,trackId,statsReport);var captureDimensions=null;if(typeof statsReport.frameWidthInput==="number"&&typeof statsReport.frameHeightInput==="number"){captureDimensions={};Object.defineProperties(captureDimensions,{width:{value:statsReport.frameWidthInput,enumerable:true},height:{value:statsReport.frameHeightInput,enumerable:true}})}var dimensions=null;if(typeof statsReport.frameWidthSent==="number"&&typeof statsReport.frameHeightSent==="number"){dimensions={};Object.defineProperties(dimensions,{width:{value:statsReport.frameWidthSent,enumerable:true},height:{value:statsReport.frameHeightSent,enumerable:true}})}Object.defineProperties(this,{captureDimensions:{value:captureDimensions,enumerable:true},dimensions:{value:dimensions,enumerable:true},captureFrameRate:{value:typeof statsReport.frameRateInput==="number"?statsReport.frameRateInput:null,enumerable:true},frameRate:{value:typeof statsReport.frameRateSent==="number"?statsReport.frameRateSent:null,enumerable:true}})}inherits(LocalVideoTrackStats,LocalTrackStats);module.exports=LocalVideoTrackStats},{"./localtrackstats":42,util:116}],44:[function(require,module,exports){"use strict";var inherits=require("util").inherits;var RemoteTrackStats=require("./remotetrackstats");function RemoteAudioTrackStats(trackId,statsReport){RemoteTrackStats.call(this,trackId,statsReport);Object.defineProperties(this,{audioLevel:{value:typeof statsReport.audioOutputLevel==="number"?statsReport.audioOutputLevel:null,enumerable:true},jitter:{value:typeof statsReport.jitter==="number"?statsReport.jitter:null,enumerable:true}})}inherits(RemoteAudioTrackStats,RemoteTrackStats);module.exports=RemoteAudioTrackStats},{"./remotetrackstats":45,util:116}],45:[function(require,module,exports){"use strict";var inherits=require("util").inherits;var TrackStats=require("./trackstats");function RemoteTrackStats(trackId,statsReport){TrackStats.call(this,trackId,statsReport);Object.defineProperties(this,{bytesReceived:{value:typeof statsReport.bytesReceived==="number"?statsReport.bytesReceived:null,enumerable:true},packetsReceived:{value:typeof statsReport.packetsReceived==="number"?statsReport.packetsReceived:null,enumerable:true}})}inherits(RemoteTrackStats,TrackStats);module.exports=RemoteTrackStats},{"./trackstats":48,util:116}],46:[function(require,module,exports){"use strict";var inherits=require("util").inherits;var RemoteTrackStats=require("./remotetrackstats");function RemoteVideoTrackStats(trackId,statsReport){RemoteTrackStats.call(this,trackId,statsReport);var dimensions=null;if(typeof statsReport.frameWidthReceived==="number"&&typeof statsReport.frameHeightReceived==="number"){dimensions={};Object.defineProperties(dimensions,{width:{value:statsReport.frameWidthReceived,enumerable:true},height:{value:statsReport.frameHeightReceived,enumerable:true}})}Object.defineProperties(this,{dimensions:{value:dimensions,enumerable:true},frameRate:{value:typeof statsReport.frameRateReceived==="number"?statsReport.frameRateReceived:null,enumerable:true}})}inherits(RemoteVideoTrackStats,RemoteTrackStats);module.exports=RemoteVideoTrackStats},{"./remotetrackstats":45,util:116}],47:[function(require,module,exports){"use strict";var LocalAudioTrackStats=require("./localaudiotrackstats");var LocalVideoTrackStats=require("./localvideotrackstats");var RemoteAudioTrackStats=require("./remoteaudiotrackstats");var RemoteVideoTrackStats=require("./remotevideotrackstats");function StatsReport(peerConnectionId,statsResponse){if(typeof peerConnectionId!=="string"){throw new Error("RTCPeerConnection id must be a string")}Object.defineProperties(this,{peerConnectionId:{value:peerConnectionId,enumerable:true},localAudioTrackStats:{value:statsResponse.localAudioTrackStats.map(function(report){return new LocalAudioTrackStats(report.trackId,report)}),enumerable:true},localVideoTrackStats:{value:statsResponse.localVideoTrackStats.map(function(report){return new LocalVideoTrackStats(report.trackId,report)}),enumerable:true},remoteAudioTrackStats:{value:statsResponse.remoteAudioTrackStats.map(function(report){return new RemoteAudioTrackStats(report.trackId,report)}),enumerable:true},remoteVideoTrackStats:{value:statsResponse.remoteVideoTrackStats.map(function(report){return new RemoteVideoTrackStats(report.trackId,report)}),enumerable:true}})}module.exports=StatsReport},{"./localaudiotrackstats":41,"./localvideotrackstats":43,"./remoteaudiotrackstats":44,"./remotevideotrackstats":46}],48:[function(require,module,exports){"use strict";function TrackStats(trackId,statsReport){if(typeof trackId!=="string"){throw new Error("Track id must be a string")}Object.defineProperties(this,{trackId:{value:trackId,enumerable:true},timestamp:{value:statsReport.timestamp,enumerable:true},ssrc:{value:statsReport.ssrc,enumerable:true},packetsLost:{value:typeof statsReport.packetsLost==="number"?statsReport.packetsLost:null,enumerable:true},codec:{value:typeof statsReport.codecName==="string"?statsReport.codecName:null,enumerable:true}})}module.exports=TrackStats},{}],49:[function(require,module,exports){"use strict";function CancelablePromise(onCreate,onCancel){var self=this;Object.defineProperties(this,{_isCancelable:{writable:true,value:true},_isCanceled:{writable:true,value:false},_onCancel:{value:onCancel}});Object.defineProperty(this,"_promise",{value:new Promise(function(resolve,reject){onCreate(function _resolve(value){self._isCancelable=false;resolve(value)},function _reject(reason){self._isCancelable=false;reject(reason)},function isCanceled(){return self._isCanceled})})})}CancelablePromise.reject=function reject(reason){return new CancelablePromise(function rejected(resolve,reject){reject(reason)},function onCancel(){})};CancelablePromise.resolve=function resolve(result){return new CancelablePromise(function resolved(resolve){resolve(result)},function onCancel(){})};CancelablePromise.prototype.cancel=function cancel(){if(this._isCancelable){this._isCanceled=true;this._onCancel()}return this};CancelablePromise.prototype.catch=function _catch(){var args=[].slice.call(arguments);var promise=this._promise;return new CancelablePromise(function onCreate(resolve,reject){promise.catch.apply(promise,args).then(resolve,reject)},this._onCancel)};CancelablePromise.prototype.then=function then(){var args=[].slice.call(arguments);var promise=this._promise;return new CancelablePromise(function onCreate(resolve,reject){promise.then.apply(promise,args).then(resolve,reject)},this._onCancel)};module.exports=CancelablePromise},{}],50:[function(require,module,exports){"use strict";module.exports.DEFAULT_ENVIRONMENT="prod";module.exports.DEFAULT_REALM="us1";module.exports.DEFAULT_LOG_LEVEL="warn";module.exports.REGISTRAR_SERVER="endpoint.twilio.com";module.exports.WS_SERVER=function(environment,realm){switch(environment){case"prod":switch(realm){case"us1":return"wss://endpoint.twilio.com";default:return"wss://endpoint."+realm+".twilio.com"}default:return"wss://endpoint."+environment+"-"+realm+".twilio.com"}};module.exports.ECS_SERVER=function(environment,realm){switch(environment){case"prod":return"https://ecs."+realm+".twilio.com";default:return"https://ecs."+environment+"-"+realm+".twilio.com"}};module.exports.ECS_TIMEOUT=60;module.exports.PUBLISH_MAX_ATTEMPTS=5;module.exports.PUBLISH_BACKOFF_JITTER=10;module.exports.PUBLISH_BACKOFF_MS=20;module.exports.ICE_SERVERS_TIMEOUT_MS=3e3;module.exports.ICE_SERVERS_DEFAULT_TTL=3600;module.exports.DEFAULT_ICE_SERVERS=function(environment){switch(environment){case"prod":return[{urls:"stun:global.stun.twilio.com:3478?transport=udp"}];default:return[{urls:"stun:global.stun."+environment+".twilio.com:3478?transport=udp"}]}};module.exports.headers={X_TWILIO_ACCESSTOKEN:"X-Twilio-AccessToken"};function article(word){return["a","e","i","o","u"].indexOf(word.toLowerCase()[0])>=0?"an":"a"}module.exports.typeErrors={INVALID_TYPE:function(name,type){return new TypeError(name+" must be "+article(type)+" "+type)},INVALID_VALUE:function(name,values){return new RangeError(name+" must be one of ",values.join(", "))},REQUIRED_ARGUMENT:function(name){return new TypeError(name+" must be specified")}}},{}],51:[function(require,module,exports){"use strict";function Filter(options){if(!(this instanceof Filter)){return new Filter(options)}options=Object.assign({getKey:function defaultGetKey(a){return a},getValue:function defaultGetValue(a){return a},isLessThanOrEqualTo:function defaultIsLessThanOrEqualTo(a,b){return a<=b}},options);Object.defineProperties(this,{_getKey:{value:options.getKey},_getValue:{value:options.getValue},_isLessThanOrEqualTo:{value:options.isLessThanOrEqualTo},_map:{value:new Map}})}Filter.prototype.toMap=function toMap(){return new Map(this._map)};Filter.prototype.updateAndFilter=function filter(entries){return entries.filter(this.update,this)};Filter.prototype.update=function update(entry){var key=this._getKey(entry);var value=this._getValue(entry);if(this._map.has(key)&&this._isLessThanOrEqualTo(value,this._map.get(key))){return false}this._map.set(key,value);return true};module.exports=Filter},{}],52:[function(require,module,exports){"use strict";var constants=require("./constants");function asLocalTrack(track,options){if(track instanceof options.LocalAudioTrack||track instanceof options.LocalVideoTrack){return track}if(track instanceof options.MediaStreamTrack){return track.kind==="audio"?new options.LocalAudioTrack(track,options):new options.LocalVideoTrack(track,options)}throw new constants.typeErrors.INVALID_TYPE("track","LocalAudioTrack, LocalVideoTrack or MediaStreamTrack")}function difference(list1,list2){list1=Array.isArray(list1)?new Set(list1):new Set(list1.values());list2=Array.isArray(list2)?new Set(list2):new Set(list2.values());var difference=new Set;list1.forEach(function(item){if(!list2.has(item)){difference.add(item)}});return difference}function flatMap(list,mapFn){var listArray=list instanceof Map||list instanceof Set?Array.from(list.values()):list;return listArray.reduce(function(flattened,item){var mapped=mapFn(item);return flattened.concat(mapped)},[])}function guessBrowser(){if(typeof webkitRTCPeerConnection!=="undefined"){return"chrome"}else if(typeof mozRTCPeerConnection!=="undefined"){return"firefox"}else if(typeof RTCPeerConnection!=="undefined"){if(typeof navigator!=="undefined"&&navigator.userAgent.match(/AppleWebKit\/(\d+)\./)){return"safari"}}return null}function makeClientSIPURI(){return makeUUID()+"@"+constants.REGISTRAR_SERVER}function makeServerSIPURI(){return"orchestrator@"+constants.REGISTRAR_SERVER}function makeUUID(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(c){var r=Math.random()*16|0;var v=c==="x"?r:r&3|8;return v.toString(16)})}function oncePerTick(fn){var timeout=null;function nextTick(){timeout=null;fn()}return function scheduleNextTick(){if(timeout){clearTimeout(timeout)}timeout=setTimeout(nextTick)}}function promiseFromEvents(operation,eventEmitter,successEvent,failureEvent){return new Promise(function(resolve,reject){function onSuccess(){var args=[].slice.call(arguments);if(failureEvent){eventEmitter.removeListener(failureEvent,onFailure)}resolve.apply(null,args)}function onFailure(){var args=[].slice.call(arguments);eventEmitter.removeListener(successEvent,onSuccess);reject.apply(null,args)}eventEmitter.once(successEvent,onSuccess);if(failureEvent){eventEmitter.once(failureEvent,onFailure)}operation()})}function getOrNull(obj,path){return path.split(".").reduce(function(output,step){if(!output){return null}return output[step]},obj)}function defer(){var deferred={};deferred.promise=new Promise(function(resolve,reject){deferred.resolve=resolve;deferred.reject=reject});return deferred}function delegateMethod(source,wrapper,target,methodName){if(methodName in wrapper){return}else if(methodName.match(/^on[a-z]+$/)){return}var type;try{type=typeof source[methodName]}catch(error){}if(type!=="function"){return}wrapper[methodName]=function(){return this[target][methodName].apply(this[target],arguments)}}function delegateMethods(source,wrapper,target){for(var methodName in source){delegateMethod(source,wrapper,target,methodName)}}function proxyProperties(source,wrapper,target){Object.getOwnPropertyNames(source).forEach(function(propertyName){proxyProperty(source,wrapper,target,propertyName)})}function proxyProperty(source,wrapper,target,propertyName){if(propertyName in wrapper){return}else if(propertyName.match(/^on[a-z]+$/)){Object.defineProperty(wrapper,propertyName,{value:null,writable:true});target.addEventListener(propertyName.slice(2),function(){wrapper.dispatchEvent.apply(wrapper,arguments)});return}Object.defineProperty(wrapper,propertyName,{enumerable:true,get:function(){return target[propertyName]}})}function legacyPromise(promise,onSuccess,onFailure){if(onSuccess){return promise.then(function(result){onSuccess(result)},function(error){onFailure(error)})}return promise}function buildLogLevels(logLevel){if(typeof logLevel==="string"){return{default:logLevel,media:logLevel,signaling:logLevel,webrtc:logLevel}}return logLevel}function trackClass(track,local){local=local?"Local":"";return local+(track.kind||"").replace(/\w{1}/,function(m){return m.toUpperCase()})+"Track"}function getSdpFormat(){return typeof mozRTCPeerConnection!=="undefined"?"unified":null}module.exports.constants=constants;module.exports.asLocalTrack=asLocalTrack;module.exports.difference=difference;module.exports.flatMap=flatMap;module.exports.guessBrowser=guessBrowser;module.exports.makeClientSIPURI=makeClientSIPURI;module.exports.makeServerSIPURI=makeServerSIPURI;module.exports.makeUUID=makeUUID;module.exports.oncePerTick=oncePerTick;module.exports.promiseFromEvents=promiseFromEvents;module.exports.getOrNull=getOrNull;module.exports.defer=defer;module.exports.delegateMethods=delegateMethods;module.exports.proxyProperties=proxyProperties;module.exports.legacyPromise=legacyPromise;module.exports.buildLogLevels=buildLogLevels;module.exports.trackClass=trackClass;module.exports.getSdpFormat=getSdpFormat},{"./constants":50}],53:[function(require,module,exports){(function(global){"use strict";var EventEmitter=require("events").EventEmitter;var inherits=require("util").inherits;var MAX_RECONNECT_ATTEMPTS=5;var RECONNECT_INTERVAL_MS=50;var WS_CLOSE_NORMAL=1e3;var toplevel=global.window||global;var WebSocket=toplevel.WebSocket?toplevel.WebSocket:require("ws");function InsightsPublisher(token,sdkName,sdkVersion,environment,realm,options){if(!(this instanceof InsightsPublisher)){return new InsightsPublisher(token,sdkName,sdkVersion,environment,realm,options)}EventEmitter.call(this);options=Object.assign({gateway:createGateway(environment,realm)+"/v1/VideoEvents",maxReconnectAttempts:MAX_RECONNECT_ATTEMPTS,reconnectIntervalMs:RECONNECT_INTERVAL_MS,userAgent:navigator.userAgent,WebSocket:WebSocket},options);Object.defineProperties(this,{_connectTimestamp:{value:0,writable:true},_eventQueue:{value:[]},_reconnectAttemptsLeft:{value:options.maxReconnectAttempts,writable:true},_ws:{value:null,writable:true},_WebSocket:{value:options.WebSocket}});var self=this;this.on("disconnected",function maybeReconnect(error){self._session=null;if(error&&self._reconnectAttemptsLeft>0){self.emit("reconnecting");reconnect(self,token,sdkName,sdkVersion,options);return}self.removeListener("disconnected",maybeReconnect)});connect(this,token,sdkName,sdkVersion,options)}inherits(InsightsPublisher,EventEmitter);InsightsPublisher.prototype._publish=function _publish(event){event.session=this._session;this._ws.send(JSON.stringify(event))};InsightsPublisher.prototype.disconnect=function disconnect(){if(this._ws.readyState===this._WebSocket.CLOSING||this._ws.readyState===this._WebSocket.CLOSED){return false}try{this._ws.close()}catch(error){}this.emit("disconnected");return true};InsightsPublisher.prototype.publish=function publish(groupName,eventName,payload){if(this._ws.readyState===this._WebSocket.CLOSING||this._ws.readyState===this._WebSocket.CLOSED){return false}var publishOrEnqueue=typeof this._session==="string"?this._publish.bind(this):this._eventQueue.push.bind(this._eventQueue);publishOrEnqueue({group:groupName,name:eventName,payload:payload,timestamp:Date.now(),type:"event",version:1});return true};function connect(publisher,token,sdkName,sdkVersion,options){publisher._connectTimestamp=Date.now();publisher._reconnectAttemptsLeft--;publisher._ws=new options.WebSocket(options.gateway);var ws=publisher._ws;ws.addEventListener("close",function(event){if(event.code===WS_CLOSE_NORMAL){publisher.emit("disconnected");return}publisher.emit("disconnected",new Error("WebSocket Error "+event.code+": "+event.reason))});ws.addEventListener("message",function(message){handleConnectResponse(publisher,JSON.parse(message.data),options)});ws.addEventListener("open",function(){var connectRequest={type:"connect",token:token,version:1};connectRequest.publisher={name:sdkName,sdkVersion:sdkVersion,userAgent:options.userAgent};ws.send(JSON.stringify(connectRequest))})}function createGateway(environment,realm){return environment==="prod"?"wss://sdkgw."+realm+".twilio.com":"wss://sdkgw."+environment+"-"+realm+".twilio.com"}function handleConnectResponse(publisher,response,options){switch(response.type){case"connected":publisher._session=response.session;publisher._reconnectAttemptsLeft=options.maxReconnectAttempts;publisher._eventQueue.splice(0).forEach(publisher._publish,publisher);publisher.emit("connected");break;case"error":publisher._ws.close();publisher.emit("disconnected",new Error(response.message));break}}function reconnect(publisher,token,sdkName,sdkVersion,options){var connectInterval=Date.now()-publisher._connectTimestamp;var timeToWait=options.reconnectIntervalMs-connectInterval;if(timeToWait>0){setTimeout(function(){connect(publisher,token,sdkName,sdkVersion,options)},timeToWait);return}connect(publisher,token,sdkName,sdkVersion,options)}module.exports=InsightsPublisher}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{events:112,util:116,ws:118}],54:[function(require,module,exports){"use strict";function InsightsPublisher(){if(!(this instanceof InsightsPublisher)){return new InsightsPublisher}Object.defineProperties(this,{_connected:{writable:true,value:true}})}InsightsPublisher.prototype.disconnect=function disconnect(){if(this._connected){this._connected=false;return true}return false};InsightsPublisher.prototype.publish=function publish(){return this._connected};module.exports=InsightsPublisher},{}],55:[function(require,module,exports){"use strict";var constants=require("./constants");var DEFAULT_LOG_LEVEL=constants.DEFAULT_LOG_LEVEL;var E=require("./constants").typeErrors;function Log(moduleName,component,logLevels){if(!(this instanceof Log)){return new Log(moduleName,component,logLevels)}if(typeof moduleName!=="string"){throw new E.INVALID_TYPE("moduleName","string")}if(!component){throw new E.REQUIRED_ARGUMENT("component")}if(typeof logLevels!=="object"){logLevels={}}validateLogLevels(logLevels);Object.defineProperties(this,{_deprecationWarnings:{value:new Set},_logLevels:{value:logLevels},_warnings:{value:new Set},logLevel:{get:function get(){return Log.getLevelByName(logLevels[moduleName]||DEFAULT_LOG_LEVEL)}},name:{get:component.toString.bind(component)}})}Object.defineProperties(Log,{DEBUG:{value:0},INFO:{value:1},WARN:{value:2},ERROR:{value:3},OFF:{value:4},_levels:{value:[{name:"DEBUG",logFn:console.log},{name:"INFO",logFn:console.info},{name:"WARN",logFn:console.warn},{name:"ERROR",logFn:console.error},{name:"OFF",logFn:function noop(){}}]}});var LOG_LEVELS_SET={};var LOG_LEVEL_VALUES=[];var LOG_LEVEL_NAMES=Log._levels.map(function(level,i){LOG_LEVELS_SET[level.name]=true;LOG_LEVEL_VALUES.push(i);return level.name});function validateLogLevel(level){if(!(level in LOG_LEVELS_SET)){throw new E.INVALID_VALUE("level",LOG_LEVEL_NAMES)}}function validateLogLevels(levels){Object.keys(levels).forEach(function(moduleName){validateLogLevel(levels[moduleName].toUpperCase())})}Log.getLevelByName=function getLevelByName(name){if(!isNaN(name)){return parseInt(name,10)}name=name.toUpperCase();validateLogLevel(name);return Log[name]};Log.prototype.createLog=function createLog(moduleName,component){return new Log(moduleName,component,this._logLevels)};Log.prototype.setLevels=function setLevels(levels){validateLogLevels(levels);Object.assign(this._logLevels,levels);return this};Log.prototype.log=function log(logLevel,message){var logSpec=Log._levels[logLevel];if(!logSpec){throw new E.INVALID_VALUE("logLevel",LOG_LEVEL_VALUES)}if(this.logLevel<=logLevel){var levelName=logSpec.name;var prefix=(new Date).toISOString().split("T").concat(["|",levelName,"in",this.name+":"]);logSpec.logFn.apply(console,prefix.concat(message))}return this};Log.prototype.debug=function debug(){return this.log(Log.DEBUG,[].slice.call(arguments))};Log.prototype.deprecated=function deprecated(deprecationWarning){if(this._deprecationWarnings.has(deprecationWarning)){return this}this._deprecationWarnings.add(deprecationWarning);return this.warn(deprecationWarning)}
;Log.prototype.info=function info(){return this.log(Log.INFO,[].slice.call(arguments))};Log.prototype.warn=function warn(){return this.log(Log.WARN,[].slice.call(arguments))};Log.prototype.warnOnce=function warnOnce(warning){if(this._warnings.has(warning)){return this}this._warnings.add(warning);return this.warn(warning)};Log.prototype.error=function error(){return this.log(Log.ERROR,[].slice.call(arguments))};Log.prototype.throw=function throwFn(error,customMessage){if(error.clone){error=error.clone(customMessage)}this.log(Log.ERROR,error);throw error};module.exports=Log},{"./constants":50}],56:[function(require,module,exports){"use strict";var EventEmitter=require("events").EventEmitter;var inherits=require("util").inherits;var util=require("./");function TimeoutPromise(original,initialTimeout){if(!(this instanceof TimeoutPromise)){return new TimeoutPromise(original,initialTimeout)}EventEmitter.call(this);var deferred=util.defer();var isTimedOut=false;var timedOut=new Error("Timed out");var timeout=null;var timer=null;Object.defineProperties(this,{_deferred:{value:deferred},_isTimedOut:{get:function(){return isTimedOut},set:function(_isTimedOut){isTimedOut=_isTimedOut}},_timedOut:{value:timedOut},_timeout:{get:function(){return timeout},set:function(_timeout){timeout=_timeout}},_timer:{get:function(){return timer},set:function(_timer){timer=_timer}},_promise:{value:deferred.promise},isTimedOut:{enumerable:true,get:function(){return isTimedOut}},timeout:{enumerable:true,get:function(){return timeout}}});var self=this;original.then(function originalResolved(){clearTimeout(self._timer);deferred.resolve.apply(deferred.promise,arguments)},function originalRejected(){clearTimeout(self._timer);deferred.reject.apply(deferred.promise,arguments)});if(initialTimeout){this.start(initialTimeout)}}inherits(TimeoutPromise,EventEmitter);TimeoutPromise.prototype.catch=function _catch(){return this._promise.catch.apply(this._promise,arguments)};TimeoutPromise.prototype.start=function start(timeout){if(this._timer){return this}var self=this;this._timeout=timeout;this._timer=setTimeout(function timer(){if(self._timer){self._isTimedOut=true;self.emit("timedOut",self);self._deferred.reject(self._timedOut)}},this.timeout);return this};TimeoutPromise.prototype.then=function then(){return this._promise.then.apply(this._promise,arguments)};module.exports=TimeoutPromise},{"./":52,events:112,util:116}],57:[function(require,module,exports){"use strict";var inherits=require("util").inherits;var TwilioError=require("./twilioerror");var TwilioErrorByCode={};exports.createTwilioError=function createTwilioError(code,message){code=typeof code==="number"?code:0;message=typeof message==="string"&&message?message:"Unknown error";return TwilioErrorByCode[code]?new TwilioErrorByCode[code]:new TwilioError(code,message)};function AccessTokenInvalidError(){TwilioError.call(this,20101,"Invalid Access Token")}inherits(AccessTokenInvalidError,TwilioError);exports.AccessTokenInvalidError=AccessTokenInvalidError;Object.defineProperty(TwilioErrorByCode,20101,{value:AccessTokenInvalidError});function SignalingConnectionError(){TwilioError.call(this,53e3,"Signaling connection error")}inherits(SignalingConnectionError,TwilioError);exports.SignalingConnectionError=SignalingConnectionError;Object.defineProperty(TwilioErrorByCode,53e3,{value:SignalingConnectionError});function SignalingConnectionDisconnectedError(){TwilioError.call(this,53001,"Signaling connection disconnected")}inherits(SignalingConnectionDisconnectedError,TwilioError);exports.SignalingConnectionDisconnectedError=SignalingConnectionDisconnectedError;Object.defineProperty(TwilioErrorByCode,53001,{value:SignalingConnectionDisconnectedError});function SignalingConnectionTimeoutError(){TwilioError.call(this,53002,"Signaling connection timed out")}inherits(SignalingConnectionTimeoutError,TwilioError);exports.SignalingConnectionTimeoutError=SignalingConnectionTimeoutError;Object.defineProperty(TwilioErrorByCode,53002,{value:SignalingConnectionTimeoutError});function SignalingIncomingMessageInvalidError(){TwilioError.call(this,53003,"Client received an invalid signaling message")}inherits(SignalingIncomingMessageInvalidError,TwilioError);exports.SignalingIncomingMessageInvalidError=SignalingIncomingMessageInvalidError;Object.defineProperty(TwilioErrorByCode,53003,{value:SignalingIncomingMessageInvalidError});function SignalingOutgoingMessageInvalidError(){TwilioError.call(this,53004,"Client sent an invalid signaling message")}inherits(SignalingOutgoingMessageInvalidError,TwilioError);exports.SignalingOutgoingMessageInvalidError=SignalingOutgoingMessageInvalidError;Object.defineProperty(TwilioErrorByCode,53004,{value:SignalingOutgoingMessageInvalidError});function RoomNameInvalidError(){TwilioError.call(this,53100,"Room name is invalid")}inherits(RoomNameInvalidError,TwilioError);exports.RoomNameInvalidError=RoomNameInvalidError;Object.defineProperty(TwilioErrorByCode,53100,{value:RoomNameInvalidError});function RoomNameTooLongError(){TwilioError.call(this,53101,"Room name is too long")}inherits(RoomNameTooLongError,TwilioError);exports.RoomNameTooLongError=RoomNameTooLongError;Object.defineProperty(TwilioErrorByCode,53101,{value:RoomNameTooLongError});function RoomNameCharsInvalidError(){TwilioError.call(this,53102,"Room name contains invalid characters")}inherits(RoomNameCharsInvalidError,TwilioError);exports.RoomNameCharsInvalidError=RoomNameCharsInvalidError;Object.defineProperty(TwilioErrorByCode,53102,{value:RoomNameCharsInvalidError});function RoomCreateFailedError(){TwilioError.call(this,53103,"Unable to create Room")}inherits(RoomCreateFailedError,TwilioError);exports.RoomCreateFailedError=RoomCreateFailedError;Object.defineProperty(TwilioErrorByCode,53103,{value:RoomCreateFailedError});function RoomConnectFailedError(){TwilioError.call(this,53104,"Unable to connect to Room")}inherits(RoomConnectFailedError,TwilioError);exports.RoomConnectFailedError=RoomConnectFailedError;Object.defineProperty(TwilioErrorByCode,53104,{value:RoomConnectFailedError});function RoomMaxParticipantsExceededError(){TwilioError.call(this,53105,"Room contains too many Participants")}inherits(RoomMaxParticipantsExceededError,TwilioError);exports.RoomMaxParticipantsExceededError=RoomMaxParticipantsExceededError;Object.defineProperty(TwilioErrorByCode,53105,{value:RoomMaxParticipantsExceededError});function RoomNotFoundError(){TwilioError.call(this,53106,"Room not found")}inherits(RoomNotFoundError,TwilioError);exports.RoomNotFoundError=RoomNotFoundError;Object.defineProperty(TwilioErrorByCode,53106,{value:RoomNotFoundError});function ParticipantIdentityInvalidError(){TwilioError.call(this,53200,"Participant identity is invalid")}inherits(ParticipantIdentityInvalidError,TwilioError);exports.ParticipantIdentityInvalidError=ParticipantIdentityInvalidError;Object.defineProperty(TwilioErrorByCode,53200,{value:ParticipantIdentityInvalidError});function ParticipantIdentityTooLongError(){TwilioError.call(this,53201,"Participant identity is too long")}inherits(ParticipantIdentityTooLongError,TwilioError);exports.ParticipantIdentityTooLongError=ParticipantIdentityTooLongError;Object.defineProperty(TwilioErrorByCode,53201,{value:ParticipantIdentityTooLongError});function ParticipantIdentityCharsInvalidError(){TwilioError.call(this,53202,"Participant identity contains invalid characters")}inherits(ParticipantIdentityCharsInvalidError,TwilioError);exports.ParticipantIdentityCharsInvalidError=ParticipantIdentityCharsInvalidError;Object.defineProperty(TwilioErrorByCode,53202,{value:ParticipantIdentityCharsInvalidError});function ParticipantMaxTracksExceededError(){TwilioError.call(this,53203,"Participant has too many Tracks")}inherits(ParticipantMaxTracksExceededError,TwilioError);exports.ParticipantMaxTracksExceededError=ParticipantMaxTracksExceededError;Object.defineProperty(TwilioErrorByCode,53203,{value:ParticipantMaxTracksExceededError});function ParticipantNotFoundError(){TwilioError.call(this,53204,"Participant not found")}inherits(ParticipantNotFoundError,TwilioError);exports.ParticipantNotFoundError=ParticipantNotFoundError;Object.defineProperty(TwilioErrorByCode,53204,{value:ParticipantNotFoundError});function TrackInvalidError(){TwilioError.call(this,53300,"Track is invalid")}inherits(TrackInvalidError,TwilioError);exports.TrackInvalidError=TrackInvalidError;Object.defineProperty(TwilioErrorByCode,53300,{value:TrackInvalidError});function TrackNameInvalidError(){TwilioError.call(this,53301,"Track name is invalid")}inherits(TrackNameInvalidError,TwilioError);exports.TrackNameInvalidError=TrackNameInvalidError;Object.defineProperty(TwilioErrorByCode,53301,{value:TrackNameInvalidError});function TrackNameTooLongError(){TwilioError.call(this,53302,"Track name is too long")}inherits(TrackNameTooLongError,TwilioError);exports.TrackNameTooLongError=TrackNameTooLongError;Object.defineProperty(TwilioErrorByCode,53302,{value:TrackNameTooLongError});function TrackNameCharsInvalidError(){TwilioError.call(this,53303,"Track name contains invalid characters")}inherits(TrackNameCharsInvalidError,TwilioError);exports.TrackNameCharsInvalidError=TrackNameCharsInvalidError;Object.defineProperty(TwilioErrorByCode,53303,{value:TrackNameCharsInvalidError});function MediaClientLocalDescFailedError(){TwilioError.call(this,53400,"Client is unable to create or apply a local media description")}inherits(MediaClientLocalDescFailedError,TwilioError);exports.MediaClientLocalDescFailedError=MediaClientLocalDescFailedError;Object.defineProperty(TwilioErrorByCode,53400,{value:MediaClientLocalDescFailedError});function MediaServerLocalDescFailedError(){TwilioError.call(this,53401,"Server is unable to create or apply a local media description")}inherits(MediaServerLocalDescFailedError,TwilioError);exports.MediaServerLocalDescFailedError=MediaServerLocalDescFailedError;Object.defineProperty(TwilioErrorByCode,53401,{value:MediaServerLocalDescFailedError});function MediaClientRemoteDescFailedError(){TwilioError.call(this,53402,"Client is unable to apply a remote media description")}inherits(MediaClientRemoteDescFailedError,TwilioError);exports.MediaClientRemoteDescFailedError=MediaClientRemoteDescFailedError;Object.defineProperty(TwilioErrorByCode,53402,{value:MediaClientRemoteDescFailedError});function MediaServerRemoteDescFailedError(){TwilioError.call(this,53403,"Server is unable to apply a remote media description")}inherits(MediaServerRemoteDescFailedError,TwilioError);exports.MediaServerRemoteDescFailedError=MediaServerRemoteDescFailedError;Object.defineProperty(TwilioErrorByCode,53403,{value:MediaServerRemoteDescFailedError});function MediaNoSupportedCodecError(){TwilioError.call(this,53404,"No supported codec")}inherits(MediaNoSupportedCodecError,TwilioError);exports.MediaNoSupportedCodecError=MediaNoSupportedCodecError;Object.defineProperty(TwilioErrorByCode,53404,{value:MediaNoSupportedCodecError});function ConfigurationAcquireFailedError(){TwilioError.call(this,53500,"Unable to acquire configuration")}inherits(ConfigurationAcquireFailedError,TwilioError);exports.ConfigurationAcquireFailedError=ConfigurationAcquireFailedError;Object.defineProperty(TwilioErrorByCode,53500,{value:ConfigurationAcquireFailedError});function ConfigurationAcquireTurnFailedError(){TwilioError.call(this,53501,"Unable to acquire TURN credentials")}inherits(ConfigurationAcquireTurnFailedError,TwilioError);exports.ConfigurationAcquireTurnFailedError=ConfigurationAcquireTurnFailedError;Object.defineProperty(TwilioErrorByCode,53501,{value:ConfigurationAcquireTurnFailedError})},{"./twilioerror":58,util:116}],58:[function(require,module,exports){"use strict";var inherits=require("util").inherits;function TwilioError(code){var error=Error.apply(this,[].slice.call(arguments,1));error.name="TwilioError";Object.defineProperty(this,"code",{value:code,enumerable:true});Object.getOwnPropertyNames(error).forEach(function(prop){Object.defineProperty(this,prop,{value:error[prop],enumerable:true})},this)}inherits(TwilioError,Error);TwilioError.prototype.toString=function toString(){var message=this.message?": "+this.message:"";return this.name+" "+this.code+message};module.exports=TwilioError},{util:116}],59:[function(require,module,exports){module.exports={_args:[[{raw:"@twilio/sip.js@^0.7.6",scope:"@twilio",escapedName:"@twilio%2fsip.js",name:"@twilio/sip.js",rawSpec:"^0.7.6",spec:">=0.7.6 <0.8.0",type:"range"},"/home/travis/build/twilio/twilio-video.js"]],_from:"@twilio/sip.js@>=0.7.6 <0.8.0",_id:"@twilio/sip.js@0.7.6",_inCache:true,_location:"/@twilio/sip.js",_nodeVersion:"7.10.1",_npmOperationalInternal:{host:"s3://npm-registry-packages",tmp:"tmp/sip.js-0.7.6.tgz_1503335382018_0.028498857049271464"},_npmUser:{name:"twilio-ci",email:"mroberts+twilio-ci@twilio.com"},_npmVersion:"4.2.0",_phantomChildren:{},_requested:{raw:"@twilio/sip.js@^0.7.6",scope:"@twilio",escapedName:"@twilio%2fsip.js",name:"@twilio/sip.js",rawSpec:"^0.7.6",spec:">=0.7.6 <0.8.0",type:"range"},_requiredBy:["/"],_resolved:"https://registry.npmjs.org/@twilio/sip.js/-/sip.js-0.7.6.tgz",_shasum:"9186c69736b2ec092c00791087b0a7868975c14c",_shrinkwrap:null,_spec:"@twilio/sip.js@^0.7.6",_where:"/home/travis/build/twilio/twilio-video.js",author:{name:"OnSIP",email:"developer@onsip.com",url:"http://sipjs.com/authors/"},browser:{"./src/environment.js":"./src/environment_browser.js"},bugs:{url:"https://github.com/onsip/SIP.js/issues"},contributors:[{url:"https://github.com/onsip/SIP.js/blob/master/THANKS.md"}],dependencies:{},description:"A simple, intuitive, and powerful JavaScript signaling library",devDependencies:{beefy:"^2.1.5",browserify:"^4.1.8",grunt:"~0.4.0","grunt-browserify":"^4.0.1","grunt-cli":"~0.1.6","grunt-contrib-copy":"^0.5.0","grunt-contrib-jasmine":"^1.0.3","grunt-contrib-jshint":">0.5.0","grunt-contrib-uglify":"~0.2.0","grunt-peg":"~1.3.1","grunt-trimtrailingspaces":"^0.4.0",pegjs:"^0.8.0","release-tool":"^0.2.2"},directories:{},dist:{shasum:"9186c69736b2ec092c00791087b0a7868975c14c",tarball:"https://registry.npmjs.org/@twilio/sip.js/-/sip.js-0.7.6.tgz"},engines:{node:">=0.12"},gitHead:"1dac536a50b3d9b91fd3a3d86ecd7923d7c6f70c",homepage:"http://sipjs.com",keywords:["sip","websocket","webrtc","library","javascript"],license:"MIT",main:"src/index.js",maintainers:[{name:"twilio-ci",email:"mroberts+twilio-ci@twilio.com"}],name:"@twilio/sip.js",optionalDependencies:{},readme:"ERROR: No README data found!",repository:{type:"git",url:"git+https://github.com/onsip/SIP.js.git"},scripts:{build:"grunt build",repl:"beefy test/repl.js --open",test:"grunt travis --verbose"},title:"SIP.js",version:"0.7.6"}},{}],60:[function(require,module,exports){"use strict";module.exports=function(SIP){var ClientContext;ClientContext=function(ua,method,target,options){var originalTarget=target;if(target===undefined){throw new TypeError("Not enough arguments")}this.ua=ua;this.logger=ua.getLogger("sip.clientcontext");this.method=method;target=ua.normalizeTarget(target);if(!target){throw new TypeError("Invalid target: "+originalTarget)}options=Object.create(options||Object.prototype);options.extraHeaders=(options.extraHeaders||[]).slice();this.request=new SIP.OutgoingRequest(this.method,target,this.ua,options.params,options.extraHeaders);if(options.body){this.body={};this.body.body=options.body;if(options.contentType){this.body.contentType=options.contentType}this.request.body=this.body}this.localIdentity=this.request.from;this.remoteIdentity=this.request.to;this.data={}};ClientContext.prototype=Object.create(SIP.EventEmitter.prototype);ClientContext.prototype.send=function(){new SIP.RequestSender(this,this.ua).send();return this};ClientContext.prototype.cancel=function(options){options=options||{};options.extraHeaders=(options.extraHeaders||[]).slice();var cancel_reason=SIP.Utils.getCancelReason(options.status_code,options.reason_phrase);this.request.cancel(cancel_reason,options.extraHeaders);this.emit("cancel")};ClientContext.prototype.receiveResponse=function(response){var cause=SIP.Utils.getReasonPhrase(response.status_code);switch(true){case/^1[0-9]{2}$/.test(response.status_code):this.emit("progress",response,cause);break;case/^2[0-9]{2}$/.test(response.status_code):if(this.ua.applicants[this]){delete this.ua.applicants[this]}this.emit("accepted",response,cause);break;default:if(this.ua.applicants[this]){delete this.ua.applicants[this]}this.emit("rejected",response,cause);this.emit("failed",response,cause);break}};ClientContext.prototype.onRequestTimeout=function(){this.emit("failed",null,SIP.C.causes.REQUEST_TIMEOUT)};ClientContext.prototype.onTransportError=function(){this.emit("failed",null,SIP.C.causes.CONNECTION_ERROR)};SIP.ClientContext=ClientContext}},{}],61:[function(require,module,exports){"use strict";module.exports=function(name,version){return{USER_AGENT:name+"/"+version,SIP:"sip",SIPS:"sips",causes:{CONNECTION_ERROR:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",AUTHENTICATION_ERROR:"Authentication Error",DIALOG_ERROR:"Dialog Error",WEBRTC_NOT_SUPPORTED:"WebRTC Not Supported",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",NO_PRACK:"No PRACK",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},supported:{UNSUPPORTED:"none",SUPPORTED:"supported",REQUIRED:"required"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",REFER:"REFER",PRACK:"PRACK",REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},OPTION_TAGS:{"100rel":true,199:true,answermode:true,"early-session":true,eventlist:true,explicitsub:true,"from-change":true,"geolocation-http":true,"geolocation-sip":true,gin:true,gruu:true,histinfo:true,ice:true,join:true,"multiple-refer":true,norefersub:true,nosub:true,outbound:true,path:true,policy:true,precondition:true,pref:true,privacy:true,"recipient-list-invite":true,"recipient-list-message":true,"recipient-list-subscribe":true,replaces:true,"resource-priority":true,"sdp-anat":true,"sec-agree":true,tdialog:true,timer:true,uui:true}}}},{}],62:[function(require,module,exports){"use strict";module.exports=function(SIP){var RequestSender;RequestSender=function(dialog,applicant,request){this.dialog=dialog;this.applicant=applicant;this.request=request;this.reattempt=false;this.reattemptTimer=null};RequestSender.prototype={send:function(){var self=this,request_sender=new SIP.RequestSender(this,this.dialog.owner.ua);request_sender.send();if(this.request.method===SIP.C.INVITE&&request_sender.clientTransaction.state!==SIP.Transactions.C.STATUS_TERMINATED){this.dialog.uac_pending_reply=true;request_sender.clientTransaction.on("stateChanged",function stateChanged(){if(this.state===SIP.Transactions.C.STATUS_ACCEPTED||this.state===SIP.Transactions.C.STATUS_COMPLETED||this.state===SIP.Transactions.C.STATUS_TERMINATED){this.removeListener("stateChanged",stateChanged);self.dialog.uac_pending_reply=false;if(self.dialog.uas_pending_reply===false){self.dialog.owner.onReadyToReinvite()}}})}},onRequestTimeout:function(){this.applicant.onRequestTimeout()},onTransportError:function(){this.applicant.onTransportError()},receiveResponse:function(response){var self=this;if(response.status_code===408||response.status_code===481){this.applicant.onDialogError(response)}else if(response.method===SIP.C.INVITE&&response.status_code===491){if(this.reattempt){this.applicant.receiveResponse(response)}else{this.request.cseq.value=this.dialog.local_seqnum+=1;this.reattemptTimer=SIP.Timers.setTimeout(function(){if(self.applicant.owner.status!==SIP.Session.C.STATUS_TERMINATED){self.reattempt=true;self.request_sender.send()}},this.getReattemptTimeout())}}else{this.applicant.receiveResponse(response)}}};return RequestSender}},{}],63:[function(require,module,exports){"use strict";module.exports=function(SIP){var RequestSender=require("./Dialog/RequestSender")(SIP);var Dialog,C={STATUS_EARLY:1,STATUS_CONFIRMED:2};Dialog=function(owner,message,type,state){var contact;this.uac_pending_reply=false;this.uas_pending_reply=false;if(!message.hasHeader("contact")){return{error:"unable to create a Dialog without Contact header field"}}if(message instanceof SIP.IncomingResponse){state=message.status_code<200?C.STATUS_EARLY:C.STATUS_CONFIRMED}else{state=state||C.STATUS_CONFIRMED}contact=message.parseHeader("contact");if(type==="UAS"){this.id={call_id:message.call_id,local_tag:message.to_tag,remote_tag:message.from_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}};this.state=state;this.remote_seqnum=message.cseq;this.local_uri=message.parseHeader("to").uri;this.remote_uri=message.parseHeader("from").uri;this.remote_target=contact.uri;this.route_set=message.getHeaders("record-route");this.invite_seqnum=message.cseq;this.local_seqnum=message.cseq}else if(type==="UAC"){this.id={call_id:message.call_id,local_tag:message.from_tag,remote_tag:message.to_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}};this.state=state;this.invite_seqnum=message.cseq;this.local_seqnum=message.cseq;this.local_uri=message.parseHeader("from").uri;this.pracked=[];this.remote_uri=message.parseHeader("to").uri;this.remote_target=contact.uri;this.route_set=message.getHeaders("record-route").reverse();if(this.state===C.STATUS_EARLY&&!owner.hasOffer){this.mediaHandler=owner.mediaHandlerFactory(owner)}}this.logger=owner.ua.getLogger("sip.dialog",this.id.toString());this.owner=owner;owner.ua.dialogs[this.id.toString()]=this;this.logger.log("new "+type+" dialog created with status "+(this.state===C.STATUS_EARLY?"EARLY":"CONFIRMED"));owner.emit("dialog",this)};Dialog.prototype={update:function(message,type){this.state=C.STATUS_CONFIRMED;this.logger.log("dialog "+this.id.toString()+"  changed to CONFIRMED state");if(type==="UAC"){this.route_set=message.getHeaders("record-route").reverse()}},terminate:function(){this.logger.log("dialog "+this.id.toString()+" deleted");if(this.mediaHandler&&this.state!==C.STATUS_CONFIRMED){this.mediaHandler.peerConnection.close()}delete this.owner.ua.dialogs[this.id.toString()]},createRequest:function(method,extraHeaders,body){var cseq,request;extraHeaders=(extraHeaders||[]).slice();if(!this.local_seqnum){this.local_seqnum=Math.floor(Math.random()*1e4)}cseq=method===SIP.C.CANCEL||method===SIP.C.ACK?this.invite_seqnum:this.local_seqnum+=1;request=new SIP.OutgoingRequest(method,this.remote_target,this.owner.ua,{cseq:cseq,call_id:this.id.call_id,from_uri:this.local_uri,from_tag:this.id.local_tag,to_uri:this.remote_uri,to_tag:this.id.remote_tag,route_set:this.route_set},extraHeaders,body);request.dialog=this;return request},checkInDialogRequest:function(request){var self=this;if(!this.remote_seqnum){this.remote_seqnum=request.cseq}else if(request.cseq<this.remote_seqnum){if(request.method!==SIP.C.ACK){request.reply(500)}if(request.cseq===this.invite_seqnum){return true}return false}else if(request.cseq>this.remote_seqnum){this.remote_seqnum=request.cseq}switch(request.method){case SIP.C.INVITE:if(this.uac_pending_reply===true){request.reply(491)}else if(this.uas_pending_reply===true){var retryAfter=(Math.random()*10|0)+1;request.reply(500,null,["Retry-After:"+retryAfter]);return false}else{this.uas_pending_reply=true;request.server_transaction.on("stateChanged",function stateChanged(){if(this.state===SIP.Transactions.C.STATUS_ACCEPTED||this.state===SIP.Transactions.C.STATUS_COMPLETED||this.state===SIP.Transactions.C.STATUS_TERMINATED){this.removeListener("stateChanged",stateChanged);self.uas_pending_reply=false;if(self.uac_pending_reply===false){self.owner.onReadyToReinvite()}}})}if(request.hasHeader("contact")){request.server_transaction.on("stateChanged",function(){if(this.state===SIP.Transactions.C.STATUS_ACCEPTED){self.remote_target=request.parseHeader("contact").uri}})}break;case SIP.C.NOTIFY:if(request.hasHeader("contact")){request.server_transaction.on("stateChanged",function(){if(this.state===SIP.Transactions.C.STATUS_COMPLETED){self.remote_target=request.parseHeader("contact").uri}})}break}return true},sendRequest:function(applicant,method,options){options=options||{};var extraHeaders=(options.extraHeaders||[]).slice();var body=null;if(options.body){if(options.body.body){body=options.body}else{body={};body.body=options.body;if(options.contentType){body.contentType=options.contentType}}}var request=this.createRequest(method,extraHeaders,body),request_sender=new RequestSender(this,applicant,request);request_sender.send();return request},receiveRequest:function(request){if(!this.checkInDialogRequest(request)){return}this.owner.receiveRequest(request)}};Dialog.C=C;SIP.Dialog=Dialog}},{"./Dialog/RequestSender":62}],64:[function(require,module,exports){"use strict";module.exports=function(Utils){var DigestAuthentication;DigestAuthentication=function(ua){this.logger=ua.getLogger("sipjs.digestauthentication");this.username=ua.configuration.authorizationUser;this.password=ua.configuration.password;this.cnonce=null;this.nc=0;this.ncHex="00000000";this.response=null};DigestAuthentication.prototype.authenticate=function(request,challenge){this.algorithm=challenge.algorithm;this.realm=challenge.realm;this.nonce=challenge.nonce;this.opaque=challenge.opaque;this.stale=challenge.stale;if(this.algorithm){if(this.algorithm!=="MD5"){this.logger.warn('challenge with Digest algorithm different than "MD5", authentication aborted');return false}}else{this.algorithm="MD5"}if(!this.realm){this.logger.warn("challenge without Digest realm, authentication aborted");return false}if(!this.nonce){this.logger.warn("challenge without Digest nonce, authentication aborted");return false}if(challenge.qop){if(challenge.qop.indexOf("auth")>-1){this.qop="auth"}else if(challenge.qop.indexOf("auth-int")>-1){this.qop="auth-int"}else{this.logger.warn('challenge without Digest qop different than "auth" or "auth-int", authentication aborted');return false}}else{this.qop=null}this.method=request.method;this.uri=request.ruri;this.cnonce=Utils.createRandomToken(12);this.nc+=1;this.updateNcHex();if(this.nc===4294967296){this.nc=1;this.ncHex="00000001"}this.calculateResponse();return true};DigestAuthentication.prototype.calculateResponse=function(){var ha1,ha2;ha1=Utils.calculateMD5(this.username+":"+this.realm+":"+this.password);if(this.qop==="auth"){ha2=Utils.calculateMD5(this.method+":"+this.uri);this.response=Utils.calculateMD5(ha1+":"+this.nonce+":"+this.ncHex+":"+this.cnonce+":auth:"+ha2)}else if(this.qop==="auth-int"){ha2=Utils.calculateMD5(this.method+":"+this.uri+":"+Utils.calculateMD5(this.body?this.body:""));this.response=Utils.calculateMD5(ha1+":"+this.nonce+":"+this.ncHex+":"+this.cnonce+":auth-int:"+ha2)}else if(this.qop===null){ha2=Utils.calculateMD5(this.method+":"+this.uri);this.response=Utils.calculateMD5(ha1+":"+this.nonce+":"+ha2)}};DigestAuthentication.prototype.toString=function(){var auth_params=[];if(!this.response){throw new Error("response field does not exist, cannot generate Authorization header")}auth_params.push("algorithm="+this.algorithm);auth_params.push('username="'+this.username+'"');auth_params.push('realm="'+this.realm+'"');auth_params.push('nonce="'+this.nonce+'"');auth_params.push('uri="'+this.uri+'"');auth_params.push('response="'+this.response+'"');if(this.opaque){auth_params.push('opaque="'+this.opaque+'"')}if(this.qop){auth_params.push("qop="+this.qop);auth_params.push('cnonce="'+this.cnonce+'"');auth_params.push("nc="+this.ncHex)}return"Digest "+auth_params.join(", ")};DigestAuthentication.prototype.updateNcHex=function(){var hex=Number(this.nc).toString(16);this.ncHex="00000000".substr(0,8-hex.length)+hex};return DigestAuthentication}},{}],65:[function(require,module,exports){"use strict";var NodeEventEmitter=require("events").EventEmitter;module.exports=function(console){function EventEmitter(){NodeEventEmitter.call(this)}EventEmitter.prototype=Object.create(NodeEventEmitter.prototype,{constructor:{value:EventEmitter,enumerable:false,writable:true,configurable:true}});EventEmitter.prototype.off=function off(eventName,listener){var warning="";warning+="SIP.EventEmitter#off is deprecated and may be removed in future SIP.js versions.\n";warning+="Please use removeListener or removeAllListeners instead.\n";warning+="See here for more details:\n";warning+="http://nodejs.org/api/events.html#events_emitter_removelistener_event_listener";console.warn(warning);if(arguments.length<2){return this.removeAllListeners.apply(this,arguments)}else{return this.removeListener(eventName,listener)}};return EventEmitter}},{events:112}],66:[function(require,module,exports){"use strict";module.exports={ConfigurationError:function(){var exception=function(parameter,value){this.code=1;this.name="CONFIGURATION_ERROR";this.parameter=parameter;this.value=value;this.message=!this.value?"Missing parameter: "+this.parameter:"Invalid value "+JSON.stringify(this.value)+' for parameter "'+this.parameter+'"'};exception.prototype=new Error;return exception}(),InvalidStateError:function(){var exception=function(status){this.code=2;this.name="INVALID_STATE_ERROR";this.status=status;this.message="Invalid status: "+status};exception.prototype=new Error;return exception}(),NotSupportedError:function(){var exception=function(message){this.code=3;this.name="NOT_SUPPORTED_ERROR";this.message=message};exception.prototype=new Error;return exception}(),GetDescriptionError:function(){var exception=function(message){this.code=4;this.name="GET_DESCRIPTION_ERROR";this.message=message};exception.prototype=new Error;return exception}()}},{}],67:[function(require,module,exports){"use strict";var Grammar=require("./Grammar/dist/Grammar");module.exports=function(SIP){return{parse:function parseCustom(input,startRule){
var options={startRule:startRule,SIP:SIP};try{Grammar.parse(input,options)}catch(e){options.data=-1}return options.data}}}},{"./Grammar/dist/Grammar":68}],68:[function(require,module,exports){module.exports=function(){function peg$subclass(child,parent){function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor}function SyntaxError(message,expected,found,offset,line,column){this.message=message;this.expected=expected;this.found=found;this.offset=offset;this.line=line;this.column=column;this.name="SyntaxError"}peg$subclass(SyntaxError,Error);function parse(input){var options=arguments.length>1?arguments[1]:{},peg$FAILED={},peg$startRuleIndices={Contact:118,Name_Addr_Header:155,Record_Route:175,Request_Response:81,SIP_URI:45,Subscription_State:185,Supported:190,Require:181,Via:193,absoluteURI:84,Call_ID:117,Content_Disposition:129,Content_Length:134,Content_Type:135,CSeq:145,displayName:121,Event:148,From:150,host:52,Max_Forwards:153,Min_SE:212,Proxy_Authenticate:156,quoted_string:40,Refer_To:177,Replaces:178,Session_Expires:209,stun_URI:216,To:191,turn_URI:223,uuid:226,WWW_Authenticate:208,challenge:157},peg$startRuleIndex=118,peg$consts=["\r\n",{type:"literal",value:"\r\n",description:'"\\r\\n"'},/^[0-9]/,{type:"class",value:"[0-9]",description:"[0-9]"},/^[a-zA-Z]/,{type:"class",value:"[a-zA-Z]",description:"[a-zA-Z]"},/^[0-9a-fA-F]/,{type:"class",value:"[0-9a-fA-F]",description:"[0-9a-fA-F]"},/^[\0-\xFF]/,{type:"class",value:"[\\0-\\xFF]",description:"[\\0-\\xFF]"},/^["]/,{type:"class",value:'["]',description:'["]'}," ",{type:"literal",value:" ",description:'" "'},"\t",{type:"literal",value:"\t",description:'"\\t"'},/^[a-zA-Z0-9]/,{type:"class",value:"[a-zA-Z0-9]",description:"[a-zA-Z0-9]"},";",{type:"literal",value:";",description:'";"'},"/",{type:"literal",value:"/",description:'"/"'},"?",{type:"literal",value:"?",description:'"?"'},":",{type:"literal",value:":",description:'":"'},"@",{type:"literal",value:"@",description:'"@"'},"&",{type:"literal",value:"&",description:'"&"'},"=",{type:"literal",value:"=",description:'"="'},"+",{type:"literal",value:"+",description:'"+"'},"$",{type:"literal",value:"$",description:'"$"'},",",{type:"literal",value:",",description:'","'},"-",{type:"literal",value:"-",description:'"-"'},"_",{type:"literal",value:"_",description:'"_"'},".",{type:"literal",value:".",description:'"."'},"!",{type:"literal",value:"!",description:'"!"'},"~",{type:"literal",value:"~",description:'"~"'},"*",{type:"literal",value:"*",description:'"*"'},"'",{type:"literal",value:"'",description:'"\'"'},"(",{type:"literal",value:"(",description:'"("'},")",{type:"literal",value:")",description:'")"'},peg$FAILED,"%",{type:"literal",value:"%",description:'"%"'},null,[],function(){return" "},function(){return":"},/^[!-~]/,{type:"class",value:"[!-~]",description:"[!-~]"},/^[\x80-\uFFFF]/,{type:"class",value:"[\\x80-\\uFFFF]",description:"[\\x80-\\uFFFF]"},/^[\x80-\xBF]/,{type:"class",value:"[\\x80-\\xBF]",description:"[\\x80-\\xBF]"},/^[a-f]/,{type:"class",value:"[a-f]",description:"[a-f]"},"`",{type:"literal",value:"`",description:'"`"'},"<",{type:"literal",value:"<",description:'"<"'},">",{type:"literal",value:">",description:'">"'},"\\",{type:"literal",value:"\\",description:'"\\\\"'},"[",{type:"literal",value:"[",description:'"["'},"]",{type:"literal",value:"]",description:'"]"'},"{",{type:"literal",value:"{",description:'"{"'},"}",{type:"literal",value:"}",description:'"}"'},function(){return"*"},function(){return"/"},function(){return"="},function(){return"("},function(){return")"},function(){return">"},function(){return"<"},function(){return","},function(){return";"},function(){return":"},function(){return'"'},/^[!-']/,{type:"class",value:"[!-']",description:"[!-']"},/^[*-[]/,{type:"class",value:"[*-[]",description:"[*-[]"},/^[\]-~]/,{type:"class",value:"[\\]-~]",description:"[\\]-~]"},function(contents){return contents},/^[#-[]/,{type:"class",value:"[#-[]",description:"[#-[]"},/^[\0-\t]/,{type:"class",value:"[\\0-\\t]",description:"[\\0-\\t]"},/^[\x0B-\f]/,{type:"class",value:"[\\x0B-\\f]",description:"[\\x0B-\\f]"},/^[\x0E-\x7f]/,{type:"class",value:"[\\x0E-\x7f]",description:"[\\x0E-\x7f]"},function(){options.data.uri=new options.SIP.URI(options.data.scheme,options.data.user,options.data.host,options.data.port);delete options.data.scheme;delete options.data.user;delete options.data.host;delete options.data.host_type;delete options.data.port},function(){options.data.uri=new options.SIP.URI(options.data.scheme,options.data.user,options.data.host,options.data.port,options.data.uri_params,options.data.uri_headers);delete options.data.scheme;delete options.data.user;delete options.data.host;delete options.data.host_type;delete options.data.port;delete options.data.uri_params;if(options.startRule==="SIP_URI"){options.data=options.data.uri}},"sips",{type:"literal",value:"sips",description:'"sips"'},"sip",{type:"literal",value:"sip",description:'"sip"'},function(uri_scheme){options.data.scheme=uri_scheme},function(){options.data.user=decodeURIComponent(text().slice(0,-1))},function(){options.data.password=text()},function(){options.data.host=text();return options.data.host},function(){options.data.host_type="domain";return text()},/^[a-zA-Z0-9_\-]/,{type:"class",value:"[a-zA-Z0-9_\\-]",description:"[a-zA-Z0-9_\\-]"},/^[a-zA-Z0-9\-]/,{type:"class",value:"[a-zA-Z0-9\\-]",description:"[a-zA-Z0-9\\-]"},function(){options.data.host_type="IPv6";return text()},"::",{type:"literal",value:"::",description:'"::"'},function(){options.data.host_type="IPv6";return text()},function(){options.data.host_type="IPv4";return text()},"25",{type:"literal",value:"25",description:'"25"'},/^[0-5]/,{type:"class",value:"[0-5]",description:"[0-5]"},"2",{type:"literal",value:"2",description:'"2"'},/^[0-4]/,{type:"class",value:"[0-4]",description:"[0-4]"},"1",{type:"literal",value:"1",description:'"1"'},/^[1-9]/,{type:"class",value:"[1-9]",description:"[1-9]"},function(port){port=parseInt(port.join(""));options.data.port=port;return port},"transport=",{type:"literal",value:"transport=",description:'"transport="'},"udp",{type:"literal",value:"udp",description:'"udp"'},"tcp",{type:"literal",value:"tcp",description:'"tcp"'},"sctp",{type:"literal",value:"sctp",description:'"sctp"'},"tls",{type:"literal",value:"tls",description:'"tls"'},function(transport){if(!options.data.uri_params)options.data.uri_params={};options.data.uri_params["transport"]=transport.toLowerCase()},"user=",{type:"literal",value:"user=",description:'"user="'},"phone",{type:"literal",value:"phone",description:'"phone"'},"ip",{type:"literal",value:"ip",description:'"ip"'},function(user){if(!options.data.uri_params)options.data.uri_params={};options.data.uri_params["user"]=user.toLowerCase()},"method=",{type:"literal",value:"method=",description:'"method="'},function(method){if(!options.data.uri_params)options.data.uri_params={};options.data.uri_params["method"]=method},"ttl=",{type:"literal",value:"ttl=",description:'"ttl="'},function(ttl){if(!options.data.params)options.data.params={};options.data.params["ttl"]=ttl},"maddr=",{type:"literal",value:"maddr=",description:'"maddr="'},function(maddr){if(!options.data.uri_params)options.data.uri_params={};options.data.uri_params["maddr"]=maddr},"lr",{type:"literal",value:"lr",description:'"lr"'},function(){if(!options.data.uri_params)options.data.uri_params={};options.data.uri_params["lr"]=undefined},function(param,value){if(!options.data.uri_params)options.data.uri_params={};if(value===null){value=undefined}else{value=value[1]}options.data.uri_params[param.toLowerCase()]=value&&value.toLowerCase()},function(hname,hvalue){hname=hname.join("").toLowerCase();hvalue=hvalue.join("");if(!options.data.uri_headers)options.data.uri_headers={};if(!options.data.uri_headers[hname]){options.data.uri_headers[hname]=[hvalue]}else{options.data.uri_headers[hname].push(hvalue)}},function(){if(options.startRule==="Refer_To"){options.data.uri=new options.SIP.URI(options.data.scheme,options.data.user,options.data.host,options.data.port,options.data.uri_params,options.data.uri_headers);delete options.data.scheme;delete options.data.user;delete options.data.host;delete options.data.host_type;delete options.data.port;delete options.data.uri_params}},"//",{type:"literal",value:"//",description:'"//"'},function(){options.data.scheme=text()},{type:"literal",value:"SIP",description:'"SIP"'},function(){options.data.sip_version=text()},"INVITE",{type:"literal",value:"INVITE",description:'"INVITE"'},"ACK",{type:"literal",value:"ACK",description:'"ACK"'},"VXACH",{type:"literal",value:"VXACH",description:'"VXACH"'},"OPTIONS",{type:"literal",value:"OPTIONS",description:'"OPTIONS"'},"BYE",{type:"literal",value:"BYE",description:'"BYE"'},"CANCEL",{type:"literal",value:"CANCEL",description:'"CANCEL"'},"REGISTER",{type:"literal",value:"REGISTER",description:'"REGISTER"'},"SUBSCRIBE",{type:"literal",value:"SUBSCRIBE",description:'"SUBSCRIBE"'},"NOTIFY",{type:"literal",value:"NOTIFY",description:'"NOTIFY"'},"REFER",{type:"literal",value:"REFER",description:'"REFER"'},function(){options.data.method=text();return options.data.method},function(status_code){options.data.status_code=parseInt(status_code.join(""))},function(){options.data.reason_phrase=text()},function(){options.data=text()},function(){var idx,length;length=options.data.multi_header.length;for(idx=0;idx<length;idx++){if(options.data.multi_header[idx].parsed===null){options.data=null;break}}if(options.data!==null){options.data=options.data.multi_header}else{options.data=-1}},function(){var header;if(!options.data.multi_header)options.data.multi_header=[];try{header=new options.SIP.NameAddrHeader(options.data.uri,options.data.displayName,options.data.params);delete options.data.uri;delete options.data.displayName;delete options.data.params}catch(e){header=null}options.data.multi_header.push({position:peg$currPos,offset:offset(),parsed:header})},function(displayName){displayName=text().trim();if(displayName[0]==='"'){displayName=displayName.substring(1,displayName.length-1)}options.data.displayName=displayName},"q",{type:"literal",value:"q",description:'"q"'},function(q){if(!options.data.params)options.data.params={};options.data.params["q"]=q},"expires",{type:"literal",value:"expires",description:'"expires"'},function(expires){if(!options.data.params)options.data.params={};options.data.params["expires"]=expires},function(delta_seconds){return parseInt(delta_seconds.join(""))},"0",{type:"literal",value:"0",description:'"0"'},function(){return parseFloat(text())},function(param,value){if(!options.data.params)options.data.params={};if(value===null){value=undefined}else{value=value[1]}options.data.params[param.toLowerCase()]=value},"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(){if(options.startRule==="Content_Disposition"){options.data.type=text().toLowerCase()}},"handling",{type:"literal",value:"handling",description:'"handling"'},"optional",{type:"literal",value:"optional",description:'"optional"'},"required",{type:"literal",value:"required",description:'"required"'},function(length){options.data=parseInt(length.join(""))},function(){options.data=text()},"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(cseq_value){options.data.value=parseInt(cseq_value.join(""))},function(expires){options.data=expires},function(event_type){options.data.event=event_type.toLowerCase()},function(){var tag=options.data.tag;options.data=new options.SIP.NameAddrHeader(options.data.uri,options.data.displayName,options.data.params);if(tag){options.data.setParam("tag",tag)}},"tag",{type:"literal",value:"tag",description:'"tag"'},function(tag){options.data.tag=tag},function(forwards){options.data=parseInt(forwards.join(""))},function(min_expires){options.data=min_expires},function(){options.data=new options.SIP.NameAddrHeader(options.data.uri,options.data.displayName,options.data.params)},"digest",{type:"literal",value:"Digest",description:'"Digest"'},"realm",{type:"literal",value:"realm",description:'"realm"'},function(realm){options.data.realm=realm},"domain",{type:"literal",value:"domain",description:'"domain"'},"nonce",{type:"literal",value:"nonce",description:'"nonce"'},function(nonce){options.data.nonce=nonce},"opaque",{type:"literal",value:"opaque",description:'"opaque"'},function(opaque){options.data.opaque=opaque},"stale",{type:"literal",value:"stale",description:'"stale"'},"true",{type:"literal",value:"true",description:'"true"'},function(){options.data.stale=true},"false",{type:"literal",value:"false",description:'"false"'},function(){options.data.stale=false},"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(algorithm){options.data.algorithm=algorithm.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(qop_value){options.data.qop||(options.data.qop=[]);options.data.qop.push(qop_value.toLowerCase())},function(rack_value){options.data.value=parseInt(rack_value.join(""))},function(){var idx,length;length=options.data.multi_header.length;for(idx=0;idx<length;idx++){if(options.data.multi_header[idx].parsed===null){options.data=null;break}}if(options.data!==null){options.data=options.data.multi_header}else{options.data=-1}},function(){var header;if(!options.data.multi_header)options.data.multi_header=[];try{header=new options.SIP.NameAddrHeader(options.data.uri,options.data.displayName,options.data.params);delete options.data.uri;delete options.data.displayName;delete options.data.params}catch(e){header=null}options.data.multi_header.push({position:peg$currPos,offset:offset(),parsed:header})},function(){options.data=new options.SIP.NameAddrHeader(options.data.uri,options.data.displayName,options.data.params)},function(){if(!(options.data.replaces_from_tag&&options.data.replaces_to_tag)){options.data=-1}},function(){options.data={call_id:options.data}},"from-tag",{type:"literal",value:"from-tag",description:'"from-tag"'},function(from_tag){options.data.replaces_from_tag=from_tag},"to-tag",{type:"literal",value:"to-tag",description:'"to-tag"'},function(to_tag){options.data.replaces_to_tag=to_tag},"early-only",{type:"literal",value:"early-only",description:'"early-only"'},function(){options.data.early_only=true},function(r){return r},function(first,rest){return list(first,rest)},function(value){if(options.startRule==="Require"){options.data=value||[]}},function(rseq_value){options.data.value=parseInt(rseq_value.join(""))},"active",{type:"literal",value:"active",description:'"active"'},"pending",{type:"literal",value:"pending",description:'"pending"'},"terminated",{type:"literal",value:"terminated",description:'"terminated"'},function(){options.data.state=text()},"reason",{type:"literal",value:"reason",description:'"reason"'},function(reason){if(typeof reason!=="undefined")options.data.reason=reason},function(expires){if(typeof expires!=="undefined")options.data.expires=expires},"retry_after",{type:"literal",value:"retry_after",description:'"retry_after"'},function(retry_after){if(typeof retry_after!=="undefined")options.data.retry_after=retry_after},"deactivated",{type:"literal",value:"deactivated",description:'"deactivated"'},"probation",{type:"literal",value:"probation",description:'"probation"'},"rejected",{type:"literal",value:"rejected",description:'"rejected"'},"timeout",{type:"literal",value:"timeout",description:'"timeout"'},"giveup",{type:"literal",value:"giveup",description:'"giveup"'},"noresource",{type:"literal",value:"noresource",description:'"noresource"'},"invariant",{type:"literal",value:"invariant",description:'"invariant"'},function(value){if(options.startRule==="Supported"){options.data=value||[]}},function(){var tag=options.data.tag;options.data=new options.SIP.NameAddrHeader(options.data.uri,options.data.displayName,options.data.params);if(tag){options.data.setParam("tag",tag)}},"ttl",{type:"literal",value:"ttl",description:'"ttl"'},function(via_ttl_value){options.data.ttl=via_ttl_value},"maddr",{type:"literal",value:"maddr",description:'"maddr"'},function(via_maddr){options.data.maddr=via_maddr},"received",{type:"literal",value:"received",description:'"received"'},function(via_received){options.data.received=via_received},"branch",{type:"literal",value:"branch",description:'"branch"'},function(via_branch){options.data.branch=via_branch},"rport",{type:"literal",value:"rport",description:'"rport"'},function(){if(typeof response_port!=="undefined")options.data.rport=response_port.join("")},function(via_protocol){options.data.protocol=via_protocol},{type:"literal",value:"UDP",description:'"UDP"'},{type:"literal",value:"TCP",description:'"TCP"'},{type:"literal",value:"TLS",description:'"TLS"'},{type:"literal",value:"SCTP",description:'"SCTP"'},function(via_transport){options.data.transport=via_transport},function(){options.data.host=text()},function(via_sent_by_port){options.data.port=parseInt(via_sent_by_port.join(""))},function(ttl){return parseInt(ttl.join(""))},function(deltaSeconds){if(options.startRule==="Session_Expires"){options.data.deltaSeconds=deltaSeconds}},"refresher",{type:"literal",value:"refresher",description:'"refresher"'},"uas",{type:"literal",value:"uas",description:'"uas"'},"uac",{type:"literal",value:"uac",description:'"uac"'},function(endpoint){if(options.startRule==="Session_Expires"){options.data.refresher=endpoint}},function(deltaSeconds){if(options.startRule==="Min_SE"){options.data=deltaSeconds}},"stuns",{type:"literal",value:"stuns",description:'"stuns"'},"stun",{type:"literal",value:"stun",description:'"stun"'},function(scheme){options.data.scheme=scheme},function(host){options.data.host=host},"?transport=",{type:"literal",value:"?transport=",description:'"?transport="'},"turns",{type:"literal",value:"turns",description:'"turns"'},"turn",{type:"literal",value:"turn",description:'"turn"'},function(){options.data.transport=transport},function(){options.data=text()
}],peg$bytecode=[peg$decode('. ""2 3!'),peg$decode('0"""1!3#'),peg$decode('0$""1!3%'),peg$decode('0&""1!3\''),peg$decode("7'*# \"7("),peg$decode('0(""1!3)'),peg$decode('0*""1!3+'),peg$decode('.,""2,3-'),peg$decode('..""2.3/'),peg$decode('00""1!31'),peg$decode('.2""2233*\x89 ".4""2435*} ".6""2637*q ".8""2839*e ".:""2:3;*Y ".<""2<3=*M ".>""2>3?*A ".@""2@3A*5 ".B""2B3C*) ".D""2D3E'),peg$decode('7)*# "7,'),peg$decode('.F""2F3G*} ".H""2H3I*q ".J""2J3K*e ".L""2L3M*Y ".N""2N3O*M ".P""2P3Q*A ".R""2R3S*5 ".T""2T3U*) ".V""2V3W'),peg$decode('!!.Y""2Y3Z+7$7#+-%7#+#%\'#%$## X$"# X"# X+! (%'),peg$decode('!! \\7$,#&7$"+-$7 +#%\'"%$"# X"# X*# " [+@$ \\7$+&$,#&7$""" X+\'%4"6]" %$"# X"# X'),peg$decode('7.*# " ['),peg$decode('! \\7\'*# "7(,)&7\'*# "7("+A$.8""2839+1%7/+\'%4#6^# %$## X$"# X"# X'),peg$decode('!! \\72+&$,#&72""" X+o$ \\! \\7.,#&7."+-$72+#%\'"%$"# X"# X,@&! \\7.,#&7."+-$72+#%\'"%$"# X"# X"+#%\'"%$"# X"# X+! (%'),peg$decode('0_""1!3`*# "73'),peg$decode('0a""1!3b'),peg$decode('0c""1!3d'),peg$decode('7!*) "0e""1!3f'),peg$decode('! \\7)*\x95 ".F""2F3G*\x89 ".J""2J3K*} ".L""2L3M*q ".Y""2Y3Z*e ".P""2P3Q*Y ".H""2H3I*M ".@""2@3A*A ".g""2g3h*5 ".R""2R3S*) ".N""2N3O+\x9e$,\x9b&7)*\x95 ".F""2F3G*\x89 ".J""2J3K*} ".L""2L3M*q ".Y""2Y3Z*e ".P""2P3Q*Y ".H""2H3I*M ".@""2@3A*A ".g""2g3h*5 ".R""2R3S*) ".N""2N3O""" X+! (%'),peg$decode('! \\7)*\x89 ".F""2F3G*} ".L""2L3M*q ".Y""2Y3Z*e ".P""2P3Q*Y ".H""2H3I*M ".@""2@3A*A ".g""2g3h*5 ".R""2R3S*) ".N""2N3O+\x92$,\x8f&7)*\x89 ".F""2F3G*} ".L""2L3M*q ".Y""2Y3Z*e ".P""2P3Q*Y ".H""2H3I*M ".@""2@3A*A ".g""2g3h*5 ".R""2R3S*) ".N""2N3O""" X+! (%'),peg$decode('.T""2T3U*\xe3 ".V""2V3W*\xd7 ".i""2i3j*\xcb ".k""2k3l*\xbf ".:""2:3;*\xb3 ".D""2D3E*\xa7 ".2""2233*\x9b ".8""2839*\x8f ".m""2m3n*\x83 "7&*} ".4""2435*q ".o""2o3p*e ".q""2q3r*Y ".6""2637*M ".>""2>3?*A ".s""2s3t*5 ".u""2u3v*) "7\'*# "7('),peg$decode('! \\7)*\u012b ".F""2F3G*\u011f ".J""2J3K*\u0113 ".L""2L3M*\u0107 ".Y""2Y3Z*\xfb ".P""2P3Q*\xef ".H""2H3I*\xe3 ".@""2@3A*\xd7 ".g""2g3h*\xcb ".R""2R3S*\xbf ".N""2N3O*\xb3 ".T""2T3U*\xa7 ".V""2V3W*\x9b ".i""2i3j*\x8f ".k""2k3l*\x83 ".8""2839*w ".m""2m3n*k "7&*e ".4""2435*Y ".o""2o3p*M ".q""2q3r*A ".6""2637*5 ".s""2s3t*) ".u""2u3v+\u0134$,\u0131&7)*\u012b ".F""2F3G*\u011f ".J""2J3K*\u0113 ".L""2L3M*\u0107 ".Y""2Y3Z*\xfb ".P""2P3Q*\xef ".H""2H3I*\xe3 ".@""2@3A*\xd7 ".g""2g3h*\xcb ".R""2R3S*\xbf ".N""2N3O*\xb3 ".T""2T3U*\xa7 ".V""2V3W*\x9b ".i""2i3j*\x8f ".k""2k3l*\x83 ".8""2839*w ".m""2m3n*k "7&*e ".4""2435*Y ".o""2o3p*M ".q""2q3r*A ".6""2637*5 ".s""2s3t*) ".u""2u3v""" X+! (%'),peg$decode('!7/+A$.P""2P3Q+1%7/+\'%4#6w# %$## X$"# X"# X'),peg$decode('!7/+A$.4""2435+1%7/+\'%4#6x# %$## X$"# X"# X'),peg$decode('!7/+A$.>""2>3?+1%7/+\'%4#6y# %$## X$"# X"# X'),peg$decode('!7/+A$.T""2T3U+1%7/+\'%4#6z# %$## X$"# X"# X'),peg$decode('!7/+A$.V""2V3W+1%7/+\'%4#6{# %$## X$"# X"# X'),peg$decode('!.k""2k3l+1$7/+\'%4"6|" %$"# X"# X'),peg$decode('!7/+7$.i""2i3j+\'%4"6}" %$"# X"# X'),peg$decode('!7/+A$.D""2D3E+1%7/+\'%4#6~# %$## X$"# X"# X'),peg$decode('!7/+A$.2""2233+1%7/+\'%4#6\x7f# %$## X$"# X"# X'),peg$decode('!7/+A$.8""2839+1%7/+\'%4#6\x80# %$## X$"# X"# X'),peg$decode('!7/+1$7&+\'%4"6\x81" %$"# X"# X'),peg$decode('!7&+1$7/+\'%4"6\x81" %$"# X"# X'),peg$decode('!7=+W$ \\7G*) "7K*# "7F,/&7G*) "7K*# "7F"+-%7>+#%\'#%$## X$"# X"# X'),peg$decode('0\x82""1!3\x83*A "0\x84""1!3\x85*5 "0\x86""1!3\x87*) "73*# "7.'),peg$decode('!!7/+U$7&+K% \\7J*# "7K,)&7J*# "7K"+-%7&+#%\'$%$$# X$## X$"# X"# X+! (%'),peg$decode('!7/+`$7&+V%! \\7J*# "7K,)&7J*# "7K"+! (%+2%7&+(%4$6\x88$!!%$$# X$## X$"# X"# X'),peg$decode('7.*G ".L""2L3M*; "0\x89""1!3\x8a*/ "0\x86""1!3\x87*# "73'),peg$decode('!.m""2m3n+K$0\x8b""1!3\x8c*5 "0\x8d""1!3\x8e*) "0\x8f""1!3\x90+#%\'"%$"# X"# X'),peg$decode('!7N+Q$.8""2839+A%7O*# " [+1%7S+\'%4$6\x91$ %$$# X$## X$"# X"# X'),peg$decode('!7N+k$.8""2839+[%7O*# " [+K%7S+A%7_+7%7l*# " [+\'%4&6\x92& %$&# X$%# X$$# X$## X$"# X"# X'),peg$decode('!/\x93""1$3\x94*) "/\x95""1#3\x96+\' 4!6\x97!! %'),peg$decode('!7P+b$!.8""2839+-$7R+#%\'"%$"# X"# X*# " [+7%.:""2:3;+\'%4#6\x98# %$## X$"# X"# X'),peg$decode(' \\7+*) "7-*# "7Q+2$,/&7+*) "7-*# "7Q""" X'),peg$decode('.<""2<3=*q ".>""2>3?*e ".@""2@3A*Y ".B""2B3C*M ".D""2D3E*A ".2""2233*5 ".6""2637*) ".4""2435'),peg$decode('! \\7+*_ "7-*Y ".<""2<3=*M ".>""2>3?*A ".@""2@3A*5 ".B""2B3C*) ".D""2D3E,e&7+*_ "7-*Y ".<""2<3=*M ".>""2>3?*A ".@""2@3A*5 ".B""2B3C*) ".D""2D3E"+& 4!6\x99! %'),peg$decode('!7T+N$!.8""2839+-$7^+#%\'"%$"# X"# X*# " [+#%\'"%$"# X"# X'),peg$decode('!7U*) "7\\*# "7X+& 4!6\x9a! %'),peg$decode('! \\!7V+3$.J""2J3K+#%\'"%$"# X"# X,>&!7V+3$.J""2J3K+#%\'"%$"# X"# X"+G$7W+=%.J""2J3K*# " [+\'%4#6\x9b# %$## X$"# X"# X'),peg$decode(' \\0\x9c""1!3\x9d+,$,)&0\x9c""1!3\x9d""" X'),peg$decode('!0$""1!3%+A$ \\0\x9e""1!3\x9f,)&0\x9e""1!3\x9f"+#%\'"%$"# X"# X'),peg$decode('!.o""2o3p+A$7Y+7%.q""2q3r+\'%4#6\xa0# %$## X$"# X"# X'),peg$decode('!!7Z+\xbf$.8""2839+\xaf%7Z+\xa5%.8""2839+\x95%7Z+\x8b%.8""2839+{%7Z+q%.8""2839+a%7Z+W%.8""2839+G%7Z+=%.8""2839+-%7[+#%\'-%$-# X$,# X$+# X$*# X$)# X$(# X$\'# X$&# X$%# X$$# X$## X$"# X"# X*\u0838 "!.\xa1""2\xa13\xa2+\xaf$7Z+\xa5%.8""2839+\x95%7Z+\x8b%.8""2839+{%7Z+q%.8""2839+a%7Z+W%.8""2839+G%7Z+=%.8""2839+-%7[+#%\',%$,# X$+# X$*# X$)# X$(# X$\'# X$&# X$%# X$$# X$## X$"# X"# X*\u0795 "!.\xa1""2\xa13\xa2+\x95$7Z+\x8b%.8""2839+{%7Z+q%.8""2839+a%7Z+W%.8""2839+G%7Z+=%.8""2839+-%7[+#%\'*%$*# X$)# X$(# X$\'# X$&# X$%# X$$# X$## X$"# X"# X*\u070c "!.\xa1""2\xa13\xa2+{$7Z+q%.8""2839+a%7Z+W%.8""2839+G%7Z+=%.8""2839+-%7[+#%\'(%$(# X$\'# X$&# X$%# X$$# X$## X$"# X"# X*\u069d "!.\xa1""2\xa13\xa2+a$7Z+W%.8""2839+G%7Z+=%.8""2839+-%7[+#%\'&%$&# X$%# X$$# X$## X$"# X"# X*\u0648 "!.\xa1""2\xa13\xa2+G$7Z+=%.8""2839+-%7[+#%\'$%$$# X$## X$"# X"# X*\u060d "!.\xa1""2\xa13\xa2+-$7[+#%\'"%$"# X"# X*\u05ec "!.\xa1""2\xa13\xa2+-$7Z+#%\'"%$"# X"# X*\u05cb "!7Z+\xa5$.\xa1""2\xa13\xa2+\x95%7Z+\x8b%.8""2839+{%7Z+q%.8""2839+a%7Z+W%.8""2839+G%7Z+=%.8""2839+-%7[+#%\'+%$+# X$*# X$)# X$(# X$\'# X$&# X$%# X$$# X$## X$"# X"# X*\u0538 "!7Z+\xb6$!.8""2839+-$7Z+#%\'"%$"# X"# X*# " [+\x8b%.\xa1""2\xa13\xa2+{%7Z+q%.8""2839+a%7Z+W%.8""2839+G%7Z+=%.8""2839+-%7[+#%\'*%$*# X$)# X$(# X$\'# X$&# X$%# X$$# X$## X$"# X"# X*\u0494 "!7Z+\xc7$!.8""2839+-$7Z+#%\'"%$"# X"# X*# " [+\x9c%!.8""2839+-$7Z+#%\'"%$"# X"# X*# " [+q%.\xa1""2\xa13\xa2+a%7Z+W%.8""2839+G%7Z+=%.8""2839+-%7[+#%\')%$)# X$(# X$\'# X$&# X$%# X$$# X$## X$"# X"# X*\u03df "!7Z+\xd8$!.8""2839+-$7Z+#%\'"%$"# X"# X*# " [+\xad%!.8""2839+-$7Z+#%\'"%$"# X"# X*# " [+\x82%!.8""2839+-$7Z+#%\'"%$"# X"# X*# " [+W%.\xa1""2\xa13\xa2+G%7Z+=%.8""2839+-%7[+#%\'(%$(# X$\'# X$&# X$%# X$$# X$## X$"# X"# X*\u0319 "!7Z+\xe9$!.8""2839+-$7Z+#%\'"%$"# X"# X*# " [+\xbe%!.8""2839+-$7Z+#%\'"%$"# X"# X*# " [+\x93%!.8""2839+-$7Z+#%\'"%$"# X"# X*# " [+h%!.8""2839+-$7Z+#%\'"%$"# X"# X*# " [+=%.\xa1""2\xa13\xa2+-%7[+#%\'\'%$\'# X$&# X$%# X$$# X$## X$"# X"# X*\u0242 "!7Z+\u0114$!.8""2839+-$7Z+#%\'"%$"# X"# X*# " [+\xe9%!.8""2839+-$7Z+#%\'"%$"# X"# X*# " [+\xbe%!.8""2839+-$7Z+#%\'"%$"# X"# X*# " [+\x93%!.8""2839+-$7Z+#%\'"%$"# X"# X*# " [+h%!.8""2839+-$7Z+#%\'"%$"# X"# X*# " [+=%.\xa1""2\xa13\xa2+-%7Z+#%\'(%$(# X$\'# X$&# X$%# X$$# X$## X$"# X"# X*\u0140 "!7Z+\u0135$!.8""2839+-$7Z+#%\'"%$"# X"# X*# " [+\u010a%!.8""2839+-$7Z+#%\'"%$"# X"# X*# " [+\xdf%!.8""2839+-$7Z+#%\'"%$"# X"# X*# " [+\xb4%!.8""2839+-$7Z+#%\'"%$"# X"# X*# " [+\x89%!.8""2839+-$7Z+#%\'"%$"# X"# X*# " [+^%!.8""2839+-$7Z+#%\'"%$"# X"# X*# " [+3%.\xa1""2\xa13\xa2+#%\'(%$(# X$\'# X$&# X$%# X$$# X$## X$"# X"# X+& 4!6\xa3! %'),peg$decode('!7#+S$7#*# " [+C%7#*# " [+3%7#*# " [+#%\'$%$$# X$## X$"# X"# X'),peg$decode('!7Z+=$.8""2839+-%7Z+#%\'#%$## X$"# X"# X*# "7\\'),peg$decode('!7]+u$.J""2J3K+e%7]+[%.J""2J3K+K%7]+A%.J""2J3K+1%7]+\'%4\'6\xa4\' %$\'# X$&# X$%# X$$# X$## X$"# X"# X'),peg$decode('!.\xa5""2\xa53\xa6+3$0\xa7""1!3\xa8+#%\'"%$"# X"# X*\xa0 "!.\xa9""2\xa93\xaa+=$0\xab""1!3\xac+-%7!+#%\'#%$## X$"# X"# X*o "!.\xad""2\xad3\xae+7$7!+-%7!+#%\'#%$## X$"# X"# X*D "!0\xaf""1!3\xb0+-$7!+#%\'"%$"# X"# X*# "7!'),peg$decode('!!7!*# " [+c$7!*# " [+S%7!*# " [+C%7!*# " [+3%7!*# " [+#%\'%%$%# X$$# X$## X$"# X"# X+\' 4!6\xb1!! %'),peg$decode(' \\!.2""2233+-$7`+#%\'"%$"# X"# X,>&!.2""2233+-$7`+#%\'"%$"# X"# X"'),peg$decode('7a*A "7b*; "7c*5 "7d*/ "7e*) "7f*# "7g'),peg$decode('!/\xb2""1*3\xb3+b$/\xb4""1#3\xb5*G "/\xb6""1#3\xb7*; "/\xb8""1$3\xb9*/ "/\xba""1#3\xbb*# "76+(%4"6\xbc"! %$"# X"# X'),peg$decode('!/\xbd""1%3\xbe+J$/\xbf""1%3\xc0*/ "/\xc1""1"3\xc2*# "76+(%4"6\xc3"! %$"# X"# X'),peg$decode('!/\xc4""1\'3\xc5+2$7\x8f+(%4"6\xc6"! %$"# X"# X'),peg$decode('!/\xc7""1$3\xc8+2$7\xef+(%4"6\xc9"! %$"# X"# X'),peg$decode('!/\xca""1&3\xcb+2$7T+(%4"6\xcc"! %$"# X"# X'),peg$decode('!/\xcd""1"3\xce+R$!.>""2>3?+-$76+#%\'"%$"# X"# X*# " [+\'%4"6\xcf" %$"# X"# X'),peg$decode('!7h+T$!.>""2>3?+-$7i+#%\'"%$"# X"# X*# " [+)%4"6\xd0""! %$"# X"# X'),peg$decode('! \\7j+&$,#&7j""" X+! (%'),peg$decode('! \\7j+&$,#&7j""" X+! (%'),peg$decode('7k*) "7+*# "7-'),peg$decode('.o""2o3p*e ".q""2q3r*Y ".4""2435*M ".8""2839*A ".<""2<3=*5 ".@""2@3A*) ".B""2B3C'),peg$decode('!.6""2637+u$7m+k% \\!.<""2<3=+-$7m+#%\'"%$"# X"# X,>&!.<""2<3=+-$7m+#%\'"%$"# X"# X"+#%\'#%$## X$"# X"# X'),peg$decode('!7n+C$.>""2>3?+3%7o+)%4#6\xd1#"" %$## X$"# X"# X'),peg$decode(' \\7p*) "7+*# "7-+2$,/&7p*) "7+*# "7-""" X'),peg$decode(' \\7p*) "7+*# "7-,/&7p*) "7+*# "7-"'),peg$decode('.o""2o3p*e ".q""2q3r*Y ".4""2435*M ".6""2637*A ".8""2839*5 ".@""2@3A*) ".B""2B3C'),peg$decode('7\x90*# "7r'),peg$decode("!7\x8f+K$7'+A%7s+7%7'+-%7\x84+#%'%%$%# X$$# X$## X$\"# X\"# X"),peg$decode('7M*# "7t'),peg$decode('!7\x7f+G$.8""2839+7%7u*# "7x+\'%4#6\xd2# %$## X$"# X"# X'),peg$decode('!7v*# "7w+N$!.6""2637+-$7\x83+#%\'"%$"# X"# X*# " [+#%\'"%$"# X"# X'),peg$decode('!.\xd3""2\xd33\xd4+=$7\x80+3%7w*# " [+#%\'#%$## X$"# X"# X'),peg$decode('!.4""2435+-$7{+#%\'"%$"# X"# X'),peg$decode('!7z+5$ \\7y,#&7y"+#%\'"%$"# X"# X'),peg$decode('7**) "7+*# "7-'),peg$decode('7+*\x8f "7-*\x89 ".2""2233*} ".6""2637*q ".8""2839*e ".:""2:3;*Y ".<""2<3=*M ".>""2>3?*A ".@""2@3A*5 ".B""2B3C*) ".D""2D3E'),peg$decode('!7|+k$ \\!.4""2435+-$7|+#%\'"%$"# X"# X,>&!.4""2435+-$7|+#%\'"%$"# X"# X"+#%\'"%$"# X"# X'),peg$decode('! \\7~,#&7~"+k$ \\!.2""2233+-$7}+#%\'"%$"# X"# X,>&!.2""2233+-$7}+#%\'"%$"# X"# X"+#%\'"%$"# X"# X'),peg$decode(' \\7~,#&7~"'),peg$decode('7+*w "7-*q ".8""2839*e ".:""2:3;*Y ".<""2<3=*M ".>""2>3?*A ".@""2@3A*5 ".B""2B3C*) ".D""2D3E'),peg$decode('!7"+\x8d$ \\7"*G "7!*A ".@""2@3A*5 ".F""2F3G*) ".J""2J3K,M&7"*G "7!*A ".@""2@3A*5 ".F""2F3G*) ".J""2J3K"+\'%4"6\xd5" %$"# X"# X'),peg$decode('7\x81*# "7\x82'),peg$decode('!!7O+3$.:""2:3;+#%\'"%$"# X"# X*# " [+-$7S+#%\'"%$"# X"# X*# " ['),peg$decode(' \\7+*\x83 "7-*} ".B""2B3C*q ".D""2D3E*e ".2""2233*Y ".8""2839*M ".:""2:3;*A ".<""2<3=*5 ".>""2>3?*) ".@""2@3A+\x8c$,\x89&7+*\x83 "7-*} ".B""2B3C*q ".D""2D3E*e ".2""2233*Y ".8""2839*M ".:""2:3;*A ".<""2<3=*5 ".>""2>3?*) ".@""2@3A""" X'),peg$decode(' \\7y,#&7y"'),peg$decode('!/\x95""1#3\xd6+y$.4""2435+i% \\7!+&$,#&7!""" X+P%.J""2J3K+@% \\7!+&$,#&7!""" X+\'%4%6\xd7% %$%# X$$# X$## X$"# X"# X'),peg$decode('.\xd8""2\xd83\xd9'),peg$decode('.\xda""2\xda3\xdb'),peg$decode('.\xdc""2\xdc3\xdd'),peg$decode('.\xde""2\xde3\xdf'),peg$decode('.\xe0""2\xe03\xe1'),peg$decode('.\xe2""2\xe23\xe3'),peg$decode('.\xe4""2\xe43\xe5'),peg$decode('.\xe6""2\xe63\xe7'),peg$decode('.\xe8""2\xe83\xe9'),peg$decode('.\xea""2\xea3\xeb'),peg$decode('!7\x85*S "7\x86*M "7\x88*G "7\x89*A "7\x8a*; "7\x8b*5 "7\x8c*/ "7\x8d*) "7\x8e*# "76+& 4!6\xec! %'),peg$decode("!7\x84+K$7'+A%7\x91+7%7'+-%7\x93+#%'%%$%# X$$# X$## X$\"# X\"# X"),peg$decode("!7\x92+' 4!6\xed!! %"),peg$decode('!7!+7$7!+-%7!+#%\'#%$## X$"# X"# X'),peg$decode('! \\7**A "7+*; "7-*5 "73*/ "74*) "7\'*# "7(,G&7**A "7+*; "7-*5 "73*/ "74*) "7\'*# "7("+& 4!6\xee! %'),peg$decode('!7\xb5+_$ \\!7A+-$7\xb5+#%\'"%$"# X"# X,8&!7A+-$7\xb5+#%\'"%$"# X"# X"+#%\'"%$"# X"# X'),peg$decode('!79+R$!.:""2:3;+-$79+#%\'"%$"# X"# X*# " [+\'%4"6\xef" %$"# X"# X'),peg$decode('!7:*j "!7\x97+_$ \\!7A+-$7\x97+#%\'"%$"# X"# X,8&!7A+-$7\x97+#%\'"%$"# X"# X"+#%\'"%$"# X"# X+& 4!6\xf0! %'),peg$decode('!7L*# "7\x98+c$ \\!7B+-$7\x9a+#%\'"%$"# X"# X,8&!7B+-$7\x9a+#%\'"%$"# X"# X"+\'%4"6\xf1" %$"# X"# X'),peg$decode('!7\x99*# " [+A$7@+7%7M+-%7?+#%\'$%$$# X$## X$"# X"# X'),peg$decode('!!76+_$ \\!7.+-$76+#%\'"%$"# X"# X,8&!7.+-$76+#%\'"%$"# X"# X"+#%\'"%$"# X"# X*# "7H+\' 4!6\xf2!! %'),peg$decode('7\x9b*) "7\x9c*# "7\x9f'),peg$decode('!/\xf3""1!3\xf4+<$7<+2%7\x9e+(%4#6\xf5#! %$## X$"# X"# X'),peg$decode('!/\xf6""1\'3\xf7+<$7<+2%7\x9d+(%4#6\xf8#! %$## X$"# X"# X'),peg$decode('! \\7!+&$,#&7!""" X+\' 4!6\xf9!! %'),peg$decode('!.\xfa""2\xfa3\xfb+x$!.J""2J3K+S$7!*# " [+C%7!*# " [+3%7!*# " [+#%\'$%$$# X$## X$"# X"# X*# " [+\'%4"6\xfc" %$"# X"# X'),peg$decode('!76+N$!7<+-$7\xa0+#%\'"%$"# X"# X*# " [+)%4"6\xfd""! %$"# X"# X'),peg$decode('76*) "7T*# "7H'),peg$decode('!7\xa2+_$ \\!7B+-$7\xa3+#%\'"%$"# X"# X,8&!7B+-$7\xa3+#%\'"%$"# X"# X"+#%\'"%$"# X"# X'),peg$decode('!/\xfe""1&3\xff*G "/\u0100""1\'3\u0101*; "/\u0102""1$3\u0103*/ "/\u0104""1%3\u0105*# "76+& 4!6\u0106! %'),peg$decode('7\xa4*# "7\x9f'),peg$decode('!/\u0107""1(3\u0108+O$7<+E%/\u0109""1(3\u010a*/ "/\u010b""1(3\u010c*# "76+#%\'#%$## X$"# X"# X'),peg$decode('!76+_$ \\!7A+-$76+#%\'"%$"# X"# X,8&!7A+-$76+#%\'"%$"# X"# X"+#%\'"%$"# X"# X'),peg$decode('! \\7!+&$,#&7!""" X+\' 4!6\u010d!! %'),peg$decode("!7\xa8+& 4!6\u010e! %"),peg$decode('!7\xa9+s$7;+i%7\xae+_% \\!7B+-$7\xaf+#%\'"%$"# X"# X,8&!7B+-$7\xaf+#%\'"%$"# X"# X"+#%\'$%$$# X$## X$"# X"# X'),peg$decode('7\xaa*# "7\xab'),peg$decode('/\u010f""1$3\u0110*S "/\u0111""1%3\u0112*G "/\u0113""1%3\u0114*; "/\u0115""1%3\u0116*/ "/\u0117""1+3\u0118*# "7\xac'),peg$decode('/\u0119""1\'3\u011a*/ "/\u011b""1)3\u011c*# "7\xac'),peg$decode('76*# "7\xad'),peg$decode('!/\u011d""1"3\u011e+-$76+#%\'"%$"# X"# X'),peg$decode('7\xac*# "76'),peg$decode('!76+7$7<+-%7\xb0+#%\'#%$## X$"# X"# X'),peg$decode('76*# "7H'),peg$decode('!7\xb2+7$7.+-%7\x8f+#%\'#%$## X$"# X"# X'),peg$decode('! \\7!+&$,#&7!""" X+\' 4!6\u011f!! %'),peg$decode("!7\x9d+' 4!6\u0120!! %"),peg$decode('!7\xb5+d$ \\!7B+-$7\x9f+#%\'"%$"# X"# X,8&!7B+-$7\x9f+#%\'"%$"# X"# X"+(%4"6\u0121"!!%$"# X"# X'),peg$decode('!!77+k$ \\!.J""2J3K+-$77+#%\'"%$"# X"# X,>&!.J""2J3K+-$77+#%\'"%$"# X"# X"+#%\'"%$"# X"# X+! (%'),peg$decode('!7L*# "7\x98+c$ \\!7B+-$7\xb7+#%\'"%$"# X"# X,8&!7B+-$7\xb7+#%\'"%$"# X"# X"+\'%4"6\u0122" %$"# X"# X'),peg$decode('7\xb8*# "7\x9f'),peg$decode('!/\u0123""1#3\u0124+<$7<+2%76+(%4#6\u0125#! %$## X$"# X"# X'),peg$decode('! \\7!+&$,#&7!""" X+\' 4!6\u0126!! %'),peg$decode("!7\x9d+' 4!6\u0127!! %"),peg$decode('! \\7\x99,#&7\x99"+\x81$7@+w%7M+m%7?+c% \\!7B+-$7\x9f+#%\'"%$"# X"# X,8&!7B+-$7\x9f+#%\'"%$"# X"# X"+\'%4%6\u0128% %$%# X$$# X$## X$"# X"# X'),peg$decode("7\xbd"),peg$decode('!/\u0129""1&3\u012a+s$7.+i%7\xc0+_% \\!7A+-$7\xc0+#%\'"%$"# X"# X,8&!7A+-$7\xc0+#%\'"%$"# X"# X"+#%\'$%$$# X$## X$"# X"# X*# "7\xbe'),peg$decode('!76+s$7.+i%7\xbf+_% \\!7A+-$7\xbf+#%\'"%$"# X"# X,8&!7A+-$7\xbf+#%\'"%$"# X"# X"+#%\'$%$$# X$## X$"# X"# X'),peg$decode('!76+=$7<+3%76*# "7H+#%\'#%$## X$"# X"# X'),peg$decode('7\xc1*G "7\xc3*A "7\xc5*; "7\xc7*5 "7\xc8*/ "7\xc9*) "7\xca*# "7\xbf'),peg$decode('!/\u012b""1%3\u012c+7$7<+-%7\xc2+#%\'#%$## X$"# X"# X'),peg$decode("!7I+' 4!6\u012d!! %"),peg$decode('!/\u012e""1&3\u012f+\xa5$7<+\x9b%7D+\x91%7\xc4+\x87% \\! \\7\'+&$,#&7\'""" X+-$7\xc4+#%\'"%$"# X"# X,G&! \\7\'+&$,#&7\'""" X+-$7\xc4+#%\'"%$"# X"# X"+-%7E+#%\'&%$&# X$%# X$$# X$## X$"# X"# X'),peg$decode('7t*# "7w'),peg$decode('!/\u0130""1%3\u0131+7$7<+-%7\xc6+#%\'#%$## X$"# X"# X'),peg$decode("!7I+' 4!6\u0132!! %"),peg$decode('!/\u0133""1&3\u0134+<$7<+2%7I+(%4#6\u0135#! %$## X$"# X"# X'),peg$decode('!/\u0136""1%3\u0137+_$7<+U%!/\u0138""1$3\u0139+& 4!6\u013a! %*4 "!/\u013b""1%3\u013c+& 4!6\u013d! %+#%\'#%$## X$"# X"# X'),peg$decode('!/\u013e""1)3\u013f+T$7<+J%/\u0140""1#3\u0141*/ "/\u0142""1(3\u0143*# "76+(%4#6\u0144#! %$## X$"# X"# X'),peg$decode('!/\u0145""1#3\u0146+\x9e$7<+\x94%7D+\x8a%!7\xcb+k$ \\!.D""2D3E+-$7\xcb+#%\'"%$"# X"# X,>&!.D""2D3E+-$7\xcb+#%\'"%$"# X"# X"+#%\'"%$"# X"# X+-%7E+#%\'%%$%# X$$# X$## X$"# X"# X'),peg$decode('!/\u0147""1(3\u0148*/ "/\u0149""1$3\u014a*# "76+\' 4!6\u014b!! %'),peg$decode('!76+_$ \\!7A+-$76+#%\'"%$"# X"# X,8&!7A+-$76+#%\'"%$"# X"# X"+#%\'"%$"# X"# X'),peg$decode('!7\xce+K$7.+A%7\xce+7%7.+-%7\x8f+#%\'%%$%# X$$# X$## X$"# X"# X'),peg$decode('! \\7!+&$,#&7!""" X+\' 4!6\u014c!! %'),peg$decode('!7\xd0+c$ \\!7A+-$7\xd0+#%\'"%$"# X"# X,8&!7A+-$7\xd0+#%\'"%$"# X"# X"+\'%4"6\u014d" %$"# X"# X'),peg$decode('!7\x98+c$ \\!7B+-$7\x9f+#%\'"%$"# X"# X,8&!7B+-$7\x9f+#%\'"%$"# X"# X"+\'%4"6\u014e" %$"# X"# X'),peg$decode('!7L*T "7\x98*N "!7@*# " [+=$7t+3%7?*# " [+#%\'#%$## X$"# X"# X+c$ \\!7B+-$7\x9f+#%\'"%$"# X"# X,8&!7B+-$7\x9f+#%\'"%$"# X"# X"+\'%4"6\u014f" %$"# X"# X'),peg$decode('!7\xd3+c$ \\!7B+-$7\xd4+#%\'"%$"# X"# X,8&!7B+-$7\xd4+#%\'"%$"# X"# X"+\'%4"6\u0150" %$"# X"# X'),peg$decode("!7\x95+& 4!6\u0151! %"),peg$decode('!/\u0152""1(3\u0153+<$7<+2%76+(%4#6\u0154#! %$## X$"# X"# X*j "!/\u0155""1&3\u0156+<$7<+2%76+(%4#6\u0157#! %$## X$"# X"# X*: "!/\u0158""1*3\u0159+& 4!6\u015a! %*# "7\x9f'),peg$decode('!!76+o$ \\!7A+2$76+(%4"6\u015b"! %$"# X"# X,=&!7A+2$76+(%4"6\u015b"! %$"# X"# X"+)%4"6\u015c""! %$"# X"# X*# " [+\' 4!6\u015d!! %'),peg$decode('!7\xd7+_$ \\!7A+-$7\xd7+#%\'"%$"# X"# X,8&!7A+-$7\xd7+#%\'"%$"# X"# X"+#%\'"%$"# X"# X'),peg$decode('!7\x98+_$ \\!7B+-$7\x9f+#%\'"%$"# X"# X,8&!7B+-$7\x9f+#%\'"%$"# X"# X"+#%\'"%$"# X"# X'),peg$decode('! \\7!+&$,#&7!""" X+\' 4!6\u015e!! %'),peg$decode('!7\xda+_$ \\!7B+-$7\xdb+#%\'"%$"# X"# X,8&!7B+-$7\xdb+#%\'"%$"# X"# X"+#%\'"%$"# X"# X'),peg$decode('!/\u015f""1&3\u0160*; "/\u0161""1\'3\u0162*/ "/\u0163""1*3\u0164*# "76+& 4!6\u0165! %'),peg$decode('!/\u0166""1&3\u0167+<$7<+2%7\xdc+(%4#6\u0168#! %$## X$"# X"# X*\x83 "!/\xf6""1\'3\xf7+<$7<+2%7\x9d+(%4#6\u0169#! %$## X$"# X"# X*S "!/\u016a""1+3\u016b+<$7<+2%7\x9d+(%4#6\u016c#! %$## X$"# X"# X*# "7\x9f'),peg$decode('/\u016d""1+3\u016e*k "/\u016f""1)3\u0170*_ "/\u0171""1(3\u0172*S "/\u0173""1\'3\u0174*G "/\u0175""1&3\u0176*; "/\u0177""1*3\u0178*/ "/\u0179""1)3\u017a*# "76'),peg$decode('71*# " ['),peg$decode('!!76+o$ \\!7A+2$76+(%4"6\u015b"! %$"# X"# X,=&!7A+2$76+(%4"6\u015b"! %$"# X"# X"+)%4"6\u015c""! %$"# X"# X*# " [+\' 4!6\u017b!! %'),peg$decode('!7L*# "7\x98+c$ \\!7B+-$7\xe0+#%\'"%$"# X"# X,8&!7B+-$7\xe0+#%\'"%$"# X"# X"+\'%4"6\u017c" %$"# X"# X'),peg$decode('7\xb8*# "7\x9f'),peg$decode('!7\xe2+_$ \\!7A+-$7\xe2+#%\'"%$"# X"# X,8&!7A+-$7\xe2+#%\'"%$"# X"# X"+#%\'"%$"# X"# X'),peg$decode('!7\xe9+s$7.+i%7\xec+_% \\!7B+-$7\xe3+#%\'"%$"# X"# X,8&!7B+-$7\xe3+#%\'"%$"# X"# X"+#%\'$%$$# X$## X$"# X"# X'),peg$decode('7\xe4*; "7\xe5*5 "7\xe6*/ "7\xe7*) "7\xe8*# "7\x9f'),peg$decode('!/\u017d""1#3\u017e+<$7<+2%7\xef+(%4#6\u017f#! %$## X$"# X"# X'),peg$decode('!/\u0180""1%3\u0181+<$7<+2%7T+(%4#6\u0182#! %$## X$"# X"# X'),peg$decode('!/\u0183""1(3\u0184+B$7<+8%7\\*# "7Y+(%4#6\u0185#! %$## X$"# X"# X'),peg$decode('!/\u0186""1&3\u0187+<$7<+2%76+(%4#6\u0188#! %$## X$"# X"# X'),peg$decode('!/\u0189""1%3\u018a+T$!7<+5$ \\7!,#&7!"+#%\'"%$"# X"# X*# " [+\'%4"6\u018b" %$"# X"# X'),peg$decode('!7\xea+K$7;+A%76+7%7;+-%7\xeb+#%\'%%$%# X$$# X$## X$"# X"# X'),peg$decode('!/\x95""1#3\xd6*# "76+\' 4!6\u018c!! %'),peg$decode('!/\xb4""1#3\u018d*G "/\xb6""1#3\u018e*; "/\xba""1#3\u018f*/ "/\xb8""1$3\u0190*# "76+\' 4!6\u0191!! %'),peg$decode('!7\xed+H$!7C+-$7\xee+#%\'"%$"# X"# X*# " [+#%\'"%$"# X"# X'),peg$decode('!7U*) "7\\*# "7X+& 4!6\u0192! %'),peg$decode('!!7!*# " [+c$7!*# " [+S%7!*# " [+C%7!*# " [+3%7!*# " [+#%\'%%$%# X$$# X$## X$"# X"# X+\' 4!6\u0193!! %'),peg$decode('!!7!+C$7!*# " [+3%7!*# " [+#%\'#%$## X$"# X"# X+\' 4!6\u0194!! %'),peg$decode("7\xbd"),peg$decode('!7\x9d+d$ \\!7B+-$7\xf2+#%\'"%$"# X"# X,8&!7B+-$7\xf2+#%\'"%$"# X"# X"+(%4"6\u0195"!!%$"# X"# X'),peg$decode('7\xf3*# "7\x9f'),peg$decode('!.\u0196""2\u01963\u0197+N$7<+D%.\u0198""2\u01983\u0199*) ".\u019a""2\u019a3\u019b+(%4#6\u019c#! %$## X$"# X"# X'),peg$decode('!7\x9d+d$ \\!7B+-$7\x9f+#%\'"%$"# X"# X,8&!7B+-$7\x9f+#%\'"%$"# X"# X"+(%4"6\u019d"!!%$"# X"# X'),peg$decode('!76+7$70+-%7\xf6+#%\'#%$## X$"# X"# X'),peg$decode(' \\72*) "74*# "7.,/&72*) "74*# "7."'),peg$decode(' \\7%,#&7%"'),peg$decode('!7\xf9+=$.8""2839+-%7\xfa+#%\'#%$## X$"# X"# X'),peg$decode('!/\u019e""1%3\u019f*) "/\u01a0""1$3\u01a1+\' 4!6\u01a2!! %'),peg$decode('!7\xfb+N$!.8""2839+-$7^+#%\'"%$"# X"# X*# " [+#%\'"%$"# X"# X'),peg$decode('!7\\*) "7X*# "7\x82+\' 4!6\u01a3!! %'),peg$decode('! \\7\xfd*) "7-*# "7\xfe,/&7\xfd*) "7-*# "7\xfe"+! (%'),peg$decode('7"*S "7!*M ".F""2F3G*A ".J""2J3K*5 ".H""2H3I*) ".N""2N3O'),peg$decode('.L""2L3M*\x95 ".B""2B3C*\x89 ".<""2<3=*} ".R""2R3S*q ".T""2T3U*e ".V""2V3W*Y ".P""2P3Q*M ".@""2@3A*A ".D""2D3E*5 ".2""2233*) ".>""2>3?'),peg$decode('!7\u0100+h$.8""2839+X%7\xfa+N%!.\u01a4""2\u01a43\u01a5+-$7\xeb+#%\'"%$"# X"# X*# " [+#%\'$%$$# X$## X$"# X"# X'),peg$decode('!/\u01a6""1%3\u01a7*) "/\u01a8""1$3\u01a9+\' 4!6\u01a2!! %'),peg$decode('!7\xeb+Q$/\xb4""1#3\xb5*7 "/\xb6""1#3\xb7*+ " \\7+,#&7+"+\'%4"6\u01aa" %$"# X"# X'),peg$decode('!7\u0104+\x8f$.F""2F3G+\x7f%7\u0103+u%.F""2F3G+e%7\u0103+[%.F""2F3G+K%7\u0103+A%.F""2F3G+1%7\u0105+\'%4)6\u01ab) %$)# X$(# X$\'# X$&# X$%# X$$# X$## X$"# X"# X'),peg$decode('!7#+A$7#+7%7#+-%7#+#%\'$%$$# X$## X$"# X"# X'),peg$decode('!7\u0103+-$7\u0103+#%\'"%$"# X"# X'),peg$decode('!7\u0103+7$7\u0103+-%7\u0103+#%\'#%$## X$"# X"# X')],peg$currPos=0,peg$reportedPos=0,peg$cachedPos=0,peg$cachedPosDetails={line:1,column:1,seenCR:false},peg$maxFailPos=0,peg$maxFailExpected=[],peg$silentFails=0,peg$result;if("startRule"in options){if(!(options.startRule in peg$startRuleIndices)){throw new Error("Can't start parsing from rule \""+options.startRule+'".')}peg$startRuleIndex=peg$startRuleIndices[options.startRule]}function text(){return input.substring(peg$reportedPos,peg$currPos)}function offset(){return peg$reportedPos}function line(){return peg$computePosDetails(peg$reportedPos).line}function column(){return peg$computePosDetails(peg$reportedPos).column}function expected(description){throw peg$buildException(null,[{type:"other",description:description}],peg$reportedPos)}function error(message){throw peg$buildException(message,null,peg$reportedPos)}function peg$computePosDetails(pos){function advance(details,startPos,endPos){var p,ch;for(p=startPos;p<endPos;p++){ch=input.charAt(p);if(ch==="\n"){if(!details.seenCR){details.line++}details.column=1;details.seenCR=false}else if(ch==="\r"||ch==="\u2028"||ch==="\u2029"){details.line++;details.column=1;details.seenCR=true}else{details.column++;details.seenCR=false}}}if(peg$cachedPos!==pos){if(peg$cachedPos>pos){peg$cachedPos=0;peg$cachedPosDetails={line:1,column:1,seenCR:false}}advance(peg$cachedPosDetails,peg$cachedPos,pos);peg$cachedPos=pos}return peg$cachedPosDetails}function peg$fail(expected){if(peg$currPos<peg$maxFailPos){return}if(peg$currPos>peg$maxFailPos){peg$maxFailPos=peg$currPos;peg$maxFailExpected=[]}peg$maxFailExpected.push(expected)}function peg$buildException(message,expected,pos){function cleanupExpected(expected){var i=1;expected.sort(function(a,b){if(a.description<b.description){return-1}else if(a.description>b.description){return 1}else{return 0}});while(i<expected.length){if(expected[i-1]===expected[i]){expected.splice(i,1)}else{i++}}}function buildMessage(expected,found){function stringEscape(s){function hex(ch){return ch.charCodeAt(0).toString(16).toUpperCase()}return s.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E\x0F]/g,function(ch){return"\\x0"+hex(ch)}).replace(/[\x10-\x1F\x80-\xFF]/g,function(ch){return"\\x"+hex(ch)}).replace(/[\u0180-\u0FFF]/g,function(ch){return"\\u0"+hex(ch)}).replace(/[\u1080-\uFFFF]/g,function(ch){return"\\u"+hex(ch)})}var expectedDescs=new Array(expected.length),expectedDesc,foundDesc,i;for(i=0;i<expected.length;i++){expectedDescs[i]=expected[i].description}expectedDesc=expected.length>1?expectedDescs.slice(0,-1).join(", ")+" or "+expectedDescs[expected.length-1]:expectedDescs[0];foundDesc=found?'"'+stringEscape(found)+'"':"end of input";return"Expected "+expectedDesc+" but "+foundDesc+" found."}var posDetails=peg$computePosDetails(pos),found=pos<input.length?input.charAt(pos):null;if(expected!==null){cleanupExpected(expected)}return new SyntaxError(message!==null?message:buildMessage(expected,found),expected,found,pos,posDetails.line,posDetails.column)}function peg$decode(s){var bc=new Array(s.length),i;for(i=0;i<s.length;i++){bc[i]=s.charCodeAt(i)-32}return bc}function peg$parseRule(index){var bc=peg$bytecode[index],ip=0,ips=[],end=bc.length,ends=[],stack=[],params,i;function protect(object){return Object.prototype.toString.apply(object)==="[object Array]"?[]:object}while(true){while(ip<end){switch(bc[ip]){case 0:stack.push(protect(peg$consts[bc[ip+1]]));ip+=2;break;case 1:stack.push(peg$currPos);ip++;break;case 2:stack.pop();ip++;break;case 3:peg$currPos=stack.pop();ip++;break;case 4:stack.length-=bc[ip+1];ip+=2;break;case 5:stack.splice(-2,1);ip++;break;case 6:stack[stack.length-2].push(stack.pop());ip++;break;case 7:stack.push(stack.splice(stack.length-bc[ip+1],bc[ip+1]));ip+=2;break;case 8:stack.pop();stack.push(input.substring(stack[stack.length-1],peg$currPos));ip++;break;case 9:ends.push(end);ips.push(ip+3+bc[ip+1]+bc[ip+2]);if(stack[stack.length-1]){end=ip+3+bc[ip+1];ip+=3}else{end=ip+3+bc[ip+1]+bc[ip+2];ip+=3+bc[ip+1]}break;case 10:ends.push(end);ips.push(ip+3+bc[ip+1]+bc[ip+2]);if(stack[stack.length-1]===peg$FAILED){end=ip+3+bc[ip+1];ip+=3}else{end=ip+3+bc[ip+1]+bc[ip+2];ip+=3+bc[ip+1]}break;case 11:ends.push(end);ips.push(ip+3+bc[ip+1]+bc[ip+2]);if(stack[stack.length-1]!==peg$FAILED){end=ip+3+bc[ip+1];ip+=3}else{end=ip+3+bc[ip+1]+bc[ip+2];ip+=3+bc[ip+1]}break;case 12:if(stack[stack.length-1]!==peg$FAILED){ends.push(end);ips.push(ip);end=ip+2+bc[ip+1];ip+=2}else{ip+=2+bc[ip+1]}break;case 13:ends.push(end);ips.push(ip+3+bc[ip+1]+bc[ip+2]);if(input.length>peg$currPos){end=ip+3+bc[ip+1];ip+=3}else{end=ip+3+bc[ip+1]+bc[ip+2];ip+=3+bc[ip+1]}break;case 14:ends.push(end);ips.push(ip+4+bc[ip+2]+bc[ip+3]);if(input.substr(peg$currPos,peg$consts[bc[ip+1]].length)===peg$consts[bc[ip+1]]){end=ip+4+bc[ip+2];ip+=4}else{end=ip+4+bc[ip+2]+bc[ip+3];ip+=4+bc[ip+2]}break;case 15:ends.push(end);ips.push(ip+4+bc[ip+2]+bc[ip+3]);if(input.substr(peg$currPos,peg$consts[bc[ip+1]].length).toLowerCase()===peg$consts[bc[ip+1]]){end=ip+4+bc[ip+2];ip+=4}else{end=ip+4+bc[ip+2]+bc[ip+3];ip+=4+bc[ip+2]}break;case 16:ends.push(end);ips.push(ip+4+bc[ip+2]+bc[ip+3]);if(peg$consts[bc[ip+1]].test(input.charAt(peg$currPos))){end=ip+4+bc[ip+2];ip+=4}else{end=ip+4+bc[ip+2]+bc[ip+3];ip+=4+bc[ip+2]}break;case 17:stack.push(input.substr(peg$currPos,bc[ip+1]));peg$currPos+=bc[ip+1];ip+=2;break;case 18:stack.push(peg$consts[bc[ip+1]]);peg$currPos+=peg$consts[bc[ip+1]].length;ip+=2;break;case 19:stack.push(peg$FAILED);if(peg$silentFails===0){peg$fail(peg$consts[bc[ip+1]])}ip+=2;break;case 20:peg$reportedPos=stack[stack.length-1-bc[ip+1]];ip+=2;break;case 21:peg$reportedPos=peg$currPos;ip++;break;case 22:params=bc.slice(ip+4,ip+4+bc[ip+3]);for(i=0;i<bc[ip+3];i++){params[i]=stack[stack.length-1-params[i]]}stack.splice(stack.length-bc[ip+2],bc[ip+2],peg$consts[bc[ip+1]].apply(null,params));ip+=4+bc[ip+3];break;case 23:stack.push(peg$parseRule(bc[ip+1]));ip+=2;break;case 24:peg$silentFails++;ip++;break;case 25:peg$silentFails--;ip++;break;default:throw new Error("Invalid opcode: "+bc[ip]+".")}}if(ends.length>0){end=ends.pop();ip=ips.pop()}else{break}}return stack[0]}options.data={};function list(first,rest){return[first].concat(rest)}peg$result=peg$parseRule(peg$startRuleIndex);if(peg$result!==peg$FAILED&&peg$currPos===input.length){return peg$result}else{if(peg$result!==peg$FAILED&&peg$currPos<input.length){peg$fail({type:"end",description:"end of input"})}throw peg$buildException(null,peg$maxFailExpected,peg$maxFailPos)}}return{SyntaxError:SyntaxError,parse:parse}}()},{}],69:[function(require,module,exports){"use strict";module.exports=function(SIP){SIP=SIP;var Hacks={AllBrowsers:{maskDtls:function(sdp){if(sdp){sdp=sdp.replace(/ UDP\/TLS\/RTP\/SAVP/gim," RTP/SAVP")}return sdp},unmaskDtls:function(sdp){return sdp.replace(/ RTP\/SAVP/gim," UDP/TLS/RTP/SAVP")}},Firefox:{isFirefox:function(){return typeof mozRTCPeerConnection!=="undefined"},cannotHandleExtraWhitespace:function(sdp){if(this.isFirefox()&&sdp){sdp=sdp.replace(/ \r\n/g,"\r\n")}return sdp},hasMissingCLineInSDP:function(sdp){var insertAt,mlines;if(sdp.indexOf("c=")>sdp.indexOf("m=")){mlines=sdp.match(/m=.*\r\n.*/g);for(var i=0;i<mlines.length;i++){if(mlines[i].toString().search(/i=.*/)>=0){insertAt=sdp.indexOf(mlines[i].toString())+mlines[i].toString().length;if(sdp.substr(insertAt,2)!=="c="){sdp=sdp.substr(0,insertAt)+"\r\nc=IN IP4 0.0.0.0"+sdp.substr(insertAt)}}else if(mlines[i].toString().search(/c=.*/)<0){insertAt=sdp.indexOf(mlines[i].toString().match(/.*/))+mlines[i].toString().match(/.*/).toString().length;sdp=sdp.substr(0,insertAt)+"\r\nc=IN IP4 0.0.0.0"+sdp.substr(insertAt)}}}return sdp}},Chrome:{needsExplicitlyInactiveSDP:function(sdp){var sub,index;if(Hacks.Firefox.isFirefox()){index=sdp.indexOf("m=video 0");if(index!==-1){sub=sdp.substr(index);sub=sub.replace(/\r\nc=IN IP4.*\r\n$/,"\r\nc=IN IP4 0.0.0.0\r\na=inactive\r\n");return sdp.substr(0,index)+sub}}return sdp},getsConfusedAboutGUM:function(session){if(session.mediaHandler){session.mediaHandler.close()}}}};return Hacks}},{}],70:[function(require,module,exports){"use strict";var levels={error:0,warn:1,log:2,debug:3};module.exports=function(console){var LoggerFactory=function(){var logger,level=2,builtinEnabled=true,connector=null;this.loggers={};logger=this.getLogger("sip.loggerfactory");Object.defineProperties(this,{builtinEnabled:{get:function(){return builtinEnabled},set:function(value){if(typeof value==="boolean"){builtinEnabled=value}else{logger.error('invalid "builtinEnabled" parameter value: '+JSON.stringify(value))}}},level:{get:function(){return level},set:function(value){if(value>=0&&value<=3){level=value}else if(value>3){level=3}else if(levels.hasOwnProperty(value)){level=levels[value]}else{logger.error('invalid "level" parameter value: '+JSON.stringify(value))}}},connector:{get:function(){return connector},set:function(value){if(value===null||value===""||value===undefined){connector=null}else if(typeof value==="function"){connector=value}else{logger.error('invalid "connector" parameter value: '+JSON.stringify(value))}}}})};LoggerFactory.prototype.print=function(target,category,label,content){if(typeof content==="string"){var prefix=[new Date,category];if(label){prefix.push(label)}content=prefix.concat(content).join(" | ")}target.call(console,content)};function Logger(logger,category,label){this.logger=logger;this.category=category;this.label=label}Object.keys(levels).forEach(function(targetName){Logger.prototype[targetName]=function(content){this.logger[targetName](this.category,this.label,content)};LoggerFactory.prototype[targetName]=function(category,label,content){if(this.level>=levels[targetName]){if(this.builtinEnabled){this.print(console[targetName],category,label,content)}if(this.connector){this.connector(targetName,category,label,content)}}}});LoggerFactory.prototype.getLogger=function(category,label){var logger;if(label&&this.level===3){return new Logger(this,category,label)}else if(this.loggers[category]){return this.loggers[category]}else{logger=new Logger(this,category);this.loggers[category]=logger;return logger}};return LoggerFactory}},{}],71:[function(require,module,exports){"use strict";module.exports=function(EventEmitter){var MediaHandler=function(session,options){session=session;options=options};MediaHandler.prototype=Object.create(EventEmitter.prototype,{isReady:{value:function isReady(){}},close:{value:function close(){}},getDescription:{value:function getDescription(mediaHint){mediaHint=mediaHint}},hasDescription:{value:function hasDescription(message){message=message}},setDescription:{
value:function setDescription(message){message=message}}});return MediaHandler}},{}],72:[function(require,module,exports){"use strict";module.exports=function(SIP){var NameAddrHeader;NameAddrHeader=function(uri,displayName,parameters){var param;if(!uri||!(uri instanceof SIP.URI)){throw new TypeError('missing or invalid "uri" parameter')}this.uri=uri;this.parameters={};for(param in parameters){this.setParam(param,parameters[param])}Object.defineProperties(this,{friendlyName:{get:function(){return this.displayName||uri.aor}},displayName:{get:function(){return displayName},set:function(value){displayName=value===0?"0":value}}})};NameAddrHeader.prototype={setParam:function(key,value){if(key){this.parameters[key.toLowerCase()]=typeof value==="undefined"||value===null?null:value.toString()}},getParam:SIP.URI.prototype.getParam,hasParam:SIP.URI.prototype.hasParam,deleteParam:SIP.URI.prototype.deleteParam,clearParams:SIP.URI.prototype.clearParams,clone:function(){return new NameAddrHeader(this.uri.clone(),this.displayName,JSON.parse(JSON.stringify(this.parameters)))},toString:function(){var body,parameter;body=this.displayName||this.displayName===0?'"'+this.displayName+'" ':"";body+="<"+this.uri.toString()+">";for(parameter in this.parameters){body+=";"+parameter;if(this.parameters[parameter]!==null){body+="="+this.parameters[parameter]}}return body}};NameAddrHeader.parse=function(name_addr_header){name_addr_header=SIP.Grammar.parse(name_addr_header,"Name_Addr_Header");if(name_addr_header!==-1){return name_addr_header}else{return undefined}};SIP.NameAddrHeader=NameAddrHeader}},{}],73:[function(require,module,exports){"use strict";module.exports=function(SIP){var Parser;function getHeader(data,headerStart){var start=headerStart,end=0,partialEnd=0;if(data.substring(start,start+2).match(/(^\r\n)/)){return-2}while(end===0){partialEnd=data.indexOf("\r\n",start);if(partialEnd===-1){return partialEnd}if(!data.substring(partialEnd+2,partialEnd+4).match(/(^\r\n)/)&&data.charAt(partialEnd+2).match(/(^\s+)/)){start=partialEnd+2}else{end=partialEnd}}return end}function parseHeader(message,data,headerStart,headerEnd){var header,idx,length,parsed,hcolonIndex=data.indexOf(":",headerStart),headerName=data.substring(headerStart,hcolonIndex).trim(),headerValue=data.substring(hcolonIndex+1,headerEnd).trim();switch(headerName.toLowerCase()){case"via":case"v":message.addHeader("via",headerValue);if(message.getHeaders("via").length===1){parsed=message.parseHeader("Via");if(parsed){message.via=parsed;message.via_branch=parsed.branch}}else{parsed=0}break;case"from":case"f":message.setHeader("from",headerValue);parsed=message.parseHeader("from");if(parsed){message.from=parsed;message.from_tag=parsed.getParam("tag")}break;case"to":case"t":message.setHeader("to",headerValue);parsed=message.parseHeader("to");if(parsed){message.to=parsed;message.to_tag=parsed.getParam("tag")}break;case"record-route":parsed=SIP.Grammar.parse(headerValue,"Record_Route");if(parsed===-1){parsed=undefined;break}length=parsed.length;for(idx=0;idx<length;idx++){header=parsed[idx];message.addHeader("record-route",headerValue.substring(header.position,header.offset));message.headers["Record-Route"][message.getHeaders("record-route").length-1].parsed=header.parsed}break;case"call-id":case"i":message.setHeader("call-id",headerValue);parsed=message.parseHeader("call-id");if(parsed){message.call_id=headerValue}break;case"contact":case"m":parsed=SIP.Grammar.parse(headerValue,"Contact");if(parsed===-1){parsed=undefined;break}length=parsed.length;for(idx=0;idx<length;idx++){header=parsed[idx];message.addHeader("contact",headerValue.substring(header.position,header.offset));message.headers["Contact"][message.getHeaders("contact").length-1].parsed=header.parsed}break;case"content-length":case"l":message.setHeader("content-length",headerValue);parsed=message.parseHeader("content-length");break;case"content-type":case"c":message.setHeader("content-type",headerValue);parsed=message.parseHeader("content-type");break;case"cseq":message.setHeader("cseq",headerValue);parsed=message.parseHeader("cseq");if(parsed){message.cseq=parsed.value}if(message instanceof SIP.IncomingResponse){message.method=parsed.method}break;case"max-forwards":message.setHeader("max-forwards",headerValue);parsed=message.parseHeader("max-forwards");break;case"www-authenticate":message.setHeader("www-authenticate",headerValue);parsed=message.parseHeader("www-authenticate");break;case"proxy-authenticate":message.setHeader("proxy-authenticate",headerValue);parsed=message.parseHeader("proxy-authenticate");break;case"refer-to":case"r":message.setHeader("refer-to",headerValue);parsed=message.parseHeader("refer-to");if(parsed){message.refer_to=parsed}break;default:message.setHeader(headerName,headerValue);parsed=0}if(parsed===undefined){return{error:'error parsing header "'+headerName+'"'}}else{return true}}Parser={};Parser.parseMessage=function(data,ua){var message,firstLine,contentLength,bodyStart,parsed,headerStart=0,headerEnd=data.indexOf("\r\n"),logger=ua.getLogger("sip.parser");if(headerEnd===-1){logger.warn("no CRLF found, not a SIP message, discarded");return}firstLine=data.substring(0,headerEnd);parsed=SIP.Grammar.parse(firstLine,"Request_Response");if(parsed===-1){logger.warn('error parsing first line of SIP message: "'+firstLine+'"');return}else if(!parsed.status_code){message=new SIP.IncomingRequest(ua);message.method=parsed.method;message.ruri=parsed.uri}else{message=new SIP.IncomingResponse(ua);message.status_code=parsed.status_code;message.reason_phrase=parsed.reason_phrase}message.data=data;headerStart=headerEnd+2;while(true){headerEnd=getHeader(data,headerStart);if(headerEnd===-2){bodyStart=headerStart+2;break}else if(headerEnd===-1){logger.error("malformed message");return}parsed=parseHeader(message,data,headerStart,headerEnd);if(parsed!==true){logger.error(parsed.error);return}headerStart=headerEnd+2}if(message.hasHeader("content-length")){contentLength=message.getHeader("content-length");message.body=data.substr(bodyStart,contentLength)}else{message.body=data.substring(bodyStart)}return message};SIP.Parser=Parser}},{}],74:[function(require,module,exports){var localMinSE=90;module.exports=function(Timers){function hasSmallMinSE(message){var supportedOptions=message.parseHeader("Supported")||[];var sessionExpires=message.parseHeader("Session-Expires")||{};return supportedOptions.indexOf("timer")>=0&&sessionExpires.deltaSeconds<localMinSE}function updateState(dialog,response,parseMessage,ua){dialog.sessionTimerState=dialog.sessionTimerState||{};Timers.clearTimeout(dialog.sessionTimerState.timeout);var isUAS=typeof response==="string";if(isUAS){response=parseMessage(response,ua)}var sessionExpires=response.parseHeader("Session-Expires");if(!sessionExpires){dialog.sessionTimerState=null;return}var interval=sessionExpires.deltaSeconds;var isRefresher=isUAS===(sessionExpires.refresher==="uas");dialog.sessionTimerState={interval:interval,isRefresher:isRefresher};var intervalMilliseconds=interval*1e3;var self=this;if(isRefresher){dialog.sessionTimerState.timeout=Timers.setInterval(function sendRefresh(){var exists=dialog.owner.ua.dialogs[dialog.id.toString()]||false;if(exists){dialog.sendRequest(self,"UPDATE",{extraHeaders:["Session-Expires: "+interval]})}else{Timers.clearInterval(dialog.sessionTimerState.timeout)}},intervalMilliseconds/2)}else{var before=Math.min(32*1e3,intervalMilliseconds/3);dialog.sessionTimerState.timeout=Timers.setTimeout(function sendBye(){},intervalMilliseconds-before)}}function receiveResponse(response){}function onDialogError(response){}function onRequestTimeout(){}function onTransportError(){}return{localMinSE:localMinSE,hasSmallMinSE:hasSmallMinSE,updateState:updateState,receiveResponse:receiveResponse,onDialogError:onDialogError,onRequestTimeout:onRequestTimeout,onTransportError:onTransportError}}},{}],75:[function(require,module,exports){"use strict";module.exports=function(SIP){var RegisterContext;RegisterContext=function(ua){var params={},regId=1;this.registrar=ua.configuration.registrarServer;this.expires=ua.configuration.registerExpires;this.contact=ua.contact.toString();if(regId){this.contact+=";reg-id="+regId;this.contact+=';+sip.instance="<urn:uuid:'+ua.configuration.instanceId+'>"'}this.call_id=SIP.Utils.createRandomToken(22);this.cseq=80;this.to_uri=ua.configuration.uri;params.to_uri=this.to_uri;params.to_displayName=ua.configuration.displayName;params.call_id=this.call_id;params.cseq=this.cseq;SIP.Utils.augment(this,SIP.ClientContext,[ua,"REGISTER",this.registrar,{params:params}]);this.registrationTimer=null;this.registrationExpiredTimer=null;this.registered=false;this.logger=ua.getLogger("sip.registercontext")};RegisterContext.prototype={register:function(options){var self=this,extraHeaders;this.options=options||{};extraHeaders=(this.options.extraHeaders||[]).slice();extraHeaders.push("Contact: "+this.contact+";expires="+this.expires);extraHeaders.push("Allow: "+SIP.UA.C.ALLOWED_METHODS.toString());this.closeHeaders=this.options.closeWithHeaders?(this.options.extraHeaders||[]).slice():[];this.receiveResponse=function(response){var contact,expires,contacts=response.getHeaders("contact").length,cause;if(response.cseq!==this.cseq){return}if(this.registrationTimer!==null){SIP.Timers.clearTimeout(this.registrationTimer);this.registrationTimer=null}switch(true){case/^1[0-9]{2}$/.test(response.status_code):this.emit("progress",response);break;case/^2[0-9]{2}$/.test(response.status_code):this.emit("accepted",response);if(response.hasHeader("expires")){expires=response.getHeader("expires")}if(this.registrationExpiredTimer!==null){SIP.Timers.clearTimeout(this.registrationExpiredTimer);this.registrationExpiredTimer=null}if(!contacts){this.logger.warn("no Contact header in response to REGISTER, response ignored");break}while(contacts--){contact=response.parseHeader("contact",contacts);if(contact.uri.user===this.ua.contact.uri.user){expires=contact.getParam("expires");break}else{contact=null}}if(!contact){this.logger.warn("no Contact header pointing to us, response ignored");break}if(!expires){expires=this.expires}this.registrationTimer=SIP.Timers.setTimeout(function(){self.registrationTimer=null;self.register(self.options)},expires*1e3-3e3);this.registrationExpiredTimer=SIP.Timers.setTimeout(function(){self.logger.warn("registration expired");if(self.registered){self.unregistered(null,SIP.C.causes.EXPIRES)}},expires*1e3);if(contact.hasParam("temp-gruu")){this.ua.contact.temp_gruu=SIP.URI.parse(contact.getParam("temp-gruu").replace(/"/g,""))}if(contact.hasParam("pub-gruu")){this.ua.contact.pub_gruu=SIP.URI.parse(contact.getParam("pub-gruu").replace(/"/g,""))}this.registered=true;this.emit("registered",response||null);break;case/^423$/.test(response.status_code):if(response.hasHeader("min-expires")){this.expires=response.getHeader("min-expires");this.register(this.options)}else{this.logger.warn("423 response received for REGISTER without Min-Expires");this.registrationFailure(response,SIP.C.causes.SIP_FAILURE_CODE)}break;default:cause=SIP.Utils.sipErrorCause(response.status_code);this.registrationFailure(response,cause)}};this.onRequestTimeout=function(){this.registrationFailure(null,SIP.C.causes.REQUEST_TIMEOUT)};this.onTransportError=function(){this.registrationFailure(null,SIP.C.causes.CONNECTION_ERROR)};this.cseq++;this.request.cseq=this.cseq;this.request.setHeader("cseq",this.cseq+" REGISTER");this.request.extraHeaders=extraHeaders;this.send()},registrationFailure:function(response,cause){this.emit("failed",response||null,cause||null)},onTransportClosed:function(){this.registered_before=this.registered;if(this.registrationTimer!==null){SIP.Timers.clearTimeout(this.registrationTimer);this.registrationTimer=null}if(this.registrationExpiredTimer!==null){SIP.Timers.clearTimeout(this.registrationExpiredTimer);this.registrationExpiredTimer=null}if(this.registered){this.unregistered(null,SIP.C.causes.CONNECTION_ERROR)}},onTransportConnected:function(){this.register(this.options)},close:function(){var options={all:false,extraHeaders:this.closeHeaders};this.registered_before=this.registered;this.unregister(options)},unregister:function(options){var extraHeaders;options=options||{};if(!this.registered&&!options.all){this.logger.warn("already unregistered");return}extraHeaders=(options.extraHeaders||[]).slice();this.registered=false;if(this.registrationTimer!==null){SIP.Timers.clearTimeout(this.registrationTimer);this.registrationTimer=null}if(options.all){extraHeaders.push("Contact: *");extraHeaders.push("Expires: 0")}else{extraHeaders.push("Contact: "+this.contact+";expires=0")}this.receiveResponse=function(response){var cause;switch(true){case/^1[0-9]{2}$/.test(response.status_code):this.emit("progress",response);break;case/^2[0-9]{2}$/.test(response.status_code):this.emit("accepted",response);if(this.registrationExpiredTimer!==null){SIP.Timers.clearTimeout(this.registrationExpiredTimer);this.registrationExpiredTimer=null}this.unregistered(response);break;default:cause=SIP.Utils.sipErrorCause(response.status_code);this.unregistered(response,cause)}};this.onRequestTimeout=function(){};this.onTransportError=function(){};this.cseq++;this.request.cseq=this.cseq;this.request.setHeader("cseq",this.cseq+" REGISTER");this.request.extraHeaders=extraHeaders;this.send()},unregistered:function(response,cause){this.registered=false;this.emit("unregistered",response||null,cause||null)}};SIP.RegisterContext=RegisterContext}},{}],76:[function(require,module,exports){"use strict";module.exports=function(SIP){var RequestSender;RequestSender=function(applicant,ua){this.logger=ua.getLogger("sip.requestsender");this.ua=ua;this.applicant=applicant;this.method=applicant.request.method;this.request=applicant.request;this.credentials=null;this.challenged=false;this.staled=false;if(ua.status===SIP.UA.C.STATUS_USER_CLOSED&&(this.method!==SIP.C.BYE||this.method!==SIP.C.ACK)){this.onTransportError()}};RequestSender.prototype={send:function(){switch(this.method){case"INVITE":this.clientTransaction=new SIP.Transactions.InviteClientTransaction(this,this.request,this.ua.transport);break;case"ACK":this.clientTransaction=new SIP.Transactions.AckClientTransaction(this,this.request,this.ua.transport);break;default:this.clientTransaction=new SIP.Transactions.NonInviteClientTransaction(this,this.request,this.ua.transport)}this.clientTransaction.send();return this.clientTransaction},onRequestTimeout:function(){this.applicant.onRequestTimeout()},onTransportError:function(){this.applicant.onTransportError()},receiveResponse:function(response){var cseq,challenge,authorization_header_name,status_code=response.status_code;if(status_code===401||status_code===407){if(response.status_code===401){challenge=response.parseHeader("www-authenticate");authorization_header_name="authorization"}else{challenge=response.parseHeader("proxy-authenticate");authorization_header_name="proxy-authorization"}if(!challenge){this.logger.warn(response.status_code+" with wrong or missing challenge, cannot authenticate");this.applicant.receiveResponse(response);return}if(!this.challenged||!this.staled&&challenge.stale===true){if(!this.credentials){this.credentials=this.ua.configuration.authenticationFactory(this.ua)}if(!this.credentials.authenticate(this.request,challenge)){this.applicant.receiveResponse(response);return}this.challenged=true;if(challenge.stale){this.staled=true}if(response.method===SIP.C.REGISTER){cseq=this.applicant.cseq+=1}else if(this.request.dialog){cseq=this.request.dialog.local_seqnum+=1}else{cseq=this.request.cseq+1;this.request.cseq=cseq}this.request.setHeader("cseq",cseq+" "+this.method);this.request.setHeader(authorization_header_name,this.credentials.toString());this.send()}else{this.applicant.receiveResponse(response)}}else{this.applicant.receiveResponse(response)}}};SIP.RequestSender=RequestSender}},{}],77:[function(require,module,exports){"use strict";module.exports=function(environment){var pkg=require("../package.json");var SIP=Object.defineProperties({},{version:{get:function(){return pkg.version}},name:{get:function(){return pkg.title}}});require("./Utils")(SIP,environment);SIP.LoggerFactory=require("./LoggerFactory")(environment.console);SIP.EventEmitter=require("./EventEmitter")(environment.console);SIP.C=require("./Constants")(SIP.name,SIP.version);SIP.Exceptions=require("./Exceptions");SIP.Timers=require("./Timers")(environment.timers);SIP.Transport=environment.Transport(SIP,environment.WebSocket);require("./Parser")(SIP);require("./SIPMessage")(SIP);require("./URI")(SIP);require("./NameAddrHeader")(SIP);require("./Transactions")(SIP);require("./Dialogs")(SIP);require("./RequestSender")(SIP);require("./RegisterContext")(SIP);SIP.MediaHandler=require("./MediaHandler")(SIP.EventEmitter);require("./ClientContext")(SIP);require("./ServerContext")(SIP);require("./Session")(SIP,environment);require("./Subscription")(SIP);SIP.WebRTC=require("./WebRTC")(SIP,environment);require("./UA")(SIP,environment);SIP.Hacks=require("./Hacks")(SIP);require("./SanityCheck")(SIP);SIP.DigestAuthentication=require("./DigestAuthentication")(SIP.Utils);SIP.Grammar=require("./Grammar")(SIP);return SIP}},{"../package.json":59,"./ClientContext":60,"./Constants":61,"./Dialogs":63,"./DigestAuthentication":64,"./EventEmitter":65,"./Exceptions":66,"./Grammar":67,"./Hacks":69,"./LoggerFactory":70,"./MediaHandler":71,"./NameAddrHeader":72,"./Parser":73,"./RegisterContext":75,"./RequestSender":76,"./SIPMessage":78,"./SanityCheck":79,"./ServerContext":80,"./Session":81,"./Subscription":83,"./Timers":84,"./Transactions":85,"./UA":87,"./URI":88,"./Utils":89,"./WebRTC":90}],78:[function(require,module,exports){"use strict";module.exports=function(SIP){var OutgoingRequest,IncomingMessage,IncomingRequest,IncomingResponse;function getSupportedHeader(request){var allowUnregistered=request.ua.configuration.hackAllowUnregisteredOptionTags;var optionTags=[];var optionTagSet={};if(request.method===SIP.C.REGISTER){optionTags.push("path","gruu")}else if(request.method===SIP.C.INVITE&&(request.ua.contact.pub_gruu||request.ua.contact.temp_gruu)){optionTags.push("gruu")}if(request.ua.configuration.rel100===SIP.C.supported.SUPPORTED){optionTags.push("100rel")}if(request.ua.configuration.replaces===SIP.C.supported.SUPPORTED){optionTags.push("replaces")}optionTags.push("outbound");optionTags=optionTags.concat(request.ua.configuration.extraSupported);optionTags=optionTags.filter(function(optionTag){var registered=SIP.C.OPTION_TAGS[optionTag];var unique=!optionTagSet[optionTag];optionTagSet[optionTag]=true;return(registered||allowUnregistered)&&unique});return"Supported: "+optionTags.join(", ")+"\r\n"}OutgoingRequest=function(method,ruri,ua,params,extraHeaders,body){var to,from,call_id,cseq,to_uri,from_uri;params=params||{};if(!method||!ruri||!ua){return null}this.logger=ua.getLogger("sip.sipmessage");this.ua=ua;this.headers={};this.method=method;this.ruri=ruri;this.body=body;this.extraHeaders=(extraHeaders||[]).slice();this.statusCode=params.status_code;this.reasonPhrase=params.reason_phrase;if(params.route_set){this.setHeader("route",params.route_set)}else if(ua.configuration.usePreloadedRoute){this.setHeader("route",ua.transport.server.sip_uri)}this.setHeader("via","");this.setHeader("max-forwards",SIP.UA.C.MAX_FORWARDS);to_uri=params.to_uri||ruri;to=params.to_displayName||params.to_displayName===0?'"'+params.to_displayName+'" ':"";to+="<"+(to_uri&&to_uri.toRaw?to_uri.toRaw():to_uri)+">";to+=params.to_tag?";tag="+params.to_tag:"";this.to=new SIP.NameAddrHeader.parse(to);this.setHeader("to",to);from_uri=params.from_uri||ua.configuration.uri;if(params.from_displayName||params.from_displayName===0){from='"'+params.from_displayName+'" '}else if(ua.configuration.displayName){from='"'+ua.configuration.displayName+'" '}else{from=""}from+="<"+(from_uri&&from_uri.toRaw?from_uri.toRaw():from_uri)+">;tag=";from+=params.from_tag||SIP.Utils.newTag();this.from=new SIP.NameAddrHeader.parse(from);this.setHeader("from",from);call_id=params.call_id||ua.configuration.sipjsId+SIP.Utils.createRandomToken(15);this.call_id=call_id;this.setHeader("call-id",call_id);cseq=params.cseq||Math.floor(Math.random()*1e4);this.cseq=cseq;this.setHeader("cseq",cseq+" "+method)};OutgoingRequest.prototype={setHeader:function(name,value){this.headers[SIP.Utils.headerize(name)]=value instanceof Array?value:[value]},getHeader:function(name){var regexp,idx,length=this.extraHeaders.length,header=this.headers[SIP.Utils.headerize(name)];if(header){if(header[0]){return header[0]}}else{regexp=new RegExp("^\\s*"+name+"\\s*:","i");for(idx=0;idx<length;idx++){header=this.extraHeaders[idx];if(regexp.test(header)){return header.substring(header.indexOf(":")+1).trim()}}}return},getHeaders:function(name){var idx,length,regexp,header=this.headers[SIP.Utils.headerize(name)],result=[];if(header){length=header.length;for(idx=0;idx<length;idx++){result.push(header[idx])}return result}else{length=this.extraHeaders.length;regexp=new RegExp("^\\s*"+name+"\\s*:","i");for(idx=0;idx<length;idx++){header=this.extraHeaders[idx];if(regexp.test(header)){result.push(header.substring(header.indexOf(":")+1).trim())}}return result}},hasHeader:function(name){var regexp,idx,length=this.extraHeaders.length;if(this.headers[SIP.Utils.headerize(name)]){return true}else{regexp=new RegExp("^\\s*"+name+"\\s*:","i");for(idx=0;idx<length;idx++){if(regexp.test(this.extraHeaders[idx])){return true}}}return false},toString:function(){var msg="",header,length,idx;msg+=this.method+" "+(this.ruri.toRaw?this.ruri.toRaw():this.ruri)+" SIP/2.0\r\n";for(header in this.headers){length=this.headers[header].length;for(idx=0;idx<length;idx++){msg+=header+": "+this.headers[header][idx]+"\r\n"}}length=this.extraHeaders.length;for(idx=0;idx<length;idx++){msg+=this.extraHeaders[idx].trim()+"\r\n"}msg+=getSupportedHeader(this);msg+="User-Agent: "+this.ua.configuration.userAgentString+"\r\n";if(this.body){if(typeof this.body==="string"){length=SIP.Utils.str_utf8_length(this.body);msg+="Content-Length: "+length+"\r\n\r\n";msg+=this.body}else{if(this.body.body&&this.body.contentType){length=SIP.Utils.str_utf8_length(this.body.body);msg+="Content-Type: "+this.body.contentType+"\r\n";msg+="Content-Length: "+length+"\r\n\r\n";msg+=this.body.body}else{msg+="Content-Length: "+0+"\r\n\r\n"}}}else{msg+="Content-Length: "+0+"\r\n\r\n"}return msg}};IncomingMessage=function(){this.data=null;this.headers=null;this.method=null;this.via=null;this.via_branch=null;this.call_id=null;this.cseq=null;this.from=null;this.from_tag=null;this.to=null;this.to_tag=null;this.body=null};IncomingMessage.prototype={addHeader:function(name,value){var header={raw:value};name=SIP.Utils.headerize(name);if(this.headers[name]){this.headers[name].push(header)}else{this.headers[name]=[header]}},getHeader:function(name){var header=this.headers[SIP.Utils.headerize(name)];if(header){if(header[0]){return header[0].raw}}else{return}},getHeaders:function(name){var idx,length,header=this.headers[SIP.Utils.headerize(name)],result=[];if(!header){return[]}length=header.length;for(idx=0;idx<length;idx++){result.push(header[idx].raw)}return result},hasHeader:function(name){return this.headers[SIP.Utils.headerize(name)]?true:false},parseHeader:function(name,idx){var header,value,parsed;name=SIP.Utils.headerize(name);idx=idx||0;if(!this.headers[name]){this.logger.log('header "'+name+'" not present');return}else if(idx>=this.headers[name].length){this.logger.log('not so many "'+name+'" headers present');return}header=this.headers[name][idx];value=header.raw;if(header.parsed){return header.parsed}parsed=SIP.Grammar.parse(value,name.replace(/-/g,"_"));if(parsed===-1){this.headers[name].splice(idx,1);this.logger.warn('error parsing "'+name+'" header field with value "'+value+'"');return}else{header.parsed=parsed;return parsed}},s:function(name,idx){return this.parseHeader(name,idx)},setHeader:function(name,value){var header={raw:value};this.headers[SIP.Utils.headerize(name)]=[header]},toString:function(){return this.data}};IncomingRequest=function(ua){this.logger=ua.getLogger("sip.sipmessage");this.ua=ua;this.headers={};this.ruri=null;this.transport=null;this.server_transaction=null};IncomingRequest.prototype=new IncomingMessage;IncomingRequest.prototype.reply=function(code,reason,extraHeaders,body,onSuccess,onFailure){var rr,vias,length,idx,response,to=this.getHeader("To"),r=0,v=0;response=SIP.Utils.buildStatusLine(code,reason);extraHeaders=(extraHeaders||[]).slice();if(this.method===SIP.C.INVITE&&code>100&&code<=200){rr=this.getHeaders("record-route");length=rr.length;for(r;r<length;r++){response+="Record-Route: "+rr[r]+"\r\n"}}vias=this.getHeaders("via");length=vias.length;for(v;v<length;v++){response+="Via: "+vias[v]+"\r\n"}if(!this.to_tag&&code>100){to+=";tag="+SIP.Utils.newTag()}else if(this.to_tag&&!this.s("to").hasParam("tag")){to+=";tag="+this.to_tag}response+="To: "+to+"\r\n";response+="From: "+this.getHeader("From")+"\r\n";response+="Call-ID: "+this.call_id+"\r\n";response+="CSeq: "+this.cseq+" "+this.method+"\r\n";length=extraHeaders.length;for(idx=0;idx<length;idx++){response+=extraHeaders[idx].trim()+"\r\n"}response+=getSupportedHeader(this);response+="User-Agent: "+this.ua.configuration.userAgentString+"\r\n";if(body){if(typeof body==="string"){length=SIP.Utils.str_utf8_length(body);response+="Content-Type: application/sdp\r\n";response+="Content-Length: "+length+"\r\n\r\n";response+=body}else{if(body.body&&body.contentType){length=SIP.Utils.str_utf8_length(body.body);response+="Content-Type: "+body.contentType+"\r\n";response+="Content-Length: "+length+"\r\n\r\n";response+=body.body}else{response+="Content-Length: "+0+"\r\n\r\n"}}}else{response+="Content-Length: "+0+"\r\n\r\n"}this.server_transaction.receiveResponse(code,response).then(onSuccess,onFailure);return response};IncomingRequest.prototype.reply_sl=function(code,reason){var to,response,v=0,vias=this.getHeaders("via"),length=vias.length;response=SIP.Utils.buildStatusLine(code,reason);for(v;v<length;v++){response+="Via: "+vias[v]+"\r\n"}to=this.getHeader("To");if(!this.to_tag&&code>100){to+=";tag="+SIP.Utils.newTag()}else if(this.to_tag&&!this.s("to").hasParam("tag")){to+=";tag="+this.to_tag}response+="To: "+to+"\r\n";response+="From: "+this.getHeader("From")+"\r\n";response+="Call-ID: "+this.call_id+"\r\n";response+="CSeq: "+this.cseq+" "+this.method+"\r\n";response+="User-Agent: "+this.ua.configuration.userAgentString+"\r\n";response+="Content-Length: "+0+"\r\n\r\n";this.transport.send(response)};IncomingResponse=function(ua){this.logger=ua.getLogger("sip.sipmessage");this.headers={};this.status_code=null;this.reason_phrase=null};IncomingResponse.prototype=new IncomingMessage;SIP.OutgoingRequest=OutgoingRequest;SIP.IncomingRequest=IncomingRequest;SIP.IncomingResponse=IncomingResponse}},{}],79:[function(require,module,exports){"use strict";module.exports=function(SIP){var sanityCheck,logger,message,ua,transport,requests=[],responses=[],all=[];function reply(status_code){var to,response=SIP.Utils.buildStatusLine(status_code),vias=message.getHeaders("via"),length=vias.length,idx=0;for(idx;idx<length;idx++){response+="Via: "+vias[idx]+"\r\n"}to=message.getHeader("To");if(!message.to_tag){to+=";tag="+SIP.Utils.newTag()}response+="To: "+to+"\r\n";response+="From: "+message.getHeader("From")+"\r\n";response+="Call-ID: "+message.call_id+"\r\n";response+="CSeq: "+message.cseq+" "+message.method+"\r\n";response+="\r\n";transport.send(response)}function rfc3261_8_2_2_1(){if(!message.ruri||message.ruri.scheme!=="sip"){reply(416);return false}}function rfc3261_16_3_4(){if(!message.to_tag){if(message.call_id.substr(0,5)===ua.configuration.sipjsId){reply(482);return false}}}function rfc3261_18_3_request(){var len=SIP.Utils.str_utf8_length(message.body),contentLength=message.getHeader("content-length");if(len<contentLength){reply(400);return false}}function rfc3261_8_2_2_2(){var tr,idx,fromTag=message.from_tag,call_id=message.call_id,cseq=message.cseq;if(!message.to_tag){if(message.method===SIP.C.INVITE){tr=ua.transactions.ist[message.via_branch];if(tr){return}else{for(idx in ua.transactions.ist){tr=ua.transactions.ist[idx];if(tr.request.from_tag===fromTag&&tr.request.call_id===call_id&&tr.request.cseq===cseq){reply(482);return false}}}}else{tr=ua.transactions.nist[message.via_branch];if(tr){return}else{for(idx in ua.transactions.nist){tr=ua.transactions.nist[idx];if(tr.request.from_tag===fromTag&&tr.request.call_id===call_id&&tr.request.cseq===cseq){reply(482);return false}}}}}}function rfc3261_8_1_3_3(){if(message.getHeaders("via").length>1){logger.warn("More than one Via header field present in the response. Dropping the response");return false}}function rfc3261_18_3_response(){var len=SIP.Utils.str_utf8_length(message.body),contentLength=message.getHeader("content-length");if(len<contentLength){logger.warn("Message body length is lower than the value in Content-Length header field. Dropping the response");return false}}function minimumHeaders(){var mandatoryHeaders=["from","to","call_id","cseq","via"],idx=mandatoryHeaders.length;while(idx--){if(!message.hasHeader(mandatoryHeaders[idx])){logger.warn("Missing mandatory header field : "+mandatoryHeaders[idx]+". Dropping the response");return false}}}requests.push(rfc3261_8_2_2_1);requests.push(rfc3261_16_3_4);requests.push(rfc3261_18_3_request);requests.push(rfc3261_8_2_2_2);responses.push(rfc3261_8_1_3_3);responses.push(rfc3261_18_3_response);all.push(minimumHeaders);sanityCheck=function(m,u,t){var len,pass;message=m;ua=u;transport=t;logger=ua.getLogger("sip.sanitycheck");len=all.length;while(len--){pass=all[len](message);if(pass===false){return false}}if(message instanceof SIP.IncomingRequest){len=requests.length;while(len--){pass=requests[len](message);if(pass===false){return false}}}else if(message instanceof SIP.IncomingResponse){len=responses.length;while(len--){pass=responses[len](message);if(pass===false){return false}}}return true};SIP.sanityCheck=sanityCheck}},{}],80:[function(require,module,exports){"use strict";module.exports=function(SIP){var ServerContext;ServerContext=function(ua,request){this.ua=ua;this.logger=ua.getLogger("sip.servercontext");this.request=request;if(request.method===SIP.C.INVITE){this.transaction=new SIP.Transactions.InviteServerTransaction(request,ua)}else{this.transaction=new SIP.Transactions.NonInviteServerTransaction(request,ua)}if(request.body){this.body=request.body}if(request.hasHeader("Content-Type")){this.contentType=request.getHeader("Content-Type")}this.method=request.method;this.data={};this.localIdentity=request.to;this.remoteIdentity=request.from};ServerContext.prototype=Object.create(SIP.EventEmitter.prototype);ServerContext.prototype.progress=function(options){options=Object.create(options||Object.prototype);options.statusCode||(options.statusCode=180);options.minCode=100;options.maxCode=199;options.events=["progress"];return this.reply(options)};ServerContext.prototype.accept=function(options){options=Object.create(options||Object.prototype);options.statusCode||(options.statusCode=200);options.minCode=200;options.maxCode=299;options.events=["accepted"];return this.reply(options)};ServerContext.prototype.reject=function(options){options=Object.create(options||Object.prototype);options.statusCode||(options.statusCode=480);options.minCode=300;options.maxCode=699;options.events=["rejected","failed"];return this.reply(options)};ServerContext.prototype.reply=function(options){options=options||{};var statusCode=options.statusCode||100,minCode=options.minCode||100,maxCode=options.maxCode||699,reasonPhrase=SIP.Utils.getReasonPhrase(statusCode,options.reasonPhrase),extraHeaders=options.extraHeaders||[],body=options.body,events=options.events||[],response;if(statusCode<minCode||statusCode>maxCode){throw new TypeError("Invalid statusCode: "+statusCode)}response=this.request.reply(statusCode,reasonPhrase,extraHeaders,body)
;events.forEach(function(event){this.emit(event,response,reasonPhrase)},this);return this};ServerContext.prototype.onRequestTimeout=function(){this.emit("failed",null,SIP.C.causes.REQUEST_TIMEOUT)};ServerContext.prototype.onTransportError=function(){this.emit("failed",null,SIP.C.causes.CONNECTION_ERROR)};SIP.ServerContext=ServerContext}},{}],81:[function(require,module,exports){"use strict";module.exports=function(SIP,environment){var DTMF=require("./Session/DTMF")(SIP);var RFC4028=require("./RFC4028")(SIP.Timers);var Session,InviteServerContext,InviteClientContext,C={STATUS_NULL:0,STATUS_INVITE_SENT:1,STATUS_1XX_RECEIVED:2,STATUS_INVITE_RECEIVED:3,STATUS_WAITING_FOR_ANSWER:4,STATUS_ANSWERED:5,STATUS_WAITING_FOR_PRACK:6,STATUS_WAITING_FOR_ACK:7,STATUS_CANCELED:8,STATUS_TERMINATED:9,STATUS_ANSWERED_WAITING_FOR_PRACK:10,STATUS_EARLY_MEDIA:11,STATUS_CONFIRMED:12};Session=function(mediaHandlerFactory){this.status=C.STATUS_NULL;this.dialog=null;this.earlyDialogs={};this.mediaHandlerFactory=mediaHandlerFactory||SIP.WebRTC.MediaHandler.defaultFactory;this.hasOffer=false;this.hasAnswer=false;this.timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null,rel1xxTimer:null,prackTimer:null};this.startTime=null;this.endTime=null;this.tones=null;this.local_hold=false;this.remote_hold=false;this.pending_actions={actions:[],length:function(){return this.actions.length},isPending:function(name){var idx=0,length=this.actions.length;for(idx;idx<length;idx++){if(this.actions[idx].name===name){return true}}return false},shift:function(){return this.actions.shift()},push:function(name){this.actions.push({name:name})},pop:function(name){var idx=0,length=this.actions.length;for(idx;idx<length;idx++){if(this.actions[idx].name===name){this.actions.splice(idx,1);length--;idx--}}}};this.early_sdp=null;this.rel100=SIP.C.supported.UNSUPPORTED};Session.prototype={dtmf:function(tones,options){var tone,dtmfs=[],self=this;options=options||{};if(tones===undefined){throw new TypeError("Not enough arguments")}if(this.status!==C.STATUS_CONFIRMED&&this.status!==C.STATUS_WAITING_FOR_ACK){throw new SIP.Exceptions.InvalidStateError(this.status)}if(typeof tones!=="string"&&typeof tones!=="number"||!tones.toString().match(/^[0-9A-D#*,]+$/i)){throw new TypeError("Invalid tones: "+tones)}tones=tones.toString().split("");while(tones.length>0){dtmfs.push(new DTMF(this,tones.shift(),options))}if(this.tones){this.tones=this.tones.concat(dtmfs);return this}var sendDTMF=function(){var dtmf,timeout;if(self.status===C.STATUS_TERMINATED||!self.tones||self.tones.length===0){self.tones=null;return this}dtmf=self.tones.shift();if(tone===","){timeout=2e3}else{dtmf.on("failed",function(){self.tones=null});dtmf.send(options);timeout=dtmf.duration+dtmf.interToneGap}SIP.Timers.setTimeout(sendDTMF,timeout)};this.tones=dtmfs;sendDTMF();return this},bye:function(options){options=Object.create(options||Object.prototype);var statusCode=options.statusCode;if(this.status===C.STATUS_TERMINATED){this.logger.error("Error: Attempted to send BYE in a terminated session.");return this}this.logger.log("terminating Session");if(statusCode&&(statusCode<200||statusCode>=700)){throw new TypeError("Invalid statusCode: "+statusCode)}options.receiveResponse=function(){};return this.sendRequest(SIP.C.BYE,options).terminated()},refer:function(target,options){options=options||{};var extraHeaders=(options.extraHeaders||[]).slice(),withReplaces=target instanceof SIP.InviteServerContext||target instanceof SIP.InviteClientContext,originalTarget=target;if(target===undefined){throw new TypeError("Not enough arguments")}if(this.status!==C.STATUS_CONFIRMED){throw new SIP.Exceptions.InvalidStateError(this.status)}if(withReplaces){target='"'+target.remoteIdentity.friendlyName+'" '+"<"+target.dialog.remote_target.toString()+"?Replaces="+target.dialog.id.call_id+"%3Bto-tag%3D"+target.dialog.id.remote_tag+"%3Bfrom-tag%3D"+target.dialog.id.local_tag+">"}else{try{target=SIP.Grammar.parse(target,"Refer_To").uri||target}catch(e){this.logger.debug(".refer() cannot parse Refer_To from",target);this.logger.debug("...falling through to normalizeTarget()")}target=this.ua.normalizeTarget(target);if(!target){throw new TypeError("Invalid target: "+originalTarget)}}extraHeaders.push("Contact: "+this.contact);extraHeaders.push("Allow: "+SIP.UA.C.ALLOWED_METHODS.toString());extraHeaders.push("Refer-To: "+target);this.sendRequest(SIP.C.REFER,{extraHeaders:extraHeaders,body:options.body,receiveResponse:function(response){if(!/^2[0-9]{2}$/.test(response.status_code)){return}if(withReplaces||target.scheme&&target.scheme.match("^sips?$")){this.terminate()}}.bind(this)});return this},followRefer:function followRefer(callback){return function referListener(callback,request){var referTo=request.parseHeader("refer-to");var target=referTo.uri;if(!target.scheme.match("^sips?$")){var targetString=target.toString();if(typeof environment.open==="function"){environment.open(targetString)}else{this.logger.warn("referred to non-SIP URI but `open` isn't in the environment: "+targetString)}return}var extraHeaders=[];var replaces=target.getHeader("Replaces");if(replaces!==undefined){extraHeaders.push("Replaces: "+decodeURIComponent(replaces))}target.clearHeaders();var getReferMedia=this.mediaHandler.getReferMedia;var mediaHint=getReferMedia?getReferMedia.call(this.mediaHandler):this.mediaHint;SIP.Hacks.Chrome.getsConfusedAboutGUM(this);var referSession=this.ua.invite(target,{media:mediaHint,params:{to_displayName:referTo.friendlyName},extraHeaders:extraHeaders});callback.call(this,request,referSession);this.terminate()}.bind(this,callback)},sendRequest:function(method,options){options=options||{};var self=this;var request=new SIP.OutgoingRequest(method,this.dialog.remote_target,this.ua,{cseq:options.cseq||(this.dialog.local_seqnum+=1),call_id:this.dialog.id.call_id,from_uri:this.dialog.local_uri,from_tag:this.dialog.id.local_tag,to_uri:this.dialog.remote_uri,to_tag:this.dialog.id.remote_tag,route_set:this.dialog.route_set,statusCode:options.statusCode,reasonPhrase:options.reasonPhrase},options.extraHeaders||[],options.body);new SIP.RequestSender({request:request,onRequestTimeout:function(){self.onRequestTimeout()},onTransportError:function(){self.onTransportError()},receiveResponse:options.receiveResponse||function(response){self.receiveNonInviteResponse(response)}},this.ua).send();this.emit(method.toLowerCase(),request);return this},close:function(){var idx;if(this.status===C.STATUS_TERMINATED){return this}this.logger.log("closing INVITE session "+this.id);if(this.mediaHandler){this.mediaHandler.close()}for(idx in this.timers){SIP.Timers.clearTimeout(this.timers[idx])}if(this.dialog){this.dialog.terminate();delete this.dialog}for(idx in this.earlyDialogs){this.earlyDialogs[idx].terminate();delete this.earlyDialogs[idx]}this.status=C.STATUS_TERMINATED;delete this.ua.sessions[this.id];return this},createDialog:function(message,type,early){var dialog,early_dialog,local_tag=message[type==="UAS"?"to_tag":"from_tag"],remote_tag=message[type==="UAS"?"from_tag":"to_tag"],id=message.call_id+local_tag+remote_tag;early_dialog=this.earlyDialogs[id];if(early){if(early_dialog){return true}else{early_dialog=new SIP.Dialog(this,message,type,SIP.Dialog.C.STATUS_EARLY);if(early_dialog.error){this.logger.error(early_dialog.error);this.failed(message,SIP.C.causes.INTERNAL_ERROR);return false}else{this.earlyDialogs[id]=early_dialog;return true}}}else{if(early_dialog){early_dialog.update(message,type);this.dialog=early_dialog;delete this.earlyDialogs[id];for(var dia in this.earlyDialogs){this.earlyDialogs[dia].terminate();delete this.earlyDialogs[dia]}return true}dialog=new SIP.Dialog(this,message,type);if(dialog.error){this.logger.error(dialog.error);this.failed(message,SIP.C.causes.INTERNAL_ERROR);return false}else{this.to_tag=message.to_tag;this.dialog=dialog;return true}}},isReadyToReinvite:function(){return this.mediaHandler.isReady()&&!this.dialog.uac_pending_reply&&!this.dialog.uas_pending_reply},mute:function(options){var ret=this.mediaHandler.mute(options);if(ret){this.onmute(ret)}},unmute:function(options){var ret=this.mediaHandler.unmute(options);if(ret){this.onunmute(ret)}},hold:function(){if(this.status!==C.STATUS_WAITING_FOR_ACK&&this.status!==C.STATUS_CONFIRMED){throw new SIP.Exceptions.InvalidStateError(this.status)}this.mediaHandler.hold();if(!this.isReadyToReinvite()){if(this.pending_actions.isPending("unhold")){this.pending_actions.pop("unhold")}else if(!this.pending_actions.isPending("hold")){this.pending_actions.push("hold")}return}else if(this.local_hold===true){return}this.onhold("local");this.sendReinvite()},unhold:function(options){if(this.status!==C.STATUS_WAITING_FOR_ACK&&this.status!==C.STATUS_CONFIRMED){throw new SIP.Exceptions.InvalidStateError(this.status)}this.mediaHandler.unhold();if(!this.isReadyToReinvite()){if(this.pending_actions.isPending("hold")){this.pending_actions.pop("hold")}else if(!this.pending_actions.isPending("unhold")){this.pending_actions.push("unhold")}return}else if(this.local_hold===false){return}this.onunhold("local");this.sendReinvite(options)},isOnHold:function(){return{local:this.local_hold,remote:this.remote_hold}},receiveReinvite:function(request){var self=this;if(!this.mediaHandler.hasDescription(request)){this.logger.warn("invalid Content-Type");request.reply(415);return}this.mediaHandler.setDescription(request).then(this.mediaHandler.getDescription.bind(this.mediaHandler,this.mediaHint)).then(function(description){var extraHeaders=["Contact: "+self.contact];request.reply(200,null,extraHeaders,description,function(){self.status=C.STATUS_WAITING_FOR_ACK;self.setInvite2xxTimer(request,description);self.setACKTimer();if(self.remote_hold&&!self.mediaHandler.remote_hold){self.onunhold("remote")}else if(!self.remote_hold&&self.mediaHandler.remote_hold){self.onhold("remote")}})}).catch(function onFailure(e){var statusCode;if(e instanceof SIP.Exceptions.GetDescriptionError){statusCode=500}else{self.logger.error(e);statusCode=488}request.reply(statusCode)})},sendReinvite:function(options){options=options||{};var self=this,extraHeaders=(options.extraHeaders||[]).slice(),eventHandlers=options.eventHandlers||{},succeeded;if(eventHandlers.succeeded){succeeded=eventHandlers.succeeded}this.reinviteSucceeded=function(){SIP.Timers.clearTimeout(self.timers.ackTimer);SIP.Timers.clearTimeout(self.timers.invite2xxTimer);self.status=C.STATUS_CONFIRMED;succeeded&&succeeded.apply(this,arguments)};if(eventHandlers.failed){this.reinviteFailed=eventHandlers.failed}else{this.reinviteFailed=function(){}}extraHeaders.push("Contact: "+this.contact);extraHeaders.push("Allow: "+SIP.UA.C.ALLOWED_METHODS.toString());this.receiveResponse=this.receiveReinviteResponse;this.mediaHandler.getDescription(self.mediaHint).then(function(description){self.dialog.sendRequest(self,SIP.C.INVITE,{extraHeaders:extraHeaders,body:description})},function(){if(self.isReadyToReinvite()){self.onReadyToReinvite()}self.reinviteFailed()})},receiveRequest:function(request){switch(request.method){case SIP.C.BYE:request.reply(200);if(this.status===C.STATUS_CONFIRMED){this.emit("bye",request);this.terminated(request,SIP.C.causes.BYE)}break;case SIP.C.INVITE:if(this.status===C.STATUS_CONFIRMED){this.logger.log("re-INVITE received");this.receiveReinvite(request)}break;case SIP.C.INFO:if(this.status===C.STATUS_1XX_RECEIVED||this.status===C.STATUS_WAITING_FOR_PRACK||this.status===C.STATUS_WAITING_FOR_ACK||this.status===C.STATUS_ANSWERED_WAITING_FOR_PRACK||this.status===C.STATUS_EARLY_MEDIA||this.status===C.STATUS_CONFIRMED||this.dialog){if(this.onInfo){return this.onInfo(request)}var body,tone,duration,contentType=request.getHeader("content-type"),reg_tone=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,reg_duration=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;if(contentType){if(contentType.match(/^application\/dtmf-relay/i)){if(request.body){body=request.body.split("\r\n",2);if(body.length===2){if(reg_tone.test(body[0])){tone=body[0].replace(reg_tone,"$2")}if(reg_duration.test(body[1])){duration=parseInt(body[1].replace(reg_duration,"$2"),10)}}}new DTMF(this,tone,{duration:duration}).init_incoming(request)}else{request.reply(415,null,["Accept: application/dtmf-relay"])}}}break;case SIP.C.REFER:if(this.status===C.STATUS_CONFIRMED){this.logger.log("REFER received");var hasReferListener=this.listeners("refer").length,notifyBody;if(hasReferListener){request.reply(202,"Accepted");notifyBody="SIP/2.0 100 Trying";this.sendRequest(SIP.C.NOTIFY,{extraHeaders:["Event: refer","Subscription-State: terminated","Content-Type: message/sipfrag"],body:notifyBody,receiveResponse:function(){}});this.emit("refer",request)}else{request.reply(603,"Declined")}}break;case SIP.C.NOTIFY:request.reply(200,"OK");this.emit("notify",request);break}},receiveReinviteResponse:function(response){var self=this;if(this.status===C.STATUS_TERMINATED){return}switch(true){case/^1[0-9]{2}$/.test(response.status_code):break;case/^2[0-9]{2}$/.test(response.status_code):this.status=C.STATUS_CONFIRMED;this.sendRequest(SIP.C.ACK,{cseq:response.cseq});if(!this.mediaHandler.hasDescription(response)){this.reinviteFailed();break}this.mediaHandler.setDescription(response).then(function onSuccess(){self.reinviteSucceeded()},function onFailure(){self.reinviteFailed()});break;default:this.reinviteFailed()}},acceptAndTerminate:function(response,status_code,reason_phrase){var extraHeaders=[];if(status_code){extraHeaders.push("Reason: "+SIP.Utils.getReasonHeaderValue(status_code,reason_phrase))}if(this.dialog||this.createDialog(response,"UAC")){this.sendRequest(SIP.C.ACK,{cseq:response.cseq});this.sendRequest(SIP.C.BYE,{extraHeaders:extraHeaders})}return this},setInvite2xxTimer:function(request,description){var self=this,timeout=SIP.Timers.T1;this.timers.invite2xxTimer=SIP.Timers.setTimeout(function invite2xxRetransmission(){if(self.status!==C.STATUS_WAITING_FOR_ACK){return}self.logger.log("no ACK received, attempting to retransmit OK");var extraHeaders=["Contact: "+self.contact];request.reply(200,null,extraHeaders,description);timeout=Math.min(timeout*2,SIP.Timers.T2);self.timers.invite2xxTimer=SIP.Timers.setTimeout(invite2xxRetransmission,timeout)},timeout)},setACKTimer:function(){var self=this;this.timers.ackTimer=SIP.Timers.setTimeout(function(){if(self.status===C.STATUS_WAITING_FOR_ACK){self.logger.log("no ACK received for an extended period of time, terminating the call");SIP.Timers.clearTimeout(self.timers.invite2xxTimer);self.sendRequest(SIP.C.BYE);self.terminated(null,SIP.C.causes.NO_ACK)}},SIP.Timers.TIMER_H)},onReadyToReinvite:function(){var action=this.pending_actions.shift();if(!action||!this[action.name]){return}this[action.name]()},onTransportError:function(){if(this.status!==C.STATUS_CONFIRMED&&this.status!==C.STATUS_TERMINATED){this.failed(null,SIP.C.causes.CONNECTION_ERROR)}},onRequestTimeout:function(){if(this.status===C.STATUS_CONFIRMED){this.terminated(null,SIP.C.causes.REQUEST_TIMEOUT)}else if(this.status!==C.STATUS_TERMINATED){this.failed(null,SIP.C.causes.REQUEST_TIMEOUT);this.terminated(null,SIP.C.causes.REQUEST_TIMEOUT)}},onDialogError:function(response){if(this.status===C.STATUS_CONFIRMED){this.terminated(response,SIP.C.causes.DIALOG_ERROR)}else if(this.status!==C.STATUS_TERMINATED){this.failed(response,SIP.C.causes.DIALOG_ERROR);this.terminated(response,SIP.C.causes.DIALOG_ERROR)}},onhold:function(originator){this[originator==="local"?"local_hold":"remote_hold"]=true;this.emit("hold",{originator:originator})},onunhold:function(originator){this[originator==="local"?"local_hold":"remote_hold"]=false;this.emit("unhold",{originator:originator})},onmute:function(options){this.emit("muted",{audio:options.audio,video:options.video})},onunmute:function(options){this.emit("unmuted",{audio:options.audio,video:options.video})},failed:function(response,cause){if(this.status===C.STATUS_TERMINATED){return this}this.emit("failed",response||null,cause||null);return this},rejected:function(response,cause){this.emit("rejected",response||null,cause||null);return this},canceled:function(){this.emit("cancel");return this},accepted:function(response,cause){cause=SIP.Utils.getReasonPhrase(response&&response.status_code,cause);this.startTime=new Date;if(this.replacee){this.replacee.emit("replaced",this);this.replacee.terminate()}if(response){RFC4028.updateState(this.dialog,response,SIP.Parser.parseMessage,this.ua)}this.emit("accepted",response,cause);return this},terminated:function(message,cause){if(this.status===C.STATUS_TERMINATED){return this}this.endTime=new Date;this.close();this.emit("terminated",message||null,cause||null);return this},connecting:function(request){this.emit("connecting",{request:request});return this}};Session.desugar=function desugar(options){if(environment.HTMLMediaElement&&options instanceof environment.HTMLMediaElement){options={media:{constraints:{audio:true,video:options.tagName==="VIDEO"},render:{remote:options}}}}return options||{}};Session.C=C;SIP.Session=Session;InviteServerContext=function(ua,request){var expires,self=this,contentType=request.getHeader("Content-Type"),contentDisp=request.parseHeader("Content-Disposition");SIP.Utils.augment(this,SIP.ServerContext,[ua,request]);SIP.Utils.augment(this,SIP.Session,[ua.configuration.mediaHandlerFactory]);this.mediaHandler=this.mediaHandlerFactory(this,{RTCConstraints:{optional:[{DtlsSrtpKeyAgreement:"true"}]}});if(!contentDisp&&!this.mediaHandler.hasDescription(request)||contentDisp&&contentDisp.type==="render"){this.renderbody=request.body;this.rendertype=contentType}else if(!this.mediaHandler.hasDescription(request)&&(contentDisp&&contentDisp.type==="session")){request.reply(415);return}if(RFC4028.hasSmallMinSE(request)){request.reply(422,null,["Min-SE: "+RFC4028.localMinSE]);return}this.status=C.STATUS_INVITE_RECEIVED;this.from_tag=request.from_tag;this.id=request.call_id+this.from_tag;this.request=request;this.contact=this.ua.contact.toString();this.receiveNonInviteResponse=function(){};this.logger=ua.getLogger("sip.inviteservercontext",this.id);this.ua.sessions[this.id]=this;if(request.hasHeader("expires")){expires=request.getHeader("expires")*1e3}function set100rel(h,c){if(request.hasHeader(h)&&request.getHeader(h).toLowerCase().indexOf("100rel")>=0){self.rel100=c}}set100rel("require",SIP.C.supported.REQUIRED);set100rel("supported",SIP.C.supported.SUPPORTED);request.to_tag=SIP.Utils.newTag();if(!this.createDialog(request,"UAS",true)){request.reply(500,"Missing Contact header field");return}if(this.mediaHandler&&this.mediaHandler.getRemoteStreams){this.getRemoteStreams=this.mediaHandler.getRemoteStreams.bind(this.mediaHandler);this.getLocalStreams=this.mediaHandler.getLocalStreams.bind(this.mediaHandler)}function fireNewSession(){var options={extraHeaders:["Contact: "+self.contact]};if(self.rel100!==SIP.C.supported.REQUIRED){self.progress(options)}self.status=C.STATUS_WAITING_FOR_ANSWER;self.timers.userNoAnswerTimer=SIP.Timers.setTimeout(function(){request.reply(408);self.failed(request,SIP.C.causes.NO_ANSWER);self.terminated(request,SIP.C.causes.NO_ANSWER)},self.ua.configuration.noAnswerTimeout);if(expires){self.timers.expiresTimer=SIP.Timers.setTimeout(function(){if(self.status===C.STATUS_WAITING_FOR_ANSWER){request.reply(487);self.failed(request,SIP.C.causes.EXPIRES);self.terminated(request,SIP.C.causes.EXPIRES)}},expires)}self.emit("invite",request)}if(!this.mediaHandler.hasDescription(request)||this.renderbody){SIP.Timers.setTimeout(fireNewSession,0)}else{this.hasOffer=true;this.mediaHandler.setDescription(request).then(fireNewSession,function onFailure(e){self.logger.warn("invalid description");self.logger.warn(e);request.reply(488)})}};InviteServerContext.prototype={reject:function(options){if(this.status===C.STATUS_TERMINATED){throw new SIP.Exceptions.InvalidStateError(this.status)}this.logger.log("rejecting RTCSession");SIP.ServerContext.prototype.reject.call(this,options);return this.terminated()},terminate:function(options){options=options||{};var extraHeaders=(options.extraHeaders||[]).slice(),body=options.body,dialog,self=this;if(this.status===C.STATUS_WAITING_FOR_ACK&&this.request.server_transaction.state!==SIP.Transactions.C.STATUS_TERMINATED){dialog=this.dialog;this.receiveRequest=function(request){if(request.method===SIP.C.ACK){this.sendRequest(SIP.C.BYE,{extraHeaders:extraHeaders,body:body});dialog.terminate()}};this.request.server_transaction.on("stateChanged",function(){if(this.state===SIP.Transactions.C.STATUS_TERMINATED&&this.dialog){this.request=new SIP.OutgoingRequest(SIP.C.BYE,this.dialog.remote_target,this.ua,{cseq:this.dialog.local_seqnum+=1,call_id:this.dialog.id.call_id,from_uri:this.dialog.local_uri,from_tag:this.dialog.id.local_tag,to_uri:this.dialog.remote_uri,to_tag:this.dialog.id.remote_tag,route_set:this.dialog.route_set},extraHeaders,body);new SIP.RequestSender({request:this.request,onRequestTimeout:function(){self.onRequestTimeout()},onTransportError:function(){self.onTransportError()},receiveResponse:function(){return}},this.ua).send();dialog.terminate()}});this.emit("bye",this.request);this.terminated();this.dialog=dialog;this.ua.dialogs[dialog.id.toString()]=dialog}else if(this.status===C.STATUS_CONFIRMED){this.bye(options)}else{this.reject(options)}return this},progress:function(options){options=options||{};var statusCode=options.statusCode||180,reasonPhrase=options.reasonPhrase,extraHeaders=(options.extraHeaders||[]).slice(),iceServers,stunServers=options.stunServers||null,turnServers=options.turnServers||null,body=options.body,response;if(statusCode<100||statusCode>199){throw new TypeError("Invalid statusCode: "+statusCode)}if(this.isCanceled||this.status===C.STATUS_TERMINATED){return this}if(stunServers||turnServers){if(stunServers){iceServers=SIP.UA.configuration_check.optional["stunServers"](stunServers);if(!iceServers){throw new TypeError("Invalid stunServers: "+stunServers)}else{this.stunServers=iceServers}}if(turnServers){iceServers=SIP.UA.configuration_check.optional["turnServers"](turnServers);if(!iceServers){throw new TypeError("Invalid turnServers: "+turnServers)}else{this.turnServers=iceServers}}this.mediaHandler.updateIceServers({stunServers:this.stunServers,turnServers:this.turnServers})}function do100rel(){statusCode=options.statusCode||183;this.status=C.STATUS_WAITING_FOR_PRACK;extraHeaders.push("Contact: "+this.contact);extraHeaders.push("Require: 100rel");extraHeaders.push("RSeq: "+Math.floor(Math.random()*1e4));this.mediaHint=options.media;this.mediaHandler.getDescription(options.media).then(function onSuccess(description){if(this.isCanceled||this.status===C.STATUS_TERMINATED){return}this.early_sdp=description.body;this[this.hasOffer?"hasAnswer":"hasOffer"]=true;var timeout=SIP.Timers.T1;this.timers.rel1xxTimer=SIP.Timers.setTimeout(function rel1xxRetransmission(){this.request.reply(statusCode,null,extraHeaders,description);timeout*=2;this.timers.rel1xxTimer=SIP.Timers.setTimeout(rel1xxRetransmission.bind(this),timeout)}.bind(this),timeout);this.timers.prackTimer=SIP.Timers.setTimeout(function(){if(this.status!==C.STATUS_WAITING_FOR_PRACK){return}this.logger.log("no PRACK received, rejecting the call");SIP.Timers.clearTimeout(this.timers.rel1xxTimer);this.request.reply(504);this.terminated(null,SIP.C.causes.NO_PRACK)}.bind(this),SIP.Timers.T1*64);response=this.request.reply(statusCode,reasonPhrase,extraHeaders,description);this.emit("progress",response,reasonPhrase)}.bind(this),function onFailure(){this.request.reply(480);this.failed(null,SIP.C.causes.WEBRTC_ERROR);this.terminated(null,SIP.C.causes.WEBRTC_ERROR)}.bind(this))}function normalReply(){response=this.request.reply(statusCode,reasonPhrase,extraHeaders,body);this.emit("progress",response,reasonPhrase)}if(options.statusCode!==100&&(this.rel100===SIP.C.supported.REQUIRED||this.rel100===SIP.C.supported.SUPPORTED&&options.rel100||this.rel100===SIP.C.supported.SUPPORTED&&this.ua.configuration.rel100===SIP.C.supported.REQUIRED)){do100rel.apply(this)}else{normalReply.apply(this)}return this},accept:function(options){options=Object.create(Session.desugar(options));SIP.Utils.optionsOverride(options,"media","mediaConstraints",true,this.logger,this.ua.configuration.media);this.mediaHint=options.media;this.onInfo=options.onInfo;var self=this,request=this.request,extraHeaders=(options.extraHeaders||[]).slice(),iceServers,stunServers=options.stunServers||null,turnServers=options.turnServers||null,descriptionCreationSucceeded=function(description){var response,replySucceeded=function(){self.status=C.STATUS_WAITING_FOR_ACK;self.setInvite2xxTimer(request,description);self.setACKTimer()},replyFailed=function(){self.failed(null,SIP.C.causes.CONNECTION_ERROR);self.terminated(null,SIP.C.causes.CONNECTION_ERROR)};self.mediaHandler.render();extraHeaders.push("Contact: "+self.contact);extraHeaders.push("Allow: "+SIP.UA.C.ALLOWED_METHODS.toString());var supportedOptions=request.parseHeader("Supported")||[];var sessionExpires=request.parseHeader("Session-Expires")||{};var interval=sessionExpires.deltaSeconds;if(interval){var refresher=sessionExpires.refresher||"uas";extraHeaders.push("Session-Expires: "+interval+";"+refresher);if(refresher==="uac"||supportedOptions.indexOf("timer")>=0){extraHeaders.push("Require: timer")}}if(!self.hasOffer){self.hasOffer=true}else{self.hasAnswer=true}response=request.reply(200,null,extraHeaders,description,replySucceeded,replyFailed);if(self.status!==C.STATUS_TERMINATED){self.accepted(response,SIP.Utils.getReasonPhrase(200))}},descriptionCreationFailed=function(){if(self.status===C.STATUS_TERMINATED){return}self.request.reply(480);self.failed(null,SIP.C.causes.WEBRTC_ERROR);self.terminated(null,SIP.C.causes.WEBRTC_ERROR)};if(this.status===C.STATUS_WAITING_FOR_PRACK){this.status=C.STATUS_ANSWERED_WAITING_FOR_PRACK;return this}else if(this.status===C.STATUS_WAITING_FOR_ANSWER){this.status=C.STATUS_ANSWERED}else if(this.status!==C.STATUS_EARLY_MEDIA){throw new SIP.Exceptions.InvalidStateError(this.status)}if((stunServers||turnServers)&&(this.status!==C.STATUS_EARLY_MEDIA&&this.status!==C.STATUS_ANSWERED_WAITING_FOR_PRACK)){if(stunServers){iceServers=SIP.UA.configuration_check.optional["stunServers"](stunServers);if(!iceServers){throw new TypeError("Invalid stunServers: "+stunServers)}else{this.stunServers=iceServers}}if(turnServers){iceServers=SIP.UA.configuration_check.optional["turnServers"](turnServers);if(!iceServers){throw new TypeError("Invalid turnServers: "+turnServers)}else{this.turnServers=iceServers}}this.mediaHandler.updateIceServers({stunServers:this.stunServers,turnServers:this.turnServers})}if(!this.createDialog(request,"UAS")){request.reply(500,"Missing Contact header field");return this}SIP.Timers.clearTimeout(this.timers.userNoAnswerTimer);if(this.status===C.STATUS_EARLY_MEDIA){descriptionCreationSucceeded({})}else{this.mediaHandler.getDescription(self.mediaHint).then(descriptionCreationSucceeded,descriptionCreationFailed)}return this},receiveRequest:function(request){function confirmSession(){var contentType;SIP.Timers.clearTimeout(this.timers.ackTimer);SIP.Timers.clearTimeout(this.timers.invite2xxTimer);this.status=C.STATUS_CONFIRMED;this.unmute();contentType=request.getHeader("Content-Type");if(!this.mediaHandler.hasDescription(request)){this.renderbody=request.body;this.rendertype=contentType}this.emit("confirmed",request)}switch(request.method){case SIP.C.CANCEL:if(this.status===C.STATUS_WAITING_FOR_ANSWER||this.status===C.STATUS_WAITING_FOR_PRACK||this.status===C.STATUS_ANSWERED_WAITING_FOR_PRACK||this.status===C.STATUS_EARLY_MEDIA||this.status===C.STATUS_ANSWERED){this.status=C.STATUS_CANCELED;this.request.reply(487);this.canceled(request);this.rejected(request,SIP.C.causes.CANCELED);this.failed(request,SIP.C.causes.CANCELED);this.terminated(request,SIP.C.causes.CANCELED)}break;case SIP.C.ACK:if(this.status===C.STATUS_WAITING_FOR_ACK){if(!this.hasAnswer){if(this.mediaHandler.hasDescription(request)){this.hasAnswer=true;this.mediaHandler.setDescription(request).then(confirmSession.bind(this),function onFailure(e){this.logger.warn(e);this.terminate({statusCode:"488",reasonPhrase:"Bad Media Description"});this.failed(request,SIP.C.causes.BAD_MEDIA_DESCRIPTION);this.terminated(request,SIP.C.causes.BAD_MEDIA_DESCRIPTION)}.bind(this))}else if(this.early_sdp){confirmSession.apply(this)}else{this.failed(request,SIP.C.causes.BAD_MEDIA_DESCRIPTION);this.terminated(request,SIP.C.causes.BAD_MEDIA_DESCRIPTION)}}else{confirmSession.apply(this)}}break;case SIP.C.PRACK:if(this.status===C.STATUS_WAITING_FOR_PRACK||this.status===C.STATUS_ANSWERED_WAITING_FOR_PRACK){if(!this.hasAnswer){if(this.mediaHandler.hasDescription(request)){this.hasAnswer=true;this.mediaHandler.setDescription(request).then(function onSuccess(){SIP.Timers.clearTimeout(this.timers.rel1xxTimer);SIP.Timers.clearTimeout(this.timers.prackTimer);request.reply(200);if(this.status===C.STATUS_ANSWERED_WAITING_FOR_PRACK){this.status=C.STATUS_EARLY_MEDIA;this.accept()}this.status=C.STATUS_EARLY_MEDIA;this.mute()}.bind(this),function onFailure(e){this.logger.warn(e);this.terminate({statusCode:"488",reasonPhrase:"Bad Media Description"});this.failed(request,SIP.C.causes.BAD_MEDIA_DESCRIPTION);this.terminated(request,SIP.C.causes.BAD_MEDIA_DESCRIPTION)}.bind(this))}else{this.terminate({statusCode:"488",reasonPhrase:"Bad Media Description"});this.failed(request,SIP.C.causes.BAD_MEDIA_DESCRIPTION);this.terminated(request,SIP.C.causes.BAD_MEDIA_DESCRIPTION)}}else{SIP.Timers.clearTimeout(this.timers.rel1xxTimer);SIP.Timers.clearTimeout(this.timers.prackTimer);request.reply(200);if(this.status===C.STATUS_ANSWERED_WAITING_FOR_PRACK){this.status=C.STATUS_EARLY_MEDIA;this.accept()}this.status=C.STATUS_EARLY_MEDIA;this.mute()}}else if(this.status===C.STATUS_EARLY_MEDIA){request.reply(200)}break;default:Session.prototype.receiveRequest.apply(this,[request]);break}},onTransportError:function(){if(this.status!==C.STATUS_CONFIRMED&&this.status!==C.STATUS_TERMINATED){this.failed(null,SIP.C.causes.CONNECTION_ERROR)}},onRequestTimeout:function(){if(this.status===C.STATUS_CONFIRMED){this.terminated(null,SIP.C.causes.REQUEST_TIMEOUT)}else if(this.status!==C.STATUS_TERMINATED){this.failed(null,SIP.C.causes.REQUEST_TIMEOUT);this.terminated(null,SIP.C.causes.REQUEST_TIMEOUT)}}};SIP.InviteServerContext=InviteServerContext;InviteClientContext=function(ua,target,options){options=Object.create(Session.desugar(options));options.params=Object.create(options.params||Object.prototype);var iceServers,extraHeaders=(options.extraHeaders||[]).slice(),stunServers=options.stunServers||null,turnServers=options.turnServers||null,mediaHandlerFactory=options.mediaHandlerFactory||ua.configuration.mediaHandlerFactory,isMediaSupported=mediaHandlerFactory.isSupported;if(isMediaSupported&&!isMediaSupported()){throw new SIP.Exceptions.NotSupportedError("Media not supported")}this.RTCConstraints=options.RTCConstraints||{};this.inviteWithoutSdp=options.inviteWithoutSdp||false;this.anonymous=options.anonymous||false;this.renderbody=options.renderbody||null;this.rendertype=options.rendertype||"text/plain";options.params.from_tag=this.from_tag;this.contact=ua.contact.toString({anonymous:this.anonymous,outbound:this.anonymous?!ua.contact.temp_gruu:!ua.contact.pub_gruu});if(this.anonymous){options.params.from_displayName="Anonymous";options.params.from_uri="sip:anonymous@anonymous.invalid";extraHeaders.push("P-Preferred-Identity: "+ua.configuration.uri.toString());extraHeaders.push("Privacy: id")}extraHeaders.push("Contact: "+this.contact);extraHeaders.push("Allow: "+SIP.UA.C.ALLOWED_METHODS.toString());if(this.inviteWithoutSdp&&this.renderbody){extraHeaders.push("Content-Type: "+this.rendertype);extraHeaders.push("Content-Disposition: render;handling=optional")}if(ua.configuration.rel100===SIP.C.supported.REQUIRED){extraHeaders.push("Require: 100rel")}if(ua.configuration.replaces===SIP.C.supported.REQUIRED){extraHeaders.push("Require: replaces")}
options.extraHeaders=extraHeaders;SIP.Utils.augment(this,SIP.ClientContext,[ua,SIP.C.INVITE,target,options]);SIP.Utils.augment(this,SIP.Session,[mediaHandlerFactory]);if(this.status!==C.STATUS_NULL){throw new SIP.Exceptions.InvalidStateError(this.status)}this.from_tag=SIP.Utils.newTag();this.isCanceled=false;this.received_100=false;this.method=SIP.C.INVITE;this.receiveNonInviteResponse=this.receiveResponse;this.receiveResponse=this.receiveInviteResponse;this.logger=ua.getLogger("sip.inviteclientcontext");if(stunServers){iceServers=SIP.UA.configuration_check.optional["stunServers"](stunServers);if(!iceServers){throw new TypeError("Invalid stunServers: "+stunServers)}else{this.stunServers=iceServers}}if(turnServers){iceServers=SIP.UA.configuration_check.optional["turnServers"](turnServers);if(!iceServers){throw new TypeError("Invalid turnServers: "+turnServers)}else{this.turnServers=iceServers}}ua.applicants[this]=this;this.id=this.request.call_id+this.from_tag;this.mediaHandler=this.mediaHandlerFactory(this,{RTCConstraints:this.RTCConstraints,stunServers:this.stunServers,turnServers:this.turnServers});if(this.mediaHandler&&this.mediaHandler.getRemoteStreams){this.getRemoteStreams=this.mediaHandler.getRemoteStreams.bind(this.mediaHandler);this.getLocalStreams=this.mediaHandler.getLocalStreams.bind(this.mediaHandler)}SIP.Utils.optionsOverride(options,"media","mediaConstraints",true,this.logger,this.ua.configuration.media);this.mediaHint=options.media;this.onInfo=options.onInfo};InviteClientContext.prototype={invite:function(){var self=this;this.ua.sessions[this.id]=this;if(this.inviteWithoutSdp){this.request.body=self.renderbody;this.status=C.STATUS_INVITE_SENT;this.send()}else{this.mediaHandler.getDescription(self.mediaHint).then(function onSuccess(description){if(self.isCanceled||self.status===C.STATUS_TERMINATED){return}self.hasOffer=true;self.request.body=description;self.status=C.STATUS_INVITE_SENT;self.send()},function onFailure(){if(self.status===C.STATUS_TERMINATED){return}self.failed(null,SIP.C.causes.WEBRTC_ERROR);self.terminated(null,SIP.C.causes.WEBRTC_ERROR)})}return this},receiveInviteResponse:function(response){var cause,session=this,id=response.call_id+response.from_tag+response.to_tag,extraHeaders=[],options={};if(this.status===C.STATUS_TERMINATED||response.method!==SIP.C.INVITE){return}if(this.dialog&&(response.status_code>=200&&response.status_code<=299)){if(id!==this.dialog.id.toString()){if(!this.createDialog(response,"UAC",true)){return}this.earlyDialogs[id].sendRequest(this,SIP.C.ACK,{body:SIP.Utils.generateFakeSDP(response.body)});this.earlyDialogs[id].sendRequest(this,SIP.C.BYE);if(this.status!==C.STATUS_CONFIRMED){this.failed(response,SIP.C.causes.WEBRTC_ERROR);this.terminated(response,SIP.C.causes.WEBRTC_ERROR)}return}else if(this.status===C.STATUS_CONFIRMED){this.sendRequest(SIP.C.ACK,{cseq:response.cseq});return}else if(!this.hasAnswer){return}}if(this.dialog&&response.status_code<200){if(this.dialog.pracked.indexOf(response.getHeader("rseq"))!==-1||this.dialog.pracked[this.dialog.pracked.length-1]>=response.getHeader("rseq")&&this.dialog.pracked.length>0){return}if(!this.earlyDialogs[id]&&!this.createDialog(response,"UAC",true)){return}if(this.earlyDialogs[id].pracked.indexOf(response.getHeader("rseq"))!==-1||this.earlyDialogs[id].pracked[this.earlyDialogs[id].pracked.length-1]>=response.getHeader("rseq")&&this.earlyDialogs[id].pracked.length>0){return}extraHeaders.push("RAck: "+response.getHeader("rseq")+" "+response.getHeader("cseq"));this.earlyDialogs[id].pracked.push(response.getHeader("rseq"));this.earlyDialogs[id].sendRequest(this,SIP.C.PRACK,{extraHeaders:extraHeaders,body:SIP.Utils.generateFakeSDP(response.body)});return}if(this.isCanceled){if(response.status_code>=100&&response.status_code<200){this.request.cancel(this.cancelReason,extraHeaders);this.canceled(null)}else if(response.status_code>=200&&response.status_code<299){this.acceptAndTerminate(response);this.emit("bye",this.request)}else if(response.status_code>=300){cause=SIP.C.REASON_PHRASE[response.status_code]||SIP.C.causes.CANCELED;this.rejected(response,cause);this.failed(response,cause);this.terminated(response,cause)}return}switch(true){case/^100$/.test(response.status_code):this.received_100=true;this.emit("progress",response);break;case/^1[0-9]{2}$/.test(response.status_code):if(!response.to_tag){this.logger.warn("1xx response received without to tag");break}if(response.hasHeader("contact")){if(!this.createDialog(response,"UAC",true)){break}}this.status=C.STATUS_1XX_RECEIVED;if(response.hasHeader("require")&&response.getHeader("require").indexOf("100rel")!==-1){if(this.dialog||!this.earlyDialogs[id]){break}if(this.earlyDialogs[id].pracked.indexOf(response.getHeader("rseq"))!==-1||this.earlyDialogs[id].pracked[this.earlyDialogs[id].pracked.length-1]>=response.getHeader("rseq")&&this.earlyDialogs[id].pracked.length>0){return}if(!this.mediaHandler.hasDescription(response)){extraHeaders.push("RAck: "+response.getHeader("rseq")+" "+response.getHeader("cseq"));this.earlyDialogs[id].pracked.push(response.getHeader("rseq"));this.earlyDialogs[id].sendRequest(this,SIP.C.PRACK,{extraHeaders:extraHeaders});this.emit("progress",response)}else if(this.hasOffer){if(!this.createDialog(response,"UAC")){break}this.hasAnswer=true;this.dialog.pracked.push(response.getHeader("rseq"));this.mediaHandler.setDescription(response).then(function onSuccess(){extraHeaders.push("RAck: "+response.getHeader("rseq")+" "+response.getHeader("cseq"));session.sendRequest(SIP.C.PRACK,{extraHeaders:extraHeaders,receiveResponse:function(){}});session.status=C.STATUS_EARLY_MEDIA;session.mute();session.emit("progress",response)},function onFailure(e){session.logger.warn(e);session.acceptAndTerminate(response,488,"Not Acceptable Here");session.failed(response,SIP.C.causes.BAD_MEDIA_DESCRIPTION)})}else{var earlyDialog=this.earlyDialogs[id];var earlyMedia=earlyDialog.mediaHandler;earlyDialog.pracked.push(response.getHeader("rseq"));earlyMedia.setDescription(response).then(earlyMedia.getDescription.bind(earlyMedia,session.mediaHint)).then(function onSuccess(description){extraHeaders.push("RAck: "+response.getHeader("rseq")+" "+response.getHeader("cseq"));earlyDialog.sendRequest(session,SIP.C.PRACK,{extraHeaders:extraHeaders,body:description});session.status=C.STATUS_EARLY_MEDIA;session.emit("progress",response)}).catch(function onFailure(e){if(e instanceof SIP.Exceptions.GetDescriptionError){earlyDialog.pracked.push(response.getHeader("rseq"));if(session.status===C.STATUS_TERMINATED){return}session.failed(null,SIP.C.causes.WEBRTC_ERROR);session.terminated(null,SIP.C.causes.WEBRTC_ERROR)}else{earlyDialog.pracked.splice(earlyDialog.pracked.indexOf(response.getHeader("rseq")),1);session.logger.warn("invalid description");session.logger.warn(e)}})}}else{this.emit("progress",response)}break;case/^2[0-9]{2}$/.test(response.status_code):var cseq=this.request.cseq+" "+this.request.method;if(cseq!==response.getHeader("cseq")){break}if(this.status===C.STATUS_EARLY_MEDIA&&this.dialog){this.status=C.STATUS_CONFIRMED;this.unmute();options={};if(this.renderbody){extraHeaders.push("Content-Type: "+this.rendertype);options.extraHeaders=extraHeaders;options.body=this.renderbody}options.cseq=response.cseq;this.sendRequest(SIP.C.ACK,options);this.accepted(response);break}if(this.dialog){break}if(!this.hasOffer){if(this.earlyDialogs[id]&&this.earlyDialogs[id].mediaHandler.localMedia){this.hasOffer=true;this.hasAnswer=true;this.mediaHandler=this.earlyDialogs[id].mediaHandler;if(!this.createDialog(response,"UAC")){break}this.status=C.STATUS_CONFIRMED;this.sendRequest(SIP.C.ACK,{cseq:response.cseq});this.unmute();this.accepted(response)}else{if(!this.mediaHandler.hasDescription(response)){this.acceptAndTerminate(response,400,"Missing session description");this.failed(response,SIP.C.causes.BAD_MEDIA_DESCRIPTION);break}if(!this.createDialog(response,"UAC")){break}this.hasOffer=true;this.mediaHandler.setDescription(response).then(this.mediaHandler.getDescription.bind(this.mediaHandler,this.mediaHint)).then(function onSuccess(description){if(session.isCanceled||session.status===C.STATUS_TERMINATED){return}session.status=C.STATUS_CONFIRMED;session.hasAnswer=true;session.unmute();session.sendRequest(SIP.C.ACK,{body:description,cseq:response.cseq});session.accepted(response)}).catch(function onFailure(e){if(e instanceof SIP.Exceptions.GetDescriptionError){session.logger.warn("there was a problem")}else{session.logger.warn("invalid description");session.logger.warn(e);response.reply(488)}})}}else if(this.hasAnswer){if(this.renderbody){extraHeaders.push("Content-Type: "+session.rendertype);options.extraHeaders=extraHeaders;options.body=this.renderbody}this.sendRequest(SIP.C.ACK,options)}else{if(!this.mediaHandler.hasDescription(response)){this.acceptAndTerminate(response,400,"Missing session description");this.failed(response,SIP.C.causes.BAD_MEDIA_DESCRIPTION);break}if(!this.createDialog(response,"UAC")){break}this.hasAnswer=true;this.mediaHandler.setDescription(response).then(function onSuccess(){var options={};session.status=C.STATUS_CONFIRMED;session.unmute();if(session.renderbody){extraHeaders.push("Content-Type: "+session.rendertype);options.extraHeaders=extraHeaders;options.body=session.renderbody}options.cseq=response.cseq;session.sendRequest(SIP.C.ACK,options);session.accepted(response)},function onFailure(e){session.logger.warn(e);session.acceptAndTerminate(response,488,"Not Acceptable Here");session.failed(response,SIP.C.causes.BAD_MEDIA_DESCRIPTION)})}break;default:cause=SIP.Utils.sipErrorCause(response.status_code);this.rejected(response,cause);this.failed(response,cause);this.terminated(response,cause)}},cancel:function(options){options=options||{};options.extraHeaders=(options.extraHeaders||[]).slice();if(this.status===C.STATUS_TERMINATED||this.status===C.STATUS_CONFIRMED){throw new SIP.Exceptions.InvalidStateError(this.status)}this.logger.log("canceling RTCSession");var cancel_reason=SIP.Utils.getCancelReason(options.status_code,options.reason_phrase);if(this.status===C.STATUS_NULL||this.status===C.STATUS_INVITE_SENT&&!this.received_100){this.isCanceled=true;this.cancelReason=cancel_reason}else if(this.status===C.STATUS_INVITE_SENT||this.status===C.STATUS_1XX_RECEIVED||this.status===C.STATUS_EARLY_MEDIA){this.request.cancel(cancel_reason,options.extraHeaders)}return this.canceled()},terminate:function(options){if(this.status===C.STATUS_TERMINATED){return this}if(this.status===C.STATUS_WAITING_FOR_ACK||this.status===C.STATUS_CONFIRMED){this.bye(options)}else{this.cancel(options)}return this},receiveRequest:function(request){if(request.method===SIP.C.CANCEL){}if(request.method===SIP.C.ACK&&this.status===C.STATUS_WAITING_FOR_ACK){SIP.Timers.clearTimeout(this.timers.ackTimer);SIP.Timers.clearTimeout(this.timers.invite2xxTimer);this.status=C.STATUS_CONFIRMED;this.unmute();this.accepted()}return Session.prototype.receiveRequest.apply(this,[request])},onTransportError:function(){if(this.status!==C.STATUS_CONFIRMED&&this.status!==C.STATUS_TERMINATED){this.failed(null,SIP.C.causes.CONNECTION_ERROR)}},onRequestTimeout:function(){if(this.status===C.STATUS_CONFIRMED){this.terminated(null,SIP.C.causes.REQUEST_TIMEOUT)}else if(this.status!==C.STATUS_TERMINATED){this.failed(null,SIP.C.causes.REQUEST_TIMEOUT);this.terminated(null,SIP.C.causes.REQUEST_TIMEOUT)}}};SIP.InviteClientContext=InviteClientContext}},{"./RFC4028":74,"./Session/DTMF":82}],82:[function(require,module,exports){"use strict";module.exports=function(SIP){var DTMF,C={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};DTMF=function(session,tone,options){var duration,interToneGap;if(tone===undefined){throw new TypeError("Not enough arguments")}this.logger=session.ua.getLogger("sip.invitecontext.dtmf",session.id);this.owner=session;this.direction=null;options=options||{};duration=options.duration||null;interToneGap=options.interToneGap||null;if(typeof tone==="string"){tone=tone.toUpperCase()}else if(typeof tone==="number"){tone=tone.toString()}else{throw new TypeError("Invalid tone: "+tone)}if(!tone.match(/^[0-9A-D#*]$/)){throw new TypeError("Invalid tone: "+tone)}else{this.tone=tone}if(duration&&!SIP.Utils.isDecimal(duration)){throw new TypeError("Invalid tone duration: "+duration)}else if(!duration){duration=DTMF.C.DEFAULT_DURATION}else if(duration<DTMF.C.MIN_DURATION){this.logger.warn('"duration" value is lower than the minimum allowed, setting it to '+DTMF.C.MIN_DURATION+" milliseconds");duration=DTMF.C.MIN_DURATION}else if(duration>DTMF.C.MAX_DURATION){this.logger.warn('"duration" value is greater than the maximum allowed, setting it to '+DTMF.C.MAX_DURATION+" milliseconds");duration=DTMF.C.MAX_DURATION}else{duration=Math.abs(duration)}this.duration=duration;if(interToneGap&&!SIP.Utils.isDecimal(interToneGap)){throw new TypeError("Invalid interToneGap: "+interToneGap)}else if(!interToneGap){interToneGap=DTMF.C.DEFAULT_INTER_TONE_GAP}else if(interToneGap<DTMF.C.MIN_INTER_TONE_GAP){this.logger.warn('"interToneGap" value is lower than the minimum allowed, setting it to '+DTMF.C.MIN_INTER_TONE_GAP+" milliseconds");interToneGap=DTMF.C.MIN_INTER_TONE_GAP}else{interToneGap=Math.abs(interToneGap)}this.interToneGap=interToneGap};DTMF.prototype=Object.create(SIP.EventEmitter.prototype);DTMF.prototype.send=function(options){var extraHeaders,body={};this.direction="outgoing";if(this.owner.status!==SIP.Session.C.STATUS_CONFIRMED&&this.owner.status!==SIP.Session.C.STATUS_WAITING_FOR_ACK){throw new SIP.Exceptions.InvalidStateError(this.owner.status)}options=options||{};extraHeaders=options.extraHeaders?options.extraHeaders.slice():[];body.contentType="application/dtmf-relay";body.body="Signal= "+this.tone+"\r\n";body.body+="Duration= "+this.duration;this.request=this.owner.dialog.sendRequest(this,SIP.C.INFO,{extraHeaders:extraHeaders,body:body});this.owner.emit("dtmf",this.request,this)};DTMF.prototype.receiveResponse=function(response){var cause;switch(true){case/^1[0-9]{2}$/.test(response.status_code):break;case/^2[0-9]{2}$/.test(response.status_code):this.emit("succeeded",{originator:"remote",response:response});break;default:cause=SIP.Utils.sipErrorCause(response.status_code);this.emit("failed",response,cause);break}};DTMF.prototype.onRequestTimeout=function(){this.emit("failed",null,SIP.C.causes.REQUEST_TIMEOUT);this.owner.onRequestTimeout()};DTMF.prototype.onTransportError=function(){this.emit("failed",null,SIP.C.causes.CONNECTION_ERROR);this.owner.onTransportError()};DTMF.prototype.onDialogError=function(response){this.emit("failed",response,SIP.C.causes.DIALOG_ERROR);this.owner.onDialogError(response)};DTMF.prototype.init_incoming=function(request){this.direction="incoming";this.request=request;request.reply(200);if(!this.tone||!this.duration){this.logger.warn("invalid INFO DTMF received, discarded")}else{this.owner.emit("dtmf",request,this)}};DTMF.C=C;return DTMF}},{}],83:[function(require,module,exports){"use strict";module.exports=function(SIP){SIP.Subscription=function(ua,target,event,options){options=Object.create(options||Object.prototype);this.extraHeaders=options.extraHeaders=(options.extraHeaders||[]).slice();this.id=null;this.state="init";if(!event){throw new TypeError("Event necessary to create a subscription.")}else{this.event=event}if(typeof options.expires!=="number"){ua.logger.warn("expires must be a number. Using default of 3600.");this.expires=3600}else{this.expires=options.expires}options.extraHeaders.push("Event: "+this.event);options.extraHeaders.push("Expires: "+this.expires);if(options.body){this.body=options.body}this.contact=ua.contact.toString();options.extraHeaders.push("Contact: "+this.contact);options.extraHeaders.push("Allow: "+SIP.UA.C.ALLOWED_METHODS.toString());SIP.Utils.augment(this,SIP.ClientContext,[ua,SIP.C.SUBSCRIBE,target,options]);this.logger=ua.getLogger("sip.subscription");this.dialog=null;this.timers={N:null,sub_duration:null};this.errorCodes=[404,405,410,416,480,481,482,483,484,485,489,501,604]};SIP.Subscription.prototype={subscribe:function(){var sub=this;if(this.state==="active"){this.refresh();return this}else if(this.state==="notify_wait"){return this}SIP.Timers.clearTimeout(this.timers.sub_duration);SIP.Timers.clearTimeout(this.timers.N);this.timers.N=SIP.Timers.setTimeout(sub.timer_fire.bind(sub),SIP.Timers.TIMER_N);this.send();this.state="notify_wait";return this},refresh:function(){if(this.state==="terminated"||this.state==="pending"||this.state==="notify_wait"){return}this.dialog.sendRequest(this,SIP.C.SUBSCRIBE,{extraHeaders:this.extraHeaders,body:this.body})},receiveResponse:function(response){var expires,sub=this,cause=SIP.Utils.getReasonPhrase(response.status_code);if(this.state==="notify_wait"&&response.status_code>=300||this.state!=="notify_wait"&&this.errorCodes.indexOf(response.status_code)!==-1){this.failed(response,null)}else if(/^2[0-9]{2}$/.test(response.status_code)){expires=response.getHeader("Expires");SIP.Timers.clearTimeout(this.timers.N);if(this.createConfirmedDialog(response,"UAC")){this.id=this.dialog.id.toString();this.ua.subscriptions[this.id]=this;this.emit("accepted",response,cause)}if(expires&&expires<=this.expires){this.expires=expires;this.timers.sub_duration=SIP.Timers.setTimeout(sub.refresh.bind(sub),expires*900)}else{if(!expires){this.logger.warn("Expires header missing in a 200-class response to SUBSCRIBE");this.failed(response,SIP.C.EXPIRES_HEADER_MISSING)}else{this.logger.warn("Expires header in a 200-class response to SUBSCRIBE with a higher value than the one in the request");this.failed(response,SIP.C.INVALID_EXPIRES_HEADER)}}}},unsubscribe:function(){var extraHeaders=[],sub=this;this.state="terminated";extraHeaders.push("Event: "+this.event);extraHeaders.push("Expires: 0");extraHeaders.push("Contact: "+this.contact);extraHeaders.push("Allow: "+SIP.UA.C.ALLOWED_METHODS.toString());this.receiveResponse=function(){};this.dialog.sendRequest(this,this.method,{extraHeaders:extraHeaders,body:this.body});SIP.Timers.clearTimeout(this.timers.sub_duration);SIP.Timers.clearTimeout(this.timers.N);this.timers.N=SIP.Timers.setTimeout(sub.timer_fire.bind(sub),SIP.Timers.TIMER_N)},timer_fire:function(){if(this.state==="terminated"){this.terminateDialog();SIP.Timers.clearTimeout(this.timers.N);SIP.Timers.clearTimeout(this.timers.sub_duration);delete this.ua.subscriptions[this.id]}else if(this.state==="pending"||this.state==="notify_wait"){this.close()}else{this.refresh()}},close:function(){if(this.state!=="notify_wait"&&this.state!=="terminated"){this.unsubscribe()}},createConfirmedDialog:function(message,type){var dialog;this.terminateDialog();dialog=new SIP.Dialog(this,message,type);if(!dialog.error){this.dialog=dialog;return true}else{return false}},terminateDialog:function(){if(this.dialog){delete this.ua.subscriptions[this.id];this.dialog.terminate();delete this.dialog}},receiveRequest:function(request){var sub_state,sub=this;function setExpiresTimeout(){if(sub_state.expires){SIP.Timers.clearTimeout(sub.timers.sub_duration);sub_state.expires=Math.min(sub.expires,Math.max(sub_state.expires,0));sub.timers.sub_duration=SIP.Timers.setTimeout(sub.refresh.bind(sub),sub_state.expires*900)}}if(!this.matchEvent(request)){request.reply(489);return}sub_state=request.parseHeader("Subscription-State");request.reply(200,SIP.C.REASON_200);SIP.Timers.clearTimeout(this.timers.N);this.emit("notify",{request:request});if(this.state==="terminated"){if(sub_state.state==="terminated"){this.terminateDialog();SIP.Timers.clearTimeout(this.timers.N);SIP.Timers.clearTimeout(this.timers.sub_duration);delete this.ua.subscriptions[this.id]}return}switch(sub_state.state){case"active":this.state="active";setExpiresTimeout();break;case"pending":if(this.state==="notify_wait"){setExpiresTimeout()}this.state="pending";break;case"terminated":SIP.Timers.clearTimeout(this.timers.sub_duration);if(sub_state.reason){this.logger.log("terminating subscription with reason "+sub_state.reason);switch(sub_state.reason){case"deactivated":case"timeout":this.subscribe();return;case"probation":case"giveup":if(sub_state.params&&sub_state.params["retry-after"]){this.timers.sub_duration=SIP.Timers.setTimeout(sub.subscribe.bind(sub),sub_state.params["retry-after"])}else{this.subscribe()}return;case"rejected":case"noresource":case"invariant":break}}this.close();break}},failed:function(response,cause){this.close();this.emit("failed",response,cause);return this},onDialogError:function(response){this.failed(response,SIP.C.causes.DIALOG_ERROR)},matchEvent:function(request){var event;if(!request.hasHeader("Event")){this.logger.warn("missing Event header");return false}if(!request.hasHeader("Subscription-State")){this.logger.warn("missing Subscription-State header");return false}event=request.parseHeader("event").event;if(this.event!==event){this.logger.warn("event match failed");request.reply(481,"Event Match Failed");return false}else{return true}}}}},{}],84:[function(require,module,exports){"use strict";var T1=500,T2=4e3,T4=5e3;module.exports=function(timers){var Timers={T1:T1,T2:T2,T4:T4,TIMER_B:64*T1,TIMER_D:0*T1,TIMER_F:64*T1,TIMER_H:64*T1,TIMER_I:0*T1,TIMER_J:0*T1,TIMER_K:0*T4,TIMER_L:64*T1,TIMER_M:64*T1,TIMER_N:64*T1,PROVISIONAL_RESPONSE_INTERVAL:6e4};["setTimeout","clearTimeout","setInterval","clearInterval"].forEach(function(name){Timers[name]=function(){return timers[name].apply(timers,arguments)}});return Timers}},{}],85:[function(require,module,exports){"use strict";module.exports=function(SIP){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"};function buildViaHeader(request_sender,transport,id){var via;via="SIP/2.0/"+(request_sender.ua.configuration.hackViaTcp?"TCP":transport.server.scheme);via+=" "+request_sender.ua.configuration.viaHost+";branch="+id;if(request_sender.ua.configuration.forceRport){via+=";rport"}return via}var NonInviteClientTransaction=function(request_sender,request,transport){var via;this.type=C.NON_INVITE_CLIENT;this.transport=transport;this.id="z9hG4bK"+Math.floor(Math.random()*1e7);this.request_sender=request_sender;this.request=request;this.logger=request_sender.ua.getLogger("sip.transaction.nict",this.id);via=buildViaHeader(request_sender,transport,this.id);this.request.setHeader("via",via);this.request_sender.ua.newTransaction(this)};NonInviteClientTransaction.prototype=Object.create(SIP.EventEmitter.prototype);NonInviteClientTransaction.prototype.stateChanged=function(state){this.state=state;this.emit("stateChanged")};NonInviteClientTransaction.prototype.send=function(){var tr=this;this.stateChanged(C.STATUS_TRYING);this.F=SIP.Timers.setTimeout(tr.timer_F.bind(tr),SIP.Timers.TIMER_F);if(!this.transport.send(this.request)){this.onTransportError()}};NonInviteClientTransaction.prototype.onTransportError=function(){this.logger.log("transport error occurred, deleting non-INVITE client transaction "+this.id);SIP.Timers.clearTimeout(this.F);SIP.Timers.clearTimeout(this.K);this.stateChanged(C.STATUS_TERMINATED);this.request_sender.ua.destroyTransaction(this);this.request_sender.onTransportError()};NonInviteClientTransaction.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()};NonInviteClientTransaction.prototype.timer_K=function(){this.stateChanged(C.STATUS_TERMINATED);this.request_sender.ua.destroyTransaction(this)};NonInviteClientTransaction.prototype.receiveResponse=function(response){var tr=this,status_code=response.status_code;if(status_code<200){switch(this.state){case C.STATUS_TRYING:case C.STATUS_PROCEEDING:this.stateChanged(C.STATUS_PROCEEDING);this.request_sender.receiveResponse(response);break}}else{switch(this.state){case C.STATUS_TRYING:case C.STATUS_PROCEEDING:this.stateChanged(C.STATUS_COMPLETED);SIP.Timers.clearTimeout(this.F);if(status_code===408){this.request_sender.onRequestTimeout()}else{this.request_sender.receiveResponse(response)}this.K=SIP.Timers.setTimeout(tr.timer_K.bind(tr),SIP.Timers.TIMER_K);break;case C.STATUS_COMPLETED:break}}};var InviteClientTransaction=function(request_sender,request,transport){var via,tr=this;this.type=C.INVITE_CLIENT;this.transport=transport;this.id="z9hG4bK"+Math.floor(Math.random()*1e7);this.request_sender=request_sender;this.request=request;this.logger=request_sender.ua.getLogger("sip.transaction.ict",this.id);via=buildViaHeader(request_sender,transport,this.id);this.request.setHeader("via",via);this.request_sender.ua.newTransaction(this);this.request.cancel=function(reason,extraHeaders){extraHeaders=(extraHeaders||[]).slice();var length=extraHeaders.length;var extraHeadersString=null;for(var idx=0;idx<length;idx++){extraHeadersString=(extraHeadersString||"")+extraHeaders[idx].trim()+"\r\n"}tr.cancel_request(tr,reason,extraHeadersString)}};InviteClientTransaction.prototype=Object.create(SIP.EventEmitter.prototype);InviteClientTransaction.prototype.stateChanged=function(state){this.state=state;this.emit("stateChanged")};InviteClientTransaction.prototype.send=function(){var tr=this;this.stateChanged(C.STATUS_CALLING);this.B=SIP.Timers.setTimeout(tr.timer_B.bind(tr),SIP.Timers.TIMER_B);if(!this.transport.send(this.request)){this.onTransportError()}};InviteClientTransaction.prototype.onTransportError=function(){this.logger.log("transport error occurred, deleting INVITE client transaction "+this.id);SIP.Timers.clearTimeout(this.B);SIP.Timers.clearTimeout(this.D);SIP.Timers.clearTimeout(this.M);this.stateChanged(C.STATUS_TERMINATED);this.request_sender.ua.destroyTransaction(this);if(this.state!==C.STATUS_ACCEPTED){this.request_sender.onTransportError()}};InviteClientTransaction.prototype.timer_M=function(){this.logger.log("Timer M expired for INVITE client transaction "+this.id);if(this.state===C.STATUS_ACCEPTED){SIP.Timers.clearTimeout(this.B);this.stateChanged(C.STATUS_TERMINATED);this.request_sender.ua.destroyTransaction(this)}};InviteClientTransaction.prototype.timer_B=function(){this.logger.log("Timer B expired for INVITE client transaction "+this.id);if(this.state===C.STATUS_CALLING){this.stateChanged(C.STATUS_TERMINATED);this.request_sender.ua.destroyTransaction(this);this.request_sender.onRequestTimeout()}};InviteClientTransaction.prototype.timer_D=function(){this.logger.log("Timer D expired for INVITE client transaction "+this.id);SIP.Timers.clearTimeout(this.B);this.stateChanged(C.STATUS_TERMINATED);this.request_sender.ua.destroyTransaction(this)};InviteClientTransaction.prototype.sendACK=function(response){var tr=this;this.ack="ACK "+this.request.ruri+" SIP/2.0\r\n";this.ack+="Via: "+this.request.headers["Via"].toString()+"\r\n";if(this.request.headers["Route"]){this.ack+="Route: "+this.request.headers["Route"].toString()+"\r\n"}this.ack+="To: "+response.getHeader("to")+"\r\n";this.ack+="From: "+this.request.headers["From"].toString()+"\r\n";this.ack+="Call-ID: "+this.request.headers["Call-ID"].toString()+"\r\n";this.ack+="Content-Length: 0\r\n";this.ack+="CSeq: "+this.request.headers["CSeq"].toString().split(" ")[0];this.ack+=" ACK\r\n\r\n";this.D=SIP.Timers.setTimeout(tr.timer_D.bind(tr),SIP.Timers.TIMER_D);this.transport.send(this.ack)};InviteClientTransaction.prototype.cancel_request=function(tr,reason,extraHeaders){var request=tr.request;this.cancel=SIP.C.CANCEL+" "+request.ruri+" SIP/2.0\r\n";this.cancel+="Via: "+request.headers["Via"].toString()+"\r\n";if(this.request.headers["Route"]){this.cancel+="Route: "+request.headers["Route"].toString()+"\r\n"}this.cancel+="To: "+request.headers["To"].toString()+"\r\n";this.cancel+="From: "+request.headers["From"].toString()+"\r\n";this.cancel+="Call-ID: "+request.headers["Call-ID"].toString()+"\r\n";this.cancel+="CSeq: "+request.headers["CSeq"].toString().split(" ")[0]+" CANCEL\r\n";if(reason){this.cancel+="Reason: "+reason+"\r\n"}if(extraHeaders){this.cancel+=extraHeaders}this.cancel+="Content-Length: 0\r\n\r\n";if(this.state===C.STATUS_PROCEEDING){this.transport.send(this.cancel)}};InviteClientTransaction.prototype.receiveResponse=function(response){var tr=this,status_code=response.status_code;if(status_code>=100&&status_code<=199){switch(this.state){case C.STATUS_CALLING:this.stateChanged(C.STATUS_PROCEEDING);this.request_sender.receiveResponse(response);if(this.cancel){this.transport.send(this.cancel)}break;case C.STATUS_PROCEEDING:this.request_sender.receiveResponse(response);break}}else if(status_code>=200&&status_code<=299){switch(this.state){case C.STATUS_CALLING:case C.STATUS_PROCEEDING:this.stateChanged(C.STATUS_ACCEPTED);this.M=SIP.Timers.setTimeout(tr.timer_M.bind(tr),SIP.Timers.TIMER_M);this.request_sender.receiveResponse(response);break;case C.STATUS_ACCEPTED:this.request_sender.receiveResponse(response);break}}else if(status_code>=300&&status_code<=699){switch(this.state){case C.STATUS_CALLING:case C.STATUS_PROCEEDING:this.stateChanged(C.STATUS_COMPLETED);this.sendACK(response);this.request_sender.receiveResponse(response);break;case C.STATUS_COMPLETED:this.sendACK(response);break}}};var AckClientTransaction=function(request_sender,request,transport){var via;this.transport=transport;this.id="z9hG4bK"+Math.floor(Math.random()*1e7);this.request_sender=request_sender;this.request=request;this.logger=request_sender.ua.getLogger("sip.transaction.nict",this.id);via=buildViaHeader(request_sender,transport,this.id);this.request.setHeader("via",via)};AckClientTransaction.prototype=Object.create(SIP.EventEmitter.prototype);AckClientTransaction.prototype.send=function(){if(!this.transport.send(this.request)){this.onTransportError()}};AckClientTransaction.prototype.onTransportError=function(){this.logger.log("transport error occurred, for an ACK client transaction "+this.id);this.request_sender.onTransportError()};var NonInviteServerTransaction=function(request,ua){this.type=C.NON_INVITE_SERVER;this.id=request.via_branch;this.request=request;this.transport=request.transport;this.ua=ua;this.last_response="";request.server_transaction=this;this.logger=ua.getLogger("sip.transaction.nist",this.id);this.state=C.STATUS_TRYING;ua.newTransaction(this)};NonInviteServerTransaction.prototype=Object.create(SIP.EventEmitter.prototype);NonInviteServerTransaction.prototype.stateChanged=function(state){this.state=state;this.emit("stateChanged")};NonInviteServerTransaction.prototype.timer_J=function(){this.logger.log("Timer J expired for non-INVITE server transaction "+this.id);this.stateChanged(C.STATUS_TERMINATED);this.ua.destroyTransaction(this)};NonInviteServerTransaction.prototype.onTransportError=function(){if(!this.transportError){this.transportError=true;this.logger.log("transport error occurred, deleting non-INVITE server transaction "+this.id);SIP.Timers.clearTimeout(this.J);this.stateChanged(C.STATUS_TERMINATED);this.ua.destroyTransaction(this)}};NonInviteServerTransaction.prototype.receiveResponse=function(status_code,response){var tr=this;var deferred=SIP.Utils.defer();if(status_code===100){switch(this.state){case C.STATUS_TRYING:this.stateChanged(C.STATUS_PROCEEDING);if(!this.transport.send(response)){this.onTransportError()}break;case C.STATUS_PROCEEDING:this.last_response=response;if(!this.transport.send(response)){this.onTransportError();deferred.reject()}else{deferred.resolve()}break}}else if(status_code>=200&&status_code<=699){switch(this.state){case C.STATUS_TRYING:case C.STATUS_PROCEEDING:this.stateChanged(C.STATUS_COMPLETED);this.last_response=response;this.J=SIP.Timers.setTimeout(tr.timer_J.bind(tr),SIP.Timers.TIMER_J);if(!this.transport.send(response)){this.onTransportError();deferred.reject()}else{deferred.resolve()}break;case C.STATUS_COMPLETED:break}}return deferred.promise};var InviteServerTransaction=function(request,ua){
this.type=C.INVITE_SERVER;this.id=request.via_branch;this.request=request;this.transport=request.transport;this.ua=ua;this.last_response="";request.server_transaction=this;this.logger=ua.getLogger("sip.transaction.ist",this.id);this.state=C.STATUS_PROCEEDING;ua.newTransaction(this);this.resendProvisionalTimer=null;request.reply(100)};InviteServerTransaction.prototype=Object.create(SIP.EventEmitter.prototype);InviteServerTransaction.prototype.stateChanged=function(state){this.state=state;this.emit("stateChanged")};InviteServerTransaction.prototype.timer_H=function(){this.logger.log("Timer H expired for INVITE server transaction "+this.id);if(this.state===C.STATUS_COMPLETED){this.logger.warn("transactions","ACK for INVITE server transaction was never received, call will be terminated")}this.stateChanged(C.STATUS_TERMINATED);this.ua.destroyTransaction(this)};InviteServerTransaction.prototype.timer_I=function(){this.stateChanged(C.STATUS_TERMINATED);this.ua.destroyTransaction(this)};InviteServerTransaction.prototype.timer_L=function(){this.logger.log("Timer L expired for INVITE server transaction "+this.id);if(this.state===C.STATUS_ACCEPTED){this.stateChanged(C.STATUS_TERMINATED);this.ua.destroyTransaction(this)}};InviteServerTransaction.prototype.onTransportError=function(){if(!this.transportError){this.transportError=true;this.logger.log("transport error occurred, deleting INVITE server transaction "+this.id);if(this.resendProvisionalTimer!==null){SIP.Timers.clearInterval(this.resendProvisionalTimer);this.resendProvisionalTimer=null}SIP.Timers.clearTimeout(this.L);SIP.Timers.clearTimeout(this.H);SIP.Timers.clearTimeout(this.I);this.stateChanged(C.STATUS_TERMINATED);this.ua.destroyTransaction(this)}};InviteServerTransaction.prototype.resend_provisional=function(){if(!this.transport.send(this.last_response)){this.onTransportError()}};InviteServerTransaction.prototype.receiveResponse=function(status_code,response){var tr=this;var deferred=SIP.Utils.defer();if(status_code>=100&&status_code<=199){switch(this.state){case C.STATUS_PROCEEDING:if(!this.transport.send(response)){this.onTransportError()}this.last_response=response;break}}if(status_code>100&&status_code<=199&&this.state===C.STATUS_PROCEEDING){if(this.resendProvisionalTimer===null){this.resendProvisionalTimer=SIP.Timers.setInterval(tr.resend_provisional.bind(tr),SIP.Timers.PROVISIONAL_RESPONSE_INTERVAL)}}else if(status_code>=200&&status_code<=299){switch(this.state){case C.STATUS_PROCEEDING:this.stateChanged(C.STATUS_ACCEPTED);this.last_response=response;this.L=SIP.Timers.setTimeout(tr.timer_L.bind(tr),SIP.Timers.TIMER_L);if(this.resendProvisionalTimer!==null){SIP.Timers.clearInterval(this.resendProvisionalTimer);this.resendProvisionalTimer=null}case C.STATUS_ACCEPTED:if(!this.transport.send(response)){this.onTransportError();deferred.reject()}else{deferred.resolve()}break}}else if(status_code>=300&&status_code<=699){switch(this.state){case C.STATUS_PROCEEDING:if(this.resendProvisionalTimer!==null){SIP.Timers.clearInterval(this.resendProvisionalTimer);this.resendProvisionalTimer=null}if(!this.transport.send(response)){this.onTransportError();deferred.reject()}else{this.stateChanged(C.STATUS_COMPLETED);this.H=SIP.Timers.setTimeout(tr.timer_H.bind(tr),SIP.Timers.TIMER_H);deferred.resolve()}break}}return deferred.promise};var checkTransaction=function(ua,request){var tr;switch(request.method){case SIP.C.INVITE:tr=ua.transactions.ist[request.via_branch];if(tr){switch(tr.state){case C.STATUS_PROCEEDING:tr.transport.send(tr.last_response);break;case C.STATUS_ACCEPTED:break}return true}break;case SIP.C.ACK:tr=ua.transactions.ist[request.via_branch];if(tr){if(tr.state===C.STATUS_ACCEPTED){return false}else if(tr.state===C.STATUS_COMPLETED){tr.stateChanged(C.STATUS_CONFIRMED);tr.I=SIP.Timers.setTimeout(tr.timer_I.bind(tr),SIP.Timers.TIMER_I);return true}}else{return false}break;case SIP.C.CANCEL:tr=ua.transactions.ist[request.via_branch];if(tr){request.reply_sl(200);if(tr.state===C.STATUS_PROCEEDING){return false}else{return true}}else{request.reply_sl(481);return true}break;default:tr=ua.transactions.nist[request.via_branch];if(tr){switch(tr.state){case C.STATUS_TRYING:break;case C.STATUS_PROCEEDING:case C.STATUS_COMPLETED:tr.transport.send(tr.last_response);break}return true}break}};SIP.Transactions={C:C,checkTransaction:checkTransaction,NonInviteClientTransaction:NonInviteClientTransaction,InviteClientTransaction:InviteClientTransaction,AckClientTransaction:AckClientTransaction,NonInviteServerTransaction:NonInviteServerTransaction,InviteServerTransaction:InviteServerTransaction}}},{}],86:[function(require,module,exports){"use strict";module.exports=function(SIP,WebSocket){var Transport,C={STATUS_READY:0,STATUS_DISCONNECTED:1,STATUS_ERROR:2};function computeKeepAliveTimeout(upperBound){var lowerBound=upperBound*.8;return 1e3*(Math.random()*(upperBound-lowerBound)+lowerBound)}Transport=function(ua,server){this.logger=ua.getLogger("sip.transport");this.ua=ua;this.ws=null;this.server=server;this.reconnection_attempts=0;this.closed=false;this.connected=false;this.reconnectTimer=null;this.lastTransportError={};this.keepAliveInterval=ua.configuration.keepAliveInterval;this.keepAliveTimeout=null;this.keepAliveTimer=null;this.ua.transport=this;this.connect()};Transport.prototype={send:function(msg){var message=msg.toString();if(this.ws&&this.ws.readyState===WebSocket.OPEN){if(this.ua.configuration.traceSip===true){this.logger.log("sending WebSocket message:\n\n"+message+"\n")}this.ws.send(message);return true}else{this.logger.warn("unable to send message, WebSocket is not open");return false}},sendKeepAlive:function(){if(this.keepAliveTimeout){return}this.keepAliveTimeout=SIP.Timers.setTimeout(function(){this.ua.emit("keepAliveTimeout")}.bind(this),1e4);return this.send("\r\n\r\n")},startSendingKeepAlives:function(){if(this.keepAliveInterval&&!this.keepAliveTimer){this.keepAliveTimer=SIP.Timers.setTimeout(function(){this.sendKeepAlive();this.keepAliveTimer=null;this.startSendingKeepAlives()}.bind(this),computeKeepAliveTimeout(this.keepAliveInterval))}},stopSendingKeepAlives:function(){SIP.Timers.clearTimeout(this.keepAliveTimer);SIP.Timers.clearTimeout(this.keepAliveTimeout);this.keepAliveTimer=null;this.keepAliveTimeout=null},disconnect:function(){if(this.ws){SIP.Timers.clearTimeout(this.reconnectTimer);this.stopSendingKeepAlives();this.closed=true;this.logger.log("closing WebSocket "+this.server.ws_uri);this.ws.close()}if(this.reconnectTimer!==null){SIP.Timers.clearTimeout(this.reconnectTimer);this.reconnectTimer=null;this.ua.emit("disconnected",{transport:this,code:this.lastTransportError.code,reason:this.lastTransportError.reason})}},connect:function(){var transport=this;if(this.ws&&(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING)){this.logger.log("WebSocket "+this.server.ws_uri+" is already connected");return false}if(this.ws){this.ws.close()}this.logger.log("connecting to WebSocket "+this.server.ws_uri);this.ua.onTransportConnecting(this,this.reconnection_attempts===0?1:this.reconnection_attempts);try{this.ws=new WebSocket(this.server.ws_uri,"sip")}catch(e){this.logger.warn("error connecting to WebSocket "+this.server.ws_uri+": "+e)}this.ws.binaryType="arraybuffer";this.ws.onopen=function(){transport.onOpen()};this.ws.onclose=function(e){transport.onClose(e)};this.ws.onmessage=function(e){transport.onMessage(e)};this.ws.onerror=function(e){transport.onError(e)}},onOpen:function(){this.connected=true;this.logger.log("WebSocket "+this.server.ws_uri+" connected");if(this.reconnectTimer!==null){SIP.Timers.clearTimeout(this.reconnectTimer);this.reconnectTimer=null}this.reconnection_attempts=0;this.closed=false;this.ua.onTransportConnected(this);this.startSendingKeepAlives()},onClose:function(e){var connected_before=this.connected;this.lastTransportError.code=e.code;this.lastTransportError.reason=e.reason;this.stopSendingKeepAlives();if(this.reconnection_attempts>0){this.logger.log("Reconnection attempt "+this.reconnection_attempts+" failed (code: "+e.code+(e.reason?"| reason: "+e.reason:"")+")");this.reconnect()}else{this.connected=false;this.logger.log("WebSocket disconnected (code: "+e.code+(e.reason?"| reason: "+e.reason:"")+")");if(e.wasClean===false){this.logger.warn("WebSocket abrupt disconnection")}if(connected_before===true){this.ua.onTransportClosed(this);if(!this.closed){this.reconnect()}else{this.ua.emit("disconnected",{transport:this,code:this.lastTransportError.code,reason:this.lastTransportError.reason})}}else{this.ua.onTransportError(this)}}},onMessage:function(e){var message,transaction,data=e.data;if(data==="\r\n"){SIP.Timers.clearTimeout(this.keepAliveTimeout);this.keepAliveTimeout=null;if(this.ua.configuration.traceSip===true){this.logger.log("received WebSocket message with CRLF Keep Alive response")}return}else if(typeof data!=="string"){try{data=String.fromCharCode.apply(null,new Uint8Array(data))}catch(evt){this.logger.warn("received WebSocket binary message failed to be converted into string, message discarded");return}if(this.ua.configuration.traceSip===true){this.logger.log("received WebSocket binary message:\n\n"+data+"\n")}}else{if(this.ua.configuration.traceSip===true){this.logger.log("received WebSocket text message:\n\n"+data+"\n")}}message=SIP.Parser.parseMessage(data,this.ua);if(!message){return}if(this.ua.status===SIP.UA.C.STATUS_USER_CLOSED&&message instanceof SIP.IncomingRequest){return}if(SIP.sanityCheck(message,this.ua,this)){if(message instanceof SIP.IncomingRequest){message.transport=this;this.ua.receiveRequest(message)}else if(message instanceof SIP.IncomingResponse){switch(message.method){case SIP.C.INVITE:transaction=this.ua.transactions.ict[message.via_branch];if(transaction){transaction.receiveResponse(message)}break;case SIP.C.ACK:break;default:transaction=this.ua.transactions.nict[message.via_branch];if(transaction){transaction.receiveResponse(message)}break}}}},onError:function(e){this.logger.warn("WebSocket connection error: "+JSON.stringify(e))},reconnect:function(){var transport=this;this.reconnection_attempts+=1;if(this.reconnection_attempts>this.ua.configuration.wsServerMaxReconnection){this.logger.warn("maximum reconnection attempts for WebSocket "+this.server.ws_uri);this.ua.onTransportError(this)}else if(this.reconnection_attempts===1){this.logger.log("Connection to WebSocket "+this.server.ws_uri+" severed, attempting first reconnect");transport.connect()}else{this.logger.log("trying to reconnect to WebSocket "+this.server.ws_uri+" (reconnection attempt "+this.reconnection_attempts+")");this.reconnectTimer=SIP.Timers.setTimeout(function(){transport.connect();transport.reconnectTimer=null},this.ua.configuration.wsServerReconnectionTimeout*1e3)}}};Transport.C=C;return Transport}},{}],87:[function(require,module,exports){(function(global){"use strict";module.exports=function(SIP,environment){var UA,C={STATUS_INIT:0,STATUS_STARTING:1,STATUS_READY:2,STATUS_USER_CLOSED:3,STATUS_NOT_READY:4,CONFIGURATION_ERROR:1,NETWORK_ERROR:2,ALLOWED_METHODS:["ACK","CANCEL","INVITE","MESSAGE","BYE","OPTIONS","INFO","NOTIFY","REFER"],ACCEPTED_BODY_TYPES:["application/sdp","application/dtmf-relay"],MAX_FORWARDS:70,TAG_LENGTH:10};UA=function(configuration){var self=this;function selfEmit(type){return self.emit.bind(self,type)}C.ACCEPTED_BODY_TYPES=C.ACCEPTED_BODY_TYPES.toString();this.log=new SIP.LoggerFactory;this.logger=this.getLogger("sip.ua");this.cache={credentials:{}};this.configuration={};this.dialogs={};this.applicants={};this.data={};this.sessions={};this.subscriptions={};this.transport=null;this.contact=null;this.status=C.STATUS_INIT;this.error=null;this.transactions={nist:{},nict:{},ist:{},ict:{}};this.transportRecoverAttempts=0;this.transportRecoveryTimer=null;Object.defineProperties(this,{transactionsCount:{get:function(){var type,transactions=["nist","nict","ist","ict"],count=0;for(type in transactions){count+=Object.keys(this.transactions[transactions[type]]).length}return count}},nictTransactionsCount:{get:function(){return Object.keys(this.transactions["nict"]).length}},nistTransactionsCount:{get:function(){return Object.keys(this.transactions["nist"]).length}},ictTransactionsCount:{get:function(){return Object.keys(this.transactions["ict"]).length}},istTransactionsCount:{get:function(){return Object.keys(this.transactions["ist"]).length}}});if(configuration===undefined){configuration={}}else if(typeof configuration==="string"||configuration instanceof String){configuration={uri:configuration}}if(configuration.log){if(configuration.log.hasOwnProperty("builtinEnabled")){this.log.builtinEnabled=configuration.log.builtinEnabled}if(configuration.log.hasOwnProperty("level")){this.log.level=configuration.log.level}if(configuration.log.hasOwnProperty("connector")){this.log.connector=configuration.log.connector}}try{this.loadConfig(configuration)}catch(e){this.status=C.STATUS_NOT_READY;this.error=C.CONFIGURATION_ERROR;throw e}this.registerContext=new SIP.RegisterContext(this);this.registerContext.on("failed",selfEmit("registrationFailed"));this.registerContext.on("registered",selfEmit("registered"));this.registerContext.on("unregistered",selfEmit("unregistered"));if(this.configuration.autostart){this.start()}if(typeof environment.addEventListener==="function"){if(!(global.chrome&&global.chrome.app&&global.chrome.app.runtime)){environment.addEventListener("unload",this.stop.bind(this))}}};UA.prototype=Object.create(SIP.EventEmitter.prototype);UA.prototype.register=function(options){this.configuration.register=true;this.registerContext.register(options);return this};UA.prototype.unregister=function(options){this.configuration.register=false;var context=this.registerContext;this.afterConnected(context.unregister.bind(context,options));return this};UA.prototype.isRegistered=function(){return this.registerContext.registered};UA.prototype.isConnected=function(){return this.transport?this.transport.connected:false};UA.prototype.afterConnected=function afterConnected(callback){if(this.isConnected()){callback()}else{this.once("connected",callback)}};UA.prototype.invite=function(target,options){var context=new SIP.InviteClientContext(this,target,options);this.afterConnected(context.invite.bind(context));return context};UA.prototype.subscribe=function(target,event,options){var sub=new SIP.Subscription(this,target,event,options);this.afterConnected(sub.subscribe.bind(sub));return sub};UA.prototype.message=function(target,body,options){if(body===undefined){throw new TypeError("Not enough arguments")}options=Object.create(options||Object.prototype);options.contentType||(options.contentType="text/plain");options.body=body;return this.request(SIP.C.MESSAGE,target,options)};UA.prototype.request=function(method,target,options){var req=new SIP.ClientContext(this,method,target,options);this.afterConnected(req.send.bind(req));return req};UA.prototype.stop=function(){var session,subscription,applicant,ua=this;function transactionsListener(){if(ua.nistTransactionsCount===0&&ua.nictTransactionsCount===0){ua.removeListener("transactionDestroyed",transactionsListener);ua.transport.disconnect()}}this.logger.log("user requested closure...");if(this.status===C.STATUS_USER_CLOSED){this.logger.warn("UA already closed");return this}SIP.Timers.clearTimeout(this.transportRecoveryTimer);this.logger.log("closing registerContext");this.registerContext.close();for(session in this.sessions){this.logger.log("closing session "+session);this.sessions[session].terminate()}for(subscription in this.subscriptions){this.logger.log("unsubscribing from subscription "+subscription);this.subscriptions[subscription].close()}for(applicant in this.applicants){this.applicants[applicant].close()}this.status=C.STATUS_USER_CLOSED;if(this.nistTransactionsCount===0&&this.nictTransactionsCount===0){if(this.transport){this.transport.disconnect()}}else{this.on("transactionDestroyed",transactionsListener)}return this};UA.prototype.start=function(){var server;this.logger.log("user requested startup...");if(this.status===C.STATUS_INIT){server=this.getNextWsServer();this.status=C.STATUS_STARTING;new SIP.Transport(this,server)}else if(this.status===C.STATUS_USER_CLOSED){this.logger.log("resuming");this.status=C.STATUS_READY;this.transport.connect()}else if(this.status===C.STATUS_STARTING){this.logger.log("UA is in STARTING status, not opening new connection")}else if(this.status===C.STATUS_READY){this.logger.log("UA is in READY status, not resuming")}else{this.logger.error("Connection is down. Auto-Recovery system is trying to connect")}return this};UA.prototype.normalizeTarget=function(target){return SIP.Utils.normalizeTarget(target,this.configuration.hostportParams)};UA.prototype.saveCredentials=function(credentials){this.cache.credentials[credentials.realm]=this.cache.credentials[credentials.realm]||{};this.cache.credentials[credentials.realm][credentials.uri]=credentials;return this};UA.prototype.getCredentials=function(request){var realm,credentials;realm=request.ruri.host;if(this.cache.credentials[realm]&&this.cache.credentials[realm][request.ruri]){credentials=this.cache.credentials[realm][request.ruri];credentials.method=request.method}return credentials};UA.prototype.getLogger=function(category,label){return this.log.getLogger(category,label)};UA.prototype.onTransportClosed=function(transport){var type,idx,length,client_transactions=["nict","ict","nist","ist"];transport.server.status=SIP.Transport.C.STATUS_DISCONNECTED;this.logger.log("connection state set to "+SIP.Transport.C.STATUS_DISCONNECTED);length=client_transactions.length;for(type=0;type<length;type++){for(idx in this.transactions[client_transactions[type]]){this.transactions[client_transactions[type]][idx].onTransportError()}}if(!this.contact.pub_gruu){this.closeSessionsOnTransportError()}};UA.prototype.onTransportError=function(transport){var server;this.logger.log("transport "+transport.server.ws_uri+" failed | connection state set to "+SIP.Transport.C.STATUS_ERROR);transport.server.status=SIP.Transport.C.STATUS_ERROR;this.emit("disconnected",{transport:transport});if(this.status===C.STATUS_USER_CLOSED){return}server=this.getNextWsServer();if(server){new SIP.Transport(this,server)}else{this.closeSessionsOnTransportError();if(!this.error||this.error!==C.NETWORK_ERROR){this.status=C.STATUS_NOT_READY;this.error=C.NETWORK_ERROR}this.recoverTransport()}};UA.prototype.onTransportConnected=function(transport){this.transport=transport;this.transportRecoverAttempts=0;transport.server.status=SIP.Transport.C.STATUS_READY;this.logger.log("connection state set to "+SIP.Transport.C.STATUS_READY);if(this.status===C.STATUS_USER_CLOSED){return}this.status=C.STATUS_READY;this.error=null;if(this.configuration.register){this.configuration.authenticationFactory.initialize().then(function(){this.registerContext.onTransportConnected()}.bind(this))}this.emit("connected",{transport:transport})};UA.prototype.onTransportConnecting=function(transport,attempts){this.emit("connecting",{transport:transport,attempts:attempts})};UA.prototype.newTransaction=function(transaction){this.transactions[transaction.type][transaction.id]=transaction;this.emit("newTransaction",{transaction:transaction})};UA.prototype.destroyTransaction=function(transaction){delete this.transactions[transaction.type][transaction.id];this.emit("transactionDestroyed",{transaction:transaction})};UA.prototype.receiveRequest=function(request){var dialog,session,message,method=request.method,transaction,replaces,replacedDialog,self=this;function ruriMatches(uri){return uri&&uri.user===request.ruri.user}if(!(ruriMatches(this.configuration.uri)||ruriMatches(this.contact.uri)||ruriMatches(this.contact.pub_gruu)||ruriMatches(this.contact.temp_gruu))){this.logger.warn("Request-URI does not point to us");if(request.method!==SIP.C.ACK){request.reply_sl(404)}return}if(request.ruri.scheme===SIP.C.SIPS){request.reply_sl(416);return}if(SIP.Transactions.checkTransaction(this,request)){return}if(method===SIP.C.OPTIONS){new SIP.Transactions.NonInviteServerTransaction(request,this);request.reply(200,null,["Allow: "+SIP.UA.C.ALLOWED_METHODS.toString(),"Accept: "+C.ACCEPTED_BODY_TYPES])}else if(method===SIP.C.MESSAGE){message=new SIP.ServerContext(this,request);message.body=request.body;message.content_type=request.getHeader("Content-Type")||"text/plain";request.reply(200,null);this.emit("message",message)}else if(method!==SIP.C.INVITE&&method!==SIP.C.ACK){transaction=new SIP.ServerContext(this,request)}if(!request.to_tag){switch(method){case SIP.C.INVITE:replaces=this.configuration.replaces!==SIP.C.supported.UNSUPPORTED&&request.parseHeader("replaces");if(replaces){replacedDialog=this.dialogs[replaces.call_id+replaces.replaces_to_tag+replaces.replaces_from_tag];if(!replacedDialog){request.reply_sl(481,null);return}else if(replacedDialog.owner.status===SIP.Session.C.STATUS_TERMINATED){request.reply_sl(603,null);return}else if(replacedDialog.state===SIP.Dialog.C.STATUS_CONFIRMED&&replaces.early_only){request.reply_sl(486,null);return}}var isMediaSupported=this.configuration.mediaHandlerFactory.isSupported;if(!isMediaSupported||isMediaSupported()){session=new SIP.InviteServerContext(this,request);session.replacee=replacedDialog&&replacedDialog.owner;session.on("invite",function(){self.emit("invite",this)})}else{this.logger.warn("INVITE received but WebRTC is not supported");request.reply(488)}break;case SIP.C.BYE:request.reply(481);break;case SIP.C.CANCEL:session=this.findSession(request);if(session){session.receiveRequest(request)}else{this.logger.warn("received CANCEL request for a non existent session")}break;case SIP.C.ACK:break;case SIP.C.NOTIFY:if(this.configuration.allowLegacyNotifications&&this.listeners("notify").length>0){request.reply(200,null);self.emit("notify",{request:request})}else{request.reply(481,"Subscription does not exist")}break;default:request.reply(405);break}}else{dialog=this.findDialog(request);if(dialog){if(method===SIP.C.INVITE){new SIP.Transactions.InviteServerTransaction(request,this)}dialog.receiveRequest(request)}else if(method===SIP.C.NOTIFY){session=this.findSession(request);if(session){session.receiveRequest(request)}else{this.logger.warn("received NOTIFY request for a non existent session");request.reply(481,"Subscription does not exist")}}else{if(method!==SIP.C.ACK){request.reply(481)}}}};UA.prototype.findSession=function(request){return this.sessions[request.call_id+request.from_tag]||this.sessions[request.call_id+request.to_tag]||null};UA.prototype.findDialog=function(request){return this.dialogs[request.call_id+request.from_tag+request.to_tag]||this.dialogs[request.call_id+request.to_tag+request.from_tag]||null};UA.prototype.getNextWsServer=function(){var idx,length,ws_server,candidates=[];length=this.configuration.wsServers.length;for(idx=0;idx<length;idx++){ws_server=this.configuration.wsServers[idx];if(ws_server.status===SIP.Transport.C.STATUS_ERROR){continue}else if(candidates.length===0){candidates.push(ws_server)}else if(ws_server.weight>candidates[0].weight){candidates=[ws_server]}else if(ws_server.weight===candidates[0].weight){candidates.push(ws_server)}}idx=Math.floor(Math.random()*candidates.length);return candidates[idx]};UA.prototype.closeSessionsOnTransportError=function(){var idx;for(idx in this.sessions){this.sessions[idx].onTransportError()}this.registerContext.onTransportClosed()};UA.prototype.recoverTransport=function(ua){var idx,length,k,nextRetry,count,server;ua=ua||this;count=ua.transportRecoverAttempts;length=ua.configuration.wsServers.length;for(idx=0;idx<length;idx++){ua.configuration.wsServers[idx].status=0}server=ua.getNextWsServer();k=Math.floor(Math.random()*Math.pow(2,count)+1);nextRetry=k*ua.configuration.connectionRecoveryMinInterval;if(nextRetry>ua.configuration.connectionRecoveryMaxInterval){this.logger.log("time for next connection attempt exceeds connectionRecoveryMaxInterval, resetting counter");nextRetry=ua.configuration.connectionRecoveryMinInterval;count=0}this.logger.log("next connection attempt in "+nextRetry+" seconds");this.transportRecoveryTimer=SIP.Timers.setTimeout(function(){ua.transportRecoverAttempts=count+1;new SIP.Transport(ua,server)},nextRetry*1e3)};function checkAuthenticationFactory(authenticationFactory){if(!(authenticationFactory instanceof Function)){return}if(!authenticationFactory.initialize){authenticationFactory.initialize=function initialize(){return SIP.Utils.Promise.resolve()}}return authenticationFactory}UA.prototype.loadConfig=function(configuration){var parameter,value,checked_value,hostportParams,registrarServer,settings={viaHost:SIP.Utils.createRandomToken(12)+".invalid",uri:new SIP.URI("sip","anonymous."+SIP.Utils.createRandomToken(6),"anonymous.invalid",null,null),wsServers:[{scheme:"WSS",sip_uri:"<sip:edge.sip.onsip.com;transport=ws;lr>",status:0,weight:0,ws_uri:"wss://edge.sip.onsip.com"}],password:null,registerExpires:600,register:true,registrarServer:null,wsServerMaxReconnection:3,wsServerReconnectionTimeout:4,connectionRecoveryMinInterval:2,connectionRecoveryMaxInterval:30,keepAliveInterval:0,extraSupported:[],usePreloadedRoute:false,userAgentString:SIP.C.USER_AGENT,iceCheckingTimeout:5e3,noAnswerTimeout:60,stunServers:["stun:stun.l.google.com:19302"],turnServers:[],traceSip:false,hackViaTcp:false,hackIpInContact:false,hackWssInTransport:false,hackAllowUnregisteredOptionTags:false,hackCleanJitsiSdpImageattr:false,hackStripTcp:false,contactTransport:"ws",forceRport:false,autostart:true,rel100:SIP.C.supported.UNSUPPORTED,replaces:SIP.C.supported.UNSUPPORTED,mediaHandlerFactory:SIP.WebRTC.MediaHandler.defaultFactory,authenticationFactory:checkAuthenticationFactory(function authenticationFactory(ua){return new SIP.DigestAuthentication(ua)}),allowLegacyNotifications:false};function aliasUnderscored(parameter,logger){var underscored=parameter.replace(/([a-z][A-Z])/g,function(m){return m[0]+"_"+m[1].toLowerCase()});if(parameter===underscored){return}var hasParameter=configuration.hasOwnProperty(parameter);if(configuration.hasOwnProperty(underscored)){logger.warn(underscored+" is deprecated, please use "+parameter);if(hasParameter){logger.warn(parameter+" overriding "+underscored)}}configuration[parameter]=hasParameter?configuration[parameter]:configuration[underscored]}for(parameter in UA.configuration_check.mandatory){aliasUnderscored(parameter,this.logger);if(!configuration.hasOwnProperty(parameter)){throw new SIP.Exceptions.ConfigurationError(parameter)}else{value=configuration[parameter];checked_value=UA.configuration_check.mandatory[parameter](value);if(checked_value!==undefined){settings[parameter]=checked_value}else{throw new SIP.Exceptions.ConfigurationError(parameter,value)}}}SIP.Utils.optionsOverride(configuration,"rel100","reliable",true,this.logger,SIP.C.supported.UNSUPPORTED);var emptyArraysAllowed=["stunServers","turnServers"];for(parameter in UA.configuration_check.optional){aliasUnderscored(parameter,this.logger);if(configuration.hasOwnProperty(parameter)){value=configuration[parameter];if(value instanceof Array&&value.length===0&&emptyArraysAllowed.indexOf(parameter)<0){continue}if(value===null||value===""||value===undefined){continue}else if(typeof value==="number"&&isNaN(value)){continue}checked_value=UA.configuration_check.optional[parameter](value);if(checked_value!==undefined){settings[parameter]=checked_value}else{throw new SIP.Exceptions.ConfigurationError(parameter,value)}}}if(settings.connectionRecoveryMaxInterval<settings.connectionRecoveryMinInterval){throw new SIP.Exceptions.ConfigurationError("connectionRecoveryMaxInterval",settings.connectionRecoveryMaxInterval)}if(settings.displayName===0){settings.displayName="0"}if(!settings.instanceId){settings.instanceId=SIP.Utils.newUUID()}settings.sipjsId=SIP.Utils.createRandomToken(5);hostportParams=settings.uri.clone();hostportParams.user=null;settings.hostportParams=hostportParams.toRaw().replace(/^sip:/i,"");if(!settings.authorizationUser){settings.authorizationUser=settings.uri.user}if(!settings.registrarServer){registrarServer=settings.uri.clone();registrarServer.user=null;settings.registrarServer=registrarServer}settings.noAnswerTimeout=settings.noAnswerTimeout*1e3;if(settings.hackIpInContact){if(typeof settings.hackIpInContact==="boolean"){settings.viaHost=SIP.Utils.getRandomTestNetIP()}else if(typeof settings.hackIpInContact==="string"){settings.viaHost=settings.hackIpInContact}}if(settings.hackWssInTransport){settings.contactTransport="wss"}this.contact={pub_gruu:null,temp_gruu:null,uri:new SIP.URI("sip",SIP.Utils.createRandomToken(8),settings.viaHost,null,{transport:settings.contactTransport}),toString:function(options){options=options||{};var anonymous=options.anonymous||null,outbound=options.outbound||null,contact="<";if(anonymous){contact+=(this.temp_gruu||"sip:anonymous@anonymous.invalid;transport="+settings.contactTransport).toString()}else{contact+=(this.pub_gruu||this.uri).toString()}if(outbound){contact+=";ob"}contact+=">";return contact}};SIP.Utils.optionsOverride(settings,"media","mediaConstraints",true,this.logger);for(parameter in settings){UA.configuration_skeleton[parameter].value=settings[parameter]}Object.defineProperties(this.configuration,UA.configuration_skeleton);for(parameter in settings){UA.configuration_skeleton[parameter].value=""}this.logger.log("configuration parameters after validation:");for(parameter in settings){switch(parameter){case"uri":case"registrarServer":case"mediaHandlerFactory":this.logger.log("\xb7 "+parameter+": "+settings[parameter]);break;case"password":this.logger.log("\xb7 "+parameter+": "+"NOT SHOWN");break;default:this.logger.log("\xb7 "+parameter+": "+JSON.stringify(settings[parameter]))}}return};UA.configuration_skeleton=function(){var idx,parameter,skeleton={},parameters=["sipjsId","hostportParams","uri","wsServers","authorizationUser","connectionRecoveryMaxInterval","connectionRecoveryMinInterval","keepAliveInterval","extraSupported","displayName","hackViaTcp","hackIpInContact","hackWssInTransport","hackAllowUnregisteredOptionTags","hackCleanJitsiSdpImageattr","hackStripTcp","contactTransport","forceRport","iceCheckingTimeout","instanceId","noAnswerTimeout","password","registerExpires","registrarServer","reliable","rel100","replaces","userAgentString","autostart","stunServers","traceSip","turnServers","usePreloadedRoute","wsServerMaxReconnection","wsServerReconnectionTimeout","mediaHandlerFactory","media","mediaConstraints","authenticationFactory","allowLegacyNotifications","via_core_value","viaHost"];for(idx in parameters){parameter=parameters[idx];skeleton[parameter]={value:"",writable:false,configurable:false}}skeleton["register"]={value:"",writable:true,configurable:false};return skeleton}();UA.configuration_check={mandatory:{},optional:{uri:function(uri){var parsed;if(!/^sip:/i.test(uri)){uri=SIP.C.SIP+":"+uri}parsed=SIP.URI.parse(uri);if(!parsed){return}else if(!parsed.user){return}else{return parsed}},wsServers:function(wsServers){var idx,length,url;if(typeof wsServers==="string"){wsServers=[{ws_uri:wsServers}]}else if(wsServers instanceof Array){length=wsServers.length;for(idx=0;idx<length;idx++){if(typeof wsServers[idx]==="string"){wsServers[idx]={ws_uri:wsServers[idx]}}}}else{return}if(wsServers.length===0){return false}length=wsServers.length;for(idx=0;idx<length;idx++){if(!wsServers[idx].ws_uri){return}if(wsServers[idx].weight&&!Number(wsServers[idx].weight)){return}url=SIP.Grammar.parse(wsServers[idx].ws_uri,"absoluteURI");if(url===-1){return}else if(["wss","ws","udp"].indexOf(url.scheme)<0){return}else{wsServers[idx].sip_uri="<sip:"+url.host+(url.port?":"+url.port:"")+";transport="+url.scheme.replace(/^wss$/i,"ws")+";lr>";if(!wsServers[idx].weight){wsServers[idx].weight=0}wsServers[idx].status=0;wsServers[idx].scheme=url.scheme.toUpperCase()}}return wsServers},authorizationUser:function(authorizationUser){if(SIP.Grammar.parse('"'+authorizationUser+'"',"quoted_string")===-1){return}else{
return authorizationUser}},connectionRecoveryMaxInterval:function(connectionRecoveryMaxInterval){var value;if(SIP.Utils.isDecimal(connectionRecoveryMaxInterval)){value=Number(connectionRecoveryMaxInterval);if(value>0){return value}}},connectionRecoveryMinInterval:function(connectionRecoveryMinInterval){var value;if(SIP.Utils.isDecimal(connectionRecoveryMinInterval)){value=Number(connectionRecoveryMinInterval);if(value>0){return value}}},displayName:function(displayName){if(SIP.Grammar.parse('"'+displayName+'"',"displayName")===-1){return}else{return displayName}},hackViaTcp:function(hackViaTcp){if(typeof hackViaTcp==="boolean"){return hackViaTcp}},hackIpInContact:function(hackIpInContact){if(typeof hackIpInContact==="boolean"){return hackIpInContact}else if(typeof hackIpInContact==="string"&&SIP.Grammar.parse(hackIpInContact,"host")!==-1){return hackIpInContact}},iceCheckingTimeout:function(iceCheckingTimeout){if(SIP.Utils.isDecimal(iceCheckingTimeout)){return Math.max(500,iceCheckingTimeout)}},hackWssInTransport:function(hackWssInTransport){if(typeof hackWssInTransport==="boolean"){return hackWssInTransport}},hackAllowUnregisteredOptionTags:function(hackAllowUnregisteredOptionTags){if(typeof hackAllowUnregisteredOptionTags==="boolean"){return hackAllowUnregisteredOptionTags}},hackCleanJitsiSdpImageattr:function(hackCleanJitsiSdpImageattr){if(typeof hackCleanJitsiSdpImageattr==="boolean"){return hackCleanJitsiSdpImageattr}},hackStripTcp:function(hackStripTcp){if(typeof hackStripTcp==="boolean"){return hackStripTcp}},contactTransport:function(contactTransport){if(typeof contactTransport==="string"){return contactTransport}},forceRport:function(forceRport){if(typeof forceRport==="boolean"){return forceRport}},instanceId:function(instanceId){if(typeof instanceId!=="string"){return}if(/^uuid:/i.test(instanceId)){instanceId=instanceId.substr(5)}if(SIP.Grammar.parse(instanceId,"uuid")===-1){return}else{return instanceId}},keepAliveInterval:function(keepAliveInterval){var value;if(SIP.Utils.isDecimal(keepAliveInterval)){value=Number(keepAliveInterval);if(value>0){return value}}},extraSupported:function(optionTags){var idx,length;if(!(optionTags instanceof Array)){return}length=optionTags.length;for(idx=0;idx<length;idx++){if(typeof optionTags[idx]!=="string"){return}}return optionTags},noAnswerTimeout:function(noAnswerTimeout){var value;if(SIP.Utils.isDecimal(noAnswerTimeout)){value=Number(noAnswerTimeout);if(value>0){return value}}},password:function(password){return String(password)},rel100:function(rel100){if(rel100===SIP.C.supported.REQUIRED){return SIP.C.supported.REQUIRED}else if(rel100===SIP.C.supported.SUPPORTED){return SIP.C.supported.SUPPORTED}else{return SIP.C.supported.UNSUPPORTED}},replaces:function(replaces){if(replaces===SIP.C.supported.REQUIRED){return SIP.C.supported.REQUIRED}else if(replaces===SIP.C.supported.SUPPORTED){return SIP.C.supported.SUPPORTED}else{return SIP.C.supported.UNSUPPORTED}},register:function(register){if(typeof register==="boolean"){return register}},registerExpires:function(registerExpires){var value;if(SIP.Utils.isDecimal(registerExpires)){value=Number(registerExpires);if(value>0){return value}}},registrarServer:function(registrarServer){var parsed;if(typeof registrarServer!=="string"){return}if(!/^sip:/i.test(registrarServer)){registrarServer=SIP.C.SIP+":"+registrarServer}parsed=SIP.URI.parse(registrarServer);if(!parsed){return}else if(parsed.user){return}else{return parsed}},stunServers:function(stunServers){var idx,length,stun_server;if(typeof stunServers==="string"){stunServers=[stunServers]}else if(!(stunServers instanceof Array)){return}length=stunServers.length;for(idx=0;idx<length;idx++){stun_server=stunServers[idx];if(!/^stuns?:/.test(stun_server)){stun_server="stun:"+stun_server}if(SIP.Grammar.parse(stun_server,"stun_URI")===-1){return}else{stunServers[idx]=stun_server}}return stunServers},traceSip:function(traceSip){if(typeof traceSip==="boolean"){return traceSip}},turnServers:function(turnServers){var idx,jdx,length,turn_server,num_turn_server_urls,url;if(turnServers instanceof Array){}else{turnServers=[turnServers]}length=turnServers.length;for(idx=0;idx<length;idx++){turn_server=turnServers[idx];if(turn_server.server){turn_server.urls=[turn_server.server]}if(!turn_server.urls||!turn_server.username||!turn_server.password){return}if(turn_server.urls instanceof Array){num_turn_server_urls=turn_server.urls.length}else{turn_server.urls=[turn_server.urls];num_turn_server_urls=1}for(jdx=0;jdx<num_turn_server_urls;jdx++){url=turn_server.urls[jdx];if(!/^turns?:/.test(url)){url="turn:"+url}if(SIP.Grammar.parse(url,"turn_URI")===-1){return}}}return turnServers},userAgentString:function(userAgentString){if(typeof userAgentString==="string"){return userAgentString}},usePreloadedRoute:function(usePreloadedRoute){if(typeof usePreloadedRoute==="boolean"){return usePreloadedRoute}},wsServerMaxReconnection:function(wsServerMaxReconnection){var value;if(SIP.Utils.isDecimal(wsServerMaxReconnection)){value=Number(wsServerMaxReconnection);if(value>0){return value}}},wsServerReconnectionTimeout:function(wsServerReconnectionTimeout){var value;if(SIP.Utils.isDecimal(wsServerReconnectionTimeout)){value=Number(wsServerReconnectionTimeout);if(value>0){return value}}},autostart:function(autostart){if(typeof autostart==="boolean"){return autostart}},mediaHandlerFactory:function(mediaHandlerFactory){if(mediaHandlerFactory instanceof Function){var promisifiedFactory=function promisifiedFactory(){var mediaHandler=mediaHandlerFactory.apply(this,arguments);function patchMethod(methodName){var method=mediaHandler[methodName];if(method.length>1){var callbacksFirst=methodName==="getDescription";mediaHandler[methodName]=SIP.Utils.promisify(mediaHandler,methodName,callbacksFirst)}}patchMethod("getDescription");patchMethod("setDescription");return mediaHandler};promisifiedFactory.isSupported=mediaHandlerFactory.isSupported;return promisifiedFactory}},authenticationFactory:checkAuthenticationFactory,allowLegacyNotifications:function(allowLegacyNotifications){if(typeof allowLegacyNotifications==="boolean"){return allowLegacyNotifications}}}};UA.C=C;SIP.UA=UA}}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],88:[function(require,module,exports){"use strict";module.exports=function(SIP){var URI;URI=function(scheme,user,host,port,parameters,headers){var param,header,raw,normal;if(!host){throw new TypeError('missing or invalid "host" parameter')}scheme=scheme||SIP.C.SIP;this.parameters={};this.headers={};for(param in parameters){this.setParam(param,parameters[param])}for(header in headers){this.setHeader(header,headers[header])}raw={scheme:scheme,user:user,host:host,port:port};normal={scheme:scheme.toLowerCase(),user:user,host:host.toLowerCase(),port:port};Object.defineProperties(this,{_normal:{get:function(){return normal}},_raw:{get:function(){return raw}},scheme:{get:function(){return normal.scheme},set:function(value){raw.scheme=value;normal.scheme=value.toLowerCase()}},user:{get:function(){return normal.user},set:function(value){normal.user=raw.user=value}},host:{get:function(){return normal.host},set:function(value){raw.host=value;normal.host=value.toLowerCase()}},aor:{get:function(){return normal.user+"@"+normal.host}},port:{get:function(){return normal.port},set:function(value){normal.port=raw.port=value===0?value:parseInt(value,10)||null}}})};URI.prototype={setParam:function(key,value){if(key){this.parameters[key.toLowerCase()]=typeof value==="undefined"||value===null?null:value.toString().toLowerCase()}},getParam:function(key){if(key){return this.parameters[key.toLowerCase()]}},hasParam:function(key){if(key){return this.parameters.hasOwnProperty(key.toLowerCase())&&true||false}},deleteParam:function(parameter){var value;parameter=parameter.toLowerCase();if(this.parameters.hasOwnProperty(parameter)){value=this.parameters[parameter];delete this.parameters[parameter];return value}},clearParams:function(){this.parameters={}},setHeader:function(name,value){this.headers[SIP.Utils.headerize(name)]=value instanceof Array?value:[value]},getHeader:function(name){if(name){return this.headers[SIP.Utils.headerize(name)]}},hasHeader:function(name){if(name){return this.headers.hasOwnProperty(SIP.Utils.headerize(name))&&true||false}},deleteHeader:function(header){var value;header=SIP.Utils.headerize(header);if(this.headers.hasOwnProperty(header)){value=this.headers[header];delete this.headers[header];return value}},clearHeaders:function(){this.headers={}},clone:function(){return new URI(this._raw.scheme,this._raw.user,this._raw.host,this._raw.port,JSON.parse(JSON.stringify(this.parameters)),JSON.parse(JSON.stringify(this.headers)))},toRaw:function(){return this._toString(this._raw)},toString:function(){return this._toString(this._normal)},_toString:function(uri){var header,parameter,idx,uriString,headers=[];uriString=uri.scheme+":";if(!uri.scheme.toLowerCase().match("^sips?$")){uriString+="//"}if(uri.user){uriString+=SIP.Utils.escapeUser(uri.user)+"@"}uriString+=uri.host;if(uri.port||uri.port===0){uriString+=":"+uri.port}for(parameter in this.parameters){uriString+=";"+parameter;if(this.parameters[parameter]!==null){uriString+="="+this.parameters[parameter]}}for(header in this.headers){for(idx in this.headers[header]){headers.push(header+"="+this.headers[header][idx])}}if(headers.length>0){uriString+="?"+headers.join("&")}return uriString}};URI.parse=function(uri){uri=SIP.Grammar.parse(uri,"SIP_URI");if(uri!==-1){return uri}else{return undefined}};SIP.URI=URI}},{}],89:[function(require,module,exports){"use strict";module.exports=function(SIP,environment){var Utils;Utils={Promise:environment.Promise,defer:function defer(){var deferred={};deferred.promise=new Utils.Promise(function(resolve,reject){deferred.resolve=resolve;deferred.reject=reject});return deferred},promisify:function promisify(object,methodName,callbacksFirst){var oldMethod=object[methodName];return function promisifiedMethod(arg,onSuccess,onFailure){return new Utils.Promise(function(resolve,reject){var oldArgs=[arg,resolve,reject];if(callbacksFirst){oldArgs=[resolve,reject,arg]}oldMethod.apply(object,oldArgs)}).then(onSuccess,onFailure)}},augment:function(object,constructor,args,override){var idx,proto;proto=constructor.prototype;for(idx in proto){if(override||object[idx]===undefined){object[idx]=proto[idx]}}constructor.apply(object,args)},optionsOverride:function(options,winner,loser,isDeprecated,logger,defaultValue){if(isDeprecated&&options[loser]){logger.warn(loser+" is deprecated, please use "+winner+" instead")}if(options[winner]&&options[loser]){logger.warn(winner+" overriding "+loser)}options[winner]=options[winner]||options[loser]||defaultValue},str_utf8_length:function(string){return encodeURIComponent(string).replace(/%[A-F\d]{2}/g,"U").length},generateFakeSDP:function(body){if(!body){return}var start=body.indexOf("o=");var end=body.indexOf("\r\n",start);return"v=0\r\n"+body.slice(start,end)+"\r\ns=-\r\nt=0 0\r\nc=IN IP4 0.0.0.0"},isFunction:function(fn){if(fn!==undefined){return Object.prototype.toString.call(fn)==="[object Function]"}else{return false}},isDecimal:function(num){return!isNaN(num)&&parseFloat(num)===parseInt(num,10)},createRandomToken:function(size,base){var i,r,token="";base=base||32;for(i=0;i<size;i++){r=Math.random()*base|0;token+=r.toString(base)}return token},newTag:function(){return SIP.Utils.createRandomToken(SIP.UA.C.TAG_LENGTH)},newUUID:function(){var UUID="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(c){var r=Math.random()*16|0,v=c==="x"?r:r&3|8;return v.toString(16)});return UUID},hostType:function(host){if(!host){return}else{host=SIP.Grammar.parse(host,"host");if(host!==-1){return host.host_type}}},normalizeTarget:function(target,domain){var uri,target_array,target_user,target_domain;if(!target){return}else if(target instanceof SIP.URI){return target}else if(typeof target==="string"){target_array=target.split("@");switch(target_array.length){case 1:if(!domain){return}target_user=target;target_domain=domain;break;case 2:target_user=target_array[0];target_domain=target_array[1];break;default:target_user=target_array.slice(0,target_array.length-1).join("@");target_domain=target_array[target_array.length-1]}target_user=target_user.replace(/^(sips?|tel):/i,"");if(/^[\-\.\(\)]*\+?[0-9\-\.\(\)]+$/.test(target_user)){target_user=target_user.replace(/[\-\.\(\)]/g,"")}target=SIP.C.SIP+":"+SIP.Utils.escapeUser(target_user)+"@"+target_domain;if(uri=SIP.URI.parse(target)){return uri}else{return}}else{return}},escapeUser:function(user){return encodeURIComponent(decodeURIComponent(user)).replace(/%3A/gi,":").replace(/%2B/gi,"+").replace(/%3F/gi,"?").replace(/%2F/gi,"/")},headerize:function(string){var exceptions={"Call-Id":"Call-ID",Cseq:"CSeq","Min-Se":"Min-SE",Rack:"RAck",Rseq:"RSeq","Www-Authenticate":"WWW-Authenticate"},name=string.toLowerCase().replace(/_/g,"-").split("-"),hname="",parts=name.length,part;for(part=0;part<parts;part++){if(part!==0){hname+="-"}hname+=name[part].charAt(0).toUpperCase()+name[part].substring(1)}if(exceptions[hname]){hname=exceptions[hname]}return hname},sipErrorCause:function(status_code){var cause;for(cause in SIP.C.SIP_ERROR_CAUSES){if(SIP.C.SIP_ERROR_CAUSES[cause].indexOf(status_code)!==-1){return SIP.C.causes[cause]}}return SIP.C.causes.SIP_FAILURE_CODE},getReasonPhrase:function getReasonPhrase(code,specific){return specific||SIP.C.REASON_PHRASE[code]||""},getReasonHeaderValue:function getReasonHeaderValue(code,reason){reason=SIP.Utils.getReasonPhrase(code,reason);return"SIP ;cause="+code+' ;text="'+reason+'"'},getCancelReason:function getCancelReason(code,reason){if(code&&code<200||code>699){throw new TypeError("Invalid status_code: "+code)}else if(code){return SIP.Utils.getReasonHeaderValue(code,reason)}},buildStatusLine:function buildStatusLine(code,reason){code=code||null;reason=reason||null;if(!code||(code<100||code>699)){throw new TypeError("Invalid status_code: "+code)}else if(reason&&typeof reason!=="string"&&!(reason instanceof String)){throw new TypeError("Invalid reason_phrase: "+reason)}reason=Utils.getReasonPhrase(code,reason);return"SIP/2.0 "+code+" "+reason+"\r\n"},getRandomTestNetIP:function(){function getOctet(from,to){return Math.floor(Math.random()*(to-from+1)+from)}return"192.0.2."+getOctet(1,254)},calculateMD5:function(string){function RotateLeft(lValue,iShiftBits){return lValue<<iShiftBits|lValue>>>32-iShiftBits}function AddUnsigned(lX,lY){var lX4,lY4,lX8,lY8,lResult;lX8=lX&2147483648;lY8=lY&2147483648;lX4=lX&1073741824;lY4=lY&1073741824;lResult=(lX&1073741823)+(lY&1073741823);if(lX4&lY4){return lResult^2147483648^lX8^lY8}if(lX4|lY4){if(lResult&1073741824){return lResult^3221225472^lX8^lY8}else{return lResult^1073741824^lX8^lY8}}else{return lResult^lX8^lY8}}function F(x,y,z){return x&y|~x&z}function G(x,y,z){return x&z|y&~z}function H(x,y,z){return x^y^z}function I(x,y,z){return y^(x|~z)}function FF(a,b,c,d,x,s,ac){a=AddUnsigned(a,AddUnsigned(AddUnsigned(F(b,c,d),x),ac));return AddUnsigned(RotateLeft(a,s),b)}function GG(a,b,c,d,x,s,ac){a=AddUnsigned(a,AddUnsigned(AddUnsigned(G(b,c,d),x),ac));return AddUnsigned(RotateLeft(a,s),b)}function HH(a,b,c,d,x,s,ac){a=AddUnsigned(a,AddUnsigned(AddUnsigned(H(b,c,d),x),ac));return AddUnsigned(RotateLeft(a,s),b)}function II(a,b,c,d,x,s,ac){a=AddUnsigned(a,AddUnsigned(AddUnsigned(I(b,c,d),x),ac));return AddUnsigned(RotateLeft(a,s),b)}function ConvertToWordArray(string){var lWordCount;var lMessageLength=string.length;var lNumberOfWords_temp1=lMessageLength+8;var lNumberOfWords_temp2=(lNumberOfWords_temp1-lNumberOfWords_temp1%64)/64;var lNumberOfWords=(lNumberOfWords_temp2+1)*16;var lWordArray=Array(lNumberOfWords-1);var lBytePosition=0;var lByteCount=0;while(lByteCount<lMessageLength){lWordCount=(lByteCount-lByteCount%4)/4;lBytePosition=lByteCount%4*8;lWordArray[lWordCount]=lWordArray[lWordCount]|string.charCodeAt(lByteCount)<<lBytePosition;lByteCount++}lWordCount=(lByteCount-lByteCount%4)/4;lBytePosition=lByteCount%4*8;lWordArray[lWordCount]=lWordArray[lWordCount]|128<<lBytePosition;lWordArray[lNumberOfWords-2]=lMessageLength<<3;lWordArray[lNumberOfWords-1]=lMessageLength>>>29;return lWordArray}function WordToHex(lValue){var WordToHexValue="",WordToHexValue_temp="",lByte,lCount;for(lCount=0;lCount<=3;lCount++){lByte=lValue>>>lCount*8&255;WordToHexValue_temp="0"+lByte.toString(16);WordToHexValue=WordToHexValue+WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2)}return WordToHexValue}function Utf8Encode(string){string=string.replace(/\r\n/g,"\n");var utftext="";for(var n=0;n<string.length;n++){var c=string.charCodeAt(n);if(c<128){utftext+=String.fromCharCode(c)}else if(c>127&&c<2048){utftext+=String.fromCharCode(c>>6|192);utftext+=String.fromCharCode(c&63|128)}else{utftext+=String.fromCharCode(c>>12|224);utftext+=String.fromCharCode(c>>6&63|128);utftext+=String.fromCharCode(c&63|128)}}return utftext}var x=[];var k,AA,BB,CC,DD,a,b,c,d;var S11=7,S12=12,S13=17,S14=22;var S21=5,S22=9,S23=14,S24=20;var S31=4,S32=11,S33=16,S34=23;var S41=6,S42=10,S43=15,S44=21;string=Utf8Encode(string);x=ConvertToWordArray(string);a=1732584193;b=4023233417;c=2562383102;d=271733878;for(k=0;k<x.length;k+=16){AA=a;BB=b;CC=c;DD=d;a=FF(a,b,c,d,x[k+0],S11,3614090360);d=FF(d,a,b,c,x[k+1],S12,3905402710);c=FF(c,d,a,b,x[k+2],S13,606105819);b=FF(b,c,d,a,x[k+3],S14,3250441966);a=FF(a,b,c,d,x[k+4],S11,4118548399);d=FF(d,a,b,c,x[k+5],S12,1200080426);c=FF(c,d,a,b,x[k+6],S13,2821735955);b=FF(b,c,d,a,x[k+7],S14,4249261313);a=FF(a,b,c,d,x[k+8],S11,1770035416);d=FF(d,a,b,c,x[k+9],S12,2336552879);c=FF(c,d,a,b,x[k+10],S13,4294925233);b=FF(b,c,d,a,x[k+11],S14,2304563134);a=FF(a,b,c,d,x[k+12],S11,1804603682);d=FF(d,a,b,c,x[k+13],S12,4254626195);c=FF(c,d,a,b,x[k+14],S13,2792965006);b=FF(b,c,d,a,x[k+15],S14,1236535329);a=GG(a,b,c,d,x[k+1],S21,4129170786);d=GG(d,a,b,c,x[k+6],S22,3225465664);c=GG(c,d,a,b,x[k+11],S23,643717713);b=GG(b,c,d,a,x[k+0],S24,3921069994);a=GG(a,b,c,d,x[k+5],S21,3593408605);d=GG(d,a,b,c,x[k+10],S22,38016083);c=GG(c,d,a,b,x[k+15],S23,3634488961);b=GG(b,c,d,a,x[k+4],S24,3889429448);a=GG(a,b,c,d,x[k+9],S21,568446438);d=GG(d,a,b,c,x[k+14],S22,3275163606);c=GG(c,d,a,b,x[k+3],S23,4107603335);b=GG(b,c,d,a,x[k+8],S24,1163531501);a=GG(a,b,c,d,x[k+13],S21,2850285829);d=GG(d,a,b,c,x[k+2],S22,4243563512);c=GG(c,d,a,b,x[k+7],S23,1735328473);b=GG(b,c,d,a,x[k+12],S24,2368359562);a=HH(a,b,c,d,x[k+5],S31,4294588738);d=HH(d,a,b,c,x[k+8],S32,2272392833);c=HH(c,d,a,b,x[k+11],S33,1839030562);b=HH(b,c,d,a,x[k+14],S34,4259657740);a=HH(a,b,c,d,x[k+1],S31,2763975236);d=HH(d,a,b,c,x[k+4],S32,1272893353);c=HH(c,d,a,b,x[k+7],S33,4139469664);b=HH(b,c,d,a,x[k+10],S34,3200236656);a=HH(a,b,c,d,x[k+13],S31,681279174);d=HH(d,a,b,c,x[k+0],S32,3936430074);c=HH(c,d,a,b,x[k+3],S33,3572445317);b=HH(b,c,d,a,x[k+6],S34,76029189);a=HH(a,b,c,d,x[k+9],S31,3654602809);d=HH(d,a,b,c,x[k+12],S32,3873151461);c=HH(c,d,a,b,x[k+15],S33,530742520);b=HH(b,c,d,a,x[k+2],S34,3299628645);a=II(a,b,c,d,x[k+0],S41,4096336452);d=II(d,a,b,c,x[k+7],S42,1126891415);c=II(c,d,a,b,x[k+14],S43,2878612391);b=II(b,c,d,a,x[k+5],S44,4237533241);a=II(a,b,c,d,x[k+12],S41,1700485571);d=II(d,a,b,c,x[k+3],S42,2399980690);c=II(c,d,a,b,x[k+10],S43,4293915773);b=II(b,c,d,a,x[k+1],S44,2240044497);a=II(a,b,c,d,x[k+8],S41,1873313359);d=II(d,a,b,c,x[k+15],S42,4264355552);c=II(c,d,a,b,x[k+6],S43,2734768916);b=II(b,c,d,a,x[k+13],S44,1309151649);a=II(a,b,c,d,x[k+4],S41,4149444226);d=II(d,a,b,c,x[k+11],S42,3174756917);c=II(c,d,a,b,x[k+2],S43,718787259);b=II(b,c,d,a,x[k+9],S44,3951481745);a=AddUnsigned(a,AA);b=AddUnsigned(b,BB);c=AddUnsigned(c,CC);d=AddUnsigned(d,DD)}var temp=WordToHex(a)+WordToHex(b)+WordToHex(c)+WordToHex(d);return temp.toLowerCase()}};SIP.Utils=Utils}},{}],90:[function(require,module,exports){"use strict";module.exports=function(SIP,environment){var WebRTC;WebRTC={};WebRTC.MediaHandler=require("./WebRTC/MediaHandler")(SIP);WebRTC.MediaStreamManager=require("./WebRTC/MediaStreamManager")(SIP,environment);var _isSupported;WebRTC.isSupported=function(){if(_isSupported!==undefined){return _isSupported}WebRTC.MediaStream=environment.MediaStream;WebRTC.getUserMedia=environment.getUserMedia;WebRTC.RTCPeerConnection=environment.RTCPeerConnection;WebRTC.RTCSessionDescription=environment.RTCSessionDescription;if(WebRTC.RTCPeerConnection&&WebRTC.RTCSessionDescription){if(WebRTC.getUserMedia){WebRTC.getUserMedia=SIP.Utils.promisify(environment,"getUserMedia")}_isSupported=true}else{_isSupported=false}return _isSupported};return WebRTC}},{"./WebRTC/MediaHandler":91,"./WebRTC/MediaStreamManager":92}],91:[function(require,module,exports){"use strict";module.exports=function(SIP){var MediaHandler=function(session,options){options=options||{};this.logger=session.ua.getLogger("sip.invitecontext.mediahandler",session.id);this.session=session;this.localMedia=null;this.ready=true;this.mediaStreamManager=options.mediaStreamManager||new SIP.WebRTC.MediaStreamManager(this.logger);this.audioMuted=false;this.videoMuted=false;this.local_hold=false;this.remote_hold=false;var servers=this.prepareIceServers(options.stunServers,options.turnServers);this.RTCConstraints=options.RTCConstraints||{};this.initPeerConnection(servers);function selfEmit(mh,event){if(mh.mediaStreamManager.on){mh.mediaStreamManager.on(event,function(){mh.emit.apply(mh,[event].concat(Array.prototype.slice.call(arguments)))})}}selfEmit(this,"userMediaRequest");selfEmit(this,"userMedia");selfEmit(this,"userMediaFailed")};MediaHandler.defaultFactory=function defaultFactory(session,options){return new MediaHandler(session,options)};MediaHandler.defaultFactory.isSupported=function(){return SIP.WebRTC.isSupported()};MediaHandler.prototype=Object.create(SIP.MediaHandler.prototype,{isReady:{writable:true,value:function isReady(){return this.ready}},close:{writable:true,value:function close(){this.logger.log("closing PeerConnection");this._remoteStreams=[];if(this.peerConnection&&this.peerConnection.signalingState!=="closed"){this.peerConnection.close();if(this.localMedia){this.mediaStreamManager.release(this.localMedia)}}}},getDescription:{writable:true,value:function getDescription(mediaHint){var self=this;var acquire=self.mediaStreamManager.acquire;if(acquire.length>1){acquire=SIP.Utils.promisify(this.mediaStreamManager,"acquire",true)}mediaHint=mediaHint||{};if(mediaHint.dataChannel===true){mediaHint.dataChannel={}}this.mediaHint=mediaHint;var streamPromise;if(self.localMedia){self.logger.log("already have local media");streamPromise=SIP.Utils.Promise.resolve(self.localMedia)}else{self.logger.log("acquiring local media");streamPromise=acquire.call(self.mediaStreamManager,mediaHint).then(function acquireSucceeded(streams){self.logger.log("acquired local media streams");self.localMedia=streams;self.session.connecting();return streams},function acquireFailed(err){self.logger.error("unable to acquire streams");self.logger.error(err);self.session.connecting();throw err}).then(this.addStreams.bind(this))}return streamPromise.then(function streamAdditionSucceeded(){if(self.hasOffer("remote")){self.peerConnection.ondatachannel=function(evt){self.dataChannel=evt.channel;self.emit("dataChannel",self.dataChannel)}}else if(mediaHint.dataChannel&&self.peerConnection.createDataChannel){self.dataChannel=self.peerConnection.createDataChannel("sipjs",mediaHint.dataChannel);self.emit("dataChannel",self.dataChannel)}self.render();return self.createOfferOrAnswer(self.RTCConstraints)}).then(function(sdp){sdp=SIP.Hacks.Firefox.hasMissingCLineInSDP(sdp);if(self.local_hold){if(!/a=(sendrecv|sendonly|recvonly|inactive)/.test(sdp)){sdp=sdp.replace(/(m=[^\r]*\r\n)/g,"$1a=sendonly\r\n")}else{sdp=sdp.replace(/a=sendrecv\r\n/g,"a=sendonly\r\n");sdp=sdp.replace(/a=recvonly\r\n/g,"a=inactive\r\n")}}return{body:sdp,contentType:"application/sdp"}})}},hasDescription:{writeable:true,value:function hasDescription(message){return message.getHeader("Content-Type")==="application/sdp"&&!!message.body}},setDescription:{writable:true,value:function setDescription(message){var sdp=message.body;this.remote_hold=/a=(sendonly|inactive)/.test(sdp);sdp=SIP.Hacks.Firefox.cannotHandleExtraWhitespace(sdp);sdp=SIP.Hacks.AllBrowsers.maskDtls(sdp);var rawDescription={type:this.hasOffer("local")?"answer":"offer",sdp:sdp};this.emit("setDescription",rawDescription);var description=new SIP.WebRTC.RTCSessionDescription(rawDescription);return SIP.Utils.promisify(this.peerConnection,"setRemoteDescription")(description)}},getReferMedia:{writable:true,value:function getReferMedia(){function hasTracks(trackGetter,stream){return stream[trackGetter]().length>0}function bothHaveTracks(trackGetter){return this.getLocalStreams().some(hasTracks.bind(null,trackGetter))&&this.getRemoteStreams().some(hasTracks.bind(null,trackGetter))}return{constraints:{audio:bothHaveTracks.call(this,"getAudioTracks"),video:bothHaveTracks.call(this,"getVideoTracks")}}}},updateIceServers:{writeable:true,value:function(options){var servers=this.prepareIceServers(options.stunServers,options.turnServers);this.RTCConstraints=options.RTCConstraints||this.RTCConstraints;this.initPeerConnection(servers)}},isMuted:{writable:true,value:function isMuted(){return{audio:this.audioMuted,video:this.videoMuted}}},mute:{writable:true,value:function mute(options){if(this.getLocalStreams().length===0){return}options=options||{audio:this.getLocalStreams()[0].getAudioTracks().length>0,video:this.getLocalStreams()[0].getVideoTracks().length>0};var audioMuted=false,videoMuted=false;if(options.audio&&!this.audioMuted){audioMuted=true;this.audioMuted=true;this.toggleMuteAudio(true)}if(options.video&&!this.videoMuted){videoMuted=true;this.videoMuted=true;this.toggleMuteVideo(true)}if(audioMuted||videoMuted){return{audio:audioMuted,video:videoMuted}}}},unmute:{writable:true,value:function unmute(options){if(this.getLocalStreams().length===0){return}options=options||{audio:this.getLocalStreams()[0].getAudioTracks().length>0,video:this.getLocalStreams()[0].getVideoTracks().length>0};var audioUnMuted=false,videoUnMuted=false;if(options.audio&&this.audioMuted){audioUnMuted=true;this.audioMuted=false;this.toggleMuteAudio(false)}if(options.video&&this.videoMuted){videoUnMuted=true;this.videoMuted=false;this.toggleMuteVideo(false)}if(audioUnMuted||videoUnMuted){return{audio:audioUnMuted,video:videoUnMuted}}}},hold:{writable:true,value:function hold(){this.local_hold=true;this.toggleMuteAudio(true);this.toggleMuteVideo(true)}},unhold:{writable:true,value:function unhold(){this.local_hold=false;if(!this.audioMuted){this.toggleMuteAudio(false)}if(!this.videoMuted){this.toggleMuteVideo(false)}}},getLocalStreams:{writable:true,value:function getLocalStreams(){var pc=this.peerConnection;if(pc&&pc.signalingState==="closed"){this.logger.warn("peerConnection is closed, getLocalStreams returning []");return[]}return pc.getLocalStreams&&pc.getLocalStreams()||pc.localStreams||[]}},getRemoteStreams:{writable:true,value:function getRemoteStreams(){var pc=this.peerConnection;if(pc&&pc.signalingState==="closed"){this.logger.warn("peerConnection is closed, getRemoteStreams returning this._remoteStreams");return this._remoteStreams}return pc.getRemoteStreams&&pc.getRemoteStreams()||pc.remoteStreams||[]}},render:{writable:true,value:function render(renderHint){renderHint=renderHint||this.mediaHint&&this.mediaHint.render;if(!renderHint){return false}var streamGetters={local:"getLocalStreams",remote:"getRemoteStreams"};Object.keys(streamGetters).forEach(function(loc){var streamGetter=streamGetters[loc];var streams=this[streamGetter]();SIP.WebRTC.MediaStreamManager.render(streams,renderHint[loc])}.bind(this))}},hasOffer:{writable:true,value:function hasOffer(where){var offerState="have-"+where+"-offer";return this.peerConnection.signalingState===offerState}},prepareIceServers:{writable:true,value:function prepareIceServers(stunServers,turnServers){var servers=[],config=this.session.ua.configuration;stunServers=stunServers||config.stunServers;turnServers=turnServers||config.turnServers;[].concat(stunServers).forEach(function(server){servers.push({urls:server})});[].concat(turnServers).forEach(function(server){servers.push({urls:server.urls,username:server.username,credential:server.password})});return servers}},initPeerConnection:{writable:true,value:function initPeerConnection(servers){var self=this,config=this.session.ua.configuration;this.onIceCompleted=SIP.Utils.defer();this.onIceCompleted.promise.then(function(pc){self.emit("iceGatheringComplete",pc);if(self.iceCheckingTimer){SIP.Timers.clearTimeout(self.iceCheckingTimer);self.iceCheckingTimer=null}});if(this.peerConnection){this.peerConnection.close()}this.peerConnection=new SIP.WebRTC.RTCPeerConnection({iceServers:servers});this._remoteStreams=[];this.peerConnection.onaddstream=function(e){self.logger.log("stream added: "+e.stream.id);self._remoteStreams.push(e.stream);self.render();self.emit("addStream",e)};this.peerConnection.onremovestream=function(e){self.logger.log("stream removed: "+e.stream.id)};this.startIceCheckingTimer=function(){if(!self.iceCheckingTimer){self.iceCheckingTimer=SIP.Timers.setTimeout(function(){self.logger.log("RTCIceChecking Timeout Triggered after "+config.iceCheckingTimeout+" milliseconds");self.onIceCompleted.resolve(this)}.bind(this.peerConnection),config.iceCheckingTimeout)}};this.peerConnection.onicecandidate=function(e){self.emit("iceCandidate",e);if(e.candidate){self.logger.log("ICE candidate received: "+(e.candidate.candidate===null?null:e.candidate.candidate.trim()));self.startIceCheckingTimer()}else{self.onIceCompleted.resolve(this)}};this.peerConnection.onicegatheringstatechange=function(){self.logger.log("RTCIceGatheringState changed: "+this.iceGatheringState);if(this.iceGatheringState==="gathering"){self.emit("iceGathering",this)}if(this.iceGatheringState==="complete"){self.onIceCompleted.resolve(this)}};this.peerConnection.oniceconnectionstatechange=function(){var stateEvent;if(this.iceConnectionState==="checking"){self.startIceCheckingTimer()}switch(this.iceConnectionState){case"new":stateEvent="iceConnection";break;case"checking":stateEvent="iceConnectionChecking";break;case"connected":stateEvent="iceConnectionConnected";break;case"completed":stateEvent="iceConnectionCompleted";break;case"failed":stateEvent="iceConnectionFailed";break;case"disconnected":stateEvent="iceConnectionDisconnected";break;case"closed":stateEvent="iceConnectionClosed";break;default:self.logger.warn("Unknown iceConnection state:",this.iceConnectionState);return}self.emit(stateEvent,this)};this.peerConnection.onstatechange=function(){self.logger.log('PeerConnection state changed to "'+this.readyState+'"')}}},createOfferOrAnswer:{writable:true,value:function createOfferOrAnswer(constraints){var self=this;var methodName;var pc=self.peerConnection;self.ready=false;methodName=self.hasOffer("remote")?"createAnswer":"createOffer";return SIP.Utils.promisify(pc,methodName,true)(constraints).then(SIP.Utils.promisify(pc,"setLocalDescription")).then(function onSetLocalDescriptionSuccess(){var deferred=SIP.Utils.defer();if(pc.iceConnectionState==="complete"||pc.iceConnectionState==="completed"){deferred.resolve()}else{self.onIceCompleted.promise.then(deferred.resolve)}return deferred.promise}).then(function readySuccess(){var sdp=pc.localDescription.sdp;sdp=SIP.Hacks.Chrome.needsExplicitlyInactiveSDP(sdp);sdp=SIP.Hacks.AllBrowsers.unmaskDtls(sdp);var sdpWrapper={type:methodName==="createOffer"?"offer":"answer",sdp:sdp};self.emit("getDescription",sdpWrapper);if(self.session.ua.configuration.hackStripTcp){sdpWrapper.sdp=sdpWrapper.sdp.replace(/^a=candidate:\d+ \d+ tcp .*?\r\n/gim,"")}self.ready=true;return sdpWrapper.sdp}).catch(function methodFailed(e){self.logger.error(e);self.ready=true;throw new SIP.Exceptions.GetDescriptionError(e)})}},addStreams:{writable:true,value:function addStreams(streams){try{streams=[].concat(streams)
;streams.forEach(function(stream){this.peerConnection.addStream(stream)},this)}catch(e){this.logger.error("error adding stream");this.logger.error(e);return SIP.Utils.Promise.reject(e)}return SIP.Utils.Promise.resolve()}},toggleMuteHelper:{writable:true,value:function toggleMuteHelper(trackGetter,mute){this.getLocalStreams().forEach(function(stream){stream[trackGetter]().forEach(function(track){track.enabled=!mute})})}},toggleMuteAudio:{writable:true,value:function toggleMuteAudio(mute){this.toggleMuteHelper("getAudioTracks",mute)}},toggleMuteVideo:{writable:true,value:function toggleMuteVideo(mute){this.toggleMuteHelper("getVideoTracks",mute)}}});return MediaHandler}},{}],92:[function(require,module,exports){"use strict";module.exports=function(SIP,environment){var MediaStreamManager=function MediaStreamManager(logger,defaultMediaHint){if(!SIP.WebRTC.isSupported()){throw new SIP.Exceptions.NotSupportedError("Media not supported")}this.mediaHint=defaultMediaHint||{constraints:{audio:true,video:true}};this.acquisitions={}};MediaStreamManager.streamId=function(stream){return stream.getAudioTracks().concat(stream.getVideoTracks()).map(function trackId(track){return track.id}).join("")};MediaStreamManager.render=function render(streams,elements){if(!elements){return false}if(Array.isArray(elements)&&!elements.length){throw new TypeError("elements must not be empty")}function attachMediaStream(element,stream){element.srcObject=stream}function ensureMediaPlaying(mediaElement){var interval=100;mediaElement.ensurePlayingIntervalId=SIP.Timers.setInterval(function(){if(mediaElement.paused&&mediaElement.srcObject){mediaElement.play()}else{SIP.Timers.clearInterval(mediaElement.ensurePlayingIntervalId)}},interval)}function attachAndPlay(elements,stream,index){var element=elements[index%elements.length];if(typeof element==="function"){element=element()}(environment.attachMediaStream||attachMediaStream)(element,stream);ensureMediaPlaying(element)}elements=[].concat(elements);[].concat(streams).forEach(attachAndPlay.bind(null,elements))};MediaStreamManager.prototype=Object.create(SIP.EventEmitter.prototype,{acquire:{writable:true,value:function acquire(mediaHint){mediaHint=Object.keys(mediaHint||{}).length?mediaHint:this.mediaHint;var saveSuccess=function(isHintStream,streams){streams=[].concat(streams);streams.forEach(function(stream){var streamId=MediaStreamManager.streamId(stream);this.acquisitions[streamId]=!!isHintStream},this);return SIP.Utils.Promise.resolve(streams)}.bind(this);if(mediaHint.stream){return saveSuccess(true,mediaHint.stream)}else{var constraints=mediaHint.constraints||this.mediaHint&&this.mediaHint.constraints||{audio:true,video:true};var deferred=SIP.Utils.defer();SIP.Timers.setTimeout(function(){this.emit("userMediaRequest",constraints);var emitThenCall=function(eventName,callback){var callbackArgs=Array.prototype.slice.call(arguments,2);var newArgs=[eventName].concat(callbackArgs);this.emit.apply(this,newArgs);return callback.apply(null,callbackArgs)}.bind(this);if(constraints.audio||constraints.video){deferred.resolve(SIP.WebRTC.getUserMedia(constraints).then(emitThenCall.bind(this,"userMedia",saveSuccess.bind(null,false)),emitThenCall.bind(this,"userMediaFailed",function(e){throw e})))}else{deferred.resolve([])}}.bind(this),0);return deferred.promise}}},release:{writable:true,value:function release(streams){streams=[].concat(streams);streams.forEach(function(stream){var streamId=MediaStreamManager.streamId(stream);if(this.acquisitions[streamId]===false){stream.getTracks().forEach(function(track){track.stop()})}delete this.acquisitions[streamId]},this)}}});return MediaStreamManager}},{}],93:[function(require,module,exports){"use strict";var flatMap=require("./util").flatMap;function getStats(peerConnection,options){if(!(peerConnection&&typeof peerConnection.getStats==="function")){return Promise.reject(new Error("Given PeerConnection does not support getStats"))}return _getStats(peerConnection,options)}function _getStats(peerConnection,options){var localAudioTracks=getTracks(peerConnection,"audio","local");var localVideoTracks=getTracks(peerConnection,"video","local");var remoteAudioTracks=getTracks(peerConnection,"audio");var remoteVideoTracks=getTracks(peerConnection,"video");var statsResponse={localAudioTrackStats:[],localVideoTrackStats:[],remoteAudioTrackStats:[],remoteVideoTrackStats:[]};var trackStatsPromises=flatMap([[localAudioTracks,"localAudioTrackStats"],[localVideoTracks,"localVideoTrackStats"],[remoteAudioTracks,"remoteAudioTrackStats"],[remoteVideoTracks,"remoteVideoTrackStats"]],function(pair){var tracks=pair[0];var statsArrayName=pair[1];return tracks.map(function(track){return getTrackStats(peerConnection,track,options).then(function(stats){stats.trackId=track.id;statsResponse[statsArrayName].push(stats)})})});return Promise.all(trackStatsPromises).then(function(){return statsResponse})}function getTracks(peerConnection,kind,localOrRemote){var getStreams=localOrRemote==="local"?"getLocalStreams":"getRemoteStreams";return flatMap(peerConnection[getStreams](),function(stream){var getTracks=kind==="audio"?"getAudioTracks":"getVideoTracks";return stream[getTracks]()})}function getTrackStats(peerConnection,track,options){options=options||{};if(typeof options.testForChrome!=="undefined"||typeof webkitRTCPeerConnection!=="undefined"){return chromeGetTrackStats(peerConnection,track)}if(typeof options.testForFirefox!=="undefined"||typeof mozRTCPeerConnection!=="undefined"){return firefoxGetTrackStats(peerConnection,track)}return Promise.reject(new Error("RTCPeerConnection#getStats() not supported"))}function chromeGetTrackStats(peerConnection,track){return new Promise(function(resolve,reject){peerConnection.getStats(function(response){resolve(standardizeChromeStats(response,track))},null,reject)})}function firefoxGetTrackStats(peerConnection,track){return new Promise(function(resolve,reject){peerConnection.getStats(track,function(response){resolve(standardizeFirefoxStats(response))},reject)})}function standardizeChromeStats(response,track){var ssrcReport=response.result().find(function(report){return report.type==="ssrc"&&report.stat("googTrackId")===track.id});var standardizedStats={};if(ssrcReport){standardizedStats.timestamp=Math.round(Number(ssrcReport.timestamp));standardizedStats=ssrcReport.names().reduce(function(stats,name){switch(name){case"googCodecName":stats.codecName=ssrcReport.stat(name);break;case"googRtt":stats.roundTripTime=Number(ssrcReport.stat(name));break;case"googJitterReceived":stats.jitter=Number(ssrcReport.stat(name));break;case"googFrameWidthInput":stats.frameWidthInput=Number(ssrcReport.stat(name));break;case"googFrameHeightInput":stats.frameHeightInput=Number(ssrcReport.stat(name));break;case"googFrameWidthSent":stats.frameWidthSent=Number(ssrcReport.stat(name));break;case"googFrameHeightSent":stats.frameHeightSent=Number(ssrcReport.stat(name));break;case"googFrameWidthReceived":stats.frameWidthReceived=Number(ssrcReport.stat(name));break;case"googFrameHeightReceived":stats.frameHeightReceived=Number(ssrcReport.stat(name));break;case"googFrameRateInput":stats.frameRateInput=Number(ssrcReport.stat(name));break;case"googFrameRateSent":stats.frameRateSent=Number(ssrcReport.stat(name));break;case"googFrameRateReceived":stats.frameRateReceived=Number(ssrcReport.stat(name));break;case"ssrc":stats[name]=ssrcReport.stat(name);break;case"bytesReceived":case"bytesSent":case"packetsLost":case"packetsReceived":case"packetsSent":case"audioInputLevel":case"audioOutputLevel":stats[name]=Number(ssrcReport.stat(name));break}return stats},standardizedStats)}return standardizedStats}function standardizeFirefoxStats(response){response=response||{};var inbound=Object.keys(response).reduce(function(report,id){return response[id].type==="inboundrtp"?response[id]:report},null);var outbound=Object.keys(response).reduce(function(report,id){return response[id].type==="outboundrtp"?response[id]:report},null);var standardizedStats={};function getStatValue(name){var first=outbound;var second=inbound;if(outbound&&outbound.isRemote){first=inbound;second=outbound}if(first&&typeof first[name]!=="undefined"){return first[name]}if(second&&typeof second[name]!=="undefined"){return second[name]}return null}var timestamp=getStatValue("timestamp");standardizedStats.timestamp=Math.round(timestamp);var ssrc=getStatValue("ssrc");if(typeof ssrc==="string"){standardizedStats.ssrc=ssrc}var bytesSent=getStatValue("bytesSent");if(typeof bytesSent==="number"){standardizedStats.bytesSent=bytesSent}var packetsLost=getStatValue("packetsLost");if(typeof packetsLost==="number"){standardizedStats.packetsLost=packetsLost}var packetsSent=getStatValue("packetsSent");if(typeof packetsSent==="number"){standardizedStats.packetsSent=packetsSent}var roundTripTime=getStatValue("mozRtt");if(typeof roundTripTime==="number"){standardizedStats.roundTripTime=roundTripTime}var jitter=getStatValue("jitter");if(typeof jitter==="number"){standardizedStats.jitter=Math.round(jitter*1e3)}var frameRateSent=getStatValue("framerateMean");if(typeof frameRateSent==="number"){standardizedStats.frameRateSent=Math.round(frameRateSent)}var bytesReceived=getStatValue("bytesReceived");if(typeof bytesReceived==="number"){standardizedStats.bytesReceived=bytesReceived}var packetsReceived=getStatValue("packetsReceived");if(typeof packetsReceived==="number"){standardizedStats.packetsReceived=packetsReceived}var frameRateReceived=getStatValue("framerateMean");if(typeof frameRateReceived==="number"){standardizedStats.frameRateReceived=Math.round(frameRateReceived)}return standardizedStats}module.exports=getStats},{"./util":107}],94:[function(require,module,exports){"use strict";function getUserMedia(constraints){return new Promise(function getUserMediaPromise(resolve,reject){_getUserMedia(constraints||{audio:true,video:true},resolve,reject)})}function _getUserMedia(constraints,onSuccess,onFailure){if(typeof window!=="undefined"&&typeof navigator!=="undefined"){if(typeof navigator.mediaDevices==="object"&&typeof navigator.mediaDevices.getUserMedia==="function"){navigator.mediaDevices.getUserMedia(constraints).then(onSuccess,onFailure)}else if(typeof navigator.webkitGetUserMedia==="function"){navigator.webkitGetUserMedia(constraints,onSuccess,onFailure)}else if(typeof navigator.mozGetUserMedia==="function"){navigator.mozGetUserMedia(constraints,onSuccess,onFailure)}return}onFailure(new Error("getUserMedia is not supported"))}module.exports=getUserMedia},{}],95:[function(require,module,exports){"use strict";var WebRTC={};Object.defineProperties(WebRTC,{getStats:{enumerable:true,value:require("./getstats")},getUserMedia:{enumerable:true,value:require("./getusermedia")},MediaStream:{enumerable:true,value:require("./mediastream")},MediaStreamTrack:{enumerable:true,value:require("./mediastreamtrack")},RTCIceCandidate:{enumerable:true,value:require("./rtcicecandidate")},RTCPeerConnection:{enumerable:true,value:require("./rtcpeerconnection")},RTCSessionDescription:{enumerable:true,value:require("./rtcsessiondescription")},version:{enumerable:true,value:require("../package.json").version}});module.exports=WebRTC},{"../package.json":111,"./getstats":93,"./getusermedia":94,"./mediastream":96,"./mediastreamtrack":97,"./rtcicecandidate":98,"./rtcpeerconnection":101,"./rtcsessiondescription":105}],96:[function(require,module,exports){"use strict";if(typeof webkitMediaStream!=="undefined"){module.exports=webkitMediaStream}else if(typeof MediaStream!=="undefined"){module.exports=MediaStream}else{module.exports=function MediaStream(){throw new Error("WebRTC is not supported in this browser")}}},{}],97:[function(require,module,exports){"use strict";if(typeof MediaStreamTrack!=="undefined"){module.exports=MediaStreamTrack}else{module.exports=function MediaStreamTrack(){throw new Error("WebRTC is not supported in this browser")}}},{}],98:[function(require,module,exports){"use strict";if(typeof RTCIceCandidate!=="undefined"){module.exports=RTCIceCandidate}else if(typeof mozRTCIceCandidate!=="undefined"){module.exports=mozRTCIceCandidate}else{module.exports=function RTCIceCandidate(){throw new Error("WebRTC is unsupported")}}},{}],99:[function(require,module,exports){"use strict";var ChromeRTCSessionDescription=require("../rtcsessiondescription/chrome");var EventTarget=require("../util/eventtarget");var inherits=require("util").inherits;var Latch=require("../util/latch");var updateTracksToSSRCs=require("../util/sdp").updatePlanBTrackIdsToSSRCs;var util=require("../util");var PeerConnection=typeof RTCPeerConnection!=="undefined"?RTCPeerConnection:webkitRTCPeerConnection;function ChromeRTCPeerConnection(configuration){if(!(this instanceof ChromeRTCPeerConnection)){return new ChromeRTCPeerConnection(configuration)}EventTarget.call(this);var newConfiguration=Object.assign({},configuration);if(newConfiguration.iceTransportPolicy){newConfiguration.iceTransports=newConfiguration.iceTransportPolicy}var onsignalingstatechange=null;var peerConnection=new PeerConnection(newConfiguration);Object.defineProperties(this,{_localStreams:{value:new Set},_peerConnection:{value:peerConnection},_pendingLocalOffer:{value:null,writable:true},_pendingRemoteOffer:{value:null,writable:true},_signalingStateLatch:{value:new Latch},_tracksToSSRCs:{value:new Map},localDescription:{enumerable:true,get:function(){return this._pendingLocalOffer?this._pendingLocalOffer:peerConnection.localDescription}},onsignalingstatechange:{get:function(){return onsignalingstatechange},set:function(_onsignalingstatechange){if(onsignalingstatechange){this.removeEventListener("signalingstatechange",onsignalingstatechange)}if(typeof _onsignalingstatechange==="function"){onsignalingstatechange=_onsignalingstatechange;this.addEventListener("signalingstatechange",onsignalingstatechange)}else{onsignalingstatechange=null}}},remoteDescription:{enumerable:true,get:function(){return this._pendingRemoteOffer?this._pendingRemoteOffer:peerConnection.remoteDescription}},signalingState:{enumerable:true,get:function(){if(this._pendingLocalOffer){return"have-local-offer"}else if(this._pendingRemoteOffer){return"have-remote-offer"}return peerConnection.signalingState}}});var self=this;peerConnection.addEventListener("signalingstatechange",function onsignalingstatechange(){if(!self._pendingLocalOffer&&!self._pendingRemoteOffer){self.dispatchEvent.apply(self,arguments)}});peerConnection.ontrack=function ontrack(){};util.proxyProperties(PeerConnection.prototype,this,peerConnection)}inherits(ChromeRTCPeerConnection,EventTarget);ChromeRTCPeerConnection.prototype.addStream=function addStream(stream){if(this._localStreams.has(stream)){return}this._localStreams.add(stream);this._peerConnection.addStream(stream)};ChromeRTCPeerConnection.prototype.removeStream=function removeStream(stream){this._localStreams.delete(stream);this._peerConnection.removeStream(stream)};ChromeRTCPeerConnection.prototype.addIceCandidate=function addIceCandidate(candidate){var args=[].slice.call(arguments);var promise;var self=this;if(this.signalingState==="have-remote-offer"){promise=this._signalingStateLatch.when("low").then(function signalingStatesResolved(){return self._peerConnection.addIceCandidate(candidate)})}else{promise=this._peerConnection.addIceCandidate(candidate)}return args.length>1?util.legacyPromise(promise,args[1],args[2]):promise};ChromeRTCPeerConnection.prototype.close=function close(){if(this.signalingState!=="closed"){this._pendingLocalOffer=null;this._pendingRemoteOffer=null;this._peerConnection.close()}};ChromeRTCPeerConnection.prototype.createAnswer=function createAnswer(){var args=[].slice.call(arguments);var promise;var self=this;if(this._pendingRemoteOffer){var mediaStreamTracks=util.flatMap(this.getRemoteStreams(),function(mediaStream){return mediaStream.getTracks()});promise=this._peerConnection.setRemoteDescription(this._pendingRemoteOffer).then(function setRemoteDescriptionSucceeded(){maybeDispatchTrackEvents(self,mediaStreamTracks);self._signalingStateLatch.lower();return self._peerConnection.createAnswer()}).then(function createAnswerSucceeded(answer){self._pendingRemoteOffer=null;return answer},function setRemoteDescriptionOrCreateAnswerFailed(error){self._pendingRemoteOffer=null;throw error})}if(promise){return args.length>1?util.legacyPromise(promise,args[0],args[1]):promise}return this._peerConnection.createAnswer.apply(this._peerConnection,args)};ChromeRTCPeerConnection.prototype.createOffer=function createOffer(){var args=[].slice.call(arguments);var options=(args.length>1?args[2]:args[0])||{};var self=this;var promise=this._peerConnection.createOffer(options).then(function(offer){offer.sdp=updateTracksToSSRCs(self._tracksToSSRCs,offer.sdp);return offer});return args.length>1?util.legacyPromise(promise,args[0],args[1]):promise};ChromeRTCPeerConnection.prototype.setLocalDescription=function setLocalDescription(){var args=[].slice.call(arguments);var description=args[0];var promise=setDescription(this,true,description);return args.length>1?util.legacyPromise(promise,args[1],args[2]):promise};ChromeRTCPeerConnection.prototype.setRemoteDescription=function setRemoteDescription(){var args=[].slice.call(arguments);var description=args[0];var promise=setDescription(this,false,description);return args.length>1?util.legacyPromise(promise,args[1],args[2]):promise};util.delegateMethods(PeerConnection.prototype,ChromeRTCPeerConnection.prototype,"_peerConnection");function maybeDispatchTrackEvents(peerConnection,mediaStreamTracks){if("ontrack"in PeerConnection.prototype){return}var currentMediaStreamTracks=util.flatMap(peerConnection.getRemoteStreams(),function(mediaStream){return mediaStream.getTracks()});var mediaStreamTracksAdded=util.difference(currentMediaStreamTracks,mediaStreamTracks);mediaStreamTracksAdded.forEach(function(mediaStreamTrack){var newEvent=new Event("track");newEvent.track=mediaStreamTrack;peerConnection.dispatchEvent(newEvent)})}function setDescription(peerConnection,local,description){function setPendingLocalOffer(offer){if(local){peerConnection._pendingLocalOffer=offer}else{peerConnection._pendingRemoteOffer=offer}}function clearPendingLocalOffer(){if(local){peerConnection._pendingLocalOffer=null}else{peerConnection._pendingRemoteOffer=null}}var mediaStreamTracks=util.flatMap(peerConnection.getRemoteStreams(),function(mediaStream){return mediaStream.getTracks()});var pendingLocalOffer=local?peerConnection._pendingLocalOffer:peerConnection._pendingRemoteOffer;var pendingRemoteOffer=local?peerConnection._pendingRemoteOffer:peerConnection._pendingLocalOffer;var intermediateState=local?"have-local-offer":"have-remote-offer";var setLocalDescription=local?"setLocalDescription":"setRemoteDescription";var promise;if(!local&&pendingRemoteOffer&&description.type==="answer"){promise=setRemoteAnswer(peerConnection,description)}else if(description.type==="offer"){if(peerConnection.signalingState!==intermediateState&&peerConnection.signalingState!=="stable"){return Promise.reject(new Error("Cannot set "+(local?"local":"remote")+" offer in state "+peerConnection.signalingState))}if(!pendingLocalOffer&&peerConnection._signalingStateLatch.state==="low"){peerConnection._signalingStateLatch.raise()}var previousSignalingState=peerConnection.signalingState;setPendingLocalOffer(unwrap(description));promise=Promise.resolve();if(peerConnection.signalingState!==previousSignalingState){promise.then(function dispatchSignalingStateChangeEvent(){peerConnection.dispatchEvent(new Event("signalingstatechange"))})}}else if(description.type==="rollback"){if(peerConnection.signalingState!==intermediateState){promise=Promise.reject(new Error("Cannot rollback "+(local?"local":"remote")+" description in "+peerConnection.signalingState))}else{clearPendingLocalOffer();promise=Promise.resolve();promise.then(function dispatchSignalingStateChangeEvent(){peerConnection.dispatchEvent(new Event("signalingstatechange"))})}}return promise||peerConnection._peerConnection[setLocalDescription](unwrap(description)).then(function(){if(!local){maybeDispatchTrackEvents(peerConnection,mediaStreamTracks)}})}function setRemoteAnswer(peerConnection,answer){var mediaStreamTracks=util.flatMap(peerConnection.getRemoteStreams(),function(mediaStream){return mediaStream.getTracks()});var pendingLocalOffer=peerConnection._pendingLocalOffer;return peerConnection._peerConnection.setLocalDescription(pendingLocalOffer).then(function setLocalOfferSucceeded(){peerConnection._pendingLocalOffer=null;return peerConnection.setRemoteDescription(answer)}).then(function setRemoteAnswerSucceeded(){maybeDispatchTrackEvents(peerConnection,mediaStreamTracks);peerConnection._signalingStateLatch.lower()})}function unwrap(description){if(description instanceof ChromeRTCSessionDescription){if(description._description){return description._description}}return new RTCSessionDescription(description)}module.exports=ChromeRTCPeerConnection},{"../rtcsessiondescription/chrome":103,"../util":107,"../util/eventtarget":106,"../util/latch":108,"../util/sdp":109,util:116}],100:[function(require,module,exports){"use strict";var EventTarget=require("../util/eventtarget");var FirefoxRTCSessionDescription=require("../rtcsessiondescription/firefox");var inherits=require("util").inherits;var MediaStream=require("../mediastream");var updateTracksToSSRCs=require("../util/sdp").updateUnifiedPlanTrackIdsToSSRCs;var util=require("../util");var PeerConnection=typeof RTCPeerConnection!=="undefined"?RTCPeerConnection:mozRTCPeerConnection;function FirefoxRTCPeerConnection(configuration){if(!(this instanceof FirefoxRTCPeerConnection)){return new FirefoxRTCPeerConnection(configuration)}EventTarget.call(this);var onsignalingstatechange=null;var peerConnection=new PeerConnection(configuration);Object.defineProperties(this,{_initiallyNegotiatedDtlsRole:{value:null,writable:true},_isClosed:{value:false,writable:true},_peerConnection:{value:peerConnection},_rollingBack:{value:false,writable:true},_tracksToSSRCs:{value:new Map},iceGatheringState:{enumerable:true,get:function(){return this._isClosed?"complete":this._peerConnection.iceGatheringState}},localDescription:{enumerable:true,get:function(){return overwriteWithInitiallyNegotiatedDtlsRole(this._peerConnection.localDescription,this._initiallyNegotiatedDtlsRole)}},onsignalingstatechange:{get:function(){return onsignalingstatechange},set:function(_onsignalingstatechange){if(onsignalingstatechange){this.removeEventListener("signalingstatechange",onsignalingstatechange)}if(typeof _onsignalingstatechange==="function"){onsignalingstatechange=_onsignalingstatechange;this.addEventListener("signalingstatechange",onsignalingstatechange)}else{onsignalingstatechange=null}}},signalingState:{enumerable:true,get:function(){return this._isClosed?"closed":this._peerConnection.signalingState}}});var self=this;var previousSignalingState;peerConnection.addEventListener("signalingstatechange",function onsignalingstatechange(){if(!self._rollingBack&&self.signalingState!==previousSignalingState){previousSignalingState=self.signalingState;var dispatchEventToSelf=self.dispatchEvent.apply.bind(self.dispatchEvent,self,arguments);if(self._isClosed){setTimeout(dispatchEventToSelf)}else{dispatchEventToSelf()}}});util.proxyProperties(PeerConnection.prototype,this,peerConnection);if(!("ontrack"in PeerConnection.prototype)){peerConnection.addEventListener("addstream",function onaddstream(addStreamEvent){var mediaStream=addStreamEvent.stream;mediaStream.getTracks().forEach(function(mediaStreamTrack){var newEvent=new Event("track");newEvent.track=mediaStreamTrack;newEvent.streams=[mediaStream];self.dispatchEvent(newEvent)})})}}inherits(FirefoxRTCPeerConnection,EventTarget);FirefoxRTCPeerConnection.prototype.getLocalStreams=function getLocalStreams(){if(this._isClosed){return[]}if(!this.getSenders){return this._peerConnection.getLocalStreams()}var stream=new MediaStream;this.getSenders().forEach(function(sender){var track=sender.track;if(track){stream.addTrack(track)}});return[stream]};FirefoxRTCPeerConnection.prototype.getRemoteStreams=function getRemoteStreams(){if(this._isClosed){return[]}if(!this.getReceivers){return this._peerConnection.getRemoteStreams()}var stream=new MediaStream;this.getReceivers().forEach(function(receiver){var track=receiver.track;if(track){stream.addTrack(track)}});return[stream]};Object.defineProperty(FirefoxRTCPeerConnection.prototype,"peerIdentity",{enumerable:true,value:Promise.resolve({idp:"",name:""})});FirefoxRTCPeerConnection.prototype.removeStream=function removeStream(){};FirefoxRTCPeerConnection.prototype.addStream=function addStream(mediaStream){var localTracks=this._peerConnection.getSenders().map(function(sender){return sender.track});var newLocalTracks=util.difference(mediaStream.getTracks(),localTracks);newLocalTracks.forEach(function(mediaStreamTrack){this._peerConnection.addTrack(mediaStreamTrack,mediaStream)},this)};FirefoxRTCPeerConnection.prototype.createAnswer=function createAnswer(){var args=[].slice.call(arguments);var promise;var self=this;promise=this._peerConnection.createAnswer().then(function createAnswerSucceeded(answer){saveInitiallyNegotiatedDtlsRole(self,answer);overwriteWithInitiallyNegotiatedDtlsRole(answer,self._initiallyNegotiatedDtlsRole);return answer});return typeof args[0]==="function"?util.legacyPromise(promise,args[0],args[1]):promise};FirefoxRTCPeerConnection.prototype.createOffer=function createOffer(){var args=[].slice.call(arguments);var options=(args.length>1?args[2]:args[0])||{};var promise;var self=this;if(this.signalingState==="have-local-offer"||this.signalingState==="have-remote-offer"){var local=this.signalingState==="have-local-offer";promise=rollback(this,local,function rollbackSucceeded(){return self.createOffer(options)})}else{promise=self._peerConnection.createOffer(options)}promise=promise.then(function(offer){offer.sdp=updateTracksToSSRCs(self._tracksToSSRCs,offer.sdp);return offer});return args.length>1?util.legacyPromise(promise,args[0],args[1]):promise};FirefoxRTCPeerConnection.prototype.setLocalDescription=function setLocalDescription(){var args=[].slice.call(arguments);var description=args[0];var promise;if(description&&description.type==="answer"&&this.signalingState==="have-local-offer"){promise=Promise.reject(new Error("Cannot set local answer in state have-local-offer"))}if(promise){return args.length>1?util.legacyPromise(promise,args[1],args[2]):promise}return this._peerConnection.setLocalDescription.apply(this._peerConnection,args)};FirefoxRTCPeerConnection.prototype.setRemoteDescription=function setRemoteDescription(){var args=[].slice.call(arguments);var description=args[0];var promise;var self=this;if(description&&this.signalingState==="have-remote-offer"){if(description.type==="answer"){promise=Promise.reject(new Error("Cannot set remote answer in state have-remote-offer"))}else if(description.type==="offer"){promise=rollback(this,false,function rollbackSucceeded(){return self._peerConnection.setRemoteDescription(description)})}}if(!promise){promise=this._peerConnection.setRemoteDescription(description)}promise=promise.then(function setRemoteDescriptionSucceeded(){saveInitiallyNegotiatedDtlsRole(self,description,true)});return args.length>1?util.legacyPromise(promise,args[1],args[2]):promise};FirefoxRTCPeerConnection.prototype.close=function close(){if(this.signalingState!=="closed"){this._isClosed=true;this._peerConnection.close()}};util.delegateMethods(PeerConnection.prototype,FirefoxRTCPeerConnection.prototype,"_peerConnection");function rollback(peerConnection,local,onceRolledBack){var setLocalDescription=local?"setLocalDescription":"setRemoteDescription";peerConnection._rollingBack=true;return peerConnection._peerConnection[setLocalDescription](new FirefoxRTCSessionDescription({type:"rollback"})).then(onceRolledBack).then(function onceRolledBackSucceeded(result){peerConnection._rollingBack=false;return result},function rollbackOrOnceRolledBackFailed(error){peerConnection._rollingBack=false;throw error})}function saveInitiallyNegotiatedDtlsRole(peerConnection,description,remote){if(peerConnection._initiallyNegotiatedDtlsRole||description.type==="offer"){return}var match=description.sdp.match(/a=setup:([a-z]+)/);if(!match){return}var dtlsRole=match[1];peerConnection._initiallyNegotiatedDtlsRole=remote?{active:"passive",passive:"active"}[dtlsRole]:dtlsRole}function overwriteWithInitiallyNegotiatedDtlsRole(description,dtlsRole){if(description&&description.type==="answer"&&dtlsRole){description.sdp=description.sdp.replace(/a=setup:[a-z]+/g,"a=setup:"+dtlsRole)}return description}module.exports=FirefoxRTCPeerConnection},{"../mediastream":96,"../rtcsessiondescription/firefox":104,"../util":107,"../util/eventtarget":106,"../util/sdp":109,util:116}],101:[function(require,module,exports){"use strict";var guessBrowser=require("../util").guessBrowser;switch(guessBrowser()){case"chrome":module.exports=require("./chrome");break;case"firefox":module.exports=require("./firefox");break;case"safari":module.exports=require("./safari");break;default:if(typeof RTCPeerConnection==="undefined"){break}module.exports=RTCPeerConnection}},{"../util":107,"./chrome":99,"./firefox":100,"./safari":102}],102:[function(require,module,exports){"use strict";var EventTarget=require("../util/eventtarget");var inherits=require("util").inherits;var Latch=require("../util/latch");var TrackMatcher=require("../util/trackmatcher");var updateTracksToSSRCs=require("../util/sdp").updatePlanBTrackIdsToSSRCs;var util=require("../util");function SafariRTCPeerConnection(configuration){if(!(this instanceof SafariRTCPeerConnection)){return new SafariRTCPeerConnection(configuration)}EventTarget.call(this);var oniceconnectionstatechange=null;var onsignalingstatechange=null;var ontrack=null;var trackMatcher=new TrackMatcher;var peerConnection=new RTCPeerConnection(configuration);Object.defineProperties(this,{_audioTransceiver:{value:null,writable:true},_isClosed:{value:false,writable:true},_localStreams:{value:new Map},_peerConnection:{value:peerConnection},_pendingLocalOffer:{value:null,writable:true},_pendingRemoteOffer:{value:null,writable:true},_remoteStreams:{value:new Set},_signalingStateLatch:{value:new Latch},_tracksToSSRCs:{value:new Map},_videoTransceiver:{value:null,writable:true},localDescription:{enumerable:true,get:function(){return this._isClosed?null:this._pendingLocalOffer||this._peerConnection.localDescription}},oniceconnectionstatechange:{get:function(){return oniceconnectionstatechange},set:function(_oniceconnectionstatechange){if(oniceconnectionstatechange){this.removeEventListener("iceconnectionstatechange",oniceconnectionstatechange)}if(typeof _oniceconnectionstatechange==="function"){oniceconnectionstatechange=_oniceconnectionstatechange;this.addEventListener("iceconnectionstatechange",oniceconnectionstatechange)}else{oniceconnectionstatechange=null}}},onsignalingstatechange:{get:function(){return onsignalingstatechange},set:function(_onsignalingstatechange){if(onsignalingstatechange){this.removeEventListener("signalingstatechange",onsignalingstatechange)}if(typeof _onsignalingstatechange==="function"){onsignalingstatechange=_onsignalingstatechange;this.addEventListener("signalingstatechange",onsignalingstatechange)}else{onsignalingstatechange=null}}},ontrack:{get:function(){return ontrack},set:function(_ontrack){if(ontrack){this.removeEventListener("track",ontrack)}if(typeof _ontrack==="function"){ontrack=_ontrack;this.addEventListener("track",ontrack)}else{ontrack=null}}},iceConnectionState:{enumerable:true,get:function(){return this._isClosed?"closed":this._peerConnection.iceConnectionState}},iceGatheringState:{enumerable:true,get:function(){return this._isClosed?"complete":this._peerConnection.iceGatheringState}},remoteDescription:{enumerable:true,get:function(){return this._isClosed?null:this._pendingRemoteOffer||this._peerConnection.remoteDescription}},signalingState:{enumerable:true,get:function(){
if(this._isClosed){return"closed"}else if(this._pendingLocalOffer){return"have-local-offer"}else if(this._pendingRemoteOffer){return"have-remote-offer"}return this._peerConnection.signalingState}}});var self=this;peerConnection.addEventListener("iceconnectionstatechange",function oniceconnectionstatechange(){if(self._isClosed){return}self.dispatchEvent.apply(self,arguments)});peerConnection.addEventListener("signalingstatechange",function onsignalingstatechange(){if(self._isClosed){return}if(!self._pendingLocalOffer&&!self._pendingRemoteOffer){self.dispatchEvent.apply(self,arguments)}});peerConnection.addEventListener("track",function ontrack(event){var sdp=self.remoteDescription?self.remoteDescription.sdp:null;if(sdp){trackMatcher.update(sdp);var id=trackMatcher.match(event.track.kind);if(id){Object.defineProperty(event.track,"id",{value:id})}}event.streams.forEach(function(stream){self._remoteStreams.add(stream)});self.dispatchEvent(event)});util.proxyProperties(RTCPeerConnection.prototype,this,peerConnection)}inherits(SafariRTCPeerConnection,EventTarget);SafariRTCPeerConnection.prototype.addIceCandidate=function addIceCandidate(candidate){var self=this;if(this.signalingState==="have-remote-offer"){return this._signalingStateLatch.when("low").then(function signalingStatesResolved(){return self._peerConnection.addIceCandidate(candidate)})}return this._peerConnection.addIceCandidate(candidate)};SafariRTCPeerConnection.prototype.createOffer=function createOffer(options){options=Object.assign({},options);var self=this;if(options.offerToReceiveAudio&&!this._audioTransceiver){delete options.offerToReceiveAudio;this._audioTransceiver=this.addTransceiver("audio")}if(options.offerToReceiveVideo&&!this._videoTransceiver){delete options.offerToReceiveVideo;this._videoTransceiver=this.addTransceiver("video")}return this._peerConnection.createOffer(options).then(function(offer){offer.sdp=updateTracksToSSRCs(self._tracksToSSRCs,offer.sdp);return offer})};SafariRTCPeerConnection.prototype.createAnswer=function createAnswer(options){var self=this;if(this._pendingRemoteOffer){return this._peerConnection.setRemoteDescription(this._pendingRemoteOffer).then(function setRemoteDescriptionSucceeded(){self._signalingStateLatch.lower();return self._peerConnection.createAnswer()}).then(function createAnswerSucceeded(answer){self._pendingRemoteOffer=null;return answer},function setRemoteDescriptionOrCreateAnswerFailed(error){self._pendingRemoteOffer=null;throw error})}return this._peerConnection.createAnswer(options)};SafariRTCPeerConnection.prototype.setLocalDescription=function setLocalDescription(description){return setDescription(this,true,description)};SafariRTCPeerConnection.prototype.setRemoteDescription=function setRemoteDescription(description){return setDescription(this,false,description)};SafariRTCPeerConnection.prototype.close=function close(){if(this._isClosed){return}this._isClosed=true;this._peerConnection.close();var self=this;setTimeout(function(){self.dispatchEvent(new Event("iceconnectionstatechange"));self.dispatchEvent(new Event("signalingstatechange"))})};SafariRTCPeerConnection.prototype.addStream=function addStream(stream){if(this._localStreams.has(stream)){return}var tracks=new Set(stream.getTracks());this._peerConnection.getSenders().forEach(function(sender){if(tracks.has(sender.track)){tracks.delete(sender.track)}});tracks.forEach(function(track){try{this.addTrack(track,stream)}catch(error){}},this);this._localStreams.set(stream,new Set(tracks))};SafariRTCPeerConnection.prototype.removeStream=function removeStream(stream){this._localStreams.delete(stream)};SafariRTCPeerConnection.prototype.getLocalStreams=function getLocalStreams(){return Array.from(this._localStreams.keys())};SafariRTCPeerConnection.prototype.getRemoteStreams=function getRemoteStreams(){return Array.from(this._remoteStreams)};util.delegateMethods(RTCPeerConnection.prototype,SafariRTCPeerConnection.prototype,"_peerConnection");function setDescription(peerConnection,local,description){function setPendingLocalOffer(offer){if(local){peerConnection._pendingLocalOffer=offer}else{peerConnection._pendingRemoteOffer=offer}}function clearPendingLocalOffer(){if(local){peerConnection._pendingLocalOffer=null}else{peerConnection._pendingRemoteOffer=null}}var pendingLocalOffer=local?peerConnection._pendingLocalOffer:peerConnection._pendingRemoteOffer;var pendingRemoteOffer=local?peerConnection._pendingRemoteOffer:peerConnection._pendingLocalOffer;var intermediateState=local?"have-local-offer":"have-remote-offer";var setLocalDescription=local?"setLocalDescription":"setRemoteDescription";if(!local&&pendingRemoteOffer&&description.type==="answer"){return setRemoteAnswer(peerConnection,description)}else if(description.type==="offer"){if(peerConnection.signalingState!==intermediateState&&peerConnection.signalingState!=="stable"){return Promise.reject(new Error("Cannot set "+(local?"local":"remote")+" offer in state "+peerConnection.signalingState))}if(!pendingLocalOffer&&peerConnection._signalingStateLatch.state==="low"){peerConnection._signalingStateLatch.raise()}var previousSignalingState=peerConnection.signalingState;setPendingLocalOffer(description);if(peerConnection.signalingState!==previousSignalingState){return Promise.resolve().then(function dispatchSignalingStateChangeEvent(){peerConnection.dispatchEvent(new Event("signalingstatechange"))})}return Promise.resolve()}else if(description.type==="rollback"){if(peerConnection.signalingState!==intermediateState){return Promise.reject(new Error("Cannot rollback "+(local?"local":"remote")+" description in "+peerConnection.signalingState))}clearPendingLocalOffer();return Promise.resolve().then(function dispatchSignalingStateChangeEvent(){peerConnection.dispatchEvent(new Event("signalingstatechange"))})}return peerConnection._peerConnection[setLocalDescription](description)}function setRemoteAnswer(peerConnection,answer){var pendingLocalOffer=peerConnection._pendingLocalOffer;return peerConnection._peerConnection.setLocalDescription(pendingLocalOffer).then(function setLocalOfferSucceeded(){peerConnection._pendingLocalOffer=null;return peerConnection.setRemoteDescription(answer)}).then(function setRemoteAnswerSucceeded(){peerConnection._signalingStateLatch.lower()})}module.exports=SafariRTCPeerConnection},{"../util":107,"../util/eventtarget":106,"../util/latch":108,"../util/sdp":109,"../util/trackmatcher":110,util:116}],103:[function(require,module,exports){"use strict";function ChromeRTCSessionDescription(descriptionInitDict){if(!(this instanceof ChromeRTCSessionDescription)){return new ChromeRTCSessionDescription(descriptionInitDict)}var description=descriptionInitDict&&descriptionInitDict.type==="rollback"?null:new RTCSessionDescription(descriptionInitDict);var type=description?null:"rollback";var sdp=descriptionInitDict.sdp;Object.defineProperties(this,{_description:{get:function(){return description}},sdp:{enumerable:true,get:function(){return description?description.sdp:sdp},set:function(_sdp){if(description){description.sdp=_sdp;return}sdp=_sdp}},type:{enumerable:true,get:function(){return description?description.type:type},set:function(_type){if(_type==="rollback"&&description){var sdp=description.sdp;description=null;this.sdp=sdp}else if(description){description.type=_type;return}else if(["offer","answer","pranswer","rollback"].indexOf(_type)===-1){return}type=_type}}})}module.exports=ChromeRTCSessionDescription},{}],104:[function(require,module,exports){"use strict";module.exports=typeof RTCSessionDescription!=="undefined"?RTCSessionDescription:mozRTCSessionDescription},{}],105:[function(require,module,exports){"use strict";var guessBrowser=require("../util").guessBrowser;switch(guessBrowser()){case"chrome":module.exports=require("./chrome");break;case"firefox":module.exports=require("./firefox");break;default:if(typeof RTCSessionDescription==="undefined"){break}module.exports=RTCSessionDescription}},{"../util":107,"./chrome":103,"./firefox":104}],106:[function(require,module,exports){"use strict";var EventEmitter=require("events").EventEmitter;function EventTarget(){Object.defineProperties(this,{_eventEmitter:{value:new EventEmitter}})}EventTarget.prototype.dispatchEvent=function dispatchEvent(event){return this._eventEmitter.emit(event.type,event)};EventTarget.prototype.addEventListener=function addEventListener(){return this._eventEmitter.addListener.apply(this._eventEmitter,arguments)};EventTarget.prototype.removeEventListener=function removeEventListener(){return this._eventEmitter.removeListener.apply(this._eventEmitter,arguments)};module.exports=EventTarget},{events:112}],107:[function(require,module,exports){"use strict";function defer(){var deferred={};deferred.promise=new Promise(function(resolve,reject){deferred.resolve=resolve;deferred.reject=reject});return deferred}function delegateMethod(source,wrapper,target,methodName){if(methodName in wrapper){return}else if(methodName.match(/^on[a-z]+$/)){return}var type;try{type=typeof source[methodName]}catch(error){}if(type!=="function"){return}wrapper[methodName]=function(){return this[target][methodName].apply(this[target],arguments)}}function delegateMethods(source,wrapper,target){for(var methodName in source){delegateMethod(source,wrapper,target,methodName)}}function difference(list1,list2){list1=Array.isArray(list1)?new Set(list1):new Set(list1.values());list2=Array.isArray(list2)?new Set(list2):new Set(list2.values());var difference=new Set;list1.forEach(function(item){if(!list2.has(item)){difference.add(item)}});return difference}function flatMap(list,mapFn){var listArray=list instanceof Map||list instanceof Set?Array.from(list.values()):list;return listArray.reduce(function(flattened,item){var mapped=mapFn(item);return flattened.concat(mapped)},[])}function guessBrowser(){if(typeof webkitRTCPeerConnection!=="undefined"){return"chrome"}else if(typeof mozRTCPeerConnection!=="undefined"){return"firefox"}else if(typeof RTCPeerConnection!=="undefined"){if(typeof navigator!=="undefined"&&navigator.userAgent.match(/AppleWebKit\/(\d+)\./)){return"safari"}}return null}function legacyPromise(promise,onSuccess,onFailure){if(onSuccess){return promise.then(function(result){onSuccess(result)},function(error){onFailure(error)})}return promise}function makeUUID(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(c){var r=Math.random()*16|0;var v=c==="x"?r:r&3|8;return v.toString(16)})}function proxyProperties(source,wrapper,target){Object.getOwnPropertyNames(source).forEach(function(propertyName){proxyProperty(source,wrapper,target,propertyName)})}function proxyProperty(source,wrapper,target,propertyName){if(propertyName in wrapper){return}else if(propertyName.match(/^on[a-z]+$/)){Object.defineProperty(wrapper,propertyName,{value:null,writable:true});target.addEventListener(propertyName.slice(2),function(){wrapper.dispatchEvent.apply(wrapper,arguments)});return}Object.defineProperty(wrapper,propertyName,{enumerable:true,get:function(){return target[propertyName]}})}module.exports.defer=defer;module.exports.delegateMethods=delegateMethods;module.exports.difference=difference;module.exports.flatMap=flatMap;module.exports.guessBrowser=guessBrowser;module.exports.legacyPromise=legacyPromise;module.exports.makeUUID=makeUUID;module.exports.proxyProperties=proxyProperties},{}],108:[function(require,module,exports){"use strict";var defer=require("./").defer;var states={high:new Set(["low"]),low:new Set(["high"])};function Latch(initialState){if(!(this instanceof Latch)){return new Latch(initialState)}var state=initialState||"low";Object.defineProperties(this,{_state:{set:function(_state){if(state!==_state){state=_state;var whenDeferreds=this._whenDeferreds.get(state);whenDeferreds.forEach(function(deferred){deferred.resolve(this)},this);whenDeferreds.clear()}},get:function(){return state}},_whenDeferreds:{value:new Map([["high",new Set],["low",new Set]])},state:{enumerable:true,get:function(){return this._state}}})}Latch.prototype.lower=function lower(){return this.transition("low")};Latch.prototype.raise=function raise(){return this.transition("high")};Latch.prototype.transition=function transition(newState){if(!states[this.state].has(newState)){throw createUnreachableStateError(this.state,newState)}this._state=newState;return this};Latch.prototype.when=function when(state){if(this.state===state){return Promise.resolve(this)}if(!states[this.state].has(state)){return Promise.reject(createUnreachableStateError(this.state,state))}var deferred=defer();this._whenDeferreds.get(state).add(deferred);return deferred.promise};function createUnreachableStateError(from,to){return new Error('Cannot transition from "'+from+'" to "'+to+'"')}module.exports=Latch},{"./":107}],109:[function(require,module,exports){"use strict";var flatMap=require("./").flatMap;function getMatches(pattern,lines){var matches=lines.match(new RegExp(pattern,"gm"))||[];return matches.reduce(function(results,line){var match=line.match(new RegExp(pattern));return match?results.add(match[1]):results},new Set)}function getTrackIds(pattern,sdp){return getMatches(pattern,sdp)}function getPlanBTrackIds(sdp){return getTrackIds("^a=ssrc:[0-9]+ +msid:.+ +(.+) *$",sdp)}function getUnifiedPlanTrackIds(sdp){return getTrackIds("^a=msid:.+ +(.+) *$",sdp)}function getPlanBSSRCs(sdp,trackId){var pattern="^a=ssrc:([0-9]+) +msid:[^ ]+ +"+trackId+" *$";return getMatches(pattern,sdp)}function getMediaSections(sdp,kind,direction){kind=kind||".*";direction=direction||".*";return sdp.split("\r\nm=").slice(1).map(function(mediaSection){return"m="+mediaSection}).filter(function(mediaSection){var kindPattern=new RegExp("m="+kind,"gm");var directionPattern=new RegExp("a="+direction,"gm");return kindPattern.test(mediaSection)&&directionPattern.test(mediaSection)})}function getMediaSectionSSRCs(mediaSection){return Array.from(getMatches("^a=ssrc:([0-9]+) +.*$",mediaSection))}function getUnifiedPlanSSRCs(sdp,trackId){var mediaSections=getMediaSections(sdp);var msidAttrRegExp=new RegExp("^a=msid:[^ ]+ +"+trackId+" *$","gm");var matchingMediaSections=mediaSections.filter(function(mediaSection){return mediaSection.match(msidAttrRegExp)});return new Set(flatMap(matchingMediaSections,getMediaSectionSSRCs))}function getTrackIdsToSSRCs(getTrackIds,getSSRCs,sdp){return new Map(Array.from(getTrackIds(sdp)).map(function(trackId){return[trackId,getSSRCs(sdp,trackId)]}))}function getPlanBTrackIdsToSSRCs(sdp){return getTrackIdsToSSRCs(getPlanBTrackIds,getPlanBSSRCs,sdp)}function getUnifiedPlanTrackIdsToSSRCs(sdp){return getTrackIdsToSSRCs(getUnifiedPlanTrackIds,getUnifiedPlanSSRCs,sdp)}function updateTrackIdsToSSRCs(getTrackIdsToSSRCs,trackIdsToSSRCs,sdp){var newTrackIdsToSSRCs=getTrackIdsToSSRCs(sdp);var newSSRCsToOldSSRCs=new Map;newTrackIdsToSSRCs.forEach(function(ssrcs,trackId){if(!trackIdsToSSRCs.has(trackId)){trackIdsToSSRCs.set(trackId,ssrcs);return}var oldSSRCs=Array.from(trackIdsToSSRCs.get(trackId));var newSSRCs=Array.from(ssrcs);oldSSRCs.forEach(function(oldSSRC,i){var newSSRC=newSSRCs[i];newSSRCsToOldSSRCs.set(newSSRC,oldSSRC);var pattern="^a=ssrc:"+newSSRC+" (.*)$";var replacement="a=ssrc:"+oldSSRC+" $1";sdp=sdp.replace(new RegExp(pattern,"gm"),replacement)})});var pattern="^(a=ssrc-group:[^ ]+ +)(.*)$";var matches=sdp.match(new RegExp(pattern,"gm"))||[];matches.forEach(function(line){var match=line.match(new RegExp(pattern));if(!match){return}var prefix=match[1];var newSSRCs=match[2];var oldSSRCs=newSSRCs.split(" ").map(function(newSSRC){var oldSSRC=newSSRCsToOldSSRCs.get(newSSRC);return oldSSRC?oldSSRC:newSSRC}).join(" ");sdp=sdp.replace(match[0],prefix+oldSSRCs)});return sdp}function updatePlanBTrackIdsToSSRCs(trackIdsToSSRCs,sdp){return updateTrackIdsToSSRCs(getPlanBTrackIdsToSSRCs,trackIdsToSSRCs,sdp)}function updateUnifiedPlanTrackIdsToSSRCs(trackIdsToSSRCs,sdp){return updateTrackIdsToSSRCs(getUnifiedPlanTrackIdsToSSRCs,trackIdsToSSRCs,sdp)}exports.getMediaSections=getMediaSections;exports.getPlanBTrackIds=getPlanBTrackIds;exports.getUnifiedPlanTrackIds=getUnifiedPlanTrackIds;exports.getPlanBSSRCs=getPlanBSSRCs;exports.getUnifiedPlanSSRCs=getUnifiedPlanSSRCs;exports.updatePlanBTrackIdsToSSRCs=updatePlanBTrackIdsToSSRCs;exports.updateUnifiedPlanTrackIdsToSSRCs=updateUnifiedPlanTrackIdsToSSRCs},{"./":107}],110:[function(require,module,exports){"use strict";var util=require("./");var getMediaSections=require("./sdp").getMediaSections;function create(){return{matched:new Set,unmatched:new Set}}function match(mAndM){var unmatched=Array.from(mAndM.unmatched);if(!unmatched.length){return null}var id=unmatched[0];mAndM.matched.add(id);mAndM.unmatched.delete(id);return id}function update(mAndM,ids){ids=new Set(ids);var removedMatchedIds=util.difference(mAndM.matched,ids);removedMatchedIds.forEach(mAndM.matched.delete,mAndM.matched);mAndM.unmatched=util.difference(ids,mAndM.matched)}function parse(kind,sdp){var mediaSections=getMediaSections(sdp,kind);var pattern="msid: ?(.+) +(.+) ?$";return new Set(util.flatMap(mediaSections,function(mediaSection){return mediaSection.match(new RegExp(pattern,"mg"))||[]}).map(function(msid){return msid.match(new RegExp(pattern))[2]}))}function TrackMatcher(){if(!(this instanceof TrackMatcher)){return new TrackMatcher}Object.defineProperties(this,{audio:{enumerable:true,value:create()},video:{enumerable:true,value:create()}})}TrackMatcher.prototype.match=function(kind){return match(this[kind])};TrackMatcher.prototype.update=function(sdp){["audio","video"].forEach(function(kind){update(this[kind],parse(kind,sdp))},this)};module.exports=TrackMatcher},{"./":107,"./sdp":109}],111:[function(require,module,exports){module.exports={_args:[[{raw:"@twilio/webrtc@^1.0.0",scope:"@twilio",escapedName:"@twilio%2fwebrtc",name:"@twilio/webrtc",rawSpec:"^1.0.0",spec:">=1.0.0 <2.0.0",type:"range"},"/home/travis/build/twilio/twilio-video.js"]],_from:"@twilio/webrtc@>=1.0.0 <2.0.0",_id:"@twilio/webrtc@1.0.0",_inCache:true,_location:"/@twilio/webrtc",_nodeVersion:"8.2.1",_npmOperationalInternal:{host:"s3://npm-registry-packages",tmp:"tmp/webrtc-1.0.0.tgz_1503334397107_0.2456725083757192"},_npmUser:{name:"twilio-ci",email:"mroberts+twilio-ci@twilio.com"},_npmVersion:"5.3.0",_phantomChildren:{},_requested:{raw:"@twilio/webrtc@^1.0.0",scope:"@twilio",escapedName:"@twilio%2fwebrtc",name:"@twilio/webrtc",rawSpec:"^1.0.0",spec:">=1.0.0 <2.0.0",type:"range"},_requiredBy:["/"],_resolved:"https://registry.npmjs.org/@twilio/webrtc/-/webrtc-1.0.0.tgz",_shasum:"fbb968259c08fac774a6723bf5540ec5eb53425e",_shrinkwrap:null,_spec:"@twilio/webrtc@^1.0.0",_where:"/home/travis/build/twilio/twilio-video.js",author:{name:"Manjesh Malavalli",email:"mmalavalli@twilio.com"},bugs:{url:"https://github.com/twilio/twilio-webrtc.js/issues"},contributors:[{name:"Mark Roberts",email:"mroberts@twilio.com"},{name:"Ryan Rowland",email:"rrowland@twilio.com"}],dependencies:{},description:"WebRTC-related APIs and shims used by twilio-video.js",devDependencies:{browserify:"^14.4.0",envify:"^4.1.0",eslint:"^4.4.1",istanbul:"^0.4.5",karma:"^1.7.0","karma-browserify":"^5.1.1","karma-chrome-launcher":"^2.2.0","karma-firefox-launcher":"^1.0.1","karma-mocha":"^1.3.0","karma-safaritechpreview-launcher":"0.0.6","karma-spec-reporter":"0.0.31",mocha:"^3.5.0","npm-run-all":"^4.0.2","release-tool":"^0.2.2",rimraf:"^2.6.1","travis-multirunner":"^4.2.3",watchify:"^3.9.0","webrtc-adapter":"^4.2.2"},directories:{},dist:{integrity:"sha512-6ioEOuzeYoAVIO44PM884Ni1dH0Ufln68YFobqGHjRNWpJ4RZd2AkJ1FmMJgOoeS9IAw9AY3bHcHC0p4hnuo/g==",shasum:"fbb968259c08fac774a6723bf5540ec5eb53425e",tarball:"https://registry.npmjs.org/@twilio/webrtc/-/webrtc-1.0.0.tgz"},gitHead:"bc3b8ea06ff5c0d11405bffa51ede7805a0478e8",homepage:"https://github.com/twilio/twilio-webrtc.js#readme",keywords:["shim","twilio","video","webrtc"],license:"BSD-3-Clause",main:"./lib/index.js",maintainers:[{name:"twilio-ci",email:"mroberts+twilio-ci@twilio.com"}],name:"@twilio/webrtc",optionalDependencies:{},readme:"ERROR: No README data found!",repository:{type:"git",url:"git+https://github.com/twilio/twilio-webrtc.js.git"},scripts:{build:"npm-run-all clean lint test",clean:"rimraf coverage",lint:"eslint ./lib",test:"npm-run-all test:*","test:integration":"npm-run-all test:integration:*","test:integration:adapter":"karma start karma/integration.adapter.conf.js","test:integration:native":"karma start karma/integration.conf.js","test:unit":"istanbul cover node_modules/mocha/bin/_mocha -- ./test/unit/index.js"},version:"1.0.0"}},{}],112:[function(require,module,exports){function EventEmitter(){this._events=this._events||{};this._maxListeners=this._maxListeners||undefined}module.exports=EventEmitter;EventEmitter.EventEmitter=EventEmitter;EventEmitter.prototype._events=undefined;EventEmitter.prototype._maxListeners=undefined;EventEmitter.defaultMaxListeners=10;EventEmitter.prototype.setMaxListeners=function(n){if(!isNumber(n)||n<0||isNaN(n))throw TypeError("n must be a positive number");this._maxListeners=n;return this};EventEmitter.prototype.emit=function(type){var er,handler,len,args,i,listeners;if(!this._events)this._events={};if(type==="error"){if(!this._events.error||isObject(this._events.error)&&!this._events.error.length){er=arguments[1];if(er instanceof Error){throw er}else{var err=new Error('Uncaught, unspecified "error" event. ('+er+")");err.context=er;throw err}}}handler=this._events[type];if(isUndefined(handler))return false;if(isFunction(handler)){switch(arguments.length){case 1:handler.call(this);break;case 2:handler.call(this,arguments[1]);break;case 3:handler.call(this,arguments[1],arguments[2]);break;default:args=Array.prototype.slice.call(arguments,1);handler.apply(this,args)}}else if(isObject(handler)){args=Array.prototype.slice.call(arguments,1);listeners=handler.slice();len=listeners.length;for(i=0;i<len;i++)listeners[i].apply(this,args)}return true};EventEmitter.prototype.addListener=function(type,listener){var m;if(!isFunction(listener))throw TypeError("listener must be a function");if(!this._events)this._events={};if(this._events.newListener)this.emit("newListener",type,isFunction(listener.listener)?listener.listener:listener);if(!this._events[type])this._events[type]=listener;else if(isObject(this._events[type]))this._events[type].push(listener);else this._events[type]=[this._events[type],listener];if(isObject(this._events[type])&&!this._events[type].warned){if(!isUndefined(this._maxListeners)){m=this._maxListeners}else{m=EventEmitter.defaultMaxListeners}if(m&&m>0&&this._events[type].length>m){this._events[type].warned=true;console.error("(node) warning: possible EventEmitter memory "+"leak detected. %d listeners added. "+"Use emitter.setMaxListeners() to increase limit.",this._events[type].length);if(typeof console.trace==="function"){console.trace()}}}return this};EventEmitter.prototype.on=EventEmitter.prototype.addListener;EventEmitter.prototype.once=function(type,listener){if(!isFunction(listener))throw TypeError("listener must be a function");var fired=false;function g(){this.removeListener(type,g);if(!fired){fired=true;listener.apply(this,arguments)}}g.listener=listener;this.on(type,g);return this};EventEmitter.prototype.removeListener=function(type,listener){var list,position,length,i;if(!isFunction(listener))throw TypeError("listener must be a function");if(!this._events||!this._events[type])return this;list=this._events[type];length=list.length;position=-1;if(list===listener||isFunction(list.listener)&&list.listener===listener){delete this._events[type];if(this._events.removeListener)this.emit("removeListener",type,listener)}else if(isObject(list)){for(i=length;i-- >0;){if(list[i]===listener||list[i].listener&&list[i].listener===listener){position=i;break}}if(position<0)return this;if(list.length===1){list.length=0;delete this._events[type]}else{list.splice(position,1)}if(this._events.removeListener)this.emit("removeListener",type,listener)}return this};EventEmitter.prototype.removeAllListeners=function(type){var key,listeners;if(!this._events)return this;if(!this._events.removeListener){if(arguments.length===0)this._events={};else if(this._events[type])delete this._events[type];return this}if(arguments.length===0){for(key in this._events){if(key==="removeListener")continue;this.removeAllListeners(key)}this.removeAllListeners("removeListener");this._events={};return this}listeners=this._events[type];if(isFunction(listeners)){this.removeListener(type,listeners)}else if(listeners){while(listeners.length)this.removeListener(type,listeners[listeners.length-1])}delete this._events[type];return this};EventEmitter.prototype.listeners=function(type){var ret;if(!this._events||!this._events[type])ret=[];else if(isFunction(this._events[type]))ret=[this._events[type]];else ret=this._events[type].slice();return ret};EventEmitter.prototype.listenerCount=function(type){if(this._events){var evlistener=this._events[type];if(isFunction(evlistener))return 1;else if(evlistener)return evlistener.length}return 0};EventEmitter.listenerCount=function(emitter,type){return emitter.listenerCount(type)};function isFunction(arg){return typeof arg==="function"}function isNumber(arg){return typeof arg==="number"}function isObject(arg){return typeof arg==="object"&&arg!==null}function isUndefined(arg){return arg===void 0}},{}],113:[function(require,module,exports){var process=module.exports={};var cachedSetTimeout;var cachedClearTimeout;function defaultSetTimout(){throw new Error("setTimeout has not been defined")}function defaultClearTimeout(){throw new Error("clearTimeout has not been defined")}(function(){try{if(typeof setTimeout==="function"){cachedSetTimeout=setTimeout}else{cachedSetTimeout=defaultSetTimout}}catch(e){cachedSetTimeout=defaultSetTimout}try{if(typeof clearTimeout==="function"){cachedClearTimeout=clearTimeout}else{cachedClearTimeout=defaultClearTimeout}}catch(e){cachedClearTimeout=defaultClearTimeout}})();function runTimeout(fun){if(cachedSetTimeout===setTimeout){return setTimeout(fun,0)}if((cachedSetTimeout===defaultSetTimout||!cachedSetTimeout)&&setTimeout){cachedSetTimeout=setTimeout;return setTimeout(fun,0)}try{return cachedSetTimeout(fun,0)}catch(e){try{return cachedSetTimeout.call(null,fun,0)}catch(e){return cachedSetTimeout.call(this,fun,0)}}}function runClearTimeout(marker){if(cachedClearTimeout===clearTimeout){return clearTimeout(marker)}if((cachedClearTimeout===defaultClearTimeout||!cachedClearTimeout)&&clearTimeout){cachedClearTimeout=clearTimeout;return clearTimeout(marker)}try{return cachedClearTimeout(marker)}catch(e){try{return cachedClearTimeout.call(null,marker)}catch(e){return cachedClearTimeout.call(this,marker)}}}var queue=[];var draining=false;var currentQueue;var queueIndex=-1;function cleanUpNextTick(){if(!draining||!currentQueue){return}draining=false;if(currentQueue.length){queue=currentQueue.concat(queue)}else{queueIndex=-1}if(queue.length){drainQueue()}}function drainQueue(){if(draining){return}var timeout=runTimeout(cleanUpNextTick);draining=true;var len=queue.length;while(len){currentQueue=queue;queue=[];while(++queueIndex<len){if(currentQueue){currentQueue[queueIndex].run()}}queueIndex=-1;len=queue.length}currentQueue=null;draining=false;runClearTimeout(timeout)}process.nextTick=function(fun){var args=new Array(arguments.length-1);if(arguments.length>1){for(var i=1;i<arguments.length;i++){args[i-1]=arguments[i]}}queue.push(new Item(fun,args));if(queue.length===1&&!draining){runTimeout(drainQueue)}};function Item(fun,array){this.fun=fun;this.array=array}Item.prototype.run=function(){this.fun.apply(null,this.array)};process.title="browser";process.browser=true;process.env={};process.argv=[];process.version="";process.versions={};function noop(){}process.on=noop;process.addListener=noop;process.once=noop;process.off=noop;process.removeListener=noop;process.removeAllListeners=noop;process.emit=noop;process.prependListener=noop;process.prependOnceListener=noop;process.listeners=function(name){return[]};process.binding=function(name){throw new Error("process.binding is not supported")};process.cwd=function(){return"/"};process.chdir=function(dir){throw new Error("process.chdir is not supported")};process.umask=function(){return 0}},{}],114:[function(require,module,exports){if(typeof Object.create==="function"){module.exports=function inherits(ctor,superCtor){ctor.super_=superCtor;ctor.prototype=Object.create(superCtor.prototype,{constructor:{value:ctor,enumerable:false,writable:true,configurable:true}})}}else{module.exports=function inherits(ctor,superCtor){ctor.super_=superCtor;var TempCtor=function(){};TempCtor.prototype=superCtor.prototype;ctor.prototype=new TempCtor;ctor.prototype.constructor=ctor}}},{}],115:[function(require,module,exports){module.exports=function isBuffer(arg){return arg&&typeof arg==="object"&&typeof arg.copy==="function"&&typeof arg.fill==="function"&&typeof arg.readUInt8==="function"}},{}],116:[function(require,module,exports){(function(process,global){var formatRegExp=/%[sdj%]/g;exports.format=function(f){if(!isString(f)){var objects=[];for(var i=0;i<arguments.length;i++){objects.push(inspect(arguments[i]))}return objects.join(" ")}var i=1;var args=arguments;var len=args.length;var str=String(f).replace(formatRegExp,function(x){if(x==="%%")return"%";if(i>=len)return x;switch(x){case"%s":return String(args[i++]);case"%d":return Number(args[i++]);case"%j":try{return JSON.stringify(args[i++])}catch(_){return"[Circular]"}default:return x}});for(var x=args[i];i<len;x=args[++i]){if(isNull(x)||!isObject(x)){str+=" "+x}else{str+=" "+inspect(x)}}return str};exports.deprecate=function(fn,msg){if(isUndefined(global.process)){return function(){return exports.deprecate(fn,msg).apply(this,arguments)}}if(process.noDeprecation===true){return fn}var warned=false;function deprecated(){if(!warned){if(process.throwDeprecation){throw new Error(msg)}else if(process.traceDeprecation){console.trace(msg)}else{console.error(msg)}warned=true}return fn.apply(this,arguments)}return deprecated};var debugs={};var debugEnviron;exports.debuglog=function(set){if(isUndefined(debugEnviron))debugEnviron=process.env.NODE_DEBUG||"";set=set.toUpperCase();if(!debugs[set]){if(new RegExp("\\b"+set+"\\b","i").test(debugEnviron)){var pid=process.pid;debugs[set]=function(){var msg=exports.format.apply(exports,arguments);console.error("%s %d: %s",set,pid,msg)}}else{debugs[set]=function(){}}}return debugs[set]};function inspect(obj,opts){var ctx={seen:[],stylize:stylizeNoColor};if(arguments.length>=3)ctx.depth=arguments[2];if(arguments.length>=4)ctx.colors=arguments[3];if(isBoolean(opts)){ctx.showHidden=opts}else if(opts){exports._extend(ctx,opts)}if(isUndefined(ctx.showHidden))ctx.showHidden=false;if(isUndefined(ctx.depth))ctx.depth=2;if(isUndefined(ctx.colors))ctx.colors=false;if(isUndefined(ctx.customInspect))ctx.customInspect=true;if(ctx.colors)ctx.stylize=stylizeWithColor;return formatValue(ctx,obj,ctx.depth)}exports.inspect=inspect;inspect.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]};inspect.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"};function stylizeWithColor(str,styleType){var style=inspect.styles[styleType];if(style){return"\x1b["+inspect.colors[style][0]+"m"+str+"\x1b["+inspect.colors[style][1]+"m"}else{return str}}function stylizeNoColor(str,styleType){return str}function arrayToHash(array){var hash={};array.forEach(function(val,idx){hash[val]=true});return hash}function formatValue(ctx,value,recurseTimes){if(ctx.customInspect&&value&&isFunction(value.inspect)&&value.inspect!==exports.inspect&&!(value.constructor&&value.constructor.prototype===value)){var ret=value.inspect(recurseTimes,ctx);if(!isString(ret)){ret=formatValue(ctx,ret,recurseTimes)}return ret}var primitive=formatPrimitive(ctx,value);if(primitive){
return primitive}var keys=Object.keys(value);var visibleKeys=arrayToHash(keys);if(ctx.showHidden){keys=Object.getOwnPropertyNames(value)}if(isError(value)&&(keys.indexOf("message")>=0||keys.indexOf("description")>=0)){return formatError(value)}if(keys.length===0){if(isFunction(value)){var name=value.name?": "+value.name:"";return ctx.stylize("[Function"+name+"]","special")}if(isRegExp(value)){return ctx.stylize(RegExp.prototype.toString.call(value),"regexp")}if(isDate(value)){return ctx.stylize(Date.prototype.toString.call(value),"date")}if(isError(value)){return formatError(value)}}var base="",array=false,braces=["{","}"];if(isArray(value)){array=true;braces=["[","]"]}if(isFunction(value)){var n=value.name?": "+value.name:"";base=" [Function"+n+"]"}if(isRegExp(value)){base=" "+RegExp.prototype.toString.call(value)}if(isDate(value)){base=" "+Date.prototype.toUTCString.call(value)}if(isError(value)){base=" "+formatError(value)}if(keys.length===0&&(!array||value.length==0)){return braces[0]+base+braces[1]}if(recurseTimes<0){if(isRegExp(value)){return ctx.stylize(RegExp.prototype.toString.call(value),"regexp")}else{return ctx.stylize("[Object]","special")}}ctx.seen.push(value);var output;if(array){output=formatArray(ctx,value,recurseTimes,visibleKeys,keys)}else{output=keys.map(function(key){return formatProperty(ctx,value,recurseTimes,visibleKeys,key,array)})}ctx.seen.pop();return reduceToSingleString(output,base,braces)}function formatPrimitive(ctx,value){if(isUndefined(value))return ctx.stylize("undefined","undefined");if(isString(value)){var simple="'"+JSON.stringify(value).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return ctx.stylize(simple,"string")}if(isNumber(value))return ctx.stylize(""+value,"number");if(isBoolean(value))return ctx.stylize(""+value,"boolean");if(isNull(value))return ctx.stylize("null","null")}function formatError(value){return"["+Error.prototype.toString.call(value)+"]"}function formatArray(ctx,value,recurseTimes,visibleKeys,keys){var output=[];for(var i=0,l=value.length;i<l;++i){if(hasOwnProperty(value,String(i))){output.push(formatProperty(ctx,value,recurseTimes,visibleKeys,String(i),true))}else{output.push("")}}keys.forEach(function(key){if(!key.match(/^\d+$/)){output.push(formatProperty(ctx,value,recurseTimes,visibleKeys,key,true))}});return output}function formatProperty(ctx,value,recurseTimes,visibleKeys,key,array){var name,str,desc;desc=Object.getOwnPropertyDescriptor(value,key)||{value:value[key]};if(desc.get){if(desc.set){str=ctx.stylize("[Getter/Setter]","special")}else{str=ctx.stylize("[Getter]","special")}}else{if(desc.set){str=ctx.stylize("[Setter]","special")}}if(!hasOwnProperty(visibleKeys,key)){name="["+key+"]"}if(!str){if(ctx.seen.indexOf(desc.value)<0){if(isNull(recurseTimes)){str=formatValue(ctx,desc.value,null)}else{str=formatValue(ctx,desc.value,recurseTimes-1)}if(str.indexOf("\n")>-1){if(array){str=str.split("\n").map(function(line){return"  "+line}).join("\n").substr(2)}else{str="\n"+str.split("\n").map(function(line){return"   "+line}).join("\n")}}}else{str=ctx.stylize("[Circular]","special")}}if(isUndefined(name)){if(array&&key.match(/^\d+$/)){return str}name=JSON.stringify(""+key);if(name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)){name=name.substr(1,name.length-2);name=ctx.stylize(name,"name")}else{name=name.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'");name=ctx.stylize(name,"string")}}return name+": "+str}function reduceToSingleString(output,base,braces){var numLinesEst=0;var length=output.reduce(function(prev,cur){numLinesEst++;if(cur.indexOf("\n")>=0)numLinesEst++;return prev+cur.replace(/\u001b\[\d\d?m/g,"").length+1},0);if(length>60){return braces[0]+(base===""?"":base+"\n ")+" "+output.join(",\n  ")+" "+braces[1]}return braces[0]+base+" "+output.join(", ")+" "+braces[1]}function isArray(ar){return Array.isArray(ar)}exports.isArray=isArray;function isBoolean(arg){return typeof arg==="boolean"}exports.isBoolean=isBoolean;function isNull(arg){return arg===null}exports.isNull=isNull;function isNullOrUndefined(arg){return arg==null}exports.isNullOrUndefined=isNullOrUndefined;function isNumber(arg){return typeof arg==="number"}exports.isNumber=isNumber;function isString(arg){return typeof arg==="string"}exports.isString=isString;function isSymbol(arg){return typeof arg==="symbol"}exports.isSymbol=isSymbol;function isUndefined(arg){return arg===void 0}exports.isUndefined=isUndefined;function isRegExp(re){return isObject(re)&&objectToString(re)==="[object RegExp]"}exports.isRegExp=isRegExp;function isObject(arg){return typeof arg==="object"&&arg!==null}exports.isObject=isObject;function isDate(d){return isObject(d)&&objectToString(d)==="[object Date]"}exports.isDate=isDate;function isError(e){return isObject(e)&&(objectToString(e)==="[object Error]"||e instanceof Error)}exports.isError=isError;function isFunction(arg){return typeof arg==="function"}exports.isFunction=isFunction;function isPrimitive(arg){return arg===null||typeof arg==="boolean"||typeof arg==="number"||typeof arg==="string"||typeof arg==="symbol"||typeof arg==="undefined"}exports.isPrimitive=isPrimitive;exports.isBuffer=require("./support/isBuffer");function objectToString(o){return Object.prototype.toString.call(o)}function pad(n){return n<10?"0"+n.toString(10):n.toString(10)}var months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function timestamp(){var d=new Date;var time=[pad(d.getHours()),pad(d.getMinutes()),pad(d.getSeconds())].join(":");return[d.getDate(),months[d.getMonth()],time].join(" ")}exports.log=function(){console.log("%s - %s",timestamp(),exports.format.apply(exports,arguments))};exports.inherits=require("inherits");exports._extend=function(origin,add){if(!add||!isObject(add))return origin;var keys=Object.keys(add);var i=keys.length;while(i--){origin[keys[i]]=add[keys[i]]}return origin};function hasOwnProperty(obj,prop){return Object.prototype.hasOwnProperty.call(obj,prop)}}).call(this,require("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./support/isBuffer":115,_process:113,inherits:114}],117:[function(require,module,exports){module.exports={name:"twilio-video",title:"Twilio Video",description:"Twilio Video JavaScript library",version:"1.2.2",homepage:"https://twilio.com",author:"Mark Andrus Roberts <mroberts@twilio.com>",contributors:["Ryan Rowland <rrowland@twilio.com>","Manjesh Malavalli <mmalavalli@twilio.com>"],keywords:["twilio","webrtc","library","javascript","video","rooms"],repository:{type:"git",url:"https://github.com/twilio/twilio-video.js.git"},devDependencies:{browserify:"^14.3.0",cheerio:"^0.22.0",chromedriver:"2.28.0",envify:"^4.0.0",eslint:"^3.19.0",geckodriver:"1.4.0","ink-docstrap":"^1.3.0",istanbul:"^0.4.5",jsdoc:"^3.4.3",karma:"^1.6.0","karma-browserify":"^5.1.1","karma-chrome-launcher":"^2.0.0","karma-firefox-launcher":"^1.0.1","karma-mocha":"^1.3.0","karma-safaritechpreview-launcher":"0.0.6","karma-spec-reporter":"^0.0.31",mocha:"^3.2.0","mock-browser":"^0.92.14","npm-run-all":"^4.0.2",phantom:"^4.0.2","release-tool":"^0.2.2",requirejs:"^2.3.3",rimraf:"^2.6.1","selenium-webdriver":"3.3.0",sinon:"^2.1.0","travis-multirunner":"^4.0.0",twilio:"^2.11.1","uglify-js":"^2.8.22","vinyl-fs":"^2.4.4","vinyl-source-stream":"^1.1.0","webrtc-adapter":"^4.1.1"},engines:{node:">=0.12"},license:"BSD-3-Clause",main:"./lib/index.js",scripts:{lint:"eslint ./lib","test:unit":"mocha ./test/unit/index.js","test:integration:adapter":"node ./scripts/karma.js karma/integration.adapter.conf.js","test:integration:travis":"node ./scripts/integration.js","test:integration":"node ./scripts/karma.js karma/integration.conf.js","test:umd":"mocha ./test/umd/index.js","test:framework:angular:install":"cd ./test/framework/twilio-video-angular && rimraf ./node_modules && npm install","test:framework:angular:test":"node ./scripts/framework.js twilio-video-angular","test:framework:angular:run":"mocha ./test/framework/twilio-video-angular.js","test:framework:angular":"npm-run-all test:framework:angular:*","test:framework:meteor:install":"cd ./test/framework/twilio-video-meteor && rimraf ./node_modules && npm install","test:framework:meteor:test":"node ./scripts/framework.js twilio-video-meteor","test:framework:meteor:run":"mocha ./test/framework/twilio-video-meteor.js","test:framework:meteor":"npm-run-all test:framework:meteor:*","test:framework:no-framework:run":"mocha ./test/framework/twilio-video-no-framework.js","test:framework:no-framework":"npm-run-all test:framework:no-framework:*","test:framework:react:install":"cd ./test/framework/twilio-video-react && rimraf ./node_modules && npm install","test:framework:react:test":"node ./scripts/framework.js twilio-video-react","test:framework:react:build":"cd ./test/framework/twilio-video-react && npm run build","test:framework:react:run":"mocha ./test/framework/twilio-video-react.js","test:framework:react":"npm-run-all test:framework:react:*","test:framework":"npm-run-all test:framework:angular test:framework:meteor test:framework:no-framework test:framework:react",test:"npm-run-all test:unit test:integration","build:js":"node ./scripts/build.js ./src/twilio-video.js ./LICENSE.md ./dist/twilio-video.js","build:min.js":'uglifyjs ./dist/twilio-video.js -o ./dist/twilio-video.min.js --comments "/^! twilio-video.js/" -b beautify=false,ascii_only=true',build:"npm-run-all clean lint docs cover test:integration build:js build:min.js test:umd","build:travis":"npm-run-all clean lint docs cover test:integration:travis build:js build:min.js test:umd test:framework","build:quick":"npm-run-all clean lint docs build:js build:min.js",docs:"node ./scripts/docs.js ./dist/docs",clean:"rimraf ./coverage ./dist",cover:"istanbul cover node_modules/mocha/bin/_mocha -- ./test/unit/index.js"},dependencies:{"@twilio/sip.js":"^0.7.6","@twilio/webrtc":"^1.0.0",ws:"^2.3.1",xmlhttprequest:"^1.8.0"},browser:{ws:"./src/ws.js",xmlhttprequest:"./src/xmlhttprequest.js"}}},{}],118:[function(require,module,exports){module.exports=WebSocket},{}],119:[function(require,module,exports){exports.XMLHttpRequest=XMLHttpRequest},{}]},{},[8]);var Video=bundle(8);if(typeof define==="function"&&define.amd){define([],function(){return Video})}else{var Twilio=root.Twilio=root.Twilio||{};Twilio.Video=Twilio.Video||Video}})(typeof window!=="undefined"?window:typeof global!=="undefined"?global:this);