@100mslive/100ms-web-sdk
Advanced tools
Comparing version 0.0.12-30 to 0.0.12-31
@@ -1,2 +0,2 @@ | ||
"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 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 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 l(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,m,E=(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 d?t:d).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 d(){}function l(){}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 m=p.prototype=d.prototype=Object.create(f);function E(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,d=h.value;return d&&"object"==typeof d&&n.call(d,"__await")?t.resolve(d.__await).then((function(e){r("next",e,o,s)}),(function(e){r("throw",e,o,s)})):t.resolve(d).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 l.prototype=m.constructor=p,p.constructor=l,l.displayName=s(p,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,p):(e.__proto__=p,s(e,o,"GeneratorFunction")),e.prototype=Object.create(m),e},e.awrap=function(e){return{__await:e}},E(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()}))},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=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.INFO=2]="INFO",e[e.VERBOSE=3]="VERBOSE"}(v||(v={})),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"}(k||(k={}));var T=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,[k.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,[k.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,[k.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,[k.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,[k.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 k.VERBOSE:var a;(a=console).log.apply(a,[t].concat(r));break;case k.DEBUG:var o;(o=console).debug.apply(o,[t].concat(r));break;case k.INFO:var s;(s=console).info.apply(s,[t].concat(r));break;case k.WARN:var c;(c=console).warn.apply(c,[t].concat(r));break;case k.ERROR:var u;(u=console).error.apply(u,[t].concat(r))}}},e}();T.level=k.VERBOSE;var y,g="HMSConnection",b=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(E.mark((function e(t){var n;return E.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,T.d(g,"[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(E.mark((function e(t){var n;return E.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,T.d(g,"[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(E.mark((function e(t){return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return T.d(g,"[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(E.mark((function e(t){return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,T.d(g,"[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(E.mark((function e(t){return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return T.d(g,"[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(E.mark((function e(t,n){var r,i;return E.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=n(E.mark((function e(){return E.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"}(y||(y={}));var w,x=function(e){function t(t,n,r,i){var a;return(a=e.call(this,y.PUBLISH,t)||this).observer=r,a.transport=i,a.nativeConnection=new RTCPeerConnection(n),a.nativeConnection.createDataChannel("ion-sfu",{protocol:"SCTP"}),a.nativeConnection.onicecandidate=function(e){var n=e.candidate;n&&t.trickle(a.role,n)},a.nativeConnection.oniceconnectionstatechange=function(){a.observer.onIceConnectionChange(a.nativeConnection.iceConnectionState)},a}o(t,e);var r=t.prototype;return r.initAfterJoin=function(){var e=this;this.nativeConnection.onnegotiationneeded=n(E.mark((function t(){return E.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return T.d("HMSPublishConnection","onnegotiationneeded"),t.next=3,e.observer.onRenegotiationNeeded();case 3:case"end":return t.stop()}}),t)})))},r.trackUpdate=function(e){this.transport.trackUpdate(e)},t}(b),A=function(e){this.tracks=new Array,this.nativeStream=e,this.id=e.id};!function(e){e.NONE="none",e.LOW="low",e.MEDIUM="medium",e.HIGH="high"}(w||(w={}));var S,R=function(e){function t(t,n){var r;return(r=e.call(this,t)||this).audio=!0,r.video=w.HIGH,r.frameRate=w.HIGH,r.connection=n,r}o(t,e);var r=t.prototype;return r.setAudio=function(){var e=n(E.mark((function e(t){return E.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(E.mark((function e(t){return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.video=t,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(E.mark((function e(){var t,n;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n={streamId:this.nativeStream.id,video:this.video,audio:this.audio,framerate:this.frameRate},e.next=3,null==(t=this.connection.apiChannel)?void 0:t.send(JSON.stringify(n));case 3:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),t}(A),_=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){T.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(E.mark((function e(t){return E.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:T.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}(),C=function(){function e(e,t,n){this.stream=e,this.nativeTrack=t,this.source=n}return e.prototype.setEnabled=function(){var e=n(E.mark((function e(t){return E.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}();(S=exports.HMSTrackType||(exports.HMSTrackType={})).AUDIO="audio",S.VIDEO="video";var P=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}(C),I=function(e){function t(){return e.apply(this,arguments)||this}return o(t,e),t.prototype.setEnabled=function(){var t=n(E.mark((function t(n){return E.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}(P),O=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}o(t,e);var n=t.prototype;return n.addSink=function(e){e.srcObject=new MediaStream([this.nativeTrack])},n.removeSink=function(e){e.srcObject=null},t}(C),D=function(e){function t(){return e.apply(this,arguments)||this}o(t,e);var r=t.prototype;return r.setEnabled=function(){var t=n(E.mark((function t(n){var r;return E.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 r=n?w.HIGH:w.NONE,t.next=7,this.preferLayer(r);case 7:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.preferLayer=function(){var e=n(E.mark((function e(t){return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.stream.setVideo(t);case 2:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.addSink=function(){var t=n(E.mark((function t(n){return E.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.preferLayer(w.HIGH);case 2:e.prototype.addSink.call(this,n);case 3:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.removeSink=function(){var t=n(E.mark((function t(n){return E.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.preferLayer(w.NONE);case 2:e.prototype.removeSink.call(this,n);case 3:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),t}(O),M=function(e){function t(t,n,r){var i;return(i=e.call(this,y.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 _(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 R(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?I:D)(i,t.track);i.tracks.push(a),e.observer.onTrackAdd(a)}},r.close=function(){var t=n(E.mark((function t(){var n;return E.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}(b),L=function(){function e(){}return e.fetchInitConfig=function(){var e=n(E.mark((function e(t,n,r){var i,a;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===n&&(n="https://qa-init.100ms.live/init"),void 0===r&&(r=""),T.d("InitService","fetchInitConfig: initEndpoint="+n+" token="+t+" region="+r),i=n+"?token="+t,r.length>0&&(i+="®ion="+r),e.next=7,fetch(i);case 7:return a=e.sent,e.next=10,a.json();case 10:return e.abrupt("return",e.sent);case 12:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),e}(),N=function(){function e(e,t){this.code=e,this.message=t}return e.prototype.build=function(){return new U(this.code,this.message)},e}(),U=function(e){function t(t,n){var r;return(r=e.call(this,n)||this).code=t,r}return o(t,e),t}(d(Error)),H=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(E.mark((function t(n,r){var i,a=this;return E.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(E.mark((function e(){var t,n=this;return E.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(E.mark((function e(t,n,r,i){var a,o,s=this;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a={name:t,disableVidAutoSub:i,data:n,offer:r},e.next=3,this.call("join",a);case 3:return o=e.sent,this.isJoinCompleted=!0,this.pendingTrickle.forEach((function(e){return s.trickle(e.target,e.candidate)})),this.pendingTrickle.length=0,T.d(this.TAG,"join: response="+JSON.stringify(o,null,1)),e.abrupt("return",o);case 9:case"end":return e.stop()}}),e,this)})));return function(t,n,r,i){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(E.mark((function e(t,n){return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.call("offer",{desc:t,tracks:Object.fromEntries(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){T.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 N(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 G(e){return B.apply(this,arguments)}function B(){return(B=n(E.mark((function e(t){return E.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 K(e){return j.apply(this,arguments)}function j(){return(j=n(E.mark((function e(t){return E.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)}function V(e){var t,n,r,i=(null==e||null==(t=e.getSettings())?void 0:t.width)||640,a=(null==e||null==(n=e.getSettings())?void 0:n.height)||360,o=Object.assign(document.createElement("canvas"),{width:i,height:a});null==(r=o.getContext("2d"))||r.fillRect(0,0,i,a);var s=o.captureStream().getVideoTracks()[0];return s.enabled=!1,s}var F,J,W=function(e){function t(t,n,r,i){var a;return a=e.call(this,t,n,i)||this,t.tracks.push(l(a)),a.settings=r,a}o(t,e);var r=t.prototype;return r.replaceTrackWith=function(){var e=n(E.mark((function e(t){var n,r;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.nativeTrack,e.next=3,G(t);case 3:return r=e.sent,e.next=6,this.stream.replaceTrack(this,r);case 6:null==n||n.stop();case 7:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.setEnabled=function(){var t=n(E.mark((function t(n){return E.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:this.stream.trackUpdate(this);case 5:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.setSettings=function(){var e=n(E.mark((function e(t){return E.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}(P),Y=function(e){function t(t,n,r,i){var a;return a=e.call(this,t,n,i)||this,t.tracks.push(l(a)),a.settings=r,a}o(t,e);var r=t.prototype;return r.replaceTrackWith=function(){var e=n(E.mark((function e(t){var n,r;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.nativeTrack,e.next=3,K(t);case 3:return r=e.sent,e.next=6,this.stream.replaceTrack(this,r);case 6:null==n||n.stop();case 7:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.replaceTrackWithBlackness=function(){var e=n(E.mark((function e(){var t,n;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=V(t=this.nativeTrack),e.next=4,this.stream.replaceTrack(this,n);case 4:null==t||t.stop();case 5:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),r.setEnabled=function(){var t=n(E.mark((function t(n){return E.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=12;break;case 10:return t.next=12,this.replaceTrackWithBlackness();case 12:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.setSettings=function(){var e=n(E.mark((function e(t){return E.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}(O),q=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(E.mark((function e(n){var r,i,a,o,s;return E.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 Y(a,o,n,"screen"),T.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(E.mark((function e(n){var r,i,a,o,s,c,u;return E.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 W(i,o,n.audio,"regular"),a.push(s)),null!=n.video&&(c=r.getVideoTracks()[0],u=new Y(i,c,n.video,"regular"),a.push(u)),T.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(E.mark((function e(t,n){var r;return E.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(E.mark((function e(t,n){var r;return E.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.addTrack(n),this.nativeStream.removeTrack(t.nativeTrack),r.track.stop(),e.next=8,r.replaceTrack(n);case 8: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}(A);!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"}(F||(F={})),function(e){e.CHAT="chat"}(J||(J={}));var z,$,Q,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 J.CHAT;switch(e){case"chat":return J.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},Z=function(e,t,n){this.audioLevel=0,this.peerId=e,this.trackId=t,this.audioLevel=n},ee=function(e){this.speakers=[],e&&e.length>0&&(this.speakers=e.map((function(e){return new Z(e.peer_id,e.track_id,e.level)})))},te=function(e){this.type=e.type,this.source=e.source||"regular",this.description="",e instanceof C?(this.mute=!e.enabled,this.track_id=e.trackId,this.stream_id=e.stream.id):(this.mute=e.mute,this.track_id=e.track_id,this.stream_id=e.stream_id)},ne=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||{})},re=function(e){this.peers=Object.values(e.peers).map((function(e){return new ne(e)}))},ie="[HMSTransport]:",ae=function(){function e(e){var t,r,i,a=this;this.tracks=new Map,this.publishConnection=null,this.subscribeConnection=null,this.callbacks=new Map,this.signalObserver={onOffer:(r=n(E.mark((function e(t){var n,r,i,o;return E.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(E.mark((function e(t){var n;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!==(n=t.target===y.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 H(this.signalObserver),this.publishConnectionObserver={onRenegotiationNeeded:(i=n(E.mark((function e(){var t,n,r;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return T.d(ie,"⏳ [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),T.d(ie,"✅ [role=PUBLISH] onRenegotiationNeeded DONE",a.tracks),e.next=21;break;case 18:e.prev=18,e.t0=e.catch(3),console.error(ie,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(E.mark((function e(t){return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,q.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(E.mark((function e(t){return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,q.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(E.mark((function e(t,n,r,i,a){var o,s,c,u,h,d;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===a&&(a=!0),e.next=3,L.fetchInitConfig(t,i);case 3:return T.d(ie,"⏳ join: connecting to ws endpoint",(o=e.sent).endpoint),e.next=7,this.signal.open(o.endpoint+"?peer="+n+"&token="+t);case 7:return T.d(ie,"✅ join: connected to ws endpoint"),T.d(ie,r),this.publishConnection=new x(this.signal,o.rtcConfiguration,this.publishConnectionObserver,this),this.subscribeConnection=new M(this.signal,o.rtcConfiguration,this.subscribeConnectionObserver),T.d(ie,"⏳ join: Negotiating over PUBLISH connection"),e.next=14,this.publishConnection.createOffer();case 14:return s=e.sent,e.next=17,this.publishConnection.setLocalDescription(s);case 17:return e.next=19,this.signal.join(r.name,n,s,!a);case 19:return c=e.sent,e.next=22,this.publishConnection.setRemoteDescription(c);case 22:u=f(this.publishConnection.candidates);case 23:if((h=u()).done){e.next=29;break}return d=h.value,e.next=27,this.publishConnection.addIceCandidate(d);case 27:e.next=23;break;case 29:this.publishConnection.initAfterJoin(),T.d(ie,"✅ join: Negotiated over PUBLISH connection"),T.d(ie,"✅ join: successful");case 32:case"end":return e.stop()}}),e,this)})));return function(t,n,r,i,a){return e.apply(this,arguments)}}(),t.leave=function(){var e=n(E.mark((function e(){return E.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(E.mark((function e(t){var n,r,i,a=this;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return T.d(ie,"⏳ publishTrack: trackId="+t.trackId,t),this.tracks.set(t.trackId,new te(t)),n=new Promise((function(e,t){a.callbacks.set("renegotiation-callback-id",{resolve:e,reject:t})})),(r=t.stream).setConnection(this.publishConnection),r.addTransceiver(t),e.next=8,n;case 8:return i=t.settings.maxBitRate,e.next=11,r.setMaxBitrate(1e3*i,t).then((function(){T.i(ie,"Setting maxBitrate for "+t.source+" "+t.type+" to "+i+" kpbs")})).catch((function(e){return T.e(ie,"Failed setting maxBitrate",e)}));case 11:T.d(ie,"✅ publishTrack: trackId="+t.trackId,this.callbacks);case 12:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.unpublishTrack=function(){var e=n(E.mark((function e(t){var n,r=this;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return T.d(ie,"⏳ unpublishTrack: trackId="+t.trackId,t),this.tracks.delete(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:T.d(ie,"✅ 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(E.mark((function e(t){var n,r,i;return E.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(E.mark((function e(t){var n,r,i;return E.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)},t.trackUpdate=function(e){var t=Array.from(this.tracks.values()).find((function(t){return e.type===t.type&&e.source===t.source}));if(t){var n=new te(a({},t,{mute:!e.enabled}));this.tracks.set(t.track_id,n),T.d(ie,"Track Update",this.tracks,e),this.signal.trackUpdate(new Map([[t.track_id,n]]))}},e}();(z=exports.HMSRoomUpdate||(exports.HMSRoomUpdate={}))[z.PEER_ADDED=0]="PEER_ADDED",z[z.PEER_REMOVED=1]="PEER_REMOVED",z[z.PEER_KNOCKED=2]="PEER_KNOCKED",z[z.ROOM_TYPE_CHANGED=3]="ROOM_TYPE_CHANGED",z[z.METADATA_UPDATED=4]="METADATA_UPDATED",z[z.SCREENSHARE_STARTED=5]="SCREENSHARE_STARTED",z[z.SCREENSHARE_STOPPED=6]="SCREENSHARE_STOPPED",z[z.DEFAULT_UPDATE=7]="DEFAULT_UPDATE",($=exports.HMSPeerUpdate||(exports.HMSPeerUpdate={}))[$.PEER_JOINED=0]="PEER_JOINED",$[$.PEER_LEFT=1]="PEER_LEFT",$[$.AUDIO_TOGGLED=2]="AUDIO_TOGGLED",$[$.VIDEO_TOGGLED=3]="VIDEO_TOGGLED",$[$.BECAME_DOMINANT_SPEAKER=4]="BECAME_DOMINANT_SPEAKER",$[$.RESIGNED_DOMINANT_SPEAKER=5]="RESIGNED_DOMINANT_SPEAKER",$[$.STARTED_SPEAKING=6]="STARTED_SPEAKING",$[$.STOPPED_SPEAKING=7]="STOPPED_SPEAKING",(Q=exports.HMSTrackUpdate||(exports.HMSTrackUpdate={}))[Q.TRACK_ADDED=0]="TRACK_ADDED",Q[Q.TRACK_REMOVED=1]="TRACK_REMOVED",Q[Q.TRACK_MUTED=2]="TRACK_MUTED",Q[Q.TRACK_UNMUTED=3]="TRACK_UNMUTED",Q[Q.TRACK_DESCRIPTION_CHANGED=4]="TRACK_DESCRIPTION_CHANGED";var oe,se,ce=function(e){var t=e.peerId,n=e.name,r=e.isLocal,i=e.role,a=e.customerDescription;this.customerDescription="",this.auxiliaryTracks=[],this.role="",this.name=n,this.peerId=t,this.isLocal=r,this.role=i,this.customerDescription=a},ue=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.audioListener=null,t.handleOnTrackAdd=function(e){T.d(t.TAG,"ONTRACKADD",e),t.tracksToProcess.set(e.trackId,e),t.processPendingTracks()},t.handleOnTrackRemove=function(e){T.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}e.type===exports.HMSTrackType.AUDIO&&t.dispatchEvent(new CustomEvent("track-removed",{detail:e})),t.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,e,r)}}},t.handleTrackUpdate=function(e){T.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=i[r],c=s[0],u=s[1],h=Object.assign({},null==(o=t.trackStateMap.get(c))?void 0:o.trackInfo),d=t.getPeerTrackByTrackId(n.peerId,c);t.trackStateMap.set(c,{peerId:e.peer.peer_id,trackInfo:a({},h,u)}),!d||t.tracksToProcess.has(c)?t.processPendingTracks():(d.setEnabled(!u.mute),h.mute!==u.mute?t.listener.onTrackUpdate(u.mute?exports.HMSTrackUpdate.TRACK_MUTED:exports.HMSTrackUpdate.TRACK_UNMUTED,d,n):h.description!==u.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 ce({peerId:e.peerId,name:e.info.name,isLocal:!1,customerDescription:"",role:e.role});t.hmsPeerList.set(e.peerId,n),T.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,r){switch(this.listener=n,this.audioListener=r,e){case F.PEER_JOIN:var i=t;T.d(this.TAG,"PEER_JOIN event",i,t),this.handlePeerJoin(i);break;case F.PEER_LEAVE:var a=t;T.d(this.TAG,"PEER_LEAVE event",a),this.handlePeerLeave(a);break;case F.PEER_LIST:var o=t;T.d(this.TAG,"PEER_LIST event",o),this.handlePeerList(o);break;case F.TRACK_METADATA_ADD:this.handleTrackMetadataAdd(t);break;case F.TRACK_UPDATE:this.handleTrackUpdate(t);break;case F.ROLE_CHANGE:this.handleRoleChange(t);break;case F.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){T.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.setEnabled(!n.trackInfo.mute),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}t.type===exports.HMSTrackType.AUDIO&&e.dispatchEvent(new CustomEvent("track-added",{detail:t})),e.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_ADDED,t,r),e.tracksToProcess.delete(t.trackId)}}}))},n.handleActiveSpeakers=function(e){var t,n=e.speakers;T.d(this.TAG,"ACTIVESPEAKERS",n),null==(t=this.audioListener)||t.onAudioLevelUpdate(n);var r=n[0];if(r){var i=this.findPeerByPeerId(r.peerId);this.listener.onPeerUpdate(exports.HMSPeerUpdate.BECAME_DOMINANT_SPEAKER,i)}else this.listener.onPeerUpdate(exports.HMSPeerUpdate.RESIGNED_DOMINANT_SPEAKER,null)},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}(d(EventTarget));!function(e){e.VP8="vp8",e.VP9="vp9",e.H264="h264"}(oe||(oe={})),function(e){e.OPUS="opus"}(se||(se={}));var he=function(){function e(){this._width=320,this._height=180,this._codec=oe.VP8,this._maxFrameRate=30,this._maxBitRate=15e4,this._deviceId="default",this._advanced=[]}var t=e.prototype;return t.setWidth=function(e){return this._width=e,this},t.setHeight=function(e){return this._height=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 de(this._width,this._height,this._codec,this._maxFrameRate,this._maxBitRate,this._deviceId,this._advanced)},e}(),de=function(){function e(e,t,n,r,i,a,o){this.width=e,this.height=t,this.codec=n,this.maxFrameRate=r,this.maxBitRate=i,this.deviceId=a,this.advanced=o}return e.prototype.toConstraints=function(){return{width:this.width,height:this.height,frameRate:this.maxFrameRate,deviceId:this.deviceId}},e}(),le=function(){function e(){this._volume=1,this._codec=se.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 pe(this._volume,this._codec,this._maxBitRate,this._deviceId,this._advanced)},e}(),pe=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}(),fe=function(){function e(){this._video=(new he).build(),this._audio=(new le).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 ve(this._video,this._audio,this._simulcast)},e}(),ve=function(e,t,n){this.video=e,this.audio=t,this.simulcast=n},ke=function(e,t,n){this.id=e,this.name=t,this.peers=n},me=function(){function t(t,n){var r=this;this.handleTrackAdd=function(e){var t=e.detail,n=document.createElement("audio");n.autoplay=!0,n.style.display="none",n.id=t.trackId,n.srcObject=new MediaStream([t.nativeTrack]),r.audioSink.append(n)},this.handleTrackRemove=function(e){var t;null==(t=document.getElementById(e.detail.trackId))||t.remove()};var i=document.createElement("div");i.id="HMS-SDK-audio-sink-"+e.v4(),(n&&document.getElementById(n)||document.body).append(i),this.audioSink=i,this.addSilentAudio(),this.notificationManager=t,this.notificationManager.addEventListener("track-added",this.handleTrackAdd),this.notificationManager.addEventListener("track-removed",this.handleTrackRemove)}var n=t.prototype;return n.cleanUp=function(){this.notificationManager.removeEventListener("track-added",this.handleTrackAdd),this.notificationManager.removeEventListener("track-removed",this.handleTrackRemove)},n.addSilentAudio=function(){var t=document.createElement("audio");t.autoplay=!0,t.style.display="none",t.id="HMS-SDK-silent-audio-track-"+e.v4(),t.src="https://res.cloudinary.com/dlzh3j8em/video/upload/v1619210717/silence_xko7fm.mp3",this.audioSink.append(t)},t}();exports.HMSSdk=function(){function t(){var e=this;this.logLevel=k.INFO,this.analyticsLevel=v.OFF,this.TAG="[HMSSdk]:",this.notificationManager=new ue,this.audioListener=null,this.published=!1,this.publishParams=null,this.observer={onNotification:function(t){var n=function(e){switch(e){case"on-peer-join":return F.PEER_JOIN;case"on-peer-leave":return F.PEER_LEAVE;case"peer-list":return F.PEER_LIST;case"on-track-add":return F.TRACK_METADATA_ADD;case"on-track-update":return F.TRACK_UPDATE;case"active-speakers":return F.ACTIVE_SPEAKERS;case"on-broadcast":return F.BROADCAST;case"on-role-change":return F.ROLE_CHANGE;default:return T.d("method not supported - "+e),F.UNSUPPORTED}}(t.method),r=function(e,t){switch(e){case F.PEER_JOIN:case F.PEER_LEAVE:return new ne(t);case F.PEER_LIST:return new re(t);case F.BROADCAST:return new X(t.info);case F.ACTIVE_SPEAKERS:return new ee(t["speaker-list"]);case F.ROLE_CHANGE:return t;case F.TRACK_METADATA_ADD:case F.TRACK_UPDATE:return t;default:return T.d("method not implemented "+e),t}}(n,t.params);e.notificationManager.handleNotification(n,r,e.listener,e.audioListener),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){e.publishParams=t.detail.params.role.publishParams,console.log(t.detail.params)})),this.transport=new ae(this.observer)}var r=t.prototype;return r.join=function(t,n){var r=this;this.transport=new ae(this.observer),this.listener=n,this.audioSinkManager=new me(this.notificationManager,t.audioSinkElementId);var i=JSON.parse(atob(t.authToken.split(".")[1])),a=i.room_id,o=i.role,s=e.v4();this.localPeer=new ce({peerId:s,name:t.userName,isLocal:!0,role:o,customerDescription:t.metaData}),this.notificationManager.localPeer=this.localPeer,T.d(this.TAG,"⏳ Joining room "+a),this.transport.join(t.authToken,this.localPeer.peerId,{name:t.userName},t.initEndpoint,t.autoVideoSubscribe).then((function(){var e;T.d(r.TAG,"✅ Joined room "+a),r.roomId=a,r.published||r.publish(t.settings),null==(e=r.listener)||e.onJoin(r.createRoom())}))},r.cleanUp=function(){this.audioSinkManager.cleanUp(),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(E.mark((function e(){var t,n,r,i,a,o;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.roomId){e.next=9;break}return T.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(),T.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 T.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 T.d(this.TAG,"Sending Message:: ",r),this.transport.sendMessage(r),r},r.startScreenShare=function(){var e=n(E.mark((function e(t){var n,r,i,a,o,s=this;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a=this.publishParams.screen,!(((null==(n=this.localPeer)||null==(r=n.auxiliaryTracks)?void 0:r.length)||0)>0)){e.next=3;break}throw Error("Cannot share multiple screens");case 3:return e.next=5,this.transport.getLocalScreen((new he).maxBitRate(a.bitRate).codec(a.codec).maxFrameRate(a.frameRate).setWidth(a.width).setHeight(a.height).build());case 5:return(o=e.sent).nativeTrack.onended=function(){s.stopEndedScreenshare(t)},e.next=9,this.transport.publish([o]);case 9:null==(i=this.localPeer)||i.auxiliaryTracks.push(o);case 10:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.stopEndedScreenshare=function(){var e=n(E.mark((function e(t){return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return T.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(E.mark((function e(){var t,n;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(T.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.addAudioListener=function(e){this.audioListener=e},r.onNotificationHandled=function(e,t){var n,r=this;switch(T.d(this.TAG,"onNotificationHandled",e),e){case F.PEER_JOIN:var i=t,a=this.notificationManager.findPeerByPeerId(i.peerId);a?this.listener.onPeerUpdate(exports.HMSPeerUpdate.PEER_JOINED,a):T.e(this.TAG,"⚠️ peer not found in peer-list",i,this.notificationManager.hmsPeerList);break;case F.PEER_LEAVE:var o,s,c,u,h=new ce({peerId:t.peerId,name:t.info.name,isLocal:!1,customerDescription:t.info.data});h.audioTrack&&(null==(c=this.listener)||c.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,h.audioTrack,h)),h.videoTrack&&(null==(u=this.listener)||u.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,h.videoTrack,h)),null==(o=h.auxiliaryTracks)||o.forEach((function(e){var t;null==(t=r.listener)||t.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,e,h)})),null==(s=this.listener)||s.onPeerUpdate(exports.HMSPeerUpdate.PEER_LEFT,h);break;case F.ROLE_CHANGE:case F.ACTIVE_SPEAKERS:break;case F.BROADCAST:var d=t;T.d(this.TAG,"Received Message:: ",d),null==(n=this.listener)||n.onMessageReceived(d)}},r.publish=function(e){var t=this,r=e.isAudioMuted,i=e.isVideoMuted,a=e.audioInputDeviceId,o=e.videoDeviceId,s=this.publishParams,c=s.audio,u=s.video,h=s.allowed,d=h&&h.includes("audio"),l=h&&h.includes("video");T.d(this.TAG,"Device IDs : "+a+" , "+o+" ");var p,f=(new le).codec(c.codec).maxBitRate(c.bitRate).deviceId(a).build(),v=(new he).codec(u.codec).maxBitRate(u.bitRate).maxFrameRate(u.frameRate).setWidth(u.width).setHeight(u.height).deviceId(o).build();(d||l)&&(null==(p=this.transport)||p.getLocalTracks((new fe).video(l?v:null).audio(d?f:null).build()).then(function(){var e=n(E.mark((function e(a){return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a.forEach(function(){var e=n(E.mark((function e(n){var a,o,s;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.t0=n.type,e.next=e.t0===exports.HMSTrackType.AUDIO?3:e.t0===exports.HMSTrackType.VIDEO?5:7;break;case 3:return t.localPeer.audioTrack=n,e.abrupt("break",7);case 5:return t.localPeer.videoTrack=n,e.abrupt("break",7);case 7:return e.next=9,t.transport.publish([n]);case 9:if(!r||null==(a=t.localPeer)||!a.audioTrack){e.next=12;break}return e.next=12,t.localPeer.audioTrack.setEnabled(!1);case 12:if(!i||null==(o=t.localPeer)||!o.videoTrack){e.next=15;break}return e.next=15,t.localPeer.videoTrack.setEnabled(!1);case 15:null==(s=t.listener)||s.onTrackUpdate(exports.HMSTrackUpdate.TRACK_ADDED,n,t.localPeer);case 16:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()),t.published=!0;case 2: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 ke(this.localPeer.peerId,"",e),this.hmsRoom},t}(); | ||
"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 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 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 l(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,m,E=(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 d?t:d).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=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 d(){}function l(){}function p(){}var f={};f[i]=function(){return this};var v=Object.getPrototypeOf,k=v&&v(v(w([])));k&&k!==t&&n.call(k,i)&&(f=k);var m=p.prototype=d.prototype=Object.create(f);function E(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,d=h.value;return d&&"object"==typeof d&&n.call(d,"__await")?t.resolve(d.__await).then((function(e){r("next",e,o,s)}),(function(e){r("throw",e,o,s)})):t.resolve(d).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 x(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(g,this),this.reset(!0)}function w(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 l.prototype=m.constructor=p,p.constructor=l,l.displayName=s(p,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,p):(e.__proto__=p,s(e,o,"GeneratorFunction")),e.prototype=Object.create(m),e},e.awrap=function(e){return{__await:e}},E(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()}))},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=w,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(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:w(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.INFO=2]="INFO",e[e.VERBOSE=3]="VERBOSE"}(v||(v={})),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"}(k||(k={}));var T=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,[k.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,[k.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,[k.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,[k.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,[k.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 k.VERBOSE:var a;(a=console).log.apply(a,[t].concat(r));break;case k.DEBUG:var o;(o=console).debug.apply(o,[t].concat(r));break;case k.INFO:var s;(s=console).info.apply(s,[t].concat(r));break;case k.WARN:var c;(c=console).warn.apply(c,[t].concat(r));break;case k.ERROR:var u;(u=console).error.apply(u,[t].concat(r))}}},e}();T.level=k.VERBOSE;var y,g="HMSConnection",b=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(E.mark((function e(t){var n;return E.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,T.d(g,"[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(E.mark((function e(t){var n;return E.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,T.d(g,"[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(E.mark((function e(t){return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return T.d(g,"[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(E.mark((function e(t){return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,T.d(g,"[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(E.mark((function e(t){return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return T.d(g,"[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(E.mark((function e(t,n){var r,i;return E.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=1e3*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=n(E.mark((function e(){return E.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"}(y||(y={}));var x,w=function(e){function t(t,n,r,i){var a;return(a=e.call(this,y.PUBLISH,t)||this).observer=r,a.transport=i,a.nativeConnection=new RTCPeerConnection(n),a.nativeConnection.createDataChannel("ion-sfu",{protocol:"SCTP"}),a.nativeConnection.onicecandidate=function(e){var n=e.candidate;n&&t.trickle(a.role,n)},a.nativeConnection.oniceconnectionstatechange=function(){a.observer.onIceConnectionChange(a.nativeConnection.iceConnectionState)},a}o(t,e);var r=t.prototype;return r.initAfterJoin=function(){var e=this;this.nativeConnection.onnegotiationneeded=n(E.mark((function t(){return E.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return T.d("HMSPublishConnection","onnegotiationneeded"),t.next=3,e.observer.onRenegotiationNeeded();case 3:case"end":return t.stop()}}),t)})))},r.trackUpdate=function(e){this.transport.trackUpdate(e)},t}(b),A=function(e){this.tracks=new Array,this.nativeStream=e,this.id=e.id};!function(e){e.NONE="none",e.LOW="low",e.MEDIUM="medium",e.HIGH="high"}(x||(x={}));var S,_=function(e){function t(t,n){var r;return(r=e.call(this,t)||this).audio=!0,r.video=x.HIGH,r.frameRate=x.HIGH,r.connection=n,r}o(t,e);var r=t.prototype;return r.setAudio=function(){var e=n(E.mark((function e(t){return E.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(E.mark((function e(t){return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.video=t,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(E.mark((function e(){var t,n;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n={streamId:this.nativeStream.id,video:this.video,audio:this.audio,framerate:this.frameRate},e.next=3,null==(t=this.connection.apiChannel)?void 0:t.send(JSON.stringify(n));case 3:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),t}(A),C=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){T.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(E.mark((function e(t){return E.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:T.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}(),P=function(){function e(e,t,n){this.stream=e,this.nativeTrack=t,this.source=n}return e.prototype.setEnabled=function(){var e=n(E.mark((function e(t){return E.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}();(S=exports.HMSTrackType||(exports.HMSTrackType={})).AUDIO="audio",S.VIDEO="video";var R,I,O=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}(P),D=function(e){function t(){return e.apply(this,arguments)||this}return o(t,e),t.prototype.setEnabled=function(){var t=n(E.mark((function t(n){return E.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}(O),M=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}o(t,e);var n=t.prototype;return n.addSink=function(e){e.srcObject=new MediaStream([this.nativeTrack])},n.removeSink=function(e){e.srcObject=null},t}(P),L=function(e){function t(){return e.apply(this,arguments)||this}o(t,e);var r=t.prototype;return r.setEnabled=function(){var t=n(E.mark((function t(n){var r;return E.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 r=n?x.HIGH:x.NONE,t.next=7,this.preferLayer(r);case 7:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.preferLayer=function(){var e=n(E.mark((function e(t){return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.stream.setVideo(t);case 2:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.addSink=function(){var t=n(E.mark((function t(n){return E.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.preferLayer(x.HIGH);case 2:e.prototype.addSink.call(this,n);case 3:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.removeSink=function(){var t=n(E.mark((function t(n){return E.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.preferLayer(x.NONE);case 2:e.prototype.removeSink.call(this,n);case 3:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),t}(M),N=function(e){function t(t,n,r){var i;return(i=e.call(this,y.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 C(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 _(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?D:L)(i,t.track);i.tracks.push(a),e.observer.onTrackAdd(a)}},r.close=function(){var t=n(E.mark((function t(){var n;return E.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}(b),U=function(){function e(){}return e.fetchInitConfig=function(){var e=n(E.mark((function e(t,n,r){var i,a;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===n&&(n="https://qa-init.100ms.live/init"),void 0===r&&(r=""),T.d("InitService","fetchInitConfig: initEndpoint="+n+" token="+t+" region="+r),i=n+"?token="+t,r.length>0&&(i+="®ion="+r),e.next=7,fetch(i);case 7:return a=e.sent,e.next=10,a.json();case 10:return e.abrupt("return",e.sent);case 12:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),e}(),H=function(){function e(e,t){this.code=e,this.message=t}return e.prototype.build=function(){return new B(this.code,this.message)},e}(),B=function(e){function t(t,n){var r;return(r=e.call(this,n)||this).code=t,r}return o(t,e),t}(d(Error)),G=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(E.mark((function t(n,r){var i,a=this;return E.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(E.mark((function e(){var t,n=this;return E.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(E.mark((function e(t,n,r,i){var a,o,s=this;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a={name:t,disableVidAutoSub:i,data:n,offer:r},e.next=3,this.call("join",a);case 3:return o=e.sent,this.isJoinCompleted=!0,this.pendingTrickle.forEach((function(e){return s.trickle(e.target,e.candidate)})),this.pendingTrickle.length=0,T.d(this.TAG,"join: response="+JSON.stringify(o,null,1)),e.abrupt("return",o);case 9:case"end":return e.stop()}}),e,this)})));return function(t,n,r,i){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(E.mark((function e(t,n){return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.call("offer",{desc:t,tracks:Object.fromEntries(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){T.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 H(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(e){e.VP8="vp8",e.VP9="vp9",e.H264="h264"}(R||(R={})),function(e){e.OPUS="opus"}(I||(I={}));var K=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 j(this._volume,this._codec,this._maxBitrate,this._deviceId,this._advanced)},e}(),j=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}();function V(e){return F.apply(this,arguments)}function F(){return(F=n(E.mark((function e(t){return E.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 J(e){return W.apply(this,arguments)}function W(){return(W=n(E.mark((function e(t){return E.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)}function Y(e){var t,n,r,i=(null==e||null==(t=e.getSettings())?void 0:t.width)||640,a=(null==e||null==(n=e.getSettings())?void 0:n.height)||360,o=Object.assign(document.createElement("canvas"),{width:i,height:a});null==(r=o.getContext("2d"))||r.fillRect(0,0,i,a);var s=o.captureStream().getVideoTracks()[0];return s.enabled=!1,s}var q="[HMSLocalAudioTrack]";function z(e,t){return function(n){return n in e&&e[n]!==t[n]}}var $=function(e){function t(t,n,r,i){var a;return a=e.call(this,t,n,i)||this,t.tracks.push(l(a)),a.settings=r,a}o(t,e);var r=t.prototype;return r.replaceTrackWith=function(){var e=n(E.mark((function e(t){var n,r;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.nativeTrack,e.next=3,V(t);case 3:return r=e.sent,e.next=6,this.stream.replaceTrack(this,r);case 6:null==n||n.stop();case 7:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.setEnabled=function(){var t=n(E.mark((function t(n){return E.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:this.stream.trackUpdate(this);case 5:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.setSettings=function(){var e=n(E.mark((function e(t){var n,r,i,o;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=a({},this.settings,t),r=new j(n.volume,n.codec,n.maxBitrate,n.deviceId,n.advanced),i=this.stream,(o=z(t,this.settings))("codec")&&T.w(q,"Audio Codec can't be changed mid call."),!o("deviceId")){e.next=8;break}return e.next=8,this.replaceTrackWith(r);case 8:if(!o("maxBitrate")){e.next=11;break}return e.next=11,i.setMaxBitrate(r.maxBitrate,this);case 11:if(!o("advanced")){e.next=20;break}return e.prev=12,e.next=15,this.nativeTrack.applyConstraints(r.toConstraints());case 15:e.next=20;break;case 17:e.prev=17,e.t0=e.catch(12),T.e(q,e.t0);case 20:this.settings=r;case 21:case"end":return e.stop()}}),e,this,[[12,17]])})));return function(t){return e.apply(this,arguments)}}(),t}(O),Q=function(){function e(){this._width=320,this._height=180,this._codec=R.VP8,this._maxFramerate=30,this._maxBitrate=15e4,this._deviceId="default",this._advanced=[]}var t=e.prototype;return t.setWidth=function(e){return this._width=e,this},t.setHeight=function(e){return this._height=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 X(this._width,this._height,this._codec,this._maxFramerate,this._maxBitrate,this._deviceId,this._advanced)},e}(),X=function(){function e(e,t,n,r,i,a,o){this.width=e,this.height=t,this.codec=n,this.maxFramerate=r,this.maxBitrate=i,this.deviceId=a,this.advanced=o}return e.prototype.toConstraints=function(){return{width:this.width,height:this.height,frameRate:this.maxFramerate,deviceId:this.deviceId}},e}();function Z(e,t){return function(n){return n in e&&e[n]!==t[n]}}var ee,te,ne=function(e){function t(t,n,r,i){var a;return a=e.call(this,t,n,i)||this,t.tracks.push(l(a)),a.settings=r,a}o(t,e);var r=t.prototype;return r.replaceTrackWith=function(){var e=n(E.mark((function e(t){var n,r;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.nativeTrack,e.next=3,J(t);case 3:return r=e.sent,e.next=6,this.stream.replaceTrack(this,r);case 6:null==n||n.stop();case 7:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.replaceTrackWithBlackness=function(){var e=n(E.mark((function e(){var t,n;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=Y(t=this.nativeTrack),e.next=4,this.stream.replaceTrack(this,n);case 4:null==t||t.stop();case 5:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),r.setEnabled=function(){var t=n(E.mark((function t(n){return E.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=12;break;case 10:return t.next=12,this.replaceTrackWithBlackness();case 12:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.setSettings=function(){var e=n(E.mark((function e(t){var n,r,i,o;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=a({},this.settings,t),r=new X(n.width,n.height,n.codec,n.maxFramerate,n.maxBitrate,n.deviceId,n.advanced),i=this.stream,(o=Z(t,this.settings))("codec")&&T.w("[HMSLocalVideoTrack]","Video Codec can't be changed mid call."),!o("deviceId")){e.next=8;break}return e.next=8,this.replaceTrackWith(r);case 8:if(!o("maxBitrate")){e.next=11;break}return e.next=11,i.setMaxBitrate(r.maxBitrate,this);case 11:if(!(o("width")||o("height")||o("advanced"))){e.next=14;break}return e.next=14,this.nativeTrack.applyConstraints(r.toConstraints());case 14:this.settings=r;case 15:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t}(M),re=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(E.mark((function e(n){var r,i,a,o,s;return E.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 ne(a,o,n,"screen"),T.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(E.mark((function e(n){var r,i,a,o,s,c,u;return E.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 $(i,o,n.audio,"regular"),a.push(s)),null!=n.video&&(c=r.getVideoTracks()[0],u=new ne(i,c,n.video,"regular"),a.push(u)),T.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(E.mark((function e(t,n){var r;return E.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(E.mark((function e(t,n){var r;return E.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.addTrack(n),this.nativeStream.removeTrack(t.nativeTrack),r.track.stop(),e.next=8,r.replaceTrack(n);case 8: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}(A);!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"}(ee||(ee={})),function(e){e.CHAT="chat"}(te||(te={}));var ie,ae,oe,se=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 te.CHAT;switch(e){case"chat":return te.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},ce=function(e,t,n){this.audioLevel=0,this.peerId=e,this.trackId=t,this.audioLevel=n},ue=function(e){this.speakers=[],e&&e.length>0&&(this.speakers=e.map((function(e){return new ce(e.peer_id,e.track_id,e.level)})))},he=function(e){this.type=e.type,this.source=e.source||"regular",this.description="",e instanceof P?(this.mute=!e.enabled,this.track_id=e.trackId,this.stream_id=e.stream.id):(this.mute=e.mute,this.track_id=e.track_id,this.stream_id=e.stream_id)},de=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||{})},le=function(e){this.peers=Object.values(e.peers).map((function(e){return new de(e)}))},pe="[HMSTransport]:",fe=function(){function e(e){var t,r,i,a=this;this.tracks=new Map,this.publishConnection=null,this.subscribeConnection=null,this.callbacks=new Map,this.signalObserver={onOffer:(r=n(E.mark((function e(t){var n,r,i,o;return E.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(E.mark((function e(t){var n;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!==(n=t.target===y.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 G(this.signalObserver),this.publishConnectionObserver={onRenegotiationNeeded:(i=n(E.mark((function e(){var t,n,r;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return T.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),T.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(E.mark((function e(t){return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,re.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(E.mark((function e(t){return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,re.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(E.mark((function e(t,n,r,i,a){var o,s,c,u,h,d;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===a&&(a=!0),e.next=3,U.fetchInitConfig(t,i);case 3:return T.d(pe,"⏳ join: connecting to ws endpoint",(o=e.sent).endpoint),e.next=7,this.signal.open(o.endpoint+"?peer="+n+"&token="+t);case 7:return T.d(pe,"✅ join: connected to ws endpoint"),T.d(pe,r),this.publishConnection=new w(this.signal,o.rtcConfiguration,this.publishConnectionObserver,this),this.subscribeConnection=new N(this.signal,o.rtcConfiguration,this.subscribeConnectionObserver),T.d(pe,"⏳ join: Negotiating over PUBLISH connection"),e.next=14,this.publishConnection.createOffer();case 14:return s=e.sent,e.next=17,this.publishConnection.setLocalDescription(s);case 17:return e.next=19,this.signal.join(r.name,n,s,!a);case 19:return c=e.sent,e.next=22,this.publishConnection.setRemoteDescription(c);case 22:u=f(this.publishConnection.candidates);case 23:if((h=u()).done){e.next=29;break}return d=h.value,e.next=27,this.publishConnection.addIceCandidate(d);case 27:e.next=23;break;case 29:this.publishConnection.initAfterJoin(),T.d(pe,"✅ join: Negotiated over PUBLISH connection"),T.d(pe,"✅ join: successful");case 32:case"end":return e.stop()}}),e,this)})));return function(t,n,r,i,a){return e.apply(this,arguments)}}(),t.leave=function(){var e=n(E.mark((function e(){return E.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(E.mark((function e(t){var n,r,i,a=this;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return T.d(pe,"⏳ publishTrack: trackId="+t.trackId,t),this.tracks.set(t.trackId,new he(t)),n=new Promise((function(e,t){a.callbacks.set("renegotiation-callback-id",{resolve:e,reject:t})})),(r=t.stream).setConnection(this.publishConnection),r.addTransceiver(t),e.next=8,n;case 8:return i=t.settings.maxBitrate,e.next=11,r.setMaxBitrate(i,t).then((function(){T.i(pe,"Setting maxBitrate for "+t.source+" "+t.type+" to "+i+" kpbs")})).catch((function(e){return T.e(pe,"Failed setting maxBitrate",e)}));case 11:T.d(pe,"✅ publishTrack: trackId="+t.trackId,this.callbacks);case 12:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.unpublishTrack=function(){var e=n(E.mark((function e(t){var n,r=this;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return T.d(pe,"⏳ unpublishTrack: trackId="+t.trackId,t),this.tracks.delete(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:T.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(E.mark((function e(t){var n,r,i;return E.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(E.mark((function e(t){var n,r,i;return E.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)},t.trackUpdate=function(e){var t=Array.from(this.tracks.values()).find((function(t){return e.type===t.type&&e.source===t.source}));if(t){var n=new he(a({},t,{mute:!e.enabled}));this.tracks.set(t.track_id,n),T.d(pe,"Track Update",this.tracks,e),this.signal.trackUpdate(new Map([[t.track_id,n]]))}},e}();(ie=exports.HMSRoomUpdate||(exports.HMSRoomUpdate={}))[ie.PEER_ADDED=0]="PEER_ADDED",ie[ie.PEER_REMOVED=1]="PEER_REMOVED",ie[ie.PEER_KNOCKED=2]="PEER_KNOCKED",ie[ie.ROOM_TYPE_CHANGED=3]="ROOM_TYPE_CHANGED",ie[ie.METADATA_UPDATED=4]="METADATA_UPDATED",ie[ie.SCREENSHARE_STARTED=5]="SCREENSHARE_STARTED",ie[ie.SCREENSHARE_STOPPED=6]="SCREENSHARE_STOPPED",ie[ie.DEFAULT_UPDATE=7]="DEFAULT_UPDATE",(ae=exports.HMSPeerUpdate||(exports.HMSPeerUpdate={}))[ae.PEER_JOINED=0]="PEER_JOINED",ae[ae.PEER_LEFT=1]="PEER_LEFT",ae[ae.AUDIO_TOGGLED=2]="AUDIO_TOGGLED",ae[ae.VIDEO_TOGGLED=3]="VIDEO_TOGGLED",ae[ae.BECAME_DOMINANT_SPEAKER=4]="BECAME_DOMINANT_SPEAKER",ae[ae.RESIGNED_DOMINANT_SPEAKER=5]="RESIGNED_DOMINANT_SPEAKER",ae[ae.STARTED_SPEAKING=6]="STARTED_SPEAKING",ae[ae.STOPPED_SPEAKING=7]="STOPPED_SPEAKING",(oe=exports.HMSTrackUpdate||(exports.HMSTrackUpdate={}))[oe.TRACK_ADDED=0]="TRACK_ADDED",oe[oe.TRACK_REMOVED=1]="TRACK_REMOVED",oe[oe.TRACK_MUTED=2]="TRACK_MUTED",oe[oe.TRACK_UNMUTED=3]="TRACK_UNMUTED",oe[oe.TRACK_DESCRIPTION_CHANGED=4]="TRACK_DESCRIPTION_CHANGED";var ve=function(e){var t=e.peerId,n=e.name,r=e.isLocal,i=e.role,a=e.customerDescription;this.customerDescription="",this.auxiliaryTracks=[],this.role="",this.name=n,this.peerId=t,this.isLocal=r,this.role=i,this.customerDescription=a},ke=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.audioListener=null,t.handleOnTrackAdd=function(e){T.d(t.TAG,"ONTRACKADD",e),t.tracksToProcess.set(e.trackId,e),t.processPendingTracks()},t.handleOnTrackRemove=function(e){T.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}e.type===exports.HMSTrackType.AUDIO&&t.dispatchEvent(new CustomEvent("track-removed",{detail:e})),t.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,e,r)}}},t.handleTrackUpdate=function(e){T.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=i[r],c=s[0],u=s[1],h=Object.assign({},null==(o=t.trackStateMap.get(c))?void 0:o.trackInfo),d=t.getPeerTrackByTrackId(n.peerId,c);t.trackStateMap.set(c,{peerId:e.peer.peer_id,trackInfo:a({},h,u)}),!d||t.tracksToProcess.has(c)?t.processPendingTracks():(d.setEnabled(!u.mute),h.mute!==u.mute?t.listener.onTrackUpdate(u.mute?exports.HMSTrackUpdate.TRACK_MUTED:exports.HMSTrackUpdate.TRACK_UNMUTED,d,n):h.description!==u.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:"",role:e.role});t.hmsPeerList.set(e.peerId,n),T.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,r){switch(this.listener=n,this.audioListener=r,e){case ee.PEER_JOIN:var i=t;T.d(this.TAG,"PEER_JOIN event",i,t),this.handlePeerJoin(i);break;case ee.PEER_LEAVE:var a=t;T.d(this.TAG,"PEER_LEAVE event",a),this.handlePeerLeave(a);break;case ee.PEER_LIST:var o=t;T.d(this.TAG,"PEER_LIST event",o),this.handlePeerList(o);break;case ee.TRACK_METADATA_ADD:this.handleTrackMetadataAdd(t);break;case ee.TRACK_UPDATE:this.handleTrackUpdate(t);break;case ee.ROLE_CHANGE:this.handleRoleChange(t);break;case ee.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){T.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.setEnabled(!n.trackInfo.mute),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}t.type===exports.HMSTrackType.AUDIO&&e.dispatchEvent(new CustomEvent("track-added",{detail:t})),e.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_ADDED,t,r),e.tracksToProcess.delete(t.trackId)}}}))},n.handleActiveSpeakers=function(e){var t,n=e.speakers;T.d(this.TAG,"ACTIVESPEAKERS",n),null==(t=this.audioListener)||t.onAudioLevelUpdate(n);var r=n[0];if(r){var i=this.findPeerByPeerId(r.peerId);this.listener.onPeerUpdate(exports.HMSPeerUpdate.BECAME_DOMINANT_SPEAKER,i)}else this.listener.onPeerUpdate(exports.HMSPeerUpdate.RESIGNED_DOMINANT_SPEAKER,null)},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}(d(EventTarget)),me=function(){function e(){this._video=(new Q).build(),this._audio=(new K).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 Ee(this._video,this._audio,this._simulcast)},e}(),Ee=function(e,t,n){this.video=e,this.audio=t,this.simulcast=n},Te=function(e,t,n){this.id=e,this.name=t,this.peers=n},ye=function(){function t(t,n){var r=this;this.handleTrackAdd=function(e){var t=e.detail,n=document.createElement("audio");n.autoplay=!0,n.style.display="none",n.id=t.trackId,n.srcObject=new MediaStream([t.nativeTrack]),r.audioSink.append(n)},this.handleTrackRemove=function(e){var t;null==(t=document.getElementById(e.detail.trackId))||t.remove()};var i=document.createElement("div");i.id="HMS-SDK-audio-sink-"+e.v4(),(n&&document.getElementById(n)||document.body).append(i),this.audioSink=i,this.addSilentAudio(),this.notificationManager=t,this.notificationManager.addEventListener("track-added",this.handleTrackAdd),this.notificationManager.addEventListener("track-removed",this.handleTrackRemove)}var n=t.prototype;return n.cleanUp=function(){this.notificationManager.removeEventListener("track-added",this.handleTrackAdd),this.notificationManager.removeEventListener("track-removed",this.handleTrackRemove)},n.addSilentAudio=function(){var t=document.createElement("audio");t.autoplay=!0,t.style.display="none",t.id="HMS-SDK-silent-audio-track-"+e.v4(),t.src="https://res.cloudinary.com/dlzh3j8em/video/upload/v1619210717/silence_xko7fm.mp3",this.audioSink.append(t)},t}();exports.HMSSdk=function(){function t(){var e=this;this.logLevel=k.INFO,this.analyticsLevel=v.OFF,this.TAG="[HMSSdk]:",this.notificationManager=new ke,this.audioListener=null,this.published=!1,this.publishParams=null,this.observer={onNotification:function(t){var n=function(e){switch(e){case"on-peer-join":return ee.PEER_JOIN;case"on-peer-leave":return ee.PEER_LEAVE;case"peer-list":return ee.PEER_LIST;case"on-track-add":return ee.TRACK_METADATA_ADD;case"on-track-update":return ee.TRACK_UPDATE;case"active-speakers":return ee.ACTIVE_SPEAKERS;case"on-broadcast":return ee.BROADCAST;case"on-role-change":return ee.ROLE_CHANGE;default:return T.d("method not supported - "+e),ee.UNSUPPORTED}}(t.method),r=function(e,t){switch(e){case ee.PEER_JOIN:case ee.PEER_LEAVE:return new de(t);case ee.PEER_LIST:return new le(t);case ee.BROADCAST:return new se(t.info);case ee.ACTIVE_SPEAKERS:return new ue(t["speaker-list"]);case ee.ROLE_CHANGE:return t;case ee.TRACK_METADATA_ADD:case ee.TRACK_UPDATE:return t;default:return T.d("method not implemented "+e),t}}(n,t.params);e.notificationManager.handleNotification(n,r,e.listener,e.audioListener),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){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,this.audioSinkManager=new ye(this.notificationManager,t.audioSinkElementId);var i=JSON.parse(atob(t.authToken.split(".")[1])),a=i.room_id,o=i.role,s=e.v4();this.localPeer=new ve({peerId:s,name:t.userName,isLocal:!0,role:o,customerDescription:t.metaData}),this.notificationManager.localPeer=this.localPeer,T.d(this.TAG,"⏳ Joining room "+a),this.transport.join(t.authToken,this.localPeer.peerId,{name:t.userName},t.initEndpoint,t.autoVideoSubscribe).then((function(){var e;T.d(r.TAG,"✅ Joined room "+a),r.roomId=a,r.published||r.publish(t.settings),null==(e=r.listener)||e.onJoin(r.createRoom())}))},r.cleanUp=function(){this.audioSinkManager.cleanUp(),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(E.mark((function e(){var t,n,r,i,a,o;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.roomId){e.next=9;break}return T.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(),T.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 T.d(this.TAG,"Got peers",t),t},r.sendMessage=function(e,t,n){var r=new se({sender:this.localPeer.peerId,type:e,message:t,receiver:n});return T.d(this.TAG,"Sending Message:: ",r),this.transport.sendMessage(r),r},r.startScreenShare=function(){var e=n(E.mark((function e(t){var n,r,i,a,o,s=this;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a=this.publishParams.screen,!(((null==(n=this.localPeer)||null==(r=n.auxiliaryTracks)?void 0:r.length)||0)>0)){e.next=3;break}throw Error("Cannot share multiple screens");case 3:return e.next=5,this.transport.getLocalScreen((new Q).maxBitrate(a.bitRate).codec(a.codec).maxFramerate(a.frameRate).setWidth(a.width).setHeight(a.height).build());case 5:return(o=e.sent).nativeTrack.onended=function(){s.stopEndedScreenshare(t)},e.next=9,this.transport.publish([o]);case 9:null==(i=this.localPeer)||i.auxiliaryTracks.push(o);case 10:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.stopEndedScreenshare=function(){var e=n(E.mark((function e(t){return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return T.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(E.mark((function e(){var t,n;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(T.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.addAudioListener=function(e){this.audioListener=e},r.onNotificationHandled=function(e,t){var n,r=this;switch(T.d(this.TAG,"onNotificationHandled",e),e){case ee.PEER_JOIN:var i=t,a=this.notificationManager.findPeerByPeerId(i.peerId);a?this.listener.onPeerUpdate(exports.HMSPeerUpdate.PEER_JOINED,a):T.e(this.TAG,"⚠️ peer not found in peer-list",i,this.notificationManager.hmsPeerList);break;case ee.PEER_LEAVE:var o,s,c,u,h=new ve({peerId:t.peerId,name:t.info.name,isLocal:!1,customerDescription:t.info.data});h.audioTrack&&(null==(c=this.listener)||c.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,h.audioTrack,h)),h.videoTrack&&(null==(u=this.listener)||u.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,h.videoTrack,h)),null==(o=h.auxiliaryTracks)||o.forEach((function(e){var t;null==(t=r.listener)||t.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,e,h)})),null==(s=this.listener)||s.onPeerUpdate(exports.HMSPeerUpdate.PEER_LEFT,h);break;case ee.ROLE_CHANGE:case ee.ACTIVE_SPEAKERS:break;case ee.BROADCAST:var d=t;T.d(this.TAG,"Received Message:: ",d),null==(n=this.listener)||n.onMessageReceived(d)}},r.publish=function(e){var t=this,r=e.isAudioMuted,i=e.isVideoMuted,a=e.audioInputDeviceId,o=e.videoDeviceId,s=this.publishParams,c=s.audio,u=s.video,h=s.allowed,d=h&&h.includes("audio"),l=h&&h.includes("video");T.d(this.TAG,"Device IDs : "+a+" , "+o+" ");var p,f=(new K).codec(c.codec).maxBitrate(c.bitRate).deviceId(a).build(),v=(new Q).codec(u.codec).maxBitrate(u.bitRate).maxFramerate(u.frameRate).setWidth(u.width).setHeight(u.height).deviceId(o).build();(d||l)&&(null==(p=this.transport)||p.getLocalTracks((new me).video(l?v:null).audio(d?f:null).build()).then(function(){var e=n(E.mark((function e(a){return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a.forEach(function(){var e=n(E.mark((function e(n){var a,o,s;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.t0=n.type,e.next=e.t0===exports.HMSTrackType.AUDIO?3:e.t0===exports.HMSTrackType.VIDEO?5:7;break;case 3:return t.localPeer.audioTrack=n,e.abrupt("break",7);case 5:return t.localPeer.videoTrack=n,e.abrupt("break",7);case 7:return e.next=9,t.transport.publish([n]);case 9:if(!r||null==(a=t.localPeer)||!a.audioTrack){e.next=12;break}return e.next=12,t.localPeer.audioTrack.setEnabled(!1);case 12:if(!i||null==(o=t.localPeer)||!o.videoTrack){e.next=15;break}return e.next=15,t.localPeer.videoTrack.setEnabled(!1);case 15:null==(s=t.listener)||s.onTrackUpdate(exports.HMSTrackUpdate.TRACK_ADDED,n,t.localPeer);case 16:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()),t.published=!0;case 2: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 Te(this.localPeer.peerId,"",e),this.hmsRoom},t}(); | ||
//# sourceMappingURL=100ms-web-sdk.cjs.production.min.js.map |
@@ -5,3 +5,3 @@ import { HMSAudioCodec } from '../codec'; | ||
private _codec; | ||
private _maxBitRate; | ||
private _maxBitrate; | ||
private _deviceId; | ||
@@ -11,3 +11,3 @@ private _advanced; | ||
codec(codec: HMSAudioCodec): this; | ||
maxBitRate(maxBitRate: number): this; | ||
maxBitrate(maxBitrate: number): this; | ||
deviceId(deviceId: string): this; | ||
@@ -20,7 +20,7 @@ advanced(advanced: Array<MediaTrackConstraintSet>): this; | ||
readonly codec: HMSAudioCodec; | ||
readonly maxBitRate: number; | ||
readonly maxBitrate: number; | ||
readonly deviceId: string; | ||
readonly advanced: Array<MediaTrackConstraintSet>; | ||
constructor(volume: number, codec: HMSAudioCodec, maxBitRate: number, deviceId: string, advanced: Array<MediaTrackConstraintSet>); | ||
constructor(volume: number, codec: HMSAudioCodec, maxBitrate: number, deviceId: string, advanced: Array<MediaTrackConstraintSet>); | ||
toConstraints(): MediaTrackConstraints; | ||
} |
@@ -11,4 +11,4 @@ import { HMSVideoCodec } from '../codec'; | ||
private _codec; | ||
private _maxFrameRate; | ||
private _maxBitRate; | ||
private _maxFramerate; | ||
private _maxBitrate; | ||
private _deviceId; | ||
@@ -19,4 +19,4 @@ private _advanced; | ||
codec(codec: HMSVideoCodec): this; | ||
maxFrameRate(maxFrameRate: number): this; | ||
maxBitRate(maxBitRate: number): this; | ||
maxFramerate(maxFramerate: number): this; | ||
maxBitrate(maxBitrate: number): this; | ||
deviceId(deviceId: string): this; | ||
@@ -30,8 +30,8 @@ advanced(advanced: Array<MediaTrackConstraintSet>): this; | ||
readonly codec: HMSVideoCodec; | ||
readonly maxFrameRate: number; | ||
readonly maxBitRate: number; | ||
readonly maxFramerate: number; | ||
readonly maxBitrate: number; | ||
readonly deviceId: string; | ||
readonly advanced: Array<MediaTrackConstraintSet>; | ||
constructor(width: number, height: number, codec: HMSVideoCodec, maxFrameRate: number, maxBitRate: number, deviceId: string, advanced: Array<MediaTrackConstraintSet>); | ||
constructor(width: number, height: number, codec: HMSVideoCodec, maxFramerate: number, maxBitrate: number, deviceId: string, advanced: Array<MediaTrackConstraintSet>); | ||
toConstraints(): MediaTrackConstraints; | ||
} |
@@ -9,3 +9,3 @@ import HMSAudioTrack from './HMSAudioTrack'; | ||
setEnabled(value: boolean): Promise<void>; | ||
setSettings(newSettings: HMSAudioTrackSettings): Promise<void>; | ||
setSettings(settings: HMSAudioTrackSettings): Promise<void>; | ||
} |
@@ -10,3 +10,3 @@ import HMSVideoTrack from './HMSVideoTrack'; | ||
setEnabled(value: boolean): Promise<void>; | ||
setSettings(newSettings: HMSVideoTrackSettings): Promise<void>; | ||
setSettings(settings: HMSVideoTrackSettings): Promise<void>; | ||
} |
{ | ||
"version": "0.0.12-30", | ||
"version": "0.0.12-31", | ||
"license": "UNLICENSED", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
@@ -85,3 +85,3 @@ import { HMSConnectionRole } from './model'; | ||
const params = sender.getParameters(); | ||
params.encodings[0].maxBitrate = maxBitrate; | ||
params.encodings[0].maxBitrate = maxBitrate * 1000; | ||
await sender.setParameters(params); | ||
@@ -88,0 +88,0 @@ } |
@@ -6,3 +6,3 @@ import { HMSAudioCodec } from '../codec'; | ||
private _codec: HMSAudioCodec = HMSAudioCodec.OPUS; | ||
private _maxBitRate: number = 32_000; | ||
private _maxBitrate: number = 32_000; | ||
private _deviceId: string = 'default'; | ||
@@ -33,5 +33,5 @@ private _advanced: Array<MediaTrackConstraintSet> = [ | ||
maxBitRate(maxBitRate: number) { | ||
if (maxBitRate <= 0) throw Error('maxBitRate should be >= 1'); | ||
this._maxBitRate = maxBitRate; | ||
maxBitrate(maxBitrate: number) { | ||
if (maxBitrate <= 0) throw Error('maxBitrate should be >= 1'); | ||
this._maxBitrate = maxBitrate; | ||
return this; | ||
@@ -52,3 +52,3 @@ } | ||
build() { | ||
return new HMSAudioTrackSettings(this._volume, this._codec, this._maxBitRate, this._deviceId, this._advanced); | ||
return new HMSAudioTrackSettings(this._volume, this._codec, this._maxBitrate, this._deviceId, this._advanced); | ||
} | ||
@@ -60,3 +60,3 @@ } | ||
readonly codec: HMSAudioCodec; | ||
readonly maxBitRate: number; | ||
readonly maxBitrate: number; | ||
readonly deviceId: string; | ||
@@ -68,3 +68,3 @@ readonly advanced: Array<MediaTrackConstraintSet>; | ||
codec: HMSAudioCodec, | ||
maxBitRate: number, | ||
maxBitrate: number, | ||
deviceId: string, | ||
@@ -75,3 +75,3 @@ advanced: Array<MediaTrackConstraintSet>, | ||
this.codec = codec; | ||
this.maxBitRate = maxBitRate; | ||
this.maxBitrate = maxBitrate; | ||
this.deviceId = deviceId; | ||
@@ -78,0 +78,0 @@ this.advanced = advanced; |
@@ -20,4 +20,4 @@ import { HMSVideoCodec } from '../codec'; | ||
private _codec: HMSVideoCodec = HMSVideoCodec.VP8; | ||
private _maxFrameRate: number = 30; | ||
private _maxBitRate: number = 150_000; | ||
private _maxFramerate: number = 30; | ||
private _maxBitrate: number = 150_000; | ||
private _deviceId: string = 'default'; | ||
@@ -41,11 +41,11 @@ private _advanced: Array<MediaTrackConstraintSet> = []; | ||
maxFrameRate(maxFrameRate: number) { | ||
if (maxFrameRate <= 0) throw Error('maxFrameRate should be >= 1'); | ||
this._maxFrameRate = maxFrameRate; | ||
maxFramerate(maxFramerate: number) { | ||
if (maxFramerate <= 0) throw Error('maxFramerate should be >= 1'); | ||
this._maxFramerate = maxFramerate; | ||
return this; | ||
} | ||
maxBitRate(maxBitRate: number) { | ||
if (maxBitRate <= 0) throw Error('maxBitRate should be >= 1'); | ||
this._maxBitRate = maxBitRate; | ||
maxBitrate(maxBitrate: number) { | ||
if (maxBitrate <= 0) throw Error('maxBitrate should be >= 1'); | ||
this._maxBitrate = maxBitrate; | ||
return this; | ||
@@ -70,4 +70,4 @@ } | ||
this._codec, | ||
this._maxFrameRate, | ||
this._maxBitRate, | ||
this._maxFramerate, | ||
this._maxBitrate, | ||
this._deviceId, | ||
@@ -83,4 +83,4 @@ this._advanced, | ||
readonly codec: HMSVideoCodec; | ||
readonly maxFrameRate: number; | ||
readonly maxBitRate: number; | ||
readonly maxFramerate: number; | ||
readonly maxBitrate: number; | ||
readonly deviceId: string; | ||
@@ -93,4 +93,4 @@ readonly advanced: Array<MediaTrackConstraintSet>; | ||
codec: HMSVideoCodec, | ||
maxFrameRate: number, | ||
maxBitRate: number, | ||
maxFramerate: number, | ||
maxBitrate: number, | ||
deviceId: string, | ||
@@ -102,4 +102,4 @@ advanced: Array<MediaTrackConstraintSet>, | ||
this.codec = codec; | ||
this.maxFrameRate = maxFrameRate; | ||
this.maxBitRate = maxBitRate; | ||
this.maxFramerate = maxFramerate; | ||
this.maxBitrate = maxBitrate; | ||
this.deviceId = deviceId; | ||
@@ -113,3 +113,3 @@ this.advanced = advanced; | ||
height: this.height, | ||
frameRate: this.maxFrameRate, | ||
frameRate: this.maxFramerate, | ||
deviceId: this.deviceId, | ||
@@ -116,0 +116,0 @@ }; |
@@ -72,3 +72,3 @@ import HMSMediaStream from './HMSMediaStream'; | ||
async setMaxBitrate(maxBitrate: number, track: HMSTrack) { | ||
async setMaxBitrate(maxBitrate: number, track: HMSTrack): Promise<void> { | ||
await this.connection?.setMaxBitrate(maxBitrate, track); | ||
@@ -75,0 +75,0 @@ } |
@@ -5,3 +5,12 @@ import HMSAudioTrack from './HMSAudioTrack'; | ||
import { getAudioTrack } from '../../utils/track'; | ||
import HMSLogger from '../../utils/logger'; | ||
const TAG = '[HMSLocalAudioTrack]'; | ||
function generateHasPropertyChanged(newSettings: HMSAudioTrackSettings, oldSettings: HMSAudioTrackSettings) { | ||
return function hasChanged(prop: 'codec' | 'volume' | 'maxBitrate' | 'deviceId' | 'advanced') { | ||
return prop in newSettings && newSettings[prop] !== oldSettings[prop]; | ||
}; | ||
} | ||
export default class HMSLocalAudioTrack extends HMSAudioTrack { | ||
@@ -30,14 +39,30 @@ settings: HMSAudioTrackSettings; | ||
async setSettings(newSettings: HMSAudioTrackSettings) { | ||
if (this.settings.codec !== newSettings.codec) { | ||
throw Error("Audio Codec can't be changed mid call."); | ||
async setSettings(settings: HMSAudioTrackSettings) { | ||
const { volume, codec, maxBitrate, deviceId, advanced } = { ...this.settings, ...settings }; | ||
const newSettings = new HMSAudioTrackSettings(volume, codec, maxBitrate, deviceId, advanced); | ||
const stream = this.stream as HMSLocalStream; | ||
const hasPropertyChanged = generateHasPropertyChanged(settings, this.settings); | ||
if (hasPropertyChanged('codec')) { | ||
HMSLogger.w(TAG, "Audio Codec can't be changed mid call."); | ||
} | ||
if (this.settings.deviceId !== newSettings.deviceId) { | ||
if (hasPropertyChanged('deviceId')) { | ||
await this.replaceTrackWith(newSettings); | ||
} | ||
await this.nativeTrack.applyConstraints(newSettings.toConstraints()); | ||
if (hasPropertyChanged('maxBitrate')) { | ||
await stream.setMaxBitrate(newSettings.maxBitrate, this); | ||
} | ||
if (hasPropertyChanged('advanced')) { | ||
try { | ||
await this.nativeTrack.applyConstraints(newSettings.toConstraints()); | ||
} catch (error) { | ||
HMSLogger.e(TAG, error); | ||
} | ||
} | ||
this.settings = newSettings; | ||
} | ||
} |
@@ -5,3 +5,14 @@ import HMSVideoTrack from './HMSVideoTrack'; | ||
import { getEmptyVideoTrack, getVideoTrack } from '../../utils/track'; | ||
import HMSLogger from '../../utils/logger'; | ||
function generateHasPropertyChanged(newSettings: HMSVideoTrackSettings, oldSettings: HMSVideoTrackSettings) { | ||
return function hasChanged( | ||
prop: 'codec' | 'width' | 'height' | 'maxFramerate' | 'maxBitrate' | 'deviceId' | 'advanced', | ||
) { | ||
return prop in newSettings && newSettings[prop] !== oldSettings[prop]; | ||
}; | ||
} | ||
const TAG = '[HMSLocalVideoTrack]'; | ||
export default class HMSLocalVideoTrack extends HMSVideoTrack { | ||
@@ -42,14 +53,26 @@ settings: HMSVideoTrackSettings; | ||
async setSettings(newSettings: HMSVideoTrackSettings) { | ||
if (this.settings.codec !== newSettings.codec) { | ||
throw Error("Video Codec can't be changed mid call."); | ||
async setSettings(settings: HMSVideoTrackSettings) { | ||
const { width, height, codec, maxFramerate, maxBitrate, deviceId, advanced } = { ...this.settings, ...settings }; | ||
const newSettings = new HMSVideoTrackSettings(width, height, codec, maxFramerate, maxBitrate, deviceId, advanced); | ||
const stream = this.stream as HMSLocalStream; | ||
const hasPropertyChanged = generateHasPropertyChanged(settings, this.settings); | ||
if (hasPropertyChanged('codec')) { | ||
HMSLogger.w(TAG, "Video Codec can't be changed mid call."); | ||
} | ||
if (this.settings.deviceId !== newSettings.deviceId) { | ||
if (hasPropertyChanged('deviceId')) { | ||
await this.replaceTrackWith(newSettings); | ||
} | ||
await this.nativeTrack.applyConstraints(newSettings.toConstraints()); | ||
if (hasPropertyChanged('maxBitrate')) { | ||
await stream.setMaxBitrate(newSettings.maxBitrate, this); | ||
} | ||
if (hasPropertyChanged('width') || hasPropertyChanged('height') || hasPropertyChanged('advanced')) { | ||
await this.nativeTrack.applyConstraints(newSettings.toConstraints()); | ||
} | ||
this.settings = newSettings; | ||
} | ||
} |
@@ -66,3 +66,2 @@ import HMSConfig from '../interfaces/config'; | ||
this.publishParams = e.detail.params.role.publishParams; | ||
console.log(e.detail.params); | ||
}); | ||
@@ -160,5 +159,5 @@ this.transport = new HMSTransport(this.observer); | ||
new HMSVideoTrackSettingsBuilder() | ||
.maxBitRate(screen.bitRate) | ||
.maxBitrate(screen.bitRate) | ||
.codec(screen.codec) | ||
.maxFrameRate(screen.frameRate) | ||
.maxFramerate(screen.frameRate) | ||
.setWidth(screen.width) | ||
@@ -254,3 +253,3 @@ .setHeight(screen.height) | ||
.codec(audio.codec) | ||
.maxBitRate(audio.bitRate) | ||
.maxBitrate(audio.bitRate) | ||
.deviceId(audioInputDeviceId) | ||
@@ -260,4 +259,4 @@ .build(); | ||
.codec(video.codec) | ||
.maxBitRate(video.bitRate) | ||
.maxFrameRate(video.frameRate) | ||
.maxBitrate(video.bitRate) | ||
.maxFramerate(video.frameRate) | ||
.setWidth(video.width) | ||
@@ -264,0 +263,0 @@ .setHeight(video.height) |
@@ -183,5 +183,5 @@ import ITransportObserver from './ITransportObserver'; | ||
// @ts-ignore | ||
const maxBitrate = track.settings.maxBitRate; | ||
const maxBitrate = track.settings.maxBitrate; | ||
await stream | ||
.setMaxBitrate(maxBitrate * 1000, track) | ||
.setMaxBitrate(maxBitrate, track) | ||
.then(() => { | ||
@@ -188,0 +188,0 @@ HMSLogger.i(TAG, `Setting maxBitrate for ${track.source} ${track.type} to ${maxBitrate} kpbs`); |
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
1047599
11557