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

@100mslive/100ms-web-sdk

Package Overview
Dependencies
Maintainers
8
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@100mslive/100ms-web-sdk - npm Package Compare versions

Comparing version 0.0.12-23 to 0.0.12-3012

dist/sdk/HMSAudioLevelListener.d.ts

2

dist/100ms-web-sdk.cjs.production.min.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("uuid"),n=(e=require("jsonwebtoken"))&&"object"==typeof e&&"default"in e?e.default:e;function r(e,t,n,r,i,a,o){try{var s=e[a](o),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,i)}function i(e){return function(){var t=this,n=arguments;return new Promise((function(i,a){var o=e.apply(t,n);function s(e){r(o,i,a,s,c,"next",e)}function c(e){r(o,i,a,s,c,"throw",e)}s(void 0)}))}}function a(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function o(e,t,n){return t&&a(e.prototype,t),n&&a(e,n),e}function s(){return(s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function c(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,h(e,t)}function u(e){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function h(e,t){return(h=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function f(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function l(e,t,n){return(l=f()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&h(i,n.prototype),i}).apply(null,arguments)}function d(e){var t="function"==typeof Map?new Map:void 0;return(d=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return l(e,arguments,u(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),h(n,e)})(e)}function p(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function v(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function k(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return v(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?v(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}var m,E,y,g,b=(function(e){var t=function(e){var t=Object.prototype,n=t.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},i=r.iterator||"@@iterator",a=r.asyncIterator||"@@asyncIterator",o=r.toStringTag||"@@toStringTag";function s(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,n){return e[t]=n}}function c(e,t,n,r){var i=Object.create((t&&t.prototype instanceof f?t:f).prototype),a=new x(r||[]);return i._invoke=function(e,t,n){var r="suspendedStart";return function(i,a){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===i)throw a;return{value:void 0,done:!0}}for(n.method=i,n.arg=a;;){var o=n.delegate;if(o){var s=g(o,n);if(s){if(s===h)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=u(e,t,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===h)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}(e,n,a),i}function u(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var h={};function f(){}function l(){}function d(){}var p={};p[i]=function(){return this};var v=Object.getPrototypeOf,k=v&&v(v(T([])));k&&k!==t&&n.call(k,i)&&(p=k);var m=d.prototype=f.prototype=Object.create(p);function E(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function y(e,t){var r;this._invoke=function(i,a){function o(){return new t((function(r,o){!function r(i,a,o,s){var c=u(e[i],e,a);if("throw"!==c.type){var h=c.arg,f=h.value;return f&&"object"==typeof f&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,o,s)}),(function(e){r("throw",e,o,s)})):t.resolve(f).then((function(e){h.value=e,o(h)}),(function(e){return r("throw",e,o,s)}))}s(c.arg)}(i,a,r,o)}))}return r=r?r.then(o,o):o()}}function g(e,t){var n=e.iterator[t.method];if(void 0===n){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,g(e,t),"throw"===t.method))return h;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return h}var r=u(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,h;var i=r.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,h):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,h)}function b(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function w(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function x(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(b,this),this.reset(!0)}function T(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,a=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return a.next=a}}return{next:R}}function R(){return{value:void 0,done:!0}}return l.prototype=m.constructor=d,d.constructor=l,l.displayName=s(d,o,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===l||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,d):(e.__proto__=d,s(e,o,"GeneratorFunction")),e.prototype=Object.create(m),e},e.awrap=function(e){return{__await:e}},E(y.prototype),y.prototype[a]=function(){return this},e.AsyncIterator=y,e.async=function(t,n,r,i,a){void 0===a&&(a=Promise);var o=new y(c(t,n,r,i),a);return e.isGeneratorFunction(n)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},E(m),s(m,o,"Generator"),m[i]=function(){return this},m.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=T,x.prototype={constructor:x,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(w),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(n,r){return o.type="throw",o.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],o=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var s=n.call(a,"catchLoc"),c=n.call(a,"finallyLoc");if(s&&c){if(this.prev<a.catchLoc)return r(a.catchLoc,!0);if(this.prev<a.finallyLoc)return r(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return r(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return r(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var a=i;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var o=a?a.completion:{};return o.type=e,o.arg=t,a?(this.method="next",this.next=a.finallyLoc,h):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),h},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),w(n),h}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;w(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:T(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),h}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}(g={exports:{}}),g.exports);!function(e){e[e.OFF=0]="OFF",e[e.ERROR=1]="ERROR",e[e.WARN=2]="WARN",e[e.INFO=3]="INFO",e[e.VERBOSE=4]="VERBOSE"}(m||(m={})),function(e){e[e.OFF=0]="OFF",e[e.ERROR=1]="ERROR",e[e.INFO=2]="INFO",e[e.VERBOSE=3]="VERBOSE"}(E||(E={})),function(e){e[e.VERBOSE=0]="VERBOSE",e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e[e.NONE=5]="NONE"}(y||(y={}));var w=function(){function e(){}return e.v=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[y.VERBOSE,e].concat(n))},e.d=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[y.DEBUG,e].concat(n))},e.i=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[y.INFO,e].concat(n))},e.w=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[y.WARN,e].concat(n))},e.e=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[y.ERROR,e].concat(n))},e.log=function(e,t){if(!(this.level.valueOf()>e.valueOf())){for(var n=arguments.length,r=new Array(n>2?n-2:0),i=2;i<n;i++)r[i-2]=arguments[i];switch(e){case y.VERBOSE:var a;(a=console).log.apply(a,[t].concat(r));break;case y.DEBUG:var o;(o=console).debug.apply(o,[t].concat(r));break;case y.INFO:var s;(s=console).info.apply(s,[t].concat(r));break;case y.WARN:var c;(c=console).warn.apply(c,[t].concat(r));break;case y.ERROR:var u;(u=console).error.apply(u,[t].concat(r))}}},e}();w.level=y.VERBOSE;var x,T="HMSConnection",R=function(){function e(e,t){this.candidates=new Array,this.role=e,this.signal=t}var t=e.prototype;return t.addTransceiver=function(e,t){return this.nativeConnection.addTransceiver(e,t)},t.createOffer=function(){var e=i(b.mark((function e(t){var n;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===t&&(t=void 0),e.prev=1,e.next=4,this.nativeConnection.createOffer(t);case 4:return n=e.sent,w.d(T,"[role="+this.role+"] createOffer offer="+JSON.stringify(n,null,1)),e.abrupt("return",n);case 9:throw e.prev=9,e.t0=e.catch(1),e.t0;case 12:case"end":return e.stop()}}),e,this,[[1,9]])})));return function(t){return e.apply(this,arguments)}}(),t.createAnswer=function(){var e=i(b.mark((function e(t){var n;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===t&&(t=void 0),e.next=3,this.nativeConnection.createAnswer(t);case 3:return n=e.sent,w.d(T,"[role="+this.role+"] createAnswer answer="+JSON.stringify(n,null,1)),e.abrupt("return",n);case 6:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.setLocalDescription=function(){var e=i(b.mark((function e(t){return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return w.d(T,"[role="+this.role+"] setLocalDescription description="+JSON.stringify(t,null,1)),e.next=3,this.nativeConnection.setLocalDescription(t);case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.setRemoteDescription=function(){var e=i(b.mark((function e(t){return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,w.d(T,"[role="+this.role+"] setRemoteDescription description="+JSON.stringify(t,null,1)),e.next=4,this.nativeConnection.setRemoteDescription(t);case 4:e.next=9;break;case 6:throw e.prev=6,e.t0=e.catch(0),e.t0;case 9:case"end":return e.stop()}}),e,this,[[0,6]])})));return function(t){return e.apply(this,arguments)}}(),t.addIceCandidate=function(){var e=i(b.mark((function e(t){return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return w.d(T,"[role="+this.role+"] addIceCandidate candidate="+JSON.stringify(t,null,1)),e.next=3,this.nativeConnection.addIceCandidate(t);case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.getSenders=function(){return this.nativeConnection.getSenders()},t.removeTrack=function(e){this.nativeConnection.removeTrack(e)},t.setMaxBitrate=function(){var e=i(b.mark((function e(t,n){var r,i;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(r=this.getSenders().find((function(e){var t;return(null==e||null==(t=e.track)?void 0:t.id)===n.trackId})))){e.next=6;break}return(i=r.getParameters()).encodings[0].maxBitrate=t,e.next=6,r.setParameters(i);case 6:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),t.close=function(){var e=i(b.mark((function e(){return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.nativeConnection.close();case 1:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),o(e,[{key:"remoteDescription",get:function(){return this.nativeConnection.remoteDescription}}]),e}();!function(e){e[e.PUBLISH=0]="PUBLISH",e[e.SUBSCRIBE=1]="SUBSCRIBE"}(x||(x={}));var A,S,C=function(e){function t(t,n,r){var i;return(i=e.call(this,x.PUBLISH,t)||this).observer=r,i.nativeConnection=new RTCPeerConnection(n),i.nativeConnection.createDataChannel("ion-sfu",{protocol:"SCTP"}),i.nativeConnection.onicecandidate=function(e){var n=e.candidate;n&&t.trickle(i.role,n)},i.nativeConnection.oniceconnectionstatechange=function(){i.observer.onIceConnectionChange(i.nativeConnection.iceConnectionState)},i}return c(t,e),t.prototype.initAfterJoin=function(){var e=this;this.nativeConnection.onnegotiationneeded=i(b.mark((function t(){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return w.d("HMSPublishConnection","onnegotiationneeded"),t.next=3,e.observer.onRenegotiationNeeded();case 3:case"end":return t.stop()}}),t)})))},t}(R),O=function(e){this.tracks=new Array,this.nativeStream=e,this.id=e.id};!function(e){e.VP8="vp8",e.VP9="vp9",e.H264="h264"}(A||(A={})),function(e){e.OPUS="opus"}(S||(S={}));var _,I=function(e,t){if(e<=0)throw Error("Height should be >= 1");if(t<=0)throw Error("Height should be >= 1");this.width=e,this.height=t},P=function(){function e(){this._resolution=new I(320,180),this._codec=A.VP8,this._maxFrameRate=24,this._maxBitRate=15e4,this._deviceId="default",this._advanced=[]}var t=e.prototype;return t.resolution=function(e){return this._resolution=e,this},t.codec=function(e){return this._codec=e,this},t.maxFrameRate=function(e){if(e<=0)throw Error("maxFrameRate should be >= 1");return this._maxFrameRate=e,this},t.maxBitRate=function(e){if(e<=0)throw Error("maxBitRate should be >= 1");return this._maxBitRate=e,this},t.deviceId=function(e){return this._deviceId=e,this},t.advanced=function(e){return this._advanced=e,this},t.build=function(){return new D(this._resolution,this._codec,this._maxFrameRate,this._maxBitRate,this._deviceId,this._advanced)},e}(),D=function(){function e(e,t,n,r,i,a){this.resolution=e,this.codec=t,this.maxFrameRate=n,this.maxBitRate=r,this.deviceId=i,this.advanced=a}return e.prototype.toConstraints=function(){return{width:this.resolution.width,height:this.resolution.height,frameRate:this.maxFrameRate,deviceId:this.deviceId}},e}(),L=function(){function e(){this._volume=1,this._codec=S.OPUS,this._maxBitRate=32e3,this._deviceId="default",this._advanced=[{googEchoCancellation:{exact:!0}},{googExperimentalEchoCancellation:{exact:!0}},{autoGainControl:{exact:!0}},{noiseSuppression:{exact:!0}},{googHighpassFilter:{exact:!0}},{googAudioMirroring:{exact:!0}}]}var t=e.prototype;return t.volume=function(e){if(!(0<=e&&e<=1))throw Error("volume can only be in range [0.0, 1.0]");return this._volume=e,this},t.codec=function(e){return this._codec=e,this},t.maxBitRate=function(e){if(e<=0)throw Error("maxBitRate should be >= 1");return this._maxBitRate=e,this},t.deviceId=function(e){return this._deviceId=e,this},t.advanced=function(e){return this._advanced=e,this},t.build=function(){return new N(this._volume,this._codec,this._maxBitRate,this._deviceId,this._advanced)},e}(),N=function(){function e(e,t,n,r,i){this.volume=e,this.codec=t,this.maxBitRate=n,this.deviceId=r,this.advanced=i}return e.prototype.toConstraints=function(){return{deviceId:this.deviceId,advanced:this.advanced}},e}(),M={QVGA:(new P).resolution(new I(320,180)).maxBitRate(15e4).build(),VGA:(new P).resolution(new I(640,360)).maxBitRate(5e5).build(),SHD:(new P).resolution(new I(960,540)).maxBitRate(12e5).build(),HD:(new P).resolution(new I(1280,720)).maxBitRate(25e5).build(),FHD:(new P).resolution(new I(1920,1080)).maxBitRate(4e6).build(),QHD:(new P).resolution(new I(2560,1440)).maxBitRate(8e6).build()},H=function(){function e(){this._video=M.QVGA,this._audio=(new L).build(),this._simulcast=!1}var t=e.prototype;return t.video=function(e){return this._video=e,this},t.audio=function(e){return this._audio=e,this},t.simulcast=function(e){return this._simulcast=e,this},t.build=function(){if(null===this._audio&&null===this._video)throw Error("There is no media to return. Please select either video or audio or both");if(null===this._video&&this._simulcast)throw Error("Cannot enable simulcast when no video settings are provided");return new U(this._video,this._audio,this._simulcast)},e}(),U=function(e,t,n){this.video=e,this.audio=t,this.simulcast=n};!function(e){e.NONE="none",e.LOW="low",e.MEDIUM="medium",e.HIGH="high"}(_||(_={}));var G,B=function(e){function t(t,n){var r;return(r=e.call(this,t)||this).audio=!0,r.video=_.HIGH,r.frameRate=_.HIGH,r.connection=n,r}c(t,e);var n=t.prototype;return n.setAudio=function(){var e=i(b.mark((function e(t){return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.audio=t,e.next=3,this.syncWithApiChannel();case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.setVideo=function(){var e=i(b.mark((function e(t){return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.video=t?_.HIGH:_.NONE,e.next=3,this.syncWithApiChannel();case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.syncWithApiChannel=function(){var e=i(b.mark((function e(){var t;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t={streamId:this.nativeStream.id,video:this.video,audio:this.audio,framerate:this.frameRate},e.next=3,this.connection.apiChannel.send(JSON.stringify(t));case 3:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),t}(O),V=function(){function e(e,t,n){var r=this;void 0===n&&(n=""),this.TAG="HMSDataChannel",this.nativeChannel=e,this.observer=t,this.metadata=n,e.onmessage=function(e){w.d(r.TAG,"["+r.metadata+"] onMessage: label="+r.label+", message="+e.data),r.observer.onMessage(e.data)}}var t=e.prototype;return t.send=function(){var e=i(b.mark((function e(t){return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("open"===this.nativeChannel.readyState){e.next=2;break}throw Error("Channel "+this.label+" not yet ready");case 2:w.d(this.TAG,"["+this.metadata+"] Sending [size="+t.length+"] message="+t),this.nativeChannel.send(t);case 4:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.close=function(){this.nativeChannel.close()},o(e,[{key:"id",get:function(){return this.nativeChannel.id}},{key:"label",get:function(){return this.nativeChannel.label}}]),e}(),j=function(){function e(e,t){this.stream=e,this.nativeTrack=t}return e.prototype.setEnabled=function(){var e=i(b.mark((function e(t){return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.nativeTrack.enabled=t;case 1:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),o(e,[{key:"enabled",get:function(){return this.nativeTrack.enabled}},{key:"trackId",get:function(){return this.nativeTrack.id}}]),e}();(G=exports.HMSTrackType||(exports.HMSTrackType={}))[G.AUDIO=0]="AUDIO",G[G.VIDEO=1]="VIDEO";var F,J=function(e){function t(t,n){var r;if((r=e.call(this,t,n)||this).type=exports.HMSTrackType.AUDIO,"audio"!==n.kind)throw new Error("Expected 'track' kind = 'audio'");return r}return c(t,e),t}(j),K=function(e){function t(){return e.apply(this,arguments)||this}return c(t,e),t.prototype.setEnabled=function(){var t=i(b.mark((function t(n){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n!==this.enabled){t.next=2;break}return t.abrupt("return");case 2:return t.next=4,e.prototype.setEnabled.call(this,n);case 4:return t.next=6,this.stream.setAudio(n);case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),t}(J);!function(e){e.REGULAR="regular",e.SCREEN="screen"}(F||(F={}));var W=function(e){function t(t,n,r){var i;if(void 0===r&&(r=F.REGULAR),(i=e.call(this,t,n)||this).type=exports.HMSTrackType.VIDEO,"video"!==n.kind)throw new Error("Expected 'track' kind = 'video'");return i.videoSourceType=r,i}return c(t,e),t}(j),Y=function(e){function t(){return e.apply(this,arguments)||this}return c(t,e),t.prototype.setEnabled=function(){var t=i(b.mark((function t(n){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n!==this.enabled){t.next=2;break}return t.abrupt("return");case 2:return t.next=4,e.prototype.setEnabled.call(this,n);case 4:return t.next=6,this.stream.setVideo(n);case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),t}(W),q=function(e){function t(t,n,r){var i;return(i=e.call(this,x.SUBSCRIBE,t)||this).remoteStreams=new Map,i._apiChannel=null,i.observer=r,i.nativeConnection=new RTCPeerConnection(n),i.initNativeConnectionCallbacks(),i}c(t,e);var n=t.prototype;return n.initNativeConnectionCallbacks=function(){var e=this;this.nativeConnection.oniceconnectionstatechange=function(){e.observer.onIceConnectionChange(e.nativeConnection.iceConnectionState)},this.nativeConnection.ondatachannel=function(t){"ion-sfu"===t.channel.label&&(e._apiChannel=new V(t.channel,{onMessage:function(t){e.observer.onApiChannelMessage(t)}},"role="+e.role))},this.nativeConnection.onicecandidate=function(t){null!==t.candidate&&e.signal.trickle(e.role,t.candidate)},this.nativeConnection.ontrack=function(t){var n=t.streams[0];if(!e.remoteStreams.has(n.id)){var r=new B(n,e);e.remoteStreams.set(n.id,r),n.onremovetrack=function(t){var i=r.tracks.findIndex((function(e){return e.trackId===t.track.id}));i>=0&&(e.observer.onTrackRemove(r.tracks[i]),r.tracks.splice(i,1),0===r.tracks.length&&e.remoteStreams.delete(n.id))}}var i=e.remoteStreams.get(n.id),a=new("audio"===t.track.kind?K:Y)(i,t.track);i.tracks.push(a),e.observer.onTrackAdd(a)}},n.close=function(){var t=i(b.mark((function t(){var n;return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.prototype.close.call(this);case 2:null==(n=this.apiChannel)||n.close();case 3:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),o(t,[{key:"apiChannel",get:function(){return this._apiChannel}}]),t}(R),Q=function(){function e(){}return e.fetchInitConfig=function(){var e=i(b.mark((function e(t,n){var r,i;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===n&&(n=""),w.d("InitService","fetchInitConfig: token="+t+" region="+n),r="https://qa2-us.100ms.live/init?token="+t,n.length>0&&(r+="&region="+n),e.next=6,fetch(r);case 6:return i=e.sent,e.next=9,i.json();case 9:return e.abrupt("return",s({},e.sent,{endpoint:"wss://100ms-grpc.100ms.live:8443/ws"}));case 11:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),e}(),z=function(){function e(e,t){this.code=e,this.message=t}return e.prototype.build=function(){return new Z(this.code,this.message)},e}(),Z=function(e){function t(t,n){var r;return(r=e.call(this,n)||this).code=t,r}return c(t,e),t}(d(Error)),$=function(){function e(e){this.TAG="[ SIGNAL ]: ",this.isJoinCompleted=!1,this.pendingTrickle=[],this.socket=null,this.callbacks=new Map,this.observer=e}var n=e.prototype;return n.call=function(){var e=i(b.mark((function e(n,r){var i,a=this;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=t.v4(),this.socket.send(JSON.stringify({method:n,params:r,id:i})),e.next=5,new Promise((function(e,t){a.callbacks.set(i,{resolve:e,reject:t})}));case 5:return e.abrupt("return",JSON.parse(e.sent));case 7:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),n.notify=function(e,t){this.socket.send(JSON.stringify({method:e,params:t}))},n.open=function(e){var t=this;return new Promise((function(n){t.socket=new WebSocket(e),t.socket.addEventListener("open",(function e(){n(),t.socket.removeEventListener("open",e)})),t.socket.addEventListener("message",(function(e){return t.onMessageHandler(e.data)}))}))},n.close=function(){var e=i(b.mark((function e(){var t,n=this;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=new Promise((function(e){n.socket.addEventListener("close",(function(){return e()}))})),this.socket.close(1e3,"Normal Close"),e.abrupt("return",t);case 3:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),n.join=function(){var e=i(b.mark((function e(t,n,r){var i,a,o=this;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i={name:t,data:n,offer:r},e.next=3,this.call("join",i);case 3:return a=e.sent,this.isJoinCompleted=!0,this.pendingTrickle.forEach((function(e){return o.trickle(e.target,e.candidate)})),this.pendingTrickle.length=0,w.d(this.TAG,"join: response="+JSON.stringify(a,null,1)),e.abrupt("return",a);case 9:case"end":return e.stop()}}),e,this)})));return function(t,n,r){return e.apply(this,arguments)}}(),n.trickle=function(e,t){this.isJoinCompleted?this.notify("trickle",{target:e,candidate:t}):this.pendingTrickle.push({target:e,candidate:t})},n.offer=function(){var e=i(b.mark((function e(t,n){return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this.call("offer",{desc:t,tracks:n});case 3:return e.abrupt("return",e.sent);case 7:throw e.prev=7,e.t0=e.catch(0),e.t0;case 10:case"end":return e.stop()}}),e,this,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),n.answer=function(e){this.notify("answer",{desc:e})},n.trackUpdate=function(e){w.d("Yet to implement",String(e))},n.broadcast=function(e){this.notify("broadcast",{version:"1.0",info:e})},n.recordStart=function(){},n.recordEnd=function(){},n.leave=function(){},n.analytics=function(){},n.onMessageHandler=function(e){var t=JSON.parse(e);if(t.hasOwnProperty("id")){var n=t.id;if(this.callbacks.has(n)){var r=this.callbacks.get(n);if(this.callbacks.delete(n),t.result)r.resolve(JSON.stringify(t.result));else{var i=t.error,a=new z(i.code,i.message).build();r.reject(a)}}else this.observer.onNotification(t)}else{if(!t.hasOwnProperty("method"))throw Error("WebSocket message has no 'method' or 'id' field, message="+t);"offer"===t.method?this.observer.onOffer(t.params):"trickle"===t.method?this.observer.onTrickle(t.params):this.observer.onNotification(t)}},e}();function X(e){return ee.apply(this,arguments)}function ee(){return(ee=i(b.mark((function e(t){return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,navigator.mediaDevices.getUserMedia({audio:t.toConstraints()});case 2:return e.abrupt("return",e.sent.getAudioTracks()[0]);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function te(e){return ne.apply(this,arguments)}function ne(){return(ne=i(b.mark((function e(t){return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,navigator.mediaDevices.getUserMedia({video:t.toConstraints()});case 2:return e.abrupt("return",e.sent.getVideoTracks()[0]);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var re=function(e){function t(t,n,r){var i;return i=e.call(this,t,n)||this,t.tracks.push(p(i)),i.settings=r,i}c(t,e);var n=t.prototype;return n.replaceTrackWith=function(){var e=i(b.mark((function e(t){var n;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,X(t);case 2:return n=e.sent,e.next=5,this.stream.replaceTrack(this,n);case 5:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.setEnabled=function(){var t=i(b.mark((function t(n){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n!==this.enabled){t.next=2;break}return t.abrupt("return");case 2:return t.next=4,e.prototype.setEnabled.call(this,n);case 4:if(!n){t.next=9;break}return t.next=7,this.replaceTrackWith(this.settings);case 7:t.next=10;break;case 9:this.nativeTrack.stop();case 10:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.setSettings=function(){var e=i(b.mark((function e(t){return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.settings.codec===t.codec){e.next=2;break}throw Error("Audio Codec can't be changed mid call.");case 2:if(this.settings.deviceId===t.deviceId){e.next=5;break}return e.next=5,this.replaceTrackWith(t);case 5:return e.next=7,this.nativeTrack.applyConstraints(t.toConstraints());case 7:this.settings=t;case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t}(J);function ie(e){if(e<=0)throw Error("`ms` should be a positive integer");return new Promise((function(t){return setTimeout(t,e)}))}var ae,oe,se,ce,ue,he=function(e){function t(t,n,r,i){var a;return void 0===i&&(i=F.REGULAR),a=e.call(this,t,n,i)||this,t.tracks.push(p(a)),a.settings=r,a}c(t,e);var n=t.prototype;return n.replaceTrackWith=function(){var e=i(b.mark((function e(t){var n;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,te(t);case 2:return n=e.sent,e.next=5,this.stream.replaceTrack(this,n);case 5:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.setEnabled=function(){var t=i(b.mark((function t(n){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n!==this.enabled){t.next=2;break}return t.abrupt("return");case 2:return t.next=4,e.prototype.setEnabled.call(this,n);case 4:if(!n){t.next=9;break}return t.next=7,this.replaceTrackWith(this.settings);case 7:t.next=12;break;case 9:return t.next=11,ie(100);case 11:this.nativeTrack.stop();case 12:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.setSettings=function(){var e=i(b.mark((function e(t){return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.settings.codec===t.codec){e.next=2;break}throw Error("Video Codec can't be changed mid call.");case 2:if(this.settings.deviceId===t.deviceId){e.next=5;break}return e.next=5,this.replaceTrackWith(t);case 5:return e.next=7,this.nativeTrack.applyConstraints(t.toConstraints());case 7:this.settings=t;case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t}(W),fe=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).connection=null,t}c(t,e);var n=t.prototype;return n.setConnection=function(e){this.connection=e},t.getLocalScreen=function(){var e=i(b.mark((function e(n){var r,i,a,o,s;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r={video:n.toConstraints(),audio:!1},e.next=3,navigator.mediaDevices.getDisplayMedia(r);case 3:return a=new t(i=e.sent),o=i.getVideoTracks()[0],s=new he(a,o,n,F.SCREEN),w.v("HMSLocalStream","getLocalScreen",s),e.abrupt("return",s);case 9:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),t.getLocalTracks=function(){var e=i(b.mark((function e(n){var r,i,a,o,s,c,u;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,navigator.mediaDevices.getUserMedia({audio:null!=n.audio&&n.audio.toConstraints(),video:null!=n.video&&n.video.toConstraints()});case 2:return i=new t(r=e.sent),a=[],null!=n.audio&&(o=r.getAudioTracks()[0],s=new re(i,o,n.audio),a.push(s)),null!=n.video&&(c=r.getVideoTracks()[0],u=new he(i,c,n.video),a.push(u)),w.v("HMSLocalStream","getLocalTracks",a),e.abrupt("return",a);case 9:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),n.addTransceiver=function(e){var t=this.connection.addTransceiver(e.nativeTrack,{streams:[this.nativeStream],direction:"sendonly",sendEncodings:void 0});return this.setPreferredCodec(t,e.nativeTrack.kind),t},n.setMaxBitrate=function(){var e=i(b.mark((function e(t,n){var r;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,null==(r=this.connection)?void 0:r.setMaxBitrate(t,n);case 2:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),n.setPreferredCodec=function(e,t){},n.replaceTrack=function(){var e=i(b.mark((function e(t,n){var r;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==(r=this.connection.getSenders().find((function(e){return e.track&&e.track.id===t.trackId})))){e.next=3;break}throw Error("No sender found for trackId="+t.trackId);case 3:return this.nativeStream.removeTrack(t.nativeTrack),r.track.stop(),e.next=7,r.replaceTrack(n);case 7:this.nativeStream.addTrack(n),t.nativeTrack=n;case 9:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),n.removeSender=function(e){var t=this,n=0;if(this.connection.getSenders().forEach((function(r){if(r.track&&r.track.id===e.trackId){t.connection.removeTrack(r),n+=1;var i=t.tracks.indexOf(e);if(-1===i)throw Error("Cannot find "+e+" in locally stored tracks");t.tracks.splice(i,1)}})),1!==n)throw Error("Removed "+n+" sender's, expected to remove 1")},t}(O),le="[HMSTransport]:",de=function(){function e(e){var t,n,r,a=this;this.tracks={},this.publishConnection=null,this.subscribeConnection=null,this.callbacks=new Map,this.signalObserver={onOffer:(n=i(b.mark((function e(t){var n,r,i,o;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,a.subscribeConnection.setRemoteDescription(t);case 2:n=k(a.subscribeConnection.candidates);case 3:if((r=n()).done){e.next=9;break}return i=r.value,e.next=7,a.subscribeConnection.addIceCandidate(i);case 7:e.next=3;break;case 9:return a.subscribeConnection.candidates.length=0,e.next=12,a.subscribeConnection.createAnswer();case 12:return o=e.sent,e.next=15,a.subscribeConnection.setLocalDescription(o);case 15:a.signal.answer(o);case 16:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)}),onTrickle:(t=i(b.mark((function e(t){var n;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!==(n=t.target===x.PUBLISH?a.publishConnection:a.subscribeConnection).remoteDescription){e.next=5;break}n.candidates.push(t.candidate),e.next=7;break;case 5:return e.next=7,n.addIceCandidate(t.candidate);case 7:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)}),onNotification:function(e){return a.observer.onNotification(e)},onFailure:function(e){a.observer.onFailure(e)}},this.signal=new $(this.signalObserver),this.publishConnectionObserver={onRenegotiationNeeded:(r=i(b.mark((function e(){var t,n,r;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return w.d(le,"⏳ [role=PUBLISH] onRenegotiationNeeded START",a.tracks),t=a.callbacks.get("renegotiation-callback-id"),a.callbacks.delete("renegotiation-callback-id"),e.prev=3,e.next=6,a.publishConnection.createOffer();case 6:return n=e.sent,e.next=9,a.publishConnection.setLocalDescription(n);case 9:return e.next=11,a.signal.offer(n,a.tracks);case 11:return r=e.sent,e.next=14,a.publishConnection.setRemoteDescription(r);case 14:null==t||t.resolve(!0),w.d(le,"✅ [role=PUBLISH] onRenegotiationNeeded DONE",a.tracks),e.next=21;break;case 18:e.prev=18,e.t0=e.catch(3),console.error(le,e.t0);case 21:case"end":return e.stop()}}),e,null,[[3,18]])}))),function(){return r.apply(this,arguments)}),onIceConnectionChange:function(e){}},this.subscribeConnectionObserver={onApiChannelMessage:function(e){var t={method:"active-speakers",params:JSON.parse(e)};a.observer.onNotification(t)},onTrackAdd:function(e){return a.observer.onTrackAdd(e)},onTrackRemove:function(e){return a.observer.onTrackRemove(e)},onIceConnectionChange:function(e){}},this.observer=e}var t=e.prototype;return t.getLocalScreen=function(){var e=i(b.mark((function e(t){return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,fe.getLocalScreen(t);case 2:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),t.getLocalTracks=function(){var e=i(b.mark((function e(t){return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,fe.getLocalTracks(t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),t.join=function(){var e=i(b.mark((function e(t,n,r){var i,a,o,s,c,u;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Q.fetchInitConfig(t);case 2:return w.d(le,"⏳ join: connecting to ws endpoint",(i=e.sent).endpoint),e.next=6,this.signal.open(i.endpoint+"?peer="+n+"&token="+t);case 6:return w.d(le,"✅ join: connected to ws endpoint"),w.d(le,r),this.publishConnection=new C(this.signal,i.rtcConfiguration,this.publishConnectionObserver),this.subscribeConnection=new q(this.signal,i.rtcConfiguration,this.subscribeConnectionObserver),w.d(le,"⏳ join: Negotiating over PUBLISH connection"),e.next=13,this.publishConnection.createOffer();case 13:return a=e.sent,e.next=16,this.publishConnection.setLocalDescription(a);case 16:return e.next=18,this.signal.join(r.name,n,a);case 18:return o=e.sent,e.next=21,this.publishConnection.setRemoteDescription(o);case 21:s=k(this.publishConnection.candidates);case 22:if((c=s()).done){e.next=28;break}return u=c.value,e.next=26,this.publishConnection.addIceCandidate(u);case 26:e.next=22;break;case 28:this.publishConnection.initAfterJoin(),w.d(le,"✅ join: Negotiated over PUBLISH connection"),w.d(le,"✅ join: successful");case 31:case"end":return e.stop()}}),e,this)})));return function(t,n,r){return e.apply(this,arguments)}}(),t.leave=function(){var e=i(b.mark((function e(){return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.publishConnection.close();case 2:return e.next=4,this.subscribeConnection.close();case 4:return e.next=6,this.signal.close();case 6:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),t.publishTrack=function(){var e=i(b.mark((function e(t){var n,r,i=this;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return w.d(le,"⏳ publishTrack: trackId="+t.trackId,t),this.tracks[t.trackId]={mute:!1,type:t.nativeTrack.kind,source:"audio"===t.nativeTrack.kind?"regular":t.videoSourceType,description:"",track_id:t.trackId,stream_id:t.stream.id},n=new Promise((function(e,t){i.callbacks.set("renegotiation-callback-id",{resolve:e,reject:t})})),(r=t.stream).setConnection(this.publishConnection),r.addTransceiver(t),e.next=8,n;case 8:if(t.type!==exports.HMSTrackType.VIDEO){e.next=12;break}return e.next=12,r.setMaxBitrate(25e4,t).then((function(){w.d(le,"Setting maxBitrate to 250 kpbs")})).catch((function(e){return w.e(le,"Failed setting maxBitrate",e)}));case 12:w.d(le,"✅ publishTrack: trackId="+t.trackId,this.callbacks);case 13:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.unpublishTrack=function(){var e=i(b.mark((function e(t){var n,r=this;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return w.d(le,"⏳ unpublishTrack: trackId="+t.trackId,t),delete this.tracks[t.trackId],n=new Promise((function(e,t){r.callbacks.set("renegotiation-callback-id",{resolve:e,reject:t})})),t.stream.removeSender(t),e.next=7,n;case 7:w.d(le,"✅ unpublishTrack: trackId="+t.trackId,this.callbacks);case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.publish=function(){var e=i(b.mark((function e(t){var n,r,i;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=k(t);case 1:if((r=n()).done){e.next=7;break}return i=r.value,e.next=5,this.publishTrack(i);case 5:e.next=1;break;case 7:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.unpublish=function(){var e=i(b.mark((function e(t){var n,r,i;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=k(t);case 1:if((r=n()).done){e.next=7;break}return i=r.value,e.next=5,this.unpublishTrack(i);case 5:e.next=1;break;case 7:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.sendMessage=function(e){this.signal.broadcast(e)},e}();(ae=exports.HMSRoomUpdate||(exports.HMSRoomUpdate={}))[ae.PEER_ADDED=0]="PEER_ADDED",ae[ae.PEER_REMOVED=1]="PEER_REMOVED",ae[ae.PEER_KNOCKED=2]="PEER_KNOCKED",ae[ae.ROOM_TYPE_CHANGED=3]="ROOM_TYPE_CHANGED",ae[ae.METADATA_UPDATED=4]="METADATA_UPDATED",ae[ae.SCREENSHARE_STARTED=5]="SCREENSHARE_STARTED",ae[ae.SCREENSHARE_STOPPED=6]="SCREENSHARE_STOPPED",ae[ae.DEFAULT_UPDATE=7]="DEFAULT_UPDATE",(oe=exports.HMSPeerUpdate||(exports.HMSPeerUpdate={}))[oe.PEER_JOINED=0]="PEER_JOINED",oe[oe.PEER_LEFT=1]="PEER_LEFT",oe[oe.AUDIO_TOGGLED=2]="AUDIO_TOGGLED",oe[oe.VIDEO_TOGGLED=3]="VIDEO_TOGGLED",(se=exports.HMSTrackUpdate||(exports.HMSTrackUpdate={}))[se.TRACK_ADDED=0]="TRACK_ADDED",se[se.TRACK_REMOVED=1]="TRACK_REMOVED",se[se.TRACK_MUTED=2]="TRACK_MUTED",se[se.TRACK_UNMUTED=3]="TRACK_UNMUTED",se[se.TRACK_DESCRIPTION_CHANGED=4]="TRACK_DESCRIPTION_CHANGED",function(e){e[e.PEER_JOIN=0]="PEER_JOIN",e[e.PEER_LEAVE=1]="PEER_LEAVE",e[e.PEER_LIST=2]="PEER_LIST",e[e.STREAM_ADD=3]="STREAM_ADD",e[e.ACTIVE_SPEAKERS=4]="ACTIVE_SPEAKERS",e[e.BROADCAST=5]="BROADCAST",e[e.ROLE_CHANGE=6]="ROLE_CHANGE",e[e.TRACK_ADD=7]="TRACK_ADD"}(ce||(ce={})),function(e){e.CHAT="chat"}(ue||(ue={}));var pe=function(e){var t=e.sender,n=e.message,r=e.type,i=e.receiver,a=e.time;this.receiver="",this.sender=t,this.message=n,this.type=function(e){if(!e)return ue.CHAT;switch(e){case"chat":return ue.CHAT;default:throw Error("Unsupported message type="+e+" received")}}(r),i&&(this.receiver=i),this.time=a&&a instanceof Date?a:a&&"string"==typeof a?new Date(a):new Date},ve=function(e){this.tracks=[],this.peerId=e.peer_id,this.info={name:e.info.name,data:e.info.data,userId:e.info.user_id},this.role=e.role,this.tracks=Object.values(e.tracks||{})},ke=function(e){this.peers=Object.values(e.peers).map((function(e){return new ve(e)}))},me=function(e){var t=e.peerId,n=e.name,r=e.isLocal,i=e.customerDescription;this.customerDescription="",this.auxiliaryTracks=[],this.name=n,this.peerId=t,this.isLocal=r,this.customerDescription=i},Ee=function(){function e(){var e=this;this.hmsPeerList=new Map,this.TAG="[Notification Manager]:",this.tracksToProcess=new Map,this.trackStateMap=new Map,this.handleOnTrackAdd=function(t){w.d(e.TAG,"ONTRACKADD",t),e.tracksToProcess.set(t.trackId,t),e.processPendingTracks()},this.handleOnTrackRemove=function(t){w.d(e.TAG,"ONTRACKREMOVE",t);var n=e.trackStateMap.get(t.trackId);if(n){var r=e.hmsPeerList.get(n.peerId);if(r){switch(t.type){case exports.HMSTrackType.AUDIO:r.audioTrack=null;break;case exports.HMSTrackType.VIDEO:var i=r.auxiliaryTracks.indexOf(t);i>-1?r.auxiliaryTracks.splice(i,1):r.videoTrack=null}e.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,t,r)}}},this.handleLeave=function(){e.hmsPeerList.clear()},this.findPeerByUID=function(t){return e.hmsPeerList.get(t)},this.handlePeerJoin=function(t){var n=new me({peerId:t.peerId,name:t.info.name,isLocal:!1,customerDescription:""});e.hmsPeerList.set(t.peerId,n),w.d(e.TAG,"adding to the peerList",n),t.tracks.forEach((function(n){e.trackStateMap.set(n.track_id,{peerId:t.peerId,trackInfo:n})})),e.processPendingTracks()},this.handlePeerLeave=function(t){e.hmsPeerList.delete(t.peerId)},this.handlePeerList=function(t){var n=t.peers;null==n||n.forEach((function(t){return e.handlePeerJoin(t)}))}}var t=e.prototype;return t.handleNotification=function(e,t,n){switch(this.listener=n,e){case ce.PEER_JOIN:var r=t;w.d(this.TAG,"PEER_JOIN event",r,t),this.handlePeerJoin(r);break;case ce.PEER_LEAVE:var i=t;w.d(this.TAG,"PEER_LEAVE event",i),this.handlePeerLeave(i);break;case ce.PEER_LIST:var a=t;w.d(this.TAG,"PEER_LIST event",a),this.handlePeerList(a);break;case ce.TRACK_ADD:this.handleTrackAdd(t);break;case ce.ACTIVE_SPEAKERS:default:return}},t.handleTrackAdd=function(e){w.d(this.TAG,"BIZ:ONTRACKADD",e);for(var t=0,n=Object.entries(e.tracks);t<n.length;t++){var r=n[t];this.trackStateMap.set(r[0],{peerId:e.peer.peer_id,trackInfo:r[1]})}this.processPendingTracks()},t.processPendingTracks=function(){var e=this;new Map(this.tracksToProcess).forEach((function(t){var n=e.trackStateMap.get(t.trackId);if(n){var r=e.hmsPeerList.get(n.peerId);if(r){switch(t.type){case exports.HMSTrackType.AUDIO:r.audioTrack=t;break;case exports.HMSTrackType.VIDEO:r.videoTrack=t}e.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_ADDED,t,r),e.tracksToProcess.delete(t.trackId)}}}))},e}(),ye=function(e,t,n){this.id=e,this.name=t,this.peers=n};exports.HMSSdk=function(){function e(){var e=this;this.logLevel=m.OFF,this.analyticsLevel=E.OFF,this.TAG="[HMSSdk]:",this.notificationManager=new Ee,this.published=!1,this.observer={onNotification:function(t){var n=function(e){switch(e){case"on-peer-join":return ce.PEER_JOIN;case"on-peer-leave":return ce.PEER_LEAVE;case"peer-list":return ce.PEER_LIST;case"stream-add":return ce.STREAM_ADD;case"on-track-add":return ce.TRACK_ADD;case"active-speakers":return ce.ACTIVE_SPEAKERS;case"on-broadcast":return ce.BROADCAST;case"on-role-change":return ce.ROLE_CHANGE;default:throw Error("Unsupported method="+e+" received")}}(t.method),r=function(e,t){switch(e){case ce.PEER_JOIN:case ce.PEER_LEAVE:return new ve(t);case ce.PEER_LIST:return new ke(t);case ce.BROADCAST:return new pe(t.info);case ce.ACTIVE_SPEAKERS:return;case ce.ROLE_CHANGE:case ce.TRACK_ADD:return t;default:throw Error("Unsupported method="+e+" received")}}(n,t.params);e.notificationManager.handleNotification(n,r,e.listener),e.onNotificationHandled(n,r)},onTrackAdd:function(t){e.notificationManager.handleOnTrackAdd(t)},onTrackRemove:function(t){e.notificationManager.handleOnTrackRemove(t)},onFailure:function(t){e.listener.onError(t)}},this.transport=new de(this.observer)}var r=e.prototype;return r.join=function(e,r){var i=this;this.transport=new de(this.observer),this.listener=r;var a=n.decode(e.authToken,{json:!0}).room_id,o=t.v4();this.localPeer=new me({peerId:o,name:e.userName,isLocal:!0,customerDescription:e.metaData}),w.d(this.TAG,"⏳ Joining room "+a),this.transport.join(e.authToken,this.localPeer.peerId,{name:e.userName}).then((function(){w.d(i.TAG,"✅ Joined room "+a),i.roomId=a,i.published||i.publish()}))},r.leave=function(){var e=i(b.mark((function e(){var t,n;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.roomId&&(w.d(this.TAG,"⏳ Leaving room "+this.roomId),null==(t=this.localPeer.audioTrack)||t.nativeTrack.stop(),null==(n=this.localPeer.videoTrack)||n.nativeTrack.stop(),this.notificationManager.handleLeave(),this.transport.leave(),w.d(this.TAG,"✅ Left room "+this.roomId),this.roomId=null);case 1:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),r.getLocalPeer=function(){return this.localPeer},r.getPeers=function(){var e=Array.from(this.notificationManager.hmsPeerList,(function(e){return e[1]})),t=[].concat(e,[this.getLocalPeer()]);return w.d(this.TAG,"Got peers",t),t},r.sendMessage=function(e,t,n){var r=new pe({sender:this.localPeer.peerId,type:e,message:t,receiver:n});return w.d(this.TAG,"Sending Message:: ",r),this.transport.sendMessage(r),r},r.startScreenShare=function(){var e=i(b.mark((function e(t){var n,r,i=this;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(((null==(n=this.localPeer.auxiliaryTracks)?void 0:n.length)||0)>0)){e.next=2;break}throw Error("Cannot share multiple screens");case 2:return e.next=4,this.transport.getLocalScreen(M.HD);case 4:return(r=e.sent).nativeTrack.onended=function(){i.stopEndedScreenshare(t)},e.next=8,this.transport.publish([r]);case 8:this.localPeer.auxiliaryTracks=[r];case 9:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.stopEndedScreenshare=function(){var e=i(b.mark((function e(t){return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return w.d(this.TAG,"✅ Screenshare ended natively"),e.next=3,this.stopScreenShare();case 3:t();case 4:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.stopScreenShare=function(){var e=i(b.mark((function e(){var t;return b.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return w.d(this.TAG,"✅ Screenshare ended from app"),t=this.localPeer.auxiliaryTracks[0],e.next=4,t.setEnabled(!1);case 4:this.transport.unpublish([t]),this.localPeer.auxiliaryTracks.length=0;case 6:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),r.onNotificationHandled=function(e,t){var n,r,i=this;switch(w.d(this.TAG,"onNotificationHandled",e),e){case ce.PEER_JOIN:(r=this.notificationManager.findPeerByUID((n=t).peerId))?this.listener.onPeerUpdate(exports.HMSPeerUpdate.PEER_JOINED,r):w.e(this.TAG,"⚠️ peer not found in peer-list",n,this.notificationManager.hmsPeerList);break;case ce.PEER_LEAVE:var a,o=new me({peerId:t.peerId,name:t.info.name,isLocal:!1,customerDescription:t.info.data});o.audioTrack&&this.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,o.audioTrack,o),o.videoTrack&&this.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,o.videoTrack,o),null==(a=o.auxiliaryTracks)||a.forEach((function(e){i.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,e,o)})),this.listener.onPeerUpdate(exports.HMSPeerUpdate.PEER_LEFT,o);break;case ce.PEER_LIST:this.listener.onJoin(this.createRoom());break;case ce.ROLE_CHANGE:this.roomId&&this.publish();break;case ce.STREAM_ADD:case ce.ACTIVE_SPEAKERS:return;case ce.BROADCAST:var s=t;w.d(this.TAG,"Received Message:: ",s),this.listener.onMessageReceived(s)}},r.publish=function(){var e=this;this.transport.getLocalTracks((new H).build()).then(function(){var t=i(b.mark((function t(n){return b.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n.forEach((function(t){switch(t.type){case exports.HMSTrackType.AUDIO:e.localPeer.audioTrack=t;break;case exports.HMSTrackType.VIDEO:e.localPeer.videoTrack=t}})),t.next=3,e.transport.publish(n);case 3:e.published=!0;case 4:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())},r.createRoom=function(){var e=this.getPeers();return this.hmsRoom=new ye(this.localPeer.peerId,"",e),this.hmsRoom},e}();
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("uuid");function t(e,t,n,r,i,a,o){try{var s=e[a](o),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,i)}function n(e){return function(){var n=this,r=arguments;return new Promise((function(i,a){var o=e.apply(n,r);function s(e){t(o,i,a,s,c,"next",e)}function c(e){t(o,i,a,s,c,"throw",e)}s(void 0)}))}}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}function a(){return(a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function o(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,c(e,t)}function s(e){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function c(e,t){return(c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function h(e,t,n){return(h=u()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&c(i,n.prototype),i}).apply(null,arguments)}function l(e){var t="function"==typeof Map?new Map:void 0;return(l=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return h(e,arguments,s(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),c(n,e)})(e)}function d(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function p(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function f(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return p(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?p(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}var v,k,E,m,T=(function(e){var t=function(e){var t=Object.prototype,n=t.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},i=r.iterator||"@@iterator",a=r.asyncIterator||"@@asyncIterator",o=r.toStringTag||"@@toStringTag";function s(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,n){return e[t]=n}}function c(e,t,n,r){var i=Object.create((t&&t.prototype instanceof l?t:l).prototype),a=new w(r||[]);return i._invoke=function(e,t,n){var r="suspendedStart";return function(i,a){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===i)throw a;return{value:void 0,done:!0}}for(n.method=i,n.arg=a;;){var o=n.delegate;if(o){var s=y(o,n);if(s){if(s===h)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=u(e,t,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===h)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}(e,n,a),i}function u(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var h={};function l(){}function d(){}function p(){}var f={};f[i]=function(){return this};var v=Object.getPrototypeOf,k=v&&v(v(x([])));k&&k!==t&&n.call(k,i)&&(f=k);var E=p.prototype=l.prototype=Object.create(f);function m(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function T(e,t){var r;this._invoke=function(i,a){function o(){return new t((function(r,o){!function r(i,a,o,s){var c=u(e[i],e,a);if("throw"!==c.type){var h=c.arg,l=h.value;return l&&"object"==typeof l&&n.call(l,"__await")?t.resolve(l.__await).then((function(e){r("next",e,o,s)}),(function(e){r("throw",e,o,s)})):t.resolve(l).then((function(e){h.value=e,o(h)}),(function(e){return r("throw",e,o,s)}))}s(c.arg)}(i,a,r,o)}))}return r=r?r.then(o,o):o()}}function y(e,t){var n=e.iterator[t.method];if(void 0===n){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,y(e,t),"throw"===t.method))return h;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return h}var r=u(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,h;var i=r.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,h):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,h)}function g(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function b(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function w(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(g,this),this.reset(!0)}function x(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,a=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return a.next=a}}return{next:A}}function A(){return{value:void 0,done:!0}}return d.prototype=E.constructor=p,p.constructor=d,d.displayName=s(p,o,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,p):(e.__proto__=p,s(e,o,"GeneratorFunction")),e.prototype=Object.create(E),e},e.awrap=function(e){return{__await:e}},m(T.prototype),T.prototype[a]=function(){return this},e.AsyncIterator=T,e.async=function(t,n,r,i,a){void 0===a&&(a=Promise);var o=new T(c(t,n,r,i),a);return e.isGeneratorFunction(n)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},m(E),s(E,o,"Generator"),E[i]=function(){return this},E.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=x,w.prototype={constructor:w,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(b),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(n,r){return o.type="throw",o.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],o=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var s=n.call(a,"catchLoc"),c=n.call(a,"finallyLoc");if(s&&c){if(this.prev<a.catchLoc)return r(a.catchLoc,!0);if(this.prev<a.finallyLoc)return r(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return r(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return r(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var a=i;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var o=a?a.completion:{};return o.type=e,o.arg=t,a?(this.method="next",this.next=a.finallyLoc,h):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),h},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),b(n),h}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;b(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:x(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),h}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}(m={exports:{}}),m.exports);!function(e){e[e.OFF=0]="OFF",e[e.ERROR=1]="ERROR",e[e.WARN=2]="WARN",e[e.INFO=3]="INFO",e[e.VERBOSE=4]="VERBOSE"}(v||(v={})),function(e){e[e.OFF=0]="OFF",e[e.ERROR=1]="ERROR",e[e.INFO=2]="INFO",e[e.VERBOSE=3]="VERBOSE"}(k||(k={})),function(e){e[e.VERBOSE=0]="VERBOSE",e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e[e.NONE=5]="NONE"}(E||(E={}));var y,g,b=function(){function e(){}return e.v=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[E.VERBOSE,e].concat(n))},e.d=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[E.DEBUG,e].concat(n))},e.i=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[E.INFO,e].concat(n))},e.w=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[E.WARN,e].concat(n))},e.e=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[E.ERROR,e].concat(n))},e.log=function(e,t){if(!(this.level.valueOf()>e.valueOf())){for(var n=arguments.length,r=new Array(n>2?n-2:0),i=2;i<n;i++)r[i-2]=arguments[i];switch(e){case E.VERBOSE:var a;(a=console).log.apply(a,[t].concat(r));break;case E.DEBUG:var o;(o=console).debug.apply(o,[t].concat(r));break;case E.INFO:var s;(s=console).info.apply(s,[t].concat(r));break;case E.WARN:var c;(c=console).warn.apply(c,[t].concat(r));break;case E.ERROR:var u;(u=console).error.apply(u,[t].concat(r))}}},e}();b.level=E.VERBOSE,function(e){e[e.PEER_JOIN=0]="PEER_JOIN",e[e.PEER_LEAVE=1]="PEER_LEAVE",e[e.PEER_LIST=2]="PEER_LIST",e[e.ACTIVE_SPEAKERS=3]="ACTIVE_SPEAKERS",e[e.BROADCAST=4]="BROADCAST",e[e.ROLE_CHANGE=5]="ROLE_CHANGE",e[e.TRACK_METADATA_ADD=6]="TRACK_METADATA_ADD",e[e.TRACK_UPDATE=7]="TRACK_UPDATE",e[e.UNSUPPORTED=8]="UNSUPPORTED"}(y||(y={})),function(e){e.CHAT="chat"}(g||(g={}));var w,x=function(e){var t=e.sender,n=e.message,r=e.type,i=e.receiver,a=e.time;this.receiver="",this.sender=t,this.message=n,this.type=function(e){if(!e)return g.CHAT;switch(e){case"chat":return g.CHAT;default:throw Error("Unsupported message type="+e+" received")}}(r),i&&(this.receiver=i),this.time=a&&a instanceof Date?a:a&&"string"==typeof a?new Date(a):new Date},A=function(e){this.mute=!e.enabled,this.type=e.type,this.source=e.source||"regular",this.description="",this.track_id=e.trackId,this.stream_id=e.stream.id},R=function(e){this.tracks=[],this.peerId=e.peer_id,this.info={name:e.info.name,data:e.info.data,userId:e.info.user_id},this.role=e.role,this.tracks=Object.values(e.tracks||{})},S=function(e){this.peers=Object.values(e.peers).map((function(e){return new R(e)}))},_="HMSConnection",C=function(){function e(e,t){this.candidates=new Array,this.role=e,this.signal=t}var t=e.prototype;return t.addTransceiver=function(e,t){return this.nativeConnection.addTransceiver(e,t)},t.createOffer=function(){var e=n(T.mark((function e(t){var n;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===t&&(t=void 0),e.prev=1,e.next=4,this.nativeConnection.createOffer(t);case 4:return n=e.sent,b.d(_,"[role="+this.role+"] createOffer offer="+JSON.stringify(n,null,1)),e.abrupt("return",n);case 9:throw e.prev=9,e.t0=e.catch(1),e.t0;case 12:case"end":return e.stop()}}),e,this,[[1,9]])})));return function(t){return e.apply(this,arguments)}}(),t.createAnswer=function(){var e=n(T.mark((function e(t){var n;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===t&&(t=void 0),e.next=3,this.nativeConnection.createAnswer(t);case 3:return n=e.sent,b.d(_,"[role="+this.role+"] createAnswer answer="+JSON.stringify(n,null,1)),e.abrupt("return",n);case 6:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.setLocalDescription=function(){var e=n(T.mark((function e(t){return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return b.d(_,"[role="+this.role+"] setLocalDescription description="+JSON.stringify(t,null,1)),e.next=3,this.nativeConnection.setLocalDescription(t);case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.setRemoteDescription=function(){var e=n(T.mark((function e(t){return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,b.d(_,"[role="+this.role+"] setRemoteDescription description="+JSON.stringify(t,null,1)),e.next=4,this.nativeConnection.setRemoteDescription(t);case 4:e.next=9;break;case 6:throw e.prev=6,e.t0=e.catch(0),e.t0;case 9:case"end":return e.stop()}}),e,this,[[0,6]])})));return function(t){return e.apply(this,arguments)}}(),t.addIceCandidate=function(){var e=n(T.mark((function e(t){return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return b.d(_,"[role="+this.role+"] addIceCandidate candidate="+JSON.stringify(t,null,1)),e.next=3,this.nativeConnection.addIceCandidate(t);case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.getSenders=function(){return this.nativeConnection.getSenders()},t.removeTrack=function(e){this.nativeConnection.removeTrack(e)},t.setMaxBitrate=function(){var e=n(T.mark((function e(t,n){var r,i;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(r=this.getSenders().find((function(e){var t;return(null==e||null==(t=e.track)?void 0:t.id)===n.trackId})))){e.next=6;break}return(i=r.getParameters()).encodings[0].maxBitrate=t,e.next=6,r.setParameters(i);case 6:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),t.trackUpdate=function(e){var t=new A(e);this.signal.trackUpdate(new Map([[e.trackId,t]]))},t.close=function(){var e=n(T.mark((function e(){return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.nativeConnection.close();case 1:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),i(e,[{key:"remoteDescription",get:function(){return this.nativeConnection.remoteDescription}}]),e}();!function(e){e[e.PUBLISH=0]="PUBLISH",e[e.SUBSCRIBE=1]="SUBSCRIBE"}(w||(w={}));var P,I,O=function(e){function t(t,n,r){var i;return(i=e.call(this,w.PUBLISH,t)||this).observer=r,i.nativeConnection=new RTCPeerConnection(n),i.nativeConnection.createDataChannel("ion-sfu",{protocol:"SCTP"}),i.nativeConnection.onicecandidate=function(e){var n=e.candidate;n&&t.trickle(i.role,n)},i.nativeConnection.oniceconnectionstatechange=function(){i.observer.onIceConnectionChange(i.nativeConnection.iceConnectionState)},i}return o(t,e),t.prototype.initAfterJoin=function(){var e=this;this.nativeConnection.onnegotiationneeded=n(T.mark((function t(){return T.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return b.d("HMSPublishConnection","onnegotiationneeded"),t.next=3,e.observer.onRenegotiationNeeded();case 3:case"end":return t.stop()}}),t)})))},t}(C),D=function(e){this.tracks=new Array,this.nativeStream=e,this.id=e.id};!function(e){e.VP8="vp8",e.VP9="vp9",e.H264="h264"}(P||(P={})),function(e){e.OPUS="opus"}(I||(I={}));var M,N=function(e,t){if(e<=0)throw Error("Height should be >= 1");if(t<=0)throw Error("Height should be >= 1");this.width=e,this.height=t},L=function(){function e(){this._resolution=new N(320,180),this._codec=P.VP8,this._maxFrameRate=24,this._maxBitRate=15e4,this._deviceId="default",this._advanced=[]}var t=e.prototype;return t.resolution=function(e){return this._resolution=e,this},t.codec=function(e){return this._codec=e,this},t.maxFrameRate=function(e){if(e<=0)throw Error("maxFrameRate should be >= 1");return this._maxFrameRate=e,this},t.maxBitRate=function(e){if(e<=0)throw Error("maxBitRate should be >= 1");return this._maxBitRate=e,this},t.deviceId=function(e){return this._deviceId=e,this},t.advanced=function(e){return this._advanced=e,this},t.build=function(){return new U(this._resolution,this._codec,this._maxFrameRate,this._maxBitRate,this._deviceId,this._advanced)},e}(),U=function(){function e(e,t,n,r,i,a){this.resolution=e,this.codec=t,this.maxFrameRate=n,this.maxBitRate=r,this.deviceId=i,this.advanced=a}return e.prototype.toConstraints=function(){return{width:this.resolution.width,height:this.resolution.height,frameRate:this.maxFrameRate,deviceId:this.deviceId}},e}(),H=function(){function e(){this._volume=1,this._codec=I.OPUS,this._maxBitRate=32e3,this._deviceId="default",this._advanced=[{googEchoCancellation:{exact:!0}},{googExperimentalEchoCancellation:{exact:!0}},{autoGainControl:{exact:!0}},{noiseSuppression:{exact:!0}},{googHighpassFilter:{exact:!0}},{googAudioMirroring:{exact:!0}}]}var t=e.prototype;return t.volume=function(e){if(!(0<=e&&e<=1))throw Error("volume can only be in range [0.0, 1.0]");return this._volume=e,this},t.codec=function(e){return this._codec=e,this},t.maxBitRate=function(e){if(e<=0)throw Error("maxBitRate should be >= 1");return this._maxBitRate=e,this},t.deviceId=function(e){return this._deviceId=e,this},t.advanced=function(e){return this._advanced=e,this},t.build=function(){return new G(this._volume,this._codec,this._maxBitRate,this._deviceId,this._advanced)},e}(),G=function(){function e(e,t,n,r,i){this.volume=e,this.codec=t,this.maxBitRate=n,this.deviceId=r,this.advanced=i}return e.prototype.toConstraints=function(){return{deviceId:this.deviceId,advanced:this.advanced}},e}(),B={QVGA:(new L).resolution(new N(320,180)).maxBitRate(15e4).build(),VGA:(new L).resolution(new N(640,360)).maxBitRate(5e5).build(),SHD:(new L).resolution(new N(960,540)).maxBitRate(12e5).build(),HD:(new L).resolution(new N(1280,720)).maxBitRate(25e5).build(),FHD:(new L).resolution(new N(1920,1080)).maxBitRate(4e6).build(),QHD:(new L).resolution(new N(2560,1440)).maxBitRate(8e6).build()},K=function(){function e(){this._video=B.QVGA,this._audio=(new H).build(),this._simulcast=!1}var t=e.prototype;return t.video=function(e){return this._video=e,this},t.audio=function(e){return this._audio=e,this},t.simulcast=function(e){return this._simulcast=e,this},t.build=function(){if(null===this._audio&&null===this._video)throw Error("There is no media to return. Please select either video or audio or both");if(null===this._video&&this._simulcast)throw Error("Cannot enable simulcast when no video settings are provided");return new V(this._video,this._audio,this._simulcast)},e}(),V=function(e,t,n){this.video=e,this.audio=t,this.simulcast=n};!function(e){e.NONE="none",e.LOW="low",e.MEDIUM="medium",e.HIGH="high"}(M||(M={}));var j,F=function(e){function t(t,n){var r;return(r=e.call(this,t)||this).audio=!0,r.video=M.HIGH,r.frameRate=M.HIGH,r.connection=n,r}o(t,e);var r=t.prototype;return r.setAudio=function(){var e=n(T.mark((function e(t){return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.audio=t,e.next=3,this.syncWithApiChannel();case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.setVideo=function(){var e=n(T.mark((function e(t){return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.video=t?M.HIGH:M.NONE,e.next=3,this.syncWithApiChannel();case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.syncWithApiChannel=function(){var e=n(T.mark((function e(){var t;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t={streamId:this.nativeStream.id,video:this.video,audio:this.audio,framerate:this.frameRate},e.next=3,this.connection.apiChannel.send(JSON.stringify(t));case 3:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),t}(D),J=function(){function e(e,t,n){var r=this;void 0===n&&(n=""),this.TAG="HMSDataChannel",this.nativeChannel=e,this.observer=t,this.metadata=n,e.onmessage=function(e){b.d(r.TAG,"["+r.metadata+"] onMessage: label="+r.label+", message="+e.data),r.observer.onMessage(e.data)}}var t=e.prototype;return t.send=function(){var e=n(T.mark((function e(t){return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("open"===this.nativeChannel.readyState){e.next=2;break}throw Error("Channel "+this.label+" not yet ready");case 2:b.d(this.TAG,"["+this.metadata+"] Sending [size="+t.length+"] message="+t),this.nativeChannel.send(t);case 4:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.close=function(){this.nativeChannel.close()},i(e,[{key:"id",get:function(){return this.nativeChannel.id}},{key:"label",get:function(){return this.nativeChannel.label}}]),e}(),W=function(){function e(e,t,n){this.stream=e,this.nativeTrack=t,this.source=n}return e.prototype.setEnabled=function(){var e=n(T.mark((function e(t){return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.nativeTrack.enabled=t;case 1:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),i(e,[{key:"enabled",get:function(){return this.nativeTrack.enabled}},{key:"trackId",get:function(){return this.nativeTrack.id}}]),e}();(j=exports.HMSTrackType||(exports.HMSTrackType={})).AUDIO="audio",j.VIDEO="video";var Y=function(e){function t(t,n,r){var i;if((i=e.call(this,t,n,r)||this).type=exports.HMSTrackType.AUDIO,"audio"!==n.kind)throw new Error("Expected 'track' kind = 'audio'");return i}return o(t,e),t}(W),Q=function(e){function t(){return e.apply(this,arguments)||this}return o(t,e),t.prototype.setEnabled=function(){var t=n(T.mark((function t(n){return T.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n!==this.enabled){t.next=2;break}return t.abrupt("return");case 2:return t.next=4,e.prototype.setEnabled.call(this,n);case 4:return t.next=6,this.stream.setAudio(n);case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),t}(Y),q=function(e){function t(t,n,r){var i;if((i=e.call(this,t,n,r)||this).type=exports.HMSTrackType.VIDEO,"video"!==n.kind)throw new Error("Expected 'track' kind = 'video'");return i}return o(t,e),t}(W),z=function(e){function t(){return e.apply(this,arguments)||this}return o(t,e),t.prototype.setEnabled=function(){var t=n(T.mark((function t(n){return T.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n!==this.enabled){t.next=2;break}return t.abrupt("return");case 2:return t.next=4,e.prototype.setEnabled.call(this,n);case 4:return t.next=6,this.stream.setVideo(n);case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),t}(q),$=function(e){function t(t,n,r){var i;return(i=e.call(this,w.SUBSCRIBE,t)||this).remoteStreams=new Map,i._apiChannel=null,i.observer=r,i.nativeConnection=new RTCPeerConnection(n),i.initNativeConnectionCallbacks(),i}o(t,e);var r=t.prototype;return r.initNativeConnectionCallbacks=function(){var e=this;this.nativeConnection.oniceconnectionstatechange=function(){e.observer.onIceConnectionChange(e.nativeConnection.iceConnectionState)},this.nativeConnection.ondatachannel=function(t){"ion-sfu"===t.channel.label&&(e._apiChannel=new J(t.channel,{onMessage:function(t){e.observer.onApiChannelMessage(t)}},"role="+e.role))},this.nativeConnection.onicecandidate=function(t){null!==t.candidate&&e.signal.trickle(e.role,t.candidate)},this.nativeConnection.ontrack=function(t){var n=t.streams[0];if(!e.remoteStreams.has(n.id)){var r=new F(n,e);e.remoteStreams.set(n.id,r),n.onremovetrack=function(t){var i=r.tracks.findIndex((function(e){return e.trackId===t.track.id}));i>=0&&(e.observer.onTrackRemove(r.tracks[i]),r.tracks.splice(i,1),0===r.tracks.length&&e.remoteStreams.delete(n.id))}}var i=e.remoteStreams.get(n.id),a=new("audio"===t.track.kind?Q:z)(i,t.track);i.tracks.push(a),e.observer.onTrackAdd(a)}},r.close=function(){var t=n(T.mark((function t(){var n;return T.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.prototype.close.call(this);case 2:null==(n=this.apiChannel)||n.close();case 3:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),i(t,[{key:"apiChannel",get:function(){return this._apiChannel}}]),t}(C),X=function(){function e(){}return e.fetchInitConfig=function(){var e=n(T.mark((function e(t,n){var r,i;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===n&&(n=""),b.d("InitService","fetchInitConfig: token="+t+" region="+n),r="https://qa2-us.100ms.live/init?token="+t,n.length>0&&(r+="&region="+n),e.next=6,fetch(r);case 6:return i=e.sent,e.next=9,i.json();case 9:return e.abrupt("return",e.sent);case 11:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),e}(),Z=function(){function e(e,t){this.code=e,this.message=t}return e.prototype.build=function(){return new ee(this.code,this.message)},e}(),ee=function(e){function t(t,n){var r;return(r=e.call(this,n)||this).code=t,r}return o(t,e),t}(l(Error)),te=function(){function t(e){this.TAG="[ SIGNAL ]: ",this.isJoinCompleted=!1,this.pendingTrickle=[],this.socket=null,this.callbacks=new Map,this.observer=e}var r=t.prototype;return r.call=function(){var t=n(T.mark((function t(n,r){var i,a=this;return T.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return i=e.v4(),this.socket.send(JSON.stringify({method:n,params:r,id:i})),t.next=5,new Promise((function(e,t){a.callbacks.set(i,{resolve:e,reject:t})}));case 5:return t.abrupt("return",JSON.parse(t.sent));case 7:case"end":return t.stop()}}),t,this)})));return function(e,n){return t.apply(this,arguments)}}(),r.notify=function(e,t){this.socket.send(JSON.stringify({method:e,params:t}))},r.open=function(e){var t=this;return new Promise((function(n){t.socket=new WebSocket(e),t.socket.addEventListener("open",(function e(){n(),t.socket.removeEventListener("open",e)})),t.socket.addEventListener("message",(function(e){return t.onMessageHandler(e.data)}))}))},r.close=function(){var e=n(T.mark((function e(){var t,n=this;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=new Promise((function(e){n.socket.addEventListener("close",(function(){return e()}))})),this.socket.close(1e3,"Normal Close"),e.abrupt("return",t);case 3:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),r.join=function(){var e=n(T.mark((function e(t,n,r){var i,a,o=this;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i={name:t,data:n,offer:r},e.next=3,this.call("join",i);case 3:return a=e.sent,this.isJoinCompleted=!0,this.pendingTrickle.forEach((function(e){return o.trickle(e.target,e.candidate)})),this.pendingTrickle.length=0,b.d(this.TAG,"join: response="+JSON.stringify(a,null,1)),e.abrupt("return",a);case 9:case"end":return e.stop()}}),e,this)})));return function(t,n,r){return e.apply(this,arguments)}}(),r.trickle=function(e,t){this.isJoinCompleted?this.notify("trickle",{target:e,candidate:t}):this.pendingTrickle.push({target:e,candidate:t})},r.offer=function(){var e=n(T.mark((function e(t,n){return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.call("offer",{desc:t,tracks:n});case 2:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),r.answer=function(e){this.notify("answer",{desc:e})},r.trackUpdate=function(e){b.d(this.TAG,"Track Update: ",{tracks:Object.fromEntries(e)}),this.notify("track-update",{version:"1.0",tracks:Object.fromEntries(e)})},r.broadcast=function(e){this.notify("broadcast",{version:"1.0",info:e})},r.recordStart=function(){},r.recordEnd=function(){},r.leave=function(){this.notify("leave",{version:"1.0"})},r.analytics=function(){},r.onMessageHandler=function(e){var t=JSON.parse(e);if(t.hasOwnProperty("id")){var n=t.id;if(this.callbacks.has(n)){var r=this.callbacks.get(n);if(this.callbacks.delete(n),t.result)r.resolve(JSON.stringify(t.result));else{var i=t.error,a=new Z(i.code,i.message).build();r.reject(a)}}else this.observer.onNotification(t)}else{if(!t.hasOwnProperty("method"))throw Error("WebSocket message has no 'method' or 'id' field, message="+t);"offer"===t.method?this.observer.onOffer(t.params):"trickle"===t.method?this.observer.onTrickle(t.params):this.observer.onNotification(t)}},t}();function ne(e){return re.apply(this,arguments)}function re(){return(re=n(T.mark((function e(t){return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,navigator.mediaDevices.getUserMedia({audio:t.toConstraints()});case 2:return e.abrupt("return",e.sent.getAudioTracks()[0]);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ie(e){return ae.apply(this,arguments)}function ae(){return(ae=n(T.mark((function e(t){return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,navigator.mediaDevices.getUserMedia({video:t.toConstraints()});case 2:return e.abrupt("return",e.sent.getVideoTracks()[0]);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var oe=function(e){function t(t,n,r,i){var a;return a=e.call(this,t,n,i)||this,t.tracks.push(d(a)),a.settings=r,a}o(t,e);var r=t.prototype;return r.replaceTrackWith=function(){var e=n(T.mark((function e(t){var n;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ne(t);case 2:return n=e.sent,e.next=5,this.stream.replaceTrack(this,n);case 5:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.setEnabled=function(){var t=n(T.mark((function t(n){return T.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n!==this.enabled){t.next=2;break}return t.abrupt("return");case 2:return t.next=4,e.prototype.setEnabled.call(this,n);case 4:if(this.stream.trackUpdate(this),!n){t.next=10;break}return t.next=8,this.replaceTrackWith(this.settings);case 8:t.next=11;break;case 10:this.nativeTrack.stop();case 11:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.setSettings=function(){var e=n(T.mark((function e(t){return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.settings.codec===t.codec){e.next=2;break}throw Error("Audio Codec can't be changed mid call.");case 2:if(this.settings.deviceId===t.deviceId){e.next=5;break}return e.next=5,this.replaceTrackWith(t);case 5:return e.next=7,this.nativeTrack.applyConstraints(t.toConstraints());case 7:this.settings=t;case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t}(Y);function se(e){if(e<=0)throw Error("`ms` should be a positive integer");return new Promise((function(t){return setTimeout(t,e)}))}var ce,ue,he,le=function(e){function t(t,n,r,i){var a;return a=e.call(this,t,n,i)||this,t.tracks.push(d(a)),a.settings=r,a}o(t,e);var r=t.prototype;return r.replaceTrackWith=function(){var e=n(T.mark((function e(t){var n;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ie(t);case 2:return n=e.sent,e.next=5,this.stream.replaceTrack(this,n);case 5:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.setEnabled=function(){var t=n(T.mark((function t(n){return T.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n!==this.enabled){t.next=2;break}return t.abrupt("return");case 2:return t.next=4,e.prototype.setEnabled.call(this,n);case 4:if(this.stream.trackUpdate(this),!n){t.next=10;break}return t.next=8,this.replaceTrackWith(this.settings);case 8:t.next=13;break;case 10:return t.next=12,se(100);case 12:this.nativeTrack.stop();case 13:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.setSettings=function(){var e=n(T.mark((function e(t){return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.settings.codec===t.codec){e.next=2;break}throw Error("Video Codec can't be changed mid call.");case 2:if(this.settings.deviceId===t.deviceId){e.next=5;break}return e.next=5,this.replaceTrackWith(t);case 5:return e.next=7,this.nativeTrack.applyConstraints(t.toConstraints());case 7:this.settings=t;case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t}(q),de=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).connection=null,t}o(t,e);var r=t.prototype;return r.setConnection=function(e){this.connection=e},t.getLocalScreen=function(){var e=n(T.mark((function e(n){var r,i,a,o,s;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r={video:n.toConstraints(),audio:!1},e.next=3,navigator.mediaDevices.getDisplayMedia(r);case 3:return a=new t(i=e.sent),o=i.getVideoTracks()[0],s=new le(a,o,n,"screen"),b.v("HMSLocalStream","getLocalScreen",s),e.abrupt("return",s);case 9:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),t.getLocalTracks=function(){var e=n(T.mark((function e(n){var r,i,a,o,s,c,u;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,navigator.mediaDevices.getUserMedia({audio:null!=n.audio&&n.audio.toConstraints(),video:null!=n.video&&n.video.toConstraints()});case 2:return i=new t(r=e.sent),a=[],null!=n.audio&&(o=r.getAudioTracks()[0],s=new oe(i,o,n.audio,"regular"),a.push(s)),null!=n.video&&(c=r.getVideoTracks()[0],u=new le(i,c,n.video,"regular"),a.push(u)),b.v("HMSLocalStream","getLocalTracks",a),e.abrupt("return",a);case 9:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),r.addTransceiver=function(e){var t=this.connection.addTransceiver(e.nativeTrack,{streams:[this.nativeStream],direction:"sendonly",sendEncodings:void 0});return this.setPreferredCodec(t,e.nativeTrack.kind),t},r.setMaxBitrate=function(){var e=n(T.mark((function e(t,n){var r;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,null==(r=this.connection)?void 0:r.setMaxBitrate(t,n);case 2:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),r.setPreferredCodec=function(e,t){},r.replaceTrack=function(){var e=n(T.mark((function e(t,n){var r;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==(r=this.connection.getSenders().find((function(e){return e.track&&e.track.id===t.trackId})))){e.next=3;break}throw Error("No sender found for trackId="+t.trackId);case 3:return this.nativeStream.removeTrack(t.nativeTrack),r.track.stop(),e.next=7,r.replaceTrack(n);case 7:this.nativeStream.addTrack(n),t.nativeTrack=n;case 9:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),r.removeSender=function(e){var t=this,n=0;if(this.connection.getSenders().forEach((function(r){if(r.track&&r.track.id===e.trackId){t.connection.removeTrack(r),n+=1;var i=t.tracks.indexOf(e);if(-1===i)throw Error("Cannot find "+e+" in locally stored tracks");t.tracks.splice(i,1)}})),1!==n)throw Error("Removed "+n+" sender's, expected to remove 1")},r.trackUpdate=function(e){var t;null==(t=this.connection)||t.trackUpdate(e)},t}(D),pe="[HMSTransport]:",fe=function(){function e(e){var t,r,i,a=this;this.tracks={},this.publishConnection=null,this.subscribeConnection=null,this.callbacks=new Map,this.signalObserver={onOffer:(r=n(T.mark((function e(t){var n,r,i,o;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,a.subscribeConnection.setRemoteDescription(t);case 2:n=f(a.subscribeConnection.candidates);case 3:if((r=n()).done){e.next=9;break}return i=r.value,e.next=7,a.subscribeConnection.addIceCandidate(i);case 7:e.next=3;break;case 9:return a.subscribeConnection.candidates.length=0,e.next=12,a.subscribeConnection.createAnswer();case 12:return o=e.sent,e.next=15,a.subscribeConnection.setLocalDescription(o);case 15:a.signal.answer(o);case 16:case"end":return e.stop()}}),e)}))),function(e){return r.apply(this,arguments)}),onTrickle:(t=n(T.mark((function e(t){var n;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!==(n=t.target===w.PUBLISH?a.publishConnection:a.subscribeConnection).remoteDescription){e.next=5;break}n.candidates.push(t.candidate),e.next=7;break;case 5:return e.next=7,n.addIceCandidate(t.candidate);case 7:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)}),onNotification:function(e){return a.observer.onNotification(e)},onFailure:function(e){a.observer.onFailure(e)}},this.signal=new te(this.signalObserver),this.publishConnectionObserver={onRenegotiationNeeded:(i=n(T.mark((function e(){var t,n,r;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return b.d(pe,"⏳ [role=PUBLISH] onRenegotiationNeeded START",a.tracks),t=a.callbacks.get("renegotiation-callback-id"),a.callbacks.delete("renegotiation-callback-id"),e.prev=3,e.next=6,a.publishConnection.createOffer();case 6:return n=e.sent,e.next=9,a.publishConnection.setLocalDescription(n);case 9:return e.next=11,a.signal.offer(n,a.tracks);case 11:return r=e.sent,e.next=14,a.publishConnection.setRemoteDescription(r);case 14:null==t||t.resolve(!0),b.d(pe,"✅ [role=PUBLISH] onRenegotiationNeeded DONE",a.tracks),e.next=21;break;case 18:e.prev=18,e.t0=e.catch(3),console.error(pe,e.t0);case 21:case"end":return e.stop()}}),e,null,[[3,18]])}))),function(){return i.apply(this,arguments)}),onIceConnectionChange:function(e){}},this.subscribeConnectionObserver={onApiChannelMessage:function(e){a.observer.onNotification(JSON.parse(e))},onTrackAdd:function(e){return a.observer.onTrackAdd(e)},onTrackRemove:function(e){return a.observer.onTrackRemove(e)},onIceConnectionChange:function(e){}},this.observer=e}var t=e.prototype;return t.getLocalScreen=function(){var e=n(T.mark((function e(t){return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,de.getLocalScreen(t);case 2:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),t.getLocalTracks=function(){var e=n(T.mark((function e(t){return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,de.getLocalTracks(t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),t.join=function(){var e=n(T.mark((function e(t,n,r){var i,a,o,s,c,u;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,X.fetchInitConfig(t);case 2:return b.d(pe,"⏳ join: connecting to ws endpoint",(i=e.sent).endpoint),e.next=6,this.signal.open(i.endpoint+"?peer="+n+"&token="+t);case 6:return b.d(pe,"✅ join: connected to ws endpoint"),b.d(pe,r),this.publishConnection=new O(this.signal,i.rtcConfiguration,this.publishConnectionObserver),this.subscribeConnection=new $(this.signal,i.rtcConfiguration,this.subscribeConnectionObserver),b.d(pe,"⏳ join: Negotiating over PUBLISH connection"),e.next=13,this.publishConnection.createOffer();case 13:return a=e.sent,e.next=16,this.publishConnection.setLocalDescription(a);case 16:return e.next=18,this.signal.join(r.name,n,a);case 18:return o=e.sent,e.next=21,this.publishConnection.setRemoteDescription(o);case 21:s=f(this.publishConnection.candidates);case 22:if((c=s()).done){e.next=28;break}return u=c.value,e.next=26,this.publishConnection.addIceCandidate(u);case 26:e.next=22;break;case 28:this.publishConnection.initAfterJoin(),b.d(pe,"✅ join: Negotiated over PUBLISH connection"),b.d(pe,"✅ join: successful");case 31:case"end":return e.stop()}}),e,this)})));return function(t,n,r){return e.apply(this,arguments)}}(),t.leave=function(){var e=n(T.mark((function e(){return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.publishConnection.close();case 2:return e.next=4,this.subscribeConnection.close();case 4:return this.signal.leave(),e.next=7,this.signal.close();case 7:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),t.publishTrack=function(){var e=n(T.mark((function e(t){var n,r,i=this;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return b.d(pe,"⏳ publishTrack: trackId="+t.trackId,t),this.tracks[t.trackId]={mute:!1,type:t.nativeTrack.kind,source:t.source,description:"",track_id:t.trackId,stream_id:t.stream.id},n=new Promise((function(e,t){i.callbacks.set("renegotiation-callback-id",{resolve:e,reject:t})})),(r=t.stream).setConnection(this.publishConnection),r.addTransceiver(t),e.next=8,n;case 8:if(t.type!==exports.HMSTrackType.VIDEO){e.next=12;break}return e.next=12,r.setMaxBitrate(25e4,t).then((function(){b.d(pe,"Setting maxBitrate to 250 kpbs")})).catch((function(e){return b.e(pe,"Failed setting maxBitrate",e)}));case 12:b.d(pe,"✅ publishTrack: trackId="+t.trackId,this.callbacks);case 13:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.unpublishTrack=function(){var e=n(T.mark((function e(t){var n,r=this;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return b.d(pe,"⏳ unpublishTrack: trackId="+t.trackId,t),delete this.tracks[t.trackId],n=new Promise((function(e,t){r.callbacks.set("renegotiation-callback-id",{resolve:e,reject:t})})),t.stream.removeSender(t),e.next=7,n;case 7:b.d(pe,"✅ unpublishTrack: trackId="+t.trackId,this.callbacks);case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.publish=function(){var e=n(T.mark((function e(t){var n,r,i;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=f(t);case 1:if((r=n()).done){e.next=7;break}return i=r.value,e.next=5,this.publishTrack(i);case 5:e.next=1;break;case 7:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.unpublish=function(){var e=n(T.mark((function e(t){var n,r,i;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=f(t);case 1:if((r=n()).done){e.next=7;break}return i=r.value,e.next=5,this.unpublishTrack(i);case 5:e.next=1;break;case 7:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.sendMessage=function(e){this.signal.broadcast(e)},e}();(ce=exports.HMSRoomUpdate||(exports.HMSRoomUpdate={}))[ce.PEER_ADDED=0]="PEER_ADDED",ce[ce.PEER_REMOVED=1]="PEER_REMOVED",ce[ce.PEER_KNOCKED=2]="PEER_KNOCKED",ce[ce.ROOM_TYPE_CHANGED=3]="ROOM_TYPE_CHANGED",ce[ce.METADATA_UPDATED=4]="METADATA_UPDATED",ce[ce.SCREENSHARE_STARTED=5]="SCREENSHARE_STARTED",ce[ce.SCREENSHARE_STOPPED=6]="SCREENSHARE_STOPPED",ce[ce.DEFAULT_UPDATE=7]="DEFAULT_UPDATE",(ue=exports.HMSPeerUpdate||(exports.HMSPeerUpdate={}))[ue.PEER_JOINED=0]="PEER_JOINED",ue[ue.PEER_LEFT=1]="PEER_LEFT",ue[ue.AUDIO_TOGGLED=2]="AUDIO_TOGGLED",ue[ue.VIDEO_TOGGLED=3]="VIDEO_TOGGLED",ue[ue.BECAME_DOMINANT_SPEAKER=4]="BECAME_DOMINANT_SPEAKER",ue[ue.RESIGNED_DOMINANT_SPEAKER=5]="RESIGNED_DOMINANT_SPEAKER",ue[ue.STARTED_SPEAKING=6]="STARTED_SPEAKING",ue[ue.STOPPED_SPEAKING=7]="STOPPED_SPEAKING",(he=exports.HMSTrackUpdate||(exports.HMSTrackUpdate={}))[he.TRACK_ADDED=0]="TRACK_ADDED",he[he.TRACK_REMOVED=1]="TRACK_REMOVED",he[he.TRACK_MUTED=2]="TRACK_MUTED",he[he.TRACK_UNMUTED=3]="TRACK_UNMUTED",he[he.TRACK_DESCRIPTION_CHANGED=4]="TRACK_DESCRIPTION_CHANGED";var ve=function(e){var t=e.peerId,n=e.name,r=e.isLocal,i=e.customerDescription;this.customerDescription="",this.auxiliaryTracks=[],this.name=n,this.peerId=t,this.isLocal=r,this.customerDescription=i},ke=function(){function e(){this.TAG="[HMSAudioLevelListener]:",this.recentUpdate=null,this.dominantSpeaker=null}return e.prototype.updateDominantSpeaker=function(e,t,n){var r=this;if(this.listener=n,this.recentUpdate)this.recentUpdate=new Date,this.dominantSpeaker=t,b.d(this.TAG,"BECAME_DOMINANT_SPEAKER",e,t),this.listener.onPeerUpdate(exports.HMSPeerUpdate.BECAME_DOMINANT_SPEAKER,t);else{this.recentUpdate=new Date,this.dominantSpeaker=t,b.d(this.TAG,"BECAME_DOMINANT_SPEAKER",e,t),this.listener.onPeerUpdate(exports.HMSPeerUpdate.BECAME_DOMINANT_SPEAKER,t);var i=setInterval((function(){var e=new Date;r.recentUpdate&&e.getTime()-r.recentUpdate.getTime()>1e3&&(r.recentUpdate=null,b.d(r.TAG,"RESIGNED_DOMINANT_SPEAKER",r.dominantSpeaker),r.listener.onPeerUpdate(exports.HMSPeerUpdate.RESIGNED_DOMINANT_SPEAKER,r.dominantSpeaker),r.dominantSpeaker=null,clearInterval(i))}),1e3)}},e}(),Ee=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).hmsPeerList=new Map,t.TAG="[Notification Manager]:",t.tracksToProcess=new Map,t.trackStateMap=new Map,t.audioLevelListener=new ke,t.handleOnTrackAdd=function(e){b.d(t.TAG,"ONTRACKADD",e),t.tracksToProcess.set(e.trackId,e),t.processPendingTracks()},t.handleOnTrackRemove=function(e){b.d(t.TAG,"ONTRACKREMOVE",e);var n=t.trackStateMap.get(e.trackId);if(n){var r=t.hmsPeerList.get(n.peerId);if(r){switch(e.type){case exports.HMSTrackType.AUDIO:r.audioTrack=null;break;case exports.HMSTrackType.VIDEO:var i=r.auxiliaryTracks.indexOf(e);i>-1?r.auxiliaryTracks.splice(i,1):r.videoTrack=null}t.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,e,r)}}},t.handleTrackUpdate=function(e){b.d(t.TAG,"TRACK_UPDATE",e);var n=t.hmsPeerList.get(e.peer.peer_id);if(n)for(var r=0,i=Object.entries(e.tracks);r<i.length;r++){var o,s,c=i[r],u=c[0],h=c[1],l=Object.assign({},null==(o=t.trackStateMap.get(u))?void 0:o.trackInfo),d=t.getPeerTrackByTrackId(n.peerId,u);if(!d)return;t.trackStateMap.set(u,{peerId:e.peer.peer_id,trackInfo:a({},l,h)}),l.mute!==h.mute?h.mute?(n.peerId==(null==(s=t.audioLevelListener.dominantSpeaker)?void 0:s.peerId)&&(b.d(t.TAG,"DOMINANT_SPEAKER_MUTE",n),t.listener.onPeerUpdate(exports.HMSPeerUpdate.RESIGNED_DOMINANT_SPEAKER,n)),t.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_MUTED,d,n)):t.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_UNMUTED,d,n):l.description!==h.description&&t.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_DESCRIPTION_CHANGED,d,n)}},t.cleanUp=function(){t.hmsPeerList.clear()},t.findPeerByPeerId=function(e){var n;return(null==(n=t.localPeer)?void 0:n.peerId)===e?t.localPeer:t.hmsPeerList.get(e)},t.handlePeerJoin=function(e){var n=new ve({peerId:e.peerId,name:e.info.name,isLocal:!1,customerDescription:""});t.hmsPeerList.set(e.peerId,n),b.d(t.TAG,"adding to the peerList",n),e.tracks.forEach((function(n){t.trackStateMap.set(n.track_id,{peerId:e.peerId,trackInfo:n})})),t.processPendingTracks()},t.handlePeerLeave=function(e){t.hmsPeerList.delete(e.peerId)},t.handlePeerList=function(e){var n=e.peers;null==n||n.forEach((function(e){return t.handlePeerJoin(e)}))},t}o(t,e);var n=t.prototype;return n.handleNotification=function(e,t,n){switch(this.listener=n,e){case y.PEER_JOIN:var r=t;b.d(this.TAG,"PEER_JOIN event",r,t),this.handlePeerJoin(r);break;case y.PEER_LEAVE:var i=t;b.d(this.TAG,"PEER_LEAVE event",i),this.handlePeerLeave(i);break;case y.PEER_LIST:var a=t;b.d(this.TAG,"PEER_LIST event",a),this.handlePeerList(a);break;case y.TRACK_METADATA_ADD:this.handleTrackMetadataAdd(t);break;case y.TRACK_UPDATE:this.handleTrackUpdate(t);break;case y.ROLE_CHANGE:this.handleRoleChange(t);break;case y.ACTIVE_SPEAKERS:this.handleActiveSpeakers(t);break;default:return}},n.handleRoleChange=function(e){this.dispatchEvent(new CustomEvent("role-change",{detail:{params:e}}))},n.handleTrackMetadataAdd=function(e){b.d(this.TAG,"TRACK_METADATA_ADD",e);for(var t=0,n=Object.entries(e.tracks);t<n.length;t++){var r=n[t];this.trackStateMap.set(r[0],{peerId:e.peer.peer_id,trackInfo:r[1]})}this.processPendingTracks()},n.processPendingTracks=function(){var e=this;new Map(this.tracksToProcess).forEach((function(t){var n=e.trackStateMap.get(t.trackId);if(n){var r=e.hmsPeerList.get(n.peerId);if(r){switch(t.source=n.trackInfo.source,t.type){case exports.HMSTrackType.AUDIO:r.audioTrack||(r.audioTrack=t);break;case exports.HMSTrackType.VIDEO:r.videoTrack||"regular"!==t.source?r.auxiliaryTracks.push(t):r.videoTrack=t}e.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_ADDED,t,r),e.tracksToProcess.delete(t.trackId)}}}))},n.handleActiveSpeakers=function(e){b.d(this.TAG,"ACTIVESPEAKERS",e);var t=e[0],n=this.findPeerByPeerId(t.peer_id);this.audioLevelListener.updateDominantSpeaker(t,n,this.listener)},n.getPeerTrackByTrackId=function(e,t){var n,r,i=this.findPeerByPeerId(e);return(null==i||null==(n=i.audioTrack)?void 0:n.trackId)===t?i.audioTrack:(null==i||null==(r=i.videoTrack)?void 0:r.trackId)===t?i.videoTrack:null==i?void 0:i.auxiliaryTracks.find((function(e){return e.trackId===t}))},t}(l(EventTarget)),me=function(e,t,n){this.id=e,this.name=t,this.peers=n};exports.HMSSdk=function(){function t(){var e=this;this.logLevel=v.OFF,this.analyticsLevel=k.OFF,this.TAG="[HMSSdk]:",this.notificationManager=new Ee,this.published=!1,this.publishParams=null,this.observer={onNotification:function(t){var n=function(e){switch(e){case"on-peer-join":return y.PEER_JOIN;case"on-peer-leave":return y.PEER_LEAVE;case"peer-list":return y.PEER_LIST;case"on-track-add":return y.TRACK_METADATA_ADD;case"on-track-update":return y.TRACK_UPDATE;case"active-speakers":return y.ACTIVE_SPEAKERS;case"on-broadcast":return y.BROADCAST;case"on-role-change":return y.ROLE_CHANGE;default:return b.d("method not supported - "+e),y.UNSUPPORTED}}(t.method),r=function(e,t){switch(e){case y.PEER_JOIN:case y.PEER_LEAVE:return new R(t);case y.PEER_LIST:return new S(t);case y.BROADCAST:return new x(t.info);case y.ACTIVE_SPEAKERS:return t.hasOwnProperty("speaker-list")?t["speaker-list"]:[];case y.ROLE_CHANGE:return t;case y.TRACK_METADATA_ADD:case y.TRACK_UPDATE:return t;default:return b.d("method not implemented "+e),t}}(n,t.params);e.notificationManager.handleNotification(n,r,e.listener),e.onNotificationHandled(n,r)},onTrackAdd:function(t){e.notificationManager.handleOnTrackAdd(t)},onTrackRemove:function(t){e.notificationManager.handleOnTrackRemove(t)},onFailure:function(t){var n;null==(n=e.listener)||n.onError(t)}},this.notificationManager.addEventListener("role-change",(function(t){return e.publishParams=t.detail.params.role.publishParams})),this.transport=new fe(this.observer)}var r=t.prototype;return r.join=function(t,n){var r=this;this.transport=new fe(this.observer),this.listener=n;var i=JSON.parse(atob(t.authToken.split(".")[1])).room_id,a=e.v4();this.localPeer=new ve({peerId:a,name:t.userName,isLocal:!0,customerDescription:t.metaData}),this.notificationManager.localPeer=this.localPeer,b.d(this.TAG,"⏳ Joining room "+i),this.transport.join(t.authToken,this.localPeer.peerId,{name:t.userName}).then((function(){b.d(r.TAG,"✅ Joined room "+i),r.roomId=i,r.published||r.publish()}))},r.cleanUp=function(){this.notificationManager.cleanUp(),this.published=!1,this.localPeer=null,this.roomId=null,this.hmsRoom=null,this.transport=null,this.listener=null},r.leave=function(){var e=n(T.mark((function e(){var t,n,r,i,a,o;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.roomId){e.next=9;break}return b.d(this.TAG,"⏳ Leaving room "+(o=this.roomId)),null==(t=this.localPeer)||null==(n=t.audioTrack)||n.nativeTrack.stop(),null==(r=this.localPeer)||null==(i=r.videoTrack)||i.nativeTrack.stop(),e.next=7,null==(a=this.transport)?void 0:a.leave();case 7:this.cleanUp(),b.d(this.TAG,"✅ Left room "+o);case 9:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),r.getLocalPeer=function(){return this.localPeer},r.getPeers=function(){var e=Array.from(this.notificationManager.hmsPeerList,(function(e){return e[1]})),t=this.localPeer?[].concat(e,[this.getLocalPeer()]):e;return b.d(this.TAG,"Got peers",t),t},r.sendMessage=function(e,t,n){var r=new x({sender:this.localPeer.peerId,type:e,message:t,receiver:n});return b.d(this.TAG,"Sending Message:: ",r),this.transport.sendMessage(r),r},r.startScreenShare=function(){var e=n(T.mark((function e(t){var n,r,i,a,o=this;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(((null==(n=this.localPeer)||null==(r=n.auxiliaryTracks)?void 0:r.length)||0)>0)){e.next=2;break}throw Error("Cannot share multiple screens");case 2:return e.next=4,this.transport.getLocalScreen(B.HD);case 4:return(a=e.sent).nativeTrack.onended=function(){o.stopEndedScreenshare(t)},e.next=8,this.transport.publish([a]);case 8:null==(i=this.localPeer)||i.auxiliaryTracks.push(a);case 9:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.stopEndedScreenshare=function(){var e=n(T.mark((function e(t){return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return b.d(this.TAG,"✅ Screenshare ended natively"),e.next=3,this.stopScreenShare();case 3:t();case 4:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.stopScreenShare=function(){var e=n(T.mark((function e(){var t,n;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(b.d(this.TAG,"✅ Screenshare ended from app"),!(n=null==(t=this.localPeer)?void 0:t.auxiliaryTracks.find((function(e){return e.type===exports.HMSTrackType.VIDEO&&"screen"===e.source})))){e.next=7;break}return e.next=5,n.setEnabled(!1);case 5:this.transport.unpublish([n]),this.localPeer.auxiliaryTracks.splice(this.localPeer.auxiliaryTracks.indexOf(n),1);case 7:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),r.onNotificationHandled=function(e,t){var n,r,i=this;switch(b.d(this.TAG,"onNotificationHandled",e),e){case y.PEER_JOIN:var a=t,o=this.notificationManager.findPeerByPeerId(a.peerId);o?this.listener.onPeerUpdate(exports.HMSPeerUpdate.PEER_JOINED,o):b.e(this.TAG,"⚠️ peer not found in peer-list",a,this.notificationManager.hmsPeerList);break;case y.PEER_LEAVE:var s,c,u,h,l=new ve({peerId:t.peerId,name:t.info.name,isLocal:!1,customerDescription:t.info.data});l.audioTrack&&(null==(u=this.listener)||u.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,l.audioTrack,l)),l.videoTrack&&(null==(h=this.listener)||h.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,l.videoTrack,l)),null==(s=l.auxiliaryTracks)||s.forEach((function(e){var t;null==(t=i.listener)||t.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,e,l)})),null==(c=this.listener)||c.onPeerUpdate(exports.HMSPeerUpdate.PEER_LEFT,l);break;case y.PEER_LIST:null==(n=this.listener)||n.onJoin(this.createRoom());break;case y.ROLE_CHANGE:case y.ACTIVE_SPEAKERS:break;case y.BROADCAST:var d=t;b.d(this.TAG,"Received Message:: ",d),null==(r=this.listener)||r.onMessageReceived(d)}},r.publish=function(){var e,t=this,r=this.publishParams,i=r.audio,a=r.video,o=r.allowed,s=o&&o.includes("audio"),c=o&&o.includes("video"),u=(new H).codec(i.codec).maxBitRate(i.bitrate).build(),h=(new L).codec(a.codec).maxBitRate(a.bitRate).maxFrameRate(a.frameRate).build();(s||c)&&(null==(e=this.transport)||e.getLocalTracks((new K).video(c?h:null).audio(s?u:null).build()).then(function(){var e=n(T.mark((function e(n){return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n.forEach((function(e){var n;switch(e.type){case exports.HMSTrackType.AUDIO:t.localPeer.audioTrack=e;break;case exports.HMSTrackType.VIDEO:t.localPeer.videoTrack=e}null==(n=t.listener)||n.onTrackUpdate(exports.HMSTrackUpdate.TRACK_ADDED,e,t.localPeer)})),e.next=3,t.transport.publish(n);case 3:t.published=!0;case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()))},r.createRoom=function(){var e=this.getPeers();return this.hmsRoom=new me(this.localPeer.peerId,"",e),this.hmsRoom},t}();
//# sourceMappingURL=100ms-web-sdk.cjs.production.min.js.map

@@ -30,3 +30,4 @@ import { HMSConnectionRole } from './model';

setMaxBitrate(maxBitrate: number, track: HMSTrack): Promise<void>;
trackUpdate(track: HMSTrack): void;
close(): Promise<void>;
}

@@ -20,3 +20,7 @@ import HMSException from '../error/HMSException';

AUDIO_TOGGLED = 2,
VIDEO_TOGGLED = 3
VIDEO_TOGGLED = 3,
BECAME_DOMINANT_SPEAKER = 4,
RESIGNED_DOMINANT_SPEAKER = 5,
STARTED_SPEAKING = 6,
STOPPED_SPEAKING = 7
}

@@ -23,0 +27,0 @@ export declare enum HMSTrackUpdate {

@@ -6,3 +6,3 @@ import HMSTrack from './HMSTrack';

readonly type: HMSTrackType;
constructor(stream: HMSMediaStream, track: MediaStreamTrack);
constructor(stream: HMSMediaStream, track: MediaStreamTrack, source?: string);
}

@@ -6,3 +6,3 @@ import HMSAudioTrack from './HMSAudioTrack';

private settings;
constructor(stream: HMSLocalStream, track: MediaStreamTrack, settings: HMSAudioTrackSettings);
constructor(stream: HMSLocalStream, track: MediaStreamTrack, settings: HMSAudioTrackSettings, source: string);
private replaceTrackWith;

@@ -9,0 +9,0 @@ setEnabled(value: boolean): Promise<void>;

import HMSVideoTrack from './HMSVideoTrack';
import HMSLocalStream from '../streams/HMSLocalStream';
import HMSVideoTrackSettings from '../settings/HMSVideoTrackSettings';
import { HMSVideoSourceType } from './HMSVideoSourceType';
export default class HMSLocalVideoTrack extends HMSVideoTrack {
private settings;
constructor(stream: HMSLocalStream, track: MediaStreamTrack, settings: HMSVideoTrackSettings, videoSourceType?: HMSVideoSourceType);
constructor(stream: HMSLocalStream, track: MediaStreamTrack, settings: HMSVideoTrackSettings, source: string);
private replaceTrackWith;

@@ -9,0 +8,0 @@ setEnabled(value: boolean): Promise<void>;

import HMSMediaStream from '../streams/HMSMediaStream';
import { HMSTrackType } from './HMSTrackType';
export declare type HMSTrackSource = 'regular' | 'screen' | 'plugin';
export default abstract class HMSTrack {
source?: HMSTrackSource;
abstract readonly type: HMSTrackType;

@@ -8,3 +10,3 @@ get enabled(): boolean;

setEnabled(value: boolean): Promise<void>;
protected constructor(stream: HMSMediaStream, track: MediaStreamTrack);
protected constructor(stream: HMSMediaStream, track: MediaStreamTrack, source?: HMSTrackSource);
}
export declare enum HMSTrackType {
AUDIO = 0,
VIDEO = 1
AUDIO = "audio",
VIDEO = "video"
}
import HMSTrack from './HMSTrack';
import { HMSTrackType } from './HMSTrackType';
import HMSMediaStream from '../streams/HMSMediaStream';
import { HMSVideoSourceType } from './HMSVideoSourceType';
export default class HMSVideoTrack extends HMSTrack {
readonly type: HMSTrackType;
readonly videoSourceType: HMSVideoSourceType;
constructor(stream: HMSMediaStream, track: MediaStreamTrack, videoSourceType?: HMSVideoSourceType);
constructor(stream: HMSMediaStream, track: MediaStreamTrack, source?: string);
}

@@ -13,5 +13,5 @@ import HMSConfig from '../interfaces/config';

analyticsLevel: HMSAnalyticsLevel;
transport: HMSTransport;
transport: HMSTransport | null;
roomId: string | null;
localPeer: HMSPeer;
localPeer: HMSPeer | null;
private TAG;

@@ -22,5 +22,7 @@ private notificationManager;

private published;
private publishParams;
private observer;
constructor();
join(config: HMSConfig, listener: HMSUpdateListener): void;
private cleanUp;
leave(): Promise<void>;

@@ -27,0 +29,0 @@ getLocalPeer(): HMSPeer;

@@ -5,8 +5,9 @@ export declare enum HMSNotificationMethod {

PEER_LIST = 2,
STREAM_ADD = 3,
ACTIVE_SPEAKERS = 4,
BROADCAST = 5,
ROLE_CHANGE = 6,
TRACK_ADD = 7
ACTIVE_SPEAKERS = 3,
BROADCAST = 4,
ROLE_CHANGE = 5,
TRACK_METADATA_ADD = 6,
TRACK_UPDATE = 7,
UNSUPPORTED = 8
}
export declare const getNotificationMethod: (method: string) => HMSNotificationMethod;

@@ -0,4 +1,6 @@

import HMSTrack from '../../media/tracks/HMSTrack';
import { Track } from '../../signal/ISignal';
import { HMSNotificationMethod } from './enums/HMSNotificationMethod';
import Message from './HMSMessage';
export declare type HMSNotifications = Peer | PeerList | Message | TrackStateNotification | undefined;
export declare type HMSNotifications = Peer | PeerList | Message | TrackStateNotification | Speaker[] | undefined;
export interface TrackStateNotification {

@@ -17,9 +19,10 @@ tracks: Map<string, TrackState>;

}
export interface TrackState {
export declare class TrackState implements Track {
mute: boolean;
type: string;
source: string;
type: 'audio' | 'video';
source: 'regular' | 'screen' | 'plugin';
description: string;
track_id: string;
stream_id: string;
constructor(track: HMSTrack);
}

@@ -37,2 +40,6 @@ export declare class Peer {

}
export interface Speaker {
peer_id: string;
level: number;
}
export declare const getNotification: (method: HMSNotificationMethod, params: any) => any;
import HMSTrack from '../media/tracks/HMSTrack';
import { HMSNotificationMethod } from './models/enums/HMSNotificationMethod';
import { HMSNotifications, TrackStateNotification } from './models/HMSNotifications';
import { HMSNotifications, TrackStateNotification, Speaker } from './models/HMSNotifications';
import HMSPeer from '../interfaces/hms-peer';
import HMSUpdateListener from '../interfaces/update-listener';
export default class NotificationManager {
export default class NotificationManager extends EventTarget {
hmsPeerList: Map<string, HMSPeer>;
localPeer: HMSPeer | null;
private TAG;

@@ -12,4 +13,6 @@ private tracksToProcess;

private listener;
private audioLevelListener;
handleNotification(method: HMSNotificationMethod, notification: HMSNotifications, listener: HMSUpdateListener): void;
handleTrackAdd(params: TrackStateNotification): void;
handleRoleChange(params: TrackStateNotification): void;
handleTrackMetadataAdd(params: TrackStateNotification): void;
private processPendingTracks;

@@ -24,7 +27,13 @@ /**

handleOnTrackRemove: (track: HMSTrack) => void;
handleLeave: () => void;
findPeerByUID: (uid: string) => HMSPeer | undefined;
handleTrackUpdate: (params: TrackStateNotification) => void;
cleanUp: () => void;
findPeerByPeerId: (peerId: string) => HMSPeer | undefined;
private handlePeerJoin;
private handlePeerLeave;
private handlePeerList;
/**
* @param speakersList List of speakers[peer_id, level] sorted by level in descending order.
*/
handleActiveSpeakers(speakers: Speaker[]): void;
private getPeerTrackByTrackId;
}
{
"version": "0.0.12-23",
"version": "0.0.12-3012",
"license": "UNLICENSED",

@@ -39,7 +39,7 @@ "main": "dist/index.js",

"path": "dist/100ms-web-sdk.cjs.production.min.js",
"limit": "250 KB"
"limit": "20 KB"
},
{
"path": "dist/100ms-web-sdk.esm.js",
"limit": "250 KB"
"limit": "20 KB"
}

@@ -49,9 +49,5 @@ ],

"@size-limit/preset-small-lib": "^4.10.2",
"@types/jsonwebtoken": "^8.5.1",
"@types/node": "^14.14.37",
"@types/node-fetch": "^2.5.10",
"@types/uuid": "^8.3.0",
"husky": "^6.0.0",
"jest-websocket-mock": "^2.2.0",
"mock-socket": "^9.0.3",
"prettier": "2.2.1",

@@ -64,8 +60,4 @@ "size-limit": "^4.10.2",

"dependencies": {
"jsonwebtoken": "^8.5.1",
"loglevel": "^1.7.1",
"node-fetch": "^2.6.1",
"sdp-transform": "^2.14.1",
"uuid": "^8.3.2"
}
}

@@ -5,2 +5,3 @@ import { HMSConnectionRole } from './model';

import HMSTrack from '../media/tracks/HMSTrack';
import { TrackState } from '../sdk/models/HMSNotifications';

@@ -91,2 +92,7 @@ const TAG = 'HMSConnection';

trackUpdate(track: HMSTrack) {
const trackState = new TrackState(track);
this.signal.trackUpdate(new Map([[track.trackId, trackState]]));
}
async close() {

@@ -93,0 +99,0 @@ this.nativeConnection.close();

@@ -23,2 +23,6 @@ import HMSException from '../error/HMSException';

VIDEO_TOGGLED,
BECAME_DOMINANT_SPEAKER,
RESIGNED_DOMINANT_SPEAKER,
STARTED_SPEAKING,
STOPPED_SPEAKING,
}

@@ -25,0 +29,0 @@

@@ -9,3 +9,2 @@ import HMSMediaStream from './HMSMediaStream';

import HMSLogger from '../../utils/logger';
import { HMSVideoSourceType } from '../tracks/HMSVideoSourceType';

@@ -32,3 +31,3 @@ const TAG = 'HMSLocalStream';

const nativeTrack = stream.getVideoTracks()[0];
const track = new HMSLocalVideoTrack(local, nativeTrack, settings, HMSVideoSourceType.SCREEN);
const track = new HMSLocalVideoTrack(local, nativeTrack, settings, 'screen');

@@ -50,3 +49,3 @@ HMSLogger.v(TAG, 'getLocalScreen', track);

const nativeTrack = stream.getAudioTracks()[0];
const track = new HMSLocalAudioTrack(local, nativeTrack, settings.audio);
const track = new HMSLocalAudioTrack(local, nativeTrack, settings.audio, 'regular');
tracks.push(track);

@@ -57,3 +56,3 @@ }

const nativeTrack = stream.getVideoTracks()[0];
const track = new HMSLocalVideoTrack(local, nativeTrack, settings.video);
const track = new HMSLocalVideoTrack(local, nativeTrack, settings.video, 'regular');
tracks.push(track);

@@ -66,4 +65,2 @@ }

// TODO: Add static method to get screen-share (similar to getLocalTracks)
addTransceiver(track: HMSTrack) {

@@ -120,2 +117,6 @@ // TODO: Add support for simulcast

}
trackUpdate(track: HMSTrack) {
this.connection?.trackUpdate(track);
}
}

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

import HMSTrack from './HMSTrack';
import HMSTrack, { HMSTrackSource } from './HMSTrack';
import { HMSTrackType } from './HMSTrackType';

@@ -8,6 +8,6 @@ import HMSMediaStream from '../streams/HMSMediaStream';

constructor(stream: HMSMediaStream, track: MediaStreamTrack) {
super(stream, track);
constructor(stream: HMSMediaStream, track: MediaStreamTrack, source?: string) {
super(stream, track, source as HMSTrackSource);
if (track.kind !== 'audio') throw new Error("Expected 'track' kind = 'audio'");
}
}

@@ -9,4 +9,4 @@ import HMSAudioTrack from './HMSAudioTrack';

constructor(stream: HMSLocalStream, track: MediaStreamTrack, settings: HMSAudioTrackSettings) {
super(stream, track);
constructor(stream: HMSLocalStream, track: MediaStreamTrack, settings: HMSAudioTrackSettings, source: string) {
super(stream, track, source);
stream.tracks.push(this);

@@ -25,2 +25,3 @@

await super.setEnabled(value);
(this.stream as HMSLocalStream).trackUpdate(this);
if (value) {

@@ -27,0 +28,0 @@ await this.replaceTrackWith(this.settings);

@@ -6,3 +6,2 @@ import HMSVideoTrack from './HMSVideoTrack';

import { sleep } from '../../utils/sleep';
import { HMSVideoSourceType } from './HMSVideoSourceType';

@@ -12,9 +11,4 @@ export default class HMSLocalVideoTrack extends HMSVideoTrack {

constructor(
stream: HMSLocalStream,
track: MediaStreamTrack,
settings: HMSVideoTrackSettings,
videoSourceType: HMSVideoSourceType = HMSVideoSourceType.REGULAR,
) {
super(stream, track, videoSourceType);
constructor(stream: HMSLocalStream, track: MediaStreamTrack, settings: HMSVideoTrackSettings, source: string) {
super(stream, track, source);
stream.tracks.push(this);

@@ -33,3 +27,3 @@

await super.setEnabled(value);
(this.stream as HMSLocalStream).trackUpdate(this);
if (value) {

@@ -36,0 +30,0 @@ await this.replaceTrackWith(this.settings);

import HMSMediaStream from '../streams/HMSMediaStream';
import { HMSTrackType } from './HMSTrackType';
export type HMSTrackSource = 'regular' | 'screen' | 'plugin';
export default abstract class HMSTrack {
// @internal
readonly stream: HMSMediaStream;
source?: HMSTrackSource;

@@ -28,6 +31,7 @@ /** Changes only when un-muting the local track

protected constructor(stream: HMSMediaStream, track: MediaStreamTrack) {
protected constructor(stream: HMSMediaStream, track: MediaStreamTrack, source?: HMSTrackSource) {
this.stream = stream;
this.nativeTrack = track;
this.source = source;
}
}
export enum HMSTrackType {
AUDIO,
VIDEO,
AUDIO = 'audio',
VIDEO = 'video',
}

@@ -1,19 +0,12 @@

import HMSTrack from './HMSTrack';
import HMSTrack, { HMSTrackSource } from './HMSTrack';
import { HMSTrackType } from './HMSTrackType';
import HMSMediaStream from '../streams/HMSMediaStream';
import { HMSVideoSourceType } from './HMSVideoSourceType';
export default class HMSVideoTrack extends HMSTrack {
readonly type: HMSTrackType = HMSTrackType.VIDEO;
readonly videoSourceType: HMSVideoSourceType;
constructor(
stream: HMSMediaStream,
track: MediaStreamTrack,
videoSourceType: HMSVideoSourceType = HMSVideoSourceType.REGULAR,
) {
super(stream, track);
constructor(stream: HMSMediaStream, track: MediaStreamTrack, source?: string) {
super(stream, track, source as HMSTrackSource);
if (track.kind !== 'video') throw new Error("Expected 'track' kind = 'video'");
this.videoSourceType = videoSourceType;
}
}

@@ -21,2 +21,4 @@ import HMSConfig from '../interfaces/config';

import Message from './models/HMSMessage';
import HMSVideoTrackSettings, { HMSVideoTrackSettingsBuilder } from '../media/settings/HMSVideoTrackSettings';
import HMSAudioTrackSettings, { HMSAudioTrackSettingsBuilder } from '../media/settings/HMSAudioTrackSettings';

@@ -26,17 +28,19 @@ export class HMSSdk implements HMSInterface {

analyticsLevel: HMSAnalyticsLevel = HMSAnalyticsLevel.OFF;
transport!: HMSTransport;
transport!: HMSTransport | null;
roomId!: string | null;
localPeer!: HMSPeer;
localPeer!: HMSPeer | null;
private TAG: string = '[HMSSdk]:';
private notificationManager: NotificationManager = new NotificationManager();
private listener!: HMSUpdateListener;
private hmsRoom?: HMSRoom;
private published: Boolean = false;
private listener!: HMSUpdateListener | null;
private hmsRoom?: HMSRoom | null;
private published: boolean = false;
private publishParams: any = null;
private observer: ITransportObserver = {
onNotification: (message: any) => {
const method = getNotificationMethod(message!.method);
const notification = getNotification(method, message!.params);
this.notificationManager.handleNotification(method, notification, this.listener);
const method = getNotificationMethod(message.method);
const notification = getNotification(method, message.params);
// @TODO: Notification manager needs to be refactored. The current implementation is not manageable
this.notificationManager.handleNotification(method, notification, this.listener!);
this.onNotificationHandled(method, notification);

@@ -54,3 +58,3 @@ },

onFailure: (exception: HMSException) => {
this.listener.onError(exception);
this.listener?.onError(exception);
},

@@ -60,2 +64,6 @@ };

constructor() {
this.notificationManager.addEventListener(
'role-change',
(e: any) => (this.publishParams = e.detail.params.role.publishParams),
);
this.transport = new HMSTransport(this.observer);

@@ -73,2 +81,3 @@ }

this.localPeer = new Peer({ peerId, name: config.userName, isLocal: true, customerDescription: config.metaData });
this.notificationManager.localPeer = this.localPeer;

@@ -86,11 +95,22 @@ HMSLogger.d(this.TAG, `⏳ Joining room ${roomId}`);

private cleanUp() {
this.notificationManager.cleanUp();
this.published = false;
this.localPeer = null;
this.roomId = null;
this.hmsRoom = null;
this.transport = null;
this.listener = null;
}
async leave() {
if (this.roomId) {
HMSLogger.d(this.TAG, `⏳ Leaving room ${this.roomId}`);
this.localPeer.audioTrack?.nativeTrack.stop();
this.localPeer.videoTrack?.nativeTrack.stop();
this.notificationManager.handleLeave();
this.transport.leave();
HMSLogger.d(this.TAG, `✅ Left room ${this.roomId}`);
this.roomId = null;
const roomId = this.roomId;
HMSLogger.d(this.TAG, `⏳ Leaving room ${roomId}`);
this.localPeer?.audioTrack?.nativeTrack.stop();
this.localPeer?.videoTrack?.nativeTrack.stop();
await this.transport?.leave();
this.cleanUp();
HMSLogger.d(this.TAG, `✅ Left room ${roomId}`);
}

@@ -100,3 +120,3 @@ }

getLocalPeer(): HMSPeer {
return this.localPeer;
return this.localPeer!;
}

@@ -106,3 +126,3 @@

const remotePeers = Array.from(this.notificationManager.hmsPeerList, (x) => x[1]);
const peers = [...remotePeers, this.getLocalPeer()];
const peers = this.localPeer ? [...remotePeers, this.getLocalPeer()] : remotePeers;
HMSLogger.d(this.TAG, `Got peers`, peers);

@@ -113,5 +133,5 @@ return peers;

sendMessage(type: string, message: string, receiver?: string) {
const hmsMessage = new Message({ sender: this.localPeer.peerId, type, message, receiver });
const hmsMessage = new Message({ sender: this.localPeer!.peerId, type, message, receiver });
HMSLogger.d(this.TAG, 'Sending Message:: ', hmsMessage);
this.transport.sendMessage(hmsMessage);
this.transport!.sendMessage(hmsMessage);
return hmsMessage;

@@ -123,12 +143,12 @@ }

if ((this.localPeer.auxiliaryTracks?.length || 0) > 0) {
if ((this.localPeer?.auxiliaryTracks?.length || 0) > 0) {
throw Error('Cannot share multiple screens');
}
const track = await this.transport.getLocalScreen(DefaultVideoSettings.HD);
const track = await this.transport!.getLocalScreen(DefaultVideoSettings.HD);
track.nativeTrack.onended = () => {
this.stopEndedScreenshare(onStop);
};
await this.transport.publish([track]);
this.localPeer.auxiliaryTracks = [track];
await this.transport!.publish([track]);
this.localPeer?.auxiliaryTracks.push(track);
}

@@ -143,8 +163,9 @@

async stopScreenShare() {
// TODO: Right now we assume for now that there is only one aux track -- screen-share
HMSLogger.d(this.TAG, `✅ Screenshare ended from app`);
const track = this.localPeer.auxiliaryTracks![0];
await track.setEnabled(false);
this.transport.unpublish([track]);
this.localPeer.auxiliaryTracks!.length = 0;
const track = this.localPeer?.auxiliaryTracks.find((t) => t.type === HMSTrackType.VIDEO && t.source === 'screen');
if (track) {
await track.setEnabled(false);
this.transport!.unpublish([track]);
this.localPeer!.auxiliaryTracks.splice(this.localPeer!.auxiliaryTracks.indexOf(track), 1);
}
}

@@ -154,11 +175,11 @@

HMSLogger.d(this.TAG, 'onNotificationHandled', method);
let peer, hmsPeer;
switch (method) {
case HMSNotificationMethod.PEER_JOIN:
peer = notification as PeerNotification;
hmsPeer = this.notificationManager.findPeerByUID(peer.peerId);
case HMSNotificationMethod.PEER_JOIN: {
const peer = notification as PeerNotification;
const hmsPeer = this.notificationManager.findPeerByPeerId(peer.peerId);
hmsPeer
? this.listener.onPeerUpdate(HMSPeerUpdate.PEER_JOINED, hmsPeer!)
? this.listener!.onPeerUpdate(HMSPeerUpdate.PEER_JOINED, hmsPeer)
: HMSLogger.e(this.TAG, `⚠️ peer not found in peer-list`, peer, this.notificationManager.hmsPeerList);
break;
}

@@ -175,14 +196,14 @@ case HMSNotificationMethod.PEER_LEAVE: {

if (hmsPeer.audioTrack) {
this.listener.onTrackUpdate(HMSTrackUpdate.TRACK_REMOVED, hmsPeer.audioTrack, hmsPeer);
this.listener?.onTrackUpdate(HMSTrackUpdate.TRACK_REMOVED, hmsPeer.audioTrack, hmsPeer);
}
if (hmsPeer.videoTrack) {
this.listener.onTrackUpdate(HMSTrackUpdate.TRACK_REMOVED, hmsPeer.videoTrack, hmsPeer);
this.listener?.onTrackUpdate(HMSTrackUpdate.TRACK_REMOVED, hmsPeer.videoTrack, hmsPeer);
}
hmsPeer.auxiliaryTracks?.forEach((track) => {
this.listener.onTrackUpdate(HMSTrackUpdate.TRACK_REMOVED, track, hmsPeer);
this.listener?.onTrackUpdate(HMSTrackUpdate.TRACK_REMOVED, track, hmsPeer);
});
this.listener.onPeerUpdate(HMSPeerUpdate.PEER_LEFT, hmsPeer);
this.listener?.onPeerUpdate(HMSPeerUpdate.PEER_LEFT, hmsPeer);
break;

@@ -192,18 +213,16 @@ }

case HMSNotificationMethod.PEER_LIST:
this.listener.onJoin(this.createRoom());
this.listener?.onJoin(this.createRoom());
break;
case HMSNotificationMethod.ROLE_CHANGE:
if (this.roomId) {
this.publish();
}
break;
case HMSNotificationMethod.ACTIVE_SPEAKERS:
break;
case HMSNotificationMethod.STREAM_ADD:
return;
case HMSNotificationMethod.ACTIVE_SPEAKERS:
return;
case HMSNotificationMethod.BROADCAST:
const message = notification as Message;
HMSLogger.d(this.TAG, `Received Message:: `, message);
this.listener.onMessageReceived(message);
this.listener?.onMessageReceived(message);
break;
}

@@ -213,15 +232,39 @@ }

private publish() {
this.transport.getLocalTracks(new HMSTrackSettingsBuilder().build()).then(async (hmsTracks) => {
hmsTracks.forEach((hmsTrack) => {
switch (hmsTrack.type) {
case HMSTrackType.AUDIO:
this.localPeer.audioTrack = hmsTrack;
break;
case HMSTrackType.VIDEO:
this.localPeer.videoTrack = hmsTrack;
}
});
await this.transport.publish(hmsTracks);
this.published = true;
});
const { audio, video, allowed } = this.publishParams;
const canPublishAudio = allowed && allowed.includes('audio');
const canPublishVideo = allowed && allowed.includes('video');
const audioSettings: HMSAudioTrackSettings = new HMSAudioTrackSettingsBuilder()
.codec(audio.codec)
.maxBitRate(audio.bitrate)
.build();
const videoSettings: HMSVideoTrackSettings = new HMSVideoTrackSettingsBuilder()
.codec(video.codec)
.maxBitRate(video.bitRate)
.maxFrameRate(video.frameRate)
.build();
if (canPublishAudio || canPublishVideo) {
this.transport
?.getLocalTracks(
new HMSTrackSettingsBuilder()
.video(canPublishVideo ? videoSettings : null)
.audio(canPublishAudio ? audioSettings : null)
.build(),
)
.then(async (hmsTracks) => {
hmsTracks.forEach((hmsTrack) => {
switch (hmsTrack.type) {
case HMSTrackType.AUDIO:
this.localPeer!.audioTrack = hmsTrack;
break;
case HMSTrackType.VIDEO:
this.localPeer!.videoTrack = hmsTrack;
}
this.listener?.onTrackUpdate(HMSTrackUpdate.TRACK_ADDED, hmsTrack, this.localPeer!);
});
await this.transport!.publish(hmsTracks);
this.published = true;
});
}
}

@@ -231,5 +274,5 @@

const hmsPeerList = this.getPeers();
this.hmsRoom = new HMSRoom(this.localPeer.peerId, '', hmsPeerList);
this.hmsRoom = new HMSRoom(this.localPeer!.peerId, '', hmsPeerList);
return this.hmsRoom;
}
}

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

import HMSLogger from '../../../utils/logger';
export enum HMSNotificationMethod {

@@ -5,7 +7,8 @@ PEER_JOIN,

PEER_LIST,
STREAM_ADD,
ACTIVE_SPEAKERS,
BROADCAST,
ROLE_CHANGE,
TRACK_ADD,
TRACK_METADATA_ADD,
TRACK_UPDATE,
UNSUPPORTED,
}

@@ -21,6 +24,6 @@

return HMSNotificationMethod.PEER_LIST;
case 'stream-add':
return HMSNotificationMethod.STREAM_ADD;
case 'on-track-add':
return HMSNotificationMethod.TRACK_ADD;
return HMSNotificationMethod.TRACK_METADATA_ADD;
case 'on-track-update':
return HMSNotificationMethod.TRACK_UPDATE;
case 'active-speakers':

@@ -33,4 +36,5 @@ return HMSNotificationMethod.ACTIVE_SPEAKERS;

default:
throw Error(`Unsupported method=${method} received`);
HMSLogger.d(`method not supported - ${method}`);
return HMSNotificationMethod.UNSUPPORTED;
}
};

@@ -0,5 +1,8 @@

import HMSTrack from '../../media/tracks/HMSTrack';
import { Track } from '../../signal/ISignal';
import HMSLogger from '../../utils/logger';
import { HMSNotificationMethod } from './enums/HMSNotificationMethod';
import Message from './HMSMessage';
export type HMSNotifications = Peer | PeerList | Message | TrackStateNotification | undefined;
export type HMSNotifications = Peer | PeerList | Message | TrackStateNotification | Speaker[] | undefined;

@@ -22,9 +25,18 @@ export interface TrackStateNotification {

export interface TrackState {
export class TrackState implements Track {
mute: boolean;
type: string;
source: string;
type: 'audio' | 'video';
source: 'regular' | 'screen' | 'plugin';
description: string;
track_id: string;
stream_id: string;
constructor(track: HMSTrack) {
this.mute = !track.enabled;
this.type = track.type;
this.source = track.source || 'regular';
this.description = '';
this.track_id = track.trackId;
this.stream_id = track.stream.id;
}
}

@@ -58,2 +70,7 @@

export interface Speaker {
peer_id: string;
level: number;
}
export const getNotification = (method: HMSNotificationMethod, params: any) => {

@@ -70,11 +87,13 @@ switch (method) {

case HMSNotificationMethod.ACTIVE_SPEAKERS:
return;
return (params.hasOwnProperty('speaker-list') ? params['speaker-list'] : []) as Speaker[];
case HMSNotificationMethod.ROLE_CHANGE:
return params as TrackStateNotification;
case HMSNotificationMethod.TRACK_ADD: {
case HMSNotificationMethod.TRACK_METADATA_ADD:
case HMSNotificationMethod.TRACK_UPDATE: {
return params;
}
default:
throw Error(`Unsupported method=${method} received`);
HMSLogger.d(`method not implemented ${method}`);
return params;
}
};

@@ -11,6 +11,8 @@ import HMSTrack from '../media/tracks/HMSTrack';

TrackState,
Speaker,
} from './models/HMSNotifications';
import HMSLogger from '../utils/logger';
import HMSPeer from '../interfaces/hms-peer';
import HMSUpdateListener, { HMSTrackUpdate } from '../interfaces/update-listener';
import HMSUpdateListener, { HMSPeerUpdate, HMSTrackUpdate } from '../interfaces/update-listener';
import { HMSAudioLevelListener } from './HMSAudioLevelListener';

@@ -22,4 +24,5 @@ interface TrackStateEntry {

export default class NotificationManager {
export default class NotificationManager extends EventTarget {
hmsPeerList: Map<string, HMSPeer> = new Map();
localPeer!: HMSPeer | null;

@@ -30,2 +33,3 @@ private TAG: string = '[Notification Manager]:';

private listener!: HMSUpdateListener;
private audioLevelListener = new HMSAudioLevelListener();

@@ -53,8 +57,17 @@ handleNotification(method: HMSNotificationMethod, notification: HMSNotifications, listener: HMSUpdateListener) {

}
case HMSNotificationMethod.TRACK_ADD: {
this.handleTrackAdd(notification as TrackStateNotification);
case HMSNotificationMethod.TRACK_METADATA_ADD: {
this.handleTrackMetadataAdd(notification as TrackStateNotification);
break;
}
case HMSNotificationMethod.TRACK_UPDATE: {
this.handleTrackUpdate(notification as TrackStateNotification);
break;
}
case HMSNotificationMethod.ROLE_CHANGE: {
this.handleRoleChange(notification as TrackStateNotification);
break;
}
case HMSNotificationMethod.ACTIVE_SPEAKERS:
return;
this.handleActiveSpeakers(notification as Speaker[]);
break;
default:

@@ -65,5 +78,10 @@ return;

handleTrackAdd(params: TrackStateNotification) {
HMSLogger.d(this.TAG, `BIZ:ONTRACKADD`, params);
handleRoleChange(params: TrackStateNotification) {
// @DISCUSS: Make everything event based instead?
this.dispatchEvent(new CustomEvent('role-change', { detail: { params } }));
}
handleTrackMetadataAdd(params: TrackStateNotification) {
HMSLogger.d(this.TAG, `TRACK_METADATA_ADD`, params);
for (const [trackId, trackEntry] of Object.entries(params.tracks)) {

@@ -89,8 +107,18 @@ this.trackStateMap.set(trackId, {

track.source = state.trackInfo.source;
switch (track.type) {
case HMSTrackType.AUDIO:
hmsPeer.audioTrack = track;
if (!hmsPeer.audioTrack) {
hmsPeer.audioTrack = track;
}
// @DISCUSS: Do we have auxilliary audio tracks too?
break;
case HMSTrackType.VIDEO:
hmsPeer.videoTrack = track;
if (!hmsPeer.videoTrack && track.source === 'regular') {
hmsPeer.videoTrack = track;
} else {
hmsPeer.auxiliaryTracks.push(track);
}
}

@@ -143,8 +171,46 @@

handleLeave = () => {
handleTrackUpdate = (params: TrackStateNotification) => {
HMSLogger.d(this.TAG, `TRACK_UPDATE`, params);
const hmsPeer = this.hmsPeerList.get(params.peer.peer_id);
if (!hmsPeer) return;
for (const [trackId, trackEntry] of Object.entries(params.tracks)) {
const currentTrackStateInfo = Object.assign({}, this.trackStateMap.get(trackId)?.trackInfo);
const track = this.getPeerTrackByTrackId(hmsPeer.peerId, trackId);
if (!track) return;
this.trackStateMap.set(trackId, {
peerId: params.peer.peer_id,
trackInfo: { ...currentTrackStateInfo, ...trackEntry },
});
if (currentTrackStateInfo.mute !== trackEntry.mute) {
if (trackEntry.mute) {
// If dominant speaker is muted, resign dominant speaker.
if (hmsPeer.peerId == this.audioLevelListener.dominantSpeaker?.peerId) {
HMSLogger.d(this.TAG, 'DOMINANT_SPEAKER_MUTE', hmsPeer);
this.listener.onPeerUpdate(HMSPeerUpdate.RESIGNED_DOMINANT_SPEAKER, hmsPeer);
}
this.listener.onTrackUpdate(HMSTrackUpdate.TRACK_MUTED, track, hmsPeer);
} else {
this.listener.onTrackUpdate(HMSTrackUpdate.TRACK_UNMUTED, track, hmsPeer);
}
} else if (currentTrackStateInfo.description !== trackEntry.description) {
this.listener.onTrackUpdate(HMSTrackUpdate.TRACK_DESCRIPTION_CHANGED, track, hmsPeer);
}
}
};
cleanUp = () => {
this.hmsPeerList.clear();
};
findPeerByUID = (uid: string) => {
return this.hmsPeerList.get(uid);
findPeerByPeerId = (peerId: string) => {
if (this.localPeer?.peerId === peerId) {
return this.localPeer;
}
return this.hmsPeerList.get(peerId);
};

@@ -181,2 +247,24 @@

};
/**
* @param speakersList List of speakers[peer_id, level] sorted by level in descending order.
*/
handleActiveSpeakers(speakers: Speaker[]) {
HMSLogger.d(this.TAG, `ACTIVESPEAKERS`, speakers);
const dominantSpeaker = speakers[0];
const dominantSpeakerPeer = this.findPeerByPeerId(dominantSpeaker.peer_id);
this.audioLevelListener.updateDominantSpeaker(dominantSpeaker, dominantSpeakerPeer!, this.listener);
}
private getPeerTrackByTrackId(peerId: string, trackId: string) {
const peer = this.findPeerByPeerId(peerId);
if (peer?.audioTrack?.trackId === trackId) {
return peer.audioTrack;
} else if (peer?.videoTrack?.trackId === trackId) {
return peer.videoTrack;
} else {
return peer?.auxiliaryTracks.find((track) => track.trackId === trackId);
}
}
}

@@ -18,4 +18,4 @@ import { InitConfig } from './models';

const config = (await response.json()) as InitConfig;
return {...config, endpoint: 'wss://100ms-grpc.100ms.live:8443/ws'};
return config;
}
}

@@ -78,3 +78,3 @@ import { v4 as uuid } from 'uuid';

const params = { name, data, offer };
const response = (await this.call('join', params)) as RTCSessionDescriptionInit;
const response: RTCSessionDescriptionInit = await this.call('join', params);

@@ -98,11 +98,7 @@ this.isJoinCompleted = true;

async offer(desc: RTCSessionDescriptionInit, tracks: Map<string, any>): Promise<RTCSessionDescriptionInit> {
try {
const response = await this.call('offer', {
desc,
tracks,
});
return response as RTCSessionDescriptionInit;
} catch (e) {
throw e;
}
const response = await this.call('offer', {
desc,
tracks,
});
return response as RTCSessionDescriptionInit;
}

@@ -115,3 +111,4 @@

trackUpdate(tracks: Map<string, Track>) {
HMSLogger.d('Yet to implement', String(tracks));
HMSLogger.d(this.TAG, 'Track Update: ', { tracks: Object.fromEntries(tracks) });
this.notify('track-update', { version: '1.0', tracks: Object.fromEntries(tracks) });
}

@@ -128,3 +125,5 @@

leave() {}
leave() {
this.notify('leave', { version: '1.0' });
}

@@ -131,0 +130,0 @@ analytics() {}

@@ -21,3 +21,2 @@ import ITransportObserver from './ITransportObserver';

import HMSMessage from '../interfaces/message';
import HMSVideoTrack from '../media/tracks/HMSVideoTrack';
import { HMSTrackType } from '../media/tracks';

@@ -97,4 +96,3 @@

onApiChannelMessage: (message: string) => {
const data = { method: 'active-speakers', params: JSON.parse(message) };
this.observer.onNotification(data);
this.observer.onNotification(JSON.parse(message));
},

@@ -152,5 +150,5 @@

for (const candidate of this.publishConnection.candidates) {
await this.publishConnection!.addIceCandidate(candidate);
await this.publishConnection.addIceCandidate(candidate);
}
this.publishConnection!.initAfterJoin();
this.publishConnection.initAfterJoin();
HMSLogger.d(TAG, '✅ join: Negotiated over PUBLISH connection');

@@ -165,2 +163,3 @@

await this.subscribeConnection!.close();
this.signal.leave();
await this.signal.close();

@@ -174,3 +173,3 @@ }

type: track.nativeTrack.kind,
source: track.nativeTrack.kind === 'audio' ? 'regular' : (track as HMSVideoTrack).videoSourceType,
source: track.source,
description: '',

@@ -177,0 +176,0 @@ track_id: track.trackId,

@@ -1,8 +0,5 @@

import jwt from 'jsonwebtoken';
function getRoomId(token: string) {
const decoded = jwt.decode(token, { json: true });
return decoded!.room_id;
return JSON.parse(atob(token.split('.')[1])).room_id;
}
export { getRoomId };

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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