New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vertojs

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vertojs - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

1

dist/index.d.ts

@@ -24,2 +24,3 @@ import { JsonRpcClient, JsonRpcClientParams } from './json-rpc';

constructor(conf: RTCConfiguration, rpc: JsonRpcClient, dest?: string, id?: string, options?: VertoCallOptions, ice_timeout?: number, debug?: boolean);
getStats(): Promise<RTCStatsReport>;
onAnswer(sdp: string): void;

@@ -26,0 +27,0 @@ onMedia(sdp: string): void;

2

dist/index.js

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Verto={})}(this,(function(t){"use strict";class e{constructor(t,e){this.request_id=1,this.queue=[],this.callbacks=[],this.debug=!1,this.debug=e,this.options=Object.assign({},t)}initSocket_(){this.socket_=new WebSocket(this.options.socketUrl),this.socket_.onmessage=this.onMessage.bind(this),this.socket_.onclose=()=>{setTimeout((()=>{this.debug&&console.log("WSS reconnect"),this.initSocket_()}),1e3)},this.socket_.onopen=()=>{let t="";for(this.reconnectHandler&&this.reconnectHandler();t=this.queue.pop();)this.socket.send(t)}}closeSocket_(){this.socket_.onclose=()=>{console.log("WebSocket is closed now.")},this.socket_.close()}get socket(){return this.socket_||this.initSocket_(),this.socket_}onMessage(t){let e;try{e=JSON.parse(t.data)}catch(t){}if(this.debug&&console.log(e),"object"==typeof e&&"jsonrpc"in e&&"2.0"===e.jsonrpc)if("method"in e)this.eventHandler(e.method,e.params);else if("result"in e&&this.callbacks[e.id]){let t=this.callbacks[e.id].success_cb;delete this.callbacks[e.id],t(Object.assign({},e.result))}else if("error"in e&&this.callbacks[e.id]){let t=this.callbacks[e.id].error_cb,s=Object.assign({},this.callbacks[e.id]);delete this.callbacks[e.id],-32e3==e.error.code&&this.options.login&&this.options.passwd?this.call("login",{login:this.options.login,passwd:this.options.passwd,loginParams:this.options.loginParams,userVariables:this.options.userVariables},(t=>{this.socketCall_(s)}),(s=>{t(Object.assign({},e.result))})):t(Object.assign({},e.result))}}socketCall_({request:t,success_cb:e,error_cb:s}){t.id=this.request_id++;let i=JSON.stringify(t);this.callbacks[t.id]={request:t,success_cb:e,error_cb:s},this.socket.readyState<1?(this.queue.push(i),this.debug&&console.log("Queued",i)):(this.socket.send(i),this.debug&&console.log("Sent",i))}setEventHandler(t){this.eventHandler=t}setReconnectHandler(t){this.reconnectHandler=t}call(t,e,s,i){let n={jsonrpc:"2.0",method:t,params:Object.assign({},e),id:0};this.socket&&this.socketCall_({request:n,success_cb:s,error_cb:i})}close(){this.queue=[],this.callbacks=[],this.eventHandler=null,this.reconnectHandler=null,this.closeSocket_()}}const s="undefined"!=typeof window&&void 0!==window.crypto&&void 0!==window.crypto.getRandomValues?function(){let t=new Uint16Array(8);window.crypto.getRandomValues(t);let e=function(t){let e=t.toString(16);for(;e.length<4;)e="0"+e;return e};return e(t[0])+e(t[1])+"-"+e(t[2])+"-"+e(t[3])+"-"+e(t[4])+"-"+e(t[5])+e(t[6])+e(t[7])}:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){let e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)}))};class i{constructor(t){this.event_handlers={},this.debug=t}subscribeEvent(t,e){let i=s();return this.event_handlers[t]||(this.event_handlers[t]=[]),this.event_handlers[t].push({id:i,code:e}),i}unsubscribeEvent(t,e){this.event_handlers[t]=e?this.event_handlers[t].map(((t,s,i)=>t.id==e?void 0:t)):[]}dispatchEvent(t,e){if(this.debug&&console.log("Dispatch",t,e),this.event_handlers[t])for(let s of this.event_handlers[t])s.code(e)}}var n,o;t.CallDirection=void 0,(n=t.CallDirection||(t.CallDirection={}))[n.Incoming=0]="Incoming",n[n.Outgoing=1]="Outgoing",function(t){t[t.None=0]="None",t[t.Schedulled=1]="Schedulled",t[t.MessageSent=2]="MessageSent"}(o||(o={}));class c extends i{constructor(e,s,i,n){super(n),this.state=o.None,this.direction=t.CallDirection.Incoming,this.ice_timeout=i||3e3,e.iceCandidatePoolSize="iceCandidatePoolSize"in e?e.iceCandidatePoolSize:1,this.pc=new RTCPeerConnection(e),this.pc.ontrack=this.onTrack.bind(this),this.pc.onnegotiationneeded=this.onNegotiation.bind(this),this.pc.onicecandidate=this.onCandidate.bind(this),this.pc.onicegatheringstatechange=this.onIceGatheringStateChange.bind(this),void 0!==s&&(this.direction=s)}onTrack(t){this.dispatchEvent("track",t.track)}onCandidate(t){}onIceGatheringStateChange(t){if("complete"==this.pc.iceGatheringState){if(this.ice_timer&&clearTimeout(this.ice_timer),this.state==o.MessageSent)return;this.direction?this.dispatchEvent("send-offer",this.pc.localDescription):this.dispatchEvent("send-answer",this.pc.localDescription)}}iceTimerTriggered(){this.debug&&console.log(this.pc),this.state==o.Schedulled&&(this.state=o.MessageSent,this.direction?this.dispatchEvent("send-offer",this.pc.localDescription):this.dispatchEvent("send-answer",this.pc.localDescription))}onNegotiation(){this.pc.createOffer().then((t=>(this.ice_timer=setTimeout(this.iceTimerTriggered.bind(this),this.ice_timeout),this.pc.setLocalDescription(t)))).then((()=>{this.state=o.Schedulled})).catch((t=>{}))}onMedia(t){this.pc.setRemoteDescription(new RTCSessionDescription({type:"answer",sdp:t})).then((()=>{this.debug&&console.log("got remote media")})).catch((t=>{this.debug&&console.log("remote media error",t)}))}preSdp(t){this.presdp=t}addTrack(t){this.pc.addTrack(t)}answer(t){for(let e of t)this.pc.addTrack(e);this.ice_timer=setTimeout(this.iceTimerTriggered.bind(this),this.ice_timeout),this.pc.setRemoteDescription(new RTCSessionDescription({type:"offer",sdp:this.presdp})).then((()=>{this.pc.createAnswer().then((t=>{this.pc.setLocalDescription(t),this.state=o.Schedulled}))}))}}const a="verto.invite",h="verto.answer",l="verto.bye",r="verto.media",d="verto.modify",p="verto.info";class g extends i{constructor(e,i,n,o,l,r,d){super(d),this.id=o||s(),this.options=l||{},this.direction=n?t.CallDirection.Outgoing:t.CallDirection.Incoming,this.rtc=new c(e,this.direction,r,d),this.rpc=i,this.rtc.subscribeEvent("send-offer",(t=>{let e=Object.assign({},this.options);e=Object.assign(e,{destination_number:n,callID:this.id}),this.rpc.call(a,{dialogParams:e,sdp:t.sdp},(t=>{}),(t=>{}))})),this.rtc.subscribeEvent("send-answer",(t=>{this.rpc.call(h,{dialogParams:{destination_number:n,callID:this.id},sdp:t.sdp},(t=>{}),(t=>{}))})),this.rtc.subscribeEvent("track",(t=>{this.dispatchEvent("track",t)}))}onAnswer(t){t&&this.rtc.onMedia(t),this.debug&&console.log("answer"),this.dispatchEvent("answer")}onMedia(t){this.rtc.onMedia(t),this.dispatchEvent("media")}addTrack(t){this.rtc.addTrack(t)}preSdp(t){this.rtc.preSdp(t)}answer(t){this.rtc.answer(t)}hangup(t={}){this.rpc.call(l,Object.assign({dialogParams:{callID:this.id}},t),(t=>{}),(t=>{})),this.clear()}clear(){this.dispatchEvent("bye",this)}dtmf(t){this.rpc.call(p,{dtmf:t.toString(),dialogParams:{callID:this.id}},(t=>{}),(t=>{}))}hold(t){this.rpc.call(d,{action:"hold",dialogParams:Object.assign(Object.assign({callID:this.id},this.options),t)},(t=>{"held"===t.holdState?(this.holdStatus=!0,this.dispatchEvent("hold",this)):(this.holdStatus=!1,this.dispatchEvent("unhold",this))}),(t=>{}))}unhold(t){this.rpc.call(d,{action:"unhold",dialogParams:Object.assign(Object.assign({callID:this.id},this.options),t)},(t=>{"held"===t.holdState?(this.holdStatus=!0,this.dispatchEvent("hold",this)):(this.holdStatus=!1,this.dispatchEvent("unhold",this))}),(t=>{}))}toggleHold(t){this.rpc.call(d,{action:"toggleHold",dialogParams:Object.assign(Object.assign({callID:this.id},this.options),t)},(t=>{"held"===t.holdState?(this.holdStatus=!0,this.dispatchEvent("hold",this)):(this.holdStatus=!1,this.dispatchEvent("unhold",this))}),(t=>{}))}}t.Verto=class extends i{constructor(t){super(t.debug),this.calls={},this.logged_in=!1,this.options=t,this.rpc=new e(t.transportConfig,t.debug),this.rpc.setEventHandler(((t,e)=>{switch(t){case h:{let t=e.callID;this.calls[t].onAnswer(e.sdp);break}case r:{let t=e.callID;this.calls[t].onMedia(e.sdp);break}case a:{let t=new g(this.options.rtcConfig,this.rpc,"",e.callID,{caller_id_name:e.caller_id_name,caller_id_number:e.caller_id_number},this.options.ice_timeout,this.options.debug);t.preSdp(e.sdp),this.calls[e.callID]=t,this.dispatchEvent("invite",t);break}case l:this.calls[e.callID].clear(),delete this.calls[e.callID];break}})),this.rpc.setReconnectHandler((()=>{this.logged_in&&this.login()})),this.options.rtcConfig=Object.assign({},this.options.rtcConfig||{})}login(){return new Promise(((t,e)=>{this.rpc.call("login",{login:this.options.transportConfig.login,passwd:this.options.transportConfig.passwd},(e=>{this.sessid=e.sessid,this.logged_in=!0,t(e)}),(t=>{e(t)}))}))}call(t,e,i){let n=new g(this.options.rtcConfig,this.rpc,e,s(),i,this.options.ice_timeout,this.options.debug);for(let e of t)n.addTrack(e);return this.calls[n.id]=n,n}isLogged(){return this.logged_in}logout(){this.calls&&Object.keys(this.calls).forEach((t=>{this.calls[t].hangup()})),this.rpc.close(),this.rpc=null,this.sessid=null,this.logged_in=!1}},Object.defineProperty(t,"__esModule",{value:!0})}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Verto={})}(this,(function(t){"use strict";class e{constructor(t,e){this.request_id=1,this.queue=[],this.callbacks=[],this.debug=!1,this.debug=e,this.options=Object.assign({},t)}initSocket_(){this.socket_=new WebSocket(this.options.socketUrl),this.socket_.onmessage=this.onMessage.bind(this),this.socket_.onclose=()=>{setTimeout((()=>{this.debug&&console.log("WSS reconnect"),this.initSocket_()}),1e3)},this.socket_.onopen=()=>{let t="";for(this.reconnectHandler&&this.reconnectHandler();t=this.queue.pop();)this.socket.send(t)}}closeSocket_(){this.socket_.onclose=()=>{console.log("WebSocket is closed now.")},this.socket_.close()}get socket(){return this.socket_||this.initSocket_(),this.socket_}onMessage(t){let e;try{e=JSON.parse(t.data)}catch(t){}if(this.debug&&console.log(e),"object"==typeof e&&"jsonrpc"in e&&"2.0"===e.jsonrpc)if("method"in e)this.eventHandler(e.method,e.params);else if("result"in e&&this.callbacks[e.id]){let t=this.callbacks[e.id].success_cb;delete this.callbacks[e.id],t(Object.assign({},e.result))}else if("error"in e&&this.callbacks[e.id]){let t=this.callbacks[e.id].error_cb,s=Object.assign({},this.callbacks[e.id]);delete this.callbacks[e.id],-32e3==e.error.code&&this.options.login&&this.options.passwd?this.call("login",{login:this.options.login,passwd:this.options.passwd,loginParams:this.options.loginParams,userVariables:this.options.userVariables},(t=>{this.socketCall_(s)}),(s=>{t(Object.assign({},e.result))})):t(Object.assign({},e.result))}}socketCall_({request:t,success_cb:e,error_cb:s}){t.id=this.request_id++;let i=JSON.stringify(t);this.callbacks[t.id]={request:t,success_cb:e,error_cb:s},this.socket.readyState<1?(this.queue.push(i),this.debug&&console.log("Queued",i)):(this.socket.send(i),this.debug&&console.log("Sent",i))}setEventHandler(t){this.eventHandler=t}setReconnectHandler(t){this.reconnectHandler=t}call(t,e,s,i){let n={jsonrpc:"2.0",method:t,params:Object.assign({},e),id:0};this.socket&&this.socketCall_({request:n,success_cb:s,error_cb:i})}close(){this.queue=[],this.callbacks=[],this.eventHandler=null,this.reconnectHandler=null,this.closeSocket_()}}const s="undefined"!=typeof window&&void 0!==window.crypto&&void 0!==window.crypto.getRandomValues?function(){let t=new Uint16Array(8);window.crypto.getRandomValues(t);let e=function(t){let e=t.toString(16);for(;e.length<4;)e="0"+e;return e};return e(t[0])+e(t[1])+"-"+e(t[2])+"-"+e(t[3])+"-"+e(t[4])+"-"+e(t[5])+e(t[6])+e(t[7])}:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){let e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)}))};class i{constructor(t){this.event_handlers={},this.debug=t}subscribeEvent(t,e){let i=s();return this.event_handlers[t]||(this.event_handlers[t]=[]),this.event_handlers[t].push({id:i,code:e}),i}unsubscribeEvent(t,e){this.event_handlers[t]=e?this.event_handlers[t].map(((t,s,i)=>t.id==e?void 0:t)):[]}dispatchEvent(t,e){if(this.debug&&console.log("Dispatch",t,e),this.event_handlers[t])for(let s of this.event_handlers[t])s.code(e)}}var n,o;t.CallDirection=void 0,(n=t.CallDirection||(t.CallDirection={}))[n.Incoming=0]="Incoming",n[n.Outgoing=1]="Outgoing",function(t){t[t.None=0]="None",t[t.Schedulled=1]="Schedulled",t[t.MessageSent=2]="MessageSent"}(o||(o={}));class c extends i{constructor(e,s,i,n){super(n),this.state=o.None,this.direction=t.CallDirection.Incoming,this.ice_timeout=i||3e3,e.iceCandidatePoolSize="iceCandidatePoolSize"in e?e.iceCandidatePoolSize:1,this.pc=new RTCPeerConnection(e),this.pc.ontrack=this.onTrack.bind(this),this.pc.onnegotiationneeded=this.onNegotiation.bind(this),this.pc.onicecandidate=this.onCandidate.bind(this),this.pc.onicegatheringstatechange=this.onIceGatheringStateChange.bind(this),void 0!==s&&(this.direction=s)}onTrack(t){this.dispatchEvent("track",t.track)}onCandidate(t){}onIceGatheringStateChange(t){if("complete"==this.pc.iceGatheringState){if(this.ice_timer&&clearTimeout(this.ice_timer),this.state==o.MessageSent)return;this.direction?this.dispatchEvent("send-offer",this.pc.localDescription):this.dispatchEvent("send-answer",this.pc.localDescription)}}iceTimerTriggered(){this.debug&&console.log(this.pc),this.state==o.Schedulled&&(this.state=o.MessageSent,this.direction?this.dispatchEvent("send-offer",this.pc.localDescription):this.dispatchEvent("send-answer",this.pc.localDescription))}onNegotiation(){this.pc.createOffer().then((t=>(this.ice_timer=setTimeout(this.iceTimerTriggered.bind(this),this.ice_timeout),this.pc.setLocalDescription(t)))).then((()=>{this.state=o.Schedulled})).catch((t=>{}))}getStats(){return this.pc?this.pc.getStats():Promise.reject()}onMedia(t){this.pc.setRemoteDescription(new RTCSessionDescription({type:"answer",sdp:t})).then((()=>{this.debug&&console.log("got remote media")})).catch((t=>{this.debug&&console.log("remote media error",t)}))}preSdp(t){this.presdp=t}addTrack(t){this.pc.addTrack(t)}answer(t){for(let e of t)this.pc.addTrack(e);this.ice_timer=setTimeout(this.iceTimerTriggered.bind(this),this.ice_timeout),this.pc.setRemoteDescription(new RTCSessionDescription({type:"offer",sdp:this.presdp})).then((()=>{this.pc.createAnswer().then((t=>{this.pc.setLocalDescription(t),this.state=o.Schedulled}))}))}}const a="verto.invite",h="verto.answer",l="verto.bye",r="verto.media",d="verto.modify",p="verto.info";class g extends i{constructor(e,i,n,o,l,r,d){super(d),this.id=o||s(),this.options=l||{},this.direction=n?t.CallDirection.Outgoing:t.CallDirection.Incoming,this.rtc=new c(e,this.direction,r,d),this.rpc=i,this.rtc.subscribeEvent("send-offer",(t=>{let e=Object.assign({},this.options);e=Object.assign(e,{destination_number:n,callID:this.id}),this.rpc.call(a,{dialogParams:e,sdp:t.sdp},(t=>{}),(t=>{}))})),this.rtc.subscribeEvent("send-answer",(t=>{this.rpc.call(h,{dialogParams:{destination_number:n,callID:this.id},sdp:t.sdp},(t=>{}),(t=>{}))})),this.rtc.subscribeEvent("track",(t=>{this.dispatchEvent("track",t)}))}getStats(){return this.rtc.getStats()}onAnswer(t){t&&this.rtc.onMedia(t),this.debug&&console.log("answer"),this.dispatchEvent("answer")}onMedia(t){this.rtc.onMedia(t),this.dispatchEvent("media")}addTrack(t){this.rtc.addTrack(t)}preSdp(t){this.rtc.preSdp(t)}answer(t){this.rtc.answer(t)}hangup(t={}){this.rpc.call(l,Object.assign({dialogParams:{callID:this.id}},t),(t=>{}),(t=>{})),this.clear()}clear(){this.dispatchEvent("bye",this)}dtmf(t){this.rpc.call(p,{dtmf:t.toString(),dialogParams:{callID:this.id}},(t=>{}),(t=>{}))}hold(t){this.rpc.call(d,{action:"hold",dialogParams:Object.assign(Object.assign({callID:this.id},this.options),t)},(t=>{"held"===t.holdState?(this.holdStatus=!0,this.dispatchEvent("hold",this)):(this.holdStatus=!1,this.dispatchEvent("unhold",this))}),(t=>{}))}unhold(t){this.rpc.call(d,{action:"unhold",dialogParams:Object.assign(Object.assign({callID:this.id},this.options),t)},(t=>{"held"===t.holdState?(this.holdStatus=!0,this.dispatchEvent("hold",this)):(this.holdStatus=!1,this.dispatchEvent("unhold",this))}),(t=>{}))}toggleHold(t){this.rpc.call(d,{action:"toggleHold",dialogParams:Object.assign(Object.assign({callID:this.id},this.options),t)},(t=>{"held"===t.holdState?(this.holdStatus=!0,this.dispatchEvent("hold",this)):(this.holdStatus=!1,this.dispatchEvent("unhold",this))}),(t=>{}))}}t.Verto=class extends i{constructor(t){super(t.debug),this.calls={},this.logged_in=!1,this.options=t,this.rpc=new e(t.transportConfig,t.debug),this.rpc.setEventHandler(((t,e)=>{switch(t){case h:{let t=e.callID;this.calls[t].onAnswer(e.sdp);break}case r:{let t=e.callID;this.calls[t].onMedia(e.sdp);break}case a:{let t=new g(this.options.rtcConfig,this.rpc,"",e.callID,{caller_id_name:e.caller_id_name,caller_id_number:e.caller_id_number},this.options.ice_timeout,this.options.debug);t.preSdp(e.sdp),this.calls[e.callID]=t,this.dispatchEvent("invite",t);break}case l:this.calls[e.callID].clear(),delete this.calls[e.callID];break}})),this.rpc.setReconnectHandler((()=>{this.logged_in&&this.login()})),this.options.rtcConfig=Object.assign({},this.options.rtcConfig||{})}login(){return new Promise(((t,e)=>{this.rpc.call("login",{login:this.options.transportConfig.login,passwd:this.options.transportConfig.passwd},(e=>{this.sessid=e.sessid,this.logged_in=!0,t(e)}),(t=>{e(t)}))}))}call(t,e,i){let n=new g(this.options.rtcConfig,this.rpc,e,s(),i,this.options.ice_timeout,this.options.debug);for(let e of t)n.addTrack(e);return this.calls[n.id]=n,n}isLogged(){return this.logged_in}logout(){this.calls&&Object.keys(this.calls).forEach((t=>{this.calls[t].hangup()})),this.rpc.close(),this.rpc=null,this.sessid=null,this.logged_in=!1}},Object.defineProperty(t,"__esModule",{value:!0})}));

@@ -19,2 +19,3 @@ import { VertoBase } from './base';

private onNegotiation;
getStats(): Promise<RTCStatsReport>;
onMedia(sdp: string): void;

@@ -21,0 +22,0 @@ preSdp(sdp: string): void;

@@ -1,1 +0,1 @@

var Verto=function(t){"use strict";class e{constructor(t,e){this.request_id=1,this.queue=[],this.callbacks=[],this.debug=!1,this.debug=e,this.options=Object.assign({},t)}initSocket_(){this.socket_=new WebSocket(this.options.socketUrl),this.socket_.onmessage=this.onMessage.bind(this),this.socket_.onclose=()=>{setTimeout((()=>{this.debug&&console.log("WSS reconnect"),this.initSocket_()}),1e3)},this.socket_.onopen=()=>{let t="";for(this.reconnectHandler&&this.reconnectHandler();t=this.queue.pop();)this.socket.send(t)}}closeSocket_(){this.socket_.onclose=()=>{console.log("WebSocket is closed now.")},this.socket_.close()}get socket(){return this.socket_||this.initSocket_(),this.socket_}onMessage(t){let e;try{e=JSON.parse(t.data)}catch(t){}if(this.debug&&console.log(e),"object"==typeof e&&"jsonrpc"in e&&"2.0"===e.jsonrpc)if("method"in e)this.eventHandler(e.method,e.params);else if("result"in e&&this.callbacks[e.id]){let t=this.callbacks[e.id].success_cb;delete this.callbacks[e.id],t(Object.assign({},e.result))}else if("error"in e&&this.callbacks[e.id]){let t=this.callbacks[e.id].error_cb,s=Object.assign({},this.callbacks[e.id]);delete this.callbacks[e.id],-32e3==e.error.code&&this.options.login&&this.options.passwd?this.call("login",{login:this.options.login,passwd:this.options.passwd,loginParams:this.options.loginParams,userVariables:this.options.userVariables},(t=>{this.socketCall_(s)}),(s=>{t(Object.assign({},e.result))})):t(Object.assign({},e.result))}}socketCall_({request:t,success_cb:e,error_cb:s}){t.id=this.request_id++;let i=JSON.stringify(t);this.callbacks[t.id]={request:t,success_cb:e,error_cb:s},this.socket.readyState<1?(this.queue.push(i),this.debug&&console.log("Queued",i)):(this.socket.send(i),this.debug&&console.log("Sent",i))}setEventHandler(t){this.eventHandler=t}setReconnectHandler(t){this.reconnectHandler=t}call(t,e,s,i){let n={jsonrpc:"2.0",method:t,params:Object.assign({},e),id:0};this.socket&&this.socketCall_({request:n,success_cb:s,error_cb:i})}close(){this.queue=[],this.callbacks=[],this.eventHandler=null,this.reconnectHandler=null,this.closeSocket_()}}const s="undefined"!=typeof window&&void 0!==window.crypto&&void 0!==window.crypto.getRandomValues?function(){let t=new Uint16Array(8);window.crypto.getRandomValues(t);let e=function(t){let e=t.toString(16);for(;e.length<4;)e="0"+e;return e};return e(t[0])+e(t[1])+"-"+e(t[2])+"-"+e(t[3])+"-"+e(t[4])+"-"+e(t[5])+e(t[6])+e(t[7])}:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){let e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)}))};class i{constructor(t){this.event_handlers={},this.debug=t}subscribeEvent(t,e){let i=s();return this.event_handlers[t]||(this.event_handlers[t]=[]),this.event_handlers[t].push({id:i,code:e}),i}unsubscribeEvent(t,e){this.event_handlers[t]=e?this.event_handlers[t].map(((t,s,i)=>t.id==e?void 0:t)):[]}dispatchEvent(t,e){if(this.debug&&console.log("Dispatch",t,e),this.event_handlers[t])for(let s of this.event_handlers[t])s.code(e)}}var n,o;t.CallDirection=void 0,(n=t.CallDirection||(t.CallDirection={}))[n.Incoming=0]="Incoming",n[n.Outgoing=1]="Outgoing",function(t){t[t.None=0]="None",t[t.Schedulled=1]="Schedulled",t[t.MessageSent=2]="MessageSent"}(o||(o={}));class c extends i{constructor(e,s,i,n){super(n),this.state=o.None,this.direction=t.CallDirection.Incoming,this.ice_timeout=i||3e3,e.iceCandidatePoolSize="iceCandidatePoolSize"in e?e.iceCandidatePoolSize:1,this.pc=new RTCPeerConnection(e),this.pc.ontrack=this.onTrack.bind(this),this.pc.onnegotiationneeded=this.onNegotiation.bind(this),this.pc.onicecandidate=this.onCandidate.bind(this),this.pc.onicegatheringstatechange=this.onIceGatheringStateChange.bind(this),void 0!==s&&(this.direction=s)}onTrack(t){this.dispatchEvent("track",t.track)}onCandidate(t){}onIceGatheringStateChange(t){if("complete"==this.pc.iceGatheringState){if(this.ice_timer&&clearTimeout(this.ice_timer),this.state==o.MessageSent)return;this.direction?this.dispatchEvent("send-offer",this.pc.localDescription):this.dispatchEvent("send-answer",this.pc.localDescription)}}iceTimerTriggered(){this.debug&&console.log(this.pc),this.state==o.Schedulled&&(this.state=o.MessageSent,this.direction?this.dispatchEvent("send-offer",this.pc.localDescription):this.dispatchEvent("send-answer",this.pc.localDescription))}onNegotiation(){this.pc.createOffer().then((t=>(this.ice_timer=setTimeout(this.iceTimerTriggered.bind(this),this.ice_timeout),this.pc.setLocalDescription(t)))).then((()=>{this.state=o.Schedulled})).catch((t=>{}))}onMedia(t){this.pc.setRemoteDescription(new RTCSessionDescription({type:"answer",sdp:t})).then((()=>{this.debug&&console.log("got remote media")})).catch((t=>{this.debug&&console.log("remote media error",t)}))}preSdp(t){this.presdp=t}addTrack(t){this.pc.addTrack(t)}answer(t){for(let e of t)this.pc.addTrack(e);this.ice_timer=setTimeout(this.iceTimerTriggered.bind(this),this.ice_timeout),this.pc.setRemoteDescription(new RTCSessionDescription({type:"offer",sdp:this.presdp})).then((()=>{this.pc.createAnswer().then((t=>{this.pc.setLocalDescription(t),this.state=o.Schedulled}))}))}}const a="verto.invite",h="verto.answer",l="verto.bye",r="verto.media",d="verto.modify",p="verto.info";class g extends i{constructor(e,i,n,o,l,r,d){super(d),this.id=o||s(),this.options=l||{},this.direction=n?t.CallDirection.Outgoing:t.CallDirection.Incoming,this.rtc=new c(e,this.direction,r,d),this.rpc=i,this.rtc.subscribeEvent("send-offer",(t=>{let e=Object.assign({},this.options);e=Object.assign(e,{destination_number:n,callID:this.id}),this.rpc.call(a,{dialogParams:e,sdp:t.sdp},(t=>{}),(t=>{}))})),this.rtc.subscribeEvent("send-answer",(t=>{this.rpc.call(h,{dialogParams:{destination_number:n,callID:this.id},sdp:t.sdp},(t=>{}),(t=>{}))})),this.rtc.subscribeEvent("track",(t=>{this.dispatchEvent("track",t)}))}onAnswer(t){t&&this.rtc.onMedia(t),this.debug&&console.log("answer"),this.dispatchEvent("answer")}onMedia(t){this.rtc.onMedia(t),this.dispatchEvent("media")}addTrack(t){this.rtc.addTrack(t)}preSdp(t){this.rtc.preSdp(t)}answer(t){this.rtc.answer(t)}hangup(t={}){this.rpc.call(l,Object.assign({dialogParams:{callID:this.id}},t),(t=>{}),(t=>{})),this.clear()}clear(){this.dispatchEvent("bye",this)}dtmf(t){this.rpc.call(p,{dtmf:t.toString(),dialogParams:{callID:this.id}},(t=>{}),(t=>{}))}hold(t){this.rpc.call(d,{action:"hold",dialogParams:Object.assign(Object.assign({callID:this.id},this.options),t)},(t=>{"held"===t.holdState?(this.holdStatus=!0,this.dispatchEvent("hold",this)):(this.holdStatus=!1,this.dispatchEvent("unhold",this))}),(t=>{}))}unhold(t){this.rpc.call(d,{action:"unhold",dialogParams:Object.assign(Object.assign({callID:this.id},this.options),t)},(t=>{"held"===t.holdState?(this.holdStatus=!0,this.dispatchEvent("hold",this)):(this.holdStatus=!1,this.dispatchEvent("unhold",this))}),(t=>{}))}toggleHold(t){this.rpc.call(d,{action:"toggleHold",dialogParams:Object.assign(Object.assign({callID:this.id},this.options),t)},(t=>{"held"===t.holdState?(this.holdStatus=!0,this.dispatchEvent("hold",this)):(this.holdStatus=!1,this.dispatchEvent("unhold",this))}),(t=>{}))}}return t.Verto=class extends i{constructor(t){super(t.debug),this.calls={},this.logged_in=!1,this.options=t,this.rpc=new e(t.transportConfig,t.debug),this.rpc.setEventHandler(((t,e)=>{switch(t){case h:{let t=e.callID;this.calls[t].onAnswer(e.sdp);break}case r:{let t=e.callID;this.calls[t].onMedia(e.sdp);break}case a:{let t=new g(this.options.rtcConfig,this.rpc,"",e.callID,{caller_id_name:e.caller_id_name,caller_id_number:e.caller_id_number},this.options.ice_timeout,this.options.debug);t.preSdp(e.sdp),this.calls[e.callID]=t,this.dispatchEvent("invite",t);break}case l:this.calls[e.callID].clear(),delete this.calls[e.callID];break}})),this.rpc.setReconnectHandler((()=>{this.logged_in&&this.login()})),this.options.rtcConfig=Object.assign({},this.options.rtcConfig||{})}login(){return new Promise(((t,e)=>{this.rpc.call("login",{login:this.options.transportConfig.login,passwd:this.options.transportConfig.passwd},(e=>{this.sessid=e.sessid,this.logged_in=!0,t(e)}),(t=>{e(t)}))}))}call(t,e,i){let n=new g(this.options.rtcConfig,this.rpc,e,s(),i,this.options.ice_timeout,this.options.debug);for(let e of t)n.addTrack(e);return this.calls[n.id]=n,n}isLogged(){return this.logged_in}logout(){this.calls&&Object.keys(this.calls).forEach((t=>{this.calls[t].hangup()})),this.rpc.close(),this.rpc=null,this.sessid=null,this.logged_in=!1}},Object.defineProperty(t,"__esModule",{value:!0}),t}({});
var Verto=function(t){"use strict";class e{constructor(t,e){this.request_id=1,this.queue=[],this.callbacks=[],this.debug=!1,this.debug=e,this.options=Object.assign({},t)}initSocket_(){this.socket_=new WebSocket(this.options.socketUrl),this.socket_.onmessage=this.onMessage.bind(this),this.socket_.onclose=()=>{setTimeout((()=>{this.debug&&console.log("WSS reconnect"),this.initSocket_()}),1e3)},this.socket_.onopen=()=>{let t="";for(this.reconnectHandler&&this.reconnectHandler();t=this.queue.pop();)this.socket.send(t)}}closeSocket_(){this.socket_.onclose=()=>{console.log("WebSocket is closed now.")},this.socket_.close()}get socket(){return this.socket_||this.initSocket_(),this.socket_}onMessage(t){let e;try{e=JSON.parse(t.data)}catch(t){}if(this.debug&&console.log(e),"object"==typeof e&&"jsonrpc"in e&&"2.0"===e.jsonrpc)if("method"in e)this.eventHandler(e.method,e.params);else if("result"in e&&this.callbacks[e.id]){let t=this.callbacks[e.id].success_cb;delete this.callbacks[e.id],t(Object.assign({},e.result))}else if("error"in e&&this.callbacks[e.id]){let t=this.callbacks[e.id].error_cb,s=Object.assign({},this.callbacks[e.id]);delete this.callbacks[e.id],-32e3==e.error.code&&this.options.login&&this.options.passwd?this.call("login",{login:this.options.login,passwd:this.options.passwd,loginParams:this.options.loginParams,userVariables:this.options.userVariables},(t=>{this.socketCall_(s)}),(s=>{t(Object.assign({},e.result))})):t(Object.assign({},e.result))}}socketCall_({request:t,success_cb:e,error_cb:s}){t.id=this.request_id++;let i=JSON.stringify(t);this.callbacks[t.id]={request:t,success_cb:e,error_cb:s},this.socket.readyState<1?(this.queue.push(i),this.debug&&console.log("Queued",i)):(this.socket.send(i),this.debug&&console.log("Sent",i))}setEventHandler(t){this.eventHandler=t}setReconnectHandler(t){this.reconnectHandler=t}call(t,e,s,i){let n={jsonrpc:"2.0",method:t,params:Object.assign({},e),id:0};this.socket&&this.socketCall_({request:n,success_cb:s,error_cb:i})}close(){this.queue=[],this.callbacks=[],this.eventHandler=null,this.reconnectHandler=null,this.closeSocket_()}}const s="undefined"!=typeof window&&void 0!==window.crypto&&void 0!==window.crypto.getRandomValues?function(){let t=new Uint16Array(8);window.crypto.getRandomValues(t);let e=function(t){let e=t.toString(16);for(;e.length<4;)e="0"+e;return e};return e(t[0])+e(t[1])+"-"+e(t[2])+"-"+e(t[3])+"-"+e(t[4])+"-"+e(t[5])+e(t[6])+e(t[7])}:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){let e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)}))};class i{constructor(t){this.event_handlers={},this.debug=t}subscribeEvent(t,e){let i=s();return this.event_handlers[t]||(this.event_handlers[t]=[]),this.event_handlers[t].push({id:i,code:e}),i}unsubscribeEvent(t,e){this.event_handlers[t]=e?this.event_handlers[t].map(((t,s,i)=>t.id==e?void 0:t)):[]}dispatchEvent(t,e){if(this.debug&&console.log("Dispatch",t,e),this.event_handlers[t])for(let s of this.event_handlers[t])s.code(e)}}var n,o;t.CallDirection=void 0,(n=t.CallDirection||(t.CallDirection={}))[n.Incoming=0]="Incoming",n[n.Outgoing=1]="Outgoing",function(t){t[t.None=0]="None",t[t.Schedulled=1]="Schedulled",t[t.MessageSent=2]="MessageSent"}(o||(o={}));class c extends i{constructor(e,s,i,n){super(n),this.state=o.None,this.direction=t.CallDirection.Incoming,this.ice_timeout=i||3e3,e.iceCandidatePoolSize="iceCandidatePoolSize"in e?e.iceCandidatePoolSize:1,this.pc=new RTCPeerConnection(e),this.pc.ontrack=this.onTrack.bind(this),this.pc.onnegotiationneeded=this.onNegotiation.bind(this),this.pc.onicecandidate=this.onCandidate.bind(this),this.pc.onicegatheringstatechange=this.onIceGatheringStateChange.bind(this),void 0!==s&&(this.direction=s)}onTrack(t){this.dispatchEvent("track",t.track)}onCandidate(t){}onIceGatheringStateChange(t){if("complete"==this.pc.iceGatheringState){if(this.ice_timer&&clearTimeout(this.ice_timer),this.state==o.MessageSent)return;this.direction?this.dispatchEvent("send-offer",this.pc.localDescription):this.dispatchEvent("send-answer",this.pc.localDescription)}}iceTimerTriggered(){this.debug&&console.log(this.pc),this.state==o.Schedulled&&(this.state=o.MessageSent,this.direction?this.dispatchEvent("send-offer",this.pc.localDescription):this.dispatchEvent("send-answer",this.pc.localDescription))}onNegotiation(){this.pc.createOffer().then((t=>(this.ice_timer=setTimeout(this.iceTimerTriggered.bind(this),this.ice_timeout),this.pc.setLocalDescription(t)))).then((()=>{this.state=o.Schedulled})).catch((t=>{}))}getStats(){return this.pc?this.pc.getStats():Promise.reject()}onMedia(t){this.pc.setRemoteDescription(new RTCSessionDescription({type:"answer",sdp:t})).then((()=>{this.debug&&console.log("got remote media")})).catch((t=>{this.debug&&console.log("remote media error",t)}))}preSdp(t){this.presdp=t}addTrack(t){this.pc.addTrack(t)}answer(t){for(let e of t)this.pc.addTrack(e);this.ice_timer=setTimeout(this.iceTimerTriggered.bind(this),this.ice_timeout),this.pc.setRemoteDescription(new RTCSessionDescription({type:"offer",sdp:this.presdp})).then((()=>{this.pc.createAnswer().then((t=>{this.pc.setLocalDescription(t),this.state=o.Schedulled}))}))}}const a="verto.invite",h="verto.answer",l="verto.bye",r="verto.media",d="verto.modify",p="verto.info";class g extends i{constructor(e,i,n,o,l,r,d){super(d),this.id=o||s(),this.options=l||{},this.direction=n?t.CallDirection.Outgoing:t.CallDirection.Incoming,this.rtc=new c(e,this.direction,r,d),this.rpc=i,this.rtc.subscribeEvent("send-offer",(t=>{let e=Object.assign({},this.options);e=Object.assign(e,{destination_number:n,callID:this.id}),this.rpc.call(a,{dialogParams:e,sdp:t.sdp},(t=>{}),(t=>{}))})),this.rtc.subscribeEvent("send-answer",(t=>{this.rpc.call(h,{dialogParams:{destination_number:n,callID:this.id},sdp:t.sdp},(t=>{}),(t=>{}))})),this.rtc.subscribeEvent("track",(t=>{this.dispatchEvent("track",t)}))}getStats(){return this.rtc.getStats()}onAnswer(t){t&&this.rtc.onMedia(t),this.debug&&console.log("answer"),this.dispatchEvent("answer")}onMedia(t){this.rtc.onMedia(t),this.dispatchEvent("media")}addTrack(t){this.rtc.addTrack(t)}preSdp(t){this.rtc.preSdp(t)}answer(t){this.rtc.answer(t)}hangup(t={}){this.rpc.call(l,Object.assign({dialogParams:{callID:this.id}},t),(t=>{}),(t=>{})),this.clear()}clear(){this.dispatchEvent("bye",this)}dtmf(t){this.rpc.call(p,{dtmf:t.toString(),dialogParams:{callID:this.id}},(t=>{}),(t=>{}))}hold(t){this.rpc.call(d,{action:"hold",dialogParams:Object.assign(Object.assign({callID:this.id},this.options),t)},(t=>{"held"===t.holdState?(this.holdStatus=!0,this.dispatchEvent("hold",this)):(this.holdStatus=!1,this.dispatchEvent("unhold",this))}),(t=>{}))}unhold(t){this.rpc.call(d,{action:"unhold",dialogParams:Object.assign(Object.assign({callID:this.id},this.options),t)},(t=>{"held"===t.holdState?(this.holdStatus=!0,this.dispatchEvent("hold",this)):(this.holdStatus=!1,this.dispatchEvent("unhold",this))}),(t=>{}))}toggleHold(t){this.rpc.call(d,{action:"toggleHold",dialogParams:Object.assign(Object.assign({callID:this.id},this.options),t)},(t=>{"held"===t.holdState?(this.holdStatus=!0,this.dispatchEvent("hold",this)):(this.holdStatus=!1,this.dispatchEvent("unhold",this))}),(t=>{}))}}return t.Verto=class extends i{constructor(t){super(t.debug),this.calls={},this.logged_in=!1,this.options=t,this.rpc=new e(t.transportConfig,t.debug),this.rpc.setEventHandler(((t,e)=>{switch(t){case h:{let t=e.callID;this.calls[t].onAnswer(e.sdp);break}case r:{let t=e.callID;this.calls[t].onMedia(e.sdp);break}case a:{let t=new g(this.options.rtcConfig,this.rpc,"",e.callID,{caller_id_name:e.caller_id_name,caller_id_number:e.caller_id_number},this.options.ice_timeout,this.options.debug);t.preSdp(e.sdp),this.calls[e.callID]=t,this.dispatchEvent("invite",t);break}case l:this.calls[e.callID].clear(),delete this.calls[e.callID];break}})),this.rpc.setReconnectHandler((()=>{this.logged_in&&this.login()})),this.options.rtcConfig=Object.assign({},this.options.rtcConfig||{})}login(){return new Promise(((t,e)=>{this.rpc.call("login",{login:this.options.transportConfig.login,passwd:this.options.transportConfig.passwd},(e=>{this.sessid=e.sessid,this.logged_in=!0,t(e)}),(t=>{e(t)}))}))}call(t,e,i){let n=new g(this.options.rtcConfig,this.rpc,e,s(),i,this.options.ice_timeout,this.options.debug);for(let e of t)n.addTrack(e);return this.calls[n.id]=n,n}isLogged(){return this.logged_in}logout(){this.calls&&Object.keys(this.calls).forEach((t=>{this.calls[t].hangup()})),this.rpc.close(),this.rpc=null,this.sessid=null,this.logged_in=!1}},Object.defineProperty(t,"__esModule",{value:!0}),t}({});
{
"name": "vertojs",
"version": "0.0.4",
"version": "0.0.5",
"description": "Verto FreeSWITCH interface",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -328,2 +328,12 @@ # vertojs

**getStats**
***Parameters***
- None
***Returns***
https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/getStats
### Instance variables

@@ -330,0 +340,0 @@

@@ -100,2 +100,6 @@ /*

getStats() {
return this.rtc.getStats()
}
onAnswer(sdp: string) {

@@ -102,0 +106,0 @@ if (sdp) {

@@ -114,2 +114,6 @@ /*

getStats() {
return this.pc ? this.pc.getStats() : Promise.reject()
}
onMedia(sdp: string) {

@@ -148,2 +152,2 @@ this.pc.setRemoteDescription(new RTCSessionDescription({type: 'answer', sdp}))

export { VertoRtc, CallDirection }
export { VertoRtc, CallDirection }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc