Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@testrtc/watchrtc-sdk

Package Overview
Dependencies
Maintainers
2
Versions
127
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@testrtc/watchrtc-sdk - npm Package Compare versions

Comparing version 1.28.8 to 1.28.9

2

lib/index.js

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

!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.watchRTC=n():e.watchRTC=n()}(self,(function(){return(e={607:(e,n,t)=>{"use strict";n.v6=n.IO=n.S1=void 0,t(699);var o=t(231);n.S1=function(e){o.initSDK(e,["","webkit","moz"])},n.IO=function(e,n){o.setUserRating(e,n)},n.v6=function(e){o.setConfig(e)},n.default={init:n.S1,setConfig:n.v6,setUserRating:n.IO}},231:function(e,n,t){"use strict";var o=this&&this.__assign||function(){return(o=Object.assign||function(e){for(var n,t=1,o=arguments.length;t<o;t++)for(var r in n=arguments[t])Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r]);return e}).apply(this,arguments)},r=this&&this.__spreadArrays||function(){for(var e=0,n=0,t=arguments.length;n<t;n++)e+=arguments[n].length;var o=Array(e),r=0;for(n=0;n<t;n++)for(var i=arguments[n],a=0,c=i.length;a<c;a++,r++)o[r]=i[a];return o};Object.defineProperty(n,"__esModule",{value:!0}),n.setUserRating=n.initSDK=n.setConfig=void 0;var i=t(85),a=t(412),c=t(593),s=function(e,n){e=e||{},n=n||{},n=JSON.parse(JSON.stringify(n)),Object.keys(n).forEach((function(t){var o=n[t];delete o.id,e[t]&&Object.keys(o).forEach((function(r){o[r]===e[t][r]&&delete n[t][r],(0===Object.keys(o).length||1===Object.keys(o).length&&o.timestamp)&&delete n[t]}))}));var t=-1/0;return Object.keys(n).forEach((function(e){var o=n[e];o.timestamp>t&&(t=o.timestamp)})),Object.keys(n).forEach((function(e){var o=n[e];o.timestamp===t&&(o.timestamp=0)})),n.timestamp=t,n},l=function(e){return{id:e.id,tracks:e.getTracks().map((function(e){return{id:e.id,kind:e.kind,label:e.label,enabled:e.enabled,muted:e.muted,readyState:e.readyState}}))}},u=null;n.setConfig=function(e){u=e},n.initSDK=function(e,n){if(!window.watchRTCInitialized){window.watchRTCInitialized=!0;var t,f=0,d=0,p=!1,g=new i.default,h=g.trace,v={},m=!!window.mozRTCPeerConnection,y=!!window.RTCIceGatherer,w=(!m&&window.RTCPeerConnection&&window.navigator.webkitGetUserMedia,function(){return Object.keys(v).filter((function(e){return v[e].validConnection})).length}),_=function(){var e,n,i,s,l,f=w();if(f>0&&!p){p=!0;var m=(l=u)?l.rtcApiKey?l.rtcRoomId?!!l.rtcPeerId||(console.info.apply(console,r(c.logPrefix("error"),["config.rtcPeerId is required."])),!1):(console.info.apply(console,r(c.logPrefix("error"),["config.rtcRoomId is required."])),!1):(console.info.apply(console,r(c.logPrefix("error"),["config.rtcApiKey is required."])),!1):(console.info.apply(console,r(c.logPrefix("error"),["config is required."])),!1),_=Object.keys(v)[f-1];if(m){u.rtcTags&&(Array.isArray(u.rtcTags)?u.rtcTags.some((function(e){return e.includes(",")}))&&console.info.apply(console,r(c.logPrefix("info"),["To apply multiple tags please use an array and not comma separated values."])):(console.info.apply(console,r(c.logPrefix("info"),["config.rtcTags must be an array."])),u.rtcTags=void 0));var C=(e=u.rtcApiKey,n=u.proxyUrl||u.wsUrl,i="wss://watchrtc.testrtc.com",s=e.split(":"),-1!==e.indexOf("local")?{url:n||"ws://localhost:9101",apiKey:s[1]}:-1!==e.indexOf("staging")?{url:n||"wss://watchrtc-staging2.testrtc.com",apiKey:s[1]}:-1!==e.indexOf("production")?{url:n||i,apiKey:s[1]}:{url:n||i,apiKey:s[0]});d=Date.now(),g.connect(C.url+"?apiKey="+C.apiKey+"&timestamp="+Date.now(),(function(e){console.info.apply(console,r(c.logPrefix("info"),["Connection established. watchRTCConnectionId: "+e.connectionId+" sdkVersion:"+a.default])),h("watchrtc",_,o(o(o({},u),e),{sdkVersion:a.default})),y||(window.clearInterval(t),t=window.setInterval((function(){0===w()?d&&d+2e4<Date.now()&&(p=!1,window.clearInterval(t),g.close(),console.info.apply(console,r(c.logPrefix("info"),["Last connection closed. watchRTCConnectionId: "+e.connectionId+" sdkVersion: "+a.default]))):(d=Date.now(),Object.values(v).forEach((function(e){"closed"!==e.pc.signalingState&&b(e)})))}),e.interval))}),(function(){p=!1,d=0}))}}},b=function(e){if(e){var n=e.id,t=e.pc,o=e.prev;t.getStats(null).then((function(t){var r=function(e){if(!e.entries)return e;var n={};return e.forEach((function(e,t){n[t]=e})),n}(t),i=JSON.parse(JSON.stringify(r)),a=s(o,r);null!==(null==a?void 0:a.timestamp)&&(null==a?void 0:a.timestamp)!==-1/0&&h("getstats",n,s(e.prev,r)),e.prev=i}))}};if(n.forEach((function(n){if(window[n+"RTCPeerConnection"]&&("webkit"!==n||!y)){var t=window[n+"RTCPeerConnection"],o=function(n,o){console.info.apply(console,r(c.logPrefix("info"),["new RTCPeerConnection called.",{config:n,constraints:o}]));var i=new t(n,o),a="PC_"+f++;return i.__rtcStatsId=a,v[a]={id:a,pc:i,validConnection:!1},u=u||e||(null==n?void 0:n.watchrtc),n||(n={nullConfig:!0}),((n=JSON.parse(JSON.stringify(n)))&&n.iceServers||[]).forEach((function(e){delete e.credential})),(null==n?void 0:n.watchrtc)&&delete n.watchrtc,n.browserType=m?"moz":y?"edge":"webkit",h("create",a,n),o&&h("constraints",a,o),i.addEventListener("icecandidate",(function(e){h("onicecandidate",a,e.candidate)})),i.addEventListener("addstream",(function(e){h("onaddstream",a,e.stream.id+" "+e.stream.getTracks().map((function(e){return e.kind+":"+e.id})))})),i.addEventListener("track",(function(e){h("ontrack",a,e.track.kind+":"+e.track.id+" "+e.streams.map((function(e){return"stream:"+e.id})))})),i.addEventListener("removestream",(function(e){h("onremovestream",a,e.stream.id+" "+e.stream.getTracks().map((function(e){return e.kind+":"+e.id})))})),i.addEventListener("signalingstatechange",(function(){v[a]&&!v[a].validConnection&&(v[a].validConnection=!0,setTimeout(_,5e3)),h("onsignalingstatechange",a,i.signalingState)})),i.addEventListener("iceconnectionstatechange",(function(){h("oniceconnectionstatechange",a,i.iceConnectionState)})),i.addEventListener("icegatheringstatechange",(function(){h("onicegatheringstatechange",a,i.iceGatheringState)})),i.addEventListener("connectionstatechange",(function(){h("onconnectionstatechange",a,i.connectionState)})),i.addEventListener("negotiationneeded",(function(){h("onnegotiationneeded",a,void 0)})),i.addEventListener("datachannel",(function(e){h("ondatachannel",a,[e.channel.id,e.channel.label])})),y||i.addEventListener("iceconnectionstatechange",(function(){"connected"===i.iceConnectionState&&b(v[a])})),i};["createDataChannel"].forEach((function(e){var n=t.prototype[e];n&&(t.prototype[e]=function(){return h(e,this.__rtcStatsId,arguments),n.apply(this,arguments)})})),["close"].forEach((function(e){var n=t.prototype[e];n&&(t.prototype[e]=function(){return h(e,this.__rtcStatsId,arguments),delete v[this.__rtcStatsId],n.apply(this,arguments)})})),["addStream","removeStream"].forEach((function(e){var n=t.prototype[e];n&&(t.prototype[e]=function(){var t=arguments[0],o=t.getTracks().map((function(e){return e.kind+":"+e.id})).join(",");return h(e,this.__rtcStatsId,t.id+" "+o),n.apply(this,arguments)})})),["addTrack"].forEach((function(e){var n=t.prototype[e];n&&(t.prototype[e]=function(){var t=arguments[0],o=[].slice.call(arguments,1);return h(e,this.__rtcStatsId,t.kind+":"+t.id+" "+(o.map((function(e){return"stream:"+e.id})).join(";")||"-")),n.apply(this,arguments)})})),["removeTrack"].forEach((function(e){var n=t.prototype[e];n&&(t.prototype[e]=function(){var t=arguments[0].track;return h(e,this.__rtcStatsId,t?t.kind+":"+t.id:"null"),n.apply(this,arguments)})})),["createOffer","createAnswer"].forEach((function(e){var n=t.prototype[e];n&&(t.prototype[e]=function(){var t,o=this.__rtcStatsId,r=arguments;return 1===arguments.length&&"object"==typeof arguments[0]?t=arguments[0]:3===arguments.length&&"object"==typeof arguments[2]&&(t=arguments[2]),h(e,this.__rtcStatsId,t),n.apply(this,t?[t]:void 0).then((function(n){if(h(e+"OnSuccess",o,n),!(r.length>0&&"function"==typeof r[0]))return n;r[0].apply(null,[n])}),(function(n){if(h(e+"OnFailure",o,n.toString()),!(r.length>1&&"function"==typeof r[1]))throw n;r[1].apply(null,[n])}))})})),["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach((function(e){var n=t.prototype[e];n&&(t.prototype[e]=function(){var t=this.__rtcStatsId,o=arguments;return h(e,this.__rtcStatsId,o[0]),n.apply(this,[o[0]]).then((function(){h(e+"OnSuccess",t,void 0),o.length>=2&&"function"==typeof o[1]&&o[1].apply(null,[])}),(function(n){if(h(e+"OnFailure",t,n.toString()),!(o.length>=3&&"function"==typeof o[2]))throw n;o[2].apply(null,[n])}))})})),t.generateCertificate&&Object.defineProperty(o,"generateCertificate",{get:function(){return arguments.length?t.generateCertificate.apply(null,arguments):t.generateCertificate}}),window[n+"RTCPeerConnection"]=o,window[n+"RTCPeerConnection"].prototype=t.prototype}})),n.forEach((function(e){var n=e+(e.length?"GetUserMedia":"getUserMedia");if(navigator[n]){var t=navigator[n].bind(navigator);navigator[n]=function(){h("getUserMedia",null,arguments[0]);var e=arguments[1],n=arguments[2];t(arguments[0],(function(n){h("getUserMediaOnSuccess",null,l(n)),e&&e(n)}),(function(e){h("getUserMediaOnFailure",null,e.name),n&&n(e)}))}.bind(navigator)}})),navigator.mediaDevices&&navigator.mediaDevices.getUserMedia){var C=navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);navigator.mediaDevices.getUserMedia=function(){return h("navigator.mediaDevices.getUserMedia",null,arguments[0]),C.apply(navigator.mediaDevices,arguments).then((function(e){return h("navigator.mediaDevices.getUserMediaOnSuccess",null,l(e)),e}),(function(e){return h("navigator.mediaDevices.getUserMediaOnFailure",null,e.name),Promise.reject(e)}))}.bind(navigator.mediaDevices)}if(navigator.mediaDevices&&navigator.mediaDevices.getDisplayMedia){var O=navigator.mediaDevices.getDisplayMedia.bind(navigator.mediaDevices);navigator.mediaDevices.getDisplayMedia=function(){return h("navigator.mediaDevices.getDisplayMedia",null,arguments[0]),O.apply(navigator.mediaDevices,arguments).then((function(e){return h("navigator.mediaDevices.getDisplayMediaOnSuccess",null,l(e)),e}),(function(e){return h("navigator.mediaDevices.getDisplayMediaOnFailure",null,e.name),Promise.reject(e)}))}.bind(navigator.mediaDevices)}}},n.setUserRating=function(e,n){var t;e&&(i.default._instance&&(null===(t=i.default._instance.connection)||void 0===t?void 0:t.readyState)===WebSocket.OPEN?i.default._instance.trace("userRating","",{rate:e,rateReason:n}):console.info.apply(console,r(c.logPrefix("error"),["Please set user rating before websocket connection is closed."])))}},699:(e,n)=>{"use strict";Object.defineProperty(n,"__esModule",{value:!0})},593:(e,n)=>{"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.logPrefix=void 0,n.logPrefix=function(e){return void 0===e&&(e="info"),"error"===e?["%cwatchRTC %cERROR","background: gold; color: black; padding: 2px 0.5em; border-radius: 0.5em;","background: red; color: white; padding: 2px 0.5em; border-radius: 0.5em;"]:["%cwatchRTC","background: gold; color: black; padding: 2px 0.5em; border-radius: 0.5em;"]}},412:(e,n)=>{"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default="1.28.8"},85:function(e,n,t){"use strict";var o=this&&this.__spreadArrays||function(){for(var e=0,n=0,t=arguments.length;n<t;n++)e+=arguments[n].length;var o=Array(e),r=0;for(n=0;n<t;n++)for(var i=arguments[n],a=0,c=i.length;a<c;a++,r++)o[r]=i[a];return o};Object.defineProperty(n,"__esModule",{value:!0});var r=t(593),i=t(354),a=function(){function e(){this.connection=null,this.buffer=[],this.sendInterval=1,this.onClose=function(){},e._instance?console.info.apply(console,o(r.logPrefix("info"),["WatchRTCSocket instance already created"])):e._instance=this}return e.prototype.connect=function(n,t,i){e._instance.connection&&e._instance.connection.close(),e._instance.connection=new WebSocket(n,"2.0"),e._instance.connection.onopen=function(e){},e._instance.connection.onclose=function(e){};var a=e._instance;e._instance.connection.onmessage=function(n){var c;try{var s=JSON.parse(n.data);s.error?(null===(c=null==a?void 0:a.connection)||void 0===c||c.close(),a.connection=null,console.info.apply(console,o(r.logPrefix("error"),["\n"+s.error])),i(s.error)):(s.sendInterval&&(e._instance.sendInterval=s.sendInterval),t(s))}catch(e){console.info.apply(console,o(r.logPrefix("error"),[{err:e.stack}])),i(e.message)}},e._instance.connection.onerror=function(e){console.info.apply(console,o(r.logPrefix("error"),["\n",e])),i(e)}},e.prototype.trace=function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var a=Array.prototype.slice.call(n);if(a.push(Date.now()),a[1]instanceof RTCPeerConnection&&(a[1]=a[1].__rtcStatsId),e._instance.connection){if(e._instance.connection.readyState===WebSocket.OPEN&&(e._instance.buffer.push(a),e._instance.buffer.length>=e._instance.sendInterval)){var c=JSON.stringify(e._instance.buffer),s=i.compressToEncodedURIComponent(c);console.log.apply(console,o(r.logPrefix("info"),["lines: "+c.length])),console.log.apply(console,o(r.logPrefix("info"),["compressedMessage: "+s.length])),e._instance.buffer=[],e._instance.connection.send(s)}}else{if(e._instance.buffer.length>1e3)return;e._instance.buffer.push(a)}},e.prototype.close=function(){e._instance.buffer=[],e._instance.connection&&(e._instance.connection.close(),e._instance.onClose(),e._instance.connection=null)},e}();n.default=a},354:(e,n,t)=>{var o,r=function(){function e(e,n){if(!r[e]){r[e]={};for(var t=0;t<e.length;t++)r[e][e.charAt(t)]=t}return r[e][n]}var n=String.fromCharCode,t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",r={},i={compressToBase64:function(e){if(null==e)return"";var n=i._compress(e,6,(function(e){return t.charAt(e)}));switch(n.length%4){default:case 0:return n;case 1:return n+"===";case 2:return n+"==";case 3:return n+"="}},decompressFromBase64:function(n){return null==n?"":""==n?null:i._decompress(n.length,32,(function(o){return e(t,n.charAt(o))}))},compressToUTF16:function(e){return null==e?"":i._compress(e,15,(function(e){return n(e+32)}))+" "},decompressFromUTF16:function(e){return null==e?"":""==e?null:i._decompress(e.length,16384,(function(n){return e.charCodeAt(n)-32}))},compressToUint8Array:function(e){for(var n=i.compress(e),t=new Uint8Array(2*n.length),o=0,r=n.length;r>o;o++){var a=n.charCodeAt(o);t[2*o]=a>>>8,t[2*o+1]=a%256}return t},decompressFromUint8Array:function(e){if(null==e)return i.decompress(e);for(var t=new Array(e.length/2),o=0,r=t.length;r>o;o++)t[o]=256*e[2*o]+e[2*o+1];var a=[];return t.forEach((function(e){a.push(n(e))})),i.decompress(a.join(""))},compressToEncodedURIComponent:function(e){return null==e?"":i._compress(e,6,(function(e){return o.charAt(e)}))},decompressFromEncodedURIComponent:function(n){return null==n?"":""==n?null:(n=n.replace(/ /g,"+"),i._decompress(n.length,32,(function(t){return e(o,n.charAt(t))})))},compress:function(e){return i._compress(e,16,(function(e){return n(e)}))},_compress:function(e,n,t){if(null==e)return"";var o,r,i,a={},c={},s="",l="",u="",f=2,d=3,p=2,g=[],h=0,v=0;for(i=0;i<e.length;i+=1)if(s=e.charAt(i),Object.prototype.hasOwnProperty.call(a,s)||(a[s]=d++,c[s]=!0),l=u+s,Object.prototype.hasOwnProperty.call(a,l))u=l;else{if(Object.prototype.hasOwnProperty.call(c,u)){if(u.charCodeAt(0)<256){for(o=0;p>o;o++)h<<=1,v==n-1?(v=0,g.push(t(h)),h=0):v++;for(r=u.charCodeAt(0),o=0;8>o;o++)h=h<<1|1&r,v==n-1?(v=0,g.push(t(h)),h=0):v++,r>>=1}else{for(r=1,o=0;p>o;o++)h=h<<1|r,v==n-1?(v=0,g.push(t(h)),h=0):v++,r=0;for(r=u.charCodeAt(0),o=0;16>o;o++)h=h<<1|1&r,v==n-1?(v=0,g.push(t(h)),h=0):v++,r>>=1}0==--f&&(f=Math.pow(2,p),p++),delete c[u]}else for(r=a[u],o=0;p>o;o++)h=h<<1|1&r,v==n-1?(v=0,g.push(t(h)),h=0):v++,r>>=1;0==--f&&(f=Math.pow(2,p),p++),a[l]=d++,u=String(s)}if(""!==u){if(Object.prototype.hasOwnProperty.call(c,u)){if(u.charCodeAt(0)<256){for(o=0;p>o;o++)h<<=1,v==n-1?(v=0,g.push(t(h)),h=0):v++;for(r=u.charCodeAt(0),o=0;8>o;o++)h=h<<1|1&r,v==n-1?(v=0,g.push(t(h)),h=0):v++,r>>=1}else{for(r=1,o=0;p>o;o++)h=h<<1|r,v==n-1?(v=0,g.push(t(h)),h=0):v++,r=0;for(r=u.charCodeAt(0),o=0;16>o;o++)h=h<<1|1&r,v==n-1?(v=0,g.push(t(h)),h=0):v++,r>>=1}0==--f&&(f=Math.pow(2,p),p++),delete c[u]}else for(r=a[u],o=0;p>o;o++)h=h<<1|1&r,v==n-1?(v=0,g.push(t(h)),h=0):v++,r>>=1;0==--f&&(f=Math.pow(2,p),p++)}for(r=2,o=0;p>o;o++)h=h<<1|1&r,v==n-1?(v=0,g.push(t(h)),h=0):v++,r>>=1;for(;;){if(h<<=1,v==n-1){g.push(t(h));break}v++}return g.join("")},decompress:function(e){return null==e?"":""==e?null:i._decompress(e.length,32768,(function(n){return e.charCodeAt(n)}))},_decompress:function(e,t,o){var r,i,a,c,s,l,u,f=[],d=4,p=4,g=3,h="",v=[],m={val:o(0),position:t,index:1};for(r=0;3>r;r+=1)f[r]=r;for(a=0,s=Math.pow(2,2),l=1;l!=s;)c=m.val&m.position,m.position>>=1,0==m.position&&(m.position=t,m.val=o(m.index++)),a|=(c>0?1:0)*l,l<<=1;switch(a){case 0:for(a=0,s=Math.pow(2,8),l=1;l!=s;)c=m.val&m.position,m.position>>=1,0==m.position&&(m.position=t,m.val=o(m.index++)),a|=(c>0?1:0)*l,l<<=1;u=n(a);break;case 1:for(a=0,s=Math.pow(2,16),l=1;l!=s;)c=m.val&m.position,m.position>>=1,0==m.position&&(m.position=t,m.val=o(m.index++)),a|=(c>0?1:0)*l,l<<=1;u=n(a);break;case 2:return""}for(f[3]=u,i=u,v.push(u);;){if(m.index>e)return"";for(a=0,s=Math.pow(2,g),l=1;l!=s;)c=m.val&m.position,m.position>>=1,0==m.position&&(m.position=t,m.val=o(m.index++)),a|=(c>0?1:0)*l,l<<=1;switch(u=a){case 0:for(a=0,s=Math.pow(2,8),l=1;l!=s;)c=m.val&m.position,m.position>>=1,0==m.position&&(m.position=t,m.val=o(m.index++)),a|=(c>0?1:0)*l,l<<=1;f[p++]=n(a),u=p-1,d--;break;case 1:for(a=0,s=Math.pow(2,16),l=1;l!=s;)c=m.val&m.position,m.position>>=1,0==m.position&&(m.position=t,m.val=o(m.index++)),a|=(c>0?1:0)*l,l<<=1;f[p++]=n(a),u=p-1,d--;break;case 2:return v.join("")}if(0==d&&(d=Math.pow(2,g),g++),f[u])h=f[u];else{if(u!==p)return null;h=i+i.charAt(0)}v.push(h),f[p++]=i+h.charAt(0),i=h,0==--d&&(d=Math.pow(2,g),g++)}}};return i}();void 0===(o=function(){return r}.call(n,t,n,e))||(e.exports=o)}},n={},function t(o){if(n[o])return n[o].exports;var r=n[o]={exports:{}};return e[o].call(r.exports,r,r.exports,t),r.exports}(607)).default;var e,n}));
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.watchRTC=n():e.watchRTC=n()}(self,(function(){return(e={607:(e,n,t)=>{"use strict";n.v6=n.IO=n.S1=void 0,t(699);var o=t(231);n.S1=function(e){o.initSDK(e,["","webkit","moz"])},n.IO=function(e,n){o.setUserRating(e,n)},n.v6=function(e){o.setConfig(e)},n.default={init:n.S1,setConfig:n.v6,setUserRating:n.IO}},231:function(e,n,t){"use strict";var o=this&&this.__assign||function(){return(o=Object.assign||function(e){for(var n,t=1,o=arguments.length;t<o;t++)for(var i in n=arguments[t])Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i]);return e}).apply(this,arguments)},i=this&&this.__spreadArrays||function(){for(var e=0,n=0,t=arguments.length;n<t;n++)e+=arguments[n].length;var o=Array(e),i=0;for(n=0;n<t;n++)for(var r=arguments[n],a=0,c=r.length;a<c;a++,i++)o[i]=r[a];return o};Object.defineProperty(n,"__esModule",{value:!0}),n.setUserRating=n.initSDK=n.setConfig=void 0;var r=t(85),a=t(412),c=t(593),s=function(e,n){e=e||{},n=n||{},n=JSON.parse(JSON.stringify(n)),Object.keys(n).forEach((function(t){var o=n[t];delete o.id,e[t]&&Object.keys(o).forEach((function(i){o[i]===e[t][i]&&delete n[t][i],(0===Object.keys(o).length||1===Object.keys(o).length&&o.timestamp)&&delete n[t]}))}));var t=-1/0;return Object.keys(n).forEach((function(e){var o=n[e];o.timestamp>t&&(t=o.timestamp)})),Object.keys(n).forEach((function(e){var o=n[e];o.timestamp===t&&(o.timestamp=0)})),n.timestamp=t,n},l=function(e){return{id:e.id,tracks:e.getTracks().map((function(e){return{id:e.id,kind:e.kind,label:e.label,enabled:e.enabled,muted:e.muted,readyState:e.readyState}}))}},u=null;n.setConfig=function(e){u=e},n.initSDK=function(e,n){if(!window.watchRTCInitialized){window.watchRTCInitialized=!0;var t,f=0,d=0,p=!1,g=new r.default(e.debug),h=g.trace,v={},m=!!window.mozRTCPeerConnection,y=!!window.RTCIceGatherer,w=(!m&&window.RTCPeerConnection&&window.navigator.webkitGetUserMedia,function(){return Object.keys(v).filter((function(e){return v[e].validConnection})).length}),_=function(){var e,n,r,s,l,f=w();if(f>0&&!p){p=!0;var m=(l=u)?l.rtcApiKey?l.rtcRoomId?!!l.rtcPeerId||(console.info.apply(console,i(c.logPrefix("error"),["config.rtcPeerId is required."])),!1):(console.info.apply(console,i(c.logPrefix("error"),["config.rtcRoomId is required."])),!1):(console.info.apply(console,i(c.logPrefix("error"),["config.rtcApiKey is required."])),!1):(console.info.apply(console,i(c.logPrefix("error"),["config is required."])),!1),_=Object.keys(v)[f-1];if(m){u.rtcTags&&(Array.isArray(u.rtcTags)?u.rtcTags.some((function(e){return e.includes(",")}))&&console.info.apply(console,i(c.logPrefix("info"),["To apply multiple tags please use an array and not comma separated values."])):(console.info.apply(console,i(c.logPrefix("info"),["config.rtcTags must be an array."])),u.rtcTags=void 0));var C=(e=u.rtcApiKey,n=u.proxyUrl||u.wsUrl,r="wss://watchrtc.testrtc.com",s=e.split(":"),-1!==e.indexOf("local")?{url:n||"ws://localhost:9101",apiKey:s[1]}:-1!==e.indexOf("staging")?{url:n||"wss://watchrtc-staging2.testrtc.com",apiKey:s[1]}:-1!==e.indexOf("production")?{url:n||r,apiKey:s[1]}:{url:n||r,apiKey:s[0]});d=Date.now(),g.connect(C.url+"?apiKey="+C.apiKey+"&timestamp="+Date.now(),(function(e){console.info.apply(console,i(c.logPrefix("info"),["Connection established. watchRTCConnectionId: "+e.connectionId+" sdkVersion:"+a.default])),h("watchrtc",_,o(o(o({},u),e),{sdkVersion:a.default})),y||(window.clearInterval(t),t=window.setInterval((function(){0===w()?d&&d+2e4<Date.now()&&(p=!1,window.clearInterval(t),g.close(),console.info.apply(console,i(c.logPrefix("info"),["Last connection closed. watchRTCConnectionId: "+e.connectionId+" sdkVersion: "+a.default]))):(d=Date.now(),Object.values(v).forEach((function(e){"closed"!==e.pc.signalingState&&b(e)})))}),e.interval))}),(function(){p=!1,d=0}))}}},b=function(e){if(e){var n=e.id,t=e.pc,o=e.prev;t.getStats(null).then((function(t){var i=function(e){if(!e.entries)return e;var n={};return e.forEach((function(e,t){n[t]=e})),n}(t),r=JSON.parse(JSON.stringify(i)),a=s(o,i);null!==(null==a?void 0:a.timestamp)&&(null==a?void 0:a.timestamp)!==-1/0&&h("getstats",n,s(e.prev,i)),e.prev=r}))}};if(n.forEach((function(n){if(window[n+"RTCPeerConnection"]&&("webkit"!==n||!y)){var t=window[n+"RTCPeerConnection"],o=function(n,o){(null==u?void 0:u.debug)&&console.info.apply(console,i(c.logPrefix("info"),["new RTCPeerConnection called.",{config:n,constraints:o}]));var r=new t(n,o),a="PC_"+f++;return r.__rtcStatsId=a,v[a]={id:a,pc:r,validConnection:!1},u=u||e||(null==n?void 0:n.watchrtc),n||(n={nullConfig:!0}),((n=JSON.parse(JSON.stringify(n)))&&n.iceServers||[]).forEach((function(e){delete e.credential})),(null==n?void 0:n.watchrtc)&&delete n.watchrtc,n.browserType=m?"moz":y?"edge":"webkit",h("create",a,n),o&&h("constraints",a,o),r.addEventListener("icecandidate",(function(e){h("onicecandidate",a,e.candidate)})),r.addEventListener("addstream",(function(e){h("onaddstream",a,e.stream.id+" "+e.stream.getTracks().map((function(e){return e.kind+":"+e.id})))})),r.addEventListener("track",(function(e){h("ontrack",a,e.track.kind+":"+e.track.id+" "+e.streams.map((function(e){return"stream:"+e.id})))})),r.addEventListener("removestream",(function(e){h("onremovestream",a,e.stream.id+" "+e.stream.getTracks().map((function(e){return e.kind+":"+e.id})))})),r.addEventListener("signalingstatechange",(function(){v[a]&&!v[a].validConnection&&(v[a].validConnection=!0,setTimeout(_,5e3)),h("onsignalingstatechange",a,r.signalingState)})),r.addEventListener("iceconnectionstatechange",(function(){h("oniceconnectionstatechange",a,r.iceConnectionState)})),r.addEventListener("icegatheringstatechange",(function(){h("onicegatheringstatechange",a,r.iceGatheringState)})),r.addEventListener("connectionstatechange",(function(){h("onconnectionstatechange",a,r.connectionState)})),r.addEventListener("negotiationneeded",(function(){h("onnegotiationneeded",a,void 0)})),r.addEventListener("datachannel",(function(e){h("ondatachannel",a,[e.channel.id,e.channel.label])})),y||r.addEventListener("iceconnectionstatechange",(function(){"connected"===r.iceConnectionState&&b(v[a])})),r};["createDataChannel"].forEach((function(e){var n=t.prototype[e];n&&(t.prototype[e]=function(){return h(e,this.__rtcStatsId,arguments),n.apply(this,arguments)})})),["close"].forEach((function(e){var n=t.prototype[e];n&&(t.prototype[e]=function(){return h(e,this.__rtcStatsId,arguments),delete v[this.__rtcStatsId],n.apply(this,arguments)})})),["addStream","removeStream"].forEach((function(e){var n=t.prototype[e];n&&(t.prototype[e]=function(){var t=arguments[0],o=t.getTracks().map((function(e){return e.kind+":"+e.id})).join(",");return h(e,this.__rtcStatsId,t.id+" "+o),n.apply(this,arguments)})})),["addTrack"].forEach((function(e){var n=t.prototype[e];n&&(t.prototype[e]=function(){var t=arguments[0],o=[].slice.call(arguments,1);return h(e,this.__rtcStatsId,t.kind+":"+t.id+" "+(o.map((function(e){return"stream:"+e.id})).join(";")||"-")),n.apply(this,arguments)})})),["removeTrack"].forEach((function(e){var n=t.prototype[e];n&&(t.prototype[e]=function(){var t=arguments[0].track;return h(e,this.__rtcStatsId,t?t.kind+":"+t.id:"null"),n.apply(this,arguments)})})),["createOffer","createAnswer"].forEach((function(e){var n=t.prototype[e];n&&(t.prototype[e]=function(){var t,o=this.__rtcStatsId,i=arguments;return 1===arguments.length&&"object"==typeof arguments[0]?t=arguments[0]:3===arguments.length&&"object"==typeof arguments[2]&&(t=arguments[2]),h(e,this.__rtcStatsId,t),n.apply(this,t?[t]:void 0).then((function(n){if(h(e+"OnSuccess",o,n),!(i.length>0&&"function"==typeof i[0]))return n;i[0].apply(null,[n])}),(function(n){if(h(e+"OnFailure",o,n.toString()),!(i.length>1&&"function"==typeof i[1]))throw n;i[1].apply(null,[n])}))})})),["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach((function(e){var n=t.prototype[e];n&&(t.prototype[e]=function(){var t=this.__rtcStatsId,o=arguments;return h(e,this.__rtcStatsId,o[0]),n.apply(this,[o[0]]).then((function(){h(e+"OnSuccess",t,void 0),o.length>=2&&"function"==typeof o[1]&&o[1].apply(null,[])}),(function(n){if(h(e+"OnFailure",t,n.toString()),!(o.length>=3&&"function"==typeof o[2]))throw n;o[2].apply(null,[n])}))})})),t.generateCertificate&&Object.defineProperty(o,"generateCertificate",{get:function(){return arguments.length?t.generateCertificate.apply(null,arguments):t.generateCertificate}}),window[n+"RTCPeerConnection"]=o,window[n+"RTCPeerConnection"].prototype=t.prototype}})),n.forEach((function(e){var n=e+(e.length?"GetUserMedia":"getUserMedia");if(navigator[n]){var t=navigator[n].bind(navigator);navigator[n]=function(){h("getUserMedia",null,arguments[0]);var e=arguments[1],n=arguments[2];t(arguments[0],(function(n){h("getUserMediaOnSuccess",null,l(n)),e&&e(n)}),(function(e){h("getUserMediaOnFailure",null,e.name),n&&n(e)}))}.bind(navigator)}})),navigator.mediaDevices&&navigator.mediaDevices.getUserMedia){var C=navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);navigator.mediaDevices.getUserMedia=function(){return h("navigator.mediaDevices.getUserMedia",null,arguments[0]),C.apply(navigator.mediaDevices,arguments).then((function(e){return h("navigator.mediaDevices.getUserMediaOnSuccess",null,l(e)),e}),(function(e){return h("navigator.mediaDevices.getUserMediaOnFailure",null,e.name),Promise.reject(e)}))}.bind(navigator.mediaDevices)}if(navigator.mediaDevices&&navigator.mediaDevices.getDisplayMedia){var O=navigator.mediaDevices.getDisplayMedia.bind(navigator.mediaDevices);navigator.mediaDevices.getDisplayMedia=function(){return h("navigator.mediaDevices.getDisplayMedia",null,arguments[0]),O.apply(navigator.mediaDevices,arguments).then((function(e){return h("navigator.mediaDevices.getDisplayMediaOnSuccess",null,l(e)),e}),(function(e){return h("navigator.mediaDevices.getDisplayMediaOnFailure",null,e.name),Promise.reject(e)}))}.bind(navigator.mediaDevices)}}},n.setUserRating=function(e,n){var t;e&&(r.default._instance&&(null===(t=r.default._instance.connection)||void 0===t?void 0:t.readyState)===WebSocket.OPEN?r.default._instance.trace("userRating","",{rate:e,rateReason:n}):console.info.apply(console,i(c.logPrefix("error"),["Please set user rating before websocket connection is closed."])))}},699:(e,n)=>{"use strict";Object.defineProperty(n,"__esModule",{value:!0})},593:(e,n)=>{"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.logPrefix=void 0,n.logPrefix=function(e){return void 0===e&&(e="info"),"error"===e?["%cwatchRTC %cERROR","background: gold; color: black; padding: 2px 0.5em; border-radius: 0.5em;","background: red; color: white; padding: 2px 0.5em; border-radius: 0.5em;"]:["%cwatchRTC","background: gold; color: black; padding: 2px 0.5em; border-radius: 0.5em;"]}},412:(e,n)=>{"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default="1.28.9"},85:function(e,n,t){"use strict";var o=this&&this.__spreadArrays||function(){for(var e=0,n=0,t=arguments.length;n<t;n++)e+=arguments[n].length;var o=Array(e),i=0;for(n=0;n<t;n++)for(var r=arguments[n],a=0,c=r.length;a<c;a++,i++)o[i]=r[a];return o};Object.defineProperty(n,"__esModule",{value:!0});var i=t(593),r=t(354),a=function(){function e(n){this.connection=null,this.buffer=[],this.sendInterval=1,this.onClose=function(){},this.debug=!1,e._instance?console.info.apply(console,o(i.logPrefix("info"),["WatchRTCSocket instance already created"])):(e._instance=this,this.debug=!!n)}return e.prototype.connect=function(n,t,r){e._instance.connection&&e._instance.connection.close(),e._instance.connection=new WebSocket(n,"2.0"),e._instance.connection.onopen=function(e){},e._instance.connection.onclose=function(e){};var a=e._instance;e._instance.connection.onmessage=function(n){var c;try{var s=JSON.parse(n.data);s.error?(null===(c=null==a?void 0:a.connection)||void 0===c||c.close(),a.connection=null,console.info.apply(console,o(i.logPrefix("error"),["\n"+s.error])),r(s.error)):(s.sendInterval&&(e._instance.sendInterval=s.sendInterval),t(s))}catch(e){console.info.apply(console,o(i.logPrefix("error"),[{err:e.stack}])),r(e.message)}},e._instance.connection.onerror=function(e){console.info.apply(console,o(i.logPrefix("error"),["\n",e])),r(e)}},e.prototype.trace=function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var a=Array.prototype.slice.call(n);if(a.push(Date.now()),a[1]instanceof RTCPeerConnection&&(a[1]=a[1].__rtcStatsId),e._instance.connection){if(e._instance.connection.readyState===WebSocket.OPEN&&(e._instance.buffer.push(a),e._instance.buffer.length>=e._instance.sendInterval)){var c=JSON.stringify(e._instance.buffer),s=r.compressToEncodedURIComponent(c);e._instance.debug&&(console.log.apply(console,o(i.logPrefix("info"),["lines: "+c.length])),console.log.apply(console,o(i.logPrefix("info"),["compressedMessage: "+s.length]))),e._instance.buffer=[],e._instance.connection.send(s)}}else{if(e._instance.buffer.length>1e3)return;e._instance.buffer.push(a)}},e.prototype.close=function(){e._instance.buffer=[],e._instance.connection&&(e._instance.connection.close(),e._instance.onClose(),e._instance.connection=null)},e}();n.default=a},354:(e,n,t)=>{var o,i=function(){function e(e,n){if(!i[e]){i[e]={};for(var t=0;t<e.length;t++)i[e][e.charAt(t)]=t}return i[e][n]}var n=String.fromCharCode,t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",i={},r={compressToBase64:function(e){if(null==e)return"";var n=r._compress(e,6,(function(e){return t.charAt(e)}));switch(n.length%4){default:case 0:return n;case 1:return n+"===";case 2:return n+"==";case 3:return n+"="}},decompressFromBase64:function(n){return null==n?"":""==n?null:r._decompress(n.length,32,(function(o){return e(t,n.charAt(o))}))},compressToUTF16:function(e){return null==e?"":r._compress(e,15,(function(e){return n(e+32)}))+" "},decompressFromUTF16:function(e){return null==e?"":""==e?null:r._decompress(e.length,16384,(function(n){return e.charCodeAt(n)-32}))},compressToUint8Array:function(e){for(var n=r.compress(e),t=new Uint8Array(2*n.length),o=0,i=n.length;i>o;o++){var a=n.charCodeAt(o);t[2*o]=a>>>8,t[2*o+1]=a%256}return t},decompressFromUint8Array:function(e){if(null==e)return r.decompress(e);for(var t=new Array(e.length/2),o=0,i=t.length;i>o;o++)t[o]=256*e[2*o]+e[2*o+1];var a=[];return t.forEach((function(e){a.push(n(e))})),r.decompress(a.join(""))},compressToEncodedURIComponent:function(e){return null==e?"":r._compress(e,6,(function(e){return o.charAt(e)}))},decompressFromEncodedURIComponent:function(n){return null==n?"":""==n?null:(n=n.replace(/ /g,"+"),r._decompress(n.length,32,(function(t){return e(o,n.charAt(t))})))},compress:function(e){return r._compress(e,16,(function(e){return n(e)}))},_compress:function(e,n,t){if(null==e)return"";var o,i,r,a={},c={},s="",l="",u="",f=2,d=3,p=2,g=[],h=0,v=0;for(r=0;r<e.length;r+=1)if(s=e.charAt(r),Object.prototype.hasOwnProperty.call(a,s)||(a[s]=d++,c[s]=!0),l=u+s,Object.prototype.hasOwnProperty.call(a,l))u=l;else{if(Object.prototype.hasOwnProperty.call(c,u)){if(u.charCodeAt(0)<256){for(o=0;p>o;o++)h<<=1,v==n-1?(v=0,g.push(t(h)),h=0):v++;for(i=u.charCodeAt(0),o=0;8>o;o++)h=h<<1|1&i,v==n-1?(v=0,g.push(t(h)),h=0):v++,i>>=1}else{for(i=1,o=0;p>o;o++)h=h<<1|i,v==n-1?(v=0,g.push(t(h)),h=0):v++,i=0;for(i=u.charCodeAt(0),o=0;16>o;o++)h=h<<1|1&i,v==n-1?(v=0,g.push(t(h)),h=0):v++,i>>=1}0==--f&&(f=Math.pow(2,p),p++),delete c[u]}else for(i=a[u],o=0;p>o;o++)h=h<<1|1&i,v==n-1?(v=0,g.push(t(h)),h=0):v++,i>>=1;0==--f&&(f=Math.pow(2,p),p++),a[l]=d++,u=String(s)}if(""!==u){if(Object.prototype.hasOwnProperty.call(c,u)){if(u.charCodeAt(0)<256){for(o=0;p>o;o++)h<<=1,v==n-1?(v=0,g.push(t(h)),h=0):v++;for(i=u.charCodeAt(0),o=0;8>o;o++)h=h<<1|1&i,v==n-1?(v=0,g.push(t(h)),h=0):v++,i>>=1}else{for(i=1,o=0;p>o;o++)h=h<<1|i,v==n-1?(v=0,g.push(t(h)),h=0):v++,i=0;for(i=u.charCodeAt(0),o=0;16>o;o++)h=h<<1|1&i,v==n-1?(v=0,g.push(t(h)),h=0):v++,i>>=1}0==--f&&(f=Math.pow(2,p),p++),delete c[u]}else for(i=a[u],o=0;p>o;o++)h=h<<1|1&i,v==n-1?(v=0,g.push(t(h)),h=0):v++,i>>=1;0==--f&&(f=Math.pow(2,p),p++)}for(i=2,o=0;p>o;o++)h=h<<1|1&i,v==n-1?(v=0,g.push(t(h)),h=0):v++,i>>=1;for(;;){if(h<<=1,v==n-1){g.push(t(h));break}v++}return g.join("")},decompress:function(e){return null==e?"":""==e?null:r._decompress(e.length,32768,(function(n){return e.charCodeAt(n)}))},_decompress:function(e,t,o){var i,r,a,c,s,l,u,f=[],d=4,p=4,g=3,h="",v=[],m={val:o(0),position:t,index:1};for(i=0;3>i;i+=1)f[i]=i;for(a=0,s=Math.pow(2,2),l=1;l!=s;)c=m.val&m.position,m.position>>=1,0==m.position&&(m.position=t,m.val=o(m.index++)),a|=(c>0?1:0)*l,l<<=1;switch(a){case 0:for(a=0,s=Math.pow(2,8),l=1;l!=s;)c=m.val&m.position,m.position>>=1,0==m.position&&(m.position=t,m.val=o(m.index++)),a|=(c>0?1:0)*l,l<<=1;u=n(a);break;case 1:for(a=0,s=Math.pow(2,16),l=1;l!=s;)c=m.val&m.position,m.position>>=1,0==m.position&&(m.position=t,m.val=o(m.index++)),a|=(c>0?1:0)*l,l<<=1;u=n(a);break;case 2:return""}for(f[3]=u,r=u,v.push(u);;){if(m.index>e)return"";for(a=0,s=Math.pow(2,g),l=1;l!=s;)c=m.val&m.position,m.position>>=1,0==m.position&&(m.position=t,m.val=o(m.index++)),a|=(c>0?1:0)*l,l<<=1;switch(u=a){case 0:for(a=0,s=Math.pow(2,8),l=1;l!=s;)c=m.val&m.position,m.position>>=1,0==m.position&&(m.position=t,m.val=o(m.index++)),a|=(c>0?1:0)*l,l<<=1;f[p++]=n(a),u=p-1,d--;break;case 1:for(a=0,s=Math.pow(2,16),l=1;l!=s;)c=m.val&m.position,m.position>>=1,0==m.position&&(m.position=t,m.val=o(m.index++)),a|=(c>0?1:0)*l,l<<=1;f[p++]=n(a),u=p-1,d--;break;case 2:return v.join("")}if(0==d&&(d=Math.pow(2,g),g++),f[u])h=f[u];else{if(u!==p)return null;h=r+r.charAt(0)}v.push(h),f[p++]=r+h.charAt(0),r=h,0==--d&&(d=Math.pow(2,g),g++)}}};return r}();void 0===(o=function(){return i}.call(n,t,n,e))||(e.exports=o)}},n={},function t(o){if(n[o])return n[o].exports;var i=n[o]={exports:{}};return e[o].call(i.exports,i,i.exports,t),i.exports}(607)).default;var e,n}));
//# sourceMappingURL=index.js.map
export interface IWatchRTCConfiguration {
/** Watchrtc api key */
rtcApiKey: string;
/** Identifier for the session */
rtcRoomId: string;
/** Identifier for the current peer */
rtcPeerId: string;
/** ["tag1", "tag2", "tag3"] */
rtcTags?: string[];
wsUrl?: string;
proxyUrl?: string;
/** Enables additional logging */
debug?: boolean;
}

@@ -9,0 +15,0 @@ export declare type Rate = 1 | 2 | 3 | 4 | 5;

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

declare const _default: "1.28.8";
declare const _default: "1.28.9";
export default _default;

@@ -7,3 +7,4 @@ export default class WatchRTCSocket {

private onClose;
constructor();
private debug;
constructor(debug?: boolean);
connect(url: string, onData: (data: any) => void, onError: (error: any) => void): void;

@@ -10,0 +11,0 @@ trace(...data: any[]): void;

{
"name": "@testrtc/watchrtc-sdk",
"version": "1.28.8",
"version": "1.28.9",
"description": "gather WebRTC API traces and statistics",

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

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