@100mslive/100ms-web-sdk
Advanced tools
Comparing version 0.0.9 to 0.0.10
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("uuid"),n=(e=require("jsonwebtoken"))&&"object"==typeof e&&"default"in e?e.default:e;function r(e,t,n,r,i,a,o){try{var s=e[a](o),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,i)}function i(e){return function(){var t=this,n=arguments;return new Promise((function(i,a){var o=e.apply(t,n);function s(e){r(o,i,a,s,c,"next",e)}function c(e){r(o,i,a,s,c,"throw",e)}s(void 0)}))}}function a(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function o(e,t,n){return t&&a(e.prototype,t),n&&a(e,n),e}function s(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,u(e,t)}function c(e){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(e,t){return(u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function h(){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 f(e,t,n){return(f=h()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&u(i,n.prototype),i}).apply(null,arguments)}function l(e){var t="function"==typeof Map?new Map:void 0;return(l=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return f(e,arguments,c(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),u(n,e)})(e)}function d(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function p(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function v(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 m,k,E,y,w=(function(e){var t=function(e){var t=Object.prototype,n=t.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},i=r.iterator||"@@iterator",a=r.asyncIterator||"@@asyncIterator",o=r.toStringTag||"@@toStringTag";function s(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,n){return e[t]=n}}function c(e,t,n,r){var i=Object.create((t&&t.prototype instanceof f?t:f).prototype),a=new x(r||[]);return i._invoke=function(e,t,n){var r="suspendedStart";return function(i,a){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===i)throw a;return{value:void 0,done:!0}}for(n.method=i,n.arg=a;;){var o=n.delegate;if(o){var s=w(o,n);if(s){if(s===h)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=u(e,t,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===h)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}(e,n,a),i}function u(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var h={};function f(){}function l(){}function d(){}var p={};p[i]=function(){return this};var v=Object.getPrototypeOf,m=v&&v(v(T([])));m&&m!==t&&n.call(m,i)&&(p=m);var k=d.prototype=f.prototype=Object.create(p);function E(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function y(e,t){var r;this._invoke=function(i,a){function o(){return new t((function(r,o){!function r(i,a,o,s){var c=u(e[i],e,a);if("throw"!==c.type){var h=c.arg,f=h.value;return f&&"object"==typeof f&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,o,s)}),(function(e){r("throw",e,o,s)})):t.resolve(f).then((function(e){h.value=e,o(h)}),(function(e){return r("throw",e,o,s)}))}s(c.arg)}(i,a,r,o)}))}return r=r?r.then(o,o):o()}}function w(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,w(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 T(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,a=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return a.next=a}}return{next:R}}function R(){return{value:void 0,done:!0}}return l.prototype=k.constructor=d,d.constructor=l,l.displayName=s(d,o,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===l||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,d):(e.__proto__=d,s(e,o,"GeneratorFunction")),e.prototype=Object.create(k),e},e.awrap=function(e){return{__await:e}},E(y.prototype),y.prototype[a]=function(){return this},e.AsyncIterator=y,e.async=function(t,n,r,i,a){void 0===a&&(a=Promise);var o=new y(c(t,n,r,i),a);return e.isGeneratorFunction(n)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},E(k),s(k,o,"Generator"),k[i]=function(){return this},k.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=T,x.prototype={constructor:x,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(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:T(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),h}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}(y={exports:{}}),y.exports);!function(e){e[e.OFF=0]="OFF",e[e.ERROR=1]="ERROR",e[e.WARN=2]="WARN",e[e.INFO=3]="INFO",e[e.VERBOSE=4]="VERBOSE"}(m||(m={})),function(e){e[e.OFF=0]="OFF",e[e.ERROR=1]="ERROR",e[e.INFO=2]="INFO",e[e.VERBOSE=3]="VERBOSE"}(k||(k={})),function(e){e[e.VERBOSE=0]="VERBOSE",e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e[e.NONE=5]="NONE"}(E||(E={}));var g=function(){function e(){}return e.v=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[E.VERBOSE,e].concat(n))},e.d=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[E.DEBUG,e].concat(n))},e.i=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[E.INFO,e].concat(n))},e.w=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[E.WARN,e].concat(n))},e.e=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[E.ERROR,e].concat(n))},e.log=function(e,t){if(!(this.level.valueOf()>e.valueOf())){for(var n=arguments.length,r=new Array(n>2?n-2:0),i=2;i<n;i++)r[i-2]=arguments[i];switch(e){case E.VERBOSE:var a;(a=console).log.apply(a,[t].concat(r));break;case E.DEBUG:var o;(o=console).debug.apply(o,[t].concat(r));break;case E.INFO:var s;(s=console).info.apply(s,[t].concat(r));break;case E.WARN:var c;(c=console).warn.apply(c,[t].concat(r));break;case E.ERROR:var u;(u=console).error.apply(u,[t].concat(r))}}},e}();g.level=E.VERBOSE;var b,x="HMSConnection",T=function(){function e(e,t){this.candidates=new Array,this.role=e,this.signal=t}var t=e.prototype;return t.addTransceiver=function(e,t){return this.nativeConnection.addTransceiver(e,t)},t.createOffer=function(){var e=i(w.mark((function e(t){var n;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===t&&(t=void 0),e.next=3,this.nativeConnection.createOffer(t);case 3:return n=e.sent,g.d(x,"[role="+this.role+"] createOffer offer="+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.createAnswer=function(){var e=i(w.mark((function e(t){var n;return w.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,g.d(x,"[role="+this.role+"] createAnswer answer="+JSON.stringify(n,null,1)),e.abrupt("return",n);case 6:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.setLocalDescription=function(){var e=i(w.mark((function e(t){return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return g.d(x,"[role="+this.role+"] setLocalDescription description="+JSON.stringify(t,null,1)),e.next=3,this.nativeConnection.setLocalDescription(t);case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.setRemoteDescription=function(){var e=i(w.mark((function e(t){return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return g.d(x,"[role="+this.role+"] setRemoteDescription description="+JSON.stringify(t,null,1)),e.next=3,this.nativeConnection.setRemoteDescription(t);case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.addIceCandidate=function(){var e=i(w.mark((function e(t){return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return g.d(x,"[role="+this.role+"] addIceCandidate candidate="+JSON.stringify(t,null,1)),e.next=3,this.nativeConnection.addIceCandidate(t);case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.getSenders=function(){return this.nativeConnection.getSenders()},t.removeTrack=function(e){this.nativeConnection.removeTrack(e)},t.setMaxBitrate=function(){var e=i(w.mark((function e(t,n){var r,i;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(r=this.getSenders().find((function(e){var t;return(null==e||null==(t=e.track)?void 0:t.id)===n.trackId})))){e.next=6;break}return(i=r.getParameters()).encodings[0].maxBitrate=t,e.next=6,r.setParameters(i);case 6:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),t.close=function(){var e=i(w.mark((function e(){return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.nativeConnection.close();case 1:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),o(e,[{key:"remoteDescription",get:function(){return this.nativeConnection.remoteDescription}}]),e}();!function(e){e[e.PUBLISH=0]="PUBLISH",e[e.SUBSCRIBE=1]="SUBSCRIBE"}(b||(b={}));var R,S,C=function(e){function t(t,n,r){var i;return(i=e.call(this,b.PUBLISH,t)||this).observer=r,i.nativeConnection=new RTCPeerConnection(n),i.nativeConnection.createDataChannel("ion-sfu",{protocol:"SCTP"}),i.nativeConnection.onicecandidate=function(e){var n=e.candidate;n&&t.trickle({target:i.role,candidate:n})},i.nativeConnection.oniceconnectionstatechange=function(){i.observer.onIceConnectionChange(i.nativeConnection.iceConnectionState)},i}return s(t,e),t.prototype.initAfterJoin=function(){var e=this;this.nativeConnection.onnegotiationneeded=i(w.mark((function t(){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return g.d("HMSPublishConnection","onnegotiationneeded"),t.next=3,e.observer.onRenegotiationNeeded();case 3:case"end":return t.stop()}}),t)})))},t}(T),I=function(e){this.tracks=new Array,this.nativeStream=e,this.id=e.id};!function(e){e.VP8="vp8",e.VP9="vp9",e.H264="h264"}(R||(R={})),function(e){e.OPUS="opus"}(S||(S={}));var O,A=function(){function e(){this._resolution=new P(320,180),this._codec=R.VP8,this._maxFrameRate=24,this._maxBitRate=15e4,this._deviceId="default",this._advanced=[]}var t=e.prototype;return t.resolution=function(e){return this._resolution=e,this},t.codec=function(e){return this._codec=e,this},t.maxFrameRate=function(e){if(e<=0)throw Error("maxFrameRate should be >= 1");return this._maxFrameRate=e,this},t.maxBitRate=function(e){if(e<=0)throw Error("maxBitRate should be >= 1");return this._maxBitRate=e,this},t.deviceId=function(e){return this._deviceId=e,this},t.advanced=function(e){return this._advanced=e,this},t.build=function(){return new _(this._resolution,this._codec,this._maxFrameRate,this._maxBitRate,this._deviceId,this._advanced)},e}(),_=function(){function e(e,t,n,r,i,a){this.resolution=e,this.codec=t,this.maxFrameRate=n,this.maxBitRate=r,this.deviceId=i,this.advanced=a}return e.prototype.toConstraints=function(){return{width:this.resolution.width,height:this.resolution.height,frameRate:this.maxFrameRate,deviceId:this.deviceId}},e}();!function(e){e.NONE="none",e.LOW="low",e.MEDIUM="medium",e.HIGH="high"}(O||(O={}));var D,P=function(e,t){if(e<=0)throw Error("Height should be >= 1");if(t<=0)throw Error("Height should be >= 1");this.width=e,this.height=t},M={QVGA:(new A).resolution(new P(320,180)).maxBitRate(15e4).build(),VGA:(new A).resolution(new P(640,360)).maxBitRate(5e5).build(),SHD:(new A).resolution(new P(960,540)).maxBitRate(12e5).build(),HD:(new A).resolution(new P(1280,720)).maxBitRate(25e5).build(),FHD:(new A).resolution(new P(1920,1080)).maxBitRate(4e6).build(),QHD:(new A).resolution(new P(2560,1440)).maxBitRate(8e6).build()},L=function(e){function t(t,n){var r;return(r=e.call(this,t)||this).audio=!0,r.video=O.HIGH,r.frameRate=O.HIGH,r.connection=n,r}s(t,e);var n=t.prototype;return n.setAudio=function(){var e=i(w.mark((function e(t){return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.audio=t,e.next=3,this.syncWithApiChannel();case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.setVideo=function(){var e=i(w.mark((function e(t){return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.video=t?O.HIGH:O.NONE,e.next=3,this.syncWithApiChannel();case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.syncWithApiChannel=function(){var e=i(w.mark((function e(){var t;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t={streamId:this.nativeStream.id,video:this.video,audio:this.audio,framerate:this.frameRate},e.next=3,this.connection.apiChannel.send(JSON.stringify(t));case 3:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),t}(I),N=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){g.d(r.TAG,"["+r.metadata+"] onMessage: label="+r.label+", message="+e.data),r.observer.onMessage(e.data)}}var t=e.prototype;return t.send=function(){var e=i(w.mark((function e(t){return w.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:g.d(this.TAG,"["+this.metadata+"] Sending [size="+t.length+"] message="+t),this.nativeChannel.send(t);case 4:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.close=function(){this.nativeChannel.close()},o(e,[{key:"id",get:function(){return this.nativeChannel.id}},{key:"label",get:function(){return this.nativeChannel.label}}]),e}(),U=function(){function e(e,t){this.stream=e,this.nativeTrack=t}return e.prototype.setEnabled=function(){var e=i(w.mark((function e(t){return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.nativeTrack.enabled=t;case 1:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),o(e,[{key:"enabled",get:function(){return this.nativeTrack.enabled}},{key:"trackId",get:function(){return this.nativeTrack.id}}]),e}();(D=exports.HMSTrackType||(exports.HMSTrackType={}))[D.AUDIO=0]="AUDIO",D[D.VIDEO=1]="VIDEO";var H=function(e){function t(t,n){var r;if((r=e.call(this,t,n)||this).type=exports.HMSTrackType.AUDIO,"audio"!==n.kind)throw new Error("Expected 'track' kind = 'audio'");return r}return s(t,e),t}(U),B=function(e){function t(t,n){return e.call(this,t,n)||this}return s(t,e),t.prototype.setEnabled=function(){var t=i(w.mark((function t(n){return w.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}(H),V=function(e){function t(t,n){var r;if((r=e.call(this,t,n)||this).type=exports.HMSTrackType.VIDEO,"video"!==n.kind)throw new Error("Expected 'track' kind = 'video'");return r}return s(t,e),t}(U),G=function(e){function t(t,n){return e.call(this,t,n)||this}return s(t,e),t.prototype.setEnabled=function(){var t=i(w.mark((function t(n){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n!==this.enabled){t.next=2;break}return t.abrupt("return");case 2:return t.next=4,e.prototype.setEnabled.call(this,n);case 4:return t.next=6,this.stream.setVideo(n);case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),t}(V),F=function(e){function t(t,n,r){var i;return(i=e.call(this,b.SUBSCRIBE,t)||this).remoteStreams=new Map,i._apiChannel=null,i.observer=r,i.nativeConnection=new RTCPeerConnection(n),i.initNativeConnectionCallbacks(),i}s(t,e);var n=t.prototype;return n.initNativeConnectionCallbacks=function(){var e=this;this.nativeConnection.oniceconnectionstatechange=function(){e.observer.onIceConnectionChange(e.nativeConnection.iceConnectionState)},this.nativeConnection.ondatachannel=function(t){"ion-sfu"===t.channel.label&&(e._apiChannel=new N(t.channel,{onMessage:function(t){e.observer.onApiChannelMessage(t)}},"role="+e.role))},this.nativeConnection.onicecandidate=function(t){null!==t.candidate&&e.signal.trickle({candidate:t.candidate,target:e.role})},this.nativeConnection.ontrack=function(t){var n=t.streams[0];if(!e.remoteStreams.has(n.id)){var r=new L(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?B:G)(i,t.track);i.tracks.push(a),e.observer.onTrackAdd(a)}},n.close=function(){var t=i(w.mark((function t(){var n;return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.prototype.close.call(this);case 2:null==(n=this.apiChannel)||n.close();case 3:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),o(t,[{key:"apiChannel",get:function(){return this._apiChannel}}]),t}(T),j=function(){function e(){}return e.fetchInitConfig=function(){var e=i(w.mark((function e(t,n){var r,i;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===n&&(n=""),g.d("InitService","fetchInitConfig: token="+t+" region="+n),r="https://qa2-us.100ms.live/init?token="+t,n.length>0&&(r+="®ion="+n),e.next=6,fetch(r);case 6:return i=e.sent,e.next=9,i.json();case 9:return e.abrupt("return",e.sent);case 11:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),e}(),J=function(){function e(e,t){this.code=e,this.message=t}return e.prototype.build=function(){return new K(this.code,this.message)},e}(),K=function(e){function t(t,n){var r;return(r=e.call(this,n)||this).code=t,r}return s(t,e),t}(l(Error)),W=function(){function e(e){this.TAG="JsonRpcSignal",this.isJoinCompleted=!1,this.pendingTrickle=[],this.socket=null,this.callbacks=new Map,this.observer=e}var n=e.prototype;return n.call=function(){var e=i(w.mark((function e(n,r){var i,a=this;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=t.v4(),this.socket.send(JSON.stringify({method:n,params:r,id:i})),e.next=5,new Promise((function(e,t){a.callbacks.set(i,{resolve:e,reject:t})}));case 5:return e.abrupt("return",JSON.parse(e.sent));case 7:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),n.notify=function(e,t){this.socket.send(JSON.stringify({method:e,params:t}))},n.open=function(e){var t=this;return new Promise((function(n){t.socket=new WebSocket(e),t.socket.addEventListener("open",(function e(){n(),t.socket.removeEventListener("open",e)})),t.socket.addEventListener("message",(function(e){return t.onMessageHandler(e.data)}))}))},n.close=function(){var e=i(w.mark((function e(){var t,n=this;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=new Promise((function(e){n.socket.addEventListener("close",(function(){return e()}))})),this.socket.close(1e3,"Normal Close"),e.abrupt("return",t);case 3:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),n.join=function(){var e=i(w.mark((function e(t,n,r,i){var a,o,s=this;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a={sid:t,uid:n,offer:r,info:i},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)})),this.pendingTrickle.length=0,g.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)}}(),n.offer=function(){var e=i(w.mark((function e(t){return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.call("offer",{desc:t});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.answer=function(e){this.notify("answer",{desc:e})},n.trickle=function(e){this.isJoinCompleted?this.notify("trickle",e):this.pendingTrickle.push(e)},n.onMessageHandler=function(e){var t=JSON.parse(e);if(t.hasOwnProperty("id")){var n=t.id;if(this.callbacks.has(n)){var r=this.callbacks.get(n);if(this.callbacks.delete(n),t.result)r.resolve(JSON.stringify(t.result));else{var i=t.error,a=new J(i.code,i.message).build();r.reject(a)}}else this.observer.onNotification(t)}else{if(!t.hasOwnProperty("method"))throw Error("WebSocket message has no 'method' or 'id' field, message="+t);"offer"===t.method?this.observer.onOffer(t.params):"trickle"===t.method?this.observer.onTrickle(t.params):this.observer.onNotification(t)}},e}();function Y(e){return q.apply(this,arguments)}function q(){return(q=i(w.mark((function e(t){return w.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 Q(e){return z.apply(this,arguments)}function z(){return(z=i(w.mark((function e(t){return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,navigator.mediaDevices.getUserMedia({video:t.toConstraints()});case 2:return e.abrupt("return",e.sent.getVideoTracks()[0]);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var $=function(e){function t(t,n,r){var i;return i=e.call(this,t,n)||this,t.tracks.push(d(i)),i.settings=r,i}s(t,e);var n=t.prototype;return n.replaceTrackWith=function(){var e=i(w.mark((function e(t){var n;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Y(t);case 2:return n=e.sent,e.next=5,this.stream.replaceTrack(this,n);case 5:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.setEnabled=function(){var t=i(w.mark((function t(n){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n!==this.enabled){t.next=2;break}return t.abrupt("return");case 2:return t.next=4,e.prototype.setEnabled.call(this,n);case 4:if(!n){t.next=9;break}return t.next=7,this.replaceTrackWith(this.settings);case 7:t.next=10;break;case 9:this.nativeTrack.stop();case 10:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.setSettings=function(){var e=i(w.mark((function e(t){return w.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}(H);function X(e){if(e<=0)throw Error("`ms` should be a positive integer");return new Promise((function(t){return setTimeout(t,e)}))}var Z,ee,te,ne,re=function(e){function t(t,n,r){var i;return i=e.call(this,t,n)||this,t.tracks.push(d(i)),i.settings=r,i}s(t,e);var n=t.prototype;return n.replaceTrackWith=function(){var e=i(w.mark((function e(t){var n;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Q(t);case 2:return n=e.sent,e.next=5,this.stream.replaceTrack(this,n);case 5:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.setEnabled=function(){var t=i(w.mark((function t(n){return w.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n!==this.enabled){t.next=2;break}return t.abrupt("return");case 2:return t.next=4,e.prototype.setEnabled.call(this,n);case 4:if(!n){t.next=9;break}return t.next=7,this.replaceTrackWith(this.settings);case 7:t.next=12;break;case 9:return t.next=11,X(100);case 11:this.nativeTrack.stop();case 12:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.setSettings=function(){var e=i(w.mark((function e(t){return w.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}(V),ie=function(e){function t(t){var n;return(n=e.call(this,t)||this).connection=null,n}s(t,e);var n=t.prototype;return n.setConnection=function(e){this.connection=e},t.getLocalScreen=function(){var e=i(w.mark((function e(n){var r,i,a,o,s;return w.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 re(a,o,n),g.v("HMSLocalStream","getLocalScreen",s),e.abrupt("return",s);case 9:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),t.getLocalTracks=function(){var e=i(w.mark((function e(n){var r,i,a,o,s,c,u;return w.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),a.push(s)),null!=n.video&&(c=r.getVideoTracks()[0],u=new re(i,c,n.video),a.push(u)),g.v("HMSLocalStream","getLocalTracks",a),e.abrupt("return",a);case 9:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),n.addTransceiver=function(e){var t=this.connection.addTransceiver(e.nativeTrack,{streams:[this.nativeStream],direction:"sendonly",sendEncodings:void 0});return this.setPreferredCodec(t,e.nativeTrack.kind),t},n.setMaxBitrate=function(){var e=i(w.mark((function e(t,n){var r;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,null==(r=this.connection)?void 0:r.setMaxBitrate(t,n);case 2:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),n.setPreferredCodec=function(e,t){},n.replaceTrack=function(){var e=i(w.mark((function e(t,n){var r;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==(r=this.connection.getSenders().find((function(e){return e.track&&e.track.id===t.trackId})))){e.next=3;break}throw Error("No sender found for trackId="+t.trackId);case 3:return this.nativeStream.removeTrack(t.nativeTrack),r.track.stop(),e.next=7,r.replaceTrack(n);case 7:this.nativeStream.addTrack(n),t.nativeTrack=n;case 9:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),n.removeSender=function(e){var t=this,n=0;if(this.connection.getSenders().forEach((function(r){if(r.track&&r.track.id===e.trackId){t.connection.removeTrack(r),n+=1;var i=t.tracks.indexOf(e);if(-1===i)throw Error("Cannot find "+e+" in locally stored tracks");t.tracks.splice(i,1)}})),1!=n)throw Error("Removed "+n+" sender's, expected to remove 1")},t}(I),ae="[HMSTransport]: ",oe=function(){function e(e){var t,n,r,a=this;this.publishConnection=null,this.subscribeConnection=null,this.callbacks=new Map,this.signalObserver={onOffer:(n=i(w.mark((function e(t){var n,r,i,o;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,a.subscribeConnection.setRemoteDescription(t);case 2:n=v(a.subscribeConnection.candidates);case 3:if((r=n()).done){e.next=9;break}return i=r.value,e.next=7,a.subscribeConnection.addIceCandidate(i);case 7:e.next=3;break;case 9:return a.subscribeConnection.candidates.length=0,e.next=12,a.subscribeConnection.createAnswer();case 12:return o=e.sent,e.next=15,a.subscribeConnection.setLocalDescription(o);case 15:a.signal.answer(o);case 16:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)}),onTrickle:(t=i(w.mark((function e(t){var n;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!==(n=t.target===b.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 W(this.signalObserver),this.publishConnectionObserver={onRenegotiationNeeded:(r=i(w.mark((function e(){var t,n,r;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return g.d(ae,"[role=PUBLISH] onRenegotiationNeeded START ⏰"),t=a.callbacks.get("renegotiation-callback-id"),a.callbacks.delete("renegotiation-callback-id"),e.next=5,a.publishConnection.createOffer();case 5:return n=e.sent,e.next=8,a.publishConnection.setLocalDescription(n);case 8:return e.next=10,a.signal.offer(n);case 10:return r=e.sent,e.next=13,a.publishConnection.setRemoteDescription(r);case 13:null==t||t.resolve(!0),g.d(ae,"[role=PUBLISH] onRenegotiationNeeded DONE ✅");case 15:case"end":return e.stop()}}),e)}))),function(){return r.apply(this,arguments)}),onIceConnectionChange:function(e){}},this.subscribeConnectionObserver={onApiChannelMessage:function(e){var t={method:"active-speakers",params:JSON.parse(e)};a.observer.onNotification(t)},onTrackAdd:function(e){return a.observer.onTrackAdd(e)},onTrackRemove:function(e){return a.observer.onTrackRemove(e)},onIceConnectionChange:function(e){}},this.observer=e}var t=e.prototype;return t.getLocalScreen=function(){var e=i(w.mark((function e(t,n){var r;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ie.getLocalScreen(t);case 2:return(r=e.sent).nativeTrack.onended=function(){return n()},e.abrupt("return",r);case 5:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),t.getLocalTracks=function(){var e=i(w.mark((function e(t){return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ie.getLocalTracks(t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),t.join=function(){var e=i(w.mark((function e(t,n,r,i){var a,o,s,c,u,h;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return g.d(ae,"join: started ⏰"),e.next=3,j.fetchInitConfig(t);case 3:return a=e.sent,e.next=6,this.signal.open(a.endpoint+"?peer="+r+"&token="+t);case 6:return g.d(ae,"join: connected to ws endpoint"),this.publishConnection=new C(this.signal,a.rtcConfiguration,this.publishConnectionObserver),this.subscribeConnection=new F(this.signal,a.rtcConfiguration,this.subscribeConnectionObserver),g.d(ae,"join: Negotiating over PUBLISH connection ⏰"),e.next=12,this.publishConnection.createOffer();case 12:return o=e.sent,e.next=15,this.publishConnection.setLocalDescription(o);case 15:return e.next=17,this.signal.join(n,r,o,i);case 17:return s=e.sent,e.next=20,this.publishConnection.setRemoteDescription(s);case 20:c=v(this.publishConnection.candidates);case 21:if((u=c()).done){e.next=27;break}return h=u.value,e.next=25,this.publishConnection.addIceCandidate(h);case 25:e.next=21;break;case 27:this.publishConnection.initAfterJoin(),g.d(ae,"join: Negotiating over PUBLISH connection ✅"),g.d(ae,"join: successful ✅");case 30:case"end":return e.stop()}}),e,this)})));return function(t,n,r,i){return e.apply(this,arguments)}}(),t.leave=function(){var e=i(w.mark((function e(){return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.publishConnection.close();case 2:return e.next=4,this.subscribeConnection.close();case 4:return e.next=6,this.signal.close();case 6:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),t.publishTrack=function(){var e=i(w.mark((function e(t){var n,r,i=this;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return g.d(ae,"publishTrack: trackId="+t.trackId+" ⏰",t),n=new Promise((function(e,t){i.callbacks.set("renegotiation-callback-id",{resolve:e,reject:t})})),(r=t.stream).setConnection(this.publishConnection),r.addTransceiver(t),e.next=7,n;case 7:if(t.type!==exports.HMSTrackType.VIDEO){e.next=11;break}return e.next=11,r.setMaxBitrate(25e4,t).then((function(){g.d(ae,"Setting maxBitrate to 250 kpbs")})).catch((function(e){return g.e(ae,"Failed setting maxBitrate",e)}));case 11:g.d(ae,"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=i(w.mark((function e(t){var n,r=this;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return g.d(ae,"unpublishTrack: trackId="+t.trackId+" ⏰",t),n=new Promise((function(e,t){r.callbacks.set("renegotiation-callback-id",{resolve:e,reject:t})})),t.stream.removeSender(t),e.next=6,n;case 6:g.d(ae,"unpublishTrack: trackId="+t.trackId+" ✅",this.callbacks);case 7:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.publish=function(){var e=i(w.mark((function e(t){var n,r,i;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=v(t);case 1:if((r=n()).done){e.next=7;break}return i=r.value,e.next=5,this.publishTrack(i);case 5:e.next=1;break;case 7:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.unpublish=function(){var e=i(w.mark((function e(t){var n,r,i;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=v(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)}}(),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",(ee=exports.HMSPeerUpdate||(exports.HMSPeerUpdate={}))[ee.PEER_JOINED=0]="PEER_JOINED",ee[ee.PEER_LEFT=1]="PEER_LEFT",ee[ee.AUDIO_TOGGLED=2]="AUDIO_TOGGLED",ee[ee.VIDEO_TOGGLED=3]="VIDEO_TOGGLED",(te=exports.HMSTrackUpdate||(exports.HMSTrackUpdate={}))[te.TRACK_ADDED=0]="TRACK_ADDED",te[te.TRACK_REMOVED=1]="TRACK_REMOVED",te[te.TRACK_MUTED=2]="TRACK_MUTED",te[te.TRACK_UNMUTED=3]="TRACK_UNMUTED",te[te.TRACK_DESCRIPTION_CHANGED=4]="TRACK_DESCRIPTION_CHANGED",function(e){e[e.PEER_JOIN=0]="PEER_JOIN",e[e.PEER_LEAVE=1]="PEER_LEAVE",e[e.PEER_LIST=2]="PEER_LIST",e[e.STREAM_ADD=3]="STREAM_ADD",e[e.ACTIVE_SPEAKERS=4]="ACTIVE_SPEAKERS"}(ne||(ne={}));var se=function(e){this.name=null==e?void 0:e.name,this.metadata=null==e?void 0:e.metadata},ce=function(e){this.uid=e.uid,this.sid=e.sid,this.info=new se(e.info)},ue=function(e){this.uid=e.uid,this.stream=e.stream,this.streamId=this.stream.streamId},he=function(e){this.peers=e.peers,this.streams=e.streams},fe=function(e){var t=e.peerId,n=e.name,r=e.isLocal,i=e.customerDescription;this.customerDescription="",this.auxiliaryTracks=[],this.name=n,this.peerId=t,this.isLocal=r,this.customerDescription=i},le=function(){var e=this;this.hmsPeerList=[],this.TAG="NotificationManager",this.streamIdToUIDMap=new Map,this.streamIdToTrackMap=new Map,this.handleNotification=function(t,n){var r;switch(t){case ne.PEER_JOIN:g.d(e.TAG,"PEER_JOIN event",r=n),e.handlePeerJoin(r);break;case ne.PEER_LEAVE:g.d(e.TAG,"PEER_LEAVE event",r=n),e.handlePeerLeave(r);break;case ne.PEER_LIST:var i=n;g.d(e.TAG,"PEER_LIST event",i),e.handlePeerList(i);break;case ne.STREAM_ADD:var a=n;g.d(e.TAG,"STREAM_ADD event",a),e.handleStreamAdd(a.stream);break;case ne.ACTIVE_SPEAKERS:default:return}},this.handleOnTrackAdd=function(t){g.d(e.TAG,"ONTRACKADD",t);var n=t.stream.id,r=e.streamIdToUIDMap.get(n)?e.findPeerByUID(e.streamIdToUIDMap.get(n)):null;if(r)switch(t.type){case exports.HMSTrackType.AUDIO:r.audioTrack=t;break;case exports.HMSTrackType.VIDEO:r.videoTrack?r.auxiliaryTracks.push(t):r.videoTrack=t}else e.streamIdToTrackMap.set(n,t);return r},this.handleOnTrackRemove=function(t){g.d(e.TAG,"ONTRACKREMOVE",t);var n=e.streamIdToUIDMap.get(t.stream.id),r=n&&e.findPeerByUID(n);if(r)switch(t.type){case exports.HMSTrackType.AUDIO:r.audioTrack=null;break;case exports.HMSTrackType.VIDEO:var i=r.auxiliaryTracks.indexOf(t);i>-1?r.auxiliaryTracks.splice(i,1):r.videoTrack=null}else g.w(e.TAG,"No peer found for track "+t);return r},this.handleLeave=function(){e.hmsPeerList.length=0},this.findPeerByUID=function(t){return e.hmsPeerList.find((function(e){return e.peerId===t}))},this.handlePeerJoin=function(t){var n=new fe({peerId:t.uid,name:t.info&&t.info.name?t.info.name:"",isLocal:!1,customerDescription:t.info&&t.info.metadata?t.info.metadata:""});e.hmsPeerList.push(n)},this.handlePeerLeave=function(t){var n=e.findPeerByUID(t.uid),r=n&&e.hmsPeerList.indexOf(n);r&&r>-1&&e.hmsPeerList.splice(r,1)},this.handlePeerList=function(t){var n=t.peers,r=t.streams;n&&n.forEach((function(t){return e.handlePeerJoin(t)})),r&&r.forEach((function(t){return e.handleStreamAdd(t)}))},this.handleStreamAdd=function(t){if(e.streamIdToUIDMap.set(t.streamId,t.uid),e.streamIdToTrackMap.has(t.streamId)){var n=e.findPeerByUID(t.uid),r=e.streamIdToTrackMap.get(t.streamId);if(r&&n)switch(r.type){case exports.HMSTrackType.AUDIO:n.audioTrack=r;break;case exports.HMSTrackType.VIDEO:n.videoTrack=r}}}},de=function(){function e(){this._volume=1,this._codec=S.OPUS,this._maxBitRate=32e3,this._deviceId="default",this._advanced=[{googEchoCancellation:{exact:!0}},{googExperimentalEchoCancellation:{exact:!0}},{autoGainControl:{exact:!0}},{noiseSuppression:{exact:!0}},{googHighpassFilter:{exact:!0}},{googAudioMirroring:{exact:!0}}]}var t=e.prototype;return t.volume=function(e){if(!(0<=e&&e<=1))throw Error("volume can only be in range [0.0, 1.0]");return this._volume=e,this},t.codec=function(e){return this._codec=e,this},t.maxBitRate=function(e){if(e<=0)throw Error("maxBitRate should be >= 1");return this._maxBitRate=e,this},t.deviceId=function(e){return this._deviceId=e,this},t.advanced=function(e){return this._advanced=e,this},t.build=function(){return new 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}(),ve=function(){function e(){this._video=M.QVGA,this._audio=(new de).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 me(this._video,this._audio,this._simulcast)},e}(),me=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};exports.HMSSdk=function(){function e(){var e=this;this.logLevel=m.OFF,this.analyticsLevel=k.OFF,this.TAG="HMSSdk",this.notificationManager=new le,this.observer={onNotification:function(t){var n=function(e){switch(e){case"peer-join":return ne.PEER_JOIN;case"peer-leave":return ne.PEER_LEAVE;case"peer-list":return ne.PEER_LIST;case"stream-add":return ne.STREAM_ADD;case"active-speakers":return ne.ACTIVE_SPEAKERS;default:throw Error("Unsupported method="+e+" received")}}(t.method);if(n!==ne.ACTIVE_SPEAKERS){var r=function(e,t){switch(e){case ne.PEER_JOIN:case ne.PEER_LEAVE:return new ce(t);case ne.PEER_LIST:return new he(t);case ne.STREAM_ADD:return new ue(t);case ne.ACTIVE_SPEAKERS:return;default:throw Error("Unsupported method="+e+" received")}}(n,t.params);e.notificationManager.handleNotification(n,r),e.onNotificationHandled(n,r)}},onTrackAdd:function(t){var n=e.notificationManager.handleOnTrackAdd(t);n?e.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_ADDED,t,n):g.d(e.TAG,"No Peer found for added track:: "+t)},onTrackRemove:function(t){var n=e.notificationManager.handleOnTrackRemove(t);n?e.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,t,n):g.d(e.TAG,"No Peer found for added track:: "+t)},onFailure:function(t){e.listener.onError(t)}},this.transport=new oe(this.observer)}var r=e.prototype;return r.join=function(e,r){var i=this;this.listener=r;var a=n.decode(e.authToken,{json:!0}).room_id,o=t.v4();this.localPeer=new fe({peerId:o,name:e.userName,isLocal:!0,customerDescription:e.metaData}),this.transport.join(e.authToken,a,this.localPeer.peerId,{name:e.userName}).then((function(){console.log("JOINED!",a),i.roomId=a}))},r.leave=function(){var e=i(w.mark((function e(){var t,n;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.roomId&&(null==(t=this.localPeer.audioTrack)||t.nativeTrack.stop(),null==(n=this.localPeer.videoTrack)||n.nativeTrack.stop(),this.notificationManager.handleLeave(),this.transport.leave(),this.roomId=null);case 1:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),r.getLocalPeer=function(){return this.localPeer},r.getPeers=function(){return[].concat(this.notificationManager.hmsPeerList,[this.localPeer])},r.sendMessage=function(e){throw console.log(e),"Yet to implement"},r.onMessageReceived=function(e){throw console.log(e),"Yet to implement"},r.startScreenShare=function(){var e=i(w.mark((function e(t){var n,r;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(((null==(n=this.localPeer.auxiliaryTracks)?void 0:n.length)||0)>0)){e.next=2;break}throw Error("Cannot share multiple screens");case 2:return e.next=4,this.transport.getLocalScreen(M.HD,t);case 4:return r=e.sent,e.next=7,this.transport.publish([r]);case 7:this.localPeer.auxiliaryTracks=[r];case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.stopScreenShare=function(){var e=i(w.mark((function e(){var t;return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=this.localPeer.auxiliaryTracks[0],e.next=3,t.setEnabled(!1);case 3:this.transport.unpublish([t]),this.localPeer.auxiliaryTracks.length=0;case 5:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),r.onNotificationHandled=function(e,t){var n,r,a=this;switch(e){case ne.PEER_JOIN:(r=this.notificationManager.findPeerByUID((n=t).uid))?this.listener.onPeerUpdate(exports.HMSPeerUpdate.PEER_JOINED,r):g.e(this.TAG,"peer not found in peer-list "+n);break;case ne.PEER_LEAVE:var o,s=new fe({peerId:t.uid,name:t.info.name,isLocal:!1,customerDescription:t.info.metadata});s.audioTrack&&this.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,s.audioTrack,s),s.videoTrack&&this.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,s.videoTrack,s),null==(o=s.auxiliaryTracks)||o.forEach((function(e){a.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,e,s)})),this.listener.onPeerUpdate(exports.HMSPeerUpdate.PEER_LEFT,s);break;case ne.PEER_LIST:this.transport.getLocalTracks((new ve).build()).then(function(){var e=i(w.mark((function e(t){return w.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t.forEach((function(e){switch(e.type){case exports.HMSTrackType.AUDIO:a.localPeer.audioTrack=e;break;case exports.HMSTrackType.VIDEO:a.localPeer.videoTrack=e}})),a.listener.onJoin(a.createRoom()),e.next=4,a.transport.publish(t);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}());break;case ne.STREAM_ADD:case ne.ACTIVE_SPEAKERS:return}},r.createRoom=function(){var e=this.getPeers();return this.hmsRoom=new ke(this.localPeer.peerId,"",e),this.hmsRoom},e}(); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("uuid"),n=(e=require("jsonwebtoken"))&&"object"==typeof e&&"default"in e?e.default:e;function r(e,t,n,r,i,a,o){try{var s=e[a](o),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,i)}function i(e){return function(){var t=this,n=arguments;return new Promise((function(i,a){var o=e.apply(t,n);function s(e){r(o,i,a,s,c,"next",e)}function c(e){r(o,i,a,s,c,"throw",e)}s(void 0)}))}}function a(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function o(e,t,n){return t&&a(e.prototype,t),n&&a(e,n),e}function s(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,u(e,t)}function c(e){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(e,t){return(u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function h(){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 f(e,t,n){return(f=h()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&u(i,n.prototype),i}).apply(null,arguments)}function l(e){var t="function"==typeof Map?new Map:void 0;return(l=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return f(e,arguments,c(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),u(n,e)})(e)}function d(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function p(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function v(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 k,m,E,y,g=(function(e){var t=function(e){var t=Object.prototype,n=t.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},i=r.iterator||"@@iterator",a=r.asyncIterator||"@@asyncIterator",o=r.toStringTag||"@@toStringTag";function s(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,n){return e[t]=n}}function c(e,t,n,r){var i=Object.create((t&&t.prototype instanceof f?t:f).prototype),a=new x(r||[]);return i._invoke=function(e,t,n){var r="suspendedStart";return function(i,a){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===i)throw a;return{value:void 0,done:!0}}for(n.method=i,n.arg=a;;){var o=n.delegate;if(o){var s=g(o,n);if(s){if(s===h)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=u(e,t,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===h)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}(e,n,a),i}function u(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var h={};function f(){}function l(){}function d(){}var p={};p[i]=function(){return this};var v=Object.getPrototypeOf,k=v&&v(v(T([])));k&&k!==t&&n.call(k,i)&&(p=k);var m=d.prototype=f.prototype=Object.create(p);function E(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function y(e,t){var r;this._invoke=function(i,a){function o(){return new t((function(r,o){!function r(i,a,o,s){var c=u(e[i],e,a);if("throw"!==c.type){var h=c.arg,f=h.value;return f&&"object"==typeof f&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,o,s)}),(function(e){r("throw",e,o,s)})):t.resolve(f).then((function(e){h.value=e,o(h)}),(function(e){return r("throw",e,o,s)}))}s(c.arg)}(i,a,r,o)}))}return r=r?r.then(o,o):o()}}function g(e,t){var n=e.iterator[t.method];if(void 0===n){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,g(e,t),"throw"===t.method))return h;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return h}var r=u(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,h;var i=r.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,h):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,h)}function w(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(w,this),this.reset(!0)}function T(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,a=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return a.next=a}}return{next:R}}function R(){return{value:void 0,done:!0}}return l.prototype=m.constructor=d,d.constructor=l,l.displayName=s(d,o,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===l||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,d):(e.__proto__=d,s(e,o,"GeneratorFunction")),e.prototype=Object.create(m),e},e.awrap=function(e){return{__await:e}},E(y.prototype),y.prototype[a]=function(){return this},e.AsyncIterator=y,e.async=function(t,n,r,i,a){void 0===a&&(a=Promise);var o=new y(c(t,n,r,i),a);return e.isGeneratorFunction(n)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},E(m),s(m,o,"Generator"),m[i]=function(){return this},m.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=T,x.prototype={constructor:x,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(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:T(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),h}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}(y={exports:{}}),y.exports);!function(e){e[e.OFF=0]="OFF",e[e.ERROR=1]="ERROR",e[e.WARN=2]="WARN",e[e.INFO=3]="INFO",e[e.VERBOSE=4]="VERBOSE"}(k||(k={})),function(e){e[e.OFF=0]="OFF",e[e.ERROR=1]="ERROR",e[e.INFO=2]="INFO",e[e.VERBOSE=3]="VERBOSE"}(m||(m={})),function(e){e[e.VERBOSE=0]="VERBOSE",e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e[e.NONE=5]="NONE"}(E||(E={}));var w=function(){function e(){}return e.v=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[E.VERBOSE,e].concat(n))},e.d=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[E.DEBUG,e].concat(n))},e.i=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[E.INFO,e].concat(n))},e.w=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[E.WARN,e].concat(n))},e.e=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[E.ERROR,e].concat(n))},e.log=function(e,t){if(!(this.level.valueOf()>e.valueOf())){for(var n=arguments.length,r=new Array(n>2?n-2:0),i=2;i<n;i++)r[i-2]=arguments[i];switch(e){case E.VERBOSE:var a;(a=console).log.apply(a,[t].concat(r));break;case E.DEBUG:var o;(o=console).debug.apply(o,[t].concat(r));break;case E.INFO:var s;(s=console).info.apply(s,[t].concat(r));break;case E.WARN:var c;(c=console).warn.apply(c,[t].concat(r));break;case E.ERROR:var u;(u=console).error.apply(u,[t].concat(r))}}},e}();w.level=E.VERBOSE;var b,x="HMSConnection",T=function(){function e(e,t){this.candidates=new Array,this.role=e,this.signal=t}var t=e.prototype;return t.addTransceiver=function(e,t){return this.nativeConnection.addTransceiver(e,t)},t.createOffer=function(){var e=i(g.mark((function e(t){var n;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===t&&(t=void 0),e.prev=1,e.next=4,this.nativeConnection.createOffer(t);case 4:return n=e.sent,w.d(x,"[role="+this.role+"] createOffer offer="+JSON.stringify(n,null,1)),e.abrupt("return",n);case 9:throw e.prev=9,e.t0=e.catch(1),e.t0;case 12:case"end":return e.stop()}}),e,this,[[1,9]])})));return function(t){return e.apply(this,arguments)}}(),t.createAnswer=function(){var e=i(g.mark((function e(t){var n;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===t&&(t=void 0),e.next=3,this.nativeConnection.createAnswer(t);case 3:return n=e.sent,w.d(x,"[role="+this.role+"] createAnswer answer="+JSON.stringify(n,null,1)),e.abrupt("return",n);case 6:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.setLocalDescription=function(){var e=i(g.mark((function e(t){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return w.d(x,"[role="+this.role+"] setLocalDescription description="+JSON.stringify(t,null,1)),e.next=3,this.nativeConnection.setLocalDescription(t);case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.setRemoteDescription=function(){var e=i(g.mark((function e(t){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,w.d(x,"[role="+this.role+"] setRemoteDescription description="+JSON.stringify(t,null,1)),e.next=4,this.nativeConnection.setRemoteDescription(t);case 4:e.next=9;break;case 6:throw e.prev=6,e.t0=e.catch(0),e.t0;case 9:case"end":return e.stop()}}),e,this,[[0,6]])})));return function(t){return e.apply(this,arguments)}}(),t.addIceCandidate=function(){var e=i(g.mark((function e(t){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return w.d(x,"[role="+this.role+"] addIceCandidate candidate="+JSON.stringify(t,null,1)),e.next=3,this.nativeConnection.addIceCandidate(t);case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.getSenders=function(){return this.nativeConnection.getSenders()},t.removeTrack=function(e){this.nativeConnection.removeTrack(e)},t.setMaxBitrate=function(){var e=i(g.mark((function e(t,n){var r,i;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(r=this.getSenders().find((function(e){var t;return(null==e||null==(t=e.track)?void 0:t.id)===n.trackId})))){e.next=6;break}return(i=r.getParameters()).encodings[0].maxBitrate=t,e.next=6,r.setParameters(i);case 6:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),t.close=function(){var e=i(g.mark((function e(){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.nativeConnection.close();case 1:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),o(e,[{key:"remoteDescription",get:function(){return this.nativeConnection.remoteDescription}}]),e}();!function(e){e[e.PUBLISH=0]="PUBLISH",e[e.SUBSCRIBE=1]="SUBSCRIBE"}(b||(b={}));var R,A,C=function(e){function t(t,n,r){var i;return(i=e.call(this,b.PUBLISH,t)||this).observer=r,i.nativeConnection=new RTCPeerConnection(n),i.nativeConnection.createDataChannel("ion-sfu",{protocol:"SCTP"}),i.nativeConnection.onicecandidate=function(e){var n=e.candidate;n&&t.trickle({target:i.role,candidate:n})},i.nativeConnection.oniceconnectionstatechange=function(){i.observer.onIceConnectionChange(i.nativeConnection.iceConnectionState)},i}return s(t,e),t.prototype.initAfterJoin=function(){var e=this;this.nativeConnection.onnegotiationneeded=i(g.mark((function t(){return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return w.d("HMSPublishConnection","onnegotiationneeded"),t.next=3,e.observer.onRenegotiationNeeded();case 3:case"end":return t.stop()}}),t)})))},t}(T),S=function(e){this.tracks=new Array,this.nativeStream=e,this.id=e.id};!function(e){e.VP8="vp8",e.VP9="vp9",e.H264="h264"}(R||(R={})),function(e){e.OPUS="opus"}(A||(A={}));var O,_=function(e,t){if(e<=0)throw Error("Height should be >= 1");if(t<=0)throw Error("Height should be >= 1");this.width=e,this.height=t},I=function(){function e(){this._resolution=new _(320,180),this._codec=R.VP8,this._maxFrameRate=24,this._maxBitRate=15e4,this._deviceId="default",this._advanced=[]}var t=e.prototype;return t.resolution=function(e){return this._resolution=e,this},t.codec=function(e){return this._codec=e,this},t.maxFrameRate=function(e){if(e<=0)throw Error("maxFrameRate should be >= 1");return this._maxFrameRate=e,this},t.maxBitRate=function(e){if(e<=0)throw Error("maxBitRate should be >= 1");return this._maxBitRate=e,this},t.deviceId=function(e){return this._deviceId=e,this},t.advanced=function(e){return this._advanced=e,this},t.build=function(){return new P(this._resolution,this._codec,this._maxFrameRate,this._maxBitRate,this._deviceId,this._advanced)},e}(),P=function(){function e(e,t,n,r,i,a){this.resolution=e,this.codec=t,this.maxFrameRate=n,this.maxBitRate=r,this.deviceId=i,this.advanced=a}return e.prototype.toConstraints=function(){return{width:this.resolution.width,height:this.resolution.height,frameRate:this.maxFrameRate,deviceId:this.deviceId}},e}(),D=function(){function e(){this._volume=1,this._codec=A.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 L(this._volume,this._codec,this._maxBitRate,this._deviceId,this._advanced)},e}(),L=function(){function e(e,t,n,r,i){this.volume=e,this.codec=t,this.maxBitRate=n,this.deviceId=r,this.advanced=i}return e.prototype.toConstraints=function(){return{deviceId:this.deviceId,advanced:this.advanced}},e}(),M={QVGA:(new I).resolution(new _(320,180)).maxBitRate(15e4).build(),VGA:(new I).resolution(new _(640,360)).maxBitRate(5e5).build(),SHD:(new I).resolution(new _(960,540)).maxBitRate(12e5).build(),HD:(new I).resolution(new _(1280,720)).maxBitRate(25e5).build(),FHD:(new I).resolution(new _(1920,1080)).maxBitRate(4e6).build(),QHD:(new I).resolution(new _(2560,1440)).maxBitRate(8e6).build()},N=function(){function e(){this._video=M.QVGA,this._audio=(new D).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 H(this._video,this._audio,this._simulcast)},e}(),H=function(e,t,n){this.video=e,this.audio=t,this.simulcast=n};!function(e){e.NONE="none",e.LOW="low",e.MEDIUM="medium",e.HIGH="high"}(O||(O={}));var U,G=function(e){function t(t,n){var r;return(r=e.call(this,t)||this).audio=!0,r.video=O.HIGH,r.frameRate=O.HIGH,r.connection=n,r}s(t,e);var n=t.prototype;return n.setAudio=function(){var e=i(g.mark((function e(t){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.audio=t,e.next=3,this.syncWithApiChannel();case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.setVideo=function(){var e=i(g.mark((function e(t){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.video=t?O.HIGH:O.NONE,e.next=3,this.syncWithApiChannel();case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.syncWithApiChannel=function(){var e=i(g.mark((function e(){var t;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t={streamId:this.nativeStream.id,video:this.video,audio:this.audio,framerate:this.frameRate},e.next=3,this.connection.apiChannel.send(JSON.stringify(t));case 3:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),t}(S),B=function(){function e(e,t,n){var r=this;void 0===n&&(n=""),this.TAG="HMSDataChannel",this.nativeChannel=e,this.observer=t,this.metadata=n,e.onmessage=function(e){w.d(r.TAG,"["+r.metadata+"] onMessage: label="+r.label+", message="+e.data),r.observer.onMessage(e.data)}}var t=e.prototype;return t.send=function(){var e=i(g.mark((function e(t){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("open"===this.nativeChannel.readyState){e.next=2;break}throw Error("Channel "+this.label+" not yet ready");case 2:w.d(this.TAG,"["+this.metadata+"] Sending [size="+t.length+"] message="+t),this.nativeChannel.send(t);case 4:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.close=function(){this.nativeChannel.close()},o(e,[{key:"id",get:function(){return this.nativeChannel.id}},{key:"label",get:function(){return this.nativeChannel.label}}]),e}(),V=function(){function e(e,t){this.stream=e,this.nativeTrack=t}return e.prototype.setEnabled=function(){var e=i(g.mark((function e(t){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.nativeTrack.enabled=t;case 1:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),o(e,[{key:"enabled",get:function(){return this.nativeTrack.enabled}},{key:"trackId",get:function(){return this.nativeTrack.id}}]),e}();(U=exports.HMSTrackType||(exports.HMSTrackType={}))[U.AUDIO=0]="AUDIO",U[U.VIDEO=1]="VIDEO";var j=function(e){function t(t,n){var r;if((r=e.call(this,t,n)||this).type=exports.HMSTrackType.AUDIO,"audio"!==n.kind)throw new Error("Expected 'track' kind = 'audio'");return r}return s(t,e),t}(V),F=function(e){function t(){return e.apply(this,arguments)||this}return s(t,e),t.prototype.setEnabled=function(){var t=i(g.mark((function t(n){return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n!==this.enabled){t.next=2;break}return t.abrupt("return");case 2:return t.next=4,e.prototype.setEnabled.call(this,n);case 4:return t.next=6,this.stream.setAudio(n);case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),t}(j),J=function(e){function t(t,n){var r;if((r=e.call(this,t,n)||this).type=exports.HMSTrackType.VIDEO,"video"!==n.kind)throw new Error("Expected 'track' kind = 'video'");return r}return s(t,e),t}(V),K=function(e){function t(){return e.apply(this,arguments)||this}return s(t,e),t.prototype.setEnabled=function(){var t=i(g.mark((function t(n){return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n!==this.enabled){t.next=2;break}return t.abrupt("return");case 2:return t.next=4,e.prototype.setEnabled.call(this,n);case 4:return t.next=6,this.stream.setVideo(n);case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),t}(J),W=function(e){function t(t,n,r){var i;return(i=e.call(this,b.SUBSCRIBE,t)||this).remoteStreams=new Map,i._apiChannel=null,i.observer=r,i.nativeConnection=new RTCPeerConnection(n),i.initNativeConnectionCallbacks(),i}s(t,e);var n=t.prototype;return n.initNativeConnectionCallbacks=function(){var e=this;this.nativeConnection.oniceconnectionstatechange=function(){e.observer.onIceConnectionChange(e.nativeConnection.iceConnectionState)},this.nativeConnection.ondatachannel=function(t){"ion-sfu"===t.channel.label&&(e._apiChannel=new B(t.channel,{onMessage:function(t){e.observer.onApiChannelMessage(t)}},"role="+e.role))},this.nativeConnection.onicecandidate=function(t){null!==t.candidate&&e.signal.trickle({candidate:t.candidate,target:e.role})},this.nativeConnection.ontrack=function(t){var n=t.streams[0];if(!e.remoteStreams.has(n.id)){var r=new G(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?F:K)(i,t.track);i.tracks.push(a),e.observer.onTrackAdd(a)}},n.close=function(){var t=i(g.mark((function t(){var n;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.prototype.close.call(this);case 2:null==(n=this.apiChannel)||n.close();case 3:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),o(t,[{key:"apiChannel",get:function(){return this._apiChannel}}]),t}(T),Y=function(){function e(){}return e.fetchInitConfig=function(){var e=i(g.mark((function e(t,n){var r,i;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return void 0===n&&(n=""),w.d("InitService","fetchInitConfig: token="+t+" region="+n),r="https://qa2-us.100ms.live/init?token="+t,n.length>0&&(r+="®ion="+n),e.next=6,fetch(r);case 6:return i=e.sent,e.next=9,i.json();case 9:return e.abrupt("return",e.sent);case 11:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),e}(),q=function(){function e(e,t){this.code=e,this.message=t}return e.prototype.build=function(){return new Q(this.code,this.message)},e}(),Q=function(e){function t(t,n){var r;return(r=e.call(this,n)||this).code=t,r}return s(t,e),t}(l(Error)),z=function(){function e(e){this.TAG="[ SIGNAL ]: ",this.isJoinCompleted=!1,this.pendingTrickle=[],this.socket=null,this.callbacks=new Map,this.observer=e}var n=e.prototype;return n.call=function(){var e=i(g.mark((function e(n,r){var i,a=this;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=t.v4(),this.socket.send(JSON.stringify({method:n,params:r,id:i})),e.next=5,new Promise((function(e,t){a.callbacks.set(i,{resolve:e,reject:t})}));case 5:return e.abrupt("return",JSON.parse(e.sent));case 7:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),n.notify=function(e,t){this.socket.send(JSON.stringify({method:e,params:t}))},n.open=function(e){var t=this;return new Promise((function(n){t.socket=new WebSocket(e),t.socket.addEventListener("open",(function e(){n(),t.socket.removeEventListener("open",e)})),t.socket.addEventListener("message",(function(e){return t.onMessageHandler(e.data)}))}))},n.close=function(){var e=i(g.mark((function e(){var t,n=this;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=new Promise((function(e){n.socket.addEventListener("close",(function(){return e()}))})),this.socket.close(1e3,"Normal Close"),e.abrupt("return",t);case 3:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),n.join=function(){var e=i(g.mark((function e(t,n,r){var i,a,o=this;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i={name:t,data:n,offer:r},e.next=3,this.call("join",i);case 3:return a=e.sent,this.isJoinCompleted=!0,this.pendingTrickle.forEach((function(e){return o.trickle(e)})),this.pendingTrickle.length=0,w.d(this.TAG,"join: response="+JSON.stringify(a,null,1)),e.abrupt("return",a);case 9:case"end":return e.stop()}}),e,this)})));return function(t,n,r){return e.apply(this,arguments)}}(),n.offer=function(){var e=i(g.mark((function e(t,n){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this.call("offer",{desc:t,tracks:n});case 3:return e.abrupt("return",e.sent);case 7:throw e.prev=7,e.t0=e.catch(0),e.t0;case 10:case"end":return e.stop()}}),e,this,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),n.answer=function(e){this.notify("answer",{desc:e})},n.trickle=function(e){this.isJoinCompleted?this.notify("trickle",e):this.pendingTrickle.push(e)},n.sendMessage=function(){var e=i(g.mark((function e(t){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.notify("broadcast",{version:"1.0",info:t});case 1:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.onMessageHandler=function(e){var t=JSON.parse(e);if(t.hasOwnProperty("id")){var n=t.id;if(this.callbacks.has(n)){var r=this.callbacks.get(n);if(this.callbacks.delete(n),t.result)r.resolve(JSON.stringify(t.result));else{var i=t.error,a=new q(i.code,i.message).build();r.reject(a)}}else this.observer.onNotification(t)}else{if(!t.hasOwnProperty("method"))throw Error("WebSocket message has no 'method' or 'id' field, message="+t);"offer"===t.method?this.observer.onOffer(t.params):"trickle"===t.method?this.observer.onTrickle(t.params):this.observer.onNotification(t)}},e}();function Z(e){return $.apply(this,arguments)}function $(){return($=i(g.mark((function e(t){return g.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 X(e){return ee.apply(this,arguments)}function ee(){return(ee=i(g.mark((function e(t){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,navigator.mediaDevices.getUserMedia({video:t.toConstraints()});case 2:return e.abrupt("return",e.sent.getVideoTracks()[0]);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var te=function(e){function t(t,n,r){var i;return i=e.call(this,t,n)||this,t.tracks.push(d(i)),i.settings=r,i}s(t,e);var n=t.prototype;return n.replaceTrackWith=function(){var e=i(g.mark((function e(t){var n;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Z(t);case 2:return n=e.sent,e.next=5,this.stream.replaceTrack(this,n);case 5:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.setEnabled=function(){var t=i(g.mark((function t(n){return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n!==this.enabled){t.next=2;break}return t.abrupt("return");case 2:return t.next=4,e.prototype.setEnabled.call(this,n);case 4:if(!n){t.next=9;break}return t.next=7,this.replaceTrackWith(this.settings);case 7:t.next=10;break;case 9:this.nativeTrack.stop();case 10:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.setSettings=function(){var e=i(g.mark((function e(t){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.settings.codec===t.codec){e.next=2;break}throw Error("Audio Codec can't be changed mid call.");case 2:if(this.settings.deviceId===t.deviceId){e.next=5;break}return e.next=5,this.replaceTrackWith(t);case 5:return e.next=7,this.nativeTrack.applyConstraints(t.toConstraints());case 7:this.settings=t;case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t}(j);function ne(e){if(e<=0)throw Error("`ms` should be a positive integer");return new Promise((function(t){return setTimeout(t,e)}))}var re,ie,ae,oe,se,ce=function(e){function t(t,n,r){var i;return i=e.call(this,t,n)||this,t.tracks.push(d(i)),i.settings=r,i}s(t,e);var n=t.prototype;return n.replaceTrackWith=function(){var e=i(g.mark((function e(t){var n;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,X(t);case 2:return n=e.sent,e.next=5,this.stream.replaceTrack(this,n);case 5:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.setEnabled=function(){var t=i(g.mark((function t(n){return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n!==this.enabled){t.next=2;break}return t.abrupt("return");case 2:return t.next=4,e.prototype.setEnabled.call(this,n);case 4:if(!n){t.next=9;break}return t.next=7,this.replaceTrackWith(this.settings);case 7:t.next=12;break;case 9:return t.next=11,ne(100);case 11:this.nativeTrack.stop();case 12:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.setSettings=function(){var e=i(g.mark((function e(t){return g.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}(J),ue=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).connection=null,t}s(t,e);var n=t.prototype;return n.setConnection=function(e){this.connection=e},t.getLocalScreen=function(){var e=i(g.mark((function e(n){var r,i,a,o,s;return g.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 ce(a,o,n),w.v("HMSLocalStream","getLocalScreen",s),e.abrupt("return",s);case 9:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),t.getLocalTracks=function(){var e=i(g.mark((function e(n){var r,i,a,o,s,c,u;return g.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 te(i,o,n.audio),a.push(s)),null!=n.video&&(c=r.getVideoTracks()[0],u=new ce(i,c,n.video),a.push(u)),w.v("HMSLocalStream","getLocalTracks",a),e.abrupt("return",a);case 9:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),n.addTransceiver=function(e){var t=this.connection.addTransceiver(e.nativeTrack,{streams:[this.nativeStream],direction:"sendonly",sendEncodings:void 0});return this.setPreferredCodec(t,e.nativeTrack.kind),t},n.setMaxBitrate=function(){var e=i(g.mark((function e(t,n){var r;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,null==(r=this.connection)?void 0:r.setMaxBitrate(t,n);case 2:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),n.setPreferredCodec=function(e,t){},n.replaceTrack=function(){var e=i(g.mark((function e(t,n){var r;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==(r=this.connection.getSenders().find((function(e){return e.track&&e.track.id===t.trackId})))){e.next=3;break}throw Error("No sender found for trackId="+t.trackId);case 3:return this.nativeStream.removeTrack(t.nativeTrack),r.track.stop(),e.next=7,r.replaceTrack(n);case 7:this.nativeStream.addTrack(n),t.nativeTrack=n;case 9:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),n.removeSender=function(e){var t=this,n=0;if(this.connection.getSenders().forEach((function(r){if(r.track&&r.track.id===e.trackId){t.connection.removeTrack(r),n+=1;var i=t.tracks.indexOf(e);if(-1===i)throw Error("Cannot find "+e+" in locally stored tracks");t.tracks.splice(i,1)}})),1!==n)throw Error("Removed "+n+" sender's, expected to remove 1")},t}(S),he="[HMSTransport]:",fe=function(){function e(e){var t,n,r,a=this;this.tracks={},this.publishConnection=null,this.subscribeConnection=null,this.callbacks=new Map,this.signalObserver={onOffer:(n=i(g.mark((function e(t){var n,r,i,o;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,a.subscribeConnection.setRemoteDescription(t);case 2:n=v(a.subscribeConnection.candidates);case 3:if((r=n()).done){e.next=9;break}return i=r.value,e.next=7,a.subscribeConnection.addIceCandidate(i);case 7:e.next=3;break;case 9:return a.subscribeConnection.candidates.length=0,e.next=12,a.subscribeConnection.createAnswer();case 12:return o=e.sent,e.next=15,a.subscribeConnection.setLocalDescription(o);case 15:a.signal.answer(o);case 16:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)}),onTrickle:(t=i(g.mark((function e(t){var n;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!==(n=t.target===b.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 z(this.signalObserver),this.publishConnectionObserver={onRenegotiationNeeded:(r=i(g.mark((function e(){var t,n,r;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return w.d(he,"⏳ [role=PUBLISH] onRenegotiationNeeded START",a.tracks),t=a.callbacks.get("renegotiation-callback-id"),a.callbacks.delete("renegotiation-callback-id"),e.prev=3,e.next=6,a.publishConnection.createOffer();case 6:return n=e.sent,e.next=9,a.publishConnection.setLocalDescription(n);case 9:return e.next=11,a.signal.offer(n,a.tracks);case 11:return r=e.sent,e.next=14,a.publishConnection.setRemoteDescription(r);case 14:null==t||t.resolve(!0),w.d(he,"✅ [role=PUBLISH] onRenegotiationNeeded DONE",a.tracks),e.next=21;break;case 18:e.prev=18,e.t0=e.catch(3),console.error(he,e.t0);case 21:case"end":return e.stop()}}),e,null,[[3,18]])}))),function(){return r.apply(this,arguments)}),onIceConnectionChange:function(e){}},this.subscribeConnectionObserver={onApiChannelMessage:function(e){var t={method:"active-speakers",params:JSON.parse(e)};a.observer.onNotification(t)},onTrackAdd:function(e){return a.observer.onTrackAdd(e)},onTrackRemove:function(e){return a.observer.onTrackRemove(e)},onIceConnectionChange:function(e){}},this.observer=e}var t=e.prototype;return t.getLocalScreen=function(){var e=i(g.mark((function e(t){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ue.getLocalScreen(t);case 2:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),t.getLocalTracks=function(){var e=i(g.mark((function e(t){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ue.getLocalTracks(t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),t.join=function(){var e=i(g.mark((function e(t,n,r){var i,a,o,s,c,u;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Y.fetchInitConfig(t);case 2:return w.d(he,"⏳ join: connecting to ws endpoint",(i=e.sent).endpoint),e.next=6,this.signal.open(i.endpoint+"?peer="+n+"&token="+t);case 6:return w.d(he,"✅ join: connected to ws endpoint"),w.d(he,r),this.publishConnection=new C(this.signal,i.rtcConfiguration,this.publishConnectionObserver),this.subscribeConnection=new W(this.signal,i.rtcConfiguration,this.subscribeConnectionObserver),w.d(he,"⏳ join: Negotiating over PUBLISH connection"),e.next=13,this.publishConnection.createOffer();case 13:return a=e.sent,e.next=16,this.publishConnection.setLocalDescription(a);case 16:return e.next=18,this.signal.join("dayamax",n,a,{a:6});case 18:return o=e.sent,e.next=21,this.publishConnection.setRemoteDescription(o);case 21:s=v(this.publishConnection.candidates);case 22:if((c=s()).done){e.next=28;break}return u=c.value,e.next=26,this.publishConnection.addIceCandidate(u);case 26:e.next=22;break;case 28:this.publishConnection.initAfterJoin(),w.d(he,"✅ join: Negotiated over PUBLISH connection"),w.d(he,"✅ join: successful");case 31:case"end":return e.stop()}}),e,this)})));return function(t,n,r){return e.apply(this,arguments)}}(),t.leave=function(){var e=i(g.mark((function e(){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.publishConnection.close();case 2:return e.next=4,this.subscribeConnection.close();case 4:return e.next=6,this.signal.close();case 6:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),t.publishTrack=function(){var e=i(g.mark((function e(t){var n,r,i=this;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return w.d(he,"⏳ publishTrack: trackId="+t.trackId,t),this.tracks[t.trackId]={mute:!1,type:t.nativeTrack.kind,source:"regular",description:"",track_id:t.trackId,stream_id:t.stream.id},n=new Promise((function(e,t){i.callbacks.set("renegotiation-callback-id",{resolve:e,reject:t})})),(r=t.stream).setConnection(this.publishConnection),r.addTransceiver(t),e.next=8,n;case 8:w.d(he,"✅ publishTrack: trackId="+t.trackId,this.callbacks);case 9:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.unpublishTrack=function(){var e=i(g.mark((function e(t){var n,r=this;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return w.d(he,"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:w.d(he,"unpublishTrack: trackId="+t.trackId+" ✅",this.callbacks);case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.publish=function(){var e=i(g.mark((function e(t){var n,r,i;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=v(t);case 1:if((r=n()).done){e.next=7;break}return i=r.value,e.next=5,this.publishTrack(i);case 5:e.next=1;break;case 7:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.unpublish=function(){var e=i(g.mark((function e(t){var n,r,i;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=v(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.sendMessage(e)},e}();(re=exports.HMSRoomUpdate||(exports.HMSRoomUpdate={}))[re.PEER_ADDED=0]="PEER_ADDED",re[re.PEER_REMOVED=1]="PEER_REMOVED",re[re.PEER_KNOCKED=2]="PEER_KNOCKED",re[re.ROOM_TYPE_CHANGED=3]="ROOM_TYPE_CHANGED",re[re.METADATA_UPDATED=4]="METADATA_UPDATED",re[re.SCREENSHARE_STARTED=5]="SCREENSHARE_STARTED",re[re.SCREENSHARE_STOPPED=6]="SCREENSHARE_STOPPED",re[re.DEFAULT_UPDATE=7]="DEFAULT_UPDATE",(ie=exports.HMSPeerUpdate||(exports.HMSPeerUpdate={}))[ie.PEER_JOINED=0]="PEER_JOINED",ie[ie.PEER_LEFT=1]="PEER_LEFT",ie[ie.AUDIO_TOGGLED=2]="AUDIO_TOGGLED",ie[ie.VIDEO_TOGGLED=3]="VIDEO_TOGGLED",(ae=exports.HMSTrackUpdate||(exports.HMSTrackUpdate={}))[ae.TRACK_ADDED=0]="TRACK_ADDED",ae[ae.TRACK_REMOVED=1]="TRACK_REMOVED",ae[ae.TRACK_MUTED=2]="TRACK_MUTED",ae[ae.TRACK_UNMUTED=3]="TRACK_UNMUTED",ae[ae.TRACK_DESCRIPTION_CHANGED=4]="TRACK_DESCRIPTION_CHANGED",function(e){e[e.PEER_JOIN=0]="PEER_JOIN",e[e.PEER_LEAVE=1]="PEER_LEAVE",e[e.PEER_LIST=2]="PEER_LIST",e[e.STREAM_ADD=3]="STREAM_ADD",e[e.ACTIVE_SPEAKERS=4]="ACTIVE_SPEAKERS",e[e.BROADCAST=5]="BROADCAST",e[e.ROLE_CHANGE=6]="ROLE_CHANGE",e[e.TRACK_ADD=7]="TRACK_ADD"}(oe||(oe={})),function(e){e.CHAT="chat"}(se||(se={}));var le=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 se.CHAT;switch(e){case"chat":return se.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},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||{})},pe=function(e){this.peers=Object.values(e.peers).map((function(e){return new de(e)}))},ve=function(e){var t=e.peerId,n=e.name,r=e.isLocal,i=e.customerDescription;this.customerDescription="",this.auxiliaryTracks=[],this.name=n,this.peerId=t,this.isLocal=r,this.customerDescription=i},ke=function(){function e(){var e=this;this.hmsPeerList=new Map,this.TAG="[Notification Manager]:",this.tracksToProcess=new Map,this.trackStateMap=new Map,this.handleOnTrackAdd=function(t){w.d(e.TAG,"ONTRACKADD",t),e.tracksToProcess.set(t.trackId,t),e.processPendingTracks()},this.handleOnTrackRemove=function(t){w.d(e.TAG,"ONTRACKREMOVE",t);var n=e.trackStateMap.get(t.trackId);if(n){var r=e.hmsPeerList.get(n.peerId);if(r){switch(t.type){case exports.HMSTrackType.AUDIO:r.audioTrack=null;break;case exports.HMSTrackType.VIDEO:var i=r.auxiliaryTracks.indexOf(t);i>-1?r.auxiliaryTracks.splice(i,1):r.videoTrack=null}e.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,t,r)}}},this.handleLeave=function(){e.hmsPeerList.clear()},this.findPeerByUID=function(t){return e.hmsPeerList.get(t)},this.handlePeerJoin=function(t){var n=new ve({peerId:t.peerId,name:t.info.name,isLocal:!1,customerDescription:""});e.hmsPeerList.set(t.peerId,n),t.tracks.forEach((function(n){e.trackStateMap.set(n.track_id,{peerId:t.peerId,trackInfo:n})})),e.processPendingTracks()},this.handlePeerLeave=function(t){e.hmsPeerList.delete(t.peerId)},this.handlePeerList=function(t){var n=t.peers;null==n||n.forEach((function(t){return e.handlePeerJoin(t)}))}}var t=e.prototype;return t.handleNotification=function(e,t,n){switch(this.listener=n,e){case oe.PEER_JOIN:var r=new de(t);w.d(this.TAG,"PEER_JOIN event",r),this.handlePeerJoin(r);break;case oe.PEER_LEAVE:var i=new de(t);w.d(this.TAG,"PEER_LEAVE event",i),this.handlePeerLeave(i);break;case oe.PEER_LIST:var a=t;w.d(this.TAG,"PEER_LIST event",a),this.handlePeerList(a);break;case oe.TRACK_ADD:this.handleTrackAdd(t);break;case oe.ACTIVE_SPEAKERS:default:return}},t.handleTrackAdd=function(e){w.d(this.TAG,"BIZ:ONTRACKADD",e);for(var t=0,n=Object.entries(e.tracks);t<n.length;t++){var r=n[t];this.trackStateMap.set(r[0],{peerId:e.peer.peer_id,trackInfo:r[1]})}this.processPendingTracks()},t.processPendingTracks=function(){var e=this;new Map(this.tracksToProcess).forEach((function(t){var n=e.trackStateMap.get(t.trackId);if(n){var r=e.hmsPeerList.get(n.peerId);if(r){switch(t.type){case exports.HMSTrackType.AUDIO:r.audioTrack=t;break;case exports.HMSTrackType.VIDEO:r.videoTrack=t}e.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_ADDED,t,r),e.tracksToProcess.delete(t.trackId)}}}))},e}(),me=function(e,t,n){this.id=e,this.name=t,this.peers=n};exports.HMSSdk=function(){function e(){var e=this;this.logLevel=k.OFF,this.analyticsLevel=m.OFF,this.TAG="[HMSSdk]:",this.notificationManager=new ke,this.published=!1,this.observer={onNotification:function(t){var n=function(e){switch(e){case"on-peer-join":return oe.PEER_JOIN;case"on-peer-leave":return oe.PEER_LEAVE;case"peer-list":return oe.PEER_LIST;case"stream-add":return oe.STREAM_ADD;case"on-track-add":return oe.TRACK_ADD;case"active-speakers":return oe.ACTIVE_SPEAKERS;case"on-broadcast":return oe.BROADCAST;case"on-role-change":return oe.ROLE_CHANGE;default:throw Error("Unsupported method="+e+" received")}}(t.method),r=function(e,t){switch(e){case oe.PEER_JOIN:case oe.PEER_LEAVE:return new de(t);case oe.PEER_LIST:return new pe(t);case oe.BROADCAST:return new le(t.info);case oe.ACTIVE_SPEAKERS:case oe.ROLE_CHANGE:return;case oe.TRACK_ADD:return t;default:throw Error("Unsupported method="+e+" received")}}(n,t.params);e.notificationManager.handleNotification(n,r,e.listener),e.onNotificationHandled(n,r)},onTrackAdd:function(t){e.notificationManager.handleOnTrackAdd(t)},onTrackRemove:function(t){e.notificationManager.handleOnTrackRemove(t)},onFailure:function(t){e.listener.onError(t)}},this.transport=new fe(this.observer)}var r=e.prototype;return r.join=function(e,r){var i=this;this.transport=new fe(this.observer),this.listener=r;var a=n.decode(e.authToken,{json:!0}).room_id,o=t.v4();this.localPeer=new ve({peerId:o,name:e.userName,isLocal:!0,customerDescription:e.metaData}),w.d(this.TAG,"⏳ Joining room "+a),this.transport.join(e.authToken,this.localPeer.peerId,{name:e.userName}).then((function(){w.d(i.TAG,"✅ Joined room "+a),i.roomId=a,i.published||i.publish()}))},r.leave=function(){var e=i(g.mark((function e(){var t,n;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.roomId&&(w.d(this.TAG,"⏳ Leaving room "+this.roomId),null==(t=this.localPeer.audioTrack)||t.nativeTrack.stop(),null==(n=this.localPeer.videoTrack)||n.nativeTrack.stop(),this.notificationManager.handleLeave(),this.transport.leave(),w.d(this.TAG,"✅ Left room "+this.roomId),this.roomId=null);case 1:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),r.getLocalPeer=function(){return this.localPeer},r.getPeers=function(){var e=Array.from(this.notificationManager.hmsPeerList,(function(e){return e[1]})),t=[].concat(e,[this.getLocalPeer()]);return w.d(this.TAG,"Got peers",t),t},r.sendMessage=function(e,t,n){var r=new le({sender:this.localPeer.peerId,type:e,message:t,receiver:n});return w.d(this.TAG,"Sending Message:: ",r),this.transport.sendMessage(r),r},r.startScreenShare=function(){var e=i(g.mark((function e(t){var n,r,i=this;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(((null==(n=this.localPeer.auxiliaryTracks)?void 0:n.length)||0)>0)){e.next=2;break}throw Error("Cannot share multiple screens");case 2:return e.next=4,this.transport.getLocalScreen(M.HD);case 4:return(r=e.sent).nativeTrack.onended=function(){i.stopEndedScreenshare(t)},e.next=8,this.transport.publish([r]);case 8:this.localPeer.auxiliaryTracks=[r];case 9:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.stopEndedScreenshare=function(){var e=i(g.mark((function e(t){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return w.d(this.TAG,"✅ Screenshare ended natively"),e.next=3,this.stopScreenShare();case 3:t();case 4:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.stopScreenShare=function(){var e=i(g.mark((function e(){var t;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return w.d(this.TAG,"✅ Screenshare ended from app"),t=this.localPeer.auxiliaryTracks[0],e.next=4,t.setEnabled(!1);case 4:this.transport.unpublish([t]),this.localPeer.auxiliaryTracks.length=0;case 6:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),r.onNotificationHandled=function(e,t){var n,r,i=this;switch(w.d(this.TAG,"onNotificationHandled",e),e){case oe.PEER_JOIN:(r=this.notificationManager.findPeerByUID((n=t).peerId))?this.listener.onPeerUpdate(exports.HMSPeerUpdate.PEER_JOINED,r):w.e(this.TAG,"⚠️ peer not found in peer-list",n,this.notificationManager.hmsPeerList);break;case oe.PEER_LEAVE:var a,o=new ve({peerId:t.peerId,name:t.info.name,isLocal:!1,customerDescription:t.info.data});o.audioTrack&&this.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,o.audioTrack,o),o.videoTrack&&this.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,o.videoTrack,o),null==(a=o.auxiliaryTracks)||a.forEach((function(e){i.listener.onTrackUpdate(exports.HMSTrackUpdate.TRACK_REMOVED,e,o)})),this.listener.onPeerUpdate(exports.HMSPeerUpdate.PEER_LEFT,o);break;case oe.PEER_LIST:this.listener.onJoin(this.createRoom());break;case oe.ROLE_CHANGE:this.roomId&&this.publish();break;case oe.STREAM_ADD:case oe.ACTIVE_SPEAKERS:return;case oe.BROADCAST:var s=t;w.d(this.TAG,"Received Message:: ",s),this.listener.onMessageReceived(s)}},r.publish=function(){var e=this;this.transport.getLocalTracks((new N).build()).then(function(){var t=i(g.mark((function t(n){return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n.forEach((function(t){switch(t.type){case exports.HMSTrackType.AUDIO:e.localPeer.audioTrack=t;break;case exports.HMSTrackType.VIDEO:e.localPeer.videoTrack=t}})),t.next=3,e.transport.publish(n);case 3:e.published=!0;case 4:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())},r.createRoom=function(){var e=this.getPeers();return this.hmsRoom=new me(this.localPeer.peerId,"",e),this.hmsRoom},e}(); | ||
//# sourceMappingURL=100ms-web-sdk.cjs.production.min.js.map |
import HMSConfig from './config'; | ||
import HMSUpdateListener from './update-listener'; | ||
import HMSPeer from './hms-peer'; | ||
import HMSMessage, { HMSMessageListener } from './message'; | ||
import HMSMessage from './message'; | ||
export declare enum HMSlogLevel { | ||
@@ -25,6 +25,5 @@ OFF = 0, | ||
getPeers(): HMSPeer[]; | ||
sendMessage(message: HMSMessage): void; | ||
onMessageReceived(callback: HMSMessageListener): void; | ||
sendMessage(type: string, message: string, receiver?: string): HMSMessage; | ||
startScreenShare(onStop: () => void): void; | ||
stopScreenShare(): void; | ||
} |
@@ -1,10 +0,8 @@ | ||
export declare enum HMSMessageType { | ||
CHAT = 0 | ||
} | ||
import { HMSMessageType } from '../sdk/models/enums/HMSMessageType'; | ||
export default interface HMSMessage { | ||
sender: string; | ||
receiver: string; | ||
receiver?: string; | ||
time: Date; | ||
type: HMSMessageType; | ||
mesage: string; | ||
message: string; | ||
} | ||
@@ -11,0 +9,0 @@ export interface HMSMessageListener { |
import HMSException from '../error/HMSException'; | ||
import HMSTrack from '../media/tracks/HMSTrack'; | ||
import HMSPeer from './hms-peer'; | ||
import HMSMessage from './message'; | ||
import HMSRoom from './room'; | ||
@@ -33,3 +34,4 @@ export declare enum HMSRoomUpdate { | ||
onTrackUpdate(type: HMSTrackUpdate, track: HMSTrack, peer: HMSPeer): void; | ||
onMessageReceived(message: HMSMessage): void; | ||
onError(error: HMSException): void; | ||
} |
import HMSVideoTrackSettings from './HMSVideoTrackSettings'; | ||
import HMSAudioTrackSettings from './HMSAudioTrackSettings'; | ||
export declare const DefaultVideoSettings: { | ||
QVGA: HMSVideoTrackSettings; | ||
VGA: HMSVideoTrackSettings; | ||
SHD: HMSVideoTrackSettings; | ||
HD: HMSVideoTrackSettings; | ||
FHD: HMSVideoTrackSettings; | ||
QHD: HMSVideoTrackSettings; | ||
}; | ||
export declare class HMSTrackSettingsBuilder { | ||
@@ -4,0 +12,0 @@ private _video; |
@@ -1,3 +0,7 @@ | ||
import { HMSVideoResolution } from './index'; | ||
import { HMSVideoCodec } from '../codec'; | ||
export declare class HMSVideoResolution { | ||
readonly width: number; | ||
readonly height: number; | ||
constructor(width: number, height: number); | ||
} | ||
export declare class HMSVideoTrackSettingsBuilder { | ||
@@ -4,0 +8,0 @@ private _resolution; |
@@ -7,14 +7,2 @@ export declare enum HMSSimulcastLayer { | ||
} | ||
export declare class HMSVideoResolution { | ||
readonly width: number; | ||
readonly height: number; | ||
constructor(width: number, height: number); | ||
} | ||
export declare const DefaultVideoSettings: { | ||
QVGA: import("./HMSVideoTrackSettings").default; | ||
VGA: import("./HMSVideoTrackSettings").default; | ||
SHD: import("./HMSVideoTrackSettings").default; | ||
HD: import("./HMSVideoTrackSettings").default; | ||
FHD: import("./HMSVideoTrackSettings").default; | ||
QHD: import("./HMSVideoTrackSettings").default; | ||
}; | ||
export { DefaultVideoSettings } from './HMSTrackSettings'; |
@@ -6,3 +6,3 @@ import HMSTrack from './HMSTrack'; | ||
readonly type: HMSTrackType; | ||
protected constructor(stream: HMSMediaStream, track: MediaStreamTrack); | ||
constructor(stream: HMSMediaStream, track: MediaStreamTrack); | ||
} |
import HMSAudioTrack from './HMSAudioTrack'; | ||
import HMSRemoteStream from '../streams/HMSRemoteStream'; | ||
export default class HMSRemoteAudioTrack extends HMSAudioTrack { | ||
constructor(stream: HMSRemoteStream, track: MediaStreamTrack); | ||
setEnabled(value: boolean): Promise<void>; | ||
} |
import HMSVideoTrack from './HMSVideoTrack'; | ||
import HMSRemoteStream from '../streams/HMSRemoteStream'; | ||
export default class HMSRemoteVideoTrack extends HMSVideoTrack { | ||
constructor(stream: HMSRemoteStream, track: MediaStreamTrack); | ||
setEnabled(value: boolean): Promise<void>; | ||
} |
@@ -6,3 +6,3 @@ import HMSTrack from './HMSTrack'; | ||
readonly type: HMSTrackType; | ||
protected constructor(stream: HMSMediaStream, track: MediaStreamTrack); | ||
constructor(stream: HMSMediaStream, track: MediaStreamTrack); | ||
} |
import HMSConfig from '../interfaces/config'; | ||
import HMSInterface, { HMSAnalyticsLevel, HMSlogLevel } from '../interfaces/hms'; | ||
import HMSMessage, { HMSMessageListener } from '../interfaces/message'; | ||
import HMSPeer from '../interfaces/hms-peer'; | ||
@@ -10,2 +9,3 @@ import HMSTransport from '../transport'; | ||
import HMSRoom from './models/HMSRoom'; | ||
import Message from './models/HMSMessage'; | ||
export declare class HMSSdk implements HMSInterface { | ||
@@ -21,2 +21,3 @@ logLevel: HMSlogLevel; | ||
private hmsRoom?; | ||
private published; | ||
private observer; | ||
@@ -28,8 +29,9 @@ constructor(); | ||
getPeers(): HMSPeer[]; | ||
sendMessage(message: HMSMessage): void; | ||
onMessageReceived(cb: HMSMessageListener): void; | ||
sendMessage(type: string, message: string, receiver?: string): Message; | ||
startScreenShare(onStop: () => void): Promise<void>; | ||
private stopEndedScreenshare; | ||
stopScreenShare(): Promise<void>; | ||
onNotificationHandled(method: HMSNotificationMethod, notification: HMSNotifications): void; | ||
private publish; | ||
createRoom(): HMSRoom; | ||
} |
@@ -6,4 +6,7 @@ export declare enum HMSNotificationMethod { | ||
STREAM_ADD = 3, | ||
ACTIVE_SPEAKERS = 4 | ||
ACTIVE_SPEAKERS = 4, | ||
BROADCAST = 5, | ||
ROLE_CHANGE = 6, | ||
TRACK_ADD = 7 | ||
} | ||
export declare const getNotificationMethod: (method: string) => HMSNotificationMethod; |
import { HMSNotificationMethod } from './enums/HMSNotificationMethod'; | ||
import PeerInfo from './PeerInfo'; | ||
export declare type HMSNotifications = Peer | Stream | PeerList | undefined; | ||
export declare class Peer { | ||
uid: string; | ||
sid: string; | ||
info: PeerInfo; | ||
constructor(params: any); | ||
import Message from './HMSMessage'; | ||
export declare type HMSNotifications = Peer | PeerList | Message | TrackStateNotification | undefined; | ||
export interface TrackStateNotification { | ||
tracks: Map<string, TrackState>; | ||
peer: PeerNotificationInfo; | ||
} | ||
export declare class StreamInternal { | ||
uid: string; | ||
streamId: string; | ||
constructor(params: any); | ||
export interface PeerNotificationInfo { | ||
peer_id: string; | ||
info: Info; | ||
} | ||
export declare class Stream { | ||
uid: string; | ||
stream: StreamInternal; | ||
streamId: string; | ||
export interface Info { | ||
name: string; | ||
data: string; | ||
userId: string; | ||
} | ||
export interface TrackState { | ||
mute: boolean; | ||
type: string; | ||
source: string; | ||
description: string; | ||
track_id: string; | ||
stream_id: string; | ||
} | ||
export declare class Peer { | ||
peerId: string; | ||
info: Info; | ||
role: string; | ||
tracks: TrackState[]; | ||
constructor(params: any); | ||
@@ -23,5 +34,4 @@ } | ||
peers: Peer[]; | ||
streams: StreamInternal[]; | ||
constructor(params: any); | ||
} | ||
export declare const getNotification: (method: HMSNotificationMethod, params: any) => Peer | Stream | PeerList | undefined; | ||
export declare const getNotification: (method: HMSNotificationMethod, params: any) => any; |
import HMSTrack from '../media/tracks/HMSTrack'; | ||
import Peer from '../peer'; | ||
import { HMSNotificationMethod } from './models/enums/HMSNotificationMethod'; | ||
import { HMSNotifications } from './models/HMSNotifications'; | ||
import { HMSNotifications, TrackStateNotification } from './models/HMSNotifications'; | ||
import HMSPeer from '../interfaces/hms-peer'; | ||
import HMSUpdateListener from '../interfaces/update-listener'; | ||
export default class NotificationManager { | ||
hmsPeerList: Peer[]; | ||
hmsPeerList: Map<string, HMSPeer>; | ||
private TAG; | ||
private streamIdToUIDMap; | ||
private streamIdToTrackMap; | ||
handleNotification: (method: HMSNotificationMethod, notification: HMSNotifications) => void; | ||
private tracksToProcess; | ||
private trackStateMap; | ||
private listener; | ||
handleNotification(method: HMSNotificationMethod, notification: HMSNotifications, listener: HMSUpdateListener): void; | ||
handleTrackAdd(params: TrackStateNotification): void; | ||
private processPendingTracks; | ||
/** | ||
* Sets the tracks to peer and returns the peer | ||
*/ | ||
handleOnTrackAdd: (track: HMSTrack) => Peer | null | undefined; | ||
handleOnTrackAdd: (track: HMSTrack) => void; | ||
/** | ||
* Sets the track of corresponding peer to null and returns the peer | ||
*/ | ||
handleOnTrackRemove: (track: HMSTrack) => "" | Peer | undefined; | ||
handleOnTrackRemove: (track: HMSTrack) => void; | ||
handleLeave: () => void; | ||
findPeerByUID: (uid: string) => Peer | undefined; | ||
findPeerByUID: (uid: string) => HMSPeer | undefined; | ||
private handlePeerJoin; | ||
private handlePeerLeave; | ||
private handlePeerList; | ||
private handleStreamAdd; | ||
} |
import { HMSTrickle } from '../connection/model'; | ||
import HMSMessage from '../interfaces/message'; | ||
import { ISignalEventsObserver } from './ISignalEventsObserver'; | ||
@@ -12,5 +13,6 @@ export interface ISignal { | ||
join(roomId: string, uid: string, offer: RTCSessionDescriptionInit, info: Object): Promise<RTCSessionDescriptionInit>; | ||
offer(offer: RTCSessionDescriptionInit): Promise<RTCSessionDescriptionInit>; | ||
offer(offer: RTCSessionDescriptionInit, tracks: Map<string, any>): Promise<RTCSessionDescriptionInit>; | ||
answer(answer: RTCSessionDescriptionInit): void; | ||
trickle(trickle: HMSTrickle): void; | ||
sendMessage(message: HMSMessage): void; | ||
} |
import { ISignal } from '../ISignal'; | ||
import { ISignalEventsObserver } from '../ISignalEventsObserver'; | ||
import { HMSTrickle } from '../../connection/model'; | ||
import HMSMessage from '../../interfaces/message'; | ||
export default class JsonRpcSignal implements ISignal { | ||
@@ -24,7 +25,8 @@ private readonly TAG; | ||
close(): Promise<void>; | ||
join(sid: string, uid: string, offer: RTCSessionDescriptionInit, info: Object): Promise<RTCSessionDescriptionInit>; | ||
offer(offer: RTCSessionDescriptionInit): Promise<RTCSessionDescriptionInit>; | ||
join(name: string, data: string, offer: RTCSessionDescriptionInit): Promise<RTCSessionDescriptionInit>; | ||
offer(desc: RTCSessionDescriptionInit, tracks: Map<string, any>): Promise<RTCSessionDescriptionInit>; | ||
answer(answer: RTCSessionDescriptionInit): void; | ||
trickle(trickle: HMSTrickle): void; | ||
sendMessage(message: HMSMessage): Promise<void>; | ||
private onMessageHandler; | ||
} |
@@ -6,3 +6,5 @@ import ITransportObserver from './ITransportObserver'; | ||
import HMSVideoTrackSettings from '../media/settings/HMSVideoTrackSettings'; | ||
import HMSMessage from '../interfaces/message'; | ||
export default class HMSTransport implements ITransport { | ||
private tracks; | ||
private readonly observer; | ||
@@ -22,5 +24,5 @@ private publishConnection; | ||
constructor(observer: ITransportObserver); | ||
getLocalScreen(settings: HMSVideoTrackSettings, onStop: () => void): Promise<HMSTrack>; | ||
getLocalScreen(settings: HMSVideoTrackSettings): Promise<HMSTrack>; | ||
getLocalTracks(settings: HMSTrackSettings): Promise<Array<HMSTrack>>; | ||
join(authToken: string, roomId: string, peerId: string, customData: Object): Promise<void>; | ||
join(authToken: string, peerId: string, customData: Object): Promise<void>; | ||
leave(): Promise<void>; | ||
@@ -31,2 +33,3 @@ private publishTrack; | ||
unpublish(tracks: Array<HMSTrack>): Promise<void>; | ||
sendMessage(message: HMSMessage): void; | ||
} |
{ | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"license": "UNLICENSED", | ||
@@ -35,11 +35,11 @@ "main": "dist/index.js", | ||
"author": "Praveen <praveen@100ms.live>", | ||
"module": "dist/hmsvideo-web.esm.js", | ||
"module": "dist/100ms-web-sdk.esm.js", | ||
"size-limit": [ | ||
{ | ||
"path": "dist/hmsvideo-web.cjs.production.min.js", | ||
"limit": "10 KB" | ||
"path": "dist/100ms-web-sdk.cjs.production.min.js", | ||
"limit": "250 KB" | ||
}, | ||
{ | ||
"path": "dist/hmsvideo-web.esm.js", | ||
"limit": "10 KB" | ||
"path": "dist/100ms-web-sdk.esm.js", | ||
"limit": "250 KB" | ||
} | ||
@@ -49,2 +49,3 @@ ], | ||
"@size-limit/preset-small-lib": "^4.10.2", | ||
"@types/jsonwebtoken": "^8.5.1", | ||
"@types/node": "^14.14.37", | ||
@@ -54,2 +55,4 @@ "@types/node-fetch": "^2.5.10", | ||
"husky": "^6.0.0", | ||
"jest-websocket-mock": "^2.2.0", | ||
"mock-socket": "^9.0.3", | ||
"prettier": "2.2.1", | ||
@@ -59,4 +62,3 @@ "size-limit": "^4.10.2", | ||
"tslib": "^2.2.0", | ||
"typescript": "^4.2.3", | ||
"@types/jsonwebtoken": "^8.5.1" | ||
"typescript": "^4.2.3" | ||
}, | ||
@@ -63,0 +65,0 @@ "dependencies": { |
@@ -34,5 +34,9 @@ import { HMSConnectionRole } from './model'; | ||
async createOffer(options: RTCOfferOptions | undefined = undefined): Promise<RTCSessionDescriptionInit> { | ||
const offer = await this.nativeConnection.createOffer(options); | ||
HMSLogger.d(TAG, `[role=${this.role}] createOffer offer=${JSON.stringify(offer, null, 1)}`); | ||
return offer; | ||
try { | ||
const offer = await this.nativeConnection.createOffer(options); | ||
HMSLogger.d(TAG, `[role=${this.role}] createOffer offer=${JSON.stringify(offer, null, 1)}`); | ||
return offer; | ||
} catch (e) { | ||
throw e; | ||
} | ||
} | ||
@@ -52,4 +56,8 @@ | ||
async setRemoteDescription(description: RTCSessionDescriptionInit): Promise<void> { | ||
HMSLogger.d(TAG, `[role=${this.role}] setRemoteDescription description=${JSON.stringify(description, null, 1)}`); | ||
await this.nativeConnection.setRemoteDescription(description); | ||
try { | ||
HMSLogger.d(TAG, `[role=${this.role}] setRemoteDescription description=${JSON.stringify(description, null, 1)}`); | ||
await this.nativeConnection.setRemoteDescription(description); | ||
} catch (e) { | ||
throw e; | ||
} | ||
} | ||
@@ -56,0 +64,0 @@ |
import HMSConfig from './config'; | ||
import HMSUpdateListener from './update-listener'; | ||
import HMSPeer from './hms-peer'; | ||
import HMSMessage, { HMSMessageListener } from './message'; | ||
import HMSMessage from './message'; | ||
@@ -28,6 +28,5 @@ export enum HMSlogLevel { | ||
getPeers(): HMSPeer[]; | ||
sendMessage(message: HMSMessage): void; | ||
onMessageReceived(callback: HMSMessageListener): void; | ||
sendMessage(type: string, message: string, receiver?: string): HMSMessage; | ||
startScreenShare(onStop: () => void): void; | ||
stopScreenShare(): void; | ||
} |
@@ -1,11 +0,9 @@ | ||
export enum HMSMessageType { | ||
CHAT, | ||
} | ||
import { HMSMessageType } from '../sdk/models/enums/HMSMessageType'; | ||
export default interface HMSMessage { | ||
sender: string; | ||
receiver: string; | ||
receiver?: string; | ||
time: Date; | ||
type: HMSMessageType; | ||
mesage: string; | ||
message: string; | ||
} | ||
@@ -12,0 +10,0 @@ |
import HMSException from '../error/HMSException'; | ||
import HMSTrack from '../media/tracks/HMSTrack'; | ||
import HMSPeer from './hms-peer'; | ||
import HMSMessage from './message'; | ||
import HMSRoom from './room'; | ||
@@ -37,3 +38,4 @@ | ||
onTrackUpdate(type: HMSTrackUpdate, track: HMSTrack, peer: HMSPeer): void; | ||
onMessageReceived(message: HMSMessage): void; | ||
onError(error: HMSException): void; | ||
} |
@@ -1,5 +0,13 @@ | ||
import HMSVideoTrackSettings from './HMSVideoTrackSettings'; | ||
import HMSVideoTrackSettings, { HMSVideoTrackSettingsBuilder, HMSVideoResolution } from './HMSVideoTrackSettings'; | ||
import HMSAudioTrackSettings, { HMSAudioTrackSettingsBuilder } from './HMSAudioTrackSettings'; | ||
import { DefaultVideoSettings } from './index'; | ||
export const DefaultVideoSettings = { | ||
QVGA: new HMSVideoTrackSettingsBuilder().resolution(new HMSVideoResolution(320, 180)).maxBitRate(150_000).build(), | ||
VGA: new HMSVideoTrackSettingsBuilder().resolution(new HMSVideoResolution(640, 360)).maxBitRate(500_000).build(), | ||
SHD: new HMSVideoTrackSettingsBuilder().resolution(new HMSVideoResolution(960, 540)).maxBitRate(1_200_000).build(), | ||
HD: new HMSVideoTrackSettingsBuilder().resolution(new HMSVideoResolution(1280, 720)).maxBitRate(2_500_000).build(), | ||
FHD: new HMSVideoTrackSettingsBuilder().resolution(new HMSVideoResolution(1920, 1080)).maxBitRate(4_000_000).build(), | ||
QHD: new HMSVideoTrackSettingsBuilder().resolution(new HMSVideoResolution(2560, 1440)).maxBitRate(8_000_000).build(), | ||
}; | ||
export class HMSTrackSettingsBuilder { | ||
@@ -6,0 +14,0 @@ private _video: HMSVideoTrackSettings | null = DefaultVideoSettings.QVGA; |
@@ -1,4 +0,16 @@ | ||
import { HMSVideoResolution } from './index'; | ||
import { HMSVideoCodec } from '../codec'; | ||
export class HMSVideoResolution { | ||
readonly width: number; | ||
readonly height: number; | ||
constructor(width: number, height: number) { | ||
if (width <= 0) throw Error('Height should be >= 1'); | ||
if (height <= 0) throw Error('Height should be >= 1'); | ||
this.width = width; | ||
this.height = height; | ||
} | ||
} | ||
export class HMSVideoTrackSettingsBuilder { | ||
@@ -5,0 +17,0 @@ private _resolution: HMSVideoResolution = new HMSVideoResolution(320, 180); |
@@ -1,3 +0,1 @@ | ||
import { HMSVideoTrackSettingsBuilder } from './HMSVideoTrackSettings'; | ||
export enum HMSSimulcastLayer { | ||
@@ -9,23 +7,2 @@ NONE = 'none', | ||
} | ||
export class HMSVideoResolution { | ||
readonly width: number; | ||
readonly height: number; | ||
constructor(width: number, height: number) { | ||
if (width <= 0) throw Error('Height should be >= 1'); | ||
if (height <= 0) throw Error('Height should be >= 1'); | ||
this.width = width; | ||
this.height = height; | ||
} | ||
} | ||
export const DefaultVideoSettings = { | ||
QVGA: new HMSVideoTrackSettingsBuilder().resolution(new HMSVideoResolution(320, 180)).maxBitRate(150_000).build(), | ||
VGA: new HMSVideoTrackSettingsBuilder().resolution(new HMSVideoResolution(640, 360)).maxBitRate(500_000).build(), | ||
SHD: new HMSVideoTrackSettingsBuilder().resolution(new HMSVideoResolution(960, 540)).maxBitRate(1_200_000).build(), | ||
HD: new HMSVideoTrackSettingsBuilder().resolution(new HMSVideoResolution(1280, 720)).maxBitRate(2_500_000).build(), | ||
FHD: new HMSVideoTrackSettingsBuilder().resolution(new HMSVideoResolution(1920, 1080)).maxBitRate(4_000_000).build(), | ||
QHD: new HMSVideoTrackSettingsBuilder().resolution(new HMSVideoResolution(2560, 1440)).maxBitRate(8_000_000).build(), | ||
}; | ||
export { DefaultVideoSettings } from './HMSTrackSettings'; |
@@ -21,6 +21,2 @@ import HMSMediaStream from './HMSMediaStream'; | ||
constructor(nativeStream: MediaStream) { | ||
super(nativeStream); | ||
} | ||
static async getLocalScreen(settings: HMSVideoTrackSettings) { | ||
@@ -115,3 +111,3 @@ const constraints = { | ||
}); | ||
if (removedSenderCount != 1) { | ||
if (removedSenderCount !== 1) { | ||
throw Error(`Removed ${removedSenderCount} sender's, expected to remove 1`); | ||
@@ -118,0 +114,0 @@ } |
@@ -8,3 +8,3 @@ import HMSTrack from './HMSTrack'; | ||
protected constructor(stream: HMSMediaStream, track: MediaStreamTrack) { | ||
constructor(stream: HMSMediaStream, track: MediaStreamTrack) { | ||
super(stream, track); | ||
@@ -11,0 +11,0 @@ if (track.kind !== 'audio') throw new Error("Expected 'track' kind = 'audio'"); |
@@ -5,6 +5,2 @@ import HMSAudioTrack from './HMSAudioTrack'; | ||
export default class HMSRemoteAudioTrack extends HMSAudioTrack { | ||
constructor(stream: HMSRemoteStream, track: MediaStreamTrack) { | ||
super(stream, track); | ||
} | ||
async setEnabled(value: boolean): Promise<void> { | ||
@@ -11,0 +7,0 @@ if (value === this.enabled) return; |
@@ -5,6 +5,2 @@ import HMSVideoTrack from './HMSVideoTrack'; | ||
export default class HMSRemoteVideoTrack extends HMSVideoTrack { | ||
constructor(stream: HMSRemoteStream, track: MediaStreamTrack) { | ||
super(stream, track); | ||
} | ||
async setEnabled(value: boolean): Promise<void> { | ||
@@ -11,0 +7,0 @@ if (value === this.enabled) return; |
@@ -8,3 +8,3 @@ import HMSTrack from './HMSTrack'; | ||
protected constructor(stream: HMSMediaStream, track: MediaStreamTrack) { | ||
constructor(stream: HMSMediaStream, track: MediaStreamTrack) { | ||
super(stream, track); | ||
@@ -11,0 +11,0 @@ if (track.kind !== 'video') throw new Error("Expected 'track' kind = 'video'"); |
import HMSConfig from '../interfaces/config'; | ||
import HMSInterface, { HMSAnalyticsLevel, HMSlogLevel } from '../interfaces/hms'; | ||
import HMSMessage, { HMSMessageListener } from '../interfaces/message'; | ||
import HMSPeer from '../interfaces/hms-peer'; | ||
@@ -21,2 +20,3 @@ import HMSTransport from '../transport'; | ||
import { DefaultVideoSettings } from '../media/settings'; | ||
import Message from './models/HMSMessage'; | ||
@@ -26,10 +26,11 @@ export class HMSSdk implements HMSInterface { | ||
analyticsLevel: HMSAnalyticsLevel = HMSAnalyticsLevel.OFF; | ||
transport: HMSTransport; | ||
transport!: HMSTransport; | ||
roomId!: string | null; | ||
localPeer!: HMSPeer; | ||
private TAG: string = 'HMSSdk'; | ||
private TAG: string = '[HMSSdk]:'; | ||
private notificationManager: NotificationManager = new NotificationManager(); | ||
private listener!: HMSUpdateListener; | ||
private hmsRoom?: HMSRoom; | ||
private published: Boolean = false; | ||
@@ -39,9 +40,4 @@ private observer: ITransportObserver = { | ||
const method = getNotificationMethod(message!.method); | ||
// TODO: WRITE CODE FOR THIS | ||
if (method === HMSNotificationMethod.ACTIVE_SPEAKERS) return; | ||
const notification = getNotification(method, message!.params); | ||
this.notificationManager.handleNotification(method, notification); | ||
this.notificationManager.handleNotification(method, notification, this.listener); | ||
this.onNotificationHandled(method, notification); | ||
@@ -51,13 +47,7 @@ }, | ||
onTrackAdd: (track: HMSTrack) => { | ||
const hmsPeer = this.notificationManager.handleOnTrackAdd(track); | ||
hmsPeer | ||
? this.listener.onTrackUpdate(HMSTrackUpdate.TRACK_ADDED, track, hmsPeer) | ||
: HMSLogger.d(this.TAG, `No Peer found for added track:: ${track}`); | ||
this.notificationManager.handleOnTrackAdd(track); | ||
}, | ||
onTrackRemove: (track: HMSTrack) => { | ||
const hmsPeer = this.notificationManager.handleOnTrackRemove(track); | ||
hmsPeer | ||
? this.listener.onTrackUpdate(HMSTrackUpdate.TRACK_REMOVED, track, hmsPeer) | ||
: HMSLogger.d(this.TAG, `No Peer found for added track:: ${track}`); | ||
this.notificationManager.handleOnTrackRemove(track); | ||
}, | ||
@@ -75,2 +65,3 @@ | ||
join(config: HMSConfig, listener: HMSUpdateListener) { | ||
this.transport = new HMSTransport(this.observer); | ||
this.listener = listener; | ||
@@ -80,3 +71,2 @@ | ||
// @TODO: This should be part of Peer class | ||
const peerId = uuidv4(); | ||
@@ -86,5 +76,10 @@ | ||
this.transport.join(config.authToken, roomId, this.localPeer.peerId, { name: config.userName }).then(() => { | ||
console.log('JOINED!', roomId); | ||
HMSLogger.d(this.TAG, `⏳ Joining room ${roomId}`); | ||
this.transport.join(config.authToken, this.localPeer.peerId, { name: config.userName }).then(() => { | ||
HMSLogger.d(this.TAG, `✅ Joined room ${roomId}`); | ||
this.roomId = roomId; | ||
if (!this.published) { | ||
this.publish(); | ||
} | ||
}); | ||
@@ -95,2 +90,3 @@ } | ||
if (this.roomId) { | ||
HMSLogger.d(this.TAG, `⏳ Leaving room ${this.roomId}`); | ||
this.localPeer.audioTrack?.nativeTrack.stop(); | ||
@@ -100,2 +96,3 @@ this.localPeer.videoTrack?.nativeTrack.stop(); | ||
this.transport.leave(); | ||
HMSLogger.d(this.TAG, `✅ Left room ${this.roomId}`); | ||
this.roomId = null; | ||
@@ -110,15 +107,15 @@ } | ||
getPeers(): HMSPeer[] { | ||
return [...this.notificationManager.hmsPeerList, this.localPeer]; | ||
const remotePeers = Array.from(this.notificationManager.hmsPeerList, (x) => x[1]); | ||
const peers = [...remotePeers, this.getLocalPeer()]; | ||
HMSLogger.d(this.TAG, `Got peers`, peers); | ||
return peers; | ||
} | ||
sendMessage(message: HMSMessage) { | ||
console.log(message); | ||
throw 'Yet to implement'; | ||
sendMessage(type: string, message: string, receiver?: string) { | ||
const hmsMessage = new Message({ sender: this.localPeer.peerId, type, message, receiver }); | ||
HMSLogger.d(this.TAG, 'Sending Message:: ', hmsMessage); | ||
this.transport.sendMessage(hmsMessage); | ||
return hmsMessage; | ||
} | ||
onMessageReceived(cb: HMSMessageListener) { | ||
console.log(cb); | ||
throw 'Yet to implement'; | ||
} | ||
async startScreenShare(onStop: () => void) { | ||
@@ -131,4 +128,6 @@ // TODO: add optional arguments `settings` | ||
const track = await this.transport.getLocalScreen(DefaultVideoSettings.HD, onStop); | ||
const track = await this.transport.getLocalScreen(DefaultVideoSettings.HD); | ||
track.nativeTrack.onended = () => { | ||
this.stopEndedScreenshare(onStop); | ||
}; | ||
await this.transport.publish([track]); | ||
@@ -138,4 +137,11 @@ this.localPeer.auxiliaryTracks = [track]; | ||
private async stopEndedScreenshare(onStop: () => void) { | ||
HMSLogger.d(this.TAG, `✅ Screenshare ended natively`); | ||
await this.stopScreenShare(); | ||
onStop(); | ||
} | ||
async stopScreenShare() { | ||
// TODO: Right now we assume for now that there is only one aux track -- screen-share | ||
HMSLogger.d(this.TAG, `✅ Screenshare ended from app`); | ||
const track = this.localPeer.auxiliaryTracks![0]; | ||
@@ -148,2 +154,3 @@ await track.setEnabled(false); | ||
onNotificationHandled(method: HMSNotificationMethod, notification: HMSNotifications) { | ||
HMSLogger.d(this.TAG, 'onNotificationHandled', method); | ||
let peer, hmsPeer; | ||
@@ -153,6 +160,6 @@ switch (method) { | ||
peer = notification as PeerNotification; | ||
hmsPeer = this.notificationManager.findPeerByUID(peer.uid); | ||
hmsPeer = this.notificationManager.findPeerByUID(peer.peerId); | ||
hmsPeer | ||
? this.listener.onPeerUpdate(HMSPeerUpdate.PEER_JOINED, hmsPeer!) | ||
: HMSLogger.e(this.TAG, `peer not found in peer-list ${peer}`); | ||
: HMSLogger.e(this.TAG, `⚠️ peer not found in peer-list`, peer, this.notificationManager.hmsPeerList); | ||
break; | ||
@@ -163,6 +170,6 @@ | ||
const hmsPeer = new Peer({ | ||
peerId: peer.uid, | ||
peerId: peer.peerId, | ||
name: peer.info.name, | ||
isLocal: false, | ||
customerDescription: peer.info.metadata, | ||
customerDescription: peer.info.data, | ||
}); //@TODO: There should be a cleaner way | ||
@@ -187,25 +194,37 @@ | ||
case HMSNotificationMethod.PEER_LIST: | ||
// TODO: Move getLocalTracks to immediate after `transportLayer.join` | ||
this.transport.getLocalTracks(new HMSTrackSettingsBuilder().build()).then(async (hmsTracks) => { | ||
hmsTracks.forEach((hmsTrack) => { | ||
switch (hmsTrack.type) { | ||
case HMSTrackType.AUDIO: | ||
this.localPeer.audioTrack = hmsTrack; | ||
break; | ||
case HMSTrackType.VIDEO: | ||
this.localPeer.videoTrack = hmsTrack; | ||
} | ||
}); | ||
this.listener.onJoin(this.createRoom()); | ||
break; | ||
case HMSNotificationMethod.ROLE_CHANGE: | ||
if (this.roomId) { | ||
this.publish(); | ||
} | ||
this.listener.onJoin(this.createRoom()); | ||
await this.transport.publish(hmsTracks); | ||
}); | ||
break; | ||
case HMSNotificationMethod.STREAM_ADD: // TODO: Write code for this | ||
case HMSNotificationMethod.STREAM_ADD: | ||
return; | ||
case HMSNotificationMethod.ACTIVE_SPEAKERS: // TODO: Write code for this | ||
case HMSNotificationMethod.ACTIVE_SPEAKERS: | ||
return; | ||
case HMSNotificationMethod.BROADCAST: | ||
const message = notification as Message; | ||
HMSLogger.d(this.TAG, `Received Message:: `, message); | ||
this.listener.onMessageReceived(message); | ||
} | ||
} | ||
private publish() { | ||
this.transport.getLocalTracks(new HMSTrackSettingsBuilder().build()).then(async (hmsTracks) => { | ||
hmsTracks.forEach((hmsTrack) => { | ||
switch (hmsTrack.type) { | ||
case HMSTrackType.AUDIO: | ||
this.localPeer.audioTrack = hmsTrack; | ||
break; | ||
case HMSTrackType.VIDEO: | ||
this.localPeer.videoTrack = hmsTrack; | ||
} | ||
}); | ||
await this.transport.publish(hmsTracks); | ||
this.published = true; | ||
}); | ||
} | ||
createRoom() { | ||
@@ -212,0 +231,0 @@ const hmsPeerList = this.getPeers(); |
@@ -7,2 +7,5 @@ export enum HMSNotificationMethod { | ||
ACTIVE_SPEAKERS, | ||
BROADCAST, | ||
ROLE_CHANGE, | ||
TRACK_ADD, | ||
} | ||
@@ -12,17 +15,18 @@ | ||
switch (method) { | ||
case 'peer-join': | ||
case 'on-peer-join': | ||
return HMSNotificationMethod.PEER_JOIN; | ||
break; | ||
case 'peer-leave': | ||
case 'on-peer-leave': | ||
return HMSNotificationMethod.PEER_LEAVE; | ||
break; | ||
case 'peer-list': | ||
return HMSNotificationMethod.PEER_LIST; | ||
break; | ||
case 'stream-add': | ||
return HMSNotificationMethod.STREAM_ADD; | ||
break; | ||
case 'on-track-add': | ||
return HMSNotificationMethod.TRACK_ADD; | ||
case 'active-speakers': | ||
return HMSNotificationMethod.ACTIVE_SPEAKERS; | ||
break; | ||
case 'on-broadcast': | ||
return HMSNotificationMethod.BROADCAST; | ||
case 'on-role-change': | ||
return HMSNotificationMethod.ROLE_CHANGE; | ||
default: | ||
@@ -29,0 +33,0 @@ throw Error(`Unsupported method=${method} received`); |
import { HMSNotificationMethod } from './enums/HMSNotificationMethod'; | ||
import PeerInfo from './PeerInfo'; | ||
import Message from './HMSMessage'; | ||
export type HMSNotifications = Peer | Stream | PeerList | undefined; | ||
export type HMSNotifications = Peer | PeerList | Message | TrackStateNotification | undefined; | ||
export class Peer { | ||
uid: string; | ||
sid: string; | ||
info!: PeerInfo; | ||
export interface TrackStateNotification { | ||
tracks: Map<string, TrackState>; | ||
peer: PeerNotificationInfo; | ||
} | ||
constructor(params: any) { | ||
this.uid = params.uid; | ||
this.sid = params.sid; | ||
this.info = new PeerInfo(params.info); | ||
} | ||
export interface PeerNotificationInfo { | ||
peer_id: string; | ||
info: Info; | ||
} | ||
export class StreamInternal { | ||
uid: string; | ||
streamId: string; | ||
export interface Info { | ||
name: string; | ||
data: string; | ||
userId: string; | ||
} | ||
constructor(params: any) { | ||
this.uid = params.uid; | ||
this.streamId = params.streamId; | ||
} | ||
export interface TrackState { | ||
mute: boolean; | ||
type: string; | ||
source: string; | ||
description: string; | ||
track_id: string; | ||
stream_id: string; | ||
} | ||
export class Stream { | ||
uid: string; | ||
stream: StreamInternal; | ||
streamId: string; | ||
export class Peer { | ||
peerId: string; | ||
info: Info; | ||
role: string; | ||
tracks: TrackState[] = []; | ||
constructor(params: any) { | ||
this.uid = params.uid; | ||
this.stream = params.stream; | ||
this.streamId = this.stream!.streamId; | ||
this.peerId = params.peer_id; | ||
this.info = { | ||
name: params.info.name, | ||
data: params.info.data, | ||
userId: params.info.user_id, | ||
}; | ||
this.role = params.role; | ||
this.tracks = Object.values(params.tracks || {}); | ||
} | ||
@@ -42,7 +51,5 @@ } | ||
peers: Peer[]; | ||
streams: StreamInternal[]; | ||
constructor(params: any) { | ||
this.peers = params.peers; | ||
this.streams = params.streams; | ||
this.peers = Object.values(params.peers).map((peer) => new Peer(peer)); | ||
} | ||
@@ -59,6 +66,11 @@ } | ||
return new PeerList(params); | ||
case HMSNotificationMethod.STREAM_ADD: | ||
return new Stream(params); | ||
case HMSNotificationMethod.ACTIVE_SPEAKERS: // TODO: Write Code for this | ||
case HMSNotificationMethod.BROADCAST: | ||
return new Message(params.info); | ||
case HMSNotificationMethod.ACTIVE_SPEAKERS: | ||
return; | ||
case HMSNotificationMethod.ROLE_CHANGE: | ||
return; | ||
case HMSNotificationMethod.TRACK_ADD: { | ||
return params; | ||
} | ||
default: | ||
@@ -65,0 +77,0 @@ throw Error(`Unsupported method=${method} received`); |
@@ -7,4 +7,4 @@ export default class PeerInfo { | ||
this.name = params?.name; | ||
this.metadata = params?.metadata; | ||
this.metadata = params?.data; | ||
} | ||
} |
@@ -7,30 +7,40 @@ import HMSTrack from '../media/tracks/HMSTrack'; | ||
Peer as PeerNotification, | ||
Stream, | ||
StreamInternal, | ||
HMSNotifications, | ||
PeerList, | ||
TrackStateNotification, | ||
TrackState, | ||
} from './models/HMSNotifications'; | ||
import HMSLogger from '../utils/logger'; | ||
import HMSPeer from '../interfaces/hms-peer'; | ||
import HMSUpdateListener, { HMSTrackUpdate } from '../interfaces/update-listener'; | ||
interface TrackStateEntry { | ||
peerId: string; | ||
trackInfo: TrackState; | ||
} | ||
export default class NotificationManager { | ||
hmsPeerList: Peer[] = []; | ||
hmsPeerList: Map<string, HMSPeer> = new Map(); | ||
private TAG: string = 'NotificationManager'; | ||
private streamIdToUIDMap: Map<string, string> = new Map<string, string>(); | ||
private streamIdToTrackMap: Map<string, HMSTrack> = new Map<string, HMSTrack>(); | ||
private TAG: string = '[Notification Manager]:'; | ||
private tracksToProcess: Map<string, HMSTrack> = new Map(); | ||
private trackStateMap: Map<string, TrackStateEntry> = new Map(); | ||
private listener!: HMSUpdateListener; | ||
handleNotification = (method: HMSNotificationMethod, notification: HMSNotifications) => { | ||
let peer: PeerNotification; | ||
handleNotification(method: HMSNotificationMethod, notification: HMSNotifications, listener: HMSUpdateListener) { | ||
this.listener = listener; | ||
switch (method) { | ||
case HMSNotificationMethod.PEER_JOIN: | ||
peer = notification as PeerNotification; | ||
case HMSNotificationMethod.PEER_JOIN: { | ||
const peer = new PeerNotification(notification); | ||
HMSLogger.d(this.TAG, `PEER_JOIN event`, peer); | ||
this.handlePeerJoin(peer); | ||
break; | ||
case HMSNotificationMethod.PEER_LEAVE: | ||
peer = notification as PeerNotification; | ||
} | ||
case HMSNotificationMethod.PEER_LEAVE: { | ||
const peer = new PeerNotification(notification); | ||
HMSLogger.d(this.TAG, `PEER_LEAVE event`, peer); | ||
this.handlePeerLeave(peer); | ||
break; | ||
case HMSNotificationMethod.PEER_LIST: | ||
} | ||
case HMSNotificationMethod.PEER_LIST: { | ||
const peerList = notification as PeerList; | ||
@@ -40,8 +50,8 @@ HMSLogger.d(this.TAG, `PEER_LIST event`, peerList); | ||
break; | ||
case HMSNotificationMethod.STREAM_ADD: | ||
const stream = notification as Stream; | ||
HMSLogger.d(this.TAG, `STREAM_ADD event`, stream); | ||
this.handleStreamAdd(stream.stream); | ||
} | ||
case HMSNotificationMethod.TRACK_ADD: { | ||
this.handleTrackAdd(notification as TrackStateNotification); | ||
break; | ||
case HMSNotificationMethod.ACTIVE_SPEAKERS: //TODO: Write code for this | ||
} | ||
case HMSNotificationMethod.ACTIVE_SPEAKERS: | ||
return; | ||
@@ -51,34 +61,47 @@ default: | ||
} | ||
}; | ||
} | ||
/** | ||
* Sets the tracks to peer and returns the peer | ||
*/ | ||
handleOnTrackAdd = (track: HMSTrack) => { | ||
HMSLogger.d(this.TAG, `ONTRACKADD`, track); | ||
const streamId = track.stream.id; | ||
const hmsPeer = this.streamIdToUIDMap.get(streamId) | ||
? this.findPeerByUID(this.streamIdToUIDMap.get(streamId)!) | ||
: null; | ||
handleTrackAdd(params: TrackStateNotification) { | ||
HMSLogger.d(this.TAG, `BIZ:ONTRACKADD`, params); | ||
if (hmsPeer) { | ||
// Peer-JOIN has come already | ||
for (const [trackId, trackEntry] of Object.entries(params.tracks)) { | ||
this.trackStateMap.set(trackId, { | ||
peerId: params.peer.peer_id, | ||
trackInfo: trackEntry, | ||
}); | ||
} | ||
this.processPendingTracks(); | ||
} | ||
private processPendingTracks() { | ||
const tracksCopy = new Map(this.tracksToProcess); | ||
tracksCopy.forEach((track) => { | ||
const state = this.trackStateMap.get(track.trackId); | ||
if (!state) return; | ||
const hmsPeer = this.hmsPeerList.get(state.peerId); | ||
if (!hmsPeer) return; | ||
switch (track.type) { | ||
case HMSTrackType.AUDIO: | ||
hmsPeer!.audioTrack = track; | ||
hmsPeer.audioTrack = track; | ||
break; | ||
case HMSTrackType.VIDEO: { | ||
if (hmsPeer.videoTrack) { | ||
hmsPeer!.auxiliaryTracks.push(track); | ||
} else { | ||
hmsPeer!.videoTrack = track; | ||
} | ||
} | ||
case HMSTrackType.VIDEO: | ||
hmsPeer.videoTrack = track; | ||
} | ||
} else { | ||
// Peer-JOIN has not yet come | ||
this.streamIdToTrackMap.set(streamId, track); | ||
} | ||
return hmsPeer; | ||
this.listener.onTrackUpdate(HMSTrackUpdate.TRACK_ADDED, track, hmsPeer); | ||
this.tracksToProcess.delete(track.trackId); | ||
}); | ||
} | ||
/** | ||
* Sets the tracks to peer and returns the peer | ||
*/ | ||
handleOnTrackAdd = (track: HMSTrack) => { | ||
HMSLogger.d(this.TAG, `ONTRACKADD`, track); | ||
this.tracksToProcess.set(track.trackId, track); | ||
this.processPendingTracks(); | ||
}; | ||
@@ -91,4 +114,8 @@ | ||
HMSLogger.d(this.TAG, `ONTRACKREMOVE`, track); | ||
const uid = this.streamIdToUIDMap.get(track.stream.id); | ||
const hmsPeer = uid && this.findPeerByUID(uid); | ||
const trackStateEntry = this.trackStateMap.get(track.trackId); | ||
if (!trackStateEntry) return; | ||
const hmsPeer = this.hmsPeerList.get(trackStateEntry.peerId); | ||
if (hmsPeer) { | ||
@@ -103,2 +130,3 @@ switch (track.type) { | ||
if (screenShareTrackIndex > -1) { | ||
// @TODO: change this based on source | ||
hmsPeer.auxiliaryTracks.splice(screenShareTrackIndex, 1); | ||
@@ -110,15 +138,12 @@ } else { | ||
} | ||
} else { | ||
HMSLogger.w(this.TAG, `No peer found for track ${track}`); | ||
this.listener.onTrackUpdate(HMSTrackUpdate.TRACK_REMOVED, track, hmsPeer); | ||
} | ||
return hmsPeer; | ||
}; | ||
handleLeave = () => { | ||
this.hmsPeerList.length = 0; | ||
this.hmsPeerList.clear(); | ||
}; | ||
findPeerByUID = (uid: string) => { | ||
return this.hmsPeerList.find((hmsPeer) => hmsPeer.peerId === uid); | ||
return this.hmsPeerList.get(uid); | ||
}; | ||
@@ -128,14 +153,21 @@ | ||
const hmsPeer = new Peer({ | ||
peerId: peer.uid, | ||
name: peer.info && peer.info.name ? peer.info.name : '', | ||
peerId: peer.peerId, | ||
name: peer.info.name, | ||
isLocal: false, | ||
customerDescription: peer.info && peer.info.metadata ? peer.info.metadata : '', | ||
customerDescription: '', | ||
}); | ||
this.hmsPeerList.push(hmsPeer); | ||
this.hmsPeerList.set(peer.peerId, hmsPeer); | ||
peer.tracks.forEach((track) => { | ||
this.trackStateMap.set(track.track_id, { | ||
peerId: peer.peerId, | ||
trackInfo: track, | ||
}); | ||
}); | ||
this.processPendingTracks(); | ||
}; | ||
private handlePeerLeave = (peer: PeerNotification) => { | ||
const hmsPeer = this.findPeerByUID(peer.uid); | ||
const peerIdx = hmsPeer && this.hmsPeerList.indexOf(hmsPeer); | ||
peerIdx && peerIdx > -1 && this.hmsPeerList.splice(peerIdx, 1); | ||
this.hmsPeerList.delete(peer.peerId); | ||
}; | ||
@@ -145,26 +177,4 @@ | ||
const peers = peerList.peers; | ||
const streams = peerList.streams; | ||
peers && peers.forEach((peer) => this.handlePeerJoin(peer)); | ||
streams && streams.forEach((stream) => this.handleStreamAdd(stream)); | ||
peers?.forEach((peer) => this.handlePeerJoin(peer)); | ||
}; | ||
private handleStreamAdd = (stream: StreamInternal) => { | ||
this.streamIdToUIDMap.set(stream.streamId, stream.uid); | ||
// Check if onTrackAdd event already came before this | ||
if (this.streamIdToTrackMap.has(stream.streamId)) { | ||
const hmsPeer = this.findPeerByUID(stream.uid); | ||
const hmsTrack = this.streamIdToTrackMap.get(stream.streamId); | ||
if (hmsTrack && hmsPeer) { | ||
switch (hmsTrack.type) { | ||
case HMSTrackType.AUDIO: | ||
hmsPeer.audioTrack = hmsTrack; | ||
break; | ||
case HMSTrackType.VIDEO: | ||
hmsPeer.videoTrack = hmsTrack; | ||
} | ||
} | ||
} | ||
}; | ||
} |
import { HMSTrickle } from '../connection/model'; | ||
import HMSMessage from '../interfaces/message'; | ||
import { ISignalEventsObserver } from './ISignalEventsObserver'; | ||
@@ -17,3 +18,3 @@ | ||
offer(offer: RTCSessionDescriptionInit): Promise<RTCSessionDescriptionInit>; | ||
offer(offer: RTCSessionDescriptionInit, tracks: Map<string, any>): Promise<RTCSessionDescriptionInit>; | ||
@@ -23,2 +24,4 @@ answer(answer: RTCSessionDescriptionInit): void; | ||
trickle(trickle: HMSTrickle): void; | ||
sendMessage(message: HMSMessage): void; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { v4 } from 'uuid'; | ||
import { v4 as uuid } from 'uuid'; | ||
import { ISignal } from '../ISignal'; | ||
@@ -9,5 +9,6 @@ import { ISignalEventsObserver } from '../ISignalEventsObserver'; | ||
import HMSLogger from '../../utils/logger'; | ||
import HMSMessage from '../../interfaces/message'; | ||
export default class JsonRpcSignal implements ISignal { | ||
private readonly TAG = 'JsonRpcSignal'; | ||
private readonly TAG = '[ SIGNAL ]: '; | ||
readonly observer: ISignalEventsObserver; | ||
@@ -35,3 +36,3 @@ | ||
private async call<T>(method: string, params: any): Promise<T> { | ||
const id = v4(); | ||
const id = uuid(); | ||
const message = { method, params, id } as JsonRpcRequest; | ||
@@ -56,3 +57,3 @@ | ||
return new Promise((resolve) => { | ||
this.socket = new WebSocket(uri); | ||
this.socket = new WebSocket(uri); // @DISCUSS: Inject WebSocket as a dependency so that it can be easier to mock and test | ||
const openHandler = () => { | ||
@@ -78,9 +79,4 @@ resolve(); | ||
async join( | ||
sid: string, | ||
uid: string, | ||
offer: RTCSessionDescriptionInit, | ||
info: Object, | ||
): Promise<RTCSessionDescriptionInit> { | ||
const params = { sid, uid, offer, info }; | ||
async join(name: string, data: string, offer: RTCSessionDescriptionInit): Promise<RTCSessionDescriptionInit> { | ||
const params = { name, data, offer }; | ||
const response = (await this.call('join', params)) as RTCSessionDescriptionInit; | ||
@@ -96,6 +92,12 @@ | ||
async offer(offer: RTCSessionDescriptionInit): Promise<RTCSessionDescriptionInit> { | ||
return (await this.call('offer', { | ||
desc: offer, | ||
})) as RTCSessionDescriptionInit; | ||
async offer(desc: RTCSessionDescriptionInit, tracks: Map<string, any>): Promise<RTCSessionDescriptionInit> { | ||
try { | ||
const response = await this.call('offer', { | ||
desc, | ||
tracks, | ||
}); | ||
return response as RTCSessionDescriptionInit; | ||
} catch (e) { | ||
throw e; | ||
} | ||
} | ||
@@ -115,2 +117,7 @@ | ||
async sendMessage(message: HMSMessage) { | ||
// Refer https://www.notion.so/100ms/Biz-Client-Communication-V2-0e93bf0fcd0d46d49e96099d498112d8#b6dd01c8e258442fb50c11c87e4581fb | ||
this.notify('broadcast', { version: '1.0', info: message }); | ||
} | ||
private onMessageHandler(text: string) { | ||
@@ -117,0 +124,0 @@ const response = JSON.parse(text); |
@@ -20,6 +20,7 @@ import ITransportObserver from './ITransportObserver'; | ||
import HMSVideoTrackSettings from '../media/settings/HMSVideoTrackSettings'; | ||
import { HMSTrackType } from '../media/tracks'; | ||
import HMSMessage from '../interfaces/message'; | ||
const TAG = '[HMSTransport]: '; | ||
const TAG = '[HMSTransport]:'; | ||
export default class HMSTransport implements ITransport { | ||
private tracks: any = {}; | ||
private readonly observer: ITransportObserver; | ||
@@ -68,3 +69,3 @@ private publishConnection: HMSPublishConnection | null = null; | ||
onRenegotiationNeeded: async () => { | ||
HMSLogger.d(TAG, `[role=PUBLISH] onRenegotiationNeeded START ⏰`); | ||
HMSLogger.d(TAG, `⏳ [role=PUBLISH] onRenegotiationNeeded START`, this.tracks); | ||
const callback = this.callbacks.get(RENEGOTIATION_CALLBACK_ID); | ||
@@ -74,8 +75,12 @@ this.callbacks.delete(RENEGOTIATION_CALLBACK_ID); | ||
// TODO: Handle errors, pass these errors as publish failure (try-catch) | ||
const offer = await this.publishConnection!.createOffer(); | ||
await this.publishConnection!.setLocalDescription(offer); | ||
const answer = await this.signal.offer(offer); | ||
await this.publishConnection!.setRemoteDescription(answer); | ||
callback?.resolve(true); | ||
HMSLogger.d(TAG, `[role=PUBLISH] onRenegotiationNeeded DONE ✅`); | ||
try { | ||
const offer = await this.publishConnection!.createOffer(); | ||
await this.publishConnection!.setLocalDescription(offer); | ||
const answer = await this.signal.offer(offer, this.tracks); | ||
await this.publishConnection!.setRemoteDescription(answer); | ||
callback?.resolve(true); | ||
HMSLogger.d(TAG, `✅ [role=PUBLISH] onRenegotiationNeeded DONE`, this.tracks); | ||
} catch (e) { | ||
console.error(TAG, e); | ||
} | ||
}, | ||
@@ -110,5 +115,4 @@ | ||
async getLocalScreen(settings: HMSVideoTrackSettings, onStop: () => void): Promise<HMSTrack> { | ||
async getLocalScreen(settings: HMSVideoTrackSettings): Promise<HMSTrack> { | ||
const track = await HMSLocalStream.getLocalScreen(settings); | ||
track.nativeTrack.onended = () => onStop(); | ||
return track; | ||
@@ -121,8 +125,11 @@ } | ||
async join(authToken: string, roomId: string, peerId: string, customData: Object): Promise<void> { | ||
HMSLogger.d(TAG, 'join: started ⏰'); | ||
async join(authToken: string, peerId: string, customData: Object): Promise<void> { | ||
const config = await InitService.fetchInitConfig(authToken); | ||
HMSLogger.d(TAG, '⏳ join: connecting to ws endpoint', config.endpoint); | ||
await this.signal.open(`${config.endpoint}?peer=${peerId}&token=${authToken}`); | ||
HMSLogger.d(TAG, 'join: connected to ws endpoint'); | ||
HMSLogger.d(TAG, '✅ join: connected to ws endpoint'); | ||
HMSLogger.d(TAG, customData); | ||
this.publishConnection = new HMSPublishConnection( | ||
@@ -140,6 +147,6 @@ this.signal, | ||
HMSLogger.d(TAG, 'join: Negotiating over PUBLISH connection ⏰'); | ||
HMSLogger.d(TAG, '⏳ join: Negotiating over PUBLISH connection'); | ||
const offer = await this.publishConnection.createOffer(); | ||
await this.publishConnection.setLocalDescription(offer); | ||
const answer = await this.signal.join(roomId, peerId, offer, customData); | ||
const answer = await this.signal.join('dayamax', peerId, offer, { a: 6 }); | ||
await this.publishConnection.setRemoteDescription(answer); | ||
@@ -150,6 +157,6 @@ for (const candidate of this.publishConnection.candidates) { | ||
this.publishConnection!.initAfterJoin(); | ||
HMSLogger.d(TAG, 'join: Negotiating over PUBLISH connection ✅'); | ||
HMSLogger.d(TAG, '✅ join: Negotiated over PUBLISH connection'); | ||
// TODO: Handle exceptions raised - wrap them in HMSException | ||
HMSLogger.d(TAG, 'join: successful ✅'); | ||
HMSLogger.d(TAG, '✅ join: successful'); | ||
} | ||
@@ -164,7 +171,15 @@ | ||
private async publishTrack(track: HMSTrack): Promise<void> { | ||
HMSLogger.d(TAG, `publishTrack: trackId=${track.trackId} ⏰`, track); | ||
HMSLogger.d(TAG, `⏳ publishTrack: trackId=${track.trackId}`, track); | ||
this.tracks[track.trackId] = { | ||
mute: false, | ||
type: track.nativeTrack.kind, | ||
source: 'regular', | ||
description: '', | ||
track_id: track.trackId, | ||
stream_id: track.stream.id, | ||
}; | ||
const p = new Promise<boolean>((resolve, reject) => { | ||
this.callbacks.set(RENEGOTIATION_CALLBACK_ID, { resolve, reject }); | ||
}); | ||
const stream = <HMSLocalStream>track.stream; | ||
const stream = track.stream as HMSLocalStream; | ||
stream.setConnection(this.publishConnection!); | ||
@@ -175,21 +190,22 @@ stream.addTransceiver(track); | ||
// @TODO: May be this should be exposed as an API | ||
if (track.type === HMSTrackType.VIDEO) { | ||
const maxBitrate = 250; | ||
await stream | ||
.setMaxBitrate(maxBitrate * 1000, track) | ||
.then(() => { | ||
HMSLogger.d(TAG, `Setting maxBitrate to ${maxBitrate} kpbs`); | ||
}) | ||
.catch((error) => HMSLogger.e(TAG, 'Failed setting maxBitrate', error)); | ||
} | ||
// if (track.type === HMSTrackType.VIDEO) { | ||
// const maxBitrate = 250; | ||
// await stream | ||
// .setMaxBitrate(maxBitrate * 1000, track) | ||
// .then(() => { | ||
// HMSLogger.d(TAG, `Setting maxBitrate to ${maxBitrate} kpbs`); | ||
// }) | ||
// .catch((error) => HMSLogger.e(TAG, 'Failed setting maxBitrate', error)); | ||
// } | ||
HMSLogger.d(TAG, `publishTrack: trackId=${track.trackId} ✅`, this.callbacks); | ||
HMSLogger.d(TAG, `✅ publishTrack: trackId=${track.trackId}`, this.callbacks); | ||
} | ||
private async unpublishTrack(track: HMSTrack): Promise<void> { | ||
HMSLogger.d(TAG, `unpublishTrack: trackId=${track.trackId} ⏰`, track); | ||
HMSLogger.d(TAG, `unpublishTrack: trackId=${track.trackId} ⏳`, track); | ||
this.tracks.delete(track.trackId); | ||
const p = new Promise<boolean>((resolve, reject) => { | ||
this.callbacks.set(RENEGOTIATION_CALLBACK_ID, { resolve, reject }); | ||
}); | ||
const stream = <HMSLocalStream>track.stream; | ||
const stream = track.stream as HMSLocalStream; | ||
stream.removeSender(track); | ||
@@ -211,2 +227,6 @@ await p; | ||
} | ||
sendMessage(message: HMSMessage) { | ||
this.signal.sendMessage(message); | ||
} | ||
} |
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
893657
133
10173
13