sip-connector 6.13.4 → 6.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es5.js +1 -1
- package/dist/index.es5.js.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/logger.d.ts +7 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +21 -0
- package/dist/logger.js.map +1 -0
- package/dist/tools/__fixtures__/call.d.ts +11 -0
- package/dist/tools/__fixtures__/call.d.ts.map +1 -0
- package/dist/tools/__fixtures__/call.js +38 -0
- package/dist/tools/__fixtures__/call.js.map +1 -0
- package/dist/tools/__fixtures__/connectToServer.d.ts +151 -0
- package/dist/tools/__fixtures__/connectToServer.d.ts.map +1 -0
- package/dist/tools/__fixtures__/connectToServer.js +35 -0
- package/dist/tools/__fixtures__/connectToServer.js.map +1 -0
- package/dist/tools/__fixtures__/hasValidUri.d.ts +10 -0
- package/dist/tools/__fixtures__/hasValidUri.d.ts.map +1 -0
- package/dist/tools/__fixtures__/hasValidUri.js +14 -0
- package/dist/tools/__fixtures__/hasValidUri.js.map +1 -0
- package/dist/tools/__fixtures__/permissions.d.ts +9 -0
- package/dist/tools/__fixtures__/permissions.d.ts.map +1 -0
- package/dist/tools/__fixtures__/permissions.js +15 -0
- package/dist/tools/__fixtures__/permissions.js.map +1 -0
- package/dist/tools/__fixtures__/processRequest.d.ts +4 -0
- package/dist/tools/__fixtures__/processRequest.d.ts.map +1 -0
- package/dist/tools/__fixtures__/processRequest.js +71 -0
- package/dist/tools/__fixtures__/processRequest.js.map +1 -0
- package/dist/tools/__tests-utils__/parseObject.d.ts +4 -0
- package/dist/tools/__tests-utils__/parseObject.d.ts.map +1 -0
- package/dist/tools/__tests-utils__/parseObject.js +27 -0
- package/dist/tools/__tests-utils__/parseObject.js.map +1 -0
- package/dist/tools/__tests-utils__/resolveParseArray.d.ts +3 -0
- package/dist/tools/__tests-utils__/resolveParseArray.d.ts.map +1 -0
- package/dist/tools/__tests-utils__/resolveParseArray.js +17 -0
- package/dist/tools/__tests-utils__/resolveParseArray.js.map +1 -0
- package/dist/tools/answerIncomingCall.d.ts +22 -0
- package/dist/tools/answerIncomingCall.d.ts.map +1 -0
- package/dist/tools/answerIncomingCall.js +94 -0
- package/dist/tools/answerIncomingCall.js.map +1 -0
- package/dist/tools/callToServer.d.ts +23 -0
- package/dist/tools/callToServer.d.ts.map +1 -0
- package/dist/tools/callToServer.js +90 -0
- package/dist/tools/callToServer.js.map +1 -0
- package/dist/tools/connectToServer.d.ts +15 -0
- package/dist/tools/connectToServer.d.ts.map +1 -0
- package/dist/tools/connectToServer.js +52 -0
- package/dist/tools/connectToServer.js.map +1 -0
- package/dist/tools/disconnectFromServer.d.ts +4 -0
- package/dist/tools/disconnectFromServer.d.ts.map +1 -0
- package/dist/tools/disconnectFromServer.js +23 -0
- package/dist/tools/disconnectFromServer.js.map +1 -0
- package/dist/tools/error/getLinkError.d.ts +4 -0
- package/dist/tools/error/getLinkError.d.ts.map +1 -0
- package/dist/tools/error/getLinkError.js +36 -0
- package/dist/tools/error/getLinkError.js.map +1 -0
- package/dist/tools/error/getTypeFromError.d.ts +12 -0
- package/dist/tools/error/getTypeFromError.d.ts.map +1 -0
- package/dist/tools/error/getTypeFromError.js +63 -0
- package/dist/tools/error/getTypeFromError.js.map +1 -0
- package/dist/tools/error/getValuesFromError.d.ts +10 -0
- package/dist/tools/error/getValuesFromError.d.ts.map +1 -0
- package/dist/tools/error/getValuesFromError.js +26 -0
- package/dist/tools/error/getValuesFromError.js.map +1 -0
- package/dist/tools/error/index.d.ts +5 -0
- package/dist/tools/error/index.d.ts.map +1 -0
- package/dist/tools/error/index.js +13 -0
- package/dist/tools/error/index.js.map +1 -0
- package/dist/tools/hasPurgatory.d.ts +4 -0
- package/dist/tools/hasPurgatory.d.ts.map +1 -0
- package/dist/tools/hasPurgatory.js +9 -0
- package/dist/tools/hasPurgatory.js.map +1 -0
- package/dist/tools/index.d.ts +20 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +66 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/resolveAskPermissionToEnableCam.d.ts +4 -0
- package/dist/tools/resolveAskPermissionToEnableCam.d.ts.map +1 -0
- package/dist/tools/resolveAskPermissionToEnableCam.js +18 -0
- package/dist/tools/resolveAskPermissionToEnableCam.js.map +1 -0
- package/dist/tools/resolveGetRemoteStreams.d.ts +4 -0
- package/dist/tools/resolveGetRemoteStreams.d.ts.map +1 -0
- package/dist/tools/resolveGetRemoteStreams.js +15 -0
- package/dist/tools/resolveGetRemoteStreams.js.map +1 -0
- package/dist/tools/resolveHandleChangeTracks.d.ts +5 -0
- package/dist/tools/resolveHandleChangeTracks.d.ts.map +1 -0
- package/dist/tools/resolveHandleChangeTracks.js +14 -0
- package/dist/tools/resolveHandleChangeTracks.js.map +1 -0
- package/dist/tools/resolveOnMustStopPresentation.d.ts +4 -0
- package/dist/tools/resolveOnMustStopPresentation.d.ts.map +1 -0
- package/dist/tools/resolveOnMustStopPresentation.js +15 -0
- package/dist/tools/resolveOnMustStopPresentation.js.map +1 -0
- package/dist/tools/resolveOnUseLicense.d.ts +5 -0
- package/dist/tools/resolveOnUseLicense.d.ts.map +1 -0
- package/dist/tools/resolveOnUseLicense.js +15 -0
- package/dist/tools/resolveOnUseLicense.js.map +1 -0
- package/dist/tools/resolveSendMediaState.d.ts +7 -0
- package/dist/tools/resolveSendMediaState.d.ts.map +1 -0
- package/dist/tools/resolveSendMediaState.js +18 -0
- package/dist/tools/resolveSendMediaState.js.map +1 -0
- package/dist/tools/resolveSendRefusalToTurnOnCam.d.ts +4 -0
- package/dist/tools/resolveSendRefusalToTurnOnCam.d.ts.map +1 -0
- package/dist/tools/resolveSendRefusalToTurnOnCam.js +20 -0
- package/dist/tools/resolveSendRefusalToTurnOnCam.js.map +1 -0
- package/dist/tools/resolveSendRefusalToTurnOnMic.d.ts +4 -0
- package/dist/tools/resolveSendRefusalToTurnOnMic.d.ts.map +1 -0
- package/dist/tools/resolveSendRefusalToTurnOnMic.js +20 -0
- package/dist/tools/resolveSendRefusalToTurnOnMic.js.map +1 -0
- package/dist/tools/resolveStartPresentation.d.ts +10 -0
- package/dist/tools/resolveStartPresentation.d.ts.map +1 -0
- package/dist/tools/resolveStartPresentation.js +19 -0
- package/dist/tools/resolveStartPresentation.js.map +1 -0
- package/dist/tools/resolveStopShareSipConnector.d.ts +8 -0
- package/dist/tools/resolveStopShareSipConnector.d.ts.map +1 -0
- package/dist/tools/resolveStopShareSipConnector.js +19 -0
- package/dist/tools/resolveStopShareSipConnector.js.map +1 -0
- package/dist/tools/resolveUpdatePresentation.d.ts +10 -0
- package/dist/tools/resolveUpdatePresentation.d.ts.map +1 -0
- package/dist/tools/resolveUpdatePresentation.js +19 -0
- package/dist/tools/resolveUpdatePresentation.js.map +1 -0
- package/dist/tools/resolveUpdateRemoteStreams.d.ts +6 -0
- package/dist/tools/resolveUpdateRemoteStreams.d.ts.map +1 -0
- package/dist/tools/resolveUpdateRemoteStreams.js +18 -0
- package/dist/tools/resolveUpdateRemoteStreams.js.map +1 -0
- package/dist/tools/sendDTMFAccumulated.d.ts +10 -0
- package/dist/tools/sendDTMFAccumulated.d.ts.map +1 -0
- package/dist/tools/sendDTMFAccumulated.js +26 -0
- package/dist/tools/sendDTMFAccumulated.js.map +1 -0
- package/dist/tools/syncMediaState/index.d.ts +19 -0
- package/dist/tools/syncMediaState/index.d.ts.map +1 -0
- package/dist/tools/syncMediaState/index.js +55 -0
- package/dist/tools/syncMediaState/index.js.map +1 -0
- package/dist/tools/syncMediaState/resolveOnStartMainCam.d.ts +6 -0
- package/dist/tools/syncMediaState/resolveOnStartMainCam.d.ts.map +1 -0
- package/dist/tools/syncMediaState/resolveOnStartMainCam.js +15 -0
- package/dist/tools/syncMediaState/resolveOnStartMainCam.js.map +1 -0
- package/dist/tools/syncMediaState/resolveOnStartMic.d.ts +6 -0
- package/dist/tools/syncMediaState/resolveOnStartMic.d.ts.map +1 -0
- package/dist/tools/syncMediaState/resolveOnStartMic.js +15 -0
- package/dist/tools/syncMediaState/resolveOnStartMic.js.map +1 -0
- package/dist/tools/syncMediaState/resolveOnStopMainCam.d.ts +6 -0
- package/dist/tools/syncMediaState/resolveOnStopMainCam.d.ts.map +1 -0
- package/dist/tools/syncMediaState/resolveOnStopMainCam.js +15 -0
- package/dist/tools/syncMediaState/resolveOnStopMainCam.js.map +1 -0
- package/dist/tools/syncMediaState/resolveOnStopMic.d.ts +6 -0
- package/dist/tools/syncMediaState/resolveOnStopMic.d.ts.map +1 -0
- package/dist/tools/syncMediaState/resolveOnStopMic.js +15 -0
- package/dist/tools/syncMediaState/resolveOnStopMic.js.map +1 -0
- package/package.json +8 -7
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ import getCodecFromSender from './utils/getCodecFromSender';
|
|
|
2
2
|
import SipConnector, { hasCanceledCallError, EUseLicense } from './SipConnector';
|
|
3
3
|
import resolveVideoSendingBalancer from './videoSendingBalancer';
|
|
4
4
|
import * as causes from './causes';
|
|
5
|
+
import * as tools from './tools';
|
|
5
6
|
import * as eventNames from './eventNames';
|
|
6
|
-
export {
|
|
7
|
+
export { debug, disableDebug, enableDebug } from './logger';
|
|
8
|
+
export { causes, tools, eventNames, hasCanceledCallError, EUseLicense, resolveVideoSendingBalancer, getCodecFromSender, };
|
|
7
9
|
export default SipConnector;
|
|
8
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,4BAA4B,CAAC;AAC5D,OAAO,YAAY,EAAE,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,2BAA2B,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAE3C,OAAO,EACL,MAAM,EACN,UAAU,EACV,oBAAoB,EACpB,WAAW,EACX,2BAA2B,EAC3B,kBAAkB,GACnB,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,4BAA4B,CAAC;AAC5D,OAAO,YAAY,EAAE,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,2BAA2B,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5D,OAAO,EACL,MAAM,EACN,KAAK,EACL,UAAU,EACV,oBAAoB,EACpB,WAAW,EACX,2BAA2B,EAC3B,kBAAkB,GACnB,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
package/dist/index.es5.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{CancelableRequest as e,isCanceledError as t}from"@krivega/cancelable-promise";import n from"events-constructor";import s from"stack-promises";const i=e=>e.getStats().then((e=>{const t=(n="codec",(e=>[...e.keys()].map((t=>e.get(t))))(e).find((e=>e.type===n)));var n;return null==t?void 0:t.mimeType}));function r(e,t,n,s){return new(n||(n=Promise))((function(i,r){function o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))}const o="Terminated";var a=Object.freeze({__proto__:null,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",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:o,WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"});const c=["incomingCall","declinedIncomingCall","terminatedIncomingCall","failedIncomingCall","participant:canceling-word-request","participant:move-request-to-stream","participant:move-request-to-conference","channels:notify","conference:participant-token-issued","account:changed","account:deleted","webcast:started","webcast:stopped","participant:added-to-list-moderators","participant:removed-from-list-moderators"],d=["connecting","connected","disconnected","newRTCSession","registered","unregistered","registrationFailed","newMessage","sipEvent"],h=["availableSecondRemoteStream","notAvailableSecondRemoteStream","mustStopPresentation","shareState","enterRoom","useLicense","peerconnection:confirmed","peerconnection:ontrack","channels","ended:fromserver","main-cam-control","admin-start-main-cam","admin-stop-main-cam","admin-stop-mic","admin-start-mic","admin-force-sync-media-state"],l=["ended","connecting","sending","reinvite","replaces","refer","progress","accepted","confirmed","peerconnection","failed","muted","unmuted","newDTMF","newInfo","hold","unhold","update","sdp","icecandidate","getusermediafailed","peerconnection:createofferfailed","peerconnection:createanswerfailed","peerconnection:setlocaldescriptionfailed","peerconnection:setremotedescriptionfailed","presentation:start","presentation:started","presentation:end","presentation:ended","presentation:failed"],u=[...d,...c],g=[...l,...h];var m=Object.freeze({__proto__:null,UA_SYNTHETICS_EVENT_NAMES:c,UA_JSSIP_EVENT_NAMES:d,SESSION_SYNTHETICS_EVENT_NAMES:h,SESSION_JSSIP_EVENT_NAMES:l,UA_EVENT_NAMES:u,SESSION_EVENT_NAMES:g});const _=e=>e.trim().replace(/ /g,"_"),S=(f=1e5,E=99999999,()=>Math.floor(Math.random()*(E-f))+f);var f,E;const v=(e,{videoMode:t,audioMode:n}={})=>{if(!e||"recvonly"===t&&"recvonly"===n)return;const s=[..."recvonly"===n?[]:e.getAudioTracks(),..."recvonly"===t?[]:e.getVideoTracks()],i=new MediaStream(s);return i.getTracks=()=>[...i.getAudioTracks(),...i.getVideoTracks()],i},C=e=>(t,n)=>void 0!==n&&t!==n||void 0===n&&t!==e,p=C(1),N=C(void 0),T=(e,t,n)=>{const s=e.getParameters();s.encodings&&0!==s.encodings.length||(s.encodings=[{}]);const[i]=s.encodings,r=i.scaleResolutionDownBy,o=((e,t)=>{const n=void 0!==e?Math.max(e,1):null;if(null!==n&&p(n,t))return n})(t.scaleResolutionDownBy,r);let a=!1;void 0!==o&&(s.encodings[0].scaleResolutionDownBy=o,a=!0);const c=i.maxBitrate,d=((e,t)=>{if(N(e,t))return e})(t.maxBitrate,c);return void 0!==d&&(s.encodings[0].maxBitrate=d,a=!0),a?(n&&n(s),e.setParameters(s).then((()=>({parameters:s,isChanged:a})))):Promise.resolve({parameters:s,isChanged:a})};var R,w,M,A;!function(e){e.PAUSE_MAIN_CAM="PAUSEMAINCAM",e.RESUME_MAIN_CAM="RESUMEMAINCAM",e.MAX_MAIN_CAM_RESOLUTION="MAXMAINCAMRESOLUTION",e.ADMIN_STOP_MAIN_CAM="ADMINSTOPMAINCAM",e.ADMIN_START_MAIN_CAM="ADMINSTARTMAINCAM"}(R||(R={})),function(e){e.ADMIN_STOP_MIC="ADMINSTOPMIC",e.ADMIN_START_MIC="ADMINSTARTMIC"}(w||(w={})),function(e){e.ADMIN_SYNC_FORCED="1",e.ADMIN_SYNC_NOT_FORCED="0"}(M||(M={})),function(e){e.AUDIO="AUDIO",e.VIDEO="VIDEO",e.AUDIOPLUSPRESENTATION="AUDIOPLUSPRESENTATION"}(A||(A={}));const P=(e=new Error)=>{const{originator:n,cause:s}=e;return!!t(e)||"string"==typeof s&&("Request Timeout"===s||"Rejected"===s||"local"===n&&("Canceled"===s||s===o))},I="SipConnector";class b{constructor({JsSIP:t}){this._isRegisterConfig=!1,this._connectionConfiguration={},this._remoteStreams={},this.getSipServerUrl=e=>e,this.connect=e=>(this._cancelRequests(),this._cancelableConnect.request(e)),this.createUa=e=>this._cancelableCreateUa.request(e),this.set=e=>this._cancelableSet.request(e),this.call=e=>this._cancelableCall.request(e),this.disconnect=()=>(this._cancelRequests(),this._disconnectWithoutCancelRequests()),this.answerToIncomingCall=e=>this._cancelableAnswer.request(e),this.sendDTMF=e=>this._cancelableSendDTMF.request(e),this.hangUp=()=>(this._cancelRequests(),this._hangUpWithoutCancelRequests()),this.tryRegister=()=>this.isRegisterConfig?(this._uaEvents.trigger("connecting",void 0),this.unregister().finally((()=>this.register())).finally((()=>{}))):Promise.reject(new Error("Config is not registered")),this.declineToIncomingCall=({statusCode:e=487}={})=>new Promise(((t,n)=>{if(!this.isAvailableIncomingCall)return void n(new Error("no incomingSession"));const s=this.incomingSession,i=this.remoteCallerData;this._cancelableCall.cancelRequest(),this._cancelableAnswer.cancelRequest(),this.removeIncomingSession(),this._uaEvents.trigger("declinedIncomingCall",i),t(s.terminate({status_code:e}))})),this.busyIncomingCall=()=>this.declineToIncomingCall({statusCode:486}),this.removeIncomingSession=()=>{delete this.incomingSession},this.handleNewRTCSession=({originator:e,session:t})=>{if("remote"===e){this.incomingSession=t;const e=this.remoteCallerData;t.on("failed",(({originator:t})=>{this.removeIncomingSession(),"local"!==t?this._uaEvents.trigger("failedIncomingCall",e):this._uaEvents.trigger("terminatedIncomingCall",e)})),this._uaEvents.trigger("incomingCall",e)}},this._connect=e=>this.createUa(e).then((()=>this._start())),this._createUa=({displayName:e="",user:t,password:n,register:s=!1,sipServerUrl:i,sipWebSocketServerURL:o,remoteAddress:a,extraHeaders:c=[],sdpSemantics:h="plan-b",sessionTimers:l=!1,registerExpires:u=300,connectionRecoveryMinInterval:g=2,connectionRecoveryMaxInterval:m=6,userAgent:f})=>r(this,void 0,void 0,(function*(){if(!i)throw new Error("sipServerUrl is required");if(!o)throw new Error("sipWebSocketServerURL is required");if(s&&!t)throw new Error("user is required for authorized connection");if(s&&!n)throw new Error("password is required for authorized connection");let r;this._connectionConfiguration={sipServerUrl:i,displayName:e,register:s,user:t,password:n},this._init({sipServerUrl:i,sipWebSocketServerURL:o}),r=s&&t?t.trim():S();const E={password:n,register:s,display_name:_(e),user_agent:f,sdp_semantics:h,sockets:[this.socket],uri:this.getSipServerUrl(r),session_timers:l,register_expires:u,connection_recovery_min_interval:g,connection_recovery_max_interval:m};this.ua&&(yield this._disconnectWithoutCancelRequests()),this._isRegisterConfig=!!E.register,this.ua=new this.JsSIP.UA(E),this._uaEvents.eachTriggers(((e,t)=>{const n=d.find((e=>e===t));n&&this.ua.on(n,e)}));const v=(e=>{const t=[];return e&&t.push(`X-Vinteo-Remote: ${e}`),t})(a),C=[...v,...c];return this.ua.registrator().setExtraHeaders(C),this.ua})),this._start=()=>new Promise(((e,t)=>{const n=()=>{i(),e(this.ua)},s=e=>{i(),t(e)},i=()=>{this.off("registered",n),this.off("registrationFailed",s),this.off("connected",n),this.off("disconnected",s)};(()=>{this.isRegisterConfig?(this.on("registered",n),this.on("registrationFailed",s)):this.on("connected",n),this.on("disconnected",s)})(),this.on("newRTCSession",this.handleNewRTCSession),this.ua.start()})),this._set=({displayName:e,password:t})=>new Promise(((n,s)=>{let i=!1,r=!1;void 0!==e&&e!==this._connectionConfiguration.displayName&&(i=this.ua.set("display_name",_(e)),this._connectionConfiguration.displayName=e),void 0!==t&&t!==this._connectionConfiguration.password&&(r=this.ua.set("password",t),this._connectionConfiguration.password=t);const o=i||r;r&&this.isRegisterConfig?this.register().then((()=>n(o))).catch(s):o?n(o):s(o)})),this._disconnectWithoutCancelRequests=()=>this._cancelableDisconnect.request(),this._disconnect=()=>r(this,void 0,void 0,(function*(){this.off("newRTCSession",this.handleNewRTCSession);const e=new Promise((e=>{this.once("disconnected",(()=>{delete this.ua,e()}))}));return this.ua?(yield this._hangUpWithoutCancelRequests(),this.ua?this.ua.stop():this._uaEvents.trigger("disconnected",void 0)):this._uaEvents.trigger("disconnected",void 0),e})),this._call=({number:e,mediaStream:t,extraHeaders:n=[],ontrack:s,iceServers:i,videoMode:r,audioMode:o,degradationPreference:a,offerToReceiveAudio:c=!0,offerToReceiveVideo:d=!0})=>new Promise(((h,l)=>{this._connectionConfiguration.number=e,this._connectionConfiguration.answer=!1,this._handleCall({ontrack:s}).then(h).catch(l),this.session=this.ua.call(this.getSipServerUrl(e),{extraHeaders:n,mediaStream:v(t,{videoMode:r,audioMode:o}),eventHandlers:this._sessionEvents.triggers,videoMode:r,audioMode:o,degradationPreference:a,pcConfig:{iceServers:i},rtcOfferConstraints:{offerToReceiveAudio:c,offerToReceiveVideo:d}})})),this._answer=({mediaStream:e,ontrack:t,extraHeaders:n=[],iceServers:s,videoMode:i,audioMode:r,degradationPreference:o})=>new Promise(((a,c)=>{if(!this.isAvailableIncomingCall)return void c(new Error("no incomingSession"));this.session=this.incomingSession,this.removeIncomingSession();const d=this.session;if(!d)return void c(new Error("No session established"));this._sessionEvents.eachTriggers(((e,t)=>{const n=l.find((e=>e===t));n&&d.on(n,e)})),this._connectionConfiguration.answer=!0,this._connectionConfiguration.number=d.remote_identity.uri.user,this._handleCall({ontrack:t}).then(a).catch(c);const h=v(e,{videoMode:i,audioMode:r});d.answer({extraHeaders:n,videoMode:i,audioMode:r,degradationPreference:o,mediaStream:h,pcConfig:{iceServers:s}})})),this._handleCall=({ontrack:e})=>new Promise(((t,n)=>{const s=()=>{this.offSession("peerconnection",a),this.offSession("confirmed",c)},i=()=>{this.offSession("failed",r),this.offSession("ended",r)},r=e=>{s(),i(),n(e)};let o;const a=({peerconnection:t})=>{o=t,o.ontrack=t=>{this._sessionEvents.trigger("peerconnection:ontrack",o),e&&e(t)}},c=()=>{o&&this._sessionEvents.trigger("peerconnection:confirmed",o),s(),i(),t(o)};(()=>{this.onSession("peerconnection",a),this.onSession("confirmed",c)})(),(()=>{this.onSession("failed",r),this.onSession("ended",r)})()})),this._restoreSession=()=>{this._resetPresentation(),delete this._connectionConfiguration.number,delete this.session,this._remoteStreams={}},this._sendDTMF=e=>new Promise(((t,n)=>{const s=this.session;s?(this.onceSession("newDTMF",(({originator:e})=>{"local"===e&&t()})),s.sendDTMF(e,{duration:120,interToneGap:600})):n(new Error("No session established"))})),this._hangUpWithoutCancelRequests=()=>r(this,void 0,void 0,(function*(){if(this.ua&&this.session){const{session:e}=this;this._streamPresentationCurrent&&(yield this.stopPresentation()),this._restoreSession(),e.isEnded()||e.terminate()}})),this._handleShareState=e=>{switch(e){case"YOUCANRECEIVECONTENT":this._sessionEvents.trigger("availableSecondRemoteStream",void 0);break;case"CONTENTEND":this._sessionEvents.trigger("notAvailableSecondRemoteStream",void 0);break;case"YOUMUSTSTOPSENDCONTENT":this._sessionEvents.trigger("mustStopPresentation",void 0)}},this._maybeTriggerChannels=e=>{const t=e.getHeader("X-WEBRTC-INPUT-CHANNELS"),n=e.getHeader("X-WEBRTC-OUTPUT-CHANNELS");if(t&&n){const e={inputChannels:t,outputChannels:n};this._sessionEvents.trigger("channels",e)}},this._handleNotify=e=>{if("channels"===e.cmd){const t=e;this._triggerChannelsNotify(t)}else if("WebcastStarted"===e.cmd){const t=e;this._triggerWebcastStartedNotify(t)}else if("WebcastStopped"===e.cmd){const t=e;this._triggerWebcastStoppedNotify(t)}else if("addedToListModerators"===e.cmd){const t=e;this._triggerAddedToListModeratorsNotify(t)}else if("removedFromListModerators"===e.cmd){const t=e;this._triggerRemovedFromListModeratorsNotify(t)}else if("WebcastParticipationAccepted"===e.cmd){const t=e;this._triggerParticipantMoveRequestToConference(t)}else if("WebcastParticipationRejected"===e.cmd){const t=e;this._triggerParticipantCancelingWordRequest(t)}else if("ParticipantMovedToWebcast"===e.cmd){const t=e;this._triggerParticipantMoveRequestToStream(t)}else if("accountChanged"===e.cmd)this._triggerAccountChangedNotify();else if("accountDeleted"===e.cmd)this._triggerAccountDeletedNotify();else if("ConferenceParticipantTokenIssued"===e.cmd){const t=e;this._triggerConferenceParticipantTokenIssued(t)}},this._triggerRemovedFromListModeratorsNotify=({conference:e})=>{const t={conference:e};this._uaEvents.trigger("participant:removed-from-list-moderators",t)},this._triggerAddedToListModeratorsNotify=({conference:e})=>{const t={conference:e};this._uaEvents.trigger("participant:added-to-list-moderators",t)},this._triggerWebcastStartedNotify=({body:{conference:e,type:t}})=>{const n={conference:e,type:t};this._uaEvents.trigger("webcast:started",n)},this._triggerWebcastStoppedNotify=({body:{conference:e,type:t}})=>{const n={conference:e,type:t};this._uaEvents.trigger("webcast:stopped",n)},this._triggerAccountChangedNotify=()=>{this._uaEvents.trigger("account:changed",void 0)},this._triggerAccountDeletedNotify=()=>{this._uaEvents.trigger("account:deleted",void 0)},this._triggerConferenceParticipantTokenIssued=({body:{conference:e,participant:t,jwt:n}})=>{const s={conference:e,participant:t,jwt:n};this._uaEvents.trigger("conference:participant-token-issued",s)},this._triggerChannelsNotify=e=>{const t={inputChannels:e.input,outputChannels:e.output};this._uaEvents.trigger("channels:notify",t)},this._triggerParticipantMoveRequestToConference=({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger("participant:move-request-to-conference",t)},this._triggerParticipantCancelingWordRequest=({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger("participant:canceling-word-request",t)},this._triggerParticipantMoveRequestToStream=({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger("participant:move-request-to-stream",t)},this._triggerEnterRoom=e=>{const t=e.getHeader("x-webrtc-enter-room");this._sessionEvents.trigger("enterRoom",t)},this._triggerShareState=e=>{const t=e.getHeader("x-webrtc-share-state");this._sessionEvents.trigger("shareState",t)},this._triggerMainCamControl=e=>{const t=e.getHeader("X-WEBRTC-MAINCAM"),n=e.getHeader("X-WEBRTC-SYNC"),s=n===M.ADMIN_SYNC_FORCED;if(t===R.ADMIN_START_MAIN_CAM)this._sessionEvents.trigger("admin-start-main-cam",{isSyncForced:s});else if(t===R.ADMIN_STOP_MAIN_CAM)this._sessionEvents.trigger("admin-stop-main-cam",{isSyncForced:s});else if(t!==R.RESUME_MAIN_CAM&&t!==R.PAUSE_MAIN_CAM||!n){const n=e.getHeader("X-WEBRTC-MAINCAM-RESOLUTION");this._sessionEvents.trigger("main-cam-control",{mainCam:t,resolutionMainCam:n})}else this._sessionEvents.trigger("admin-force-sync-media-state",{isSyncForced:s})},this._triggerMicControl=e=>{const t=e.getHeader("X-WEBRTC-MIC"),n=e.getHeader("X-WEBRTC-SYNC")===M.ADMIN_SYNC_FORCED;t===w.ADMIN_START_MIC?this._sessionEvents.trigger("admin-start-mic",{isSyncForced:n}):t===w.ADMIN_STOP_MIC&&this._sessionEvents.trigger("admin-stop-mic",{isSyncForced:n})},this._triggerUseLicense=e=>{const t=e.getHeader("X-WEBRTC-USE-LICENSE");this._sessionEvents.trigger("useLicense",t)},this._handleNewInfo=e=>{const{originator:t}=e;if("remote"!==t)return;const n=e.request,s=n.getHeader("content-type");if(s)switch(s){case"application/vinteo.webrtc.roomname":this._triggerEnterRoom(n),this._maybeTriggerChannels(n);break;case"application/vinteo.webrtc.notify":this._maybeHandleNotify(n);break;case"application/vinteo.webrtc.sharedesktop":this._triggerShareState(n);break;case"application/vinteo.webrtc.maincam":this._triggerMainCamControl(n);break;case"application/vinteo.webrtc.mic":this._triggerMicControl(n);break;case"application/vinteo.webrtc.uselic":this._triggerUseLicense(n)}},this._handleSipEvent=({request:e})=>{this._maybeHandleNotify(e)},this._maybeHandleNotify=e=>{const t=e.getHeader("X-VINTEO-NOTIFY");if(t){const e=JSON.parse(t);this._handleNotify(e)}},this._handleEnded=e=>{const{originator:t}=e;"remote"===t&&this._sessionEvents.trigger("ended:fromserver",e),this._restoreSession()},this.JsSIP=t,this._sessionEvents=new n(g),this._uaEvents=new n(u),this._cancelableConnect=new e(this._connect,{moduleName:I,afterCancelRequest:()=>{this._cancelableCreateUa.cancelRequest(),this._cancelableDisconnect.cancelRequest()}}),this._cancelableCreateUa=new e(this._createUa,{moduleName:I}),this._cancelableDisconnect=new e(this._disconnect,{moduleName:I}),this._cancelableSet=new e(this._set,{moduleName:I}),this._cancelableCall=new e(this._call,{moduleName:I}),this._cancelableAnswer=new e(this._answer,{moduleName:I}),this._cancelableSendDTMF=new e(this._sendDTMF,{moduleName:I}),this.onSession("shareState",this._handleShareState),this.onSession("newInfo",this._handleNewInfo),this.on("sipEvent",this._handleSipEvent),this.onSession("failed",this._handleEnded),this.onSession("ended",this._handleEnded)}register(){return new Promise(((e,t)=>{this.isRegisterConfig?(this.ua.on("registered",e),this.ua.on("registrationFailed",t),this.ua.register()):t(new Error("Config is not registered"))}))}unregister(){return new Promise(((e,t)=>{this.isRegistered?(this.ua.on("unregistered",e),this.ua.unregister()):t(new Error("ua is not registered"))}))}sendOptions(e,t,n){return this.ua?new Promise(((s,i)=>{try{this.ua.sendOptions(e,t,{extraHeaders:n,eventHandlers:{succeeded:()=>{s()},failed:e=>{i(e)}}})}catch(e){i(e)}})):Promise.reject(new Error("is not connected"))}ping(e,t){if(!this.ua||!this.ua.configuration||!this.ua.configuration.uri)return Promise.reject(new Error("is not connected"));const n=this.ua.configuration.uri;return this.sendOptions(n,e,t)}replaceMediaStream(e,t){if(!this.session)throw new Error("No session established");return this.session.replaceMediaStream(e,t)}askPermissionToEnableCam(e={noTerminateWhenError:!0}){if(!this.session)throw new Error("No session established");const t=["X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE: LETMESTARTMAINCAM"];return this.session.sendInfo("application/vinteo.webrtc.maincam",void 0,Object.assign(Object.assign({},e),{extraHeaders:t})).catch((e=>{if((e=>"Error decline with 603"===e.message)(e))throw e}))}get isPendingPresentation(){return!!this.promisePendingStartPresentation||!!this.promisePendingStopPresentation}_sendPresentation(e,t,{maxBitrate:n,degradationPreference:s,isNeedReinvite:i=!0,isP2P:r=!1}){const o=v(t);this._streamPresentationCurrent=o;const a=r?["x-webrtc-share-state: YOUCANRECEIVECONTENT"]:["x-webrtc-share-state: LETMESTARTPRESENTATION"],c=e.sendInfo("application/vinteo.webrtc.sharedesktop",void 0,{extraHeaders:a}).then((()=>e.startPresentation(o,i,s))).then((()=>{const{connection:e}=this;if(!e||void 0===n)return;return((e,t,n)=>{const s=((e,t)=>e.find((e=>e.track&&t.getTracks().includes(e.track))))(e,t);return s?T(s,{maxBitrate:n}):Promise.resolve()})(e.getSenders(),t,n)})).then((()=>t)).catch((e=>{throw this._sessionEvents.trigger("presentation:failed",e),e}));return this.promisePendingStartPresentation=c,c.finally((()=>{this.promisePendingStartPresentation=void 0}))}startPresentation(e,{isNeedReinvite:t=!0,isP2P:n=!1,maxBitrate:s,degradationPreference:i}={}){const r=this.establishedSession;return r?this._streamPresentationCurrent?Promise.reject(new Error("Presentation is already started")):this._sendPresentation(r,e,{isNeedReinvite:t,isP2P:n,maxBitrate:s,degradationPreference:i}):Promise.reject(new Error("No session established"))}stopPresentation({isP2P:e=!1}={}){const t=this._streamPresentationCurrent;let n=this.promisePendingStartPresentation||Promise.resolve();const s=e?["x-webrtc-share-state: CONTENTEND"]:["x-webrtc-share-state: STOPPRESENTATION"],i=this.establishedSession;return i&&t&&(n=n.then((()=>i.sendInfo("application/vinteo.webrtc.sharedesktop",void 0,{extraHeaders:s}))).then((()=>i.stopPresentation(t))).catch((e=>{throw this._sessionEvents.trigger("presentation:failed",e),e}))),!i&&t&&this._sessionEvents.trigger("presentation:ended",t),this.promisePendingStopPresentation=n,n.finally((()=>{this._resetPresentation()}))}updatePresentation(e,{isP2P:t=!1,maxBitrate:n,degradationPreference:s}={}){return r(this,void 0,void 0,(function*(){const i=this.establishedSession;return i?this._streamPresentationCurrent?(this.promisePendingStartPresentation&&(yield this.promisePendingStartPresentation),this._sendPresentation(i,e,{isP2P:t,maxBitrate:n,degradationPreference:s,isNeedReinvite:!1})):Promise.reject(new Error("Presentation has not started yet")):Promise.reject(new Error("No session established"))}))}_resetPresentation(){delete this._streamPresentationCurrent,this.promisePendingStartPresentation=void 0,this.promisePendingStopPresentation=void 0}on(e,t){return this._uaEvents.on(e,t)}once(e,t){return this._uaEvents.once(e,t)}onceRace(e,t){return this._uaEvents.onceRace(e,t)}wait(e){return this._uaEvents.wait(e)}off(e,t){this._uaEvents.off(e,t)}onSession(e,t){return this._sessionEvents.on(e,t)}onceSession(e,t){return this._sessionEvents.once(e,t)}onceRaceSession(e,t){return this._sessionEvents.onceRace(e,t)}waitSession(e){return this._sessionEvents.wait(e)}offSession(e,t){this._sessionEvents.off(e,t)}isConfigured(){return!!this.ua}getConnectionConfiguration(){return Object.assign({},this._connectionConfiguration)}getRemoteStreams(){if(!this.connection)return;const e=this.connection.getReceivers().map((({track:e})=>e));return(e=>e.some((e=>{const{kind:t}=e;return"video"===t})))(e)?this._generateStreams(e):this._generateAudioStreams(e)}get connection(){var e;return null===(e=null==this?void 0:this.session)||void 0===e?void 0:e.connection}get remoteCallerData(){var e,t,n,s,i,r;return{displayName:null===(t=null===(e=null==this?void 0:this.incomingSession)||void 0===e?void 0:e.remote_identity)||void 0===t?void 0:t.display_name,host:null===(s=null===(n=null==this?void 0:this.incomingSession)||void 0===n?void 0:n.remote_identity)||void 0===s?void 0:s.uri.host,incomingNumber:null===(r=null===(i=null==this?void 0:this.incomingSession)||void 0===i?void 0:i.remote_identity)||void 0===r?void 0:r.uri.user,session:null==this?void 0:this.incomingSession}}get requested(){return this._cancelableConnect.requested||this._cancelableCreateUa.requested||this._cancelableCall.requested||this._cancelableAnswer.requested}get establishedSession(){return this.session&&this.session.isEstablished()?this.session:void 0}get isRegistered(){return!!this.ua&&this.ua.isRegistered()}get isRegisterConfig(){return!!this.ua&&this._isRegisterConfig}get isCallActive(){return!(!this.ua||!this.session)}get isAvailableIncomingCall(){return!!this.incomingSession}_init({sipServerUrl:e,sipWebSocketServerURL:t}){var n;this.getSipServerUrl=(n=e,e=>`sip:${e}@${n}`),this.socket=new this.JsSIP.WebSocketInterface(t)}_generateStream(e,t){const n=e.id,s=this._remoteStreams[n]||new MediaStream;return t&&s.addTrack(t),s.addTrack(e),this._remoteStreams[n]=s,s}_generateAudioStream(e){const t=e.id,n=this._remoteStreams[t]||new MediaStream;return n.addTrack(e),this._remoteStreams[t]=n,n}_generateStreams(e){const t=[];return e.forEach(((n,s)=>{if("audio"===n.kind)return;const i=n,r=e[s-1];let o;r&&"audio"===r.kind&&(o=r);const a=this._generateStream(i,o);t.push(a)}),[]),t}_generateAudioStreams(e){return e.map((e=>this._generateAudioStream(e)))}_cancelRequests(){this._cancelActionsRequests(),this._cancelCallRequests(),this._cancelConnectRequests()}_cancelConnectRequests(){this._cancelableConnect.cancelRequest()}_cancelCallRequests(){this._cancelableCall.cancelRequest(),this._cancelableAnswer.cancelRequest()}_cancelActionsRequests(){this._cancelableAnswer.cancelRequest(),this._cancelableSendDTMF.cancelRequest()}waitChannels(){return this.waitSession("channels")}waitSyncMediaState(){return this.waitSession("admin-force-sync-media-state")}sendChannels({inputChannels:e,outputChannels:t}){if(!this.session)throw new Error("No session established");const n=[`X-WEBRTC-INPUT-CHANNELS: ${e}`,`X-WEBRTC-OUTPUT-CHANNELS: ${t}`];return this.session.sendInfo("application/vinteo.webrtc.channels",void 0,{extraHeaders:n})}sendMediaState({cam:e,mic:t},n={noTerminateWhenError:!0}){if(!this.session)throw new Error("No session established");const s=["X-WEBRTC-MEDIA-STATE: currentstate","X-Vinteo-MainCam-State: "+ +e,"X-Vinteo-Mic-State: "+ +t];return this.session.sendInfo("application/vinteo.webrtc.mediastate",void 0,Object.assign(Object.assign({},n),{extraHeaders:s}))}_sendRefusalToTurnOn(e,t={noTerminateWhenError:!0}){if(!this.session)throw new Error("No session established");const n=[`X-Vinteo-Media-Type: ${"mic"==e?0:1}`];return this.session.sendInfo("application/vinteo.webrtc.refusal",void 0,Object.assign(Object.assign({},t),{extraHeaders:n}))}sendRefusalToTurnOnMic(e={noTerminateWhenError:!0}){if(!this.session)throw new Error("No session established");return this._sendRefusalToTurnOn("mic",e)}sendRefusalToTurnOnCam(e={noTerminateWhenError:!0}){if(!this.session)throw new Error("No session established");return this._sendRefusalToTurnOn("cam",e)}}const y=(e,t)=>!!e&&!!t&&e.toLowerCase().includes(t.toLowerCase()),O=e=>1e6*e,D=O(.06),U=O(4),k=(e,t)=>(e=>y(e,"av1"))(t)?.6*e:e,q=(e,t)=>{const n=(e=>e<=64?D:e<=128?O(.12):e<=256?O(.25):e<=384?O(.32):e<=426?O(.38):e<=640?O(.5):e<=848?O(.7):e<=1280?O(1):e<=1920?O(2):U)(e);return k(n,t)},x=s(),B=e=>(x.add(e),x().catch((e=>{console.debug("videoSendingBalancer: error",e)}))),W=({sender:e,scaleResolutionDownBy:t,maxBitrate:n,onSetParameters:s})=>B((()=>T(e,{scaleResolutionDownBy:t,maxBitrate:n},s))),L=({sender:e,codec:t},n)=>{const s=(e=>k(D,e))(t);return W({sender:e,maxBitrate:s,onSetParameters:n,scaleResolutionDownBy:200})},H=({sender:e,track:t,codec:n},s)=>{const i=t.getSettings().width,r=q(i,n);return W({sender:e,maxBitrate:r,onSetParameters:s,scaleResolutionDownBy:1})},F=({mainCam:e,resolutionMainCam:t,sender:n,track:s,codec:i},r)=>{switch(e){case R.PAUSE_MAIN_CAM:return L({sender:n,codec:i},r);case R.RESUME_MAIN_CAM:return H({sender:n,track:s,codec:i},r);case R.MAX_MAIN_CAM_RESOLUTION:return t?(({sender:e,track:t,resolution:n,codec:s},i)=>{const r=t.getSettings(),o=r.width,a=r.height,[c,d]=n.split("x"),h=o/+c,l=a/+d,u=Math.max(h,l,1),g=q(+c,s);return W({sender:e,maxBitrate:g,onSetParameters:i,scaleResolutionDownBy:u})})({sender:n,track:s,codec:i,resolution:t},r):H({sender:n,track:s,codec:i},r);default:return H({sender:n,track:s,codec:i},r)}},j={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},V=({mainCam:e,resolutionMainCam:t,connection:n,onSetParameters:s,ignoreForCodec:o})=>r(void 0,void 0,void 0,(function*(){const r=(e=>e.find((e=>{var t;return"video"===(null===(t=null==e?void 0:e.track)||void 0===t?void 0:t.kind)})))(n.getSenders());if(!r||!r.track)return j;const a=yield i(r);return y(a,o)?j:F({mainCam:e,resolutionMainCam:t,sender:r,codec:a,track:r.track},s)})),X=(e,{ignoreForCodec:t,onSetParameters:n}={})=>{const s=()=>{const{connection:s}=e;return s?V({connection:s,onSetParameters:n,ignoreForCodec:t}):Promise.reject(new Error("connection is not exist"))};let i=s;const r=s=>{i=()=>{const{mainCam:i,resolutionMainCam:r}=s,{connection:o}=e;return o?V({mainCam:i,resolutionMainCam:r,connection:o,onSetParameters:n,ignoreForCodec:t}):Promise.reject(new Error("connection is not exist"))},i()};return{subscribe:()=>{e.onSession("main-cam-control",r)},unsubscribe:()=>{e.offSession("main-cam-control",r)},balanceByTrack:s,resetMainCamControl(){i=s},reBalance:()=>i()}};export{A as EUseLicense,a as causes,b as default,m as eventNames,i as getCodecFromSender,P as hasCanceledCallError,X as resolveVideoSendingBalancer};
|
|
1
|
+
import{CancelableRequest as e,isCanceledError as t}from"@krivega/cancelable-promise";import n from"events-constructor";import s from"stack-promises";import i from"debug";export{default as debug}from"debug";import r from"lodash/debounce";import o from"sequent-promises";import a from"lodash/flow";import c from"lodash/split";const d=e=>e.getStats().then((e=>{const t=(n="codec",(e=>[...e.keys()].map((t=>e.get(t))))(e).find((e=>e.type===n)));var n;return null==t?void 0:t.mimeType}));function l(e,t,n,s){return new(n||(n=Promise))((function(i,r){function o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))}const h="Terminated";var u=Object.freeze({__proto__:null,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",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:h,WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"});const m=["incomingCall","declinedIncomingCall","terminatedIncomingCall","failedIncomingCall","participant:canceling-word-request","participant:move-request-to-stream","participant:move-request-to-conference","channels:notify","conference:participant-token-issued","account:changed","account:deleted","webcast:started","webcast:stopped","participant:added-to-list-moderators","participant:removed-from-list-moderators"],g=["connecting","connected","disconnected","newRTCSession","registered","unregistered","registrationFailed","newMessage","sipEvent"],_=["availableSecondRemoteStream","notAvailableSecondRemoteStream","mustStopPresentation","shareState","enterRoom","useLicense","peerconnection:confirmed","peerconnection:ontrack","channels","ended:fromserver","main-cam-control","admin-start-main-cam","admin-stop-main-cam","admin-stop-mic","admin-start-mic","admin-force-sync-media-state"],S=["ended","connecting","sending","reinvite","replaces","refer","progress","accepted","confirmed","peerconnection","failed","muted","unmuted","newDTMF","newInfo","hold","unhold","update","sdp","icecandidate","getusermediafailed","peerconnection:createofferfailed","peerconnection:createanswerfailed","peerconnection:setlocaldescriptionfailed","peerconnection:setremotedescriptionfailed","presentation:start","presentation:started","presentation:end","presentation:ended","presentation:failed"],E=[...g,...m],C=[...S,..._];var f=Object.freeze({__proto__:null,UA_SYNTHETICS_EVENT_NAMES:m,UA_JSSIP_EVENT_NAMES:g,SESSION_SYNTHETICS_EVENT_NAMES:_,SESSION_JSSIP_EVENT_NAMES:S,UA_EVENT_NAMES:E,SESSION_EVENT_NAMES:C});const v=e=>e.trim().replace(/ /g,"_"),p=(R=1e5,N=99999999,()=>Math.floor(Math.random()*(N-R))+R);var R,N;const T=(e,{videoMode:t,audioMode:n}={})=>{if(!e||"recvonly"===t&&"recvonly"===n)return;const s=[..."recvonly"===n?[]:e.getAudioTracks(),..."recvonly"===t?[]:e.getVideoTracks()],i=new MediaStream(s);return i.getTracks=()=>[...i.getAudioTracks(),...i.getVideoTracks()],i},P=e=>(t,n)=>void 0!==n&&t!==n||void 0===n&&t!==e,M=P(1),A=P(void 0),w=(e,t,n)=>{const s=e.getParameters();s.encodings&&0!==s.encodings.length||(s.encodings=[{}]);const[i]=s.encodings,r=i.scaleResolutionDownBy,o=((e,t)=>{const n=void 0!==e?Math.max(e,1):null;if(null!==n&&M(n,t))return n})(t.scaleResolutionDownBy,r);let a=!1;void 0!==o&&(s.encodings[0].scaleResolutionDownBy=o,a=!0);const c=i.maxBitrate,d=((e,t)=>{if(A(e,t))return e})(t.maxBitrate,c);return void 0!==d&&(s.encodings[0].maxBitrate=d,a=!0),a?(n&&n(s),e.setParameters(s).then((()=>({parameters:s,isChanged:a})))):Promise.resolve({parameters:s,isChanged:a})};var I,b,O,y;!function(e){e.PAUSE_MAIN_CAM="PAUSEMAINCAM",e.RESUME_MAIN_CAM="RESUMEMAINCAM",e.MAX_MAIN_CAM_RESOLUTION="MAXMAINCAMRESOLUTION",e.ADMIN_STOP_MAIN_CAM="ADMINSTOPMAINCAM",e.ADMIN_START_MAIN_CAM="ADMINSTARTMAINCAM"}(I||(I={})),function(e){e.ADMIN_STOP_MIC="ADMINSTOPMIC",e.ADMIN_START_MIC="ADMINSTARTMIC"}(b||(b={})),function(e){e.ADMIN_SYNC_FORCED="1",e.ADMIN_SYNC_NOT_FORCED="0"}(O||(O={})),function(e){e.AUDIO="AUDIO",e.VIDEO="VIDEO",e.AUDIOPLUSPRESENTATION="AUDIOPLUSPRESENTATION"}(y||(y={}));const D=(e=new Error)=>{const{originator:n,cause:s}=e;return!!t(e)||"string"==typeof s&&("Request Timeout"===s||"Rejected"===s||"local"===n&&("Canceled"===s||s===h))},U="SipConnector";class k{constructor({JsSIP:t}){this._isRegisterConfig=!1,this._connectionConfiguration={},this._remoteStreams={},this.getSipServerUrl=e=>e,this.connect=e=>(this._cancelRequests(),this._cancelableConnect.request(e)),this.createUa=e=>this._cancelableCreateUa.request(e),this.set=e=>this._cancelableSet.request(e),this.call=e=>this._cancelableCall.request(e),this.disconnect=()=>(this._cancelRequests(),this._disconnectWithoutCancelRequests()),this.answerToIncomingCall=e=>this._cancelableAnswer.request(e),this.sendDTMF=e=>this._cancelableSendDTMF.request(e),this.hangUp=()=>(this._cancelRequests(),this._hangUpWithoutCancelRequests()),this.tryRegister=()=>this.isRegisterConfig?(this._uaEvents.trigger("connecting",void 0),this.unregister().finally((()=>this.register())).finally((()=>{}))):Promise.reject(new Error("Config is not registered")),this.declineToIncomingCall=({statusCode:e=487}={})=>new Promise(((t,n)=>{if(!this.isAvailableIncomingCall)return void n(new Error("no incomingSession"));const s=this.incomingSession,i=this.remoteCallerData;this._cancelableCall.cancelRequest(),this._cancelableAnswer.cancelRequest(),this.removeIncomingSession(),this._uaEvents.trigger("declinedIncomingCall",i),t(s.terminate({status_code:e}))})),this.busyIncomingCall=()=>this.declineToIncomingCall({statusCode:486}),this.removeIncomingSession=()=>{delete this.incomingSession},this.handleNewRTCSession=({originator:e,session:t})=>{if("remote"===e){this.incomingSession=t;const e=this.remoteCallerData;t.on("failed",(({originator:t})=>{this.removeIncomingSession(),"local"!==t?this._uaEvents.trigger("failedIncomingCall",e):this._uaEvents.trigger("terminatedIncomingCall",e)})),this._uaEvents.trigger("incomingCall",e)}},this._connect=e=>this.createUa(e).then((()=>this._start())),this._createUa=({displayName:e="",user:t,password:n,register:s=!1,sipServerUrl:i,sipWebSocketServerURL:r,remoteAddress:o,extraHeaders:a=[],sdpSemantics:c="plan-b",sessionTimers:d=!1,registerExpires:h=300,connectionRecoveryMinInterval:u=2,connectionRecoveryMaxInterval:m=6,userAgent:_})=>l(this,void 0,void 0,(function*(){if(!i)throw new Error("sipServerUrl is required");if(!r)throw new Error("sipWebSocketServerURL is required");if(s&&!t)throw new Error("user is required for authorized connection");if(s&&!n)throw new Error("password is required for authorized connection");let l;this._connectionConfiguration={sipServerUrl:i,displayName:e,register:s,user:t,password:n},this._init({sipServerUrl:i,sipWebSocketServerURL:r}),l=s&&t?t.trim():p();const S={password:n,register:s,display_name:v(e),user_agent:_,sdp_semantics:c,sockets:[this.socket],uri:this.getSipServerUrl(l),session_timers:d,register_expires:h,connection_recovery_min_interval:u,connection_recovery_max_interval:m};this.ua&&(yield this._disconnectWithoutCancelRequests()),this._isRegisterConfig=!!S.register,this.ua=new this.JsSIP.UA(S),this._uaEvents.eachTriggers(((e,t)=>{const n=g.find((e=>e===t));n&&this.ua.on(n,e)}));const E=(e=>{const t=[];return e&&t.push(`X-Vinteo-Remote: ${e}`),t})(o),C=[...E,...a];return this.ua.registrator().setExtraHeaders(C),this.ua})),this._start=()=>new Promise(((e,t)=>{const n=()=>{i(),e(this.ua)},s=e=>{i(),t(e)},i=()=>{this.off("registered",n),this.off("registrationFailed",s),this.off("connected",n),this.off("disconnected",s)};(()=>{this.isRegisterConfig?(this.on("registered",n),this.on("registrationFailed",s)):this.on("connected",n),this.on("disconnected",s)})(),this.on("newRTCSession",this.handleNewRTCSession),this.ua.start()})),this._set=({displayName:e,password:t})=>new Promise(((n,s)=>{let i=!1,r=!1;void 0!==e&&e!==this._connectionConfiguration.displayName&&(i=this.ua.set("display_name",v(e)),this._connectionConfiguration.displayName=e),void 0!==t&&t!==this._connectionConfiguration.password&&(r=this.ua.set("password",t),this._connectionConfiguration.password=t);const o=i||r;r&&this.isRegisterConfig?this.register().then((()=>n(o))).catch(s):o?n(o):s(o)})),this._disconnectWithoutCancelRequests=()=>this._cancelableDisconnect.request(),this._disconnect=()=>l(this,void 0,void 0,(function*(){this.off("newRTCSession",this.handleNewRTCSession);const e=new Promise((e=>{this.once("disconnected",(()=>{delete this.ua,e()}))}));return this.ua?(yield this._hangUpWithoutCancelRequests(),this.ua?this.ua.stop():this._uaEvents.trigger("disconnected",void 0)):this._uaEvents.trigger("disconnected",void 0),e})),this._call=({number:e,mediaStream:t,extraHeaders:n=[],ontrack:s,iceServers:i,videoMode:r,audioMode:o,degradationPreference:a,offerToReceiveAudio:c=!0,offerToReceiveVideo:d=!0})=>new Promise(((l,h)=>{this._connectionConfiguration.number=e,this._connectionConfiguration.answer=!1,this._handleCall({ontrack:s}).then(l).catch(h),this.session=this.ua.call(this.getSipServerUrl(e),{extraHeaders:n,mediaStream:T(t,{videoMode:r,audioMode:o}),eventHandlers:this._sessionEvents.triggers,videoMode:r,audioMode:o,degradationPreference:a,pcConfig:{iceServers:i},rtcOfferConstraints:{offerToReceiveAudio:c,offerToReceiveVideo:d}})})),this._answer=({mediaStream:e,ontrack:t,extraHeaders:n=[],iceServers:s,videoMode:i,audioMode:r,degradationPreference:o})=>new Promise(((a,c)=>{if(!this.isAvailableIncomingCall)return void c(new Error("no incomingSession"));this.session=this.incomingSession,this.removeIncomingSession();const d=this.session;if(!d)return void c(new Error("No session established"));this._sessionEvents.eachTriggers(((e,t)=>{const n=S.find((e=>e===t));n&&d.on(n,e)})),this._connectionConfiguration.answer=!0,this._connectionConfiguration.number=d.remote_identity.uri.user,this._handleCall({ontrack:t}).then(a).catch(c);const l=T(e,{videoMode:i,audioMode:r});d.answer({extraHeaders:n,videoMode:i,audioMode:r,degradationPreference:o,mediaStream:l,pcConfig:{iceServers:s}})})),this._handleCall=({ontrack:e})=>new Promise(((t,n)=>{const s=()=>{this.offSession("peerconnection",a),this.offSession("confirmed",c)},i=()=>{this.offSession("failed",r),this.offSession("ended",r)},r=e=>{s(),i(),n(e)};let o;const a=({peerconnection:t})=>{o=t,o.ontrack=t=>{this._sessionEvents.trigger("peerconnection:ontrack",o),e&&e(t)}},c=()=>{o&&this._sessionEvents.trigger("peerconnection:confirmed",o),s(),i(),t(o)};(()=>{this.onSession("peerconnection",a),this.onSession("confirmed",c)})(),(()=>{this.onSession("failed",r),this.onSession("ended",r)})()})),this._restoreSession=()=>{this._resetPresentation(),delete this._connectionConfiguration.number,delete this.session,this._remoteStreams={}},this._sendDTMF=e=>new Promise(((t,n)=>{const s=this.session;s?(this.onceSession("newDTMF",(({originator:e})=>{"local"===e&&t()})),s.sendDTMF(e,{duration:120,interToneGap:600})):n(new Error("No session established"))})),this._hangUpWithoutCancelRequests=()=>l(this,void 0,void 0,(function*(){if(this.ua&&this.session){const{session:e}=this;this._streamPresentationCurrent&&(yield this.stopPresentation()),this._restoreSession(),e.isEnded()||e.terminate()}})),this._handleShareState=e=>{switch(e){case"YOUCANRECEIVECONTENT":this._sessionEvents.trigger("availableSecondRemoteStream",void 0);break;case"CONTENTEND":this._sessionEvents.trigger("notAvailableSecondRemoteStream",void 0);break;case"YOUMUSTSTOPSENDCONTENT":this._sessionEvents.trigger("mustStopPresentation",void 0)}},this._maybeTriggerChannels=e=>{const t=e.getHeader("X-WEBRTC-INPUT-CHANNELS"),n=e.getHeader("X-WEBRTC-OUTPUT-CHANNELS");if(t&&n){const e={inputChannels:t,outputChannels:n};this._sessionEvents.trigger("channels",e)}},this._handleNotify=e=>{if("channels"===e.cmd){const t=e;this._triggerChannelsNotify(t)}else if("WebcastStarted"===e.cmd){const t=e;this._triggerWebcastStartedNotify(t)}else if("WebcastStopped"===e.cmd){const t=e;this._triggerWebcastStoppedNotify(t)}else if("addedToListModerators"===e.cmd){const t=e;this._triggerAddedToListModeratorsNotify(t)}else if("removedFromListModerators"===e.cmd){const t=e;this._triggerRemovedFromListModeratorsNotify(t)}else if("WebcastParticipationAccepted"===e.cmd){const t=e;this._triggerParticipantMoveRequestToConference(t)}else if("WebcastParticipationRejected"===e.cmd){const t=e;this._triggerParticipantCancelingWordRequest(t)}else if("ParticipantMovedToWebcast"===e.cmd){const t=e;this._triggerParticipantMoveRequestToStream(t)}else if("accountChanged"===e.cmd)this._triggerAccountChangedNotify();else if("accountDeleted"===e.cmd)this._triggerAccountDeletedNotify();else if("ConferenceParticipantTokenIssued"===e.cmd){const t=e;this._triggerConferenceParticipantTokenIssued(t)}},this._triggerRemovedFromListModeratorsNotify=({conference:e})=>{const t={conference:e};this._uaEvents.trigger("participant:removed-from-list-moderators",t)},this._triggerAddedToListModeratorsNotify=({conference:e})=>{const t={conference:e};this._uaEvents.trigger("participant:added-to-list-moderators",t)},this._triggerWebcastStartedNotify=({body:{conference:e,type:t}})=>{const n={conference:e,type:t};this._uaEvents.trigger("webcast:started",n)},this._triggerWebcastStoppedNotify=({body:{conference:e,type:t}})=>{const n={conference:e,type:t};this._uaEvents.trigger("webcast:stopped",n)},this._triggerAccountChangedNotify=()=>{this._uaEvents.trigger("account:changed",void 0)},this._triggerAccountDeletedNotify=()=>{this._uaEvents.trigger("account:deleted",void 0)},this._triggerConferenceParticipantTokenIssued=({body:{conference:e,participant:t,jwt:n}})=>{const s={conference:e,participant:t,jwt:n};this._uaEvents.trigger("conference:participant-token-issued",s)},this._triggerChannelsNotify=e=>{const t={inputChannels:e.input,outputChannels:e.output};this._uaEvents.trigger("channels:notify",t)},this._triggerParticipantMoveRequestToConference=({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger("participant:move-request-to-conference",t)},this._triggerParticipantCancelingWordRequest=({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger("participant:canceling-word-request",t)},this._triggerParticipantMoveRequestToStream=({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger("participant:move-request-to-stream",t)},this._triggerEnterRoom=e=>{const t=e.getHeader("x-webrtc-enter-room");this._sessionEvents.trigger("enterRoom",t)},this._triggerShareState=e=>{const t=e.getHeader("x-webrtc-share-state");this._sessionEvents.trigger("shareState",t)},this._triggerMainCamControl=e=>{const t=e.getHeader("X-WEBRTC-MAINCAM"),n=e.getHeader("X-WEBRTC-SYNC"),s=n===O.ADMIN_SYNC_FORCED;if(t===I.ADMIN_START_MAIN_CAM)this._sessionEvents.trigger("admin-start-main-cam",{isSyncForced:s});else if(t===I.ADMIN_STOP_MAIN_CAM)this._sessionEvents.trigger("admin-stop-main-cam",{isSyncForced:s});else if(t!==I.RESUME_MAIN_CAM&&t!==I.PAUSE_MAIN_CAM||!n){const n=e.getHeader("X-WEBRTC-MAINCAM-RESOLUTION");this._sessionEvents.trigger("main-cam-control",{mainCam:t,resolutionMainCam:n})}else this._sessionEvents.trigger("admin-force-sync-media-state",{isSyncForced:s})},this._triggerMicControl=e=>{const t=e.getHeader("X-WEBRTC-MIC"),n=e.getHeader("X-WEBRTC-SYNC")===O.ADMIN_SYNC_FORCED;t===b.ADMIN_START_MIC?this._sessionEvents.trigger("admin-start-mic",{isSyncForced:n}):t===b.ADMIN_STOP_MIC&&this._sessionEvents.trigger("admin-stop-mic",{isSyncForced:n})},this._triggerUseLicense=e=>{const t=e.getHeader("X-WEBRTC-USE-LICENSE");this._sessionEvents.trigger("useLicense",t)},this._handleNewInfo=e=>{const{originator:t}=e;if("remote"!==t)return;const n=e.request,s=n.getHeader("content-type");if(s)switch(s){case"application/vinteo.webrtc.roomname":this._triggerEnterRoom(n),this._maybeTriggerChannels(n);break;case"application/vinteo.webrtc.notify":this._maybeHandleNotify(n);break;case"application/vinteo.webrtc.sharedesktop":this._triggerShareState(n);break;case"application/vinteo.webrtc.maincam":this._triggerMainCamControl(n);break;case"application/vinteo.webrtc.mic":this._triggerMicControl(n);break;case"application/vinteo.webrtc.uselic":this._triggerUseLicense(n)}},this._handleSipEvent=({request:e})=>{this._maybeHandleNotify(e)},this._maybeHandleNotify=e=>{const t=e.getHeader("X-VINTEO-NOTIFY");if(t){const e=JSON.parse(t);this._handleNotify(e)}},this._handleEnded=e=>{const{originator:t}=e;"remote"===t&&this._sessionEvents.trigger("ended:fromserver",e),this._restoreSession()},this.JsSIP=t,this._sessionEvents=new n(C),this._uaEvents=new n(E),this._cancelableConnect=new e(this._connect,{moduleName:U,afterCancelRequest:()=>{this._cancelableCreateUa.cancelRequest(),this._cancelableDisconnect.cancelRequest()}}),this._cancelableCreateUa=new e(this._createUa,{moduleName:U}),this._cancelableDisconnect=new e(this._disconnect,{moduleName:U}),this._cancelableSet=new e(this._set,{moduleName:U}),this._cancelableCall=new e(this._call,{moduleName:U}),this._cancelableAnswer=new e(this._answer,{moduleName:U}),this._cancelableSendDTMF=new e(this._sendDTMF,{moduleName:U}),this.onSession("shareState",this._handleShareState),this.onSession("newInfo",this._handleNewInfo),this.on("sipEvent",this._handleSipEvent),this.onSession("failed",this._handleEnded),this.onSession("ended",this._handleEnded)}register(){return new Promise(((e,t)=>{this.isRegisterConfig?(this.ua.on("registered",e),this.ua.on("registrationFailed",t),this.ua.register()):t(new Error("Config is not registered"))}))}unregister(){return new Promise(((e,t)=>{this.isRegistered?(this.ua.on("unregistered",e),this.ua.unregister()):t(new Error("ua is not registered"))}))}sendOptions(e,t,n){return this.ua?new Promise(((s,i)=>{try{this.ua.sendOptions(e,t,{extraHeaders:n,eventHandlers:{succeeded:()=>{s()},failed:e=>{i(e)}}})}catch(e){i(e)}})):Promise.reject(new Error("is not connected"))}ping(e,t){if(!this.ua||!this.ua.configuration||!this.ua.configuration.uri)return Promise.reject(new Error("is not connected"));const n=this.ua.configuration.uri;return this.sendOptions(n,e,t)}replaceMediaStream(e,t){if(!this.session)throw new Error("No session established");return this.session.replaceMediaStream(e,t)}askPermissionToEnableCam(e={noTerminateWhenError:!0}){if(!this.session)throw new Error("No session established");const t=["X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE: LETMESTARTMAINCAM"];return this.session.sendInfo("application/vinteo.webrtc.maincam",void 0,Object.assign(Object.assign({},e),{extraHeaders:t})).catch((e=>{if((e=>"Error decline with 603"===e.message)(e))throw e}))}get isPendingPresentation(){return!!this.promisePendingStartPresentation||!!this.promisePendingStopPresentation}_sendPresentation(e,t,{maxBitrate:n,degradationPreference:s,isNeedReinvite:i=!0,isP2P:r=!1}){const o=T(t);this._streamPresentationCurrent=o;const a=r?["x-webrtc-share-state: YOUCANRECEIVECONTENT"]:["x-webrtc-share-state: LETMESTARTPRESENTATION"],c=e.sendInfo("application/vinteo.webrtc.sharedesktop",void 0,{extraHeaders:a}).then((()=>e.startPresentation(o,i,s))).then((()=>{const{connection:e}=this;if(!e||void 0===n)return;return((e,t,n)=>{const s=((e,t)=>e.find((e=>e.track&&t.getTracks().includes(e.track))))(e,t);return s?w(s,{maxBitrate:n}):Promise.resolve()})(e.getSenders(),t,n)})).then((()=>t)).catch((e=>{throw this._sessionEvents.trigger("presentation:failed",e),e}));return this.promisePendingStartPresentation=c,c.finally((()=>{this.promisePendingStartPresentation=void 0}))}startPresentation(e,{isNeedReinvite:t=!0,isP2P:n=!1,maxBitrate:s,degradationPreference:i}={}){const r=this.establishedSession;return r?this._streamPresentationCurrent?Promise.reject(new Error("Presentation is already started")):this._sendPresentation(r,e,{isNeedReinvite:t,isP2P:n,maxBitrate:s,degradationPreference:i}):Promise.reject(new Error("No session established"))}stopPresentation({isP2P:e=!1}={}){const t=this._streamPresentationCurrent;let n=this.promisePendingStartPresentation||Promise.resolve();const s=e?["x-webrtc-share-state: CONTENTEND"]:["x-webrtc-share-state: STOPPRESENTATION"],i=this.establishedSession;return i&&t&&(n=n.then((()=>i.sendInfo("application/vinteo.webrtc.sharedesktop",void 0,{extraHeaders:s}))).then((()=>i.stopPresentation(t))).catch((e=>{throw this._sessionEvents.trigger("presentation:failed",e),e}))),!i&&t&&this._sessionEvents.trigger("presentation:ended",t),this.promisePendingStopPresentation=n,n.finally((()=>{this._resetPresentation()}))}updatePresentation(e,{isP2P:t=!1,maxBitrate:n,degradationPreference:s}={}){return l(this,void 0,void 0,(function*(){const i=this.establishedSession;return i?this._streamPresentationCurrent?(this.promisePendingStartPresentation&&(yield this.promisePendingStartPresentation),this._sendPresentation(i,e,{isP2P:t,maxBitrate:n,degradationPreference:s,isNeedReinvite:!1})):Promise.reject(new Error("Presentation has not started yet")):Promise.reject(new Error("No session established"))}))}_resetPresentation(){delete this._streamPresentationCurrent,this.promisePendingStartPresentation=void 0,this.promisePendingStopPresentation=void 0}on(e,t){return this._uaEvents.on(e,t)}once(e,t){return this._uaEvents.once(e,t)}onceRace(e,t){return this._uaEvents.onceRace(e,t)}wait(e){return this._uaEvents.wait(e)}off(e,t){this._uaEvents.off(e,t)}onSession(e,t){return this._sessionEvents.on(e,t)}onceSession(e,t){return this._sessionEvents.once(e,t)}onceRaceSession(e,t){return this._sessionEvents.onceRace(e,t)}waitSession(e){return this._sessionEvents.wait(e)}offSession(e,t){this._sessionEvents.off(e,t)}isConfigured(){return!!this.ua}getConnectionConfiguration(){return Object.assign({},this._connectionConfiguration)}getRemoteStreams(){if(!this.connection)return;const e=this.connection.getReceivers().map((({track:e})=>e));return(e=>e.some((e=>{const{kind:t}=e;return"video"===t})))(e)?this._generateStreams(e):this._generateAudioStreams(e)}get connection(){var e;return null===(e=null==this?void 0:this.session)||void 0===e?void 0:e.connection}get remoteCallerData(){var e,t,n,s,i,r;return{displayName:null===(t=null===(e=null==this?void 0:this.incomingSession)||void 0===e?void 0:e.remote_identity)||void 0===t?void 0:t.display_name,host:null===(s=null===(n=null==this?void 0:this.incomingSession)||void 0===n?void 0:n.remote_identity)||void 0===s?void 0:s.uri.host,incomingNumber:null===(r=null===(i=null==this?void 0:this.incomingSession)||void 0===i?void 0:i.remote_identity)||void 0===r?void 0:r.uri.user,session:null==this?void 0:this.incomingSession}}get requested(){return this._cancelableConnect.requested||this._cancelableCreateUa.requested||this._cancelableCall.requested||this._cancelableAnswer.requested}get establishedSession(){return this.session&&this.session.isEstablished()?this.session:void 0}get isRegistered(){return!!this.ua&&this.ua.isRegistered()}get isRegisterConfig(){return!!this.ua&&this._isRegisterConfig}get isCallActive(){return!(!this.ua||!this.session)}get isAvailableIncomingCall(){return!!this.incomingSession}_init({sipServerUrl:e,sipWebSocketServerURL:t}){var n;this.getSipServerUrl=(n=e,e=>`sip:${e}@${n}`),this.socket=new this.JsSIP.WebSocketInterface(t)}_generateStream(e,t){const n=e.id,s=this._remoteStreams[n]||new MediaStream;return t&&s.addTrack(t),s.addTrack(e),this._remoteStreams[n]=s,s}_generateAudioStream(e){const t=e.id,n=this._remoteStreams[t]||new MediaStream;return n.addTrack(e),this._remoteStreams[t]=n,n}_generateStreams(e){const t=[];return e.forEach(((n,s)=>{if("audio"===n.kind)return;const i=n,r=e[s-1];let o;r&&"audio"===r.kind&&(o=r);const a=this._generateStream(i,o);t.push(a)}),[]),t}_generateAudioStreams(e){return e.map((e=>this._generateAudioStream(e)))}_cancelRequests(){this._cancelActionsRequests(),this._cancelCallRequests(),this._cancelConnectRequests()}_cancelConnectRequests(){this._cancelableConnect.cancelRequest()}_cancelCallRequests(){this._cancelableCall.cancelRequest(),this._cancelableAnswer.cancelRequest()}_cancelActionsRequests(){this._cancelableAnswer.cancelRequest(),this._cancelableSendDTMF.cancelRequest()}waitChannels(){return this.waitSession("channels")}waitSyncMediaState(){return this.waitSession("admin-force-sync-media-state")}sendChannels({inputChannels:e,outputChannels:t}){if(!this.session)throw new Error("No session established");const n=[`X-WEBRTC-INPUT-CHANNELS: ${e}`,`X-WEBRTC-OUTPUT-CHANNELS: ${t}`];return this.session.sendInfo("application/vinteo.webrtc.channels",void 0,{extraHeaders:n})}sendMediaState({cam:e,mic:t},n={noTerminateWhenError:!0}){if(!this.session)throw new Error("No session established");const s=["X-WEBRTC-MEDIA-STATE: currentstate","X-Vinteo-MainCam-State: "+ +e,"X-Vinteo-Mic-State: "+ +t];return this.session.sendInfo("application/vinteo.webrtc.mediastate",void 0,Object.assign(Object.assign({},n),{extraHeaders:s}))}_sendRefusalToTurnOn(e,t={noTerminateWhenError:!0}){if(!this.session)throw new Error("No session established");const n=[`X-Vinteo-Media-Type: ${"mic"==e?0:1}`];return this.session.sendInfo("application/vinteo.webrtc.refusal",void 0,Object.assign(Object.assign({},t),{extraHeaders:n}))}sendRefusalToTurnOnMic(e={noTerminateWhenError:!0}){if(!this.session)throw new Error("No session established");return this._sendRefusalToTurnOn("mic",e)}sendRefusalToTurnOnCam(e={noTerminateWhenError:!0}){if(!this.session)throw new Error("No session established");return this._sendRefusalToTurnOn("cam",e)}}const F=(e,t)=>!!e&&!!t&&e.toLowerCase().includes(t.toLowerCase()),B=e=>1e6*e,q=B(.06),x=B(4),L=(e,t)=>(e=>F(e,"av1"))(t)?.6*e:e,W=(e,t)=>{const n=(e=>e<=64?q:e<=128?B(.12):e<=256?B(.25):e<=384?B(.32):e<=426?B(.38):e<=640?B(.5):e<=848?B(.7):e<=1280?B(1):e<=1920?B(2):x)(e);return L(n,t)},H=s(),V=e=>(H.add(e),H().catch((e=>{console.debug("videoSendingBalancer: error",e)}))),j=({sender:e,scaleResolutionDownBy:t,maxBitrate:n,onSetParameters:s})=>V((()=>w(e,{scaleResolutionDownBy:t,maxBitrate:n},s))),X=({sender:e,codec:t},n)=>{const s=(e=>L(q,e))(t);return j({sender:e,maxBitrate:s,onSetParameters:n,scaleResolutionDownBy:200})},Y=({sender:e,track:t,codec:n},s)=>{const i=t.getSettings().width,r=W(i,n);return j({sender:e,maxBitrate:r,onSetParameters:s,scaleResolutionDownBy:1})},$=({mainCam:e,resolutionMainCam:t,sender:n,track:s,codec:i},r)=>{switch(e){case I.PAUSE_MAIN_CAM:return X({sender:n,codec:i},r);case I.RESUME_MAIN_CAM:return Y({sender:n,track:s,codec:i},r);case I.MAX_MAIN_CAM_RESOLUTION:return t?(({sender:e,track:t,resolution:n,codec:s},i)=>{const r=t.getSettings(),o=r.width,a=r.height,[c,d]=n.split("x"),l=o/+c,h=a/+d,u=Math.max(l,h,1),m=W(+c,s);return j({sender:e,maxBitrate:m,onSetParameters:i,scaleResolutionDownBy:u})})({sender:n,track:s,codec:i,resolution:t},r):Y({sender:n,track:s,codec:i},r);default:return Y({sender:n,track:s,codec:i},r)}},J={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},G=({mainCam:e,resolutionMainCam:t,connection:n,onSetParameters:s,ignoreForCodec:i})=>l(void 0,void 0,void 0,(function*(){const r=(e=>e.find((e=>{var t;return"video"===(null===(t=null==e?void 0:e.track)||void 0===t?void 0:t.kind)})))(n.getSenders());if(!r||!r.track)return J;const o=yield d(r);return F(o,i)?J:$({mainCam:e,resolutionMainCam:t,sender:r,codec:o,track:r.track},s)})),K=(e,{ignoreForCodec:t,onSetParameters:n}={})=>{const s=()=>{const{connection:s}=e;return s?G({connection:s,onSetParameters:n,ignoreForCodec:t}):Promise.reject(new Error("connection is not exist"))};let i=s;const r=s=>{i=()=>{const{mainCam:i,resolutionMainCam:r}=s,{connection:o}=e;return o?G({mainCam:i,resolutionMainCam:r,connection:o,onSetParameters:n,ignoreForCodec:t}):Promise.reject(new Error("connection is not exist"))},i()};return{subscribe:()=>{e.onSession("main-cam-control",r)},unsubscribe:()=>{e.offSession("main-cam-control",r)},balanceByTrack:s,resetMainCamControl(){i=s},reBalance:()=>i()}},z=e=>{const{url:t,cause:n}=e;let s=t;return"Bad Media Description"!==n&&"Not Found"!==n||(s=`${e.message.to.uri.user}@${e.message.to.uri.host}`),s};var Q;!function(e){e.CONNECT_SERVER_FAILED="CONNECT_SERVER_FAILED",e.WRONG_USER_OR_PASSWORD="WRONG_USER_OR_PASSWORD",e.BAD_MEDIA_ERROR="BAD_MEDIA_ERROR",e.NOT_FOUND_ERROR="NOT_FOUND_ERROR",e.WS_CONNECTION_FAILED="WS_CONNECTION_FAILED",e.CONNECT_SERVER_FAILED_BY_LINK="CONNECT_SERVER_FAILED_BY_LINK"}(Q||(Q={}));var Z=Object.freeze({__proto__:null,getLinkError:z,getTypeFromError:(e=new Error)=>{var t;const{cause:n,socket:s}=e;let i=Q.CONNECT_SERVER_FAILED;return"Forbidden"===n?i=Q.WRONG_USER_OR_PASSWORD:"Bad Media Description"===n?i=Q.BAD_MEDIA_ERROR:"Not Found"===n?i=Q.NOT_FOUND_ERROR:s&&3===(null===(t=null==s?void 0:s._ws)||void 0===t?void 0:t.readyState)?i=Q.WS_CONNECTION_FAILED:z(e)&&(i=Q.CONNECT_SERVER_FAILED_BY_LINK),i},getValuesFromError:(e=new Error)=>{const{code:t,cause:n,message:s}=e,i=z(e),r={};return s&&(r.message=s),i&&(r.link=i),t&&(r.code=t),n&&(r.cause=n),r}});const ee="sip-connector",te=i(ee),ne=()=>{i.enable(`${ee}`)},se=()=>{i.enable(`-${ee}`)},ie=e=>"purgatory"===e,re=e=>()=>(te("getRemoteStreams"),e.getRemoteStreams()),oe=e=>({track:t})=>{(({kind:e,readyState:t})=>"video"===e&&"live"===t)(t)&&e()},ae=({getRemoteStreams:e,setRemoteStreams:t})=>r((()=>{const n=e();te("remoteStreams",n),n&&t(n)}),200);var ce=Object.freeze({__proto__:null,error:Z,createSyncMediaState:({sipConnector:e})=>{const t=(e,t)=>(n={isSyncForced:!1})=>n.isSyncForced?e():t(),n=(e=>t=>(te("onStartMainCam"),e.onSession("admin-start-main-cam",t)))(e),s=(e=>t=>(te("onStopMainCam"),e.onSession("admin-stop-main-cam",t)))(e),i=(e=>t=>(te("onStartMic"),e.onSession("admin-start-mic",t)))(e),r=(e=>t=>(te("onStopMic"),e.onSession("admin-stop-mic",t)))(e);let o=()=>{},a=()=>{},c=()=>{},d=()=>{};return{start:e=>{(({onStartMainCamForced:e,onStartMainCamNotForced:l,onStopMainCamForced:h,onStopMainCamNotForced:u,onStartMicForced:m,onStartMicNotForced:g,onStopMicForced:_,onStopMicNotForced:S})=>{const E=t(e,l);o=n(E);const C=t(h,u);a=s(C);const f=t(m,g);c=i(f);const v=t(_,S);d=r(v)})(e)},stop:()=>{o(),a(),c(),d()}}},resolveAnswerIncomingCall:e=>t=>{const{mediaStream:n,extraHeaders:s,iceServers:i,degradationPreference:r,setRemoteStreams:o,onBeforeProgressCall:a,onSuccessProgressCall:c,onEnterPurgatory:d,onEnterConference:l,onFailProgressCall:h,onFinishProgressCall:u,onEndedCall:m}=t,g=ae({setRemoteStreams:o,getRemoteStreams:re(e)}),_=oe(g);te("answerIncomingCall",t);let S,E=!1;const C=(te("subscribeEnterConference: onEnterConference",l),d||l?e.onSession("enterRoom",(e=>{te("enterRoom",{_room:e,isSuccessProgressCall:E}),S=e,ie(S)?d&&d():l&&l({isSuccessProgressCall:E})})):()=>{});if(te("onBeforeProgressCall"),a){a((()=>{const{remoteCallerData:t}=e,{incomingNumber:n}=t;return n})())}return e.answerToIncomingCall({mediaStream:n,extraHeaders:s,iceServers:i,degradationPreference:r,ontrack:_}).then((t=>(te("onSuccess"),E=!0,g(),c&&c({isPurgatory:ie(S)}),e.onceRaceSession(["ended","failed"],(()=>{C(),m&&m()})),t))).catch((e=>{throw te("onFail"),h&&h(),C(),e})).finally((()=>{te("onFinish"),u&&u()}))},resolveConnectToServer:e=>t=>{const{conference:n,mediaStream:s,extraHeaders:i,iceServers:r,degradationPreference:o,setRemoteStreams:a,onBeforeProgressCall:c,onSuccessProgressCall:d,onEnterPurgatory:l,onEnterConference:h,onFailProgressCall:u,onFinishProgressCall:m,onEndedCall:g}=t,_=ae({setRemoteStreams:a,getRemoteStreams:re(e)}),S=oe(_);te("callToServer",t);let E,C=!1;const f=(te("subscribeEnterConference: onEnterConference",h),l||h?e.onSession("enterRoom",(e=>{te("enterRoom",{_room:e,isSuccessProgressCall:C}),E=e,ie(E)?l&&l():h&&h({isSuccessProgressCall:C})})):()=>{});return te("onBeforeProgressCall"),c&&c(n),(te("startCall"),e.call({mediaStream:s,extraHeaders:i,iceServers:r,degradationPreference:o,number:n,ontrack:S})).then((t=>(te("onSuccess"),C=!0,_(),d&&d({isPurgatory:ie(E)}),e.onceRaceSession(["ended","failed"],(()=>{f(),g&&g()})),t))).catch((e=>{throw te("onFail"),u&&u(),f(),e})).finally((()=>{te("onFinish"),m&&m()}))},resolveDisconnectFromServer:e=>()=>(te("disconnectFromServer"),e.disconnect().then((()=>(te("disconnectFromServer: then"),!1))).catch((e=>(te("disconnectFromServer: catch",e),!1)))),hasPurgatory:ie,resolveAskPermissionToEnableCam:e=>()=>e.isCallActive?(te("askPermissionToEnableCam"),e.askPermissionToEnableCam()):Promise.resolve(),resolveStopShareSipConnector:({sipConnector:e})=>({isP2P:t=!1}={isP2P:!1})=>(te("stopShareSipConnector"),e.stopPresentation({isP2P:t}).catch(te)),resolveOnMustStopPresentation:e=>t=>(te("onMustStopPresentation"),e.onSession("mustStopPresentation",t)),resolveOnUseLicense:e=>t=>(te("onUseLicense"),e.onSession("useLicense",t)),resolveSendMediaState:e=>({isEnabledCam:t,isEnabledMic:n})=>e.isCallActive?(te("sendMediaState"),e.sendMediaState({cam:t,mic:n})):Promise.resolve(),resolveSendRefusalToTurnOnCam:e=>()=>e.isCallActive?(te("sendRefusalToTurnOnCam"),e.sendRefusalToTurnOnCam().catch((e=>{te("sendRefusalToTurnOnCam: error",e)}))):Promise.resolve(),resolveSendRefusalToTurnOnMic:e=>()=>e.isCallActive?(te("sendRefusalToTurnOnMic"),e.sendRefusalToTurnOnMic().catch((e=>{te("sendRefusalToTurnOnMic: error",e)}))):Promise.resolve(),resolveStartPresentation:({maxBitrate:e=1e6,sipConnector:t})=>({mediaStream:n,isP2P:s=!1})=>(te("startPresentation"),t.startPresentation(n,{isP2P:s,maxBitrate:e})),resolveUpdatePresentation:({sipConnector:e,maxBitrate:t=1e6})=>({mediaStream:n,isP2P:s=!1})=>(te("updatePresentation"),e.updatePresentation(n,{isP2P:s,maxBitrate:t})),resolveUpdateRemoteStreams:ae,resolveGetRemoteStreams:re,sendDTMFAccumulated:({accumulatedKeys:e,sendKey:t,canRunTask:n})=>{const s=(e=>a((e=>c(e,"")),(t=>t.map((t=>()=>e(t))))))(t),i=s(e);return o(i,n)}});export{y as EUseLicense,u as causes,k as default,se as disableDebug,ne as enableDebug,f as eventNames,d as getCodecFromSender,D as hasCanceledCallError,K as resolveVideoSendingBalancer,ce as tools};
|
|
2
2
|
//# sourceMappingURL=index.es5.js.map
|