From fa71b84b2d7432b2ca12b7087e83b0f9ed95f2bb Mon Sep 17 00:00:00 2001 From: Todd Anderson Date: Fri, 4 Oct 2024 11:23:30 +0200 Subject: [PATCH] feat: stats monitoring in proxy tests for load balancing. --- .../live/lib/red5pro/red5pro-sdk.min.js | 4 +- src/webapps/live/proxy-publisher.html | 814 ++++++++++-------- src/webapps/live/proxy-subscriber.html | 40 + webapps.json | 2 +- 4 files changed, 501 insertions(+), 359 deletions(-) diff --git a/src/webapps/live/lib/red5pro/red5pro-sdk.min.js b/src/webapps/live/lib/red5pro/red5pro-sdk.min.js index 0b05e5dc..4052893e 100644 --- a/src/webapps/live/lib/red5pro/red5pro-sdk.min.js +++ b/src/webapps/live/lib/red5pro/red5pro-sdk.min.js @@ -2,7 +2,7 @@ * * red5pro-sdk - Red5 Pro HTML Publisher and Subscriber SDK. * Author: Infrared5 Inc. - * Version: 13.0.0-release.b153 + * Version: 13.0.0 * Url: https://github.com/red5pro/red5pro-html-sdk#readme * * Copyright © 2015 Infrared5, Inc. All rights reserved. @@ -30,4 +30,4 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.red5prosdk=t():e.red5prosdk=t()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t,n){"use strict";function r(e){if(null==e)return e;if(Array.isArray(e))return e.slice();if("object"==typeof e){var t={};return Object.keys(e).forEach((function(n){t[n]=e[n]})),t}return e}var o=function(e){if(null===e)return"null";if("string"!=typeof e)return e.toString();for(var t=/%[sdj%]/g,n=1,r=arguments,o=r.length,i=String(e).replace(t,(function(e){if("%%"===e)return"%";if(n>=o)return e;switch(e){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(e){return"[Circular]"}break;default:return e}})),a=r[n];ne||(l=n(u),this._emit(l))}else{var d="unbound";if(!s[d]){var h=i();a(o("bunyan usage error: %s:%s: attempt to log with an unbound log method: `this` is: %s",h.file,h.line,this.toString()),d)}}}}function w(e){var t=e.stack||e.toString();if(e.cause&&"function"==typeof e.cause){var n=e.cause();n&&(t+="\nCaused by: "+w(n))}return t}function S(){var e=[];return function(t,n){return n&&"object"==typeof n?-1!==e.indexOf(n)?"[Circular]":(e.push(n),n):n}}Object.keys(m).forEach((function(e){y[m[e]]=e})),g.prototype.addStream=function(e,t){switch(null==t&&(t=h),!(e=r(e)).type&&e.stream&&(e.type="raw"),e.raw="raw"===e.type,e.level?e.level=b(e.level):e.level=b(t),e.level1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0,o=[];if(o.push({level:e,stream:new u,type:"raw"}),n){var i=n.map((function(t){t.level=e}));o=o.concat(i)}t&&(c=[],o.push({level:e,stream:{write:function(e){var t="[".concat(e.time.toISOString(),"] ").concat(r.nameFromLevel[e.level],": ").concat(e.msg);c.push(t)}}})),s=Object(r.createLogger)({level:e,name:"red5pro-sdk",streams:o})},f=function(){return c},p=(l(d.TRACE),l(d.INFO)),v=l(d.DEBUG),m=l(d.WARN),y=l(d.ERROR);l(d.FATAL);function b(e){return(b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function g(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=Array(t);n=0;--i){var a=this.tryEntries[i],s=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),u=r.call(a,"finallyLoc");if(c&&u){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),L(n),v}},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 o=r.arg;L(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:N(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),v}},t}function L(e,t){for(var n=0;n0)){e.next=5;break}return e.next=3,t.shift();case 3:e.next=0;break;case 5:case"end":return e.stop()}}),e)})),j(this).find=function(e,n,r,o){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null,s=j(t).next(e,n),c=O(s,2),u=c[0],l=c[1];if(l){var d=r[u];d=d||r,(i?(new l)[i](d):new l(d)).then((function(e){o.resolve(e)})).catch((function(s){a=s,j(t).find(e,n,r,o,i,a)}))}else o.reject(a)},j(this).next=function(e,t){var n,r,o=e.next();return o.done||(r=o.value,n=t.get(r)),[r,n]}},(t=[{key:"create",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,o=new C;return j(this).find(this.listorder(e.slice()),t,n,o,r),o.promise}}])&&L(e.prototype,t),n&&L(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}();function I(e){return(I="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function x(e,t){for(var n=0;n1&&(n=K.exec(e),r[1]===t&&n&&n.length>1)?n[1]:void 0}}var X=function(e){var t="function"==typeof e.textTracks?e.textTracks():e.textTracks;t&&(e.addTextTrack("metadata"),t.addEventListener("addtrack",(function(t){var n=t.track;n.mode="hidden",n.addEventListener("cuechange",(function(t){var r,o;r=(r=t&&t.currentTarget?t.currentTarget.cues:(r=n.cues)&&r.length>0?r:n.activeCues)||[];var i=function(){var t=r[o];if(t.value){var n="string"==typeof t.value.data?t.value.data:function(e,t,n){var r="",o=t,i=t+n;do{r+=String.fromCharCode(e[o++])}while(o0||e.canPlayType("application/x-mpegURL").length>0||e.canPlayType("audio/mpegurl").length>0||e.canPlayType("audio/x-mpegurl").length>0},ue=window.adapter,le=!!navigator.mozGetUserMedia,de=!!document.documentMode,he=ue?"edge"===window.adapter.browserDetails.browser.toLowerCase():!de&&!!window.StyleMedia,fe=ue?"safari"===window.adapter.browserDetails.browser.toLowerCase():ce(),pe="ontouchstart"in window||window.DocumentTouch&&window.document instanceof window.DocumentTouch;ue||(navigator.getUserMedia=navigator.mediaDevices&&navigator.mediaDevices.getUserMedia||navigator.getUserMedia||navigator.mozGetUserMedia||navigator.webkitGetUserMedia||navigator.msGetUserMedia);var ve={requestFrame:se,getIsMoz:function(){return le},getIsEdge:function(){return he},getIsPossiblySafari:function(){return fe},isTouchEnabled:function(){return pe},supportsWebSocket:function(){return!!window.WebSocket},supportsHLS:ce,supportsNonNativeHLS:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;if(e)try{return e.isSupported()}catch(e){return m("Could not access Hls.js."),!1}return!!window.Hls&&window.Hls.isSupported()},createHLSClient:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return new window.Hls(e)},getHLSClientEventEnum:function(){return window.Hls.Events},supportsFlashVersion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:".";return ae()[0]>=e.split(t)[0]},resolveElement:function(e){try{var t=document.getElementById(e);if(!t)throw new W("Element with id(".concat(e,") could not be found."));return t}catch(t){throw new W("Error in accessing element with id(".concat(e,"). ").concat(t.message))}},createWebSocket:function(e){return new WebSocket(e)},setVideoSource:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];try{e.srcObject=t}catch(n){m("[setVideoSource:obj]","Could not set srcObject: ".concat(n.message)),le?e.mozSrcObject=t:e.src=window.URL.createObjectURL(t)}if(n)try{var r=e.play();r&&r.then((function(){return v("[setVideoSource:action]","play (START)")})).catch((function(e){return m("[setVideoSource:action]","play (FAULT) "+(e.message?e.message:e))}))}catch(t){m("[setVideoSource:action]","play (CATCH::FAULT) "+t.message);try{e.setAttribute("autoplay",!1),e.pause()}catch(e){m("[setVideoSource:action]","pause (CATCH::FAULT) "+e.message)}}else try{e.setAttribute("autoplay",!1),e.pause()}catch(e){}},injectScript:function(e){var t=new C,n=document.createElement("script");return n.type="text/javascript",n.onload=function(){t.resolve()},n.onreadystatechange=function(){"loaded"!==n.readyState&&"complete"!==n.readyState||(n.onreadystatechange=null,t.resolve())},n.src=e,document.getElementsByTagName("head")[0].appendChild(n),t.promise},gUM:function(e){return(navigator.mediaDevices||navigator).getUserMedia(e)},setGlobal:function(e,t){window[e]=t},getSwfObject:function(){return window.swfobject},getEmbedObject:function(e){return document.getElementById(e)},getElementId:function(e){return e.getAttribute("id")},addOrientationChangeHandler:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n="onorientationchange"in window;n&&(v("[window:orientation]","[addOrientationChangeHandler]","adding responder."),te.push(e),t&&ne()),1===te.length&&(v("[window:orientation]","[addOrientationChangeHandler]","onorientationchange added."),window.addEventListener("orientationchange",ne))},removeOrientationChangeHandler:function(e){for(var t=te.length;--t>-1;)if(te[t]===e){te.slice(t,1);break}0===te.length&&(v("[window:orientation]","[removeOrientationChangeHandler]:: onorientationchange removed."),window.removeEventListener("onorientationchange",ne))},addCloseHandler:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:-1;re.splice(-1===t?re.length:t,0,e),oe||window.addEventListener("unload",ie)},removeCloseHandler:function(e){for(var t=re.length;--t>-1;)if(re[t]===e){re.slice(t,1);break}},invoke:function(e,t){window.hasOwnProperty(e)&&window[e].call(window,t)},toggleFullScreen:function(e){window.screenfull&&window.screenfull.enabled&&window.screenfull.toggle(e)},onFullScreenStateChange:function(e){Z.push(e),window.screenfull,!ee&&window.screenfull&&window.screenfull.enabled&&(ee=!0,window.screenfull.onchange((function(){var e,t=Z.length;for(e=0;e2&&void 0!==arguments[2]&&arguments[2];return function(){var r=e.parentNode;if(r){var o=r.clientWidth,i=r.clientHeight;e.style.width=n?i+"px":o+"px";var a=e.clientWidth,s=e.clientHeight,c=.5*(n?o-s:o-a);e.style.position="relative",e.style.left=c+"px"}t&&t(we(e,t,n))}},Se=function(e,t,n){var r,o=be.length,i=(t%=360)%180!=0,a=e.parentNode,s=e.width?e.width:a.clientWidth,c=e.height?e.height:a.clientHeight,u=_e[t.toString()];for(r=0;r=t?e.apply(null,r):function(){var e=Array.prototype.slice.call(arguments,0);return n.apply(null,r.concat(e))}}},Ce=Ee((function(e,t){for(var n=0,r=t.length,o=[];n=0;--i){var a=this.tryEntries[i],s=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),u=r.call(a,"finallyLoc");if(c&&u){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),T(n),v}},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 o=r.arg;T(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:L(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),v}},t}function Ae(e,t,n,r,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function Ne(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);function a(e){Ae(i,r,o,a,s,"next",e)}function s(e){Ae(i,r,o,a,s,"throw",e)}a(void 0)}))}}var je,He=[{label:"4K(UHD)",width:3840,height:2160},{label:"1080p(FHD)",width:1920,height:1080},{label:"UXGA",width:1600,height:1200},{label:"720p(HD)",width:1280,height:720},{label:"SVGA",width:800,height:600},{label:"VGA",width:640,height:480},{label:"360p(nHD)",width:640,height:360},{label:"CIF",width:352,height:288},{label:"QVGA",width:320,height:240},{label:"QCIF",width:176,height:144},{label:"QQVGA",width:160,height:120}],Ie=function(e){return e.exact||e.ideal||e.max||e.min||e},xe=Ee((function(e,t){if("boolean"==typeof e.video)return!0;var n=e.video.hasOwnProperty("width")?Ie(e.video.width):0,r=e.video.hasOwnProperty("height")?Ie(e.video.height):0,o=n===t.width&&r===t.height;return o&&v("[gum:isExact]","Found matching resolution for ".concat(t.width,", ").concat(t.height,".")),o})),De=Ee((function(e,t){var n=(e.video.hasOwnProperty("width")?Ie(e.video.width):0)*(e.video.hasOwnProperty("height")?Ie(e.video.height):0);return t.width*t.height0})),Fe=Ee((function(e,t){var n=De(t);return Ce(n)(e)})),Ue=function(e,t,n){if(0!=t.length){var r=t.shift();e.video.width={exact:r.width},e.video.height={exact:r.height},ve.gUM(e).then((function(t){n.resolve({media:t,constraints:e})})).catch((function(r){var o="string"==typeof r?r:[r.name,r.message].join(": ");v("[gum:getUserMedia]","Failure in getUserMedia: ".concat(o,". Attempting other resolution tests...")),v("[gUM:findformat]","Constraints declined by browser: ".concat(JSON.stringify(e,null,2))),Ue(e,t,n)}))}else!function(e,t){e.video=!0,ve.gUM(e).then((function(n){t.resolve({media:n,constraints:e})})).catch((function(n){var r="string"==typeof n?n:[n.name,n.message].join(": ");v("[gum:getUserMedia]","Failure in getUserMedia: ".concat(r,". Attempting other resolution tests...")),v("[gUM:findformat]","Constraints declined by browser: ".concat(JSON.stringify(e,null,2))),t.reject("Could not find proper camera for provided constraints.")}))}(e,n)},Be=function(){return bt&>&&_t},Ve=function(){try{var e=new bt(null);return e.createDataChannel({name:"test"}).close(),e.close(),!!Be()}catch(e){return v("Could not detect RTCDataChannel support: ".concat(e.message)),!1}},Ge=(window.RTCRtpScriptTransform,!!window.MediaStreamTrackGenerator),We=(window.MediaStreamTrackProcessor,function(){return!!wt.prototype.createEncodedStreams}),Ye=function(e,t,n,r){var o=new Et(t),i=new Ct(t.kind),a=o.readable,s=i.writable;return n.postMessage({type:e,readable:a,writable:s,options:r},[a,s]),{processor:o,generator:i}},ze=function(e,t,n,r){var o=t.createEncodedStreams(),i=o.readable,a=o.writable;return n.postMessage({type:e,readable:i,writable:a,options:r},[i,a]),{readable:i,writable:a}},Ke=function(e,t,n,r){var o=t.createEncodedStreams(),i=o.readable,a=o.writable;return n.postMessage({type:e,readable:i,writable:a,options:r},[i,a]),{readable:i,writable:a}},Je=function(){var e=Ne(Le().mark((function e(t,n,r){var o,i,a;return Le().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=new Et(t),i=new Ct(t.kind),a=new St({transform:n}),o.readable.pipeThrough(a,r).pipeTo(i.writable).catch((function(e){if(r){var t=r.signal;t&&t.abort(e)}y("[PIPE:pipeGeneratorTransform]",e.message)})),e.abrupt("return",{processor:o,generator:i});case 6:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),qe=function(){var e=Ne(Le().mark((function e(t,n,r){var o,i,a,s;return Le().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=new St({transform:n}),i=t.createEncodedStreams(),a=i.readable,s=i.writable,a.pipeThrough(o,r).pipeTo(s).catch((function(e){if(a.cancel(e),r){var t=r.signal;t&&t.abort(e)}y("[PIPE:pipeSenderTransform]",e.message)})),e.abrupt("return",{readable:a,writable:s});case 6:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),Xe=function(){var e=Ne(Le().mark((function e(t,n,r){var o,i,a,s;return Le().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=new St({transform:n}),i=t.createEncodedStreams(),a=i.readable,s=i.writable,a.pipeThrough(o,r).pipeTo(s).catch((function(e){if(a.cancel(e),r){var t=r.signal;t&&t.abort(e)}y("[PIPE:pipeReceiverTransform",e.message)})),e.abrupt("return",{readable:a,writable:s});case 6:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),$e=function(e,t){var n=new C,r=Me(He);v("[gum:getUserMedia]","Is Available in format listing: "+r(e));var o=function(r){if(r){var o="string"==typeof r?r:[r.name,r.message].join(": ");v("[gum:getUserMedia]","Failure in getUserMedia: ".concat(o,". Attempting other resolution tests..."))}(function(e){v("[gum:determineSupportedResolution]","Determine next neighbor based on constraints: "+JSON.stringify(e,null,2));var t=new C,n=Fe(He)(e),r=Pe(e);return Ue(r,n,t),t.promise})(e).then((function(e){n.resolve({media:e.media,constraints:e.constraints})})).catch((function(r){t&&t(e),n.reject({error:r,constraints:e})}))};if(function(e){return e.hasOwnProperty("video")&&(e.video.hasOwnProperty("width")||e.video.hasOwnProperty("height"))}(e))if(r(e)){v("[gum:getUserMedia]","Found constraints in list. Checking quick support for faster setup with: "+JSON.stringify(e,null,2));var i=function(e){var t=Pe(e);return"boolean"==typeof e.video||(e.video.width&&(t.video.width={exact:Ie(e.video.width)}),e.video.height&&(t.video.height={exact:Ie(e.video.height)})),t}(e);ve.gUM(i).then((function(e){n.resolve({media:e,constraints:i})})).catch(o)}else v("[gum:getUserMedia]","Could not find contraints in list. Attempting failover..."),t&&t(e),o();else v("[gum:getUserMedia]","Constraints were not defined properly. Attempting failover..."),ve.gUM(e).then((function(t){n.resolve({media:t,constraints:e})})).catch(o);return n.promise},Qe=function(e,t){for(var n=e.split("\r\n"),r=n.length;--r>-1;)t.indexOf(n[r])>-1&&n.splice(r,1);return n.join("\r\n")},Ze=function(e){return Qe(e,["a=ice-options:trickle"])},et=function(e){var t="a=ice-options:trickle";if(e.indexOf(t)>-1)return e;var n=e.split("\r\n"),r=n.map((function(e,t){return e.match(/^a=ice-ufrag:(.*)/)?t:-1})).filter((function(e){return e>-1})),o=r.length>0?r[r.length-1]:-1;return o>-1&&n.splice(o+1,0,t),n.join("\r\n")},tt=function(e){var t="a=end-of-candidates";if(e.indexOf(t)>-1)return e;var n=e.split("\r\n"),r=n.map((function(e,t){return e.match(/^a=candidate:(.*)/)?t:-1})).filter((function(e){return e>-1})),o=r.length>0?r[r.length-1]:-1;return o>-1&&n.splice(o+1,0,t),n.join("\r\n")},nt=function(e){for(var t=/^a=extmap/,n=e.split("\r\n"),r=n.length;--r>-1;)t.exec(n[r])&&n.splice(r,1);return n.join("\r\n")},rt=(je=[],["rtpmap:(\\d{1,}) ISAC","rtpmap:(\\d{1,}) G722","rtpmap:(\\d{1,}) CN","rtpmap:(\\d{1,}) PCMU","rtpmap:(\\d{1,}) PCMA","rtpmap:(\\d{1,}) telephone-event"].forEach((function(e){return je.push(new RegExp("a=(".concat(e,")"),"g"))})),je),ot=function(e){for(var t,n,r,o,i,a=e.split("\r\n"),s=a.length,c=[];--s>-1;)for(t=0;t-1;)for(t=0;t-1;)r.lastIndex=0,(t=r.exec(i[a]))&&-1===o.indexOf(t[t.length-1])&&o.push(t[t.length-1]);for(a=i.length;--a>-1;)for(s=0;s-1;)at.lastIndex=0,at.exec(t[r])&&t.splice(r,1);return t.join("\r\n")}return e})).join(t)},ct=function(e){return st(e,"m=",/^audio/g)},ut=function(e){return st(e,"m=",/^video/g)},lt=function(e,t){var n,r,o,i=t.indexOf("m=audio"),a=t.indexOf("m=video"),s=t.indexOf("m=application");return i>-1&&e.audio&&(n=t.indexOf("\r\n",i),r=t.slice(0,n),o=t.slice(n+"\r\n".length,t.length),a=(t=[r,"b=AS:"+e.audio,o].join("\r\n")).indexOf("m=video"),s=t.indexOf("m=application")),a>-1&&e.video&&(n=t.indexOf("\r\n",a),r=t.slice(0,n),o=t.slice(n+"\r\n".length,t.length),s=(t=[r,"b=AS:"+e.video,o].join("\r\n")).indexOf("m=application")),s>-1&&e.dataChannel&&(n=t.indexOf("\r\n",s),r=t.slice(0,n),o=t.slice(n+"\r\n".length,t.length),t=[r,"b=AS:"+e.dataChannel,o].join("\r\n")),t},dt=/(a=group:BUNDLE)(.*)/,ht=function(e){return dt.exec(e)?e.match(dt)[2].trim():void 0},ft=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"0 1 2";return e.replace(dt,"$1 "+t)},pt=/(profile-level-id=42)(.*)/g,vt=function(e){return e.replace(pt,"$1e01f")},mt=function(e){return e.includes("stereo=1")?e:e.replace("useinbandfec=1","useinbandfec=1;stereo=1;sprop-stereo=1")},yt=function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o="a=end-of-candidates",i=/^a=candidate:/,a=/^a=ice-ufrag:/,s=/^a=ice-pwd:/,c=/^m=(audio|video|application)\ /,u=e.split("\r\n"),l="",d="",h="a=mid:0",f=[];u.forEach((function(e){!t&&c.exec(e)?t=e:a.exec(e)?l=e:s.exec(e)?d=e:i.exec(e)&&(n&&-1!=e.indexOf(n)?f.push(e):n||f.push(e))})),r&&f[f.length-1]!==o&&f.push(o);var p=[l,d,t,h].concat(f);return p.join("\r\n")},bt=window.RTCPeerConnection||window.mozRTCPeerConnection||window.webkitRTCPeerConnection,gt=window.RTCIceCandidate||window.mozRTCIceCandidate||window.webkitRTCIceCandidate,_t=window.RTCSessionDescription||window.mozRTCSessionDescription||window.webkitRTCSessionDescription,wt=window.RTCRtpSender||window.RTCRtpSender||window.RTCRtpSender,St=window.TransformStream,Et=window.MediaStreamTrackProcessor,Ct=window.MediaStreamTrackGenerator,kt=bt,Pt=gt,Ot=_t,Tt=function(){return ve.supportsWebSocket()},Rt=Object.freeze({CONNECT_SUCCESS:"Connect.Success",CONNECT_FAILURE:"Connect.Failure",PUBLISH_START:"Publish.Start",PUBLISH_FAIL:"Publish.Fail",PUBLISH_INVALID_NAME:"Publish.InvalidName",UNPUBLISH_SUCCESS:"Unpublish.Success",PUBLISH_METADATA:"Publish.Metadata",PUBLISH_STATUS:"Publish.Status",PUBLISH_AVAILABLE:"Publish.Available",PUBLISH_INSUFFICIENT_BANDWIDTH:"Publish.InsufficientBW",PUBLISH_SUFFICIENT_BANDWIDTH:"Publish.SufficientBW",PUBLISH_RECOVERING_BANDWIDTH:"Publish.RecoveringBW",PUBLISH_SEND_INVOKE:"Publish.Send.Invoke",CONNECTION_CLOSED:"Publisher.Connection.Closed",DIMENSION_CHANGE:"Publisher.Video.DimensionChange"}),Lt=Object.freeze({PUBLISHER_REJECT:"Publisher.Reject",PUBLISHER_ACCEPT:"Publisher.Accept"}),At=Object.freeze({CONSTRAINTS_ACCEPTED:"WebRTC.MediaConstraints.Accepted",CONSTRAINTS_REJECTED:"WebRTC.MediaConstraints.Rejected",MEDIA_STREAM_AVAILABLE:"WebRTC.MediaStream.Available",PEER_CONNECTION_AVAILABLE:"WebRTC.PeerConnection.Available",OFFER_START:"WebRTC.Offer.Start",OFFER_END:"WebRTC.Offer.End",PEER_CANDIDATE_END:"WebRTC.PeerConnection.CandidateEnd",ICE_TRICKLE_COMPLETE:"WebRTC.IceTrickle.Complete",SOCKET_MESSAGE:"WebRTC.Socket.Message",DATA_CHANNEL_OPEN:"WebRTC.DataChannel.Open",DATA_CHANNEL_AVAILABLE:"WebRTC.DataChannel.Available",DATA_CHANNEL_CLOSE:"WebRTC.DataChannel.Close",DATA_CHANNEL_MESSAGE:"WebRTC.DataChannel.Message",DATA_CHANNEL_ERROR:"WebRTC.DataChannel.Error",PEER_CONNECTION_OPEN:"WebRTC.PeerConnection.Open",TRACK_ADDED:"WebRTC.PeerConnection.OnTrack",UNSUPPORTED_FEATURE:"WebRTC.Unsupported.Feature",TRANSFORM_ERROR:"WebRTC.Transform.Error",HOST_ENDPOINT_CHANGED:"WebRTC.Endpoint.Changed"}),Nt=Object.freeze({EMBED_SUCCESS:"FlashPlayer.Embed.Success",EMBED_FAILURE:"FlashPlayer.Embed.Failure"}),jt=Object.freeze({CONNECT_SUCCESS:"Connect.Success",CONNECT_FAILURE:"Connect.Failure",SUBSCRIBE_START:"Subscribe.Start",SUBSCRIBE_STOP:"Subscribe.Stop",SUBSCRIBE_FAIL:"Subscribe.Fail",SUBSCRIBE_INVALID_NAME:"Subscribe.InvalidName",SUBSCRIBE_METADATA:"Subscribe.Metadata",SUBSCRIBE_STATUS:"Subscribe.Status",SUBSCRIBE_SEND_INVOKE:"Subscribe.Send.Invoke",SUBSCRIBE_PUBLISHER_CONGESTION:"Subscribe.Publisher.NetworkCongestion",SUBSCRIBE_PUBLISHER_RECOVERY:"Subscribe.Publisher.NetworkRecovery",PLAY_UNPUBLISH:"Subscribe.Play.Unpublish",CONNECTION_CLOSED:"Subscribe.Connection.Closed",ORIENTATION_CHANGE:"Subscribe.Orientation.Change",STREAMING_MODE_CHANGE:"Subscribe.StreamingMode.Change",VIDEO_DIMENSIONS_CHANGE:"Subscribe.VideoDimensions.Change",VOLUME_CHANGE:"Subscribe.Volume.Change",SEEK_CHANGE:"Subscribe.Seek.Change",PLAYBACK_TIME_UPDATE:"Subscribe.Time.Update",PLAYBACK_STATE_CHANGE:"Subscribe.Playback.Change",FULL_SCREEN_STATE_CHANGE:"Subscribe.FullScreen.Change",AUTO_PLAYBACK_FAILURE:"Subscribe.Autoplay.Failure",AUTO_PLAYBACK_MUTED:"Subscribe.Autoplay.Muted"}),Ht=Object.freeze({SUBSCRIBER_REJECT:"Subscriber.Reject",SUBSCRIBER_ACCEPT:"Subscriber.Accept"}),It=Object.freeze({PEER_CONNECTION_AVAILABLE:"WebRTC.PeerConnection.Available",OFFER_START:"WebRTC.Offer.Start",OFFER_END:"WebRTC.Offer.End",ANSWER_START:"WebRTC.Answer.Start",ANSWER_END:"WebRTC.Answer.End",CANDIDATE_START:"WebRTC.Candidate.Start",CANDIDATE_END:"WebRTC.Candidate.End",PEER_CANDIDATE_END:"WebRTC.PeerConnection.CandidateEnd",ICE_TRICKLE_COMPLETE:"WebRTC.IceTrickle.Complete",SOCKET_MESSAGE:"WebRTC.Socket.Message",DATA_CHANNEL_MESSAGE:"WebRTC.DataChannel.Message",DATA_CHANNEL_OPEN:"WebRTC.DataChannel.Open",DATA_CHANNEL_AVAILABLE:"WebRTC.DataChannel.Available",DATA_CHANNEL_CLOSE:"WebRTC.DataChannel.Close",DATA_CHANNEL_ERROR:"WebRTC.DataChannel.Error",PEER_CONNECTION_OPEN:"WebRTC.PeerConnection.Open",ON_ADD_STREAM:"WebRTC.Add.Stream",TRACK_ADDED:"WebRTC.PeerConnection.OnTrack",SUBSCRIBE_STREAM_SWITCH:"WebRTC.Subscribe.StreamSwitch",LIVE_SEEK_UNSUPPORTED:"WebRTC.LiveSeek.Unsupported",LIVE_SEEK_ERROR:"WebRTC.LiveSeek.Error",LIVE_SEEK_ENABLED:"WebRTC.LiveSeek.Enabled",LIVE_SEEK_DISABLED:"WebRTC.LiveSeek.Disabled",LIVE_SEEK_LOADING:"WebRTC.LiveSeek.FragmentLoading",LIVE_SEEK_LOADED:"WebRTC.LiveSeek.FragmentLoaded",LIVE_SEEK_CHANGE:"WebRTC.LiveSeek.Change",TRANSFORM_ERROR:"WebRTC.Transform.Error",HOST_ENDPOINT_CHANGED:"WebRTC.Endpoint.Changed"}),xt=Object.freeze({EMBED_SUCCESS:"FlashPlayer.Embed.Success",EMBED_FAILURE:"FlashPlayer.Embed.Failure",ABR_LEVEL_CHANGE:"RTMP.AdaptiveBitrate.Level"}),Dt=Object.freeze({OPEN:"MessageTransport.Open",CLOSE:"MessageTransport.Close",CHANGE:"MessageTransport.Change",ERROR:"MessageTransport.Error"}),Mt=Object.freeze({AUDIO_STREAM:"Conference.AudioStream",VIDEO_STREAM:"Conference.VideoStream",MEDIA_STREAM:"Conference.MediaStream"});function Ft(e,t,n){return t=Ut(t),function(e,t){if(t&&("object"==Gt(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,function(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return function(){return!!e}()}()?Reflect.construct(t,n||[],Ut(e).constructor):t.apply(e,n))}function Ut(e){return(Ut=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function Bt(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Vt(e,t)}function Vt(e,t){return(Vt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function Gt(e){return(Gt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Wt(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Yt(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:void 0;Wt(this,e),this._type=t,this._data=n}),[{key:"type",get:function(){return this._type}},{key:"data",get:function(){return this._data}}])}(),qt=function(e){function t(e,n,r){var o;return Wt(this,t),(o=Ft(this,t,[e,r]))._publisher=n,o}return Bt(t,e),zt(t,[{key:"publisher",get:function(){return this._publisher}}])}(Jt),Xt=function(e){function t(e,n,r){var o;return Wt(this,t),(o=Ft(this,t,[e,r]))._subscriber=n,o}return Bt(t,e),zt(t,[{key:"subscriber",get:function(){return this._subscriber}}])}(Jt),$t=function(e){function t(e,n,r){var o;return Wt(this,t),(o=Ft(this,t,[e,r]))._name=n,o}return Bt(t,e),zt(t,[{key:"name",get:function(){return this._name}}])}(Jt),Qt=function(e){function t(e,n,r){var o;return Wt(this,t),(o=Ft(this,t,[e,r]))._participant=n,o}return Bt(t,e),zt(t,[{key:"participant",get:function(){return this._participant}}])}(Jt);function Zt(e){return(Zt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function en(e,t){for(var n=0;n1||"touchend"==e.type&&e.touches.length>0)){var t,n,r=ve.createEvent("MouseEvent"),o=e.originalTarget||e.target;switch(e.type){case"touchstart":t="mousedown",n=e.changedTouches[0];break;case"touchmove":t="mousemove",n=e.changedTouches[0];break;case"touchend":t="mouseup",n=e.changedTouches[0]}r.initMouseEvent(t,!0,!0,o.ownerDocument.defaultView,0,n.screenX,n.screenY,n.clientX,n.clientY,e.ctrlKey,e.altKey,e.shiftKey,e.metaKey,0,null),o.dispatchEvent(r)}}},{key:"_mouseup",value:function(){this._eventStartPosition=0,document.removeEventListener("mousemove",this._mousemoveHandler),document.removeEventListener("mouseup",this._mouseupHandler),document.removeEventListener("touchmove",this._touchmoveHandler),document.removeEventListener("touchup",this._touchupHandler),document.removeEventListener("touchend",this._touchupHandler),this.trigger(new an(sn.CHANGE_COMPLETE,this))}},{key:"_mousemove",value:function(e){var t=ve.getMouseXFromEvent(e)-this._eventStartPosition,n=this._button.parentNode.getBoundingClientRect(),r=this._eventStartPosition+t-n.left;r=Math.max(0,r);var o=(r=Math.min(r,n.width))/n.width;this.trigger(new an(sn.CHANGE,this,o))}},{key:"_mousedown",value:function(e){this._eventStartPosition=ve.getMouseXFromEvent(e),this.trigger(new an(sn.CHANGE_START,this)),document.addEventListener("mousemove",this._mousemoveHandler),document.addEventListener("mouseup",this._mouseupHandler),document.addEventListener("touchmove",this._touchmoveHandler),document.addEventListener("touchup",this._touchupHandler),document.addEventListener("touchend",this._touchupHandler)}},{key:"_updateHandlers",value:function(e){this._eventStartPosition=0,e?(this._track.removeEventListener("click",this._mousemoveHandler),this._progressBar.removeEventListener("click",this._mousemoveHandler),this._button.removeEventListener("mousedown",this._mousedownHandler),document.removeEventListener("mousemove",this._mousemoveHandler),document.removeEventListener("mouseup",this._mouseupHandler),document.removeEventListener("touchmove",this._touchmoveHandler),document.removeEventListener("touchup",this._touchupHandler),document.removeEventListener("touchend",this._touchupHandler),this._track.classList.add("red5pro-media-slider-disabled"),this._progressBar.classList.add("red5pro-media-slider-disabled"),this._button.classList.add("red5pro-media-slider-disabled")):(this._track.addEventListener("click",this._mousemoveHandler),this._progressBar.addEventListener("click",this._mousemoveHandler),this._button.addEventListener("mousedown",this._mousedownHandler),this._button.addEventListener("touchstart",this._touchdownHandler),this._track.classList.remove("red5pro-media-slider-disabled"),this._progressBar.classList.remove("red5pro-media-slider-disabled"),this._button.classList.remove("red5pro-media-slider-disabled"))}},{key:"_layout",value:function(){var e=this._progressBar.parentNode.clientWidth*this._value;this._progressBar.style.width=e+"px",this._button.style.left=e-.5*this._button.clientWidth+"px"}},{key:"createButton",value:function(){var e=ve.createElement("span");return e.classList.add("red5pro-media-slider-button"),e}},{key:"createProgressBar",value:function(){var e=ve.createElement("span");return e.classList.add("red5pro-media-slider-progress"),e}},{key:"createTrack",value:function(){var e=ve.createElement("span");return e.classList.add("red5pro-media-slider-track"),e}},{key:"value",get:function(){return this._value},set:function(e){this._value=e,this._layout()}},{key:"disabled",get:function(){return this._disabled},set:function(e){this._disabled=e,this._updateHandlers(e)}},{key:"view",get:function(){return this._container}}])}(M),yn=Object.freeze({UNAVAILABLE:1e3,AVAILABLE:0,IDLE:1,PLAYING:2,PAUSED:3}),bn=Object.freeze({1e3:"Playback.UNAVAILABLE",0:"Playback.AVAILABLE",1:"Playback.IDLE",2:"Playback.PLAYING",3:"Playback.PAUSED"}),gn=Object.freeze({LIVE:0,VOD:1}),_n=Object.freeze({0:"LiveSeek.LIVE",1:"LiveSeek.VOD"});function wn(e){return(wn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Sn(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function En(e,t){for(var n=0;n=60&&(n=parseInt(r/60),r%=60),t=0===e||isNaN(e)?0:parseInt(e%60);var o=n<10?["0"+n]:[n];return o.push(r<10?["0"+r]:[r]),o.push(t<10?["0"+t]:[t]),o.join(":")}},{key:"getVolume",value:function(){return this._volumeValue}},{key:"setVolume",value:function(e){return this._volumeField.value=e,this._volumeValue=e,0===e?this.setMutedState(!0):this.getMutedState()&&this.setMutedState(!1),this}},{key:"setSeekTime",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return this._seekTimeField.value=0===t?0:e/t,0!==this._playbackDuration&&parseInt(this._playbackDuration)<=parseInt(e)&&(this._seekTimeField.value=1),!isFinite(this._playbackDuration)&&ve.getIsPossiblySafari()?this._timeField.innerText="Live Broadcast":this._timeField.innerText=this.formatTime(Math.floor(e)),this}},{key:"setPlaybackDuration",value:function(e){v("PlaybackControls","[setplaybackduration]: "+e),this._playbackDuration=e}},{key:"getPlaybackDuration",value:function(){return this._playbackDuration}},{key:"getState",value:function(){return this._state}},{key:"setState",value:function(e){return v("PlaybackControls","[setState]: "+bn[e]),this._state=e,this.onStateChange(this._state),this}},{key:"getMutedState",value:function(){return"muted"in this.player?this.player.muted:this._mutedState}},{key:"setMutedState",value:function(e){return this._mutedState=e,this.onMutedStateChange(this._mutedState),this}},{key:"onStateChange",value:function(e){return e===yn.PLAYING?(this._playPauseButton.classList.remove("red5pro-media-play-button"),this._playPauseButton.classList.add("red5pro-media-pause-button")):(this._playPauseButton.classList.add("red5pro-media-play-button"),this._playPauseButton.classList.remove("red5pro-media-pause-button")),this}},{key:"onMutedStateChange",value:function(e){e?(this._muteButton.classList.add("red5pro-media-mute-button"),this._muteButton.classList.remove("red5pro-media-unmute-button"),this._volumeField.value=0):(this._muteButton.classList.remove("red5pro-media-mute-button"),this._muteButton.classList.add("red5pro-media-unmute-button"),this._volumeField.value=this._volumeValue)}},{key:"onFullScreenChange",value:function(e){return e?(this._fullScreenButton.classList.add("red5pro-media-exit-fullscreen-button"),this._fullScreenButton.classList.remove("red5pro-media-fullscreen-button")):(this._fullScreenButton.classList.remove("red5pro-media-exit-fullscreen-button"),this._fullScreenButton.classList.add("red5pro-media-fullscreen-button")),this}},{key:"setAsVOD",value:function(e){v("PlaybackControls","[setAsVOD]: "+e),e?this._seekTimeField.disabled=!1:(this._seekTimeField.value=0,this._seekTimeField.disabled=!0)}},{key:"detach",value:function(){this.enable(!1),this._controlbar&&this._controlbar.parentNode&&this._controlbar.parentNode.removeChild(this._controlbar),this._controlbar=void 0,this.container=void 0}}])}(An);function In(e){return(In="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function xn(e,t){for(var n=0;n0&&void 0!==arguments[0]&&arguments[0];this.play().catch((function(n){t?(e.mute(),e.play().then((function(){e.trigger(new Xt(jt.AUTO_PLAYBACK_MUTED,void 0,{element:e.media}))})).catch((function(t){e.trigger(new Xt(jt.AUTO_PLAYBACK_FAILURE,void 0,{error:t.message?t.message:t,element:e.media}))}))):e.trigger(new Xt(jt.AUTO_PLAYBACK_FAILURE,void 0,{error:n.message?n.message:n,element:e.media}))}))}},{key:"play",value:function(){v("RTCSourceHandler","[videoelement:action] play");var e=new C;if(!this.media.paused)return v("RTCSourceHandler","[videoelement:action] play (ALREADY PLAYING)"),e.resolve(),e.promise;try{var t=this.media.play();t?t.then((function(){v("RTCSourceHandler","[videoelement:action] play (START)"),e.resolve()})).catch(e.reject):(v("RTCSourceHandler","[videoelement:action] play (START)"),e.resolve())}catch(t){y("RTCSourceHandler","[videoelement:action] play (FAULT) - "+t.message),e.reject(t)}return e.promise}},{key:"pause",value:function(){v("RTCSourceHandler","[videoelement:action] pause");try{this.media.pause()}catch(e){m("RTCSourceHandler","[videoelement:action] pause (CATCH::FAULT) - "+e.message)}}},{key:"resume",value:function(){v("RTCSourceHandler","[videoelement:action] resume");try{var e=this.media.play();e&&e.then((function(){return v("RTCSourceHandler","[videoelement:action] play (START)")})).catch((function(e){return m("RTCSourceHandler","[videoelement:action] play (CATCH::FAULT) "+(e.message?e.message:e))}))}catch(e){m("RTCSourceHandler","[videoelement:action] resume (CATCH::FAULT) - "+e.message)}}},{key:"stop",value:function(){v("RTCSourceHandler","[videoelement:action] stop");try{this.media.stop()}catch(e){}}},{key:"mute",value:function(){this.media.muted=!0;var e=this.getControls();e&&e.setMutedState(!0)}},{key:"unmute",value:function(){this.media.muted=!1;var e=this.getControls();e&&e.setMutedState(!1)}},{key:"setVolume",value:function(e){this.unmute(),this.media.volume=e}},{key:"seekTo",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;this.media.currentTime=t?e*t:e}},{key:"toggleFullScreen",value:function(){try{this.holder&&ve.toggleFullScreen(this.holder)}catch(e){throw e}}},{key:"unpublish",value:function(){try{this.stop(),this.media.onended.call(this.media)}catch(e){}}},{key:"disconnect",value:function(){this._cleanUp()}},{key:"handleOrientationChange",value:function(e){this._controls&&e%180!=0&&(this.holder&&this.holder.classList.add("red5pro-media-background"),this.media.classList.remove("red5pro-media-background"))}},{key:"getControls",value:function(){return this._controls}},{key:"getType",value:function(){return this.playerType}},{key:"isVOD",get:function(){return this._isVOD},set:function(e){this._isVOD=e,this._controls&&this._controls.setAsVOD(e)}}])&&xn(n.prototype,r),o&&xn(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,o}(Nn);function Vn(e){return(Vn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Gn(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */Gn=function(){return t};var e,t={},n=Object.prototype,r=n.hasOwnProperty,o=Object.defineProperty||function(e,t,n){e[t]=n.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",s=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function u(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,n){return e[t]=n}}function l(e,t,n,r){var i=t&&t.prototype instanceof m?t:m,a=Object.create(i.prototype),s=new R(r||[]);return o(a,"_invoke",{value:k(e,n,s)}),a}function d(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}t.wrap=l;var h="suspendedStart",f="executing",p="completed",v={};function m(){}function y(){}function b(){}var g={};u(g,a,(function(){return this}));var _=Object.getPrototypeOf,w=_&&_(_(L([])));w&&w!==n&&r.call(w,a)&&(g=w);var S=b.prototype=m.prototype=Object.create(g);function E(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function C(e,t){function n(o,i,a,s){var c=d(e[o],e,i);if("throw"!==c.type){var u=c.arg,l=u.value;return l&&"object"==Vn(l)&&r.call(l,"__await")?t.resolve(l.__await).then((function(e){n("next",e,a,s)}),(function(e){n("throw",e,a,s)})):t.resolve(l).then((function(e){u.value=e,a(u)}),(function(e){return n("throw",e,a,s)}))}s(c.arg)}var i;o(this,"_invoke",{value:function(e,r){function o(){return new t((function(t,o){n(e,r,t,o)}))}return i=i?i.then(o,o):o()}})}function k(t,n,r){var o=h;return function(i,a){if(o===f)throw Error("Generator is already running");if(o===p){if("throw"===i)throw a;return{value:e,done:!0}}for(r.method=i,r.arg=a;;){var s=r.delegate;if(s){var c=P(s,r);if(c){if(c===v)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(o===h)throw o=p,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=f;var u=d(t,n,r);if("normal"===u.type){if(o=r.done?p:"suspendedYield",u.arg===v)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(o=p,r.method="throw",r.arg=u.arg)}}}function P(t,n){var r=n.method,o=t.iterator[r];if(o===e)return n.delegate=null,"throw"===r&&t.iterator.return&&(n.method="return",n.arg=e,P(t,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),v;var i=d(o,t.iterator,n.arg);if("throw"===i.type)return n.method="throw",n.arg=i.arg,n.delegate=null,v;var a=i.arg;return a?a.done?(n[t.resultName]=a.value,n.next=t.nextLoc,"return"!==n.method&&(n.method="next",n.arg=e),n.delegate=null,v):a:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,v)}function O(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 T(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function R(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(O,this),this.reset(!0)}function L(t){if(t||""===t){var n=t[a];if(n)return n.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function n(){for(;++o=0;--i){var a=this.tryEntries[i],s=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),u=r.call(a,"finallyLoc");if(c&&u){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),T(n),v}},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 o=r.arg;T(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:L(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),v}},t}function Wn(e,t,n,r,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function Yn(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function zn(e,t){for(var n=0;n3&&void 0!==arguments[3])||arguments[3];return Yn(this,t),(o=Jn(this,t)).media=e,o.clone=o.media.cloneNode(!0),o.parent=o.media.parentNode,o.holder=i?o._determineHolder(o.media):void 0,o.playerType=n,o.hlsOptions=r,o.subscriberId=void 0,o.hlsElement=void 0,o._usePlaybackControls=i,o._isVOD=!1,o._isSeekable=!1,o._isHLSPlaybackActive=!1,o._isFragLoading=!1,o._hlsRecoverFlop=!1,o._hlsRecoverAttempts=0,o._lastDurationUpdate=0,o._controls=void 0,o._resizeObserver=void 0,o._playbackNotificationCenter=o.media,o._pendingUnpublish=!1,o._wallOffset=NaN,o._averageSegmentDuration=6,o._manifestLoadTimeout=0,ve.onFullScreenStateChange(o._handleFullScreenChange.bind(o)),o.hls=void 0,o.hlsElement=void 0,o}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Xn(e,t)}(t,e),function(e,t,n){return t&&zn(e.prototype,t),n&&zn(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}(t,[{key:"_determineHolder",value:function(e){if(e.parentNode.classList.contains("red5pro-media-container"))return e.parentNode;var t=e.parentNode,n=ve.createElement("div");return n.classList.add("red5pro-media-container"),t.insertBefore(n,e),t.removeChild(e),n.appendChild(e),n}},{key:"_generateHLSLivePlayback",value:function(e,t,n){var r="".concat(n,"-hls-vod"),o=document.querySelector("#".concat(r));return o||((o=document.createElement("video")).id=r,o.classList.add("red5pro-hls-vod"),o.playsinline="playsinline",o.style.width="100%",o.style.height="100%",o.style.position="absolute",o.style.display="none",e.insertBefore(o,t)),o}},{key:"_loadManifest",value:(n=Gn().mark((function e(t){var n,r,o,i,a,s,c,u,l,d,h=this;return Gn().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return clearTimeout(this._manifestLoadTimeout),e.prev=1,n=/^#EXT-X-TARGETDURATION:(.*)/,r=/^.*_(.*)\.\.*/,e.next=6,fetch(t,{method:"GET",mode:"cors",cache:"no-cache",headers:{"Content-Type":"text/plain;charset=UTF-8"}});case 6:return o=e.sent,e.next=9,o.text();case 9:i=e.sent,a=i.split("\r\n"),s=a.reverse().find((function(e){return r.test(e)})),c=a.find((function(e){return n.test(e)})).match(n)[1],u=parseFloat(c),l=s.match(r)[1],d=parseInt(l,10),isNaN(d)&&(d=1),d=d>1?d-1:d,this._averageSegmentDuration=u,console.log("MANIFEST: ",i),this.isSeekable=!0,this.trigger(new Xt(It.LIVE_SEEK_ENABLED,void 0,{hlsElement:this.hlsElement,hlsControl:void 0})),this._onHLSDurationChange({target:this.hlsElement,duration:u*d}),this._manifestLoadTimeout=setTimeout((function(){clearTimeout(h._manifestLoadTimeout),h._loadManifest(t)}),1e3*u),e.next=31;break;case 26:e.prev=26,e.t0=e.catch(1),y("Could not load manifest: ".concat(e.t0.message,".")),this.trigger(new Xt(It.LIVE_SEEK_DISABLED,void 0,{hlsElement:this.hlsElement,hlsControl:void 0})),this.isSeekable=!1;case 31:case"end":return e.stop()}}),e,this,[[1,26]])})),r=function(){var e=this,t=arguments;return new Promise((function(r,o){var i=n.apply(e,t);function a(e){Wn(i,r,o,a,s,"next",e)}function s(e){Wn(i,r,o,a,s,"throw",e)}a(void 0)}))},function(e){return r.apply(this,arguments)})},{key:"_showHLSLivePlayback",value:function(e,t,n,r){if(this._isHLSPlaybackActive!==e){this._isHLSPlaybackActive=e;var o=e?n.muted:t.muted;if(e){t.volume=n.volume,t.muted=o,n.muted=!0,t.style.display="inline-block",r.style.position="relative";try{n.paused?this.pause(!1):(this.pause(!0),this.play())}catch(e){m("Could not start playback: ".concat(e.message,"."))}n.style.display="none"}else{n.volume=t.volume,t.muted=!0,n.muted=o,n.style.display="inline-block";try{t.paused?this.pause(!1):(this.pause(!0),this.play())}catch(e){m("Could not start playback: ".concat(e.message,"."))}t.style.display="none"}var i=e?gn.VOD:gn.LIVE;this.trigger(new Xt(It.LIVE_SEEK_CHANGE,void 0,{code:i,state:_n[i]}))}}},{key:"_cleanUp",value:function(){if(this.clone){var e=this.media,t=e.parentNode,n=this.holder;if(this._removePlaybackHandlers(e),this.hls&&(this.hls.detachMedia(),this.hls=void 0),this.hlsElement&&(this._removeSeekableHandlers(this.hlsElement),this.hlsElement.parentNode&&this.hlsElement.parentNode.removeChild(this.hlsElement),this.hlsElement=void 0),this._controls&&(this._controls.detach(),this._controls=void 0),t)t.removeChild(e),t!==this.parent&&(t.parentNode.removeChild(t),n=this.parent);else try{e.remove()}catch(e){m("RTCSeekableSourceHandler","Issue in DOM cleanup of WebRTC video object: ".concat(e.message))}this.media=this.clone.cloneNode(!0),n.appendChild(this.media),this._resizeObserver&&(this._resizeObserver.unobserve(),this._resizeObserver=void 0),this._isVOD=!1,this._isSeekable=!1,this._isHLSPlaybackActive=!1,this._isFragLoading=!1,this._hlsRecoverFlop=!1,this._hlsRecoverAttempts=0}}},{key:"_addPlaybackHandlers",value:function(e){var t=this,n=this.getControls();e.oncanplay=function(){v("RTCSeekableSourceHandler","[videoelement:event] canplay"),n&&n.enable(!0),t.trigger(new Xt(jt.PLAYBACK_STATE_CHANGE,void 0,{code:yn.AVAILABLE,state:bn[yn.AVAILABLE]})),t.trigger(new Xt(jt.VOLUME_CHANGE,void 0,{volume:e.volume}))},e.onended=function(){return t._onRTCEnded.bind(t)},e.ondurationchange=this._onRTCDurationChange.bind(this),e.ontimeupdate=this._onRTCTimeUpdate.bind(this),e.onplay=this._onRTCPlay.bind(this),e.onpause=this._onRTCPause.bind(this),e.onvolumechange=function(r){n&&n.getVolume()!==t.media.volume&&n.setVolume(t.media.volume),t.trigger(new Xt(jt.VOLUME_CHANGE,void 0,{volume:e.muted?0:e.volume}))},e.onencrypted=function(){v("RTCSeekableSourceHandler","[videoelement:event] encrypted")},e.onemptied=function(){v("RTCSeekableSourceHandler","[videoelement:event] emptied")},e.onloadeddata=function(){v("RTCSeekableSourceHandler","[videoelement:event] loadeddata"),t.trigger(new Xt(jt.VIDEO_DIMENSIONS_CHANGE,void 0,{width:t.media.videoWidth,height:t.media.videoHeight}))},e.onresize=function(){v("RTCSeekableSourceHandler","[videoelement:event] resize"),t.trigger(new Xt(jt.VIDEO_DIMENSIONS_CHANGE,void 0,{width:t.media.videoWidth,height:t.media.videoHeight}))},e.onloadedmetadata=function(){v("RTCSeekableSourceHandler","[videoelement:event] loadedmetadata"),t.trigger("loadedmetadata")},e.onloadstart=function(){v("RTCSeekableSourceHandler","[videoelement:event] loadedstart")},e.onstalled=function(){v("RTCSeekableSourceHandler","[videoelement:event] stalled")},e.onsuspend=function(){v("RTCSeekableSourceHandler","[videoelement:event] suspend")},e.onwaiting=function(){v("RTCSeekableSourceHandler","[videoelement:event] waiting")}}},{key:"_removePlaybackHandlers",value:function(e){e.oncanplay=void 0,e.onended=void 0,e.ondurationchange=void 0,e.ontimeupdate=void 0,e.onplay=void 0,e.onpause=void 0,e.onvolumechange=void 0,e.onencrypted=void 0,e.onemptied=void 0,e.onloadeddata=void 0,e.onresize=void 0,e.onloadedmetadata=void 0,e.onloadstart=void 0,e.onstalled=void 0,e.onsuspend=void 0,e.onwaiting=void 0}},{key:"_addSeekableHandlers",value:function(e,t){var n=this,r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];t&&(t.on(ve.getHLSClientEventEnum().ERROR,(function(r,o){var i=o.type,a=o.details,s=o.fatal,c=o.url;if("networkerror"===i.toLowerCase()){if("levelemptyerror"===a.toLowerCase()){n.trigger(new Xt(It.LIVE_SEEK_DISABLED,void 0,{hlsElement:e,hlsControl:t})),n.isSeekable=!1,t.destroy();var u=setTimeout((function(){clearTimeout(u),n.enableLiveSeek(c,n.subscriberId,n.hlsElement,!1)}),3e3);return}n.trigger(new Xt(It.LIVE_SEEK_ERROR,void 0,{hlsElement:e,hlsControl:t,error:o}))}else n.trigger(new Xt(It.LIVE_SEEK_ERROR,void 0,{hlsElement:e,hlsControl:t,error:o}));"mediaerror"===i.toLowerCase()&&(n._hlsRecoverFlop&&t.swapAudioCodec(),n._hlsRecoverFlop=!n._hlsRecoverFlop,n._hlsRecoverAttempts=n._hlsRecoverAttempts+1,t.recoverMediaError()),s&&"networkerror"===i.toLowerCase()&&t.startLoad()})),t.on(ve.getHLSClientEventEnum().MANIFEST_PARSED,(function(){try{e.pause()}catch(e){v("RTCSeekableSourceHandler","Could not pause seekable live stream: ".concat(e.message))}n.isSeekable=!0,n.trigger(new Xt(It.LIVE_SEEK_ENABLED,void 0,{hlsElement:e,hlsControl:t}))})),t.on(ve.getHLSClientEventEnum().FRAG_LOADING,(function(r,o){var i=o.frag.stats,a=i.loaded,s=i.total;n.trigger(new Xt(It.LIVE_SEEK_LOADING,void 0,{hlsElement:e,hlsControl:t,progress:a/s*100})),(n.isHLSPlaybackActive||n._isFragLoading)&&(n._isFragLoading=a/s>=1)})),t.on(ve.getHLSClientEventEnum().FRAG_LOADED,(function(r,o){n._isFragLoading=!1;var i=o.frag,a=i.endDTS,s=i.loader;if(n.isHLSPlaybackActive||a){var c=6,u=0;if(s&&s.stats&&s.stats.segments){for(var l=s.stats.segments,d=0;d=t.duration?this._showHLSLivePlayback(!1,this.hlsElement,this.media,this.holder):!isNaN(t.duration)&&this._isHLSPlaybackActive&&this.trigger(new Xt(jt.PLAYBACK_TIME_UPDATE,void 0,{time:t.currentTime,duration:t.duration+this._averageSegmentDuration,action:"hls time update"}))}},{key:"_onHLSPlay",value:function(){v("RTCSeekableSourceHandler","[HLS:videoelement:event] play");var e=this.getControls();e&&e.setState(yn.PLAYING),this.trigger(new Xt(jt.PLAYBACK_STATE_CHANGE,void 0,{code:yn.PLAYING,state:bn[yn.PLAYING]}))}},{key:"_onHLSPause",value:function(){v("RTCSeekableSourceHandler","[HLS:videoelement:event] pause");var e=this.getControls();e&&e.setState(yn.PAUSED),this.trigger(new Xt(jt.PLAYBACK_STATE_CHANGE,void 0,{code:yn.PAUSED,state:bn[yn.PAUSED]}))}},{key:"_handleFullScreenChange",value:function(e){e?(this.holder&&this.holder.classList.add("red5pro-media-container-full-screen"),this.hlsElement&&this.hlsElement.classList.add("red5pro-media-container-full-screen"),this.media.classList.add("red5pro-media-container-full-screen")):(this.holder&&this.holder.classList.remove("red5pro-media-container-full-screen"),this.hlsElement&&this.hlsElement.classList.remove("red5pro-media-container-full-screen"),this.media.classList.remove("red5pro-media-container-full-screen")),this.trigger(new Xt(jt.FULL_SCREEN_STATE_CHANGE,void 0,e))}},{key:"addSource",value:function(e){v("RTCSeekableSourceHandler","[addsource]"),this.media.controls=!0,this.media.classList.add("red5pro-media"),ve.hasAttributeDefined(this.media,"controls")&&ve.hasClassDefined(this.media,"red5pro-media")&&(this.media.classList.add("red5pro-media"),this.holder=this._determineHolder(this.media));var t=new C,n=e.controls,r=ve.hasAttributeDefined(this.media,"muted");return n||this._usePlaybackControls?(this._controls=n?e.controls:new Hn(this,this.holder),this.media.controls=!1,this._controls.setAsVOD(this.isSeekable),this._controls.setMutedState(r)):this.media.controls=!1,this._addPlaybackHandlers(this._playbackNotificationCenter),t.resolve(),t.promise}},{key:"connect",value:function(){v("RTCSeekableSourceHandler","[connect]")}},{key:"attemptAutoplay",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.play().catch((function(n){t?(e.mute(),e.play().then((function(){e.trigger(new Xt(jt.AUTO_PLAYBACK_MUTED,void 0,{element:e.media}))})).catch((function(t){e.trigger(new Xt(jt.AUTO_PLAYBACK_FAILURE,void 0,{error:t.message?t.message:t,element:e.media}))}))):e.trigger(new Xt(jt.AUTO_PLAYBACK_FAILURE,void 0,{error:n.message?n.message:n,element:e.media}))}))}},{key:"enableLiveSeek",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,o=this.getControls();if(o&&o.setSeekTime(1,1),this.subscriberId=t,this.hlsElement=n||this._generateHLSLivePlayback(this.holder,this.media,this.subscriberId),this._showHLSLivePlayback(this.isHLSPlaybackActive,this.hlsElement,this.media,this.holder),r){this._addSeekableHandlers(this.hlsElement,null,!1);var i=document.createElement("source");i.src=e,this.hlsElement.appendChild(i),this._loadManifest(e)}else{var a=this.hlsOptions,s=this._hlsjsRef?new this._hlsjsRef(a):ve.createHLSClient(a);this._addSeekableHandlers(this.hlsElement,s),s.attachMedia(this.hlsElement),s.on(ve.getHLSClientEventEnum().MEDIA_ATTACHED,(function(){s.loadSource(e)})),this.hls=s}ve.setGlobal("r5pro_media_element",this.media),ve.setGlobal("r5pro_hls_element",this.hlsElement),ve.setGlobal("r5pro_hls_control",this.hls)}},{key:"switchLiveSeek",value:function(e){this.hls&&(this.hls.detachMedia(),this.hls=void 0),this.enableLiveSeek(e,this.subscriberId,this.hlsElement),this.seekTo(1);try{this.media.play()}catch(e){m("RTCSeekableSourceHandler","[videoelement:action] play (FAULT) - "+e.message)}}},{key:"play",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];v("RTCSeekableSourceHandler","[videoelement:action] play");var t=new C;try{var n;(n=e&&this.hlsElement&&this.hlsElement.paused?this.hlsElement.play():this.media.play())?n.then((function(){v("RTCSeekableSourceHandler","[videoelement:action] play (START)"),t.resolve()})).catch(t.reject):(v("RTCSeekableSourceHandler","[videoelement:action] play (START)"),t.resolve())}catch(e){y("RTCSeekableSourceHandler","[videoelement:action] play (FAULT) - "+e.message),t.reject(e)}return t.promise}},{key:"pause",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];v("RTCSeekableSourceHandler","[videoelement:action] pause");try{e&&t&&this.hlsElement?(this.hlsElement.pause(),this.media.pause()):e&&!this.hlsElement.paused&&this.hlsElement?this.hlsElement.pause():this.media.pause()}catch(e){m("RTCSeekableSourceHandler","[videoelement:action] pause (CATCH::FAULT) - "+e.message)}}},{key:"resume",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];v("RTCSeekableSourceHandler","[videoelement:action] resume");try{var t=this.isHLSPlaybackActive&&this.hlsElement?this.hlsElement.play():this.media.play();e&&this.isHLSPlaybackActive&&this.media.play().catch((function(e){return m("RTCSeekableSourceHandler","[videoelement:action] play (CATCH::FAULT) "+(e.message?e.message:e))})),t&&t.then((function(){return v("RTCSeekableSourceHandler","[videoelement:action] play (START)")})).catch((function(e){return m("RTCSeekableSourceHandler","[videoelement:action] play (CATCH::FAULT) "+(e.message?e.message:e))}))}catch(e){m("RTCSeekableSourceHandler","[videoelement:action] resume (CATCH::FAULT) - "+e.message)}}},{key:"stop",value:function(){v("RTCSeekableSourceHandler","[videoelement:action] stop");try{this.hlsElement&&this.hlsElement.stop(),this.media.stop()}catch(e){}}},{key:"mute",value:function(){this.hlsElement&&(this.hlsElement.muted=this.isHLSPlaybackActive),this.media.muted=!0;var e=this.getControls();e&&e.setMutedState(!0)}},{key:"unmute",value:function(){this.hlsElement?(this.hlsElement.muted=!this.isHLSPlaybackActive,this.media.muted=this.isHLSPlaybackActive):this.media.muted=!1;var e=this.getControls();e&&e.setMutedState(!1)}},{key:"setVolume",value:function(e){this.unmute(),this.hlsElement&&this.isHLSPlaybackActive?this.hlsElement.volume=e:this.media.volume=e}},{key:"seekTo",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;if(this.isSeekable)if(this._controls&&this._controls.setSeekTime(e,t),this.trigger(new Xt(jt.SEEK_CHANGE,void 0,{seek:e,duration:t})),this.hlsElement&&e<1)try{this.hlsElement.classList.remove("hidden"),this.hlsElement.currentTime=this.hlsElement.duration*e,this._isFragLoading=!0,this._showHLSLivePlayback(!0,this.hlsElement,this.media,this.holder),this.media.paused||(v("RTCSeekableSourceHandler","[hlsvod:action] play (START) - (seekTo)"),this.play(!0))}catch(e){m("RTCSeekableSourceHandler","[hlsvod:action] play (CATCH::FAULT) - "+e.message)}else this.hlsElement&&e>=1&&(this._isFragLoading=!1,this._showHLSLivePlayback(!1,this.hlsElement,this.media,this.holder));else this.media.currentTime=t?e*t:e}},{key:"toggleFullScreen",value:function(){try{this.holder&&ve.toggleFullScreen(this.holder)}catch(e){throw e}}},{key:"unpublish",value:function(){if(this._pendingUnpublish||!this.isHLSPlaybackActive)try{this.stop(),this.media.onended.call(this.media)}catch(e){}finally{this._pendingUnpublish=!1}else this._pendingUnpublish=!0}},{key:"disconnect",value:function(){this._cleanUp()}},{key:"handleOrientationChange",value:function(e){this._controls&&e%180!=0&&(this.holder&&this.holder.classList.add("red5pro-media-background"),this.media.classList.remove("red5pro-media-background"))}},{key:"getControls",value:function(){return this._controls}},{key:"getType",value:function(){return this.playerType}},{key:"isVOD",get:function(){return!1},set:function(e){}},{key:"isSeekable",get:function(){return this._isSeekable},set:function(e){this._isSeekable=e,this._controls&&this._controls.setAsVOD(e)}},{key:"isHLSPlaybackActive",get:function(){return this._isHLSPlaybackActive}}]);var n,r}(Nn);function Qn(e){return(Qn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Zn(e,t){for(var n=0;n0;)n.post(n._pendingPostRequests.shift());n._responder&&n._responder.onSocketOpen&&n._responder.onSocketOpen(),n.trigger(new $t(Dt.OPEN,n._name,{socket:n}))}else 0===e.readyState?++n._readyCheckCount>n._readyCheckLimit?(m(n._name,"WebSocket connection issue. We have waited for ".concat(n._readyCheckCount-1," samples, without any connection.")),n.clearRetry(),t.reject({type:"Timeout"}),n.tearDown()):(p(n._name,"WebSocket connection is still opening, will let it continue (".concat(n._readyCheckCount,")...")),n._onopenTimeout=n._resetOnopenTimeout(e,t)):p(n._name,"WebSocket connection attempts have ended with state (".concat(e.readyState,")."))}),500);return r}},{key:"_removeSocketHandlers",value:function(e){e&&(e.onopen=void 0,e.onmessage=void 0,e.onerror=void 0,e.onclose=void 0)}},{key:"_addSocketHandlers",value:function(e,t){var n=this;this._openState=0,this._readyCheckCount=0,clearTimeout(this._onopenTimeout),this._onopenTimeout=this._resetOnopenTimeout(e,t),e.onerror=function(e){m(n._name,"[websocketerror]: Error from WebSocket. ".concat(e.type,".")),n.clearRetry(),t.reject(e),n.trigger(new $t(Dt.ERROR,n._name,{socket:n,error:e}))},e.onmessage=function(e){n.respond(e)},e.onclose=function(t){t.code>1e3?m(n._name,"[websocketclose]: ".concat(t.code)):v(n._name,"[websocketclose]: ".concat(t.code)),n._responder&&n._responder.onSocketClose&&n._responder.onSocketClose(t),n.clearRetry(),n._removeSocketHandlers(e||n._websocket),n._openState=0,n.trigger(new $t(Dt.CLOSE,n._name,{socket:n,event:t}))}}},{key:"_onUnexpectedSocketError",value:function(e){this._responder&&this._responder.onSocketClose&&this._responder.onSocketClose(e),this.trigger(new $t(Dt.CLOSE,this._name,{socket:this})),m(this._name,"[websocketerror]: Possible Unexpected Error from WebSocket. ".concat(e.type,", ").concat(e.detail)),this.clearRetry(),this._removeSocketHandlers(this._websocket)}},{key:"clearRetry",value:function(){this._retryCount=0,this._readyCheckCount=0,clearTimeout(this._onopenTimeout)}},{key:"setUp",value:function(e,t){var n=this,r=ve.getIsMoz()||ve.getIsEdge();if(v(this._name,"[websocket:setup] ".concat(e,".")),this.tearDown(),this._isTerminated=!1,this._connectionPromise=t,ve.addCloseHandler(this._onclose),this._websocket=function(e){return ve.createWebSocket(e)}(e),this._addSocketHandlers(this._websocket,this._connectionPromise),r&&this._retryCount++>"),v(this._name,"[WebSocket(".concat(this._websocket.url,")] close() >>"));try{this._websocket.close()}catch(e){m(this._name,"Attempt to close WebSocket failed: ".concat(e.message,".")),this._removeSocketHandlers(this._websocket)}finally{this._websocket&&v(this._name,"<< [WebSocket(".concat(this._websocket.url,")] close()"))}v(this._name,"<< [teardown]")}for(this._websocket=void 0,this._isTerminated=!0,this._openState=0;this._responseHandlers.length>0;)this._responseHandlers.shift();ve.removeCloseHandler(this._onclose)}},{key:"postEndOfCandidates",value:function(e){this.post({handleCandidate:e,data:{candidate:{type:"candidate",candidate:""}}})}},{key:"post",value:function(e){if(void 0===this._websocket||1!==this._openState)return(void 0===this._websocket||2!==this._websocket.readyState&&3!==this._websocket.readyState)&&!this._isTerminated&&(this._pendingPostRequests.push(e),!0);try{return v(this._name,"[websocket-post]: "+JSON.stringify(e,null,2)),this._websocket.send(JSON.stringify(e)),!0}catch(t){return v(this._name,"Could not send request: ".concat(e,". ").concat(t)),!1}}},{key:"respond",value:function(e){var t=this.handleMessageResponse(e);if(!t&&e.data){var n=this.getJsonFromSocketMessage(e);if(null===n)return m(this._name,"Determined websocket response not in correct format. Aborting message handle."),!0;if(v(this._name,"[websocket-response]: "+JSON.stringify(n,null,2)),void 0!==n.isAvailable)return"boolean"==typeof n.isAvailable&&n.isAvailable?(this._responder&&this._responder.onStreamAvailable(n),!0):(this._responder&&this._responder.onStreamUnavailable(n),!0);if(n.async&&n.id){var r=this._asyncTickets.find((function(e){return e.id===n.id})).promise;r&&n.data?r.resolve(n.data):r&&n.error&&r.reject(n.error)}else if(void 0!==n.data){var o=n.data;if(void 0!==o.message){if("error"===o.type&&this._responder)return this._responder.onSocketMessageError(o.message,o.detail),!0}else if("status"===o.type){if("NetConnection.Connect.Success"===o.code)return this._websocket.onerror=this._onUnexpectedSocketError.bind(this),this._connectionPromise.resolve(this),!0;if("NetConnection.DataChannel.Available"===o.code)return this._responder.onDataChannelAvailable(o.description),!0;if("NetConnection.Connect.Rejected"===o.code)return this._connectionPromise.reject("NetConnection.Connect.Rejected"),!0}else if("error"===o.type){if("NetConnection.Connect.Rejected"===o.code)return this._connectionPromise.reject("NetConnection.Connect.Rejected"),!0;if("NetConnection.Connect.Failed"===o.code)return this._connectionPromise.reject("NetConnection.Connect.Failed"),!0}}}return t}},{key:"isTerminated",get:function(){return this._isTerminated}}])&&ar(n.prototype,r),o&&ar(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,o}(or);function hr(e){return(hr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function fr(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function pr(e){for(var t=1;t1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this.tearDown();var r=t||new C;try{var o={iceServers:e,iceCandidatePoolSize:2,bundlePolicy:"max-bundle"};void 0!==n&&(o.rtcpMuxPolicy=n),v("R5ProWebRTCPeer","[peerconnection:setup]: ".concat(JSON.stringify(o,null,2)));var i=new kt(o,{optional:[{RtpDataChannels:!1},{googCpuOveruseDetection:!0}]});this._addConnectionHandlers(i),this._peerConnection=i,r.resolve(i)}catch(e){m("R5ProWebRTCPeer","Could not establish a PeerConnection. ".concat(e.message)),r.reject(e.message)}return r.hasOwnProperty("promise")?r.promise:r}},{key:"setUpWithPeerConfiguration",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this.tearDown();var r=n||new C;try{v("R5ProWebRTCPeer","[peerconnection:setUpWithPeerConfiguration]: ".concat(JSON.stringify(e,null,2)));var o=new kt(e);t&&(this._dataChannel=o.createDataChannel(t.name,{ordered:!0}),this._addDataChannelHandlers(this._dataChannel)),this._addConnectionHandlers(o),this._peerConnection=o,r.resolve(o)}catch(e){m("R5ProWebRTCPeer","Could not establish a PeerConnection. ".concat(e.message)),r.reject(e.message)}return r.hasOwnProperty("promise")?r.promise:r}},{key:"tearDown",value:function(){if(this._dataChannel){this._removeDataChannelHandlers(this._dataChannel);try{this._dataChannel.close()}catch(e){m("R5ProWebRTCPeer","[datachannel.close] error: ".concat(e.message))}finally{this._dataChannel=void 0}}if(this._peerConnection){v("R5ProWebRTCPeer","[teardown]"),this._removeConnectionHandlers(this._peerConnection);try{this._peerConnection.close()}catch(e){m("R5ProWebRTCPeer","[peerconnection.close] error: ".concat(e.message))}finally{this._peerConnection=void 0}}}},{key:"setLocalDescription",value:function(e){return v("R5ProWebRTCPeer","[setlocaldescription]"),this._peerConnection.setLocalDescription(e)}},{key:"setRemoteDescription",value:function(e){return v("R5ProWebRTCPeer","[setremotedescription]"),this._peerConnection.setRemoteDescription(new Ot(e))}},{key:"addIceCandidate",value:function(e){return v("R5ProWebRTCPeer","[addcandidate]"),this._peerConnection.addIceCandidate(e)}},{key:"post",value:function(e){if(this._dataChannel){var t="string"==typeof e?e:JSON.stringify(e,null,2);v("R5ProWebRTCPeer","[datachannel.send] message: ".concat(t));try{return this._dataChannel.send(t),!0}catch(e){y("R5ProWebRTCPeer",e.hasOwnProperty("message")?e.message:e)}}return!1}},{key:"connection",get:function(){return this._peerConnection}},{key:"dataChannel",get:function(){return this._dataChannel}}])&&Tr(n.prototype,r),o&&Tr(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,o}(or);function Hr(e){return(Hr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Ir(e,t){for(var n=0;n0&&void 0===r._pendingMediaStream&&(r._pendingMediaStream=e.streams[0],r._responder.onAnswerMediaStream(e.streams[0]))},e.oniceconnectionstatechange=function(t){var o=e.iceConnectionState;v("R5ProSubscriptionPeer","[peer.oniceconnectionstatechange] - State: ".concat(o)),"connected"===o&&ve.getIsEdge()?(v("R5ProSubscriptionPeer","[edge/ortc:notify complete]"),r._responder.onPeerGatheringComplete(),e.onicecandidate({candidate:null})):"failed"===o?(n&&clearTimeout(n),r._responder.onPeerConnectionFail(),r._responder.onPeerConnectionClose(t)):"disconnected"===o?n=setTimeout((function(){v("R5ProSubscriptionPeer","[peer.oniceconnectionstatechange] - Reconnect timeout reached. Closing PeerConnection."),clearTimeout(n),r._responder.onPeerConnectionClose(t)}),5e3):n&&(v("R5ProSubscriptionPeer","[peer.oniceconnectionstatechange] - Clearing timeout for reconnect."),clearTimeout(n))},e.onicegatheringstatechange=function(){var t=e.iceGatheringState;v("R5ProSubscriptionPeer","[peer.onicegatheringstatechange] - State: ".concat(t)),"complete"===t&&r._responder.onPeerGatheringComplete()},e.onremovestream=function(){v("R5ProSubscriptionPeer","[peer.onremovestream]")}}},{key:"_onDataChannelMessage",value:function(e){var n,r,o,i,a,s=e;if((n=t,r="_onDataChannelMessage",o=this,a=Mr(Ur(1&(i=3)?n.prototype:n),r,o),2&i&&"function"==typeof a?function(e){return a.apply(o,e)}:a)([e]))return!0;var c=this.getJsonFromSocketMessage(s);if(null===c)return m(this._name,"Determined websocket response not in correct format. Aborting message handle."),!0;v(this._name,"[datachannel-response]: "+JSON.stringify(c,null,2));var u=c.data;if(u&&"status"===u.type)return"NetStream.Play.UnpublishNotify"===u.code?(this._responder.onUnpublish(),this._responder.onConnectionClosed(),!0):(v("R5ProSubscriptionPeer","[datachannel.message] status :: ".concat(u.code)),this._responder.onSubscriberStatus(u),!0);if(u&&u.status&&"NetStream.Play.UnpublishNotify"===u.status)return this._responder.onUnpublish(),this._responder.onConnectionClosed(),!0;if(u&&"result"===u.type&&"Stream switch: Success"===u.message)try{return this._responder.onStreamSwitchComplete(),!0}catch(r){}return this._responder.onDataChannelMessage(this._dataChannel,s),!1}},{key:"createAnswer",value:function(e){var t=this;v("R5ProSubscriptionPeer","[createanswer]");var n=new C;return this._peerConnection.setRemoteDescription(e).then(this._responder.onSDPSuccess).catch((function(e){t._responder.onSDPError(e)})),this._peerConnection.createAnswer().then((function(e){e.sdp=mt(e.sdp),t._peerConnection.setLocalDescription(e).then(t._responder.onSDPSuccess).catch((function(e){t._responder.onSDPError(e)})),n.resolve(e)})).catch(n.reject),n.promise}},{key:"addIceCandidate",value:function(e){if(v("R5ProSubscriptionPeer","checking if empty..."),function(e){return void 0===e||"string"==typeof e&&0===e.length}(e))v("R5ProSubscriptionPeer","[addicecandidate]:: empty");else if(null!==e){v("R5ProSubscriptionPeer","[addicecandidate] :: non-empty");var t=new Pt({sdpMLineIndex:e.sdpMLineIndex,candidate:e.candidate});this._peerConnection.addIceCandidate(t).then((function(){})).catch((function(e){y("R5ProSubscriptionPeer","Error in add of ICE Candidiate + ".concat(e))}))}else v("R5ProSubscriptionPeer","[addicecandidate] :: null"),this._peerConnection.addIceCandidate(e).then((function(){})).catch((function(e){y("R5ProSubscriptionPeer","Error in add of ICE Candidiate + ".concat(e))}))}}])}(jr);function Gr(e){return(Gr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Wr(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Yr(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:"red5pro-subscriber";Wr(this,e);try{this._targetElement=ve.resolveElement(t)}catch(e){throw y("R5ProPlaybackView","Could not instantiate a new instance of Red5ProSubscriber. Reason: ".concat(e.message)),e}},(t=[{key:"attachSubscriber",value:function(e){v("R5ProPlaybackView","[attachsubscriber]"),e.setView(this,ve.getElementId(this._targetElement))}},{key:"attachStream",value:function(e){var t=this.isAutoplay;v("R5ProPlaybackView","[attachstream]"),ve.setVideoSource(this._targetElement,e,t)}},{key:"detachStream",value:function(){v("R5ProPlaybackView","[detachstream]"),ve.setVideoSource(this._targetElement,null,this.isAutoplay)}},{key:"isAutoplay",get:function(){return ve.hasAttributeDefined(this._targetElement,"autoplay")}},{key:"view",get:function(){return this._targetElement}}])&&Yr(e.prototype,t),n&&Yr(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}(),Jr=function(e){switch(e){case 8083:case"8083":return console.warn("The default WebSocket port on the server has changed from 8083 to 443 for secure connections."),443;case 8081:case"8081":return console.warn("The default WebSocket port on the server has changed from 8081 to 5080 or 80 for secure connections."),5080}return e},qr=function(e){var t={};return Object.keys(e).forEach((function(n,r){t[n]=encodeURIComponent(e[n])})),t},Xr=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=e.wsprotocol||e.protocol,r=Jr(e.wsport||e.port),o=e.context?[e.app,e.context].join("/"):e.app,i=e.endpoint?e.endpoint:"".concat(n,"://").concat(e.host,":").concat(r,"/").concat(o,"/");if(void 0!==e.connectionParams){var a=qr(e.connectionParams);t=Object.assign(t,a)}if(void 0!==t){var s=[];Object.keys(t).forEach((function(e,n){s.push([e,t[e]].join("="))})),s.length>0&&(i+="?"+s.join("&"))}return i},$r=function(e){var t=e.host,n=e.hlsprotocol,r=e.protocol,o=e.hlsport,i=e.port,a=e.context,s=e.app,c=e.streamName,u=e.connectionParams,l=e.apiVersion,d=t,h=n||("ws"===r?"http":"https"),f=o||(5080===i?5080:443),p=a?[s,a].join("/"):s,v=l||"4.0";return u&&"streammanager"===s?"".concat(h,"://").concat(d,":").concat(f,"/streammanager/api/").concat(v,"/file/").concat(u.app,"/").concat(c,".m3u8"):"".concat(h,"://").concat(d,":").concat(f,"/").concat(p,"/").concat(c,".m3u8")},Qr=function(e){var t,n,r=new URL(e),o=r.pathname.split("/").filter((function(e){return e.length>0}));return n=r.protocol,t=r.hostname,{protocol:n,port:r.port.length>0?r.port:443,app:o[0],host:t,streamName:o[o.length-1]}},Zr=function(e,t,n){var r=e.host,o=e.hlsprotocol,i=e.protocol,a=e.hlsport,s=e.port,c=e.context,u=e.app,l=e.streamName,d=r,h=o||("ws"===i?"http":"https"),f=a||(5080===s?5080:443),p=c?[u,c].join("/"):u;if(n)return n;if(t){var v=t.length-1,m="/"===t.charAt(v)?t.substr(0,v):t;return"".concat(m,"/").concat(p,"/").concat(l,".m3u8")}return"".concat(h,"://").concat(d,":").concat(f,"/").concat(p,"/").concat(l,".m3u8")},eo=Object.freeze({RTC:"rtc",RTMP:"rtmp",HLS:"hls"}),to=Object.freeze({OPUS:"Opus",PCMU:"PCMU",PCMA:"PCMA",SPEEX:"Speex",NONE:"NONE"}),no=Object.freeze({VP8:"VP8",H264:"H264",NONE:"NONE"}),ro=Object.freeze({UDP:"udp",TCP:"tcp"}),oo=Object.freeze({ENCODED_FRAME:"EncodedFrame",PACKET:"Packet"}),io=Object.freeze({VIDEO:"encodeVideo",AUDIO:"encodeAudio"}),ao=Object.freeze({VIDEO:"decodeVideo",AUDIO:"decodeAudio"});function so(e){return(so="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function co(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */co=function(){return t};var e,t={},n=Object.prototype,r=n.hasOwnProperty,o=Object.defineProperty||function(e,t,n){e[t]=n.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",s=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function u(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,n){return e[t]=n}}function l(e,t,n,r){var i=t&&t.prototype instanceof m?t:m,a=Object.create(i.prototype),s=new R(r||[]);return o(a,"_invoke",{value:k(e,n,s)}),a}function d(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}t.wrap=l;var h="suspendedStart",f="executing",p="completed",v={};function m(){}function y(){}function b(){}var g={};u(g,a,(function(){return this}));var _=Object.getPrototypeOf,w=_&&_(_(L([])));w&&w!==n&&r.call(w,a)&&(g=w);var S=b.prototype=m.prototype=Object.create(g);function E(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function C(e,t){function n(o,i,a,s){var c=d(e[o],e,i);if("throw"!==c.type){var u=c.arg,l=u.value;return l&&"object"==so(l)&&r.call(l,"__await")?t.resolve(l.__await).then((function(e){n("next",e,a,s)}),(function(e){n("throw",e,a,s)})):t.resolve(l).then((function(e){u.value=e,a(u)}),(function(e){return n("throw",e,a,s)}))}s(c.arg)}var i;o(this,"_invoke",{value:function(e,r){function o(){return new t((function(t,o){n(e,r,t,o)}))}return i=i?i.then(o,o):o()}})}function k(t,n,r){var o=h;return function(i,a){if(o===f)throw Error("Generator is already running");if(o===p){if("throw"===i)throw a;return{value:e,done:!0}}for(r.method=i,r.arg=a;;){var s=r.delegate;if(s){var c=P(s,r);if(c){if(c===v)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(o===h)throw o=p,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=f;var u=d(t,n,r);if("normal"===u.type){if(o=r.done?p:"suspendedYield",u.arg===v)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(o=p,r.method="throw",r.arg=u.arg)}}}function P(t,n){var r=n.method,o=t.iterator[r];if(o===e)return n.delegate=null,"throw"===r&&t.iterator.return&&(n.method="return",n.arg=e,P(t,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),v;var i=d(o,t.iterator,n.arg);if("throw"===i.type)return n.method="throw",n.arg=i.arg,n.delegate=null,v;var a=i.arg;return a?a.done?(n[t.resultName]=a.value,n.next=t.nextLoc,"return"!==n.method&&(n.method="next",n.arg=e),n.delegate=null,v):a:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,v)}function O(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 T(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function R(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(O,this),this.reset(!0)}function L(t){if(t||""===t){var n=t[a];if(n)return n.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function n(){for(;++o=0;--i){var a=this.tryEntries[i],s=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),u=r.call(a,"finallyLoc");if(c&&u){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),T(n),v}},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 o=r.arg;T(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:L(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),v}},t}function uo(e,t,n,r,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function lo(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);function a(e){uo(i,r,o,a,s,"next",e)}function s(e){uo(i,r,o,a,s,"throw",e)}a(void 0)}))}}var ho=function(e){v("MediaTransformPipeline",e)},fo=function(){var e=lo(co().mark((function e(t,n,r){var o,i,a,s,c,u,l;return co().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=t.video,i=t.worker,a=t.workerOperationType,s=t.transformFrameType,c=t.pipeOptions,u=s||oo.BUFFER,l=a||io.VIDEO,!o){e.next=12;break}if(ho("[track.insertablestream]::video"),u!==oo.PACKET){e.next=9;break}return e.abrupt("return",Je(r.getVideoTracks()[0],o,c));case 9:return e.abrupt("return",qe(n,o,c));case 10:e.next=19;break;case 12:if(!i||!i.video){e.next=19;break}if(ho("[track.insertablestream]::worker(encode video)"),u!==oo.PACKET){e.next=18;break}return e.abrupt("return",Ye(l,r.getVideoTracks()[0],i.video,c));case 18:return e.abrupt("return",ze(l,n,i.video,c));case 19:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),po=function(){var e=lo(co().mark((function e(t,n,r){var o,i,a,s,c,u,l;return co().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=t.video,i=t.worker,a=t.workerOperationType,s=t.transformFrameType,c=t.pipeOptions,u=s||oo.BUFFER,l=a||ao.VIDEO,!o){e.next=12;break}if(ho("[track.insertablestream]::video"),u!==oo.PACKET){e.next=9;break}return e.abrupt("return",Je(r,o,c));case 9:return e.abrupt("return",Xe(n,o,c));case 10:e.next=19;break;case 12:if(!i||!i.video){e.next=19;break}if(ho("[track.insertablestream]::worker(decode video)"),u!==oo.PACKET){e.next=18;break}return e.abrupt("return",Ye(l,r,i.video,c));case 18:return e.abrupt("return",Ke(l,n,i.video,c));case 19:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),vo=function(){var e=lo(co().mark((function e(t,n,r){var o,i,a,s,c,u,l;return co().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=t.audio,i=t.worker,a=t.workerOperationType,s=t.transformFrameType,c=t.pipeOptions,u=s||oo.BUFFER,l=a||io.AUDIO,!o){e.next=12;break}if(ho("[track.insertablestream]::audio"),u!==oo.PACKET||!Ge){e.next=9;break}return e.abrupt("return",Je(r.getAudioTracks()[0],o,c));case 9:return e.abrupt("return",qe(n,o,c));case 10:e.next=19;break;case 12:if(!i||!i.audio){e.next=19;break}if(ho("[track.insertablestream]::worker(encode audio)"),u!==oo.PACKET||!Ge){e.next=18;break}return e.abrupt("return",Ye(l,r.getAudioTracks()[0],i.audio,c));case 18:return e.abrupt("return",ze(l,n,i.audio,c));case 19:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),mo=function(){var e=lo(co().mark((function e(t,n,r){var o,i,a,s,c,u,l;return co().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=t.audio,i=t.worker,a=t.workerOperationType,s=t.transformFrameType,c=t.pipeOptions,u=s||oo.BUFFER,l=a||ao.AUDIO,!o){e.next=12;break}if(ho("[track.insertablestream]::audio"),u!==oo.PACKET){e.next=9;break}return e.abrupt("return",Je(r,o,c));case 9:return e.abrupt("return",Xe(n,o,c));case 10:e.next=19;break;case 12:if(!i||!i.audio){e.next=19;break}if(ho("[track.insertablestream]::worker(decode audio)"),u!==oo.PACKET){e.next=18;break}return e.abrupt("return",Ye(l,r,i.audio,c));case 18:return e.abrupt("return",Ke(l,n,i.audio,c));case 19:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}();function yo(e){return(yo="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function bo(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function go(e){for(var t=1;t=0;--i){var a=this.tryEntries[i],s=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),u=r.call(a,"finallyLoc");if(c&&u){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),T(n),v}},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 o=r.arg;T(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:L(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),v}},t}function So(e,t,n,r,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function Eo(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:void 0;if(void 0===e&&void 0!==t){var n=new Kr(t);n.attachSubscriber(this)}}},{key:"_initHandler",value:function(e,t){e&&t&&(t.on("*",this._boundBubbleSubscriberEvents),t.addSource(e))}},{key:"_requestAvailability",value:function(e){v("RTCSubscriber","[requestavailability]"),this._socketHelper.post({isAvailable:e})}},{key:"_requestOffer",value:function(e,t,n,r,o){var i=arguments.length>5&&void 0!==arguments[5]?arguments[5]:void 0,a=arguments.length>6&&void 0!==arguments[6]?arguments[6]:void 0;v("RTCSubscriber","[requestoffer]");var s={requestOffer:e,requestId:t,transport:n,datachannel:r,doNotSwitch:o};return void 0!==i&&i!==no.NONE?s.videoEncoding=i:ve.getIsEdge(),void 0!==a&&a!==to.NONE&&(s.audioEncoding=a),this.trigger(new Xt(It.OFFER_START,this)),this._socketHelper.post(s),!0}},{key:"_requestAnswer",value:function(e){var t=this;v("RTCSubscriber","[requestanswer]"),this._peerHelper.createAnswer(e).then((function(e){v("RTCSubscriber","[onanswercreated]"),v("RTCSubscriber","[> sendanswer]"),t._sendAnswer(t._options.streamName,t._options.subscriptionId,e)})).catch((function(e){t.onSDPError(e)}))}},{key:"_sendAnswer",value:function(e,t,n){v("RTCSubscriber","[sendanswer]: streamname(".concat(e,"), subscriptionid(").concat(t,")")),this.trigger(new Xt(It.ANSWER_START,this,n)),this._socketHelper.post({handleAnswer:e,requestId:t,data:{sdp:n}})}},{key:"_sendCandidate",value:function(e){v("RTCSubscriber","[sendcandidate]"),this.trigger(new Xt(It.CANDIDATE_START,this,e)),this._socketHelper.post({handleCandidate:this._options.streamName,requestId:this._options.subscriptionId,data:{candidate:e}})}},{key:"_setUpConnectionHandlers",value:function(e){var t=this;e.addEventListener("track",(function(e){v("RTCSubscriber","[peerconnection.ontrack]");var n=e.streams,r=e.track,o=e.receiver,i=e.transceiver;r.kind;o.playoutDelayHint=o.jitterBufferDelayHint=t._options.buffer,t.trigger(new Xt(It.TRACK_ADDED,t,{streams:n,track:r,receiver:o,transceiver:i}))}))}},{key:"_setUpMediaTransform",value:(n=wo().mark((function e(t,n){var r,o,i,a,s;return wo().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=2;break}return e.abrupt("return",!0);case 2:if(e.prev=2,r=n.getReceivers().find((function(e){return e.track&&"video"===e.track.kind})),o=n.getReceivers().find((function(e){return e.track&&"audio"===e.track.kind})),i=t.audio,a=t.video,s=t.worker,!r||!a&&!s){e.next=16;break}return e.prev=7,e.next=10,po(t,r,r.track);case 10:e.sent,e.next=16;break;case 13:e.prev=13,e.t0=e.catch(7),this.trigger(new Xt(It.TRANSFORM_ERROR,this,{type:"video",error:e.t0}));case 16:if(!o||!i&&!s){e.next=26;break}return e.prev=17,e.next=20,mo(t,o,o.track);case 20:e.sent,e.next=26;break;case 23:e.prev=23,e.t1=e.catch(17),this.trigger(new Xt(It.TRANSFORM_ERROR,this,{type:"audio",error:e.t1}));case 26:return e.abrupt("return",!0);case 29:return e.prev=29,e.t2=e.catch(2),this.trigger(new Xt(It.TRANSFORM_ERROR,this,{error:e.t2})),e.abrupt("return",!1);case 33:case"end":return e.stop()}}),e,this,[[2,29],[7,13],[17,23]])})),r=function(){var e=this,t=arguments;return new Promise((function(r,o){var i=n.apply(e,t);function a(e){So(i,r,o,a,s,"next",e)}function s(e){So(i,r,o,a,s,"throw",e)}a(void 0)}))},function(e,t){return r.apply(this,arguments)})},{key:"_connect",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;return v("RTCSubscriber","[connect]"),r&&e&&(m("The iceServers configuration property is considered deprecated. Please use the rtcConfiguration configuration property upon which you can assign iceServers. Reference: https://www.red5pro.com/docs/streaming/migrationguide.html"),e.iceServers=r),this._options.iceServers=e?e.iceServers:r,(void 0!==e?this._peerHelper.setUpWithPeerConfiguration(e,n,void 0):this._peerHelper.setUp(this._options.iceServers,void 0,this._options.rtcpMuxPolicy)).then((function(e){return t._setUpConnectionHandlers(e),t.trigger(new Xt(It.PEER_CONNECTION_AVAILABLE,t,e)),t._requestOffer(t._options.streamName,t._options.subscriptionId,t._options.iceTransport,t._options.signalingSocketOnly,t._options.maintainStreamVariant,t._options.videoEncoding,t._options.audioEncoding)})).catch((function(e){m("RTCSubscriber","Could not establish RTCPeerConnection."),t.trigger(new Xt(jt.CONNECT_FAILURE,t))})),this}},{key:"_disconnect",value:function(){this._socketHelper&&(v("RTCSubscriber","[disconnect:socket]"),this._socketHelper.tearDown()),this._peerHelper&&(v("RTCSubscriber","[disconnect:peer]"),this._peerHelper.tearDown()),this._view&&this._view.detachStream(),this._socketHelper=void 0,this._peerHelper=void 0,this._messageTransport=void 0,this._sourceHandler&&(v("RTCSubscriber","[disconnect:source]"),this._sourceHandler.disconnect(),this._sourceHandler=void 0),this._connectionClosed=!0}},{key:"_manageStreamMeta",value:function(e){var t,n=e.getTracks(),r=n.find((function(e){return"audio"===e.kind})),o=n.find((function(e){return"video"===e.kind}));o&&(o.muted||(t="Video")),r&&(r.muted||(t=t?"".concat(t,"/Audio"):"Audio")),t||(t="Empty"),this.onMetaData({streamingMode:t,method:"onMetaData"})}},{key:"_addStreamHandlers",value:function(e){var t=this,n=e.getTracks(),r=n.find((function(e){return"audio"===e.kind})),o=n.find((function(e){return"video"===e.kind}));o&&(o.addEventListener("mute",(function(){t._manageStreamMeta(e)})),o.addEventListener("unmute",(function(){t._manageStreamMeta(e)}))),r&&(r.addEventListener("mute",(function(){t._manageStreamMeta(e)})),r.addEventListener("unmute",(function(){t._manageStreamMeta(e)}))),this._manageStreamMeta(e)}},{key:"_playIfAutoplaySet",value:function(e,t){e&&t&&(e.autoplay=ve.hasAttributeDefined(t.view,"autoplay"),e.autoplay&&this._sourceHandler.attemptAutoplay(e.muteOnAutoplayRestriction))}},{key:"_startSeekable",value:function(e){var t=e.liveSeek,n=e.subscriptionId;if(t){var r=t.enabled,o=t.baseURL,i=t.fullURL,a=t.hlsjsRef,s=t.hlsElement;if(r)try{if(!ve.supportsHLS()&&!ve.supportsNonNativeHLS(a))throw new Error;var c=Zr(e,o,i);this._sourceHandler.enableLiveSeek(c,n,s,!ve.supportsNonNativeHLS())}catch(e){y("RTCSubscriber","Could not utilize the 'LiveSeek' request. This feature requires either native HLS playback or hls.js as a depenency.")}}}},{key:"_sendSubscribe",value:function(){v("RTCSubscriber","[sendsubscribe]"),this._socketHelper.post({subscribe:this._options.streamName,requestId:this._options.subscriptionId})}},{key:"init",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=new C;if(Be()&&Tt()){this._disconnect(),this._options=Object.assign({},Lo,e),this._options.subscriptionId=this._options.subscriptionId||Ro(),this._mediaTransform=n,this._mediaTransform&&!We()&&(this.trigger(new Xt(It.UNSUPPORTED_FEATURE,this,{feature:"Insertable Streams",message:"You provided Media Transforms for track processing, but your current browser does not support the Insertable Streams API."})),this._mediaTransform=void 0),this._peerHelper=new Vr(this),this._socketHelper=new Er(this),this._messageTransport=this._messageTransport||this._socketHelper;var o=new C,i=Xr(this._options,{id:this._options.subscriptionId});o.promise.then((function(){r.resolve(t),t._connectionClosed=!1,t.trigger(new Xt(jt.CONNECT_SUCCESS,t))})).catch((function(e){r.reject(e),t.trigger(new Xt(jt.CONNECT_FAILURE,t,e))})),this._socketHelper.setUp(i,o)}else r.reject("Cannot create WebRTC playback instance. Your environment does not support WebRTC and/or WebSockets.");return r.promise}},{key:"setView",value:function(e){return this._view=e,this._viewResolver.resolve(this._view),this}},{key:"subscribe",value:function(){var e=this,t=this._options,n=t.streamName,r=t.mediaElementId,o=t.rtcConfiguration,i=t.liveSeek,a=this._options,s=a.signalingSocketOnly,c=a.dataChannelConfiguration,u=s&&Ve();return u&&!c&&(c={name:"red5pro"}),this._options.signalingSocketOnly=u,this._getViewResolverPromise().then((function(t){if(i&&i.enabled){var n=i.hlsjsRef,r=i.usePlaybackControlsUI,o=i.options;ve.supportsNonNativeHLS(n)?e._sourceHandler=new $n(t.view,e.getType(),o,r):(y("RTCSubscriber","Could not utilize the 'LiveSeek' request. This feature requires either native HLS playback or hls.js as a depenency."),e.trigger(new Xt(It.LIVE_SEEK_UNSUPPORTED,e,{feature:"Live Seek",message:"Live Seek requires integration with the HLS.JS plugin in order work properly. Most likely you are viewing this on a browser that does not support the use of HLS.JS."})),e._sourceHandler=new Bn(t.view,e.getType()))}else e._sourceHandler=new Bn(t.view,e.getType());e._glomSourceHandlerAPI(e._sourceHandler),e._initHandler(e._options,e._sourceHandler)})).catch((function(){})),this._getAvailabilityResolverPromise().then((function(){var t=o;void 0===o.encodedInsertableStreams&&(t=Object.assign(o,{encodedInsertableStreams:!!e._mediaTransform})),e._connect(t,c,e._options.iceServers)})).catch((function(){})),this._setViewIfNotExist(this._view,r),this._options.bypassAvailable?this._availabilityResolver.resolve(this):this._requestAvailability(n),this._getSubscriptionResolverPromise()}},{key:"unsubscribe",value:function(){v("RTCSubscriber","[unsubscribe]");var e=new C;return this.stop(),this._disconnect(),this._mediaStream=void 0,e.resolve(this),this.trigger(new Xt(jt.SUBSCRIBE_STOP,this)),e.promise}},{key:"transform",value:function(e){!e||We()?this.getPeerConnection()?this._setUpMediaTransform(e,this.getPeerConnection()):this._mediaTransform=e:this.trigger(new Xt(jt.UNSUPPORTED_FEATURE,this,{feature:"Insertable Streams",message:"You provided Media Transforms for track processing, but your current browser does not support the Insertable Streams API."}))}},{key:"onStreamAvailable",value:function(e){v("RTCSubscriber","[onstreamavailable]: "+JSON.stringify(e,null,2)),this._availabilityResolver.resolve(this)}},{key:"onStreamUnavailable",value:function(e){v("RTCSubscriber","Stream ".concat(this._options.streamName," does not exist.")),v("RTCSubscriber","[onstreamunavailable]: "+JSON.stringify(e,null,2)),this.trigger(new Xt(jt.SUBSCRIBE_INVALID_NAME,this)),this._availabilityResolver.reject("Stream ".concat(this._options.streamName," does not exist.")),this._subscriptionResolver.reject("Stream ".concat(this._options.streamName," does not exist.")),this._options.maintainConnectionOnSubscribeErrors?(this._availabilityResolver=new C,this._subscriptionResolver=new C):this._disconnect()}},{key:"onSDPSuccess",value:function(e){v("RTCSubscriber","[onsdpsuccess]: "+JSON.stringify(e,null,2))}},{key:"onSDPOffer",value:function(e){v("RTCSubscriber","[onsdpoffer]: "+JSON.stringify(e,null,2));var t=new Ot(e.sdp);this.trigger(new Xt(It.OFFER_END,this)),this._requestAnswer(t)}},{key:"onSDPError",value:function(e){this.trigger(new Xt(jt.SUBSCRIBE_FAIL,this,e)),this._subscriptionResolver.reject("Invalid SDP."),y("RTCSubscriber","[onsdperror]"),y("RTCSubscriber",e)}},{key:"onAnswerMediaStream",value:function(){this.trigger(new Xt(It.ANSWER_END,this))}},{key:"onIceCandidate",value:function(e){v("RTCSubscriber","[onicecandidate]"),this.trigger(new Xt(It.CANDIDATE_END,this)),this._sendCandidate(e)}},{key:"onIceCandidateTrickleEnd",value:function(e){var t=this;v("RTCSubscriber","[onicetrickleend]"),this._getViewResolverPromise().then((function(n){n.attachStream(e),t._mediaStream=e,t._setUpMediaTransform(t._mediaTransform,t.getPeerConnection()),t.trigger(new Xt(It.ON_ADD_STREAM,t,t._mediaStream))}))}},{key:"onAddIceCandidate",value:function(e){v("RTCSubscriber","[onaddicecandidate]"),this._peerHelper.addIceCandidate(e)}},{key:"onEmptyCandidate",value:function(){v("RTCSubscriber","[icecandidatetrickle:empty]"),this.trigger(new Xt(It.PEER_CANDIDATE_END))}},{key:"onPeerGatheringComplete",value:function(){v("RTCSubscriber","[icecandidategathering:end]"),this._socketHelper&&this._socketHelper.postEndOfCandidates(this._options.streamName)}},{key:"onSocketIceCandidateEnd",value:function(){v("RTCSubscriber","[onsocketicecandidateend]"),this.trigger(new Xt(It.ICE_TRICKLE_COMPLETE,this)),this._sendSubscribe()}},{key:"onSocketMessage",value:function(e,t){this.trigger(new Xt(It.SOCKET_MESSAGE,this,{socket:e,message:t}))}},{key:"onSocketMessageError",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;y("RTCSubscriber","Error in stream subscription: ".concat(e,".\n[Optional detail]: ").concat(t)),this._subscriptionResolver.reject("Error in stream subscription: ".concat(e,".")),this.trigger(new Xt(jt.SUBSCRIBE_FAIL,this,e))}},{key:"onSocketClose",value:function(e){v("RTCSubscriber","[onsocketclose]"),this._peerHelper&&this._peerHelper.tearDown(),this.onConnectionClosed(e)}},{key:"onPeerConnectionFail",value:function(){v("RTCSubscriber","[onpeerconnectionfail]"),this.trigger(new Xt(jt.SUBSCRIBE_FAIL,this,"fail")),this._subscriptionResolver&&this._subscriptionResolver.reject("Peer Connection Failed.")}},{key:"onPeerConnectionClose",value:function(e){v("RTCSubscriber","[onpeerconnectionclose]");var t=this._options.liveSeek;(this._socketHelper&&this._socketHelper.tearDown(),t)?t.enabled||this.onSocketClose(e):this.onSocketClose(e)}},{key:"onPeerConnectionOpen",value:function(){v("RTCSubscriber","[onpeerconnectionopen]"),this.trigger(new Xt(It.PEER_CONNECTION_OPEN),this,this.getPeerConnection())}},{key:"onUnpublish",value:function(){v("RTCSubscriber","[onunpublish]"),this.trigger(new Xt(jt.PLAY_UNPUBLISH,this));var e=this._options.liveSeek;(this._sourceHandler&&this._sourceHandler.unpublish(),e)?e.enabled||this.unsubscribe():this.unsubscribe()}},{key:"onConnectionClosed",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0,t=this._options.liveSeek;if(!this._connectionClosed){if(v("RTCSubscriber","[onconnectionclosed]"),t){var n=t.enabled;n||this._disconnect()}else this._disconnect();this.trigger(new Xt(jt.CONNECTION_CLOSED,this,e))}}},{key:"onSendReceived",value:function(e,t){"onMetaData"===e?this.onMetaData(t):"onPublisherNetworkCongestion"===e?this.onPublisherNetworkCongestion(t):"onPublisherNetworkRecovery"===e?this.onPublisherNetworkRecovery(t):this.trigger(new Xt(jt.SUBSCRIBE_SEND_INVOKE,this,{methodName:e,data:t}))}},{key:"onSubscriberStatus",value:function(e){v("RTCSubscriber","[subscriberstatus] - "+JSON.stringify(e,null,2));var t=To.exec(e.message);t&&t[1]===this._options.streamName?(this._subscriptionResolver.resolve(this),this.trigger(new Xt(jt.SUBSCRIBE_START,this)),this._playIfAutoplaySet(this._options,this._view),this._startSeekable(this._options,this._view)):this.trigger(new Xt(jt.SUBSCRIBE_STATUS,this,e))}},{key:"onDataChannelAvailable",value:function(e){var t=this;if(v("RTCSubscriber","[ondatachannel::available]"),this._switchChannelRequest={switchChannel:e||"red5pro"},this._options.signalingSocketOnly)var n=setTimeout((function(){clearTimeout(n),t._socketHelper&&t._socketHelper.sever(t._switchChannelRequest),t._messageTransport=t._peerHelper,t.trigger(new $t(Dt.CHANGE,t,{controller:t,transport:t._messageTransport}))}),this._socketHelper?this._options.socketSwitchDelay:100);this.trigger(new Xt(It.DATA_CHANNEL_AVAILABLE,this,{name:e,dataChannel:this.getDataChannel()}))}},{key:"onDataChannelError",value:function(e,t){this.trigger(new Xt(It.DATA_CHANNEL_ERROR,this,{dataChannel:e,error:t}))}},{key:"onDataChannelMessage",value:function(e,t){this.trigger(new Xt(It.DATA_CHANNEL_MESSAGE,this,{dataChannel:e,message:t}))}},{key:"onDataChannelOpen",value:function(e){this.trigger(new Xt(It.DATA_CHANNEL_OPEN,this,{dataChannel:e}))}},{key:"onDataChannelClose",value:function(e){this.trigger(new Xt(It.DATA_CHANNEL_CLOSE,this,{dataChannel:e}))}},{key:"onMetaData",value:function(e){var t=e.orientation,n=e.streamingMode,r=this._streamingMode;void 0!==t&&t!==this._orientation&&(this._orientation=t,this._options.autoLayoutOrientation&&(Se(this._view.view,parseInt(t,10),Oe(e.resolution)),this._sourceHandler&&this._sourceHandler.handleOrientationChange(parseInt(t,10))),this.trigger(new Xt(jt.ORIENTATION_CHANGE,this,{orientation:parseInt(t,10),viewElement:this._view.view}))),void 0!==n&&n!==r&&(this._streamingMode=n,this.trigger(new Xt(jt.STREAMING_MODE_CHANGE,this,{streamingMode:n,previousStreamingMode:r,viewElement:this._view.view}))),this.trigger(new Xt(jt.SUBSCRIBE_METADATA,this,e))}},{key:"onStreamSwitchComplete",value:function(){v("RTCSubscriber","[streamswitch::complete]");var e=this._options.liveSeek,t=this._requestedStreamSwitch;if(e&&e.enabled){var n=e.baseURL,r=e.fullURL,o=t.split("/").pop(),i=t.substr(0,t.lastIndexOf("/".concat(o))),a=go(go({},this._options),{},{app:i,streamName:o}),s=r;if(r){var c=/.*\/(.*)\.m3u8/.exec(r);if(c&&c.length>1){var u="".concat(c[1],".m3u8");s=r.replace(u,"".concat(o,".m3u8"))}}var l=Zr(a,n,s);this._sourceHandler.switchLiveSeek(l)}this.trigger(new Xt(It.SUBSCRIBE_STREAM_SWITCH,this,{path:t})),this._requestedStreamSwitch=void 0}},{key:"onPublisherNetworkCongestion",value:function(e){this.trigger(new Xt(jt.SUBSCRIBE_PUBLISHER_CONGESTION,this,e))}},{key:"onPublisherNetworkRecovery",value:function(e){this.trigger(new Xt(jt.SUBSCRIBE_PUBLISHER_RECOVERY,this,e))}},{key:"callServer",value:function(e,t){var n="switchStreams"===e,r=this._options,o=r.app,i=r.streamName;if(n){var a=t[0].path;this._requestedStreamSwitch=a,v("RTCSubscriber","[callServer:switch]:: ".concat(e,", ").concat(o,"/").concat(i," -> ").concat(a))}return this.getMessageTransport().postAsync({callAdapter:{method:e,arguments:t}})}},{key:"sendLog",value:function(e,t){try{var n=Object.keys(d).find((function(t){return t.toLowerCase()===e.toLowerCase()}))?e:d.DEBUG,r="string"==typeof t?t:JSON.stringify(t);this.getMessageTransport().post({log:n.toUpperCase(),message:r})}catch(e){var o=e.message||e;y("RTCSubscriber","Could not send log to server. Message parameter expected to be String or JSON-serializable object."),y("RTCSubscriber",o)}}},{key:"enableStandby",value:function(){this.getMessageTransport().post({mute:{muteAudio:!0,muteVideo:!0}})}},{key:"disableStandby",value:function(){this.getMessageTransport().post({mute:{muteAudio:!1,muteVideo:!1}})}},{key:"muteAudio",value:function(){this.getMessageTransport().post({mute:{muteAudio:!0}})}},{key:"unmuteAudio",value:function(){this.getMessageTransport().post({mute:{muteAudio:!1}})}},{key:"muteVideo",value:function(){this.getMessageTransport().post({mute:{muteVideo:!0}})}},{key:"unmuteVideo",value:function(){this.getMessageTransport().post({mute:{muteVideo:!1}})}},{key:"getMessageTransport",value:function(){return this._messageTransport}},{key:"getConnection",value:function(){return this._socketHelper}},{key:"getPeerConnection",value:function(){return this._peerHelper?this._peerHelper.connection:void 0}},{key:"getDataChannel",value:function(){return this._peerHelper?this._peerHelper.dataChannel:void 0}},{key:"getMediaStream",value:function(){return this._mediaStream}},{key:"getControls",value:function(){return this._sourceHandler?this._sourceHandler.getControls():void 0}},{key:"getPlayer",value:function(){return this._view.view}},{key:"getOptions",value:function(){return this._options}},{key:"getType",value:function(){return eo.RTC.toUpperCase()}}]);var n,r}(Nn),No=function(e,t){var n=new C,r=e.id;if("video"===e.nodeName.toLowerCase()){var o=ve.createElement("div");o.id=r+"_rtmp",t.appendChild(o),e.parentElement&&e.parentElement.removeChild(e),n.resolve(o.id)}else n.resolve(r);return n.promise},jo=function(e,t,n,r,o){var i=new C,a={quality:"high",wmode:"opaque",bgcolor:t.backgroundColor||"#000",allowscriptaccess:"always",allowfullscreen:"true",allownetworking:"all"},s={id:e,name:e,align:"middle"};return r.hasFlashPlayerVersion(t.minFlashVersion)?r.embedSWF(t.swf,o,t.embedWidth||640,t.embedHeight||480,t.minFlashVersion,t.productInstallURL,n,a,s,(function(e){e.success?i.resolve():i.reject("Flash Object embed failed.")})):i.reject("Flash Player Version is not supported."),i.promise};function Ho(e){return(Ho="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Io(e,t){for(var n=0;n2&&void 0!==arguments[2]?arguments[2]:null,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;v("RTMPSourceHandler","[addsource]"),this._swfId=e,this.holder=this._determineHolder(this.media);var i=new C,a=t.controls,s=ve.hasAttributeDefined(this.media,"muted"),c=ve.hasAttributeDefined(this.media,"controls")&&ve.hasClassDefined(this.media,"red5pro-media");t.swf=r||t.swf,t.minFlashVersion=o||t.minFlashVersion,this._setUpInitCallback(i);var u=this.media.classList;return No(this.media,this.holder).then((function(r){var o={stream:t.streamName,app:t.context?"".concat(t.app,"/").concat(t.context):t.app,host:t.host,muted:ve.hasAttributeDefined(n.media,"muted"),autoplay:ve.hasAttributeDefined(n.media,"autoplay"),useAdaptiveBitrateController:t.useAdaptiveBitrateController};return t.backgroundColor&&(o.backgroundColor=t.backgroundColor),t.buffer&&!isNaN(Number(t.buffer))&&(o.buffer=t.buffer),t.width&&!isNaN(t.width)&&(o.width=Uo(t.width)),t.height&&!isNaN(t.height)&&(o.height=Uo(t.height)),"100%"!==t.embedWidth&&"100%"!==t.embedHeight||(o.autosize=!0),n._swfId=e,void 0!==t.connectionParams&&(o.connectionParams=encodeURIComponent(JSON.stringify(t.connectionParams))),void 0!==t.abrVariants&&(o.abrVariants=encodeURIComponent(JSON.stringify(t.abrVariants))),void 0!==t.abrVariantUpgradeSettings&&(o.abrVariantUpgradeSettings=encodeURIComponent(JSON.stringify(t.abrVariantUpgradeSettings))),jo(e,t,o,ve.getSwfObject(),r)})).then((function(){if(a||c){n._controls=a?t.controls:new Hn(n,n.holder),n.media.controls=!1,n._controls.setAsVOD(Bo(t.streamName)),n._controls.setMutedState(s);for(var e,r=n.getEmbeddedView(),o=u.length;--o>-1;)e=u.item(o),r.classList.add(e)}return n._addPlaybackHandlers(n._playbackNotificationCenter),n.trigger(new Xt(jt.PLAYBACK_STATE_CHANGE,void 0,{code:yn.AVAILABLE,state:bn[yn.AVAILABLE]})),!0})).then((function(){return!0})).catch((function(e){return i.reject(e)})),i.promise}},{key:"connect",value:function(){v("RTMPSourceHandler","[connect]");try{this.getEmbeddedView().connect()}catch(e){throw e}}},{key:"play",value:function(){try{this.getEmbeddedView().play()}catch(e){throw e}}},{key:"pause",value:function(){try{this.getEmbeddedView().pause()}catch(e){throw e}}},{key:"resume",value:function(){try{this.getEmbeddedView().resume()}catch(e){throw e}}},{key:"stop",value:function(){try{this.getEmbeddedView().stop()}catch(e){throw e}}},{key:"mute",value:function(){try{this.getEmbeddedView().mute()}catch(e){throw e}}},{key:"unmute",value:function(){try{this.getEmbeddedView().unmute()}catch(e){throw e}}},{key:"setVolume",value:function(e){try{this.getEmbeddedView().setVolume(e)}catch(e){throw e}}},{key:"seekTo",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;try{this.getEmbeddedView().seekTo(e,t)}catch(e){throw e}}},{key:"toggleFullScreen",value:function(){try{ve.toggleFullScreen(this.holder)}catch(e){throw e}}},{key:"unpublish",value:function(){this.stop()}},{key:"disconnect",value:function(){try{this.getEmbeddedView().disconnect(),v("RTMPSourceHandler","[disconnect]")}catch(e){}this._cleanUp()}},{key:"startABRController",value:function(){try{this.getEmbeddedView().startABRController()}catch(e){v("RTMPSourceHandler","Could not start the Adaptive Bitrate Controller: ".concat(e.message))}}},{key:"stopABRController",value:function(){try{this.getEmbeddedView().stopABRController()}catch(e){v("RTMPSourceHandler","Could not stop the Adaptive Bitrate Controller: ".concat(e.message))}}},{key:"setABRVariants",value:function(e,t){try{var n="string"==typeof e?encodeURIComponent(e):encodeURIComponent(JSON.stringify(e));this.getEmbeddedView().setABRVariants(n,t||1)}catch(e){v("RTMPSourceHandler","Could not set ABR Variants: ".concat(e.message))}}},{key:"setABRLevel",value:function(e,t){try{this.getEmbeddedView().setABRLevel(e,!!t)}catch(e){v("RTMPSourceHandler","Could not set ABR level: ".concat(e.message))}}},{key:"setABRVariantUpgradeSettings",value:function(e){try{var t="string"==typeof abrVariants?encodeURIComponent(e):encodeURIComponent(JSON.stringify(e));this.getEmbeddedView().setABRVariantUpgradeSettings(t)}catch(e){v("RTMPSourceHandler","Could not set ABR Variants: ".concat(e.message))}}},{key:"getEmbeddedView",value:function(){return ve.getEmbedObject(this._swfId)}},{key:"getControls",value:function(){return this._controls}},{key:"getType",value:function(){return this.playerType}}])&&Io(n.prototype,r),o&&Io(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,o}(Nn);function Go(e){return(Go="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Wo(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:void 0;if(void 0===e&&void 0!==t){var n=new Kr(t);n.attachSubscriber(this)}}},{key:"_establishExtIntHandlers",value:function(e){var t=this;v("RTMPSubcriber","Subscriber ID provided to client: (".concat(e,")."));var n=function(t){return["subscriber",t,e.split("-").join("_")].join("_")};window[n("r5proConnectClosed")]=function(){return t.trigger(new Xt(jt.CONNECTION_CLOSED,t))},window[n("r5proConnectSuccess")]=function(){return t.trigger(new Xt(jt.CONNECT_SUCCESS,t))},window[n("r5proConnectFailure")]=function(){t.trigger(new Xt(jt.CONNECT_FAILURE,t))},window[n("r5proSubscribeStop")]=function(){return t.trigger(new Xt(jt.SUBSCRIBE_STOP,t))},window[n("r5proSubscribeMetadata")]=function(e){var n=JSON.parse(e),r=n.orientation,o=n.streamingMode,i=parseInt(r,10),a=t._streamingMode;t._orientation!==i&&(t._orientation=i,t.trigger(new Xt(jt.ORIENTATION_CHANGE,t,{orientation:i}))),a!==o&&(t._streamingMode=o,t.trigger(new Xt(jt.STREAMING_MODE_CHANGE,t,{streamingMode:o,previousStreamingMode:a}))),t.trigger(new Xt(jt.SUBSCRIBE_METADATA,t,JSON.parse(e)))},window[n("r5proSubscribeUnpublish")]=function(){t.onUnpublish()},window[n("r5proSubscribePublisherCongestion")]=function(e){return t.trigger(new Xt(jt.SUBSCRIBE_PUBLISHER_CONGESTION,t,JSON.parse(e)))},window[n("r5proSubscribePublisherRecovery")]=function(e){return t.trigger(new Xt(jt.SUBSCRIBE_PUBLISHER_RECOVERY,t,JSON.parse(e)))},window[n("r5proSubscribeSendInvoke")]=function(e){t.trigger(new Xt(jt.SUBSCRIBE_SEND_INVOKE,t,"string"==typeof e?JSON.parse(e):e))},window[n("r5proSubscribePlayRequest")]=function(){t.play()},window[n("r5proSubscribeStart")]=function(){t._subscriptionResolver.resolve(t),t.trigger(new Xt(jt.SUBSCRIBE_START,t))},window[n("r5proSubscribeInvalidName")]=function(){t._subscriptionResolver.reject("NetStream.Play.StreamNotFound",t),t.trigger(new Xt(jt.SUBSCRIBE_INVALID_NAME,t))},window[n("r5proSubscribeFail")]=function(){t._subscriptionResolver.reject("NetStream.Failed",t),t.trigger(new Xt(jt.SUBSCRIBE_FAIL,t))},window[n("r5proSubscribeVolumeChange")]=function(e){t.trigger(new Xt(jt.VOLUME_CHANGE,t,{volume:JSON.parse(e).volume}))},window[n("r5proSubscribePlaybackStalled")]=function(){v("RTMPSubcriber","playback has stalled...")},window[n("r5proSubscribePlaybackTimeChange")]=function(e){var n=JSON.parse(e);t.trigger(new Xt(jt.PLAYBACK_TIME_UPDATE,t,{time:n.value,duration:n.duration}))},window[n("r5proSubscribePlaybackStateChange")]=function(e){var n=JSON.parse(e).code;t.trigger(new Xt(jt.PLAYBACK_STATE_CHANGE,t,{code:n,state:bn[n]}))},window[n("r5proSubscribeABRLevelChange")]=function(e){var n=JSON.parse(e),r=n.level,o=n.stream,i=JSON.parse(decodeURIComponent(o));t.trigger(new Xt(xt.ABR_LEVEL_CHANGE,t,{level:r,stream:i}))}}},{key:"init",value:function(e){var t=this,n=new C,r=e.minFlashVersion||qo.minFlashVersion;if(ve.supportsFlashVersion(r)){this._options=Object.assign({},qo,e);try{ve.injectScript(this._options.swfobjectURL).then((function(){var e=t._embedPromise;return v("RTMPSubcriber","SWFObject embedded."),t._sourceHandler?(t._sourceHandler.addSource(t._elementId,t._options).then((function(n){t._establishExtIntHandlers(n),e.resolve(t)})).catch((function(t){e.reject(t)})),t._getEmbedPromise()):(t._getViewResolverPromise().then((function(e){if(t._sourceHandler=new Vo(t,e.view,t.getType()),t._glomSourceHandlerAPI(t._sourceHandler),t._options){var n=t._embedPromise;t._sourceHandler.addSource(t._elementId,t._options).then((function(e){t._establishExtIntHandlers(e),n.resolve(t)})).catch((function(e){return n.reject(e)}))}})),!0)})).then((function(){t._setViewIfNotExist(t._view,t._options.mediaElementId),n.resolve(t)})).catch((function(e){y("RTMPSubcriber","Could not embed Flash-based RTMP Player. Reason: ".concat(e)),t._sourceHandler&&t._sourceHandler.disconnect(),n.reject(e),t.trigger(new Xt(xt.EMBED_FAILURE,t))}))}catch(e){n.reject("Could not inject Flash-based Player into the page. Reason: ".concat(e.message)),this.trigger(new Xt(xt.EMBED_FAILURE,this))}}else m("RTMPSubcriber","Could not resolve RTMPSubscriber instance. Requires minimum Flash Player install of ".concat(r,".")),n.reject("Could not resolve RTMPSubscriber instance. Requires minimum Flash Player install of ".concat(r,"."));return n.promise}},{key:"setView",value:function(e,t){return this._view=e,this._elementId=t,this._viewResolver.resolve(this._view),this}},{key:"subscribe",value:function(){return this._getSubscriptionResolverPromise()}},{key:"unsubscribe",value:function(){var e=this;return v("RTMPSubcriber","[unsubscribe]"),new Promise((function(t,n){try{e._sourceHandler.disconnect(),t()}catch(e){n(e.message)}}))}},{key:"play",value:function(){var e=this;v("RTMPSubcriber","[play]"),this._getEmbedPromise().then((function(){e._sourceHandler.play()}))}},{key:"onEmbedComplete",value:function(){v("RTMPSubcriber","[embed:complete]"),this.trigger(new Xt(xt.EMBED_SUCCESS,this))}},{key:"onEmbedFailure",value:function(e){v("RTMPSubcriber","[embed:failure] - ".concat(e)),this.trigger(new Xt(xt.EMBED_FAILURE,this))}},{key:"onUnpublish",value:function(){v("RTMPSubcriber","[onunpublish]"),this._sourceHandler&&this._sourceHandler.unpublish(),this.trigger(new Xt(jt.PLAY_UNPUBLISH,this)),this._sourceHandler&&this._sourceHandler.disconnect()}},{key:"getConnection",value:function(){return this._sourceHandler}},{key:"getControls",value:function(){return this._sourceHandler?this._sourceHandler.getControls():void 0}},{key:"getOptions",value:function(){return this._options}},{key:"getPlayer",value:function(){return this._sourceHandler?this._sourceHandler.getEmbeddedView():void 0}},{key:"getType",value:function(){return eo.RTMP.toUpperCase()}}])&&Wo(n.prototype,r),o&&Wo(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,o}(Nn);function $o(e){return($o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Qo(e,t){for(var n=0;n0&&void 0!==arguments[0]&&arguments[0];this.play().catch((function(n){t?(e.mute(),e.play().then((function(){e.trigger(new Xt(jt.AUTO_PLAYBACK_MUTED,void 0,{element:e.media}))})).catch((function(t){e.trigger(new Xt(jt.AUTO_PLAYBACK_FAILURE,void 0,{error:t.message?t.message:t,element:e.media}))}))):e.trigger(new Xt(jt.AUTO_PLAYBACK_FAILURE,void 0,{error:n.message?n.message:n,element:e.media}))}))}},{key:"play",value:function(){v("HLSSourceHandler","[videoelement:action] play");var e=new C;try{var t=this.media.play();t?t.then((function(){v("HLSSourceHandler","[videoelement:action] play (START)"),e.resolve()})).catch(e.reject):(v("HLSSourceHandler","[videoelement:action] play (START)"),e.resolve())}catch(t){y("HLSSourceHandler","[videoelement:action] play (FAULT) - "+t.message),e.reject(t)}return e.promise}},{key:"pause",value:function(){v("HLSSourceHandler","[videoelement:action] pause");try{this.media.pause()}catch(e){v("HLSSourceHandler","[videoelement:action] pause (FAULT) - "+e.message)}}},{key:"resume",value:function(){v("HLSSourceHandler","[videoelement:action] resume");try{var e=this.media.play();e&&e.then((function(){return v("HLSSourceHandler","[videoelement:action] play (START)")})).catch((function(e){return y("HLSSourceHandler","[videoelement:action] play (FAULT) "+(e.message?e.message:e))}))}catch(e){y("HLSSourceHandler","[videoelement:action] resume (FAULT) - "+e.message)}}},{key:"stop",value:function(){try{this.media.stop()}catch(e){}}},{key:"mute",value:function(){this.media.muted=!0;var e=this.getControls();e&&e.setMutedState(!0)}},{key:"unmute",value:function(){this.media.muted=!1;var e=this.getControls();e&&e.setMutedState(!1)}},{key:"setVolume",value:function(e){this.unmute(),this.media.volume=e}},{key:"seekTo",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;this.media.currentTime=t?e*t:e}},{key:"toggleFullScreen",value:function(){try{ve.toggleFullScreen(this.holder)}catch(e){throw e}}},{key:"unpublish",value:function(){try{this.stop(),this.media.onended.call(this.media)}catch(e){}}},{key:"disconnect",value:function(){this._cleanUp()}},{key:"_handleOrientationChange",value:function(e){this._controls&&e%180!=0&&(this.holder.classList.add("red5pro-media-background"),this.media.classList.remove("red5pro-media-background"))}},{key:"getControls",value:function(){return this._controls}},{key:"getType",value:function(){return this.playerType}},{key:"isVOD",get:function(){return this._isVOD},set:function(e){this._isVOD=e,this._controls&&this._controls.setAsVOD(e)}}])&&Qo(n.prototype,r),o&&Qo(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,o}(Nn);function oi(e){return(oi="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function ii(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:void 0;if(void 0===e&&void 0!==t){var n=new Kr(t);n.attachSubscriber(this)}}},{key:"_initHandler",value:function(e){var t=this,n=this._options,r=n.streamName,o=n.mimeType,i=r.match(hi)?r:$r(this._options);this._sourceHandler.on("*",this._boundBubbleSubscriberEvents),this._sourceHandler.addSource(i,o,e).then((function(){t.trigger(new Xt(jt.CONNECT_SUCCESS)),t._trackStreamingModeState(t._sourceHandler)})).catch((function(e){y("HLSSubscriber","Could not establish an HLS Subscriber: "+e),t.trigger(new Xt(jt.CONNECT_FAILURE))}))}},{key:"_trackStreamingModeState",value:function(e){var t=this;e.on(jt.STREAMING_MODE_CHANGE,(function(e){var n=e.data,r=n.streamingMode,o=n.previousStreamingMode;if("Empty"!==r&&"Empty"===o){t._sourceHandler.disconnect();var i=t._options,a=i.streamName,s=i.mimeType,c=a.match(hi)?a:$r(t._options);t._sourceHandler.addSource(c,s,t._options).then((function(){return t.subscribe()})).catch((function(e){return e("HLSSubscriber",e)}))}}))}},{key:"init",value:function(e){var t=this,n=new C;if(ve.supportsHLS())if(e.connectionParams&&!Tt())m("HLSSubscriber","Could not resolve HLSSubscriber instance with connection params. WebSocket support is required."),n.reject("HLSSubscriber","Could not resolve HLSSubscriber instance with connection params. WebSocket support is required.");else{this._options=Object.assign({},di,e);var r=new C;if(this._options.connectionParams)try{this._socketHelper=new dr(this,"HLSSubscriptionSocket");var o=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=e.socketParams,r=e.connectionParams,o=n.protocol,i=Jr(n.port||("wss"===o?443:5080)),a="".concat(o,"://").concat(n.host,":").concat(i,"/").concat(n.app,"/");if(r){var s=qr(e.connectionParams);t=Object.assign(t,s)}if(t){var c=[];Object.keys(t).forEach((function(e,n){c.push([e,t[e]].join("="))})),c.length>0&&(a+="?"+c.join("&"))}return a}(this._options,{id:this._options.subscriptionId});this._socketHelper.setUp(o,r)}catch(e){y("HLSSubscriber",e.message),n.reject("HLSSubscriber","Could not set up WebSocket for authentication with connectionParams: ".concat(e.message))}else r.resolve();r.promise.then((function(){t._socketHelper&&(t._socketHelper.tearDown(),t._socketHelper=void 0),t._setViewIfNotExist(t._view,t._options.mediaElementId),t._getViewResolverPromise().then((function(e){t._sourceHandler=new ri(e.view,t.getType()),t._glomSourceHandlerAPI(t._sourceHandler),t._options&&t._initHandler(t._options)})),n.resolve(t)})).catch((function(e){n.reject(e),t.trigger(new Xt(jt.CONNECT_FAILURE,t,e))}))}else m("HLSSubscriber","Could not resolve HLSSubscriber instance."),n.reject("Could not resolve HLSSubscriber instance.");return n.promise}},{key:"setView",value:function(e){return this._view=e,this._viewResolver.resolve(e),this}},{key:"subscribe",value:function(){return this._getSubscriptionResolverPromise()}},{key:"unsubscribe",value:function(){v("HLSSubscriber","[unscubscribe]");var e=new C;this._socketHelper&&this._socketHelper.tearDown();try{this._sourceHandler.stop(),this._sourceHandler.disconnect(),e.resolve()}catch(t){e.reject(t.message)}return e.promise}},{key:"getConnection",value:function(){return this._sourceHandler}},{key:"getControls",value:function(){return this._sourceHandler?this._sourceHandler.getControls():void 0}},{key:"getOptions",value:function(){return this._options}},{key:"getPlayer",value:function(){return this._view.view}},{key:"getType",value:function(){return eo.HLS.toUpperCase()}}])&&ii(n.prototype,r),o&&ii(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,o}(Nn);function pi(e){return(pi="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function vi(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */vi=function(){return t};var e,t={},n=Object.prototype,r=n.hasOwnProperty,o=Object.defineProperty||function(e,t,n){e[t]=n.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",s=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function u(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,n){return e[t]=n}}function l(e,t,n,r){var i=t&&t.prototype instanceof m?t:m,a=Object.create(i.prototype),s=new R(r||[]);return o(a,"_invoke",{value:k(e,n,s)}),a}function d(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}t.wrap=l;var h="suspendedStart",f="executing",p="completed",v={};function m(){}function y(){}function b(){}var g={};u(g,a,(function(){return this}));var _=Object.getPrototypeOf,w=_&&_(_(L([])));w&&w!==n&&r.call(w,a)&&(g=w);var S=b.prototype=m.prototype=Object.create(g);function E(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function C(e,t){function n(o,i,a,s){var c=d(e[o],e,i);if("throw"!==c.type){var u=c.arg,l=u.value;return l&&"object"==pi(l)&&r.call(l,"__await")?t.resolve(l.__await).then((function(e){n("next",e,a,s)}),(function(e){n("throw",e,a,s)})):t.resolve(l).then((function(e){u.value=e,a(u)}),(function(e){return n("throw",e,a,s)}))}s(c.arg)}var i;o(this,"_invoke",{value:function(e,r){function o(){return new t((function(t,o){n(e,r,t,o)}))}return i=i?i.then(o,o):o()}})}function k(t,n,r){var o=h;return function(i,a){if(o===f)throw Error("Generator is already running");if(o===p){if("throw"===i)throw a;return{value:e,done:!0}}for(r.method=i,r.arg=a;;){var s=r.delegate;if(s){var c=P(s,r);if(c){if(c===v)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(o===h)throw o=p,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=f;var u=d(t,n,r);if("normal"===u.type){if(o=r.done?p:"suspendedYield",u.arg===v)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(o=p,r.method="throw",r.arg=u.arg)}}}function P(t,n){var r=n.method,o=t.iterator[r];if(o===e)return n.delegate=null,"throw"===r&&t.iterator.return&&(n.method="return",n.arg=e,P(t,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),v;var i=d(o,t.iterator,n.arg);if("throw"===i.type)return n.method="throw",n.arg=i.arg,n.delegate=null,v;var a=i.arg;return a?a.done?(n[t.resultName]=a.value,n.next=t.nextLoc,"return"!==n.method&&(n.method="next",n.arg=e),n.delegate=null,v):a:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,v)}function O(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 T(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function R(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(O,this),this.reset(!0)}function L(t){if(t||""===t){var n=t[a];if(n)return n.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function n(){for(;++o=0;--i){var a=this.tryEntries[i],s=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),u=r.call(a,"finallyLoc");if(c&&u){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),T(n),v}},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 o=r.arg;T(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:L(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),v}},t}function mi(e,t,n,r,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function yi(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);function a(e){mi(i,r,o,a,s,"next",e)}function s(e){mi(i,r,o,a,s,"throw",e)}a(void 0)}))}}function bi(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function gi(e,t){for(var n=0;n0}(e)?"&":"?"},ki=function(e){return e.split(";").map((function(e){return e.trim()})).map((function(e){return"<"===e.charAt(0)?["url",e.substring(1,e.length-1)]:e.split("=")})).reduce((function(e,t){return e.set(t[0].replaceAll('"',""),t[1].replaceAll('"',""))}),new Map)},Pi=function(e){var t=e.split(":");return t.length>1?{protocol:t[0],host:t[1]}:{protocol:void 0,host:e}},Oi=function(){return e=function e(t){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];bi(this,e),v("WhipWhepSignalingHelper","[whipwhep] ".concat(t)),this._url=t,this._origin=void 0,this._forceHost=r,this._resource=void 0,this._enableSignalingChannel=n},(t=[{key:"getOptions",value:(c=yi((function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return vi().mark((function n(){var r,o,i,a,s,c,u;return vi().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return r="".concat(e._url).concat(Ci(e._url),"signal=").concat(e._enableSignalingChannel),t&&Object.keys(t).forEach((function(e){r+="&".concat(e,"=").concat(t[e])})),v("WhipWhepSignalingHelper","[whipwhep-options] ".concat(r)),n.prev=3,n.next=6,fetch(r,{method:"OPTIONS",mode:"cors"});case 6:if(o=n.sent,i=o.status,a=o.headers,200!==i&&204!==i){n.next=16;break}return s=/^(L|l)ink/,c=/^(S|s)ession-(H|h)ost/,u=[],a.forEach((function(t,n){if(c.exec(n)&&(e._origin=t),s.exec(n)&&t.indexOf('rel="ice-server"')>-1){var r=ki(t),o=r.get("url"),i=Pi(o),a=i.protocol,l=i.host,d=r.get("username"),h=r.get("credential");a&&l&&d&&h?u.push({username:d,credential:h,urls:o}):o&&u.push({urls:o})}})),v("WhipWhepSignalingHelper","[whipwhep-links]: ".concat(JSON.stringify(u))),v("WhipWhepSignalingHelper","[whipwhep-origin]: ".concat(e._origin)),n.abrupt("return",{links:u.length>0?u:void 0,origin:e._origin});case 16:n.next=22;break;case 18:throw n.prev=18,n.t0=n.catch(3),y("WhipWhepSignalingHelper",n.t0.message),n.t0;case 22:case"end":return n.stop()}}),n,null,[[3,18]])}))()})),function(){return c.apply(this,arguments)})},{key:"postSDPOffer",value:(s=yi((function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return vi().mark((function o(){var i,a,s,c,u,l,d,h,f;return vi().wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return i="".concat(t._url).concat(Ci(t._url),"signal=").concat(t._enableSignalingChannel),n&&Object.keys(n).forEach((function(e){-1===Ei.indexOf(e)&&(i+="&".concat(e,"=").concat(n[e]))})),t._forceHost&&t._origin&&!n.host&&(i+="&host=".concat(t._origin)),v("WhipWhepSignalingHelper","[whipwhep:post-offer] ".concat(i,": ")+JSON.stringify(e,null,2)),o.prev=4,a={method:"POST",mode:"cors",headers:{"Content-Type":"application/sdp"}},e&&e.length>0&&(a.body=e),o.next=9,fetch(i,a);case 9:if(s=o.sent,c=s.status,(u=s.headers)&&u.forEach((function(e,t){v("WhipWhepSignalingHelper","[header] ".concat(t,": ").concat(e))})),!(c>=200&&c<300)){o.next=28;break}return o.next=15,s.text();case 15:if(l=o.sent,!(d=u.get("Location")||u.get("location"))){o.next=23;break}return d.match(/^(http|https)/)?t._resource=d:(v("WhipWhepSignalingHelper","[whipwhep-response] Location provided as relative path: ".concat(d)),(h=new URL(t._url)).pathname=d.split("?")[0],t._resource=h.toString().replace(/\/endpoint\//,"/resource/")),v("WhipWhepSignalingHelper","[whipwhep-response] ".concat(t._resource,": ").concat(l)),o.abrupt("return",{sdp:l,location:t._resource});case 23:return m("WhipWhepSignalingHelper","Location not provided in header response to Offer."),t._resource=new URL(t._url).toString().replace(/\/endpoint\//,"/resource/"),o.abrupt("return",{sdp:l,location:t._resource});case 26:o.next=46;break;case 28:if(!r||!wi.get(c)){o.next=35;break}if(v("WhipWhepSignalingHelper",wi.get(c)),404!==c&&409!==c){o.next=32;break}throw new Y(wi.get(c));case 32:throw new Error(wi.get(c));case 35:if(r||!Si.get(c)){o.next=42;break}if(v("WhipWhepSignalingHelper",Si.get(c)),404!==c&&409!==c){o.next=39;break}throw new Y(Si.get(c));case 39:throw new Error(Si.get(c));case 42:return o.next=44,s.text();case 44:throw f=o.sent,Error(f);case 46:o.next=52;break;case 48:throw o.prev=48,o.t0=o.catch(4),y("WhipWhepSignalingHelper",o.t0.message),o.t0;case 52:case"end":return o.stop()}}),o,null,[[4,48]])}))()})),function(e){return s.apply(this,arguments)})},{key:"postSDPAnswer",value:(a=yi((function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return vi().mark((function r(){var o,i,a,s,c;return vi().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return v("WhipWhepSignalingHelper","[whipwhep:post-answer] ".concat(t._resource,": ")+JSON.stringify(e,null,2)),o=t._resource,i=Ci(o),n&&Object.keys(n).forEach((function(e){-1===Ei.indexOf(e)&&(i=Ci(o),o+="".concat(i).concat(e,"=").concat(n[e]))})),t._forceHost&&t._origin&&!n.host&&(i=o.indexOf("?")>-1?"&":"?",o+="".concat(i,"host=").concat(t._origin)),r.prev=5,r.next=8,fetch(o,{method:"PATCH",mode:"cors",headers:{"Content-Type":"application/sdp"},body:e});case 8:if(a=r.sent,!((s=a.status)>=200&&s<300)){r.next=14;break}return r.abrupt("return",{success:!0,code:s});case 14:if(!Si.get(s)){r.next=19;break}throw v("WhipWhepSignalingHelper",Si.get(s)),new Error(Si.get(s));case 19:return r.next=21,a.text();case 21:throw c=r.sent,Error(c);case 23:r.next=29;break;case 25:throw r.prev=25,r.t0=r.catch(5),y("WhipWhepSignalingHelper",r.t0.message),r.t0;case 29:case"end":return r.stop()}}),r,null,[[5,25]])}))()})),function(e){return a.apply(this,arguments)})},{key:"trickle",value:(i=yi((function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return vi().mark((function r(){var o,i,a,s,c,u;return vi().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return v("WhipWhepSignalingHelper","[whipwhep-trickle] ".concat(t._resource,": ")+JSON.stringify(e,null,2)),o=t._resource,i=Ci(o),n&&Object.keys(n).forEach((function(e){-1===Ei.indexOf(e)&&(i=Ci(o),o+="".concat(i).concat(e,"=").concat(n[e]))})),t._forceHost&&t._origin&&!n.host&&(i=Ci(o),o+="".concat(i,"host=").concat(t._origin)),r.prev=5,r.next=8,fetch(o,{method:"PATCH",mode:"cors",headers:{"Content-Type":"application/trickle-ice-sdpfrag"},body:e});case 8:if(a=r.sent,s=a.status,a.headers,!(s>=200&&s<300)){r.next=18;break}return r.next=13,a.text();case 13:return c=r.sent,v("WhipWhepSignalingHelper","[whipwhep-response] ".concat(t._resource,": ").concat(c)),r.abrupt("return",{candidate:c});case 18:if(405!==s){r.next=23;break}throw console.log("Remember to update the URL passed into the WHIP or WHEP client"),new Error("Remember to update the URL passed into the WHIP or WHEP client");case 23:return r.next=25,a.text();case 25:throw u=r.sent,Error(u);case 27:r.next=33;break;case 29:throw r.prev=29,r.t0=r.catch(5),console.error(r.t0),r.t0;case 33:case"end":return r.stop()}}),r,null,[[5,29]])}))()})),function(e){return i.apply(this,arguments)})},{key:"tearDown",value:(o=yi((function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return vi().mark((function n(){var r,o;return vi().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(e._resource){n.next=2;break}return n.abrupt("return");case 2:return r=e._resource,o=Ci(r),t&&Object.keys(t).forEach((function(e){-1===Ei.indexOf(e)&&(o=Ci(r),r+="".concat(o).concat(e,"=").concat(t[e]))})),e._forceHost&&e._origin&&!t.host&&(o=Ci(r),r+="".concat(o,"host=").concat(e._origin)),v("WhipWhepSignalingHelper","[whipwhep-teardown]"),n.next=9,fetch(r,{method:"DELETE",mode:"cors"});case 9:e._url=void 0,e._origin=void 0,e._resource=void 0,e._forceHost=!1,e._enableSignalingChannel=!1;case 14:case"end":return n.stop()}}),n)}))()})),function(){return o.apply(this,arguments)})},{key:"post",value:(r=yi(vi().mark((function e(){return vi().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return v("WhipWhepSignalingHelper","[whipwhep] transport called."),e.abrupt("return",!0);case 2:case"end":return e.stop()}}),e)}))),function(){return r.apply(this,arguments)})}])&&gi(e.prototype,t),n&&gi(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n,r,o,i,a,s,c}(),Ti=Object.freeze({EMPTY:"Empty",VIDEO:"Video",AUDIO:"Audio",FULL:"Video/Audio"});function Ri(e){return(Ri="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Li(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function Ai(e){for(var t=1;t=0;--i){var a=this.tryEntries[i],s=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),u=r.call(a,"finallyLoc");if(c&&u){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),T(n),v}},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 o=r.arg;T(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:L(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),v}},t}function Hi(e,t,n,r,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function Ii(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);function a(e){Hi(i,r,o,a,s,"next",e)}function s(e){Hi(i,r,o,a,s,"throw",e)}a(void 0)}))}}function xi(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Di(e,t){for(var n=0;n2&&void 0!==arguments[2])||arguments[2];xi(this,t),r=Fi(this,t);var i=e?Qr(e):zi;return i.mediaElementId=n?n.id:zi.mediaElementId,i.trickleIce=o,r._whipHelper=void 0,r._videoMuted=!0,r._audioMuted=!0,r._videoUnmuteHandler=r._onVideoUnmute.bind(r),r._audioUnmuteHandler=r._onAudioUnmute.bind(r),e&&r._internalConnect(i),r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Wi(e,t)}(t,e),function(e,t,n){return t&&Di(e.prototype,t),n&&Di(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}(t,[{key:"_runMuteCheck",value:(h=Ii(ji().mark((function e(){var t,n=this;return ji().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.getPeerConnection()){e.next=2;break}return e.abrupt("return");case 2:return e.prev=2,e.next=5,this.getPeerConnection().getStats();case 5:e.sent.forEach((function(e){var t=e.type,r=e.kind,o=e.bytesReceived;"inbound-rtp"!==t&&"inboundrtp"!==t||("video"===r?n._videoMuted=o<=0:"audio"===r&&(n._audioMuted=o<=0))})),t={data:{streamingMode:(r=!this._videoMuted,o=!this._audioMuted,r&&o?Ti.FULL:r?Ti.VIDEO:o?Ti.AUDIO:Ti.EMPTY),method:"onMetaData"},type:"metadata",method:"onMetaData",eventTimestamp:(new Date).getTime()},this.onMetaData(t),v("WHEPClient","[metadata]:: ".concat(JSON.stringify(t,null,2))),e.next=16;break;case 12:e.prev=12,e.t0=e.catch(2),console.warn(e.t0),m("WHEPClient",e.t0.message||e.t0);case 16:case"end":return e.stop()}var r,o}),e,this,[[2,12]])}))),function(){return h.apply(this,arguments)})},{key:"_onVideoUnmute",value:function(e){var t=this;e.target.removeEventListener("unmute",this._videoUnmuteHandler);var n=setTimeout(Ii(ji().mark((function e(){return ji().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:clearTimeout(n),t._runMuteCheck();case 2:case"end":return e.stop()}}),e)}))),1e3)}},{key:"_onAudioUnmute",value:function(e){var t=this;e.target.removeEventListener("unmute",this._audioUnmuteHandler);var n=setTimeout(Ii(ji().mark((function e(){return ji().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:clearTimeout(n),t._runMuteCheck();case 2:case"end":return e.stop()}}),e)}))),1e3)}},{key:"_switchWhipWhepHandler",value:function(e){this._options.host=e,this._options.protocol="ws",this._options.port=5080;var t=this._options,n=t.protocol,r=t.host,o=t.port,i=t.app,a=t.streamName,s=t.subscriptionId,c=t.enableChannelSignaling,u=t.disableProxy,l=n.match(/^http/)?n:"ws"===n?"http":"https",d="".concat(l,"://").concat(r,":").concat(o,"/").concat(i);this._whipUrl="".concat(d,"/whep/endpoint/").concat(a,"?requestId=").concat(s),this._whipHelper=new Oi(this._whipUrl,c,u)}},{key:"_glomSourceHandlerAPI",value:function(e){var n=this;Ui(t,"_glomSourceHandlerAPI",this,3)([e]),e.on("loadedmetadata",(function(){n._runMuteCheck()})),e.on(jt.PLAYBACK_STATE_CHANGE,(function(){n._runMuteCheck()}))}},{key:"_internalConnect",value:(d=Ii(ji().mark((function e(t){return ji().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.init(t);case 2:return e.next=4,this.subscribe();case 4:case"end":return e.stop()}}),e,this)}))),function(e){return d.apply(this,arguments)})},{key:"waitToGatherIce",value:(l=Ii(ji().mark((function e(t){return ji().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){if("complete"===t.iceGatheringState)t.addIceCandidate({candidate:""}).then((function(){e({local:t.localDescription})})).catch((function(n){y("WHEPClient",n.message||n),e({local:t.localDescription})}));else{var n=setTimeout((function(){clearTimeout(n),t.addIceCandidate({candidate:""}).then((function(){e({local:t.localDescription})})).catch((function(n){y("WHEPClient",n.message||n),e({local:t.localDescription})}))}),5e3);t.addEventListener("icegatheringstatechange",(function(){"complete"===t.iceGatheringState&&(clearTimeout(n),t.addIceCandidate({candidate:""}).then((function(){e({local:t.localDescription})})).catch((function(n){y("WHEPClient",n.message||n),e({local:t.localDescription})})))}))}})));case 1:case"end":return e.stop()}}),e)}))),function(e){return l.apply(this,arguments)})},{key:"_sendCandidate",value:function(e){v("WHEPClient","[sendcandidate]"),this.trigger(new Xt(It.CANDIDATE_START,this,e))}},{key:"_postOffer",value:(u=Ii((function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return ji().mark((function r(){var o,i,a,s,c,u,l,d,h;return ji().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.prev=0,o=t._options,i=o.maintainStreamVariant,a=o.videoEncoding,s=o.audioEncoding,c=o.connectionParams,u=o.postEmptyOffer,l=o.mungeOffer,d=Ai(Ai({},c),{},{doNotSwitch:i}),void 0!==a&&a!==no.NONE&&(d.videoEncoding=a),void 0!==s&&s!==to.NONE&&(d.audioEncoding=s),h="",u||(h=e.sdp,l&&(h=l(h)),n||(h=Ze(h),h=tt(h)),h=vt(h)),r.next=9,t._whipHelper.postSDPOffer(h,d,!1);case 9:return r.abrupt("return",r.sent);case 12:r.prev=12,r.t0=r.catch(0),y("WHEPClient",r.t0.message||r.t0),r.t0 instanceof Y?t.onStreamUnavailable(r.t0):(t.trigger(new Xt(jt.CONNECT_FAILURE,t)),t.unsubscribe(),t._subscriptionResolver.reject("Stream failure."));case 16:case"end":return r.stop()}}),r,null,[[0,12]])}))()})),function(e){return u.apply(this,arguments)})},{key:"_postEmptyOffer",value:(c=Ii(ji().mark((function e(){var t,n,r,o,i,a;return ji().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,t=this._options,n=t.maintainStreamVariant,r=t.videoEncoding,o=t.audioEncoding,i=t.connectionParams,a=Ai(Ai({},i),{},{doNotSwitch:n}),void 0!==r&&r!==no.NONE&&(a.videoEncoding=r),void 0!==o&&o!==to.NONE&&(a.audioEncoding=o),e.next=7,this._whipHelper.postSDPOffer("",a,!1);case 7:return e.abrupt("return",e.sent);case 10:throw e.prev=10,e.t0=e.catch(0),y("WHEPClient",e.t0.message||e.t0),this.onStreamUnavailable(e.t0),e.t0;case 15:case"end":return e.stop()}}),e,this,[[0,10]])}))),function(){return c.apply(this,arguments)})},{key:"_postAnswer",value:(s=Ii(ji().mark((function e(t,n,r){var o,i,a,s,c;return ji().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=this._options,i=o.mungeAnswer,a=o.connectionParams,v("WHEPClient","[sendanswer]: streamname(".concat(t,"), subscriptionid(").concat(n,")")),s=r.sdp,c=s,i&&(c=i(c)),e.next=7,this._whipHelper.postSDPAnswer(c,a);case 7:return e.abrupt("return",e.sent);case 8:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return s.apply(this,arguments)})},{key:"_postCandidateFragments",value:(a=Ii(ji().mark((function e(t){var n,r;return ji().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this._options.connectionParams,r=yt(t,void 0,!0),e.next=4,this._whipHelper.trickle(r,n);case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"_requestOffer",value:(i=Ii(ji().mark((function e(){var t,n,r,o,i,a,s,c,u,l,d,h,f,p,m,b,g,_,w,S,E,C,k;return ji().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(v("WHEPClient","[requestoffer]"),t=this._options,n=t.trickleIce,r=t.postEmptyOffer,o=t.streamName,i=t.subscriptionId,a=t.mungeOffer,s=t.mungeAnswer,c=this.getPeerConnection(),u=void 0,e.prev=4,!r){e.next=18;break}return this.trigger(new Xt(It.OFFER_START,this)),e.next=9,this._postEmptyOffer();case 9:return l=e.sent,d=l.sdp,this.trigger(new Xt(It.OFFER_END,this)),h=new Ot({type:"offer",sdp:d}),v("WHEPClient","[requestoffer:empty:remote] ".concat(JSON.stringify(h,null,2))),e.next=16,c.setRemoteDescription(h);case 16:e.next=36;break;case 18:return c.addTransceiver("video",{direction:"recvonly"}),c.addTransceiver("audio",{direction:"recvonly"}),this.trigger(new Xt(It.OFFER_START,this)),e.next=23,c.createOffer();case 23:return f=e.sent,this.trigger(new Xt(It.OFFER_END,this)),e.next=27,this._postOffer(f,n);case 27:return p=e.sent,m=p.sdp,b=vt(m),a&&(b=a(b)),u=ht(b),g=new Ot({type:"offer",sdp:b}),v("WHEPClient","[requestoffer:remote] ".concat(JSON.stringify(g,null,2))),e.next=36,c.setRemoteDescription(g);case 36:return e.next=38,c.createAnswer();case 38:if((_=e.sent).sdp=s?s(_.sdp):_.sdp,_.sdp=ft(_.sdp,u),!n||!c.canTrickleIceCandidates){e.next=60;break}return v("WHEPClient","[trickle:ice] enabled"),_.sdp=et(_.sdp),_.sdp=mt(_.sdp),e.next=47,c.setLocalDescription(_);case 47:return v("WHEPClient","[create:answer:local] ".concat(JSON.stringify({type:"answer",sdp:_.sdp},null,2))),this.trigger(new Xt(It.ANSWER_START,this,_)),e.next=51,this._postAnswer(o,i,_);case 51:return this.trigger(new Xt(It.ANSWER_END,this)),e.next=54,this.waitToGatherIce(c);case 54:return w=e.sent,S=w.local,e.next=58,this._postCandidateFragments(S.sdp);case 58:e.next=76;break;case 60:return v("WHEPClient","[trickle:ice] disabled"),_.sdp=Ze(_.sdp),_.sdp=mt(_.sdp),e.next=65,c.setLocalDescription(_);case 65:return e.next=67,this.waitToGatherIce(c);case 67:return E=e.sent,C=E.local,k=Ze(C.sdp),k=tt(k),v("WHEPClient","[create:answer:local] ".concat(JSON.stringify({type:"answer",sdp:k},null,2))),this.trigger(new Xt(It.ANSWER_START,this,{type:"answer",sdp:k})),e.next=75,this._postAnswer(o,i,{type:"answer",sdp:k});case 75:this.trigger(new Xt(It.ANSWER_END,this));case 76:e.next=82;break;case 78:throw e.prev=78,e.t0=e.catch(4),y("WHEPClient",e.t0),e.t0;case 82:case"end":return e.stop()}}),e,this,[[4,78]])}))),function(){return i.apply(this,arguments)})},{key:"_disconnect",value:function(){this._whipHelper&&this._whipHelper.tearDown(),this._whipHelper=void 0,Ui(t,"_disconnect",this,3)([])}},{key:"init",value:(o=Ii((function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;return ji().mark((function r(){var o,i,a,s,c,u,l,d,h,f,p,v;return ji().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(Be()){r.next=4;break}throw new Error("Cannot create WebRTC playback instance. Your environment does not support WebRTC and/or WebSockets.");case 4:return t._disconnect(),t._options=Ai(Ai({},zi),e),t._options.subscriptionId=t._options.subscriptionId||Yi(),o=t._options,i=o.endpoint,a=o.protocol,s=o.host,c=o.port,u=o.app,l=o.streamName,d=o.subscriptionId,h=o.enableChannelSignaling,f=o.disableProxy,p=a.match(/^http/)?a:"ws"===a?"http":"https",v="".concat(p,"://").concat(s,":").concat(c,"/").concat(u),t._whipUrl=i?"".concat(i,"?requestId=").concat(d):"".concat(v,"/whep/endpoint/").concat(l,"?requestId=").concat(d),t._whipHelper=new Oi(t._whipUrl,h,f),t._peerHelper=new Vr(t),t._messageTransport=t._whipHelper,t._mediaTransform=n,t._mediaTransform&&!We()&&(t.trigger(new Xt(It.UNSUPPORTED_FEATURE,t,{feature:"Insertable Streams",message:"You provided Media Transforms for track processing, but your current browser does not support the Insertable Streams API."})),t._mediaTransform=void 0),r.abrupt("return",t);case 17:case"end":return r.stop()}}),r)}))()})),function(e){return o.apply(this,arguments)})},{key:"subscribe",value:(r=Ii(ji().mark((function e(){var t,n,r,o,i,a,s,c,u,l,d,h,f,p,v,m,b;return ji().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return(t=this._options).streamName,n=t.mediaElementId,r=t.rtcConfiguration,o=t.liveSeek,i=t.connectionParams,a=this._options,s=a.enableChannelSignaling,c=a.dataChannelConfiguration,(u=s&&Ve())&&!c&&(c={name:"red5pro"},this._options.dataChannelConfiguration=c),this._options.enableChannelSignaling=u,this._options.signalingSocketOnly=this._options.enableChannelSignaling,e.prev=6,this._setViewIfNotExist(this._view,n),e.next=10,this._getViewResolverPromise();case 10:return l=e.sent,o&&o.enabled?(d=o.hlsjsRef,h=o.usePlaybackControlsUI,f=o.options,ve.supportsNonNativeHLS(d)?this._sourceHandler=new $n(l.view,this.getType(),f,h):(y("WHEPClient","Could not utilize the 'LiveSeek' request. This feature requires either native HLS playback or hls.js as a depenency."),this.trigger(new Xt(It.LIVE_SEEK_UNSUPPORTED,this,{feature:"Live Seek",message:"Live Seek requires integration with the HLS.JS plugin in order work properly. Most likely you are viewing this on a browser that does not support the use of HLS.JS."})),this._sourceHandler=new Bn(l.view,this.getType()))):this._sourceHandler=new Bn(l.view,this.getType()),this._glomSourceHandlerAPI(this._sourceHandler),this._initHandler(this._options,this._sourceHandler),this._getAvailabilityResolverPromise().catch((function(){})),p=i||{},e.next=18,this._whipHelper.getOptions(p);case 18:return(v=e.sent)&&v.links&&(this._options.rtcConfiguration=Ai(Ai({},r),{},{iceServers:v.links})),v&&v.origin&&this.trigger(new Xt(It.HOST_ENDPOINT_CHANGED,this,{endpoint:v.origin})),m=this._options.enableChannelSignaling?c:void 0,b=r,void 0===r.encodedInsertableStreams&&(b=Object.assign(r,{encodedInsertableStreams:!!this._mediaTransform})),this._connect(b,m,this._options.iceServers),this._connectionClosed=!1,e.abrupt("return",this._getSubscriptionResolverPromise());case 29:throw e.prev=29,e.t0=e.catch(6),this.trigger(new Xt(jt.CONNECT_FAILURE),this,e.t0),e.t0;case 33:case"end":return e.stop()}}),e,this,[[6,29]])}))),function(){return r.apply(this,arguments)})},{key:"onAnswerMediaStream",value:(n=Ii((function(){var e=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;return ji().mark((function r(){return ji().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:Ui(t,"onAnswerMediaStream",e,3)([n]),n.getTracks().forEach((function(t){"video"===t.kind?(e._videoMuted=t.muted,t.muted&&t.addEventListener("unmute",e._videoUnmuteHandler)):"audio"===t.kind&&(e._audioMuted=t.muted,t.muted&&t.addEventListener("unmute",e._audioUnmuteHandler))})),e._runMuteCheck();case 4:case"end":return r.stop()}}),r)}))()})),function(){return n.apply(this,arguments)})},{key:"onPeerConnectionOpen",value:function(){var e=this._options.enableChannelSignaling;Ui(t,"onPeerConnectionOpen",this,3)([]),this._subscriptionResolver.resolve(this),e||this.trigger(new Xt(jt.SUBSCRIBE_START,this)),this._playIfAutoplaySet(this._options,this._view),this._startSeekable(this._options,this._view)}},{key:"onDataChannelOpen",value:function(e){var n=this._options.dataChannelConfiguration;if(Ui(t,"onDataChannelOpen",this,3)([e]),n){var r=n.name;Ui(t,"onDataChannelAvailable",this,3)([r])}else Ui(t,"onDataChannelAvailable",this,3)([]);this.trigger(new Xt(jt.SUBSCRIBE_START,this))}},{key:"getConnection",value:function(){}}]);var n,r,o,i,a,s,c,u,l,d,h}(Ao);function Ji(e){return(Ji="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function qi(e){return function(e){if(Array.isArray(e))return Xi(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return Xi(e,t);var n={}.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)?Xi(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Xi(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;v("R5ProPublisherSourceHandler","[addsource]");var o=this;this._swfId=e,this._embedFuture=k.createIfNotExist(this._embedFuture);var i=this._embedFuture;return t.swf=n||t.swf,t.minFlashVersion=r||t.minFlashVersion,No(this.video,this.holder).then((function(n){v("R5ProPublisherSourceHandler","[element:complete]");var r={buffer:null!=t.buffer?t.buffer:1,streamMode:t.streamMode,streamName:t.streamName,appName:t.app,host:t.host};return t.backgroundColor&&(r.backgroundColor=t.backgroundColor),t.context&&(r.roomName=t.context),"100%"!==t.embedWidth&&"100%"!==t.embedHeight||(r.autosize=!0),void 0!==t.connectionParams&&(r.connectionParams=encodeURIComponent(JSON.stringify(t.connectionParams))),r=ua(t.mediaConstraints,r),jo(e,t,r,ve.getSwfObject(),n)})).then((function(){v("R5ProPublisherSourceHandler","[embed:complete]"),i.resolve(o)})).catch((function(e){return i.reject(e)})),i.promise}},{key:"connect",value:function(e){v("R5ProPublisherSourceHandler","[connect]");var t=ve.getEmbedObject(this._swfId);t?t.connect(e):m("R5ProPublisherSourceHandler","Could not determine embedded element with swf id: "+this._swfId+".")}},{key:"disconnect",value:function(){v("R5ProPublisherSourceHandler","[disconnect]");try{var e=ve.getEmbedObject(this._swfId);e&&e.disconnect()}catch(e){}this.cleanUp()}},{key:"send",value:function(e,t){var n=ve.getEmbedObject(this._swfId);n&&n.send(e,t)}},{key:"setMediaQuality",value:function(e){var t=ve.getEmbedObject(this._swfId);if(t&&e.video&&"boolean"!=typeof e.video){var n=isNaN(e.video.width)?Number.isNaN:ke(e.video.width),r=isNaN(e.video.height)?Number.isNaN:ke(e.video.height);t.updateResolution(n,r)}}},{key:"getType",value:function(){return this._publisherType}}])&&sa(e.prototype,t),n&&sa(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}();function da(e){return(da="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function ha(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function fa(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:"red5pro-publisher";ha(this,e);try{this._targetElement=ve.resolveElement(t)}catch(e){throw y("R5ProPublishView","Could not instantiate a new instance of Red5ProPublisher. Reason: ".concat(e.message)),e}},(t=[{key:"attachPublisher",value:function(e){v("R5ProPublishView","[attachpublisher]"),e.setView(this,ve.getElementId(this._targetElement))}},{key:"preview",value:function(e){var t=this.isAutoplay;v("R5ProPublishView","[preview]: autoplay(".concat(t,")")),ve.setVideoSource(this._targetElement,e,t)}},{key:"unpreview",value:function(){ve.setVideoSource(this._targetElement,null,this.isAutoplay)}},{key:"isAutoplay",get:function(){return ve.hasAttributeDefined(this._targetElement,"autoplay")}},{key:"view",get:function(){return this._targetElement}}])&&fa(e.prototype,t),n&&fa(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}(),ma=Object.freeze({RTMP:"rtmp",RTC:"rtc"}),ya=Object.freeze({LIVE:"live",RECORD:"record",APPEND:"append"}),ba=(Object.freeze({OPUS:"Opus",PCMU:"PCMU",PCMA:"PCMA"}),Object.freeze({VP8:"VP8",VP9:"VP9",H264:"H264"}));function ga(e){return(ga="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _a(e,t){for(var n=0;n0&&void 0!==arguments[0])||arguments[0],n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;Ea(this,e),Ca(this,"audio",t),Ca(this,"video",n||new ka)}));function Ta(e){return(Ta="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Ra(e,t){for(var n=0;n0&&void 0!==arguments[0])||arguments[0],n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;Ea(this,e),Ca(this,"audio",t),Ca(this,"video",n||new Pa)})))},Ia=function(e){function t(){var e;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(e=Aa(this,t))._options=void 0,e._view=void 0,e._sourceHandler=void 0,e._elementId=void 0,e._connectFuture=void 0,e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&ja(e,t)}(t,e),n=t,(r=[{key:"_setViewIfNotExist",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;if(void 0===e&&void 0!==t){var n=new va(t);n.attachPublisher(this)}}},{key:"setView",value:function(e,t){var n=this;return this._view=e,this._elementId=t,void 0!==this._sourceHandler&&(this._sourceHandler.disconnect(),this._sourceHandler=void 0),this._view&&(this._sourceHandler=new la(this._view.view,this.getType())),this._options&&this._sourceHandler&&this._sourceHandler.addSource(this._elementId,this._options).catch((function(e){y("RTMPPublisher","Could not establish proper RTMP publisher: ".concat(e)),n.trigger(new qt(Nt.EMBED_FAILURE,n))})),this}},{key:"_setUpConnectCallback",value:function(e){var t=this;window.setActiveId=function(n){v("RTMPPublisher","Embed and connect() complete for publisher swf. successId(".concat(n,").")),e.resolve(t),t.trigger(new qt(Nt.EMBED_SUCCESS,t)),t._tearDownConnectCallback()}}},{key:"_tearDownConnectCallback",value:function(){window.setActiveId=void 0}},{key:"_establishExtIntHandlers",value:function(){var e=this,t=this._options.streamName,n=function(e){return["publisher",e,t.split("-").join("_")].join("_")};window[n("r5proConnectClosed")]=function(){e.trigger(new qt(Rt.CONNECTION_CLOSED,e))},window[n("r5proConnectSuccess")]=function(){return e.trigger(new qt(Rt.CONNECT_SUCCESS,e))},window[n("r5proUnpublishSuccess")]=function(){return e.trigger(new qt(Rt.UNPUBLISH_SUCCESS,e))},window[n("r5proPublishStart")]=function(){e._connectFuture.resolve(e),e.trigger(new qt(Rt.PUBLISH_START,e))},window[n("r5proPublishMetadata")]=function(t){return e.trigger(new qt(Rt.PUBLISH_METADATA,e,t))},window[n("r5proPublishInsufficientBW")]=function(t){return e.trigger(new qt(Rt.PUBLISH_INSUFFICIENT_BANDWIDTH,e,t))},window[n("r5proPublishSufficientBW")]=function(t){return e.trigger(new qt(Rt.PUBLISH_SUFFICIENT_BANDWIDTH,e,t))},window[n("r5proPublishRecoveringBW")]=function(t){return e.trigger(new qt(Rt.PUBLISH_RECOVERING_BANDWIDTH,e,t))},window[n("r5proConnectFailure")]=function(){e._connectFuture.reject(Rt.CONNECT_FAILURE),e.trigger(new qt(Rt.CONNECT_FAILURE,e))},window[n("r5proPublishFail")]=function(){e._connectFuture.reject(Rt.PUBLISH_FAIL),e.trigger(new qt(Rt.PUBLISH_FAIL,e))},window[n("r5proPublishInvalidName")]=function(){e._connectFuture.reject(Rt.PUBLISH_INVALID_NAME),e.trigger(new qt(Rt.PUBLISH_INVALID_NAME,e))}}},{key:"init",value:function(e){var t=this,n=new C,r=e.minFlashVersion||Ha.minFlashVersion;if(ve.supportsFlashVersion(r)){this._options=Object.assign({},Ha,e);try{ve.injectScript(this._options.swfobjectURL).then((function(){return v("RTMPPublisher","SWFObject embedded."),t._sourceHandler?(v("RTMPPublisher","Publish handler established."),t._sourceHandler.addSource(t._elementId,t._options)):(v("RTMPPublisher","Publish handler not established."),!0)})).then((function(){t._setViewIfNotExist(t._view,t._options.mediaElementId),n.resolve(t)})).catch((function(e){y("RTMPPublisher","Could not embed Flash-based RTMP Publisher. Reason: ".concat(e)),t._sourceHandler&&t._sourceHandler.disconnect(),n.reject(e),t.trigger(new qt(Nt.EMBED_FAILURE,t))}))}catch(e){n.reject("Could not inject Flash-based Publisher into the page. Reason: ".concat(e.message)),t.trigger(new qt(Nt.EMBED_FAILURE,t))}}else n.reject("Could not resolve RTMPPublisher instance. Requires minimum Flash Player install of ".concat(r));return n.promise}},{key:"publish",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=n||new C;this._setUpConnectCallback(r),this._options.streamName=t||this._options.streamName;var o=this._options;try{var i=this._sourceHandler;this._sourceHandler.getEmbedOperation().then((function(){v("RTMPPublisher","[handler:embed:complete]"),ve.getEmbedObject(e._elementId)&&e._establishExtIntHandlers();var t=0,n=function(){var e;e=setTimeout((function(){try{clearTimeout(e),i.connect(JSON.stringify(o))}catch(e){if(t++>100)throw e;n()}}),300)};n()})).catch((function(t){r.reject(t),e.trigger(new qt(Rt.CONNECT_FAILURE,e))}))}catch(e){y("RTMPPublisher","[handler:embed:error]"),r.reject("Could not initiate connection sequence. Reason: ".concat(e.message)),this.trigger(new qt(Rt.CONNECT_FAILURE,this)),this._tearDownConnectCallback()}return this._connectFuture=r,r.promise}},{key:"unpublish",value:function(){var e=new C;try{ve.getEmbedObject(this._elementId).unpublish(),e.resolve()}catch(t){y("RTMPPublisher","Could not initiate publish sequence. Reason: ".concat(t.message)),e.reject(t.message)}return this._connectFuture=void 0,e.promise}},{key:"send",value:function(e,t){this._sourceHandler.send(e,"string"==typeof t?t:JSON.stringify(t))}},{key:"setMediaQuality",value:function(e){this._sourceHandler&&this._sourceHandler.setMediaQuality(e)}},{key:"overlayOptions",value:function(e){this._options=Object.assign(this._options,e)}},{key:"getConnection",value:function(){return this._sourceHandler}},{key:"getOptions",value:function(){return this._options}},{key:"getType",value:function(){return ma.RTMP.toUpperCase()}}])&&Ra(n.prototype,r),o&&Ra(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,o}(M);function xa(e){return(xa="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Da(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function Ma(e){for(var t=1;t=0;--i){var a=this.tryEntries[i],s=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),u=r.call(a,"finallyLoc");if(c&&u){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),T(n),v}},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 o=r.arg;T(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:L(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),v}},t}function Xa(e,t,n,r,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function $a(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:null,n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;v("R5ProPublishPeer","[createoffer]");var o=r||new C;return this._peerConnection.createOffer().then((function(r){e.setLocalDescription(r,t).then((function(){var i=r.sdp;t&&(i=lt(t,i)),n&&(i=ot(i),i=it(i),i=ct(i),i=ut(i)),r.sdp=i,e._responder.onSDPSuccess(),o.resolve(r)})).catch((function(t){e._responder.onSDPError(t),o.reject(t)}))})).catch((function(e){v("R5ProPublishPeer","[createoffer:error]"),o.reject(e)})),o.hasOwnProperty("promise")?o.promise:o}},{key:"createOfferWithoutSetLocal",value:(n=function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return qa().mark((function r(){var o,i;return qa().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return v("R5ProPublishPeer","[createoffer:withoutlocal]"),r.prev=1,r.next=4,e._peerConnection.createOffer();case 4:return o=r.sent,i=o.sdp,t&&(i=lt(t,i)),n&&(i=ot(i),i=it(i),i=ct(i),i=ut(i)),o.sdp=i,e._responder.onSDPSuccess(),r.abrupt("return",o);case 13:throw r.prev=13,r.t0=r.catch(1),v("R5ProPublishPeer","[createoffer:error]"),e._responder.onSDPError(r.t0),r.t0;case 18:case"end":return r.stop()}}),r,null,[[1,13]])}))()},r=function(){var e=this,t=arguments;return new Promise((function(r,o){var i=n.apply(e,t);function a(e){Xa(i,r,o,a,s,"next",e)}function s(e){Xa(i,r,o,a,s,"throw",e)}a(void 0)}))},function(){return r.apply(this,arguments)})},{key:"postUnpublish",value:function(e){var t=this.post({unpublish:e});return v("R5ProPublishPeer","[peerconnection:unpublish] complete: ".concat(t)),t}},{key:"postUnjoin",value:function(e,t){return v("R5ProPublishPeer","[peerconnection:leavegroup]"),this.post({leaveGroup:e,streamName:t})}}]);var n,r}(jr);function is(e){return(is="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function as(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function ss(e){for(var t=1;t=0;--i){var a=this.tryEntries[i],s=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),u=r.call(a,"finallyLoc");if(c&&u){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),T(n),v}},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 o=r.arg;T(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:L(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),v}},t}function ls(e,t,n,r,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function ds(e,t){for(var n=0;n1)&&"video"===t[0].kind};void 0!==e.onGetUserMedia?(bs("Requesting gUM from user-defined configuration:onGetUserMedia."),e.onGetUserMedia().then((function(r){if(n(r))return bs("We received a MediaStream with mismatching track listing. Trying again..."),void t._gum(e);t.trigger(new qt(At.CONSTRAINTS_ACCEPTED,t,Ss(r))),t._streamFuture.resolve(r)})).catch((function(n){_s("Could not resolve MediaStream from provided gUM. Error - ".concat(n)),t.trigger(new qt(At.CONSTRAINTS_REJECTED,t,{constraints:e.mediaConstraints})),t._streamFuture.reject(n)}))):(bs("Requesting gUM using mediaConstraints: ".concat(JSON.stringify(e.mediaConstraints,null,2))),this._peerHelper.getUserMedia(e.mediaConstraints,this._gUMRejectionHandler).then((function(r){if(n(r.media))return bs("We received a MediaStream with mismatching track listing. Trying again..."),void t._gum(e);bs("Found valid constraints: ".concat(JSON.stringify(r.constraints,null,2))),t.trigger(new qt(At.CONSTRAINTS_ACCEPTED,t,Ss(r.media))),t.trigger(new qt(Rt.DIMENSION_CHANGE,t,r.constraints)),t._streamFuture.resolve(r.media)})).catch((function(n){bs("Could not find valid constraint resolutions from: ".concat(JSON.stringify(n.constraints,null,2))),_s("Could not resolve MediaStream from provided mediaConstraints. Error - ".concat(n.error)),bs("Attempting to find resolutions from original provided constraints: ".concat(JSON.stringify(n.constraints,null,2))),t.trigger(new qt(At.CONSTRAINTS_REJECTED,t,{constraints:n.constraints})),e.onGetUserMedia=function(){return t._peerHelper.forceUserMedia(n.constraints)},t._gum(e)})))}},{key:"_onGUMRejection",value:function(e){this.trigger(new qt(At.CONSTRAINTS_REJECTED,this,{constraints:e}))}},{key:"_onOrientationChange",value:function(e){this.getMessageTransport()&&this.getMessageTransport().post({send:{method:"onMetaData",data:{deviceOrientation:e}}})}},{key:"_onMediaStreamReceived",value:function(e){this._mediaStream=e,this.trigger(new qt(At.MEDIA_STREAM_AVAILABLE,this,e)),this._view&&this._view.preview(this._mediaStream)}},{key:"_setViewIfNotExist",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;if(void 0===e&&void 0!==t){var n=new va(t);n.attachPublisher(this)}}},{key:"_requestAvailability",value:function(e){return bs("[requestavailability]"),this._availableFuture=k.createIfNotExist(this._availableFuture),this._options.bypassAvailable?this._availableFuture.resolve(!0):this._socketHelper.post({isAvailable:e,bundle:!0}),this._availableFuture.promise}},{key:"_createPeerConnection",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;return bs("[createpeeer]"),this._peerFuture=void 0,this._peerFuture=k.createIfNotExist(this._peerFuture),n&&e&&(gs("The iceServers configuration property is considered deprecated. Please use the rtcConfiguration configuration property upon which you can assign iceServers. Reference: https://www.red5pro.com/docs/streaming/migrationguide.html"),e.iceServers=n),void 0!==e?this._peerHelper.setUpWithPeerConfiguration(e,t,this._peerFuture):this._peerHelper.setUp(n,this._peerFuture,this._options.rtcpMuxPolicy)}},{key:"_createOffer",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return bs("[createoffer]"),this._offerFuture=void 0,this._offerFuture=k.createIfNotExist(this._offerFuture),this._peerHelper.createOffer(e,t,!1,this._offerFuture),this._offerFuture.promise}},{key:"_setRemoteDescription",value:function(e){return bs("[setremotedescription]"),this._peerHelper.setRemoteDescription(e)}},{key:"_sendOffer",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];bs("[sendoffer]");var o={handleOffer:t,transport:n,data:{sdp:e}};return r&&(o.videoEncoding=ba.VP8),this._sendOfferFuture=void 0,this._sendOfferFuture=k.createIfNotExist(this._sendOffFuture),this._socketHelper.post(o),this._sendOfferFuture.promise}},{key:"_sendCandidate",value:function(e,t){bs("[sendcandidate]"),this._socketHelper.post({handleCandidate:t,data:{candidate:e}})}},{key:"_requestPublish",value:function(e,t,n){return bs("[requestpublish]"),this._publishFuture=void 0,this._publishFuture=k.createIfNotExist(this._publishFuture),this._socketHelper.post({publish:e,mode:t,keyFramerate:n}),this._publishFuture.promise}},{key:"_requestUnpublish",value:function(e){return this._unpublishFuture=void 0,this._unpublishFuture=k.createIfNotExist(this._unpublishFuture),this.getMessageTransport().postUnpublish(e)||this._unpublishFuture.resolve(),this._unpublishFuture.promise}},{key:"_setUpMediaTransform",value:(n=us().mark((function e(t,n,r){var o,i,a,s,c,u,l,d;return us().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t){e.next=16;break}if(o=this._mediaTransform,i=o.audio,a=o.video,s=o.worker,c=n.getSenders().find((function(e){return e.track&&"video"===e.track.kind})),u=n.getSenders().find((function(e){return e.track&&"audio"===e.track.kind})),!c||!a&&!s){e.next=15;break}return e.prev=5,e.next=8,fo(t,c,r);case 8:(l=e.sent).generator&&(this._mediaStream.addTrack(l.generator),this._mediaStream.removeTrack(this._mediaStream.getVideoTracks()[0])),e.next=15;break;case 12:e.prev=12,e.t0=e.catch(5),this.trigger(new qt(At.TRANSFORM_ERROR,this,{type:"video",error:e.t0}));case 15:if(u&&(i||s))try{(d=vo(t,u,r)).generator&&(this._mediaStream.addTrack(d.generator),this._mediaStream.removeTrack(this._mediaStream.getAudioTracks()[0]))}catch(e){this.trigger(new qt(At.TRANSFORM_ERROR,this,{type:"audio",error:e}))}case 16:case"end":return e.stop()}}),e,this,[[5,12]])})),r=function(){var e=this,t=arguments;return new Promise((function(r,o){var i=n.apply(e,t);function a(e){ls(i,r,o,a,s,"next",e)}function s(e){ls(i,r,o,a,s,"throw",e)}a(void 0)}))},function(e,t,n){return r.apply(this,arguments)})},{key:"init",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;this._streamFuture=void 0;var n=new C;return Be()&&Tt()?(this._options=ss(ss({},ws),e),this._peerHelper=new os(this),this._socketHelper=new Ka(this),this._messageTransport=this._messageTransport||this._socketHelper,this._mediaTransform=t,this._mediaTransform&&!We()&&(this.trigger(new qt(At.UNSUPPORTED_FEATURE,this,{feature:"Insertable Streams",message:"You provided Media Transforms for track processing, but your current browser does not support the Insertable Streams API."})),this._mediaTransform=void 0),this._getMediaStream().then(this._onMediaStreamReceived.bind(this)).catch((function(e){gs("[gum]: ".concat(e))})),this._gum(this._options),this._setViewIfNotExist(this._view,this._options.mediaElementId),n.resolve(this)):n.reject("Cannot create WebRTC playback instance. Your environment does not support WebRTC and/or WebSockets."),n.promise}},{key:"initWithStream",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;bs("[initWithStream]"),this._streamFuture=void 0;var r=new C;if(Be()&&Tt()){this._mediaTransform=n,this._mediaTransform&&!We()&&(this.trigger(new qt(At.UNSUPPORTED_FEATURE,this,{feature:"Insertable Streams",message:"You provided Media Transforms for track processing, but your current browser does not support the Insertable Streams API."})),this._mediaTransform=void 0),this._options=ss(ss({},ws),e),this._peerHelper=new os(this),this._socketHelper=new Ka(this),this._messageTransport=this._messageTransport||this._socketHelper,this._setViewIfNotExist(this._view,this._options.mediaElementId);var o=this._getMediaStream();o.then(this._onMediaStreamReceived.bind(this)).catch((function(e){gs("[gum]: ".concat(e))})),this._streamFuture.resolve(t),r.resolve(this)}else r.reject("Cannot create WebRTC playback instance. Your environment does not support WebRTC and/or WebSockets.");return r.promise}},{key:"setView",value:function(e){return this._view=e,this._mediaStream&&this._view&&this._view.preview(this._mediaStream),this}},{key:"preview",value:function(){var e=this;bs("[preview]");var t=new Promise((function(t){t(e)}));return this._setViewIfNotExist(this._view,this._options.mediaElementId),t}},{key:"unpreview",value:function(){bs("[unpreview]"),this._mediaStream&&this._mediaStream.getTracks().forEach((function(e){e.stop()})),this._view&&this._view.unpreview(),this._view=void 0}},{key:"publish",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;bs("[publish]"),this._options.streamName=t||this._options.streamName;var r=n||new C,o=new C,i=Xr(this._options,{id:this._options.streamName});this._trickleEndFuture=this._getTrickleEnd(),this._peerHelper||(this._peerHelper=new os(this)),this._socketHelper?this._socketHelper.clearRetry():(this._socketHelper=new Ka(this),this._messageTransport=this._socketHelper),this._socketHelper.setUp(i,o);var a=this._options,s=a.rtcConfiguration,c=a.signalingSocketOnly,u=a.dataChannelConfiguration,l=c&&Ve();return l&&!u&&(u={name:"red5pro"}),this._options.signalingSocketOnly=l,this._publishFuture=k.createIfNotExist(this._publishFuture),this._publishFuture.promise.catch((function(t){ve.removeOrientationChangeHandler(e._onOrientationChange),r.reject(t),e.trigger(new qt(Rt.CONNECT_FAILURE,e,t))})),o.promise.then((function(){return e.trigger(new qt(Rt.CONNECT_SUCCESS,e)),e._getMediaStream()})).then((function(){return e._requestAvailability(e._options.streamName,e._options.streamType)})).then((function(){var t=s;return void 0===s.encodedInsertableStreams&&(t=Object.assign(s,{encodedInsertableStreams:!!e._mediaTransform})),e._createPeerConnection(t,u,e._options.iceServers)})).then((function(t){if(e.trigger(new qt(At.PEER_CONNECTION_AVAILABLE,e,t)),e._mediaStream.getTracks().forEach((function(n){t.addTrack(n,e._mediaStream)})),e._options.forceVP8){var n=e._mediaStream,r=RTCRtpSender.getCapabilities("video").codecs,o=r.findIndex((function(e){return"video/VP8"===e.mimeType}));if(o>-1){var i=r[o];r.splice(o,1),r.unshift(i),t.getTransceivers().find((function(e){return e.sender&&e.sender.track===n.getVideoTracks()[0]})).setCodecPreferences(r)}}return e._createOffer(e._options.bandwidth,e._options.forceVP8)})).then((function(t){var n=e._options,r=n.streamName,o=n.iceTransport,i=n.forceVP8;return e.trigger(new qt(At.OFFER_START,e,t)),e._sendOffer(t,r,o,i)})).then((function(t){return e._setRemoteDescription(t.sdp)})).then((function(t){return e.trigger(new qt(At.OFFER_END,e,t)),e._getTrickleEnd().promise})).then((function(){return e.trigger(new qt(At.ICE_TRICKLE_COMPLETE,e)),e._requestPublish(e._options.streamName,e._options.streamMode,e._options.keyFramerate)})).then((function(){e._setUpMediaTransform(e._mediaTransform,e.getPeerConnection(),e.getMediaStream()),ve.addOrientationChangeHandler(e._onOrientationChange),r.resolve(e),e.trigger(new qt(Rt.PUBLISH_START,e))})).catch((function(t){ve.removeOrientationChangeHandler(e._onOrientationChange),r.reject(t),e.trigger(new qt(Rt.CONNECT_FAILURE,e,t))})),r.hasOwnProperty("promise")?r.promise:r}},{key:"publishWithSocket",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;bs("[publishWithSocket]"),this._options.streamName=n||this._options.streamName;var o=r||new C,i=new C;return this._socketHelper=new Ka(this),this._socketHelper.setUpWithSocket(e,i),i.promise.then((function(){return t._requestPublish(t._options.streamName,t._options.streamMode,t._options.keyFramerate)})).then((function(){ve.addOrientationChangeHandler(t._onOrientationChange),o.resolve(t),t.trigger(new qt(Rt.PUBLISH_START,t))})).catch((function(e){ve.removeOrientationChangeHandler(t._onOrientationChange),o.reject(e),t.trigger(new qt(Rt.CONNECT_FAILURE,t,e))})),o.hasOwnProperty("promise")?o.promise:o}},{key:"unpublish",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];bs("[unpublish]");var n=function(){e._socketHelper&&(bs("[unpublish:teardown]"),e._socketHelper.tearDown()),e._peerHelper&&e._peerHelper.tearDown(),e._socketHelper=void 0,e._peerHelper=void 0,e._messageTransport=void 0};(this._options.clearMediaOnUnpublish||t)&&this.unpreview(),this._availableFuture=void 0,this._peerFuture=void 0,this._offerFuture=void 0,this._sendOfferFuture=void 0,this._trickleEndFuture=void 0,this._publishFuture=void 0;var r=this._requestUnpublish(this._options.streamName,this._options.groupName);return r.then((function(){e._unpublishFuture=void 0,n(),e.trigger(new qt(Rt.UNPUBLISH_SUCCESS,e))})),ve.removeOrientationChangeHandler(this._onOrientationChange),r}},{key:"mute",value:function(){this.muteAudio()}},{key:"unmute",value:function(){this.unmuteAudio()}},{key:"muteAudio",value:function(){this.getMessageTransport().post({mute:{muteAudio:!0}})}},{key:"unmuteAudio",value:function(){this.getMessageTransport().post({mute:{muteAudio:!1}})}},{key:"muteVideo",value:function(){this.getMessageTransport().post({mute:{muteVideo:!0}})}},{key:"unmuteVideo",value:function(){this.getMessageTransport().post({mute:{muteVideo:!1}})}},{key:"send",value:function(e,t){this.getMessageTransport().post({send:{method:e,data:"string"==typeof t?JSON.parse(t):t}})}},{key:"callServer",value:function(e,t){return this.getMessageTransport().postAsync({callAdapter:{method:e,arguments:t}})}},{key:"sendLog",value:function(e,t){try{var n=Object.keys(d).find((function(t){return t.toLowerCase()===e.toLowerCase()}))?e:d.DEBUG,r="string"==typeof t?t:JSON.stringify(t);this.getMessageTransport().post({log:n.toUpperCase(),message:r})}catch(e){e.message;_s("RTCPublisher"),_s("RTCPublisher")}}},{key:"onStreamAvailable",value:function(e){bs("[onstreamavailable]: "+JSON.stringify(e,null,2)),this._availableFuture=k.createIfNotExist(this._availableFuture),this._availableFuture.reject("Stream with name ".concat(this._options.streamName," already has a broadcast session.")),this.trigger(new qt(Rt.PUBLISH_INVALID_NAME,this))}},{key:"onStreamUnavailable",value:function(e){bs("Stream ".concat(this._options.streamName," does not exist.")),bs("[onstreamunavailable]: "+JSON.stringify(e,null,2)),this._availableFuture=k.createIfNotExist(this._availableFuture),this._availableFuture.resolve(!0)}},{key:"onSocketMessage",value:function(e,t){this.trigger(new qt(At.SOCKET_MESSAGE,this,{socket:e,message:t}))}},{key:"onSocketMessageError",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;_s("Error in stream publish: ".concat(e,".\n[Optional detail]: ").concat(t)),this._publishFuture&&(this.trigger(new qt(Rt.PUBLISH_FAIL,this)),this._publishFuture.reject(e),this.unpublish())}},{key:"onSocketClose",value:function(e){bs("[onsocketclose]"),this._peerHelper&&this._peerHelper.tearDown(),this.trigger(new qt(Rt.CONNECTION_CLOSED,this,e))}},{key:"onConnectionClosed",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;this._connectionClosed||(bs("RTCPublisher"),this.unpublish(),this.trigger(new qt(Rt.CONNECTION_CLOSED,this,e)))}},{key:"onPeerConnectionFail",value:function(){bs("[onpeerconnectionfail]"),this.trigger(new qt(Rt.PUBLISH_FAIL,this)),this._publishFuture&&this._publishFuture.reject("Peer Connection Failed.")}},{key:"onPeerConnectionClose",value:function(e){bs("[onpeerconnectionclose]"),this._socketHelper&&(bs("[onpeerconnectionclose:teardown]"),this._socketHelper.tearDown()),this.onSocketClose(e)}},{key:"onPeerConnectionOpen",value:function(){bs("[onpeerconnection::open]"),this.trigger(new qt(At.PEER_CONNECTION_OPEN),this,this.getPeerConnection())}},{key:"onPeerConnectionTrackAdd",value:function(e){bs("[onpeerconnection::track]"),this.trigger(new qt(At.TRACK_ADDED,this,{track:e}))}},{key:"onSDPSuccess",value:function(e){var t=e?": "+JSON.stringify(e,null,2):"";bs("[onsdpsuccess]".concat(t))}},{key:"onSDPError",value:function(e){this.trigger(new qt(Rt.PUBLISH_FAIL,this));var t=e?": "+JSON.stringify(e,null,2):"";_s("[onsdperror]".concat(t))}},{key:"onSDPAnswer",value:function(e){bs("[sdpanswer]:: "+JSON.stringify(e,null,2)),this._sendOfferFuture=k.createIfNotExist(this._sendOfferFuture),this._sendOfferFuture.resolve(e)}},{key:"onAddIceCandidate",value:function(e){bs("[addicecandidate]"),this._peerHelper.addIceCandidate(e).then((function(){bs("[addicecandidate:success]")})).catch((function(e){gs("[addicecandidate:error] - ".concat(e))}))}},{key:"onIceCandidate",value:function(e){bs("[icecandidatetrickle]"),this._sendCandidate(e,this._options.streamName)}},{key:"onIceCandidateTrickleEnd",value:function(){bs("[icecandidatetrickle:end]")}},{key:"onEmptyCandidate",value:function(){bs("[icecandidatetrickle:empty]"),this.trigger(new qt(At.PEER_CANDIDATE_END))}},{key:"onPeerGatheringComplete",value:function(){bs("[icecandidategathering:end]"),this._socketHelper&&this._socketHelper.postEndOfCandidates(this._options.streamName)}},{key:"onSocketIceCandidateEnd",value:function(){bs("[socketicecandidate:end]"),this._getTrickleEnd().resolve()}},{key:"onPublisherStatus",value:function(e){bs("[publisherstatus] - "+JSON.stringify(e,null,2));var t=ys.exec(e.message),n=ms.exec(e.message);t&&t[1]===this._options.streamName?this._unpublishFuture.resolve():n&&n[1]===this._options.streamName?this._publishFuture.resolve():e.code&&"NetStream.Publish.IsAvailable"===e.code?this.trigger(new qt(Rt.PUBLISH_AVAILABLE,this.status)):this.trigger(new qt(Rt.PUBLISH_STATUS,this,e))}},{key:"onInsufficientBandwidth",value:function(e){this.trigger(new qt(Rt.PUBLISH_INSUFFICIENT_BANDWIDTH,this,e))}},{key:"onSufficientBandwidth",value:function(e){this.trigger(new qt(Rt.PUBLISH_SUFFICIENT_BANDWIDTH,this,e))}},{key:"onRecoveringBandwidth",value:function(e){this.trigger(new qt(Rt.PUBLISH_RECOVERING_BANDWIDTH,this,e))}},{key:"onSendReceived",value:function(e,t){"onMetaData"===e?this.onMetaData(t):this.trigger(new qt(Rt.PUBLISH_SEND_INVOKE,this,{methodName:e,data:t}))}},{key:"onDataChannelAvailable",value:function(e){var t=this;if(bs("[ondatachannel::available]"),this._switchChannelRequest={switchChannel:e||"red5pro"},this._options.signalingSocketOnly)var n=setTimeout((function(){clearTimeout(n),t._socketHelper&&t._socketHelper.sever(t._switchChannelRequest),t._messageTransport=t._peerHelper,t.trigger(new $t(Dt.CHANGE,t,{controller:t,transport:t._messageTransport}))}),this._socketHelper?this._options.socketSwitchDelay:100);this.trigger(new qt(At.DATA_CHANNEL_AVAILABLE,this,{name:e,dataChannel:this.getDataChannel()}))}},{key:"onDataChannelError",value:function(e,t){this.trigger(new qt(At.DATA_CHANNEL_ERROR,this,{dataChannel:e,error:t}))}},{key:"onDataChannelMessage",value:function(e,t){this.trigger(new qt(At.DATA_CHANNEL_MESSAGE,this,{dataChannel:e,message:t}))}},{key:"onDataChannelOpen",value:function(e){this.trigger(new qt(At.DATA_CHANNEL_OPEN,this,{dataChannel:e}))}},{key:"onDataChannelClose",value:function(e){this.trigger(new qt(At.DATA_CHANNEL_CLOSE,this,{dataChannel:e}))}},{key:"onMetaData",value:function(e){this.trigger(new qt(Rt.PUBLISH_METADATA,this,e))}},{key:"overlayOptions",value:function(e){this._options=Object.assign(this._options,e)}},{key:"getMessageTransport",value:function(){return this._messageTransport}},{key:"getConnection",value:function(){return this._socketHelper}},{key:"getPeerConnection",value:function(){return this._peerHelper?this._peerHelper.connection:void 0}},{key:"getDataChannel",value:function(){return this._peerHelper?this._peerHelper.dataChannel:void 0}},{key:"getMediaStream",value:function(){return this._mediaStream}},{key:"getOptions",value:function(){return this._options}},{key:"getType",value:function(){return ma.RTC.toUpperCase()}}]);var n,r}(M);function Cs(e){return(Cs="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function ks(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function Ps(e){for(var t=1;t=0;--i){var a=this.tryEntries[i],s=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),u=r.call(a,"finallyLoc");if(c&&u){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),T(n),v}},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 o=r.arg;T(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:L(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),v}},t}function Rs(e,t,n,r,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function Ls(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);function a(e){Rs(i,r,o,a,s,"next",e)}function s(e){Rs(i,r,o,a,s,"throw",e)}a(void 0)}))}}function As(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Ns(e,t){for(var n=0;n2&&void 0!==arguments[2])||arguments[2];As(this,t),r=Hs(this,t);var i=e?Qr(e):Gs;return i.mediaElementId=n?n.id:Gs.mediaElementId,i.trickleIce=o,r._whipHelper=void 0,e&&r._internalConnect(i),r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Fs(e,t)}(t,e),n=t,(r=[{key:"_internalConnect",value:(h=Ls(Ts().mark((function e(t){return Ts().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.init(t);case 2:return e.next=4,this.publish();case 4:case"end":return e.stop()}}),e,this)}))),function(e){return h.apply(this,arguments)})},{key:"waitToGatherIce",value:(d=Ls(Ts().mark((function e(t){return Ts().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Us("[waittogatherice]"),e.abrupt("return",new Promise((function(e,n){if("complete"===t.iceGatheringState)Us("[waittogatherice] ice gathering state complete."),t.addIceCandidate(null).then((function(){e(t.localDescription)})).catch((function(n){Bs("Error adding null candidate: "+n.message||!1),e(t.localDescription)}));else{Us("[waittogatherice] waiting...");var r=setTimeout((function(){clearTimeout(r),t.addIceCandidate(null).then((function(){e(t.localDescription)})).catch((function(n){Bs("Error adding null candidate: "+n.message||!1),e(t.localDescription)}))}),1e3);t.onicegatheringstatechange=function(){clearTimeout(r),Us("[waittogatherice] ice gathering state complete."),"complete"===t.iceGatheringState&&t.addIceCandidate(null).then((function(){e(t.localDescription)})).catch((function(n){Bs("Error adding null candidate: "+n.message||!1),e(t.localDescription)}))}}})));case 2:case"end":return e.stop()}}),e)}))),function(e){return d.apply(this,arguments)})},{key:"_postOffer",value:(l=Ls((function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return Ts().mark((function r(){var o,i,a,s,c,u,l,d,h;return Ts().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.prev=0,o=e.sdp,i=t._options,a=i.mungeOffer,s=i.streamMode,c=i.keyFramerate,u=i.connectionParams,l=i.forceVP8,d=o,a&&(d=a(d)),n||(d=Ze(d),d=tt(d)),h=Ps(Ps({},u),{},{mode:s,keyFramerate:c}),l&&(h.videoEncoding=ba.VP8),r.next=10,t._whipHelper.postSDPOffer(d,h);case 10:return r.abrupt("return",r.sent);case 13:throw r.prev=13,r.t0=r.catch(0),Vs(r.t0.message||r.t0),r.t0 instanceof Y?t.onStreamAvailable(r.t0):t._publishFuture?t._publishFuture.reject(r.t0.message||r.t0):(t.trigger(new qt(Rt.CONNECT_FAILURE,t,Vs)),t.unpublish()),r.t0;case 18:case"end":return r.stop()}}),r,null,[[0,13]])}))()})),function(e){return l.apply(this,arguments)})},{key:"_postCandidateFragments",value:(u=Ls(Ts().mark((function e(t){var n,r;return Ts().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this._options.connectionParams,r=yt(t,void 0,!0),e.next=4,this._whipHelper.trickle(r,n);case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})},{key:"_sendCandidate",value:function(e,t){Us(JSON.stringify(e,null,2))}},{key:"_switchWhipWhepHandler",value:function(e){this._options.host=e,this._options.protocol="ws",this._options.port=5080;var t=this._options,n=t.protocol,r=t.host,o=t.port,i=t.app,a=t.streamName,s=t.enableChannelSignaling,c=t.disableProxy,u=n.match(/^http/)?n:"ws"===n?"http":"https";this._whipUrl="".concat(u,"://").concat(r,":").concat(o,"/").concat(i,"/whip/endpoint/").concat(a),this._whipHelper=new Oi(this._whipUrl,s,c)}},{key:"init",value:(c=Ls(Ts().mark((function e(n){var r,o,i,a,s,c,u,l,d;return Ts().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this._options=Ps(Ps({},Gs),n),r=this._options,o=r.protocol,i=r.host,a=r.port,s=r.app,c=r.streamName,u=r.enableChannelSignaling,l=r.disableProxy,d=o.match(/^http/)?o:"ws"===o?"http":"https",this._whipUrl=n.endpoint?n.endpoint:"".concat(d,"://").concat(i,":").concat(a,"/").concat(s,"/whip/endpoint/").concat(c),this._whipHelper=new Oi(this._whipUrl,u,l),this._messageTransport=this._whipHelper,e.abrupt("return",Is(t,"init",this,3)([this._options]));case 7:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"initWithStream",value:(s=Ls(Ts().mark((function e(n,r){var o,i,a,s,c,u,l,d,h;return Ts().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this._options=Ps(Ps({},Gs),n),o=this._options,i=o.protocol,a=o.host,s=o.port,c=o.app,u=o.streamName,l=o.enableChannelSignaling,d=o.disableProxy,h="ws"===i?"http":"https",this._whipUrl=n.endpoint?n.endpoint:"".concat(h,"://").concat(a,":").concat(s,"/").concat(c,"/whip/endpoint/").concat(u),this._whipHelper=new Oi(this._whipUrl,l,d),this._messageTransport=this._whipHelper,e.abrupt("return",Is(t,"initWithStream",this,3)([this._options,r]));case 7:case"end":return e.stop()}}),e,this)}))),function(e,t){return s.apply(this,arguments)})},{key:"publish",value:(a=Ls((function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return Ts().mark((function r(){var o,i,a,s,c,u,l,d,h,f,p,v,m,y,b,g,_,w,S,E,C;return Ts().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return o=e._options,i=o.bandwidth,a=o.forceVP8,s=o.rtcConfiguration,c=o.enableChannelSignaling,u=o.dataChannelConfiguration,l=o.trickleIce,d=o.mungeAnswer,h=o.connectionParams,(f=c&&Ve())&&!u&&(u={name:"red5pro"},e._options.dataChannelConfiguration=u),e._options.enableChannelSignaling=f,e._options.signalingSocketOnly=e._options.enableChannelSignaling,r.prev=5,p=h||{},t&&(e._options.streamName=t),h&&(v=h.transcode)&&(p.transcode=v),r.next=11,e._whipHelper.getOptions(p);case 11:return(m=r.sent)&&m.links&&(e._options.rtcConfiguration=Ps(Ps({},s),{},{iceServers:m.links})),m&&m.origin&&e.trigger(new qt(At.HOST_ENDPOINT_CHANGED,e,{endpoint:m.origin})),y=e._options.enableChannelSignaling?u:void 0,r.next=17,e._createPeerConnection(s,y,e._options.iceServers);case 17:return b=r.sent,e.trigger(new qt(At.PEER_CONNECTION_AVAILABLE,e,b)),r.next=21,e._getMediaStream();case 21:return r.sent.getTracks().forEach((function(e){var t=b.addTransceiver(e,{direction:"sendonly"});if(t&&"video"===e.kind&&a)try{var n=RTCRtpSender.getCapabilities("video").codecs,r=n.findIndex((function(e){return"video/VP8"===e.mimeType}));if(r>-1){var o=n[r];n.splice(r,1),n.unshift(o),t.setCodecPreferences(n)}}catch(e){Us("[forceVP8] Could not set codec preferences. ".concat(e.message||e))}})),r.next=25,e._peerHelper.createOfferWithoutSetLocal(i,a);case 25:return g=r.sent,r.next=28,e._peerHelper.setLocalDescription(g);case 28:if(l){r.next=32;break}return r.next=31,e.waitToGatherIce(b);case 31:g=r.sent;case 32:return e.trigger(new qt(At.OFFER_START,e,g)),r.next=35,e._postOffer(g,l);case 35:return _=r.sent,w=_.sdp,S=d?d(w):w,r.next=40,e._setRemoteDescription({type:"answer",sdp:nt(S)});case 40:if(e.trigger(new qt(At.OFFER_END,e,S)),!l){r.next=48;break}return r.next=44,e.waitToGatherIce(b);case 44:return E=r.sent,C=E.sdp,r.next=48,e._postCandidateFragments(C);case 48:return e.trigger(new qt(At.ICE_TRICKLE_COMPLETE,e)),ve.addOrientationChangeHandler(e._onOrientationChange),e._options.enableChannelSignaling||e.trigger(new qt(Rt.PUBLISH_START,e)),n&&n.resolve(e),r.abrupt("return",e);case 55:throw r.prev=55,r.t0=r.catch(5),Vs(r.t0),ve.removeOrientationChangeHandler(e._onOrientationChange),e.trigger(new qt(Rt.CONNECT_FAILURE,e,r.t0)),n&&n.reject(r.t0),r.t0;case 62:case"end":return r.stop()}}),r,null,[[5,55]])}))()})),function(){return a.apply(this,arguments)})},{key:"unpublish",value:(i=Ls((function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return Ts().mark((function n(){return Ts().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return Us("[unpublish:teardown]"),e._whipHelper&&e._whipHelper.tearDown(),e._peerHelper&&e._peerHelper.tearDown(),e._whipHelper=void 0,e._peerHelper=void 0,e._messageTransport=void 0,(e._options.clearMediaOnUnpublish||t)&&e.unpreview(),e.trigger(new qt(Rt.UNPUBLISH_SUCCESS,e)),ve.removeOrientationChangeHandler(e._onOrientationChange),n.abrupt("return",e);case 10:case"end":return n.stop()}}),n)}))()})),function(){return i.apply(this,arguments)})},{key:"onDataChannelOpen",value:function(e){var n=this._options.dataChannelConfiguration;if(Is(t,"onDataChannelOpen",this,3)([e]),n){var r=n.name;Is(t,"onDataChannelAvailable",this,3)([r])}else Is(t,"onDataChannelAvailable",this,3)([]);this.trigger(new qt(Rt.PUBLISH_START,this))}},{key:"getConnection",value:function(){}}])&&Ns(n.prototype,r),o&&Ns(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,o,i,a,s,c,u,l,d,h}(Es);function Ys(e){return(Ys="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function zs(e){return function(e){if(Array.isArray(e))return Ks(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return Ks(e,t);var n={}.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)?Ks(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Ks(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n-1;){var r=new AudioContext,o=r.createMediaStreamDestination();r.createMediaStreamSource(e).connect(o),e.addTrack(o.stream.getAudioTracks()[0])}}},{key:"_createOffer",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return v("[createoffer]"),this._offerFuture=void 0,this._offerFuture=k.createIfNotExist(this._offerFuture),this._peerHelper.createOffer(e,t,!0,this._offerFuture),this._offerFuture.promise}},{key:"_sendOffer",value:function(e,t,n){var r=this._options.groupName;return this._sendOfferFuture=void 0,this._sendOfferFuture=k.createIfNotExist(this._sendOffFuture),this._socketHelper.post({joinGroup:r,streamName:t,transport:n,data:{sdp:e}}),this._sendOfferFuture.promise}},{key:"_requestPublish",value:function(e,t,n){var r=this._options.autoGenerateMediaStream;return this._publishFuture=void 0,this._publishFuture=k.createIfNotExist(this._publishFuture),this._publishFuture.resolve(),r&&(this._conferenceStream=this._startReceivers(),this.trigger(new Qt(Mt.MEDIA_STREAM,this,{stream:this._conferenceStream}))),this._publishFuture.promise}},{key:"unpublish",value:function(){return this._conferenceStream&&this._conferenceStream.getTracks().forEach((function(e){return e.stop()})),ac(t,"unpublish",this,3)([])}},{key:"_requestUnpublish",value:function(e){var t=this._options.groupName;return this._unpublishFuture=void 0,this._unpublishFuture=k.createIfNotExist(this._unpublishFuture),this.getMessageTransport().postUnjoin(t,e)||this._unpublishFuture.resolve(),this._unpublishFuture.promise}},{key:"_startReceivers",value:function(){var e=this.getPeerConnection().getTransceivers().map((function(e){if("recvonly"===e.currentDirection)return e.receiver.track})).filter((function(e){return e})),t=this._options.mixAudioDown,n=this._conferenceStream||new MediaStream;if(t){var r=new AudioContext,o=e.map((function(e){if("audio"===e.kind)return r.createMediaStreamSource(new MediaStream([e]))})).filter((function(e){return e})),i=r.createMediaStreamDestination();o.forEach((function(e){return e.connect(i)})),i.stream.getTracks().forEach((function(e){return n.addTrack(e)}))}else e.forEach((function(e){return n.addTrack(e)}));return e.forEach((function(e){"video"===e.kind&&n.addTrack(e)})),n}},{key:"init",value:function(e){return ac(t,"init",this,3)([Object.assign(fc,e)])}},{key:"initWithStream",value:function(e,n){return ac(t,"initWithStream",this,3)([Object.assign(fc,e),n])}},{key:"onPeerConnectionTrackAdd",value:function(e){var n=this._options.autoGenerateMediaStream;n&&"audio"===e.kind?this._audioTracks.push(e):n&&"video"===e.kind&&this._videoTracks.push(e),ac(t,"onPeerConnectionTrackAdd",this,3)([e])}},{key:"_onMediaStreamReceived",value:function(e){this._packStreamWithAudio(e,3),ac(t,"_onMediaStreamReceived",this,3)([e])}},{key:"onSDPAnswer",value:function(e){var t=this._options.streamName;this.overlayOptions({streamName:e.participantId,participantId:e.participantId,publisherName:t}),this._sendOfferFuture=k.createIfNotExist(this._sendOfferFuture),this._sendOfferFuture.resolve(e)}},{key:"onPublisherStatus",value:function(e){v(this._name,"[publisherstatus] - "+JSON.stringify(e,null,2));var t=hc.exec(e.message),n=dc.exec(e.message);t&&t[1]===this._options.groupName?this._unpublishFuture.resolve():n&&n[1]===this._options.streamName?this._publishFuture.resolve():m(this._name,"Publisher status received, but could not handle.")}}])&&rc(n.prototype,r),o&&rc(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,o}(Es),vc=ia,mc=Ao,yc=Ki,bc=Xo,gc=fi,_c=tc,wc=Es,Sc=Ws,Ec=Ia,Cc=Rt,kc=At,Pc=Lt,Oc=jt,Tc=It,Rc=xt,Lc=Ht,Ac=Dt,Nc=Mt,jc=to,Hc=no,Ic=ro,xc=oo;h("".concat("error")||!1);var Dc=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];d.hasOwnProperty(e.toUpperCase())&&(h(e,t),console&&console.log("Red5 Pro SDK Version ".concat("13.0.0-release.b153")))},Mc=d,Fc=function(){return s}}])})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.red5prosdk=t():e.red5prosdk=t()}(window,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=1)}([function(e,t,r){"use strict";function n(e){if(null==e)return e;if(Array.isArray(e))return e.slice();if("object"==typeof e){var t={};return Object.keys(e).forEach((function(r){t[r]=e[r]})),t}return e}var o=function(e){if(null===e)return"null";if("string"!=typeof e)return e.toString();for(var t=/%[sdj%]/g,r=1,n=arguments,o=n.length,i=String(e).replace(t,(function(e){if("%%"===e)return"%";if(r>=o)return e;switch(e){case"%s":return String(n[r++]);case"%d":return Number(n[r++]);case"%j":try{return JSON.stringify(n[r++])}catch(e){return"[Circular]"}break;default:return e}})),a=n[r];re||(l=r(u),this._emit(l))}else{var f="unbound";if(!s[f]){var d=i();a(o("bunyan usage error: %s:%s: attempt to log with an unbound log method: `this` is: %s",d.file,d.line,this.toString()),f)}}}}function w(e){var t=e.stack||e.toString();if(e.cause&&"function"==typeof e.cause){var r=e.cause();r&&(t+="\nCaused by: "+w(r))}return t}function S(){var e=[];return function(t,r){return r&&"object"==typeof r?-1!==e.indexOf(r)?"[Circular]":(e.push(r),r):r}}Object.keys(y).forEach((function(e){m[y[e]]=e})),g.prototype.addStream=function(e,t){switch(null==t&&(t=d),!(e=n(e)).type&&e.stream&&(e.type="raw"),e.raw="raw"===e.type,e.level?e.level=b(e.level):e.level=b(t),e.level1&&void 0!==arguments[1]&&arguments[1],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0,o=[];if(o.push({level:e,stream:new c,type:"raw"}),r){var i=r.map((function(t){t.level=e}));o=o.concat(i)}t&&(s=[],o.push({level:e,stream:{write:function(e){var t="[".concat(e.time.toISOString(),"] ").concat(n.nameFromLevel[e.level],": ").concat(e.msg);s.push(t)}}})),a=Object(n.createLogger)({level:e,name:"red5pro-sdk",streams:o})},d=function(){return s},h=(u(l.TRACE),u(l.INFO)),p=u(l.DEBUG),v=u(l.WARN),y=u(l.ERROR);u(l.FATAL);function m(e){return(m="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function b(e,t){for(var r=0;re.length)&&(t=e.length);for(var r=0,n=new Array(t);r=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),O(r),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;O(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:T(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},e}function T(e,t){for(var r=0;r0)){e.next=5;break}return e.next=3,t.shift();case 3:e.next=0;break;case 5:case"end":return e.stop()}}),e)})),A(this).find=function(e,r,n,o){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null,s=A(t).next(e,r),c=O(s,2),u=c[0],l=c[1];if(l){var f=n[u];f=f||n,(i?(new l)[i](f):new l(f)).then((function(e){o.resolve(e)})).catch((function(s){a=s,A(t).find(e,r,n,o,i,a)}))}else o.reject(a)},A(this).next=function(e,t){var r,n,o=e.next();return o.done||(n=o.value,r=t.get(n)),[n,r]}}var t,r,n;return t=e,(r=[{key:"create",value:function(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,o=new S;return A(this).find(this.listorder(e.slice()),t,r,o,n),o.promise}}])&&T(t.prototype,r),n&&T(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function N(e){return(N="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function j(e,t){for(var r=0;r1&&(r=V.exec(e),n[1]===t&&r&&r.length>1)?r[1]:void 0}}var Y=function(e){var t="function"==typeof e.textTracks?e.textTracks():e.textTracks;t&&(e.addTextTrack("metadata"),t.addEventListener("addtrack",(function(t){var r=t.track;r.mode="hidden",r.addEventListener("cuechange",(function(t){var n,o;n=(n=t&&t.currentTarget?t.currentTarget.cues:(n=r.cues)&&n.length>0?n:r.activeCues)||[];var i=function(){var t=n[o];if(t.value){var r="string"==typeof t.value.data?t.value.data:function(e,t,r){var n="",o=t,i=t+r;do{n+=String.fromCharCode(e[o++])}while(o=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),C(r),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;C(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:k(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},e}function J(e,t,r,n,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}function q(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function X(e){for(var t=1;t0||e.canPlayType("application/x-mpegURL").length>0||e.canPlayType("audio/mpegurl").length>0||e.canPlayType("audio/x-mpegurl").length>0},ue=window.adapter,le=!!navigator.mozGetUserMedia,fe=!!document.documentMode,de=ue?"edge"===window.adapter.browserDetails.browser.toLowerCase():!fe&&!!window.StyleMedia,he=ue?"safari"===window.adapter.browserDetails.browser.toLowerCase():ce(),pe="ontouchstart"in window||window.DocumentTouch&&window.document instanceof window.DocumentTouch;ue||(navigator.getUserMedia=navigator.mediaDevices&&navigator.mediaDevices.getUserMedia||navigator.getUserMedia||navigator.mozGetUserMedia||navigator.webkitGetUserMedia||navigator.msGetUserMedia);var ve,ye,me={requestFrame:se,getBrowserDetails:function(){var e=window,t=e.navigator,r=e.adapter,n={appVersion:t.appVersion,platform:t.platform,userAgent:t.userAgent,vendor:t.vendor};return ue?X(X({},r.browserDetails),n):n},getGeoLocation:(ve=K().mark((function e(){var t,r;return K().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=window,!("geolocation"in(r=t.navigator))){e.next=3;break}return e.abrupt("return",new Promise((function(e){r.geolocation.getCurrentPosition((function(t){var r=t.coords;e(r)})).catch((function(){e(void 0)}))})));case 3:return e.abrupt("return",void 0);case 4:case"end":return e.stop()}}),e)})),ye=function(){var e=this,t=arguments;return new Promise((function(r,n){var o=ve.apply(e,t);function i(e){J(o,r,n,i,a,"next",e)}function a(e){J(o,r,n,i,a,"throw",e)}i(void 0)}))},function(){return ye.apply(this,arguments)}),getIsMoz:function(){return le},getIsEdge:function(){return de},getIsPossiblySafari:function(){return he},isTouchEnabled:function(){return pe},supportsWebSocket:function(){return!!window.WebSocket},supportsHLS:ce,supportsNonNativeHLS:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;if(e)try{return e.isSupported()}catch(e){return v("Could not access Hls.js."),!1}return!!window.Hls&&window.Hls.isSupported()},createHLSClient:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return new window.Hls(e)},getHLSClientEventEnum:function(){return window.Hls.Events},supportsFlashVersion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:".";return ae()[0]>=e.split(t)[0]},resolveElement:function(e){try{var t=document.getElementById(e);if(!t)throw new F("Element with id(".concat(e,") could not be found."));return t}catch(t){throw new F("Error in accessing element with id(".concat(e,"). ").concat(t.message))}},createWebSocket:function(e){return new WebSocket(e)},setVideoSource:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];try{e.srcObject=t}catch(r){v("[setVideoSource:obj]","Could not set srcObject: ".concat(r.message)),le?e.mozSrcObject=t:e.src=window.URL.createObjectURL(t)}if(r)try{var n=e.play();n&&n.then((function(){return p("[setVideoSource:action]","play (START)")})).catch((function(e){return v("[setVideoSource:action]","play (FAULT) "+(e.message?e.message:e))}))}catch(t){v("[setVideoSource:action]","play (CATCH::FAULT) "+t.message);try{e.setAttribute("autoplay",!1),e.pause()}catch(e){v("[setVideoSource:action]","pause (CATCH::FAULT) "+e.message)}}else try{e.setAttribute("autoplay",!1),e.pause()}catch(e){}},injectScript:function(e){var t=new S,r=document.createElement("script");return r.type="text/javascript",r.onload=function(){t.resolve()},r.onreadystatechange=function(){"loaded"!==r.readyState&&"complete"!==r.readyState||(r.onreadystatechange=null,t.resolve())},r.src=e,document.getElementsByTagName("head")[0].appendChild(r),t.promise},gUM:function(e){return(navigator.mediaDevices||navigator).getUserMedia(e)},setGlobal:function(e,t){window[e]=t},getSwfObject:function(){return window.swfobject},getEmbedObject:function(e){return document.getElementById(e)},getElementId:function(e){return e.getAttribute("id")},addOrientationChangeHandler:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r="onorientationchange"in window;r&&(p("[window:orientation]","[addOrientationChangeHandler]","adding responder."),te.push(e),t&&re()),1===te.length&&(p("[window:orientation]","[addOrientationChangeHandler]","onorientationchange added."),window.addEventListener("orientationchange",re))},removeOrientationChangeHandler:function(e){for(var t=te.length;--t>-1;)if(te[t]===e){te.slice(t,1);break}0===te.length&&(p("[window:orientation]","[removeOrientationChangeHandler]:: onorientationchange removed."),window.removeEventListener("onorientationchange",re))},addCloseHandler:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:-1;ne.splice(-1===t?ne.length:t,0,e),oe||window.addEventListener("unload",ie)},removeCloseHandler:function(e){for(var t=ne.length;--t>-1;)if(ne[t]===e){ne.slice(t,1);break}},invoke:function(e,t){window.hasOwnProperty(e)&&window[e].call(window,t)},toggleFullScreen:function(e){window.screenfull&&window.screenfull.enabled&&window.screenfull.toggle(e)},onFullScreenStateChange:function(e){Z.push(e),window.screenfull,!ee&&window.screenfull&&window.screenfull.enabled&&(ee=!0,window.screenfull.onchange((function(){var e,t=Z.length;for(e=0;e2&&void 0!==arguments[2]&&arguments[2];return function(){var o=t.parentNode;if(o){var i=o.clientWidth,a=o.clientHeight;t.style.width=n?a+"px":i+"px";var s=t.clientWidth,c=t.clientHeight,u=.5*(n?i-c:i-s);t.style.position="relative",t.style.left=u+"px"}r&&r(e(t,r,n))}},Ce=function(e,t,r){var n,o=_e.length,i=(t%=360)%180!=0,a=e.parentNode,s=e.width?e.width:a.clientWidth,c=e.height?e.height:a.clientHeight,u=Se[t.toString()];for(n=0;n=t?e.apply(null,n):function(){var e=Array.prototype.slice.call(arguments,0);return r.apply(null,n.concat(e))}}},ke=Oe((function(e,t){for(var r=0,n=t.length,o=[];r=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),C(r),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;C(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:k(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},e}function He(e,t,r,n,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}function Ie(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){He(i,n,o,a,s,"next",e)}function s(e){He(i,n,o,a,s,"throw",e)}a(void 0)}))}}var xe,De=[{label:"4K(UHD)",width:3840,height:2160},{label:"1080p(FHD)",width:1920,height:1080},{label:"UXGA",width:1600,height:1200},{label:"720p(HD)",width:1280,height:720},{label:"SVGA",width:800,height:600},{label:"VGA",width:640,height:480},{label:"360p(nHD)",width:640,height:360},{label:"CIF",width:352,height:288},{label:"QVGA",width:320,height:240},{label:"QCIF",width:176,height:144},{label:"QQVGA",width:160,height:120}],Me=function(e){return e.exact||e.ideal||e.max||e.min||e},Fe=Oe((function(e,t){if("boolean"==typeof e.video)return!0;var r=e.video.hasOwnProperty("width")?Me(e.video.width):0,n=e.video.hasOwnProperty("height")?Me(e.video.height):0,o=r===t.width&&n===t.height;return o&&p("[gum:isExact]","Found matching resolution for ".concat(t.width,", ").concat(t.height,".")),o})),Ue=Oe((function(e,t){var r=(e.video.hasOwnProperty("width")?Me(e.video.width):0)*(e.video.hasOwnProperty("height")?Me(e.video.height):0);return t.width*t.height0})),Ve=Oe((function(e,t){var r=Ue(t);return ke(r)(e)})),Ge=function e(t,r,n){if(0!=r.length){var o=r.shift();t.video.width={exact:o.width},t.video.height={exact:o.height},me.gUM(t).then((function(e){n.resolve({media:e,constraints:t})})).catch((function(o){var i="string"==typeof o?o:[o.name,o.message].join(": ");p("[gum:getUserMedia]","Failure in getUserMedia: ".concat(i,". Attempting other resolution tests...")),p("[gUM:findformat]","Constraints declined by browser: ".concat(JSON.stringify(t,null,2))),e(t,r,n)}))}else!function(e,t){e.video=!0,me.gUM(e).then((function(r){t.resolve({media:r,constraints:e})})).catch((function(r){var n="string"==typeof r?r:[r.name,r.message].join(": ");p("[gum:getUserMedia]","Failure in getUserMedia: ".concat(n,". Attempting other resolution tests...")),p("[gUM:findformat]","Constraints declined by browser: ".concat(JSON.stringify(e,null,2))),t.reject("Could not find proper camera for provided constraints.")}))}(t,n)},We=function(){return wt&&St&&Et},Ye=function(){try{var e=new wt(null);return e.createDataChannel({name:"test"}).close(),e.close(),!!We()}catch(e){return p("Could not detect RTCDataChannel support: ".concat(e.message)),!1}},ze=(window.RTCRtpScriptTransform,!!window.MediaStreamTrackGenerator),Ke=(window.MediaStreamTrackProcessor,function(){return!!Ct.prototype.createEncodedStreams}),Je=function(e,t,r,n){var o=new kt(t),i=new Pt(t.kind),a=o.readable,s=i.writable;return r.postMessage({type:e,readable:a,writable:s,options:n},[a,s]),{processor:o,generator:i}},qe=function(e,t,r,n){var o=t.createEncodedStreams(),i=o.readable,a=o.writable;return r.postMessage({type:e,readable:i,writable:a,options:n},[i,a]),{readable:i,writable:a}},Xe=function(e,t,r,n){var o=t.createEncodedStreams(),i=o.readable,a=o.writable;return r.postMessage({type:e,readable:i,writable:a,options:n},[i,a]),{readable:i,writable:a}},Qe=function(){var e=Ie(je().mark((function e(t,r,n){var o,i,a;return je().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=new kt(t),i=new Pt(t.kind),a=new Ot({transform:r}),o.readable.pipeThrough(a,n).pipeTo(i.writable).catch((function(e){if(n){var t=n.signal;t&&t.abort(e)}y("[PIPE:pipeGeneratorTransform]",e.message)})),e.abrupt("return",{processor:o,generator:i});case 6:case"end":return e.stop()}}),e)})));return function(t,r,n){return e.apply(this,arguments)}}(),$e=function(){var e=Ie(je().mark((function e(t,r,n){var o,i,a,s;return je().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=new Ot({transform:r}),i=t.createEncodedStreams(),a=i.readable,s=i.writable,a.pipeThrough(o,n).pipeTo(s).catch((function(e){if(a.cancel(e),n){var t=n.signal;t&&t.abort(e)}y("[PIPE:pipeSenderTransform]",e.message)})),e.abrupt("return",{readable:a,writable:s});case 6:case"end":return e.stop()}}),e)})));return function(t,r,n){return e.apply(this,arguments)}}(),Ze=function(){var e=Ie(je().mark((function e(t,r,n){var o,i,a,s;return je().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=new Ot({transform:r}),i=t.createEncodedStreams(),a=i.readable,s=i.writable,a.pipeThrough(o,n).pipeTo(s).catch((function(e){if(a.cancel(e),n){var t=n.signal;t&&t.abort(e)}y("[PIPE:pipeReceiverTransform",e.message)})),e.abrupt("return",{readable:a,writable:s});case 6:case"end":return e.stop()}}),e)})));return function(t,r,n){return e.apply(this,arguments)}}(),et=function(e,t){var r=new S,n=Be(De);p("[gum:getUserMedia]","Is Available in format listing: "+n(e));var o=function(n){if(n){var o="string"==typeof n?n:[n.name,n.message].join(": ");p("[gum:getUserMedia]","Failure in getUserMedia: ".concat(o,". Attempting other resolution tests..."))}(function(e){p("[gum:determineSupportedResolution]","Determine next neighbor based on constraints: "+JSON.stringify(e,null,2));var t=new S,r=Ve(De)(e),n=Re(e);return Ge(n,r,t),t.promise})(e).then((function(e){r.resolve({media:e.media,constraints:e.constraints})})).catch((function(n){t&&t(e),r.reject({error:n,constraints:e})}))};if(function(e){return e.hasOwnProperty("video")&&(e.video.hasOwnProperty("width")||e.video.hasOwnProperty("height"))}(e))if(n(e)){p("[gum:getUserMedia]","Found constraints in list. Checking quick support for faster setup with: "+JSON.stringify(e,null,2));var i=function(e){var t=Re(e);return"boolean"==typeof e.video||(e.video.width&&(t.video.width={exact:Me(e.video.width)}),e.video.height&&(t.video.height={exact:Me(e.video.height)})),t}(e);me.gUM(i).then((function(e){r.resolve({media:e,constraints:i})})).catch(o)}else p("[gum:getUserMedia]","Could not find contraints in list. Attempting failover..."),t&&t(e),o();else p("[gum:getUserMedia]","Constraints were not defined properly. Attempting failover..."),me.gUM(e).then((function(t){r.resolve({media:t,constraints:e})})).catch(o);return r.promise},tt=function(e,t){for(var r=e.split("\r\n"),n=r.length;--n>-1;)t.indexOf(r[n])>-1&&r.splice(n,1);return r.join("\r\n")},rt=function(e){return tt(e,["a=ice-options:trickle"])},nt=function(e){var t="a=ice-options:trickle";if(e.indexOf(t)>-1)return e;var r=e.split("\r\n"),n=r.map((function(e,t){return e.match(/^a=ice-ufrag:(.*)/)?t:-1})).filter((function(e){return e>-1})),o=n.length>0?n[n.length-1]:-1;return o>-1&&r.splice(o+1,0,t),r.join("\r\n")},ot=function(e){var t="a=end-of-candidates";if(e.indexOf(t)>-1)return e;var r=e.split("\r\n"),n=r.map((function(e,t){return e.match(/^a=candidate:(.*)/)?t:-1})).filter((function(e){return e>-1})),o=n.length>0?n[n.length-1]:-1;return o>-1&&r.splice(o+1,0,t),r.join("\r\n")},it=function(e){for(var t=/^a=extmap/,r=e.split("\r\n"),n=r.length;--n>-1;)t.exec(r[n])&&r.splice(n,1);return r.join("\r\n")},at=(xe=[],["rtpmap:(\\d{1,}) ISAC","rtpmap:(\\d{1,}) G722","rtpmap:(\\d{1,}) CN","rtpmap:(\\d{1,}) PCMU","rtpmap:(\\d{1,}) PCMA","rtpmap:(\\d{1,}) telephone-event"].forEach((function(e){return xe.push(new RegExp("a=(".concat(e,")"),"g"))})),xe),st=function(e){for(var t,r,n,o,i,a=e.split("\r\n"),s=a.length,c=[];--s>-1;)for(t=0;t-1;)for(t=0;t-1;)n.lastIndex=0,(t=n.exec(i[a]))&&-1===o.indexOf(t[t.length-1])&&o.push(t[t.length-1]);for(a=i.length;--a>-1;)for(s=0;s-1;)ut.lastIndex=0,ut.exec(t[n])&&t.splice(n,1);return t.join("\r\n")}return e})).join(t)},ft=function(e){return lt(e,"m=",/^audio/g)},dt=function(e){return lt(e,"m=",/^video/g)},ht=function(e,t){var r,n,o,i=t.indexOf("m=audio"),a=t.indexOf("m=video"),s=t.indexOf("m=application");return i>-1&&e.audio&&(r=t.indexOf("\r\n",i),n=t.slice(0,r),o=t.slice(r+"\r\n".length,t.length),a=(t=[n,"b=AS:"+e.audio,o].join("\r\n")).indexOf("m=video"),s=t.indexOf("m=application")),a>-1&&e.video&&(r=t.indexOf("\r\n",a),n=t.slice(0,r),o=t.slice(r+"\r\n".length,t.length),s=(t=[n,"b=AS:"+e.video,o].join("\r\n")).indexOf("m=application")),s>-1&&e.dataChannel&&(r=t.indexOf("\r\n",s),n=t.slice(0,r),o=t.slice(r+"\r\n".length,t.length),t=[n,"b=AS:"+e.dataChannel,o].join("\r\n")),t},pt=/(a=group:BUNDLE)(.*)/,vt=function(e){return pt.exec(e)?e.match(pt)[2].trim():void 0},yt=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"0 1 2";return e.replace(pt,"$1 "+t)},mt=/(profile-level-id=42)(.*)/g,bt=function(e){return e.replace(mt,"$1e01f")},gt=function(e){return e.includes("stereo=1")?e:e.replace("useinbandfec=1","useinbandfec=1;stereo=1;sprop-stereo=1")},_t=function(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o="a=end-of-candidates",i=/^a=candidate:/,a=/^a=ice-ufrag:/,s=/^a=ice-pwd:/,c=/^m=(audio|video|application)\ /,u=e.split("\r\n"),l="",f="",d="a=mid:0",h=[];u.forEach((function(e){!t&&c.exec(e)?t=e:a.exec(e)?l=e:s.exec(e)?f=e:i.exec(e)&&(r&&-1!=e.indexOf(r)?h.push(e):r||h.push(e))})),n&&h[h.length-1]!==o&&h.push(o);var p=[l,f,t,d].concat(h);return p.join("\r\n")},wt=window.RTCPeerConnection||window.mozRTCPeerConnection||window.webkitRTCPeerConnection,St=window.RTCIceCandidate||window.mozRTCIceCandidate||window.webkitRTCIceCandidate,Et=window.RTCSessionDescription||window.mozRTCSessionDescription||window.webkitRTCSessionDescription,Ct=window.RTCRtpSender||window.RTCRtpSender||window.RTCRtpSender,Ot=window.TransformStream,kt=window.MediaStreamTrackProcessor,Pt=window.MediaStreamTrackGenerator,Tt=wt,Rt=St,At=Et,Lt=function(){return me.supportsWebSocket()},Nt=Object.freeze({CONNECT_SUCCESS:"Connect.Success",CONNECT_FAILURE:"Connect.Failure",PUBLISH_START:"Publish.Start",PUBLISH_FAIL:"Publish.Fail",PUBLISH_INVALID_NAME:"Publish.InvalidName",UNPUBLISH_SUCCESS:"Unpublish.Success",PUBLISH_METADATA:"Publish.Metadata",PUBLISH_STATUS:"Publish.Status",PUBLISH_AVAILABLE:"Publish.Available",PUBLISH_INSUFFICIENT_BANDWIDTH:"Publish.InsufficientBW",PUBLISH_SUFFICIENT_BANDWIDTH:"Publish.SufficientBW",PUBLISH_RECOVERING_BANDWIDTH:"Publish.RecoveringBW",PUBLISH_SEND_INVOKE:"Publish.Send.Invoke",CONNECTION_CLOSED:"Publisher.Connection.Closed",DIMENSION_CHANGE:"Publisher.Video.DimensionChange",STATISTICS_ENDPOINT_CHANGE:"Publisher.StatisticsEndpoint.Change"}),jt=Object.freeze({PUBLISHER_REJECT:"Publisher.Reject",PUBLISHER_ACCEPT:"Publisher.Accept"}),Ht=Object.freeze({CONSTRAINTS_ACCEPTED:"WebRTC.MediaConstraints.Accepted",CONSTRAINTS_REJECTED:"WebRTC.MediaConstraints.Rejected",MEDIA_STREAM_AVAILABLE:"WebRTC.MediaStream.Available",PEER_CONNECTION_AVAILABLE:"WebRTC.PeerConnection.Available",OFFER_START:"WebRTC.Offer.Start",OFFER_END:"WebRTC.Offer.End",PEER_CANDIDATE_END:"WebRTC.PeerConnection.CandidateEnd",ICE_TRICKLE_COMPLETE:"WebRTC.IceTrickle.Complete",SOCKET_MESSAGE:"WebRTC.Socket.Message",DATA_CHANNEL_OPEN:"WebRTC.DataChannel.Open",DATA_CHANNEL_AVAILABLE:"WebRTC.DataChannel.Available",DATA_CHANNEL_CLOSE:"WebRTC.DataChannel.Close",DATA_CHANNEL_MESSAGE:"WebRTC.DataChannel.Message",DATA_CHANNEL_ERROR:"WebRTC.DataChannel.Error",PEER_CONNECTION_OPEN:"WebRTC.PeerConnection.Open",TRACK_ADDED:"WebRTC.PeerConnection.OnTrack",UNSUPPORTED_FEATURE:"WebRTC.Unsupported.Feature",TRANSFORM_ERROR:"WebRTC.Transform.Error",HOST_ENDPOINT_CHANGED:"WebRTC.Endpoint.Changed",STATS_REPORT:"WebRTC.Stats.Report"}),It=Object.freeze({EMBED_SUCCESS:"FlashPlayer.Embed.Success",EMBED_FAILURE:"FlashPlayer.Embed.Failure"}),xt=Object.freeze({CONNECT_SUCCESS:"Connect.Success",CONNECT_FAILURE:"Connect.Failure",SUBSCRIBE_START:"Subscribe.Start",SUBSCRIBE_STOP:"Subscribe.Stop",SUBSCRIBE_FAIL:"Subscribe.Fail",SUBSCRIBE_INVALID_NAME:"Subscribe.InvalidName",SUBSCRIBE_METADATA:"Subscribe.Metadata",SUBSCRIBE_STATUS:"Subscribe.Status",SUBSCRIBE_SEND_INVOKE:"Subscribe.Send.Invoke",SUBSCRIBE_PUBLISHER_CONGESTION:"Subscribe.Publisher.NetworkCongestion",SUBSCRIBE_PUBLISHER_RECOVERY:"Subscribe.Publisher.NetworkRecovery",PLAY_UNPUBLISH:"Subscribe.Play.Unpublish",CONNECTION_CLOSED:"Subscribe.Connection.Closed",ORIENTATION_CHANGE:"Subscribe.Orientation.Change",STREAMING_MODE_CHANGE:"Subscribe.StreamingMode.Change",VIDEO_DIMENSIONS_CHANGE:"Subscribe.VideoDimensions.Change",VOLUME_CHANGE:"Subscribe.Volume.Change",SEEK_CHANGE:"Subscribe.Seek.Change",PLAYBACK_TIME_UPDATE:"Subscribe.Time.Update",PLAYBACK_STATE_CHANGE:"Subscribe.Playback.Change",FULL_SCREEN_STATE_CHANGE:"Subscribe.FullScreen.Change",AUTO_PLAYBACK_FAILURE:"Subscribe.Autoplay.Failure",AUTO_PLAYBACK_MUTED:"Subscribe.Autoplay.Muted",STATISTICS_ENDPOINT_CHANGE:"Subscribe.StatisticsEndpoint.Change"}),Dt=Object.freeze({SUBSCRIBER_REJECT:"Subscriber.Reject",SUBSCRIBER_ACCEPT:"Subscriber.Accept"}),Mt=Object.freeze({PEER_CONNECTION_AVAILABLE:"WebRTC.PeerConnection.Available",OFFER_START:"WebRTC.Offer.Start",OFFER_END:"WebRTC.Offer.End",ANSWER_START:"WebRTC.Answer.Start",ANSWER_END:"WebRTC.Answer.End",CANDIDATE_START:"WebRTC.Candidate.Start",CANDIDATE_END:"WebRTC.Candidate.End",PEER_CANDIDATE_END:"WebRTC.PeerConnection.CandidateEnd",ICE_TRICKLE_COMPLETE:"WebRTC.IceTrickle.Complete",SOCKET_MESSAGE:"WebRTC.Socket.Message",DATA_CHANNEL_MESSAGE:"WebRTC.DataChannel.Message",DATA_CHANNEL_OPEN:"WebRTC.DataChannel.Open",DATA_CHANNEL_AVAILABLE:"WebRTC.DataChannel.Available",DATA_CHANNEL_CLOSE:"WebRTC.DataChannel.Close",DATA_CHANNEL_ERROR:"WebRTC.DataChannel.Error",PEER_CONNECTION_OPEN:"WebRTC.PeerConnection.Open",ON_ADD_STREAM:"WebRTC.Add.Stream",TRACK_ADDED:"WebRTC.PeerConnection.OnTrack",SUBSCRIBE_STREAM_SWITCH:"WebRTC.Subscribe.StreamSwitch",LIVE_SEEK_UNSUPPORTED:"WebRTC.LiveSeek.Unsupported",LIVE_SEEK_ERROR:"WebRTC.LiveSeek.Error",LIVE_SEEK_ENABLED:"WebRTC.LiveSeek.Enabled",LIVE_SEEK_DISABLED:"WebRTC.LiveSeek.Disabled",LIVE_SEEK_LOADING:"WebRTC.LiveSeek.FragmentLoading",LIVE_SEEK_LOADED:"WebRTC.LiveSeek.FragmentLoaded",LIVE_SEEK_CHANGE:"WebRTC.LiveSeek.Change",TRANSFORM_ERROR:"WebRTC.Transform.Error",HOST_ENDPOINT_CHANGED:"WebRTC.Endpoint.Changed",STATS_REPORT:"WebRTC.Stats.Report"}),Ft=Object.freeze({EMBED_SUCCESS:"FlashPlayer.Embed.Success",EMBED_FAILURE:"FlashPlayer.Embed.Failure",ABR_LEVEL_CHANGE:"RTMP.AdaptiveBitrate.Level"}),Ut=Object.freeze({OPEN:"MessageTransport.Open",CLOSE:"MessageTransport.Close",CHANGE:"MessageTransport.Change",ERROR:"MessageTransport.Error"}),Bt=Object.freeze({AUDIO_STREAM:"Conference.AudioStream",VIDEO_STREAM:"Conference.VideoStream",MEDIA_STREAM:"Conference.MediaStream"});function Vt(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Gt(e,t)}function Gt(e,t){return(Gt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function Wt(e){var t=function(){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}}();return function(){var r,n=zt(e);if(t){var o=zt(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return Yt(this,r)}}function Yt(e,t){if(t&&("object"===Kt(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function zt(e){return(zt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function Kt(e){return(Kt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Jt(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function qt(e,t){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:void 0;Jt(this,e),this._type=t,this._data=r}return Xt(e,[{key:"type",get:function(){return this._type}},{key:"data",get:function(){return this._data}}]),e}(),$t=function(e){Vt(r,e);var t=Wt(r);function r(e,n,o){var i;return Jt(this,r),(i=t.call(this,e,o))._publisher=n,i}return Xt(r,[{key:"publisher",get:function(){return this._publisher}}]),r}(Qt),Zt=function(e){Vt(r,e);var t=Wt(r);function r(e,n,o){var i;return Jt(this,r),(i=t.call(this,e,o))._subscriber=n,i}return Xt(r,[{key:"subscriber",get:function(){return this._subscriber}}]),r}(Qt),er=function(e){Vt(r,e);var t=Wt(r);function r(e,n,o){var i;return Jt(this,r),(i=t.call(this,e,o))._name=n,i}return Xt(r,[{key:"name",get:function(){return this._name}}]),r}(Qt),tr=function(e){Vt(r,e);var t=Wt(r);function r(e,n,o){var i;return Jt(this,r),(i=t.call(this,e,o))._participant=n,i}return Xt(r,[{key:"participant",get:function(){return this._participant}}]),r}(Qt);function rr(e){return(rr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function nr(e,t){for(var r=0;r1||"touchend"==e.type&&e.touches.length>0)){var t,r,n=me.createEvent("MouseEvent"),o=e.originalTarget||e.target;switch(e.type){case"touchstart":t="mousedown",r=e.changedTouches[0];break;case"touchmove":t="mousemove",r=e.changedTouches[0];break;case"touchend":t="mouseup",r=e.changedTouches[0]}n.initMouseEvent(t,!0,!0,o.ownerDocument.defaultView,0,r.screenX,r.screenY,r.clientX,r.clientY,e.ctrlKey,e.altKey,e.shiftKey,e.metaKey,0,null),o.dispatchEvent(n)}}},{key:"_mouseup",value:function(){this._eventStartPosition=0,document.removeEventListener("mousemove",this._mousemoveHandler),document.removeEventListener("mouseup",this._mouseupHandler),document.removeEventListener("touchmove",this._touchmoveHandler),document.removeEventListener("touchup",this._touchupHandler),document.removeEventListener("touchend",this._touchupHandler),this.trigger(new cr(ur.CHANGE_COMPLETE,this))}},{key:"_mousemove",value:function(e){var t=me.getMouseXFromEvent(e)-this._eventStartPosition,r=this._button.parentNode.getBoundingClientRect(),n=this._eventStartPosition+t-r.left;n=Math.max(0,n);var o=(n=Math.min(n,r.width))/r.width;this.trigger(new cr(ur.CHANGE,this,o))}},{key:"_mousedown",value:function(e){this._eventStartPosition=me.getMouseXFromEvent(e),this.trigger(new cr(ur.CHANGE_START,this)),document.addEventListener("mousemove",this._mousemoveHandler),document.addEventListener("mouseup",this._mouseupHandler),document.addEventListener("touchmove",this._touchmoveHandler),document.addEventListener("touchup",this._touchupHandler),document.addEventListener("touchend",this._touchupHandler)}},{key:"_updateHandlers",value:function(e){this._eventStartPosition=0,e?(this._track.removeEventListener("click",this._mousemoveHandler),this._progressBar.removeEventListener("click",this._mousemoveHandler),this._button.removeEventListener("mousedown",this._mousedownHandler),document.removeEventListener("mousemove",this._mousemoveHandler),document.removeEventListener("mouseup",this._mouseupHandler),document.removeEventListener("touchmove",this._touchmoveHandler),document.removeEventListener("touchup",this._touchupHandler),document.removeEventListener("touchend",this._touchupHandler),this._track.classList.add("red5pro-media-slider-disabled"),this._progressBar.classList.add("red5pro-media-slider-disabled"),this._button.classList.add("red5pro-media-slider-disabled")):(this._track.addEventListener("click",this._mousemoveHandler),this._progressBar.addEventListener("click",this._mousemoveHandler),this._button.addEventListener("mousedown",this._mousedownHandler),this._button.addEventListener("touchstart",this._touchdownHandler),this._track.classList.remove("red5pro-media-slider-disabled"),this._progressBar.classList.remove("red5pro-media-slider-disabled"),this._button.classList.remove("red5pro-media-slider-disabled"))}},{key:"_layout",value:function(){var e=this._progressBar.parentNode.clientWidth*this._value;this._progressBar.style.width=e+"px",this._button.style.left=e-.5*this._button.clientWidth+"px"}},{key:"createButton",value:function(){var e=me.createElement("span");return e.classList.add("red5pro-media-slider-button"),e}},{key:"createProgressBar",value:function(){var e=me.createElement("span");return e.classList.add("red5pro-media-slider-progress"),e}},{key:"createTrack",value:function(){var e=me.createElement("span");return e.classList.add("red5pro-media-slider-track"),e}},{key:"value",get:function(){return this._value},set:function(e){this._value=e,this._layout()}},{key:"disabled",get:function(){return this._disabled},set:function(e){this._disabled=e,this._updateHandlers(e)}},{key:"view",get:function(){return this._container}}])&&dr(t.prototype,r),n&&dr(t,n),Object.defineProperty(t,"prototype",{writable:!1}),i}(H),_r=Object.freeze({UNAVAILABLE:1e3,AVAILABLE:0,IDLE:1,PLAYING:2,PAUSED:3}),wr=Object.freeze({1e3:"Playback.UNAVAILABLE",0:"Playback.AVAILABLE",1:"Playback.IDLE",2:"Playback.PLAYING",3:"Playback.PAUSED"}),Sr=Object.freeze({LIVE:0,VOD:1}),Er=Object.freeze({0:"LiveSeek.LIVE",1:"LiveSeek.VOD"});function Cr(e){return(Cr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Or(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function kr(e,t){for(var r=0;r=60&&(r=parseInt(n/60),n%=60),t=0===e||isNaN(e)?0:parseInt(e%60);var o=r<10?["0"+r]:[r];return o.push(n<10?["0"+n]:[n]),o.push(t<10?["0"+t]:[t]),o.join(":")}},{key:"getVolume",value:function(){return this._volumeValue}},{key:"setVolume",value:function(e){return this._volumeField.value=e,this._volumeValue=e,0===e?this.setMutedState(!0):this.getMutedState()&&this.setMutedState(!1),this}},{key:"setSeekTime",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return this._seekTimeField.value=0===t?0:e/t,0!==this._playbackDuration&&parseInt(this._playbackDuration)<=parseInt(e)&&(this._seekTimeField.value=1),!isFinite(this._playbackDuration)&&me.getIsPossiblySafari()?this._timeField.innerText="Live Broadcast":this._timeField.innerText=this.formatTime(Math.floor(e)),this}},{key:"setPlaybackDuration",value:function(e){p("PlaybackControls","[setplaybackduration]: "+e),this._playbackDuration=e}},{key:"getPlaybackDuration",value:function(){return this._playbackDuration}},{key:"getState",value:function(){return this._state}},{key:"setState",value:function(e){return p("PlaybackControls","[setState]: "+wr[e]),this._state=e,this.onStateChange(this._state),this}},{key:"getMutedState",value:function(){return"muted"in this.player?this.player.muted:this._mutedState}},{key:"setMutedState",value:function(e){return this._mutedState=e,this.onMutedStateChange(this._mutedState),this}},{key:"onStateChange",value:function(e){return e===_r.PLAYING?(this._playPauseButton.classList.remove("red5pro-media-play-button"),this._playPauseButton.classList.add("red5pro-media-pause-button")):(this._playPauseButton.classList.add("red5pro-media-play-button"),this._playPauseButton.classList.remove("red5pro-media-pause-button")),this}},{key:"onMutedStateChange",value:function(e){e?(this._muteButton.classList.add("red5pro-media-mute-button"),this._muteButton.classList.remove("red5pro-media-unmute-button"),this._volumeField.value=0):(this._muteButton.classList.remove("red5pro-media-mute-button"),this._muteButton.classList.add("red5pro-media-unmute-button"),this._volumeField.value=this._volumeValue)}},{key:"onFullScreenChange",value:function(e){return e?(this._fullScreenButton.classList.add("red5pro-media-exit-fullscreen-button"),this._fullScreenButton.classList.remove("red5pro-media-fullscreen-button")):(this._fullScreenButton.classList.remove("red5pro-media-exit-fullscreen-button"),this._fullScreenButton.classList.add("red5pro-media-fullscreen-button")),this}},{key:"setAsVOD",value:function(e){p("PlaybackControls","[setAsVOD]: "+e),e?this._seekTimeField.disabled=!1:(this._seekTimeField.value=0,this._seekTimeField.disabled=!0)}},{key:"detach",value:function(){this.enable(!1),this._controlbar&&this._controlbar.parentNode&&this._controlbar.parentNode.removeChild(this._controlbar),this._controlbar=void 0,this.container=void 0}}]),r}(Ir);function Fr(e){return(Fr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Ur(e,t){for(var r=0;r0&&void 0!==arguments[0]&&arguments[0];this.play().catch((function(r){t?(e.mute(),e.play().then((function(){e.trigger(new Zt(xt.AUTO_PLAYBACK_MUTED,void 0,{element:e.media}))})).catch((function(t){e.trigger(new Zt(xt.AUTO_PLAYBACK_FAILURE,void 0,{error:t.message?t.message:t,element:e.media}))}))):e.trigger(new Zt(xt.AUTO_PLAYBACK_FAILURE,void 0,{error:r.message?r.message:r,element:e.media}))}))}},{key:"play",value:function(){p("RTCSourceHandler","[videoelement:action] play");var e=new S;if(!this.media.paused)return p("RTCSourceHandler","[videoelement:action] play (ALREADY PLAYING)"),e.resolve(),e.promise;try{var t=this.media.play();t?t.then((function(){p("RTCSourceHandler","[videoelement:action] play (START)"),e.resolve()})).catch(e.reject):(p("RTCSourceHandler","[videoelement:action] play (START)"),e.resolve())}catch(t){y("RTCSourceHandler","[videoelement:action] play (FAULT) - "+t.message),e.reject(t)}return e.promise}},{key:"pause",value:function(){p("RTCSourceHandler","[videoelement:action] pause");try{this.media.pause()}catch(e){v("RTCSourceHandler","[videoelement:action] pause (CATCH::FAULT) - "+e.message)}}},{key:"resume",value:function(){p("RTCSourceHandler","[videoelement:action] resume");try{var e=this.media.play();e&&e.then((function(){return p("RTCSourceHandler","[videoelement:action] play (START)")})).catch((function(e){return v("RTCSourceHandler","[videoelement:action] play (CATCH::FAULT) "+(e.message?e.message:e))}))}catch(e){v("RTCSourceHandler","[videoelement:action] resume (CATCH::FAULT) - "+e.message)}}},{key:"stop",value:function(){p("RTCSourceHandler","[videoelement:action] stop");try{this.media.stop()}catch(e){}}},{key:"mute",value:function(){this.media.muted=!0;var e=this.getControls();e&&e.setMutedState(!0)}},{key:"unmute",value:function(){this.media.muted=!1;var e=this.getControls();e&&e.setMutedState(!1)}},{key:"setVolume",value:function(e){this.unmute(),this.media.volume=e}},{key:"seekTo",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;this.media.currentTime=t?e*t:e}},{key:"toggleFullScreen",value:function(){try{this.holder&&me.toggleFullScreen(this.holder)}catch(e){throw e}}},{key:"unpublish",value:function(){try{this.stop(),this.media.onended.call(this.media)}catch(e){}}},{key:"disconnect",value:function(){this._cleanUp()}},{key:"handleOrientationChange",value:function(e){this._controls&&e%180!=0&&(this.holder&&this.holder.classList.add("red5pro-media-background"),this.media.classList.remove("red5pro-media-background"))}},{key:"getControls",value:function(){return this._controls}},{key:"getType",value:function(){return this.playerType}},{key:"isVOD",get:function(){return this._isVOD},set:function(e){this._isVOD=e,this._controls&&this._controls.setAsVOD(e)}}])&&Ur(t.prototype,r),n&&Ur(t,n),Object.defineProperty(t,"prototype",{writable:!1}),i}(xr);function Kr(e){return(Kr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Jr(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */Jr=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function u(e,t,r,o){var i=t&&t.prototype instanceof d?t:d,a=Object.create(i.prototype),s=new O(o||[]);return n(a,"_invoke",{value:w(e,r,s)}),a}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var f={};function d(){}function h(){}function p(){}var v={};c(v,i,(function(){return this}));var y=Object.getPrototypeOf,m=y&&y(y(k([])));m&&m!==t&&r.call(m,i)&&(v=m);var b=p.prototype=d.prototype=Object.create(v);function g(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function _(e,t){var o;n(this,"_invoke",{value:function(n,i){function a(){return new t((function(o,a){!function n(o,i,a,s){var c=l(e[o],e,i);if("throw"!==c.type){var u=c.arg,f=u.value;return f&&"object"==Kr(f)&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,a,s)}),(function(e){n("throw",e,a,s)})):t.resolve(f).then((function(e){u.value=e,a(u)}),(function(e){return n("throw",e,a,s)}))}s(c.arg)}(n,i,o,a)}))}return o=o?o.then(a,a):a()}})}function w(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return P()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var s=S(a,r);if(s){if(s===f)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=l(e,t,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===f)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function S(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,S(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),f;var o=l(n,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,f;var i=o.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,f):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,f)}function E(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 C(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function O(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(E,this),this.reset(!0)}function k(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 n=-1,o=function t(){for(;++n=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),C(r),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;C(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:k(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},e}function qr(e,t,r,n,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}function Xr(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Qr(e,t){for(var r=0;r3&&void 0!==arguments[3])||arguments[3];return Xr(this,a),(n=i.call(this)).media=e,n.clone=n.media.cloneNode(!0),n.parent=n.media.parentNode,n.holder=o?n._determineHolder(n.media):void 0,n.playerType=t,n.hlsOptions=r,n.subscriberId=void 0,n.hlsElement=void 0,n._usePlaybackControls=o,n._isVOD=!1,n._isSeekable=!1,n._isHLSPlaybackActive=!1,n._isFragLoading=!1,n._hlsRecoverFlop=!1,n._hlsRecoverAttempts=0,n._lastDurationUpdate=0,n._controls=void 0,n._resizeObserver=void 0,n._playbackNotificationCenter=n.media,n._pendingUnpublish=!1,n._wallOffset=NaN,n._averageSegmentDuration=6,n._manifestLoadTimeout=0,me.onFullScreenStateChange(n._handleFullScreenChange.bind(tn(n))),n.hls=void 0,n.hlsElement=void 0,n}return t=a,(r=[{key:"_determineHolder",value:function(e){if(e.parentNode.classList.contains("red5pro-media-container"))return e.parentNode;var t=e.parentNode,r=me.createElement("div");return r.classList.add("red5pro-media-container"),t.insertBefore(r,e),t.removeChild(e),r.appendChild(e),r}},{key:"_generateHLSLivePlayback",value:function(e,t,r){var n="".concat(r,"-hls-vod"),o=document.querySelector("#".concat(n));return o||((o=document.createElement("video")).id=n,o.classList.add("red5pro-hls-vod"),o.playsinline="playsinline",o.style.width="100%",o.style.height="100%",o.style.position="absolute",o.style.display="none",e.insertBefore(o,t)),o}},{key:"_loadManifest",value:(o=function(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){qr(i,n,o,a,s,"next",e)}function s(e){qr(i,n,o,a,s,"throw",e)}a(void 0)}))}}(Jr().mark((function e(t){var r,n,o,i,a,s,c,u,l,f,d=this;return Jr().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return clearTimeout(this._manifestLoadTimeout),e.prev=1,r=/^#EXT-X-TARGETDURATION:(.*)/,n=/^.*_(.*)\.\.*/,e.next=6,fetch(t,{method:"GET",mode:"cors",cache:"no-cache",headers:{"Content-Type":"text/plain;charset=UTF-8"}});case 6:return o=e.sent,e.next=9,o.text();case 9:i=e.sent,a=i.split("\r\n"),s=a.reverse().find((function(e){return n.test(e)})),c=a.find((function(e){return r.test(e)})).match(r)[1],u=parseFloat(c),l=s.match(n)[1],f=parseInt(l,10),isNaN(f)&&(f=1),f=f>1?f-1:f,this._averageSegmentDuration=u,console.log("MANIFEST: ",i),this.isSeekable=!0,this.trigger(new Zt(Mt.LIVE_SEEK_ENABLED,void 0,{hlsElement:this.hlsElement,hlsControl:void 0})),this._onHLSDurationChange({target:this.hlsElement,duration:u*f}),this._manifestLoadTimeout=setTimeout((function(){clearTimeout(d._manifestLoadTimeout),d._loadManifest(t)}),1e3*u),e.next=31;break;case 26:e.prev=26,e.t0=e.catch(1),y("Could not load manifest: ".concat(e.t0.message,".")),this.trigger(new Zt(Mt.LIVE_SEEK_DISABLED,void 0,{hlsElement:this.hlsElement,hlsControl:void 0})),this.isSeekable=!1;case 31:case"end":return e.stop()}}),e,this,[[1,26]])}))),function(e){return o.apply(this,arguments)})},{key:"_showHLSLivePlayback",value:function(e,t,r,n){if(this._isHLSPlaybackActive!==e){this._isHLSPlaybackActive=e;var o=e?r.muted:t.muted;if(e){t.volume=r.volume,t.muted=o,r.muted=!0,t.style.display="inline-block",n.style.position="relative";try{r.paused?this.pause(!1):(this.pause(!0),this.play())}catch(e){v("Could not start playback: ".concat(e.message,"."))}r.style.display="none"}else{r.volume=t.volume,t.muted=!0,r.muted=o,r.style.display="inline-block";try{t.paused?this.pause(!1):(this.pause(!0),this.play())}catch(e){v("Could not start playback: ".concat(e.message,"."))}t.style.display="none"}var i=e?Sr.VOD:Sr.LIVE;this.trigger(new Zt(Mt.LIVE_SEEK_CHANGE,void 0,{code:i,state:Er[i]}))}}},{key:"_cleanUp",value:function(){if(this.clone){var e=this.media,t=e.parentNode,r=this.holder;if(this._removePlaybackHandlers(e),this.hls&&(this.hls.detachMedia(),this.hls=void 0),this.hlsElement&&(this._removeSeekableHandlers(this.hlsElement),this.hlsElement.parentNode&&this.hlsElement.parentNode.removeChild(this.hlsElement),this.hlsElement=void 0),this._controls&&(this._controls.detach(),this._controls=void 0),t)t.removeChild(e),t!==this.parent&&(t.parentNode.removeChild(t),r=this.parent);else try{e.remove()}catch(e){v("RTCSeekableSourceHandler","Issue in DOM cleanup of WebRTC video object: ".concat(e.message))}this.media=this.clone.cloneNode(!0),r.appendChild(this.media),this._resizeObserver&&(this._resizeObserver.unobserve(),this._resizeObserver=void 0),this._isVOD=!1,this._isSeekable=!1,this._isHLSPlaybackActive=!1,this._isFragLoading=!1,this._hlsRecoverFlop=!1,this._hlsRecoverAttempts=0}}},{key:"_addPlaybackHandlers",value:function(e){var t=this,r=this.getControls();e.oncanplay=function(){p("RTCSeekableSourceHandler","[videoelement:event] canplay"),r&&r.enable(!0),t.trigger(new Zt(xt.PLAYBACK_STATE_CHANGE,void 0,{code:_r.AVAILABLE,state:wr[_r.AVAILABLE]})),t.trigger(new Zt(xt.VOLUME_CHANGE,void 0,{volume:e.volume}))},e.onended=function(){return t._onRTCEnded.bind(t)},e.ondurationchange=this._onRTCDurationChange.bind(this),e.ontimeupdate=this._onRTCTimeUpdate.bind(this),e.onplay=this._onRTCPlay.bind(this),e.onpause=this._onRTCPause.bind(this),e.onvolumechange=function(n){r&&r.getVolume()!==t.media.volume&&r.setVolume(t.media.volume),t.trigger(new Zt(xt.VOLUME_CHANGE,void 0,{volume:e.muted?0:e.volume}))},e.onencrypted=function(){p("RTCSeekableSourceHandler","[videoelement:event] encrypted")},e.onemptied=function(){p("RTCSeekableSourceHandler","[videoelement:event] emptied")},e.onloadeddata=function(){p("RTCSeekableSourceHandler","[videoelement:event] loadeddata"),t.trigger(new Zt(xt.VIDEO_DIMENSIONS_CHANGE,void 0,{width:t.media.videoWidth,height:t.media.videoHeight}))},e.onresize=function(){p("RTCSeekableSourceHandler","[videoelement:event] resize"),t.trigger(new Zt(xt.VIDEO_DIMENSIONS_CHANGE,void 0,{width:t.media.videoWidth,height:t.media.videoHeight}))},e.onloadedmetadata=function(){p("RTCSeekableSourceHandler","[videoelement:event] loadedmetadata"),t.trigger("loadedmetadata")},e.onloadstart=function(){p("RTCSeekableSourceHandler","[videoelement:event] loadedstart")},e.onstalled=function(){p("RTCSeekableSourceHandler","[videoelement:event] stalled")},e.onsuspend=function(){p("RTCSeekableSourceHandler","[videoelement:event] suspend")},e.onwaiting=function(){p("RTCSeekableSourceHandler","[videoelement:event] waiting")}}},{key:"_removePlaybackHandlers",value:function(e){e.oncanplay=void 0,e.onended=void 0,e.ondurationchange=void 0,e.ontimeupdate=void 0,e.onplay=void 0,e.onpause=void 0,e.onvolumechange=void 0,e.onencrypted=void 0,e.onemptied=void 0,e.onloadeddata=void 0,e.onresize=void 0,e.onloadedmetadata=void 0,e.onloadstart=void 0,e.onstalled=void 0,e.onsuspend=void 0,e.onwaiting=void 0}},{key:"_addSeekableHandlers",value:function(e,t){var r=this,n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];t&&(t.on(me.getHLSClientEventEnum().ERROR,(function(n,o){var i=o.type,a=o.details,s=o.fatal,c=o.url;if("networkerror"===i.toLowerCase()){if("levelemptyerror"===a.toLowerCase()){r.trigger(new Zt(Mt.LIVE_SEEK_DISABLED,void 0,{hlsElement:e,hlsControl:t})),r.isSeekable=!1,t.destroy();var u=setTimeout((function(){clearTimeout(u),r.enableLiveSeek(c,r.subscriberId,r.hlsElement,!1)}),3e3);return}r.trigger(new Zt(Mt.LIVE_SEEK_ERROR,void 0,{hlsElement:e,hlsControl:t,error:o}))}else r.trigger(new Zt(Mt.LIVE_SEEK_ERROR,void 0,{hlsElement:e,hlsControl:t,error:o}));"mediaerror"===i.toLowerCase()&&(r._hlsRecoverFlop&&t.swapAudioCodec(),r._hlsRecoverFlop=!r._hlsRecoverFlop,r._hlsRecoverAttempts=r._hlsRecoverAttempts+1,t.recoverMediaError()),s&&"networkerror"===i.toLowerCase()&&t.startLoad()})),t.on(me.getHLSClientEventEnum().MANIFEST_PARSED,(function(){try{e.pause()}catch(e){p("RTCSeekableSourceHandler","Could not pause seekable live stream: ".concat(e.message))}r.isSeekable=!0,r.trigger(new Zt(Mt.LIVE_SEEK_ENABLED,void 0,{hlsElement:e,hlsControl:t}))})),t.on(me.getHLSClientEventEnum().FRAG_LOADING,(function(n,o){var i=o.frag.stats,a=i.loaded,s=i.total;r.trigger(new Zt(Mt.LIVE_SEEK_LOADING,void 0,{hlsElement:e,hlsControl:t,progress:a/s*100})),(r.isHLSPlaybackActive||r._isFragLoading)&&(r._isFragLoading=a/s>=1)})),t.on(me.getHLSClientEventEnum().FRAG_LOADED,(function(n,o){r._isFragLoading=!1;var i=o.frag,a=i.endDTS,s=i.loader;if(r.isHLSPlaybackActive||a){var c=6,u=0;if(s&&s.stats&&s.stats.segments){for(var l=s.stats.segments,f=0;f=t.duration?this._showHLSLivePlayback(!1,this.hlsElement,this.media,this.holder):!isNaN(t.duration)&&this._isHLSPlaybackActive&&this.trigger(new Zt(xt.PLAYBACK_TIME_UPDATE,void 0,{time:t.currentTime,duration:t.duration+this._averageSegmentDuration,action:"hls time update"}))}},{key:"_onHLSPlay",value:function(){p("RTCSeekableSourceHandler","[HLS:videoelement:event] play");var e=this.getControls();e&&e.setState(_r.PLAYING),this.trigger(new Zt(xt.PLAYBACK_STATE_CHANGE,void 0,{code:_r.PLAYING,state:wr[_r.PLAYING]}))}},{key:"_onHLSPause",value:function(){p("RTCSeekableSourceHandler","[HLS:videoelement:event] pause");var e=this.getControls();e&&e.setState(_r.PAUSED),this.trigger(new Zt(xt.PLAYBACK_STATE_CHANGE,void 0,{code:_r.PAUSED,state:wr[_r.PAUSED]}))}},{key:"_handleFullScreenChange",value:function(e){e?(this.holder&&this.holder.classList.add("red5pro-media-container-full-screen"),this.hlsElement&&this.hlsElement.classList.add("red5pro-media-container-full-screen"),this.media.classList.add("red5pro-media-container-full-screen")):(this.holder&&this.holder.classList.remove("red5pro-media-container-full-screen"),this.hlsElement&&this.hlsElement.classList.remove("red5pro-media-container-full-screen"),this.media.classList.remove("red5pro-media-container-full-screen")),this.trigger(new Zt(xt.FULL_SCREEN_STATE_CHANGE,void 0,e))}},{key:"addSource",value:function(e){p("RTCSeekableSourceHandler","[addsource]"),this.media.controls=!0,this.media.classList.add("red5pro-media"),me.hasAttributeDefined(this.media,"controls")&&me.hasClassDefined(this.media,"red5pro-media")&&(this.media.classList.add("red5pro-media"),this.holder=this._determineHolder(this.media));var t=new S,r=e.controls,n=me.hasAttributeDefined(this.media,"muted");return r||this._usePlaybackControls?(this._controls=r?e.controls:new Mr(this,this.holder),this.media.controls=!1,this._controls.setAsVOD(this.isSeekable),this._controls.setMutedState(n)):this.media.controls=!1,this._addPlaybackHandlers(this._playbackNotificationCenter),t.resolve(),t.promise}},{key:"connect",value:function(){p("RTCSeekableSourceHandler","[connect]")}},{key:"attemptAutoplay",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.play().catch((function(r){t?(e.mute(),e.play().then((function(){e.trigger(new Zt(xt.AUTO_PLAYBACK_MUTED,void 0,{element:e.media}))})).catch((function(t){e.trigger(new Zt(xt.AUTO_PLAYBACK_FAILURE,void 0,{error:t.message?t.message:t,element:e.media}))}))):e.trigger(new Zt(xt.AUTO_PLAYBACK_FAILURE,void 0,{error:r.message?r.message:r,element:e.media}))}))}},{key:"enableLiveSeek",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0,o=this.getControls();if(o&&o.setSeekTime(1,1),this.subscriberId=t,this.hlsElement=r||this._generateHLSLivePlayback(this.holder,this.media,this.subscriberId),this._showHLSLivePlayback(this.isHLSPlaybackActive,this.hlsElement,this.media,this.holder),n){this._addSeekableHandlers(this.hlsElement,null,!1);var i=document.createElement("source");i.src=e,this.hlsElement.appendChild(i),this._loadManifest(e)}else{var a=this.hlsOptions,s=this._hlsjsRef?new this._hlsjsRef(a):me.createHLSClient(a);this._addSeekableHandlers(this.hlsElement,s),s.attachMedia(this.hlsElement),s.on(me.getHLSClientEventEnum().MEDIA_ATTACHED,(function(){s.loadSource(e)})),this.hls=s}me.setGlobal("r5pro_media_element",this.media),me.setGlobal("r5pro_hls_element",this.hlsElement),me.setGlobal("r5pro_hls_control",this.hls)}},{key:"switchLiveSeek",value:function(e){this.hls&&(this.hls.detachMedia(),this.hls=void 0),this.enableLiveSeek(e,this.subscriberId,this.hlsElement),this.seekTo(1);try{this.media.play()}catch(e){v("RTCSeekableSourceHandler","[videoelement:action] play (FAULT) - "+e.message)}}},{key:"play",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];p("RTCSeekableSourceHandler","[videoelement:action] play");var t=new S;try{var r;(r=e&&this.hlsElement&&this.hlsElement.paused?this.hlsElement.play():this.media.play())?r.then((function(){p("RTCSeekableSourceHandler","[videoelement:action] play (START)"),t.resolve()})).catch(t.reject):(p("RTCSeekableSourceHandler","[videoelement:action] play (START)"),t.resolve())}catch(e){y("RTCSeekableSourceHandler","[videoelement:action] play (FAULT) - "+e.message),t.reject(e)}return t.promise}},{key:"pause",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];p("RTCSeekableSourceHandler","[videoelement:action] pause");try{e&&t&&this.hlsElement?(this.hlsElement.pause(),this.media.pause()):e&&!this.hlsElement.paused&&this.hlsElement?this.hlsElement.pause():this.media.pause()}catch(e){v("RTCSeekableSourceHandler","[videoelement:action] pause (CATCH::FAULT) - "+e.message)}}},{key:"resume",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];p("RTCSeekableSourceHandler","[videoelement:action] resume");try{var t=this.isHLSPlaybackActive&&this.hlsElement?this.hlsElement.play():this.media.play();e&&this.isHLSPlaybackActive&&this.media.play().catch((function(e){return v("RTCSeekableSourceHandler","[videoelement:action] play (CATCH::FAULT) "+(e.message?e.message:e))})),t&&t.then((function(){return p("RTCSeekableSourceHandler","[videoelement:action] play (START)")})).catch((function(e){return v("RTCSeekableSourceHandler","[videoelement:action] play (CATCH::FAULT) "+(e.message?e.message:e))}))}catch(e){v("RTCSeekableSourceHandler","[videoelement:action] resume (CATCH::FAULT) - "+e.message)}}},{key:"stop",value:function(){p("RTCSeekableSourceHandler","[videoelement:action] stop");try{this.hlsElement&&this.hlsElement.stop(),this.media.stop()}catch(e){}}},{key:"mute",value:function(){this.hlsElement&&(this.hlsElement.muted=this.isHLSPlaybackActive),this.media.muted=!0;var e=this.getControls();e&&e.setMutedState(!0)}},{key:"unmute",value:function(){this.hlsElement?(this.hlsElement.muted=!this.isHLSPlaybackActive,this.media.muted=this.isHLSPlaybackActive):this.media.muted=!1;var e=this.getControls();e&&e.setMutedState(!1)}},{key:"setVolume",value:function(e){this.unmute(),this.hlsElement&&this.isHLSPlaybackActive?this.hlsElement.volume=e:this.media.volume=e}},{key:"seekTo",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;if(this.isSeekable)if(this._controls&&this._controls.setSeekTime(e,t),this.trigger(new Zt(xt.SEEK_CHANGE,void 0,{seek:e,duration:t})),this.hlsElement&&e<1)try{this.hlsElement.classList.remove("hidden"),this.hlsElement.currentTime=this.hlsElement.duration*e,this._isFragLoading=!0,this._showHLSLivePlayback(!0,this.hlsElement,this.media,this.holder),this.media.paused||(p("RTCSeekableSourceHandler","[hlsvod:action] play (START) - (seekTo)"),this.play(!0))}catch(e){v("RTCSeekableSourceHandler","[hlsvod:action] play (CATCH::FAULT) - "+e.message)}else this.hlsElement&&e>=1&&(this._isFragLoading=!1,this._showHLSLivePlayback(!1,this.hlsElement,this.media,this.holder));else this.media.currentTime=t?e*t:e}},{key:"toggleFullScreen",value:function(){try{this.holder&&me.toggleFullScreen(this.holder)}catch(e){throw e}}},{key:"unpublish",value:function(){if(this._pendingUnpublish||!this.isHLSPlaybackActive)try{this.stop(),this.media.onended.call(this.media)}catch(e){}finally{this._pendingUnpublish=!1}else this._pendingUnpublish=!0}},{key:"disconnect",value:function(){this._cleanUp()}},{key:"handleOrientationChange",value:function(e){this._controls&&e%180!=0&&(this.holder&&this.holder.classList.add("red5pro-media-background"),this.media.classList.remove("red5pro-media-background"))}},{key:"getControls",value:function(){return this._controls}},{key:"getType",value:function(){return this.playerType}},{key:"isVOD",get:function(){return!1},set:function(e){}},{key:"isSeekable",get:function(){return this._isSeekable},set:function(e){this._isSeekable=e,this._controls&&this._controls.setAsVOD(e)}},{key:"isHLSPlaybackActive",get:function(){return this._isHLSPlaybackActive}}])&&Qr(t.prototype,r),n&&Qr(t,n),Object.defineProperty(t,"prototype",{writable:!1}),a}(xr);function on(e){return(on="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function an(e,t){for(var r=0;r0;)r.post(r._pendingPostRequests.shift());r._responder&&r._responder.onSocketOpen&&r._responder.onSocketOpen(),r.trigger(new er(Ut.OPEN,r._name,{socket:r}))}else 0===e.readyState?++r._readyCheckCount>r._readyCheckLimit?(v(r._name,"WebSocket connection issue. We have waited for ".concat(r._readyCheckCount-1," samples, without any connection.")),r.clearRetry(),t.reject({type:"Timeout"}),r.tearDown()):(h(r._name,"WebSocket connection is still opening, will let it continue (".concat(r._readyCheckCount,")...")),r._onopenTimeout=r._resetOnopenTimeout(e,t)):h(r._name,"WebSocket connection attempts have ended with state (".concat(e.readyState,")."))}),500);return n}},{key:"_removeSocketHandlers",value:function(e){e&&(e.onopen=void 0,e.onmessage=void 0,e.onerror=void 0,e.onclose=void 0)}},{key:"_addSocketHandlers",value:function(e,t){var r=this;this._openState=0,this._readyCheckCount=0,clearTimeout(this._onopenTimeout),this._onopenTimeout=this._resetOnopenTimeout(e,t),e.onerror=function(e){v(r._name,"[websocketerror]: Error from WebSocket. ".concat(e.type,".")),r.clearRetry(),t.reject(e),r.trigger(new er(Ut.ERROR,r._name,{socket:r,error:e}))},e.onmessage=function(e){r.respond(e)},e.onclose=function(t){t.code>1e3?v(r._name,"[websocketclose]: ".concat(t.code)):p(r._name,"[websocketclose]: ".concat(t.code)),r._responder&&r._responder.onSocketClose&&r._responder.onSocketClose(t),r.clearRetry(),r._removeSocketHandlers(e||r._websocket),r._openState=0,r.trigger(new er(Ut.CLOSE,r._name,{socket:r,event:t}))}}},{key:"_onUnexpectedSocketError",value:function(e){this._responder&&this._responder.onSocketClose&&this._responder.onSocketClose(e),this.trigger(new er(Ut.CLOSE,this._name,{socket:this})),v(this._name,"[websocketerror]: Possible Unexpected Error from WebSocket. ".concat(e.type,", ").concat(e.detail)),this.clearRetry(),this._removeSocketHandlers(this._websocket)}},{key:"clearRetry",value:function(){this._retryCount=0,this._readyCheckCount=0,clearTimeout(this._onopenTimeout)}},{key:"setUp",value:function(e,t){var r=this,n=me.getIsMoz()||me.getIsEdge();if(p(this._name,"[websocket:setup] ".concat(e,".")),this.tearDown(),this._isTerminated=!1,this._connectionPromise=t,me.addCloseHandler(this._onclose),this._websocket=function(e){return me.createWebSocket(e)}(e),this._addSocketHandlers(this._websocket,this._connectionPromise),n&&this._retryCount++>"),p(this._name,"[WebSocket(".concat(this._websocket.url,")] close() >>"));try{this._websocket.close()}catch(e){v(this._name,"Attempt to close WebSocket failed: ".concat(e.message,".")),this._removeSocketHandlers(this._websocket)}finally{this._websocket&&p(this._name,"<< [WebSocket(".concat(this._websocket.url,")] close()"))}p(this._name,"<< [teardown]")}for(this._websocket=void 0,this._isTerminated=!0,this._openState=0;this._responseHandlers.length>0;)this._responseHandlers.shift();me.removeCloseHandler(this._onclose)}},{key:"postEndOfCandidates",value:function(e){this.post({handleCandidate:e,data:{candidate:{type:"candidate",candidate:""}}})}},{key:"post",value:function(e){if(void 0===this._websocket||1!==this._openState)return(void 0===this._websocket||2!==this._websocket.readyState&&3!==this._websocket.readyState)&&!this._isTerminated&&(this._pendingPostRequests.push(e),!0);try{return p(this._name,"[websocket-post]: "+JSON.stringify(e,null,2)),this._websocket.send(JSON.stringify(e)),!0}catch(t){return p(this._name,"Could not send request: ".concat(e,". ").concat(t)),!1}}},{key:"respond",value:function(e){var t=this.handleMessageResponse(e);if(!t&&e.data){var r=this.getJsonFromSocketMessage(e);if(null===r)return v(this._name,"Determined websocket response not in correct format. Aborting message handle."),!0;if(p(this._name,"[websocket-response]: "+JSON.stringify(r,null,2)),void 0!==r.isAvailable)return"boolean"==typeof r.isAvailable&&r.isAvailable?(this._responder&&this._responder.onStreamAvailable(r),!0):(this._responder&&this._responder.onStreamUnavailable(r),!0);if(r.async&&r.id){var n=this._asyncTickets.find((function(e){return e.id===r.id})).promise;n&&r.data?n.resolve(r.data):n&&r.error&&n.reject(r.error)}else if(void 0!==r.data){var o=r.data;if(void 0!==o.message){if("error"===o.type&&this._responder)return this._responder.onSocketMessageError(o.message,o.detail),!0}else if("status"===o.type){if("NetConnection.Connect.Success"===o.code)return this._websocket.onerror=this._onUnexpectedSocketError.bind(this),this._connectionPromise.resolve(this),!0;if("NetConnection.DataChannel.Available"===o.code)return this._responder.onDataChannelAvailable(o.description),!0;if("NetConnection.Connect.Rejected"===o.code)return this._connectionPromise.reject("NetConnection.Connect.Rejected"),!0;"Application.Statistics.Endpoint"===o.code&&this._responder.onStatisticsEndpoint&&this._responder.onStatisticsEndpoint(o.statistics)}else if("error"===o.type){if("NetConnection.Connect.Rejected"===o.code)return this._connectionPromise.reject("NetConnection.Connect.Rejected"),!0;if("NetConnection.Connect.Failed"===o.code)return this._connectionPromise.reject("NetConnection.Connect.Failed"),!0}}}return t}},{key:"isTerminated",get:function(){return this._isTerminated}}])&&hn(t.prototype,r),n&&hn(t,n),Object.defineProperty(t,"prototype",{writable:!1}),i}(fn);function _n(e){return(_n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function wn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function Sn(e){for(var t=1;t1&&void 0!==arguments[1]?arguments[1]:void 0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this.tearDown();var n=t||new S;try{var o={iceServers:e,iceCandidatePoolSize:2,bundlePolicy:"max-bundle"};void 0!==r&&(o.rtcpMuxPolicy=r),p("R5ProWebRTCPeer","[peerconnection:setup]: ".concat(JSON.stringify(o,null,2)));var i=new Tt(o,{optional:[{RtpDataChannels:!1},{googCpuOveruseDetection:!0}]});this._addConnectionHandlers(i),this._peerConnection=i,n.resolve(i)}catch(e){v("R5ProWebRTCPeer","Could not establish a PeerConnection. ".concat(e.message)),n.reject(e.message)}return n.hasOwnProperty("promise")?n.promise:n}},{key:"setUpWithPeerConfiguration",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this.tearDown();var n=r||new S;try{p("R5ProWebRTCPeer","[peerconnection:setUpWithPeerConfiguration]: ".concat(JSON.stringify(e,null,2)));var o=new Tt(e);t&&(this._dataChannel=o.createDataChannel(t.name,{ordered:!0}),this._addDataChannelHandlers(this._dataChannel)),this._addConnectionHandlers(o),this._peerConnection=o,n.resolve(o)}catch(e){v("R5ProWebRTCPeer","Could not establish a PeerConnection. ".concat(e.message)),n.reject(e.message)}return n.hasOwnProperty("promise")?n.promise:n}},{key:"tearDown",value:function(){if(this._dataChannel){this._removeDataChannelHandlers(this._dataChannel);try{this._dataChannel.close()}catch(e){v("R5ProWebRTCPeer","[datachannel.close] error: ".concat(e.message))}finally{this._dataChannel=void 0}}if(this._peerConnection){p("R5ProWebRTCPeer","[teardown]"),this._removeConnectionHandlers(this._peerConnection);try{this._peerConnection.close()}catch(e){v("R5ProWebRTCPeer","[peerconnection.close] error: ".concat(e.message))}finally{this._peerConnection=void 0}}}},{key:"setLocalDescription",value:function(e){return p("R5ProWebRTCPeer","[setlocaldescription]"),this._peerConnection.setLocalDescription(e)}},{key:"setRemoteDescription",value:function(e){return p("R5ProWebRTCPeer","[setremotedescription]"),this._peerConnection.setRemoteDescription(new At(e))}},{key:"addIceCandidate",value:function(e){return p("R5ProWebRTCPeer","[addcandidate]"),this._peerConnection.addIceCandidate(e)}},{key:"post",value:function(e){if(this._dataChannel){var t="string"==typeof e?e:JSON.stringify(e,null,2);p("R5ProWebRTCPeer","[datachannel.send] message: ".concat(t));try{return this._dataChannel.send(t),!0}catch(e){y("R5ProWebRTCPeer",e.hasOwnProperty("message")?e.message:e)}}return!1}},{key:"connection",get:function(){return this._peerConnection}},{key:"dataChannel",get:function(){return this._dataChannel}}])&&Dn(t.prototype,r),n&&Dn(t,n),Object.defineProperty(t,"prototype",{writable:!1}),i}(fn);function Yn(e){return(Yn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function zn(e,t){for(var r=0;r0&&void 0===n._pendingMediaStream&&(n._pendingMediaStream=e.streams[0],n._responder.onAnswerMediaStream(e.streams[0]))},e.oniceconnectionstatechange=function(t){var o=e.iceConnectionState;p("R5ProSubscriptionPeer","[peer.oniceconnectionstatechange] - State: ".concat(o)),"connected"===o&&me.getIsEdge()?(p("R5ProSubscriptionPeer","[edge/ortc:notify complete]"),n._responder.onPeerGatheringComplete(),e.onicecandidate({candidate:null})):"failed"===o?(r&&clearTimeout(r),n._responder.onPeerConnectionFail(),n._responder.onPeerConnectionClose(t)):"disconnected"===o?r=setTimeout((function(){p("R5ProSubscriptionPeer","[peer.oniceconnectionstatechange] - Reconnect timeout reached. Closing PeerConnection."),clearTimeout(r),n._responder.onPeerConnectionClose(t)}),5e3):r&&(p("R5ProSubscriptionPeer","[peer.oniceconnectionstatechange] - Clearing timeout for reconnect."),clearTimeout(r))},e.onicegatheringstatechange=function(){var t=e.iceGatheringState;p("R5ProSubscriptionPeer","[peer.onicegatheringstatechange] - State: ".concat(t)),"complete"===t&&n._responder.onPeerGatheringComplete()},e.onremovestream=function(){p("R5ProSubscriptionPeer","[peer.onremovestream]")}}},{key:"_onDataChannelMessage",value:function(e){var t=e;if(Kn($n(i.prototype),"_onDataChannelMessage",this).call(this,e))return!0;var r=this.getJsonFromSocketMessage(t);if(null===r)return v(this._name,"Determined websocket response not in correct format. Aborting message handle."),!0;p(this._name,"[datachannel-response]: "+JSON.stringify(r,null,2));var n=r.data;if(n&&"status"===n.type)return"NetStream.Play.UnpublishNotify"===n.code?(this._responder.onUnpublish(),this._responder.onConnectionClosed(),!0):(p("R5ProSubscriptionPeer","[datachannel.message] status :: ".concat(n.code)),this._responder.onSubscriberStatus(n),!0);if(n&&n.status&&"NetStream.Play.UnpublishNotify"===n.status)return this._responder.onUnpublish(),this._responder.onConnectionClosed(),!0;if(n&&"result"===n.type&&"Stream switch: Success"===n.message)try{return this._responder.onStreamSwitchComplete(),!0}catch(e){}return this._responder.onDataChannelMessage(this._dataChannel,t),!1}},{key:"createAnswer",value:function(e){var t=this;p("R5ProSubscriptionPeer","[createanswer]");var r=new S;return this._peerConnection.setRemoteDescription(e).then(this._responder.onSDPSuccess).catch((function(e){t._responder.onSDPError(e)})),this._peerConnection.createAnswer().then((function(e){e.sdp=gt(e.sdp),t._peerConnection.setLocalDescription(e).then(t._responder.onSDPSuccess).catch((function(e){t._responder.onSDPError(e)})),r.resolve(e)})).catch(r.reject),r.promise}},{key:"addIceCandidate",value:function(e){if(p("R5ProSubscriptionPeer","checking if empty..."),function(e){return void 0===e||"string"==typeof e&&0===e.length}(e))p("R5ProSubscriptionPeer","[addicecandidate]:: empty");else if(null!==e){p("R5ProSubscriptionPeer","[addicecandidate] :: non-empty");var t=new Rt({sdpMLineIndex:e.sdpMLineIndex,candidate:e.candidate});this._peerConnection.addIceCandidate(t).then((function(){})).catch((function(e){y("R5ProSubscriptionPeer","Error in add of ICE Candidiate + ".concat(e))}))}else p("R5ProSubscriptionPeer","[addicecandidate] :: null"),this._peerConnection.addIceCandidate(e).then((function(){})).catch((function(e){y("R5ProSubscriptionPeer","Error in add of ICE Candidiate + ".concat(e))}))}}])&&zn(t.prototype,r),n&&zn(t,n),Object.defineProperty(t,"prototype",{writable:!1}),i}(Wn);function eo(e){return(eo="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function to(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function ro(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:"red5pro-subscriber";to(this,e);try{this._targetElement=me.resolveElement(t)}catch(e){throw y("R5ProPlaybackView","Could not instantiate a new instance of Red5ProSubscriber. Reason: ".concat(e.message)),e}}var t,r,n;return t=e,(r=[{key:"attachSubscriber",value:function(e){p("R5ProPlaybackView","[attachsubscriber]"),e.setView(this,me.getElementId(this._targetElement))}},{key:"attachStream",value:function(e){var t=this.isAutoplay;p("R5ProPlaybackView","[attachstream]"),me.setVideoSource(this._targetElement,e,t)}},{key:"detachStream",value:function(){p("R5ProPlaybackView","[detachstream]"),me.setVideoSource(this._targetElement,null,this.isAutoplay)}},{key:"isAutoplay",get:function(){return me.hasAttributeDefined(this._targetElement,"autoplay")}},{key:"view",get:function(){return this._targetElement}}])&&ro(t.prototype,r),n&&ro(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}(),oo=function(e){switch(e){case 8083:case"8083":return console.warn("The default WebSocket port on the server has changed from 8083 to 443 for secure connections."),443;case 8081:case"8081":return console.warn("The default WebSocket port on the server has changed from 8081 to 5080 or 80 for secure connections."),5080}return e},io=function(e){var t={};return Object.keys(e).forEach((function(r,n){t[r]=encodeURIComponent(e[r])})),t},ao=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=e.wsprotocol||e.protocol,n=oo(e.wsport||e.port),o=e.context?[e.app,e.context].join("/"):e.app,i=e.endpoint?e.endpoint:"".concat(r,"://").concat(e.host,":").concat(n,"/").concat(o,"/");if(void 0!==e.connectionParams){var a=io(e.connectionParams);t=Object.assign(t,a)}if(void 0!==t){var s=[];Object.keys(t).forEach((function(e,r){s.push([e,t[e]].join("="))})),s.length>0&&(i+="?"+s.join("&"))}return i},so=function(e){var t=e.host,r=e.hlsprotocol,n=e.protocol,o=e.hlsport,i=e.port,a=e.context,s=e.app,c=e.streamName,u=e.connectionParams,l=e.apiVersion,f=t,d=r||("ws"===n?"http":"https"),h=o||(5080===i?5080:443),p=a?[s,a].join("/"):s,v=l||"4.0";return u&&"streammanager"===s?"".concat(d,"://").concat(f,":").concat(h,"/streammanager/api/").concat(v,"/file/").concat(u.app,"/").concat(c,".m3u8"):"".concat(d,"://").concat(f,":").concat(h,"/").concat(p,"/").concat(c,".m3u8")},co=function(e){var t,r,n=new URL(e),o=n.pathname.split("/").filter((function(e){return e.length>0}));return r=n.protocol,t=n.hostname,{protocol:r,port:n.port.length>0?n.port:443,app:o[0],host:t,streamName:o[o.length-1]}},uo=function(e,t,r){var n=e.host,o=e.hlsprotocol,i=e.protocol,a=e.hlsport,s=e.port,c=e.context,u=e.app,l=e.streamName,f=n,d=o||("ws"===i?"http":"https"),h=a||(5080===s?5080:443),p=c?[u,c].join("/"):u;if(r)return r;if(t){var v=t.length-1,y="/"===t.charAt(v)?t.substr(0,v):t;return"".concat(y,"/").concat(p,"/").concat(l,".m3u8")}return"".concat(d,"://").concat(f,":").concat(h,"/").concat(p,"/").concat(l,".m3u8")},lo=Object.freeze({RTC:"rtc",RTMP:"rtmp",HLS:"hls"}),fo=Object.freeze({OPUS:"Opus",PCMU:"PCMU",PCMA:"PCMA",SPEEX:"Speex",NONE:"NONE"}),ho=Object.freeze({VP8:"VP8",H264:"H264",NONE:"NONE"}),po=Object.freeze({UDP:"udp",TCP:"tcp"}),vo=Object.freeze({ENCODED_FRAME:"EncodedFrame",PACKET:"Packet"}),yo=Object.freeze({VIDEO:"encodeVideo",AUDIO:"encodeAudio"}),mo=Object.freeze({VIDEO:"decodeVideo",AUDIO:"decodeAudio"});function bo(e){return(bo="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function go(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */go=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function u(e,t,r,o){var i=t&&t.prototype instanceof d?t:d,a=Object.create(i.prototype),s=new O(o||[]);return n(a,"_invoke",{value:w(e,r,s)}),a}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var f={};function d(){}function h(){}function p(){}var v={};c(v,i,(function(){return this}));var y=Object.getPrototypeOf,m=y&&y(y(k([])));m&&m!==t&&r.call(m,i)&&(v=m);var b=p.prototype=d.prototype=Object.create(v);function g(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function _(e,t){var o;n(this,"_invoke",{value:function(n,i){function a(){return new t((function(o,a){!function n(o,i,a,s){var c=l(e[o],e,i);if("throw"!==c.type){var u=c.arg,f=u.value;return f&&"object"==bo(f)&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,a,s)}),(function(e){n("throw",e,a,s)})):t.resolve(f).then((function(e){u.value=e,a(u)}),(function(e){return n("throw",e,a,s)}))}s(c.arg)}(n,i,o,a)}))}return o=o?o.then(a,a):a()}})}function w(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return P()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var s=S(a,r);if(s){if(s===f)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=l(e,t,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===f)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function S(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,S(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),f;var o=l(n,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,f;var i=o.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,f):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,f)}function E(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 C(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function O(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(E,this),this.reset(!0)}function k(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 n=-1,o=function t(){for(;++n=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),C(r),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;C(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:k(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},e}function _o(e,t,r,n,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}function wo(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){_o(i,n,o,a,s,"next",e)}function s(e){_o(i,n,o,a,s,"throw",e)}a(void 0)}))}}var So=function(e){p("MediaTransformPipeline",e)},Eo=function(){var e=wo(go().mark((function e(t,r,n){var o,i,a,s,c,u,l;return go().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=t.video,i=t.worker,a=t.workerOperationType,s=t.transformFrameType,c=t.pipeOptions,u=s||vo.BUFFER,l=a||yo.VIDEO,!o){e.next=12;break}if(So("[track.insertablestream]::video"),u!==vo.PACKET){e.next=9;break}return e.abrupt("return",Qe(n.getVideoTracks()[0],o,c));case 9:return e.abrupt("return",$e(r,o,c));case 10:e.next=19;break;case 12:if(!i||!i.video){e.next=19;break}if(So("[track.insertablestream]::worker(encode video)"),u!==vo.PACKET){e.next=18;break}return e.abrupt("return",Je(l,n.getVideoTracks()[0],i.video,c));case 18:return e.abrupt("return",qe(l,r,i.video,c));case 19:case"end":return e.stop()}}),e)})));return function(t,r,n){return e.apply(this,arguments)}}(),Co=function(){var e=wo(go().mark((function e(t,r,n){var o,i,a,s,c,u,l;return go().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=t.video,i=t.worker,a=t.workerOperationType,s=t.transformFrameType,c=t.pipeOptions,u=s||vo.BUFFER,l=a||mo.VIDEO,!o){e.next=12;break}if(So("[track.insertablestream]::video"),u!==vo.PACKET){e.next=9;break}return e.abrupt("return",Qe(n,o,c));case 9:return e.abrupt("return",Ze(r,o,c));case 10:e.next=19;break;case 12:if(!i||!i.video){e.next=19;break}if(So("[track.insertablestream]::worker(decode video)"),u!==vo.PACKET){e.next=18;break}return e.abrupt("return",Je(l,n,i.video,c));case 18:return e.abrupt("return",Xe(l,r,i.video,c));case 19:case"end":return e.stop()}}),e)})));return function(t,r,n){return e.apply(this,arguments)}}(),Oo=function(){var e=wo(go().mark((function e(t,r,n){var o,i,a,s,c,u,l;return go().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=t.audio,i=t.worker,a=t.workerOperationType,s=t.transformFrameType,c=t.pipeOptions,u=s||vo.BUFFER,l=a||yo.AUDIO,!o){e.next=12;break}if(So("[track.insertablestream]::audio"),u!==vo.PACKET||!ze){e.next=9;break}return e.abrupt("return",Qe(n.getAudioTracks()[0],o,c));case 9:return e.abrupt("return",$e(r,o,c));case 10:e.next=19;break;case 12:if(!i||!i.audio){e.next=19;break}if(So("[track.insertablestream]::worker(encode audio)"),u!==vo.PACKET||!ze){e.next=18;break}return e.abrupt("return",Je(l,n.getAudioTracks()[0],i.audio,c));case 18:return e.abrupt("return",qe(l,r,i.audio,c));case 19:case"end":return e.stop()}}),e)})));return function(t,r,n){return e.apply(this,arguments)}}(),ko=function(){var e=wo(go().mark((function e(t,r,n){var o,i,a,s,c,u,l;return go().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=t.audio,i=t.worker,a=t.workerOperationType,s=t.transformFrameType,c=t.pipeOptions,u=s||vo.BUFFER,l=a||mo.AUDIO,!o){e.next=12;break}if(So("[track.insertablestream]::audio"),u!==vo.PACKET){e.next=9;break}return e.abrupt("return",Qe(n,o,c));case 9:return e.abrupt("return",Ze(r,o,c));case 10:e.next=19;break;case 12:if(!i||!i.audio){e.next=19;break}if(So("[track.insertablestream]::worker(decode audio)"),u!==vo.PACKET){e.next=18;break}return e.abrupt("return",Je(l,n,i.audio,c));case 18:return e.abrupt("return",Xe(l,r,i.audio,c));case 19:case"end":return e.stop()}}),e)})));return function(t,r,n){return e.apply(this,arguments)}}(),Po={endpoint:void 0,protocol:"wss",port:443,app:"live",autoLayoutOrientation:!0,mediaElementId:"red5pro-subscriber",rtcConfiguration:{iceServers:[{urls:"stun:stun2.l.google.com:19302"}],iceCandidatePoolSize:2,bundlePolicy:"max-bundle"},iceServers:void 0,iceTransport:po.UDP,muteOnAutoplayRestriction:!0,maintainConnectionOnSubscribeErrors:!1,signalingSocketOnly:!0,dataChannelConfiguration:void 0,socketSwitchDelay:1e3,bypassAvailable:!1,maintainStreamVariant:!1,buffer:0,liveSeek:{enabled:!1,baseURL:void 0,fullURL:void 0,hlsjsRef:void 0,hlsElement:void 0,usePlaybackControlsUI:!0,options:{debug:!1,backBufferLength:0}},stats:void 0},To=Object.freeze({INBOUND:"inbound-rtp",OUTBOUND:"outbound-rtp",CODEC:"codec",MEDIA_SOURCE:"media-source",CANDIDATE_PAIR:"candidate-pair",CERTIFICATE:"certificate",DATA_CHANNEL:"data-channel",LOCAL_CANDIDATE:"local-candidate",REMOTE_CANDIDATE:"remote-candidate",PEER_CONNECTION:"peer-connection",REMOTE_INBOUND:"remote-inbound-rtp",REMOTE_OUTBOUND:"remote-outbound-rtp",TRANSPORT:"transport"}),Ro={endpoint:void 0,additionalHeaders:void 0,interval:5e3,include:[]};function Ao(e){return(Ao="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Lo(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */Lo=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function u(e,t,r,o){var i=t&&t.prototype instanceof d?t:d,a=Object.create(i.prototype),s=new O(o||[]);return n(a,"_invoke",{value:w(e,r,s)}),a}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var f={};function d(){}function h(){}function p(){}var v={};c(v,i,(function(){return this}));var y=Object.getPrototypeOf,m=y&&y(y(k([])));m&&m!==t&&r.call(m,i)&&(v=m);var b=p.prototype=d.prototype=Object.create(v);function g(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function _(e,t){var o;n(this,"_invoke",{value:function(n,i){function a(){return new t((function(o,a){!function n(o,i,a,s){var c=l(e[o],e,i);if("throw"!==c.type){var u=c.arg,f=u.value;return f&&"object"==Ao(f)&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,a,s)}),(function(e){n("throw",e,a,s)})):t.resolve(f).then((function(e){u.value=e,a(u)}),(function(e){return n("throw",e,a,s)}))}s(c.arg)}(n,i,o,a)}))}return o=o?o.then(a,a):a()}})}function w(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return P()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var s=S(a,r);if(s){if(s===f)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=l(e,t,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===f)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function S(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,S(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),f;var o=l(n,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,f;var i=o.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,f):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,f)}function E(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 C(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function O(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(E,this),this.reset(!0)}function k(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 n=-1,o=function t(){for(;++n=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),C(r),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;C(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:k(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},e}function No(e,t,r,n,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}function jo(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){No(i,n,o,a,s,"next",e)}function s(e){No(i,n,o,a,s,"throw",e)}a(void 0)}))}}function Ho(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function Io(e){for(var t=1;t0;){var e=this.client.getMessageTransport();if(e){var t=this.queue.shift();e.post(t)}else v(this.NAME,"Failed to post stats data to message transport. Message transport is not available.")}}},{key:"_getStats",value:function(){var e=this,t=this.client,r=this.config,n=this.connection;if(n&&"connected"===n.connectionState)try{n.getStats(null).then((function(o){o.forEach((function(o){null!==r.endpoint&&e._handleStatsReport(o),t&&t.onStatsReport&&t.onStatsReport(n,o)}))})).catch((function(t){y(e.NAME,"Failed to get stats report. ".concat(t.message||t))}))}catch(e){e(this.NAME,"Failed to get stats report. ".concat(e.message||e))}}},{key:"_handleStatsReport",value:function(e){console.log("[".concat(this.NAME,"]: ").concat(JSON.stringify(e,null,2)))}},{key:"appendClientDetails",value:function(e){this.identifier.client=Io(Io({},this.identifier.client),e)}},{key:"start",value:(s=jo(Lo().mark((function e(t){var r=this;return Lo().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.startTime=(new Date).getTime(),this.stopped=!1,this.connection=t,this.postAction("started"),this._getStats(),this.interval=setInterval((function(){r.stopped||r._getStats()}),this.config.interval);case 6:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"stop",value:function(){this.stopped=!0,clearInterval(this.interval),this.postAction("ended")}},{key:"post",value:(a=jo(Lo().mark((function e(t){var r,n,o,i,a,s,c,u=this;return Lo().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=Io(Io({},this.identifier),{},{type:"stats-report",timestamp:(new Date).getTime(),data:t}),n=this.config,o=n.endpoint,i=n.additionalHeaders,a={"Content-Type":"application/json"},i&&(a=Io(Io({},a),i)),!o){e.next=17;break}return e.prev=5,e.next=8,fetch(o,{method:"POST",headers:a,body:JSON.stringify(r)});case 8:(s=e.sent).status>=200&&s.status<300?p(this.NAME,"Posted stats data to endpoint: ".concat(o,".")):y(this.NAME,"Failed to post stats data to endpoint: ".concat(o,". ").concat(s.status)),e.next=15;break;case 12:e.prev=12,e.t0=e.catch(5),e.t0(this.NAME,"Failed to post stats data to endpoint: ".concat(o,". ").concat(e.t0.message||e.t0));case 15:e.next=18;break;case 17:if(this.client&&this.client.getMessageTransport())try{(c=this.client.getMessageTransport())?c.post(r):(this.queue.push(r),this.client.on(Ut.CHANGE,(function(){u.client.off(Ut.CHANGE),u._emptyStatsReportQueue()})),v(this.NAME,"Failed to post stats data to message transport. Message transport is not available. Pushed to Queue."))}catch(e){e(this.NAME,"Failed to post stats data to message transport. ".concat(e.message||e))}case 18:case"end":return e.stop()}}),e,this,[[5,12]])}))),function(e){return a.apply(this,arguments)})},{key:"postAction",value:(i=jo((function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;return Lo().mark((function n(){return Lo().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",t.post({action:{type:e,data:r,timestamp:(new Date).getTime()}}));case 1:case"end":return n.stop()}}),n)}))()})),function(e){return i.apply(this,arguments)})},{key:"postEvent",value:(o=jo((function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;return Lo().mark((function n(){return Lo().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",t.post({event:{type:e,data:r,timestamp:(new Date).getTime()}}));case 1:case"end":return n.stop()}}),n)}))()})),function(e){return o.apply(this,arguments)})},{key:"updateEndpoint",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=this.config.endpoint;t?this.config.endpoint=e:t||r||(this.config.endpoint=e)}},{key:"dispose",value:function(){this.stop(),this.connection=null,this.client=null}}])&&xo(t.prototype,r),n&&xo(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function Uo(e){return(Uo="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Bo(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function Vo(e){for(var t=1;t-1)if(t===xt.STREAMING_MODE_CHANGE){var o=n.streamingMode,i=n.previousStreamingMode;r.postEvent(t,{data:{streamingMode:o,previousStreamingMode:i}})}else if(t===xt.PLAYBACK_STATE_CHANGE){var a=n.code,s=void 0;a===_r.AVAILABLE&&(s={timeToFirstFrameMS:(new Date).getTime()-r.startTime}),r.postEvent(wr[a],s)}else{if(t===xt.STATISTICS_ENDPOINT_CHANGE){var c=n.statisticsEndpoint;r.updateEndpoint(c,!1)}r.postEvent(t)}})),t.on(Mt.HOST_ENDPOINT_CHANGED,(function(e){var t=e.data,n=t.endpoint,o=t.iceServers;r.appendClientDetails({node:n,iceServers:o})})),t.getPeerConnection()?r.start(r.client.getPeerConnection()):t.on(Mt.PEER_CONNECTION_AVAILABLE,(function(e){var t=e.data;r.start(t)})),r}return t=i,(r=[{key:"_handleStatsReport",value:function(e){var t=e.type,r=this.config.include,n=r&&r.length>0;if(n&&r.indexOf(t)>=-1)this.post(e);else if(!n)if(t===To.CODEC){var o=e.id,i=e.clockRate,a=e.mimeType,s=e.payloadType;this.post({id:o,type:t,clockRate:i,mimeType:a,payloadType:s})}else if(t===To.CANDIDATE_PAIR){var c=e.availableOutgoingBitrate,u=e.currentRoundTripTime,l=e.totalRoundTripTime,f=e.state;this.post({type:t,availableOutgoingBitrate:c,currentRoundTripTime:u,totalRoundTripTime:l,state:f})}else if([To.INBOUND,"inboundrtp"].indexOf(t)>-1){var d=e.timestamp,h=e.kind,p=e.codecId,v=e.jitter,y=e.packetsLost,m=e.packetsReceived,b=e.bytesReceived,g={type:t,kind:h,codecId:p,jitter:v,packetsLost:y,packetsReceived:m,bytesReceived:b};if("audio"===h){var _=e.packetsDiscarded;if(this.lastAudioReport){var w=this.lastAudioReport,S=8*(b-w.bytesReceived)/(d-w.timestamp);this.estimatedAudioBitrate=S}this.post(Vo(Vo({},g),{},{packetsDiscarded:_,estimatedBitrate:Math.floor(this.estimatedAudioBitrate)})),this.lastAudioReport=e}else if("video"===h){var E=e.firCount,C=e.frameWidth,O=e.frameHeight,k=e.framesDecoded,P=e.framesDropped,T=e.framesPerSecond,R=e.framesReceived,A=e.freezeCount,L=e.keyFramesDecoded,N=e.nackCount,j=e.pauseCount,H=e.pliCount,I=e.totalFreezesDuration,x=e.totalPausesDuration,D=Vo(Vo({},g),{},{firCount:E,frameWidth:C,frameHeight:O,framesDecoded:k,framesDropped:P,framesPerSecond:T,framesReceived:R,freezeCount:A,keyFramesDecoded:L,nackCount:N,pauseCount:j,pliCount:H,totalFreezesDuration:I,totalPausesDuration:x});if(this.lastVideoReport){var M=this.lastVideoReport,F=8*(b-M.bytesReceived)/(d-M.timestamp);this.estimatedVideoBitrate=F}this.post(Vo(Vo({},D),{},{estimatedBitrate:Math.floor(this.estimatedVideoBitrate)})),this.lastVideoReport=e}}}}])&&Go(t.prototype,r),n&&Go(t,n),Object.defineProperty(t,"prototype",{writable:!1}),i}(Fo);function Zo(e){return(Zo="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function ei(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function ti(e){for(var t=1;t=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),C(r),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;C(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:k(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},e}function oi(e,t,r,n,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}function ii(e,t){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:void 0;if(void 0===e&&void 0!==t){var r=new no(t);r.attachSubscriber(this)}}},{key:"_initHandler",value:function(e,t){e&&t&&(t.on("*",this._boundBubbleSubscriberEvents),t.addSource(e))}},{key:"_requestAvailability",value:function(e){p("RTCSubscriber","[requestavailability]"),this._socketHelper.post({isAvailable:e})}},{key:"_requestOffer",value:function(e,t,r,n,o){var i=arguments.length>5&&void 0!==arguments[5]?arguments[5]:void 0,a=arguments.length>6&&void 0!==arguments[6]?arguments[6]:void 0;p("RTCSubscriber","[requestoffer]");var s={requestOffer:e,requestId:t,transport:r,datachannel:n,doNotSwitch:o};return void 0!==i&&i!==ho.NONE?s.videoEncoding=i:me.getIsEdge(),void 0!==a&&a!==fo.NONE&&(s.audioEncoding=a),this.trigger(new Zt(Mt.OFFER_START,this)),this._socketHelper.post(s),!0}},{key:"_requestAnswer",value:function(e){var t=this;p("RTCSubscriber","[requestanswer]"),this._peerHelper.createAnswer(e).then((function(e){p("RTCSubscriber","[onanswercreated]"),p("RTCSubscriber","[> sendanswer]"),t._sendAnswer(t._options.streamName,t._options.subscriptionId,e)})).catch((function(e){t.onSDPError(e)}))}},{key:"_sendAnswer",value:function(e,t,r){p("RTCSubscriber","[sendanswer]: streamname(".concat(e,"), subscriptionid(").concat(t,")")),this.trigger(new Zt(Mt.ANSWER_START,this,r)),this._socketHelper.post({handleAnswer:e,requestId:t,data:{sdp:r}})}},{key:"_sendCandidate",value:function(e){p("RTCSubscriber","[sendcandidate]"),this.trigger(new Zt(Mt.CANDIDATE_START,this,e)),this._socketHelper.post({handleCandidate:this._options.streamName,requestId:this._options.subscriptionId,data:{candidate:e}})}},{key:"_setUpConnectionHandlers",value:function(e){var t=this;e.addEventListener("track",(function(e){p("RTCSubscriber","[peerconnection.ontrack]");var r=e.streams,n=e.track,o=e.receiver,i=e.transceiver;o.playoutDelayHint=o.jitterBufferDelayHint=t._options.buffer,t.trigger(new Zt(Mt.TRACK_ADDED,t,{streams:r,track:n,receiver:o,transceiver:i}))}))}},{key:"_setUpMediaTransform",value:(o=function(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){oi(i,n,o,a,s,"next",e)}function s(e){oi(i,n,o,a,s,"throw",e)}a(void 0)}))}}(ni().mark((function e(t,r){var n,o,i,a,s;return ni().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=2;break}return e.abrupt("return",!0);case 2:if(e.prev=2,n=r.getReceivers().find((function(e){return e.track&&"video"===e.track.kind})),o=r.getReceivers().find((function(e){return e.track&&"audio"===e.track.kind})),i=t.audio,a=t.video,s=t.worker,!n||!a&&!s){e.next=16;break}return e.prev=7,e.next=10,Co(t,n,n.track);case 10:e.sent,e.next=16;break;case 13:e.prev=13,e.t0=e.catch(7),this.trigger(new Zt(Mt.TRANSFORM_ERROR,this,{type:"video",error:e.t0}));case 16:if(!o||!i&&!s){e.next=26;break}return e.prev=17,e.next=20,ko(t,o,o.track);case 20:e.sent,e.next=26;break;case 23:e.prev=23,e.t1=e.catch(17),this.trigger(new Zt(Mt.TRANSFORM_ERROR,this,{type:"audio",error:e.t1}));case 26:return e.abrupt("return",!0);case 29:return e.prev=29,e.t2=e.catch(2),this.trigger(new Zt(Mt.TRANSFORM_ERROR,this,{error:e.t2})),e.abrupt("return",!1);case 33:case"end":return e.stop()}}),e,this,[[2,29],[7,13],[17,23]])}))),function(e,t){return o.apply(this,arguments)})},{key:"_connect",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;return p("RTCSubscriber","[connect]"),n&&e&&(v("The iceServers configuration property is considered deprecated. Please use the rtcConfiguration configuration property upon which you can assign iceServers. Reference: https://www.red5pro.com/docs/streaming/migrationguide.html"),e.iceServers=n),this._options.iceServers=e?e.iceServers:n,(void 0!==e?this._peerHelper.setUpWithPeerConfiguration(e,r,void 0):this._peerHelper.setUp(this._options.iceServers,void 0,this._options.rtcpMuxPolicy)).then((function(e){return t._setUpConnectionHandlers(e),t.trigger(new Zt(Mt.PEER_CONNECTION_AVAILABLE,t,e)),t._requestOffer(t._options.streamName,t._options.subscriptionId,t._options.iceTransport,t._options.signalingSocketOnly,t._options.maintainStreamVariant,t._options.videoEncoding,t._options.audioEncoding)})).catch((function(e){v("RTCSubscriber","Could not establish RTCPeerConnection"),t.trigger(new Zt(xt.CONNECT_FAILURE,t))})),this}},{key:"_disconnect",value:function(){this._socketHelper&&(p("RTCSubscriber","[disconnect:socket]"),this._socketHelper.tearDown()),this._peerHelper&&(p("RTCSubscriber","[disconnect:peer]"),this._peerHelper.tearDown()),this._view&&this._view.detachStream(),this._socketHelper=void 0,this._peerHelper=void 0,this._messageTransport=void 0,this._sourceHandler&&(p("RTCSubscriber","[disconnect:source]"),this._sourceHandler.disconnect(),this._sourceHandler=void 0),this._connectionClosed=!0,this.unmonitorStats()}},{key:"_manageStreamMeta",value:function(e){var t,r=e.getTracks(),n=r.find((function(e){return"audio"===e.kind})),o=r.find((function(e){return"video"===e.kind}));o&&(o.muted||(t="Video")),n&&(n.muted||(t=t?"".concat(t,"/Audio"):"Audio")),t||(t="Empty"),this.onMetaData({streamingMode:t,method:"onMetaData"})}},{key:"_addStreamHandlers",value:function(e){var t=this,r=e.getTracks(),n=r.find((function(e){return"audio"===e.kind})),o=r.find((function(e){return"video"===e.kind}));o&&(o.addEventListener("mute",(function(){t._manageStreamMeta(e)})),o.addEventListener("unmute",(function(){t._manageStreamMeta(e)}))),n&&(n.addEventListener("mute",(function(){t._manageStreamMeta(e)})),n.addEventListener("unmute",(function(){t._manageStreamMeta(e)}))),this._manageStreamMeta(e)}},{key:"_playIfAutoplaySet",value:function(e,t){e&&t&&(e.autoplay=me.hasAttributeDefined(t.view,"autoplay"),e.autoplay&&this._sourceHandler.attemptAutoplay(e.muteOnAutoplayRestriction))}},{key:"_startSeekable",value:function(e){var t=e.liveSeek,r=e.subscriptionId;if(t){var n=t.enabled,o=t.baseURL,i=t.fullURL,a=t.hlsjsRef,s=t.hlsElement;if(n)try{if(!me.supportsHLS()&&!me.supportsNonNativeHLS(a))throw new Error;var c=uo(e,o,i);this._sourceHandler.enableLiveSeek(c,r,s,!me.supportsNonNativeHLS())}catch(e){y("RTCSubscriber","Could not utilize the 'LiveSeek' request. This feature requires either native HLS playback or hls.js as a depenency.")}}}},{key:"_sendSubscribe",value:function(){p("RTCSubscriber","[sendsubscribe]"),this._socketHelper.post({subscribe:this._options.streamName,requestId:this._options.subscriptionId})}},{key:"init",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=new S,o=e.stats;if(We()&&Lt()){this._disconnect(),this._options=Object.assign({},di,e),this._options.subscriptionId=this._options.subscriptionId||Te(),this._mediaTransform=r,this._mediaTransform&&!Ke()&&(this.trigger(new Zt(Mt.UNSUPPORTED_FEATURE,this,{feature:"Insertable Streams",message:"You provided Media Transforms for track processing, but your current browser does not support the Insertable Streams API."})),this._mediaTransform=void 0),this._peerHelper=new Zn(this),this._socketHelper=new Nn(this),this._messageTransport=this._messageTransport||this._socketHelper;var i=new S,a=ao(this._options,{id:this._options.subscriptionId});o&&this.monitorStats(o),i.promise.then((function(){n.resolve(t),t._connectionClosed=!1,t.trigger(new Zt(xt.CONNECT_SUCCESS,t))})).catch((function(e){n.reject(e),t.trigger(new Zt(xt.CONNECT_FAILURE,t,e))})),this._socketHelper.setUp(a,i)}else n.reject("Cannot create WebRTC playback instance. Your environment does not support WebRTC and/or WebSockets.");return n.promise}},{key:"setView",value:function(e){return this._view=e,this._viewResolver.resolve(this._view),this}},{key:"subscribe",value:function(){var e=this,t=this._options,r=t.streamName,n=t.mediaElementId,o=t.rtcConfiguration,i=t.liveSeek,a=this._options,s=a.signalingSocketOnly,c=a.dataChannelConfiguration,u=s&&Ye();return u&&!c&&(c={name:"red5pro"}),this._options.signalingSocketOnly=u,this._getViewResolverPromise().then((function(t){if(i&&i.enabled){var r=i.hlsjsRef,n=i.usePlaybackControlsUI,o=i.options;me.supportsNonNativeHLS(r)?e._sourceHandler=new nn(t.view,e.getType(),o,n):(y("RTCSubscriber","Could not utilize the 'LiveSeek' request. This feature requires either native HLS playback or hls.js as a depenency."),e.trigger(new Zt(Mt.LIVE_SEEK_UNSUPPORTED,e,{feature:"Live Seek",message:"Live Seek requires integration with the HLS.JS plugin in order work properly. Most likely you are viewing this on a browser that does not support the use of HLS.JS."})),e._sourceHandler=new zr(t.view,e.getType()))}else e._sourceHandler=new zr(t.view,e.getType());e._glomSourceHandlerAPI(e._sourceHandler),e._initHandler(e._options,e._sourceHandler)})).catch((function(){})),this._getAvailabilityResolverPromise().then((function(){var t=o;void 0===o.encodedInsertableStreams&&(t=Object.assign(o,{encodedInsertableStreams:!!e._mediaTransform})),e._connect(t,c,e._options.iceServers)})).catch((function(){})),this._setViewIfNotExist(this._view,n),this._options.bypassAvailable?this._availabilityResolver.resolve(this):this._requestAvailability(r),this._getSubscriptionResolverPromise()}},{key:"unsubscribe",value:function(){p("RTCSubscriber","[unsubscribe]");var e=new S;return this.stop(),this._disconnect(),this._mediaStream=void 0,e.resolve(this),this.trigger(new Zt(xt.SUBSCRIBE_STOP,this)),e.promise}},{key:"monitorStats",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this._options,r=t.host,n=t.app,o=t.streamName,i=t.subscriptionId,a=t.connectionParams;return this._statisticsConfiguration=ti(ti({},e),{host:r,app:n,streamName:o,subscriptionId:i,connectionParams:a}),this._statsMonitor?v("RTCSubscriber","Cannot monitor stats without a Peer Connection. Please call `init` before calling `monitorStats`."):this._statsMonitor=new $o(this._statisticsConfiguration,this),this}},{key:"unmonitorStats",value:function(){return this._statsMonitor&&(this._statsMonitor.dispose(),this._statsMonitor=void 0),this._statisticsConfiguration=void 0,this}},{key:"transform",value:function(e){!e||Ke()?this.getPeerConnection()?this._setUpMediaTransform(e,this.getPeerConnection()):this._mediaTransform=e:this.trigger(new Zt(xt.UNSUPPORTED_FEATURE,this,{feature:"Insertable Streams",message:"You provided Media Transforms for track processing, but your current browser does not support the Insertable Streams API."}))}},{key:"onStreamAvailable",value:function(e){p("RTCSubscriber","[onstreamavailable]: "+JSON.stringify(e,null,2)),this._availabilityResolver.resolve(this)}},{key:"onStreamUnavailable",value:function(e){p("RTCSubscriber","Stream ".concat(this._options.streamName," does not exist.")),p("RTCSubscriber","[onstreamunavailable]: "+JSON.stringify(e,null,2)),this.trigger(new Zt(xt.SUBSCRIBE_INVALID_NAME,this)),this._availabilityResolver.reject("Stream ".concat(this._options.streamName," does not exist.")),this._subscriptionResolver.reject("Stream ".concat(this._options.streamName," does not exist.")),this._options.maintainConnectionOnSubscribeErrors?(this._availabilityResolver=new S,this._subscriptionResolver=new S):this._disconnect()}},{key:"onSDPSuccess",value:function(e){p("RTCSubscriber","[onsdpsuccess]: "+JSON.stringify(e,null,2))}},{key:"onSDPOffer",value:function(e){p("RTCSubscriber","[onsdpoffer]: "+JSON.stringify(e,null,2));var t=new At(e.sdp);this.trigger(new Zt(Mt.OFFER_END,this)),this._requestAnswer(t)}},{key:"onSDPError",value:function(e){this.trigger(new Zt(xt.SUBSCRIBE_FAIL,this,e)),this._subscriptionResolver.reject("Invalid SDP."),y("RTCSubscriber","[onsdperror]"),y("RTCSubscriber",e)}},{key:"onAnswerMediaStream",value:function(){this.trigger(new Zt(Mt.ANSWER_END,this))}},{key:"onIceCandidate",value:function(e){p("RTCSubscriber","[onicecandidate]"),this.trigger(new Zt(Mt.CANDIDATE_END,this)),this._sendCandidate(e)}},{key:"onIceCandidateTrickleEnd",value:function(e){var t=this;p("RTCSubscriber","[onicetrickleend]"),this._getViewResolverPromise().then((function(r){r.attachStream(e),t._mediaStream=e,t._setUpMediaTransform(t._mediaTransform,t.getPeerConnection()),t.trigger(new Zt(Mt.ON_ADD_STREAM,t,t._mediaStream))}))}},{key:"onAddIceCandidate",value:function(e){p("RTCSubscriber","[onaddicecandidate]"),this._peerHelper.addIceCandidate(e)}},{key:"onEmptyCandidate",value:function(){p("RTCSubscriber","[icecandidatetrickle:empty]"),this.trigger(new Zt(Mt.PEER_CANDIDATE_END))}},{key:"onPeerGatheringComplete",value:function(){p("RTCSubscriber","[icecandidategathering:end]"),this._socketHelper&&this._socketHelper.postEndOfCandidates(this._options.streamName)}},{key:"onSocketIceCandidateEnd",value:function(){p("RTCSubscriber","[onsocketicecandidateend]"),this.trigger(new Zt(Mt.ICE_TRICKLE_COMPLETE,this)),this._sendSubscribe()}},{key:"onSocketMessage",value:function(e,t){this.trigger(new Zt(Mt.SOCKET_MESSAGE,this,{socket:e,message:t}))}},{key:"onSocketMessageError",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;y("RTCSubscriber","Error in stream subscription: ".concat(e,".\n[Optional detail]: ").concat(t)),this._subscriptionResolver.reject("Error in stream subscription: ".concat(e,".")),this.trigger(new Zt(xt.SUBSCRIBE_FAIL,this,e))}},{key:"onSocketClose",value:function(e){p("RTCSubscriber","[onsocketclose]"),this._peerHelper&&this._peerHelper.tearDown(),this.onConnectionClosed(e)}},{key:"onPeerConnectionFail",value:function(){p("RTCSubscriber","[onpeerconnectionfail]"),this.trigger(new Zt(xt.SUBSCRIBE_FAIL,this,"fail")),this._subscriptionResolver&&this._subscriptionResolver.reject("Peer Connection Failed.")}},{key:"onPeerConnectionClose",value:function(e){p("RTCSubscriber","[onpeerconnectionclose]");var t=this._options.liveSeek;this._socketHelper&&this._socketHelper.tearDown(),t&&t.enabled||this.onSocketClose(e)}},{key:"onPeerConnectionOpen",value:function(){p("RTCSubscriber","[onpeerconnectionopen]"),this.trigger(new Zt(Mt.PEER_CONNECTION_OPEN),this,this.getPeerConnection())}},{key:"onUnpublish",value:function(){p("RTCSubscriber","[onunpublish]"),this.trigger(new Zt(xt.PLAY_UNPUBLISH,this));var e=this._options.liveSeek;this._sourceHandler&&this._sourceHandler.unpublish(),e&&e.enabled||this.unsubscribe()}},{key:"onConnectionClosed",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0,t=this._options.liveSeek;if(!this._connectionClosed){if(p("RTCSubscriber","[onconnectionclosed]"),t){var r=t.enabled;r||this._disconnect()}else this._disconnect();this.trigger(new Zt(xt.CONNECTION_CLOSED,this,e))}}},{key:"onSendReceived",value:function(e,t){"onMetaData"===e?this.onMetaData(t):"onPublisherNetworkCongestion"===e?this.onPublisherNetworkCongestion(t):"onPublisherNetworkRecovery"===e?this.onPublisherNetworkRecovery(t):this.trigger(new Zt(xt.SUBSCRIBE_SEND_INVOKE,this,{methodName:e,data:t}))}},{key:"onSubscriberStatus",value:function(e){p("RTCSubscriber","[subscriberstatus] - "+JSON.stringify(e,null,2));var t=fi.exec(e.message);t&&t[1]===this._options.streamName?(this._subscriptionResolver.resolve(this),this.trigger(new Zt(xt.SUBSCRIBE_START,this)),this._playIfAutoplaySet(this._options,this._view),this._startSeekable(this._options,this._view)):this.trigger(new Zt(xt.SUBSCRIBE_STATUS,this,e))}},{key:"onStatisticsEndpoint",value:function(e){this.trigger(new Zt(xt.STATISTICS_ENDPOINT_CHANGE,this,{statisticsEndpoint:e}))}},{key:"onDataChannelAvailable",value:function(e){var t=this;if(p("RTCSubscriber","[ondatachannel::available]"),this._switchChannelRequest={switchChannel:e||"red5pro"},this._options.signalingSocketOnly)var r=setTimeout((function(){clearTimeout(r),t._socketHelper&&t._socketHelper.sever(t._switchChannelRequest),t._messageTransport=t._peerHelper,t.trigger(new er(Ut.CHANGE,t,{controller:t,transport:t._messageTransport}))}),this._socketHelper?this._options.socketSwitchDelay:100);this.trigger(new Zt(Mt.DATA_CHANNEL_AVAILABLE,this,{name:e,dataChannel:this.getDataChannel()}))}},{key:"onDataChannelError",value:function(e,t){this.trigger(new Zt(Mt.DATA_CHANNEL_ERROR,this,{dataChannel:e,error:t}))}},{key:"onDataChannelMessage",value:function(e,t){this.trigger(new Zt(Mt.DATA_CHANNEL_MESSAGE,this,{dataChannel:e,message:t}))}},{key:"onDataChannelOpen",value:function(e){this.trigger(new Zt(Mt.DATA_CHANNEL_OPEN,this,{dataChannel:e}))}},{key:"onDataChannelClose",value:function(e){this.trigger(new Zt(Mt.DATA_CHANNEL_CLOSE,this,{dataChannel:e}))}},{key:"onMetaData",value:function(e){var t=e.orientation,r=e.streamingMode,n=this._streamingMode;void 0!==t&&t!==this._orientation&&(this._orientation=t,this._options.autoLayoutOrientation&&(Ce(this._view.view,parseInt(t,10),Ae(e.resolution)),this._sourceHandler&&this._sourceHandler.handleOrientationChange(parseInt(t,10))),this.trigger(new Zt(xt.ORIENTATION_CHANGE,this,{orientation:parseInt(t,10),viewElement:this._view.view}))),void 0!==r&&r!==n&&(this._streamingMode=r,this.trigger(new Zt(xt.STREAMING_MODE_CHANGE,this,{streamingMode:r,previousStreamingMode:n,viewElement:this._view.view}))),this.trigger(new Zt(xt.SUBSCRIBE_METADATA,this,e))}},{key:"onStreamSwitchComplete",value:function(){p("RTCSubscriber","[streamswitch::complete]");var e=this._options.liveSeek,t=this._requestedStreamSwitch;if(e&&e.enabled){var r=e.baseURL,n=e.fullURL,o=t.split("/").pop(),i=t.substr(0,t.lastIndexOf("/".concat(o))),a=ti(ti({},this._options),{},{app:i,streamName:o}),s=n;if(n){var c=/.*\/(.*)\.m3u8/.exec(n);if(c&&c.length>1){var u="".concat(c[1],".m3u8");s=n.replace(u,"".concat(o,".m3u8"))}}var l=uo(a,r,s);this._sourceHandler.switchLiveSeek(l)}this.trigger(new Zt(Mt.SUBSCRIBE_STREAM_SWITCH,this,{path:t})),this._requestedStreamSwitch=void 0}},{key:"onPublisherNetworkCongestion",value:function(e){this.trigger(new Zt(xt.SUBSCRIBE_PUBLISHER_CONGESTION,this,e))}},{key:"onPublisherNetworkRecovery",value:function(e){this.trigger(new Zt(xt.SUBSCRIBE_PUBLISHER_RECOVERY,this,e))}},{key:"onStatsReport",value:function(e,t){this.trigger(new Zt(Mt.STATS_REPORT,this,{connection:e,report:t}))}},{key:"callServer",value:function(e,t){var r="switchStreams"===e,n=this._options,o=n.app,i=n.streamName;if(r){var a=t[0].path;this._requestedStreamSwitch=a,p("RTCSubscriber","[callServer:switch]:: ".concat(e,", ").concat(o,"/").concat(i," -> ").concat(a))}return this.getMessageTransport().postAsync({callAdapter:{method:e,arguments:t}})}},{key:"sendLog",value:function(e,t){try{var r=Object.keys(l).find((function(t){return t.toLowerCase()===e.toLowerCase()}))?e:l.DEBUG,n="string"==typeof t?t:JSON.stringify(t);this.getMessageTransport().post({log:r.toUpperCase(),message:n})}catch(e){var o=e.message||e;y("RTCSubscriber","Could not send log to server. Message parameter expected to be String or JSON-serializable object."),y("RTCSubscriber",o)}}},{key:"enableStandby",value:function(){this.getMessageTransport().post({mute:{muteAudio:!0,muteVideo:!0}})}},{key:"disableStandby",value:function(){this.getMessageTransport().post({mute:{muteAudio:!1,muteVideo:!1}})}},{key:"muteAudio",value:function(){this.getMessageTransport().post({mute:{muteAudio:!0}})}},{key:"unmuteAudio",value:function(){this.getMessageTransport().post({mute:{muteAudio:!1}})}},{key:"muteVideo",value:function(){this.getMessageTransport().post({mute:{muteVideo:!0}})}},{key:"unmuteVideo",value:function(){this.getMessageTransport().post({mute:{muteVideo:!1}})}},{key:"getMessageTransport",value:function(){return this._messageTransport}},{key:"getConnection",value:function(){return this._socketHelper}},{key:"getPeerConnection",value:function(){return this._peerHelper?this._peerHelper.connection:void 0}},{key:"getDataChannel",value:function(){return this._peerHelper?this._peerHelper.dataChannel:void 0}},{key:"getMediaStream",value:function(){return this._mediaStream}},{key:"getControls",value:function(){return this._sourceHandler?this._sourceHandler.getControls():void 0}},{key:"getPlayer",value:function(){return this._view.view}},{key:"getOptions",value:function(){return this._options}},{key:"getType",value:function(){return lo.RTC.toUpperCase()}}])&&ii(t.prototype,r),n&&ii(t,n),Object.defineProperty(t,"prototype",{writable:!1}),a}(xr),pi=function(e,t){var r=new S,n=e.id;if("video"===e.nodeName.toLowerCase()){var o=me.createElement("div");o.id=n+"_rtmp",t.appendChild(o),e.parentElement&&e.parentElement.removeChild(e),r.resolve(o.id)}else r.resolve(n);return r.promise},vi=function(e,t,r,n,o){var i=new S,a={quality:"high",wmode:"opaque",bgcolor:t.backgroundColor||"#000",allowscriptaccess:"always",allowfullscreen:"true",allownetworking:"all"},s={id:e,name:e,align:"middle"};return n.hasFlashPlayerVersion(t.minFlashVersion)?n.embedSWF(t.swf,o,t.embedWidth||640,t.embedHeight||480,t.minFlashVersion,t.productInstallURL,r,a,s,(function(e){e.success?i.resolve():i.reject("Flash Object embed failed.")})):i.reject("Flash Player Version is not supported."),i.promise};function yi(e){return(yi="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function mi(e,t){for(var r=0;r2&&void 0!==arguments[2]?arguments[2]:null,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;p("RTMPSourceHandler","[addsource]"),this._swfId=e,this.holder=this._determineHolder(this.media);var i=new S,a=t.controls,s=me.hasAttributeDefined(this.media,"muted"),c=me.hasAttributeDefined(this.media,"controls")&&me.hasClassDefined(this.media,"red5pro-media");t.swf=n||t.swf,t.minFlashVersion=o||t.minFlashVersion,this._setUpInitCallback(i);var u=this.media.classList;return pi(this.media,this.holder).then((function(n){var o={stream:t.streamName,app:t.context?"".concat(t.app,"/").concat(t.context):t.app,host:t.host,muted:me.hasAttributeDefined(r.media,"muted"),autoplay:me.hasAttributeDefined(r.media,"autoplay"),useAdaptiveBitrateController:t.useAdaptiveBitrateController};return t.backgroundColor&&(o.backgroundColor=t.backgroundColor),t.buffer&&!isNaN(Number(t.buffer))&&(o.buffer=t.buffer),t.width&&!isNaN(t.width)&&(o.width=Ei(t.width)),t.height&&!isNaN(t.height)&&(o.height=Ei(t.height)),"100%"!==t.embedWidth&&"100%"!==t.embedHeight||(o.autosize=!0),r._swfId=e,void 0!==t.connectionParams&&(o.connectionParams=encodeURIComponent(JSON.stringify(t.connectionParams))),void 0!==t.abrVariants&&(o.abrVariants=encodeURIComponent(JSON.stringify(t.abrVariants))),void 0!==t.abrVariantUpgradeSettings&&(o.abrVariantUpgradeSettings=encodeURIComponent(JSON.stringify(t.abrVariantUpgradeSettings))),vi(e,t,o,me.getSwfObject(),n)})).then((function(){if(a||c){r._controls=a?t.controls:new Mr(r,r.holder),r.media.controls=!1,r._controls.setAsVOD(Ci(t.streamName)),r._controls.setMutedState(s);for(var e,n=r.getEmbeddedView(),o=u.length;--o>-1;)e=u.item(o),n.classList.add(e)}return r._addPlaybackHandlers(r._playbackNotificationCenter),r.trigger(new Zt(xt.PLAYBACK_STATE_CHANGE,void 0,{code:_r.AVAILABLE,state:wr[_r.AVAILABLE]})),!0})).then((function(){return!0})).catch((function(e){return i.reject(e)})),i.promise}},{key:"connect",value:function(){p("RTMPSourceHandler","[connect]");try{this.getEmbeddedView().connect()}catch(e){throw e}}},{key:"play",value:function(){try{this.getEmbeddedView().play()}catch(e){throw e}}},{key:"pause",value:function(){try{this.getEmbeddedView().pause()}catch(e){throw e}}},{key:"resume",value:function(){try{this.getEmbeddedView().resume()}catch(e){throw e}}},{key:"stop",value:function(){try{this.getEmbeddedView().stop()}catch(e){throw e}}},{key:"mute",value:function(){try{this.getEmbeddedView().mute()}catch(e){throw e}}},{key:"unmute",value:function(){try{this.getEmbeddedView().unmute()}catch(e){throw e}}},{key:"setVolume",value:function(e){try{this.getEmbeddedView().setVolume(e)}catch(e){throw e}}},{key:"seekTo",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;try{this.getEmbeddedView().seekTo(e,t)}catch(e){throw e}}},{key:"toggleFullScreen",value:function(){try{me.toggleFullScreen(this.holder)}catch(e){throw e}}},{key:"unpublish",value:function(){this.stop()}},{key:"disconnect",value:function(){try{this.getEmbeddedView().disconnect(),p("RTMPSourceHandler","[disconnect]")}catch(e){}this._cleanUp()}},{key:"startABRController",value:function(){try{this.getEmbeddedView().startABRController()}catch(e){p("RTMPSourceHandler","Could not start the Adaptive Bitrate Controller: ".concat(e.message))}}},{key:"stopABRController",value:function(){try{this.getEmbeddedView().stopABRController()}catch(e){p("RTMPSourceHandler","Could not stop the Adaptive Bitrate Controller: ".concat(e.message))}}},{key:"setABRVariants",value:function(e,t){try{var r="string"==typeof e?encodeURIComponent(e):encodeURIComponent(JSON.stringify(e));this.getEmbeddedView().setABRVariants(r,t||1)}catch(e){p("RTMPSourceHandler","Could not set ABR Variants: ".concat(e.message))}}},{key:"setABRLevel",value:function(e,t){try{this.getEmbeddedView().setABRLevel(e,!!t)}catch(e){p("RTMPSourceHandler","Could not set ABR level: ".concat(e.message))}}},{key:"setABRVariantUpgradeSettings",value:function(e){try{var t="string"==typeof abrVariants?encodeURIComponent(e):encodeURIComponent(JSON.stringify(e));this.getEmbeddedView().setABRVariantUpgradeSettings(t)}catch(e){p("RTMPSourceHandler","Could not set ABR Variants: ".concat(e.message))}}},{key:"getEmbeddedView",value:function(){return me.getEmbedObject(this._swfId)}},{key:"getControls",value:function(){return this._controls}},{key:"getType",value:function(){return this.playerType}}])&&mi(t.prototype,r),n&&mi(t,n),Object.defineProperty(t,"prototype",{writable:!1}),i}(xr);function ki(e){return(ki="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Pi(e,t){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:void 0;if(void 0===e&&void 0!==t){var r=new no(t);r.attachSubscriber(this)}}},{key:"_establishExtIntHandlers",value:function(e){var t=this;p("RTMPSubcriber","Subscriber ID provided to client: (".concat(e,")."));var r=function(t){return["subscriber",t,e.split("-").join("_")].join("_")};window[r("r5proConnectClosed")]=function(){return t.trigger(new Zt(xt.CONNECTION_CLOSED,t))},window[r("r5proConnectSuccess")]=function(){return t.trigger(new Zt(xt.CONNECT_SUCCESS,t))},window[r("r5proConnectFailure")]=function(){t.trigger(new Zt(xt.CONNECT_FAILURE,t))},window[r("r5proSubscribeStop")]=function(){return t.trigger(new Zt(xt.SUBSCRIBE_STOP,t))},window[r("r5proSubscribeMetadata")]=function(e){var r=JSON.parse(e),n=r.orientation,o=r.streamingMode,i=parseInt(n,10),a=t._streamingMode;t._orientation!==i&&(t._orientation=i,t.trigger(new Zt(xt.ORIENTATION_CHANGE,t,{orientation:i}))),a!==o&&(t._streamingMode=o,t.trigger(new Zt(xt.STREAMING_MODE_CHANGE,t,{streamingMode:o,previousStreamingMode:a}))),t.trigger(new Zt(xt.SUBSCRIBE_METADATA,t,JSON.parse(e)))},window[r("r5proSubscribeUnpublish")]=function(){t.onUnpublish()},window[r("r5proSubscribePublisherCongestion")]=function(e){return t.trigger(new Zt(xt.SUBSCRIBE_PUBLISHER_CONGESTION,t,JSON.parse(e)))},window[r("r5proSubscribePublisherRecovery")]=function(e){return t.trigger(new Zt(xt.SUBSCRIBE_PUBLISHER_RECOVERY,t,JSON.parse(e)))},window[r("r5proSubscribeSendInvoke")]=function(e){t.trigger(new Zt(xt.SUBSCRIBE_SEND_INVOKE,t,"string"==typeof e?JSON.parse(e):e))},window[r("r5proSubscribePlayRequest")]=function(){t.play()},window[r("r5proSubscribeStart")]=function(){t._subscriptionResolver.resolve(t),t.trigger(new Zt(xt.SUBSCRIBE_START,t))},window[r("r5proSubscribeInvalidName")]=function(){t._subscriptionResolver.reject("NetStream.Play.StreamNotFound",t),t.trigger(new Zt(xt.SUBSCRIBE_INVALID_NAME,t))},window[r("r5proSubscribeFail")]=function(){t._subscriptionResolver.reject("NetStream.Failed",t),t.trigger(new Zt(xt.SUBSCRIBE_FAIL,t))},window[r("r5proSubscribeVolumeChange")]=function(e){t.trigger(new Zt(xt.VOLUME_CHANGE,t,{volume:JSON.parse(e).volume}))},window[r("r5proSubscribePlaybackStalled")]=function(){p("RTMPSubcriber","playback has stalled...")},window[r("r5proSubscribePlaybackTimeChange")]=function(e){var r=JSON.parse(e);t.trigger(new Zt(xt.PLAYBACK_TIME_UPDATE,t,{time:r.value,duration:r.duration}))},window[r("r5proSubscribePlaybackStateChange")]=function(e){var r=JSON.parse(e).code;t.trigger(new Zt(xt.PLAYBACK_STATE_CHANGE,t,{code:r,state:wr[r]}))},window[r("r5proSubscribeABRLevelChange")]=function(e){var r=JSON.parse(e),n=r.level,o=r.stream,i=JSON.parse(decodeURIComponent(o));t.trigger(new Zt(Ft.ABR_LEVEL_CHANGE,t,{level:n,stream:i}))}}},{key:"init",value:function(e){var t=this,r=new S,n=e.minFlashVersion||Ni.minFlashVersion;if(me.supportsFlashVersion(n)){this._options=Object.assign({},Ni,e);try{me.injectScript(this._options.swfobjectURL).then((function(){var e=t._embedPromise;return p("RTMPSubcriber","SWFObject embedded."),t._sourceHandler?(t._sourceHandler.addSource(t._elementId,t._options).then((function(r){t._establishExtIntHandlers(r),e.resolve(t)})).catch((function(t){e.reject(t)})),t._getEmbedPromise()):(t._getViewResolverPromise().then((function(e){if(t._sourceHandler=new Oi(t,e.view,t.getType()),t._glomSourceHandlerAPI(t._sourceHandler),t._options){var r=t._embedPromise;t._sourceHandler.addSource(t._elementId,t._options).then((function(e){t._establishExtIntHandlers(e),r.resolve(t)})).catch((function(e){return r.reject(e)}))}})),!0)})).then((function(){t._setViewIfNotExist(t._view,t._options.mediaElementId),r.resolve(t)})).catch((function(e){y("RTMPSubcriber","Could not embed Flash-based RTMP Player. Reason: ".concat(e)),t._sourceHandler&&t._sourceHandler.disconnect(),r.reject(e),t.trigger(new Zt(Ft.EMBED_FAILURE,t))}))}catch(e){r.reject("Could not inject Flash-based Player into the page. Reason: ".concat(e.message)),this.trigger(new Zt(Ft.EMBED_FAILURE,this))}}else v("RTMPSubcriber","Could not resolve RTMPSubscriber instance. Requires minimum Flash Player install of ".concat(n,".")),r.reject("Could not resolve RTMPSubscriber instance. Requires minimum Flash Player install of ".concat(n,"."));return r.promise}},{key:"setView",value:function(e,t){return this._view=e,this._elementId=t,this._viewResolver.resolve(this._view),this}},{key:"subscribe",value:function(){return this._getSubscriptionResolverPromise()}},{key:"unsubscribe",value:function(){var e=this;return p("RTMPSubcriber","[unsubscribe]"),new Promise((function(t,r){try{e._sourceHandler.disconnect(),t()}catch(e){r(e.message)}}))}},{key:"play",value:function(){var e=this;p("RTMPSubcriber","[play]"),this._getEmbedPromise().then((function(){e._sourceHandler.play()}))}},{key:"onEmbedComplete",value:function(){p("RTMPSubcriber","[embed:complete]"),this.trigger(new Zt(Ft.EMBED_SUCCESS,this))}},{key:"onEmbedFailure",value:function(e){p("RTMPSubcriber","[embed:failure] - ".concat(e)),this.trigger(new Zt(Ft.EMBED_FAILURE,this))}},{key:"onUnpublish",value:function(){p("RTMPSubcriber","[onunpublish]"),this._sourceHandler&&this._sourceHandler.unpublish(),this.trigger(new Zt(xt.PLAY_UNPUBLISH,this)),this._sourceHandler&&this._sourceHandler.disconnect()}},{key:"getConnection",value:function(){return this._sourceHandler}},{key:"getControls",value:function(){return this._sourceHandler?this._sourceHandler.getControls():void 0}},{key:"getOptions",value:function(){return this._options}},{key:"getPlayer",value:function(){return this._sourceHandler?this._sourceHandler.getEmbeddedView():void 0}},{key:"getType",value:function(){return lo.RTMP.toUpperCase()}}])&&Pi(t.prototype,r),n&&Pi(t,n),Object.defineProperty(t,"prototype",{writable:!1}),i}(xr);function Hi(e){return(Hi="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Ii(e,t){for(var r=0;r0&&void 0!==arguments[0]&&arguments[0];this.play().catch((function(r){t?(e.mute(),e.play().then((function(){e.trigger(new Zt(xt.AUTO_PLAYBACK_MUTED,void 0,{element:e.media}))})).catch((function(t){e.trigger(new Zt(xt.AUTO_PLAYBACK_FAILURE,void 0,{error:t.message?t.message:t,element:e.media}))}))):e.trigger(new Zt(xt.AUTO_PLAYBACK_FAILURE,void 0,{error:r.message?r.message:r,element:e.media}))}))}},{key:"play",value:function(){p("HLSSourceHandler","[videoelement:action] play");var e=new S;try{var t=this.media.play();t?t.then((function(){p("HLSSourceHandler","[videoelement:action] play (START)"),e.resolve()})).catch(e.reject):(p("HLSSourceHandler","[videoelement:action] play (START)"),e.resolve())}catch(t){y("HLSSourceHandler","[videoelement:action] play (FAULT) - "+t.message),e.reject(t)}return e.promise}},{key:"pause",value:function(){p("HLSSourceHandler","[videoelement:action] pause");try{this.media.pause()}catch(e){p("HLSSourceHandler","[videoelement:action] pause (FAULT) - "+e.message)}}},{key:"resume",value:function(){p("HLSSourceHandler","[videoelement:action] resume");try{var e=this.media.play();e&&e.then((function(){return p("HLSSourceHandler","[videoelement:action] play (START)")})).catch((function(e){return y("HLSSourceHandler","[videoelement:action] play (FAULT) "+(e.message?e.message:e))}))}catch(e){y("HLSSourceHandler","[videoelement:action] resume (FAULT) - "+e.message)}}},{key:"stop",value:function(){try{this.media.stop()}catch(e){}}},{key:"mute",value:function(){this.media.muted=!0;var e=this.getControls();e&&e.setMutedState(!0)}},{key:"unmute",value:function(){this.media.muted=!1;var e=this.getControls();e&&e.setMutedState(!1)}},{key:"setVolume",value:function(e){this.unmute(),this.media.volume=e}},{key:"seekTo",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;this.media.currentTime=t?e*t:e}},{key:"toggleFullScreen",value:function(){try{me.toggleFullScreen(this.holder)}catch(e){throw e}}},{key:"unpublish",value:function(){try{this.stop(),this.media.onended.call(this.media)}catch(e){}}},{key:"disconnect",value:function(){this._cleanUp()}},{key:"_handleOrientationChange",value:function(e){this._controls&&e%180!=0&&(this.holder.classList.add("red5pro-media-background"),this.media.classList.remove("red5pro-media-background"))}},{key:"getControls",value:function(){return this._controls}},{key:"getType",value:function(){return this.playerType}},{key:"isVOD",get:function(){return this._isVOD},set:function(e){this._isVOD=e,this._controls&&this._controls.setAsVOD(e)}}])&&Ii(t.prototype,r),n&&Ii(t,n),Object.defineProperty(t,"prototype",{writable:!1}),i}(xr);function Vi(e){return(Vi="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Gi(e,t){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:void 0;if(void 0===e&&void 0!==t){var r=new no(t);r.attachSubscriber(this)}}},{key:"_initHandler",value:function(e){var t=this,r=this._options,n=r.streamName,o=r.mimeType,i=n.match(Qi)?n:so(this._options);this._sourceHandler.on("*",this._boundBubbleSubscriberEvents),this._sourceHandler.addSource(i,o,e).then((function(){t.trigger(new Zt(xt.CONNECT_SUCCESS)),t._trackStreamingModeState(t._sourceHandler)})).catch((function(e){y("HLSSubscriber","Could not establish an HLS Subscriber: "+e),t.trigger(new Zt(xt.CONNECT_FAILURE))}))}},{key:"_trackStreamingModeState",value:function(e){var t=this;e.on(xt.STREAMING_MODE_CHANGE,(function(e){var r=e.data,n=r.streamingMode,o=r.previousStreamingMode;if("Empty"!==n&&"Empty"===o){t._sourceHandler.disconnect();var i=t._options,a=i.streamName,s=i.mimeType,c=a.match(Qi)?a:so(t._options);t._sourceHandler.addSource(c,s,t._options).then((function(){return t.subscribe()})).catch((function(e){return e("HLSSubscriber",e)}))}}))}},{key:"init",value:function(e){var t=this,r=new S;if(me.supportsHLS())if(e.connectionParams&&!Lt())v("HLSSubscriber","Could not resolve HLSSubscriber instance with connection params. WebSocket support is required."),r.reject("HLSSubscriber","Could not resolve HLSSubscriber instance with connection params. WebSocket support is required.");else{this._options=Object.assign({},Xi,e);var n=new S;if(this._options.connectionParams)try{this._socketHelper=new gn(this,"HLSSubscriptionSocket");var o=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=e.socketParams,n=e.connectionParams,o=r.protocol,i=oo(r.port||("wss"===o?443:5080)),a="".concat(o,"://").concat(r.host,":").concat(i,"/").concat(r.app,"/");if(n){var s=io(e.connectionParams);t=Object.assign(t,s)}if(t){var c=[];Object.keys(t).forEach((function(e,r){c.push([e,t[e]].join("="))})),c.length>0&&(a+="?"+c.join("&"))}return a}(this._options,{id:this._options.subscriptionId});this._socketHelper.setUp(o,n)}catch(e){y("HLSSubscriber",e.message),r.reject("HLSSubscriber","Could not set up WebSocket for authentication with connectionParams: ".concat(e.message))}else n.resolve();n.promise.then((function(){t._socketHelper&&(t._socketHelper.tearDown(),t._socketHelper=void 0),t._setViewIfNotExist(t._view,t._options.mediaElementId),t._getViewResolverPromise().then((function(e){t._sourceHandler=new Bi(e.view,t.getType()),t._glomSourceHandlerAPI(t._sourceHandler),t._options&&t._initHandler(t._options)})),r.resolve(t)})).catch((function(e){r.reject(e),t.trigger(new Zt(xt.CONNECT_FAILURE,t,e))}))}else v("HLSSubscriber","Could not resolve HLSSubscriber instance."),r.reject("Could not resolve HLSSubscriber instance.");return r.promise}},{key:"setView",value:function(e){return this._view=e,this._viewResolver.resolve(e),this}},{key:"subscribe",value:function(){return this._getSubscriptionResolverPromise()}},{key:"unsubscribe",value:function(){p("HLSSubscriber","[unscubscribe]");var e=new S;this._socketHelper&&this._socketHelper.tearDown();try{this._sourceHandler.stop(),this._sourceHandler.disconnect(),e.resolve()}catch(t){e.reject(t.message)}return e.promise}},{key:"getConnection",value:function(){return this._sourceHandler}},{key:"getControls",value:function(){return this._sourceHandler?this._sourceHandler.getControls():void 0}},{key:"getOptions",value:function(){return this._options}},{key:"getPlayer",value:function(){return this._view.view}},{key:"getType",value:function(){return lo.HLS.toUpperCase()}}])&&Gi(t.prototype,r),n&&Gi(t,n),Object.defineProperty(t,"prototype",{writable:!1}),i}(xr);function Zi(e){return(Zi="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function ea(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ea=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function u(e,t,r,o){var i=t&&t.prototype instanceof d?t:d,a=Object.create(i.prototype),s=new O(o||[]);return n(a,"_invoke",{value:w(e,r,s)}),a}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var f={};function d(){}function h(){}function p(){}var v={};c(v,i,(function(){return this}));var y=Object.getPrototypeOf,m=y&&y(y(k([])));m&&m!==t&&r.call(m,i)&&(v=m);var b=p.prototype=d.prototype=Object.create(v);function g(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function _(e,t){var o;n(this,"_invoke",{value:function(n,i){function a(){return new t((function(o,a){!function n(o,i,a,s){var c=l(e[o],e,i);if("throw"!==c.type){var u=c.arg,f=u.value;return f&&"object"==Zi(f)&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,a,s)}),(function(e){n("throw",e,a,s)})):t.resolve(f).then((function(e){u.value=e,a(u)}),(function(e){return n("throw",e,a,s)}))}s(c.arg)}(n,i,o,a)}))}return o=o?o.then(a,a):a()}})}function w(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return P()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var s=S(a,r);if(s){if(s===f)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=l(e,t,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===f)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function S(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,S(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),f;var o=l(n,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,f;var i=o.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,f):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,f)}function E(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 C(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function O(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(E,this),this.reset(!0)}function k(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 n=-1,o=function t(){for(;++n=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),C(r),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;C(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:k(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},e}function ta(e,t,r,n,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}function ra(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){ta(i,n,o,a,s,"next",e)}function s(e){ta(i,n,o,a,s,"throw",e)}a(void 0)}))}}function na(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function oa(e,t){for(var r=0;r0}(e)?"&":"?"},la=function(e){return e.split(";").map((function(e){return e.trim()})).map((function(e){return"<"===e.charAt(0)?["url",e.substring(1,e.length-1)]:e.split("=")})).reduce((function(e,t){return e.set(t[0].replaceAll('"',""),t[1].replaceAll('"',""))}),new Map)},fa=function(e){var t=e.split(":");return t.length>1?{protocol:t[0],host:t[1]}:{protocol:void 0,host:e}},da=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];na(this,e),p("WhipWhepSignalingHelper","[whipwhep] ".concat(t)),this._url=t,this._origin=void 0,this._forceHost=n,this._resource=void 0,this._enableSignalingChannel=r}var t,r,n,o,i,a,s,c,u;return t=e,(r=[{key:"getOptions",value:(u=ra((function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return ea().mark((function r(){var n,o,i,a,s,c,u,l,f;return ea().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n="".concat(e._url).concat(ua(e._url),"signal=").concat(e._enableSignalingChannel),t&&Object.keys(t).forEach((function(e){n+="&".concat(e,"=").concat(t[e])})),p("WhipWhepSignalingHelper","[whipwhep-options] ".concat(n)),r.prev=3,r.next=6,fetch(n,{method:"OPTIONS",mode:"cors"});case 6:if(o=r.sent,i=o.status,a=o.headers,200!==i&&204!==i){r.next=19;break}return s=/^(L|l)ink/,c=/^(S|s)ession-(H|h)ost/,u=[],a.forEach((function(t,r){if(c.exec(r)&&(e._origin=t),s.exec(r))if(t.indexOf('rel="'.concat(ca.ICE_SERVER,'"'))>-1){var n=la(t),o=n.get("url"),i=fa(o),a=i.protocol,f=i.host,d=n.get("username"),h=n.get("credential");a&&f&&d&&h?u.push({username:d,credential:h,urls:o}):o&&u.push({urls:o})}else if(t.indexOf('rel="'.concat(ca.STATISTICS,'"'))>-1){var p=la(t).get("url");p&&(l=p)}})),p("WhipWhepSignalingHelper","[whipwhep-links]: ".concat(JSON.stringify(u))),p("WhipWhepSignalingHelper","[whipwhep-origin]: ".concat(e._origin)),p("WhipWhepSignalingHelper","[whipwhep-statistics]: ".concat(l)),r.abrupt("return",{links:u.length>0?u:void 0,origin:e._origin,statisticsEndpoint:l});case 19:return r.next=21,o.text();case 21:throw f=r.sent,Error("".concat(i,":: ").concat(f));case 23:r.next=29;break;case 25:throw r.prev=25,r.t0=r.catch(3),y("WhipWhepSignalingHelper",r.t0.message),r.t0;case 29:case"end":return r.stop()}}),r,null,[[3,25]])}))()})),function(){return u.apply(this,arguments)})},{key:"postSDPOffer",value:(c=ra((function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return ea().mark((function o(){var i,a,s,c,u,l,f,d,h;return ea().wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return i="".concat(t._url).concat(ua(t._url),"signal=").concat(t._enableSignalingChannel),r&&Object.keys(r).forEach((function(e){-1===sa.indexOf(e)&&(i+="&".concat(e,"=").concat(r[e]))})),t._forceHost&&t._origin&&!r.host&&(i+="&host=".concat(t._origin)),p("WhipWhepSignalingHelper","[whipwhep:post-offer] ".concat(i,": ")+JSON.stringify(e,null,2)),o.prev=4,a={method:"POST",mode:"cors",headers:{"Content-Type":"application/sdp"}},e&&e.length>0&&(a.body=e),o.next=9,fetch(i,a);case 9:if(s=o.sent,c=s.status,(u=s.headers)&&u.forEach((function(e,t){p("WhipWhepSignalingHelper","[header] ".concat(t,": ").concat(e))})),!(c>=200&&c<300)){o.next=28;break}return o.next=15,s.text();case 15:if(l=o.sent,!(f=u.get("Location")||u.get("location"))){o.next=23;break}return f.match(/^(http|https)/)?t._resource=f:(p("WhipWhepSignalingHelper","[whipwhep-response] Location provided as relative path: ".concat(f)),(d=new URL(t._url)).pathname=f.split("?")[0],t._resource=d.toString().replace(/\/endpoint\//,"/resource/")),p("WhipWhepSignalingHelper","[whipwhep-response] ".concat(t._resource,": ").concat(l)),o.abrupt("return",{sdp:l,location:t._resource});case 23:return v("WhipWhepSignalingHelper","Location not provided in header response to Offer."),t._resource=new URL(t._url).toString().replace(/\/endpoint\//,"/resource/"),o.abrupt("return",{sdp:l,location:t._resource});case 26:o.next=46;break;case 28:if(!n||!ia.get(c)){o.next=35;break}if(p("WhipWhepSignalingHelper",ia.get(c)),404!==c&&409!==c){o.next=32;break}throw new U(ia.get(c));case 32:throw new Error(ia.get(c));case 35:if(n||!aa.get(c)){o.next=42;break}if(p("WhipWhepSignalingHelper",aa.get(c)),404!==c&&409!==c){o.next=39;break}throw new U(aa.get(c));case 39:throw new Error(aa.get(c));case 42:return o.next=44,s.text();case 44:throw h=o.sent,Error(h);case 46:o.next=52;break;case 48:throw o.prev=48,o.t0=o.catch(4),y("WhipWhepSignalingHelper",o.t0.message),o.t0;case 52:case"end":return o.stop()}}),o,null,[[4,48]])}))()})),function(e){return c.apply(this,arguments)})},{key:"postSDPAnswer",value:(s=ra((function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return ea().mark((function n(){var o,i,a,s,c;return ea().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return p("WhipWhepSignalingHelper","[whipwhep:post-answer] ".concat(t._resource,": ")+JSON.stringify(e,null,2)),o=t._resource,i=ua(o),r&&Object.keys(r).forEach((function(e){-1===sa.indexOf(e)&&(i=ua(o),o+="".concat(i).concat(e,"=").concat(r[e]))})),t._forceHost&&t._origin&&!r.host&&(i=o.indexOf("?")>-1?"&":"?",o+="".concat(i,"host=").concat(t._origin)),n.prev=5,n.next=8,fetch(o,{method:"PATCH",mode:"cors",headers:{"Content-Type":"application/sdp"},body:e});case 8:if(a=n.sent,!((s=a.status)>=200&&s<300)){n.next=14;break}return n.abrupt("return",{success:!0,code:s});case 14:if(!aa.get(s)){n.next=19;break}throw p("WhipWhepSignalingHelper",aa.get(s)),new Error(aa.get(s));case 19:return n.next=21,a.text();case 21:throw c=n.sent,Error(c);case 23:n.next=29;break;case 25:throw n.prev=25,n.t0=n.catch(5),y("WhipWhepSignalingHelper",n.t0.message),n.t0;case 29:case"end":return n.stop()}}),n,null,[[5,25]])}))()})),function(e){return s.apply(this,arguments)})},{key:"trickle",value:(a=ra((function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return ea().mark((function n(){var o,i,a,s,c,u;return ea().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return p("WhipWhepSignalingHelper","[whipwhep-trickle] ".concat(t._resource,": ")+JSON.stringify(e,null,2)),o=t._resource,i=ua(o),r&&Object.keys(r).forEach((function(e){-1===sa.indexOf(e)&&(i=ua(o),o+="".concat(i).concat(e,"=").concat(r[e]))})),t._forceHost&&t._origin&&!r.host&&(i=ua(o),o+="".concat(i,"host=").concat(t._origin)),n.prev=5,n.next=8,fetch(o,{method:"PATCH",mode:"cors",headers:{"Content-Type":"application/trickle-ice-sdpfrag"},body:e});case 8:if(a=n.sent,s=a.status,a.headers,!(s>=200&&s<300)){n.next=18;break}return n.next=13,a.text();case 13:return c=n.sent,p("WhipWhepSignalingHelper","[whipwhep-response] ".concat(t._resource,": ").concat(c)),n.abrupt("return",{candidate:c});case 18:if(405!==s){n.next=23;break}throw console.log("Remember to update the URL passed into the WHIP or WHEP client"),new Error("Remember to update the URL passed into the WHIP or WHEP client");case 23:return n.next=25,a.text();case 25:throw u=n.sent,Error(u);case 27:n.next=33;break;case 29:throw n.prev=29,n.t0=n.catch(5),console.error(n.t0),n.t0;case 33:case"end":return n.stop()}}),n,null,[[5,29]])}))()})),function(e){return a.apply(this,arguments)})},{key:"tearDown",value:(i=ra((function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return ea().mark((function r(){var n,o;return ea().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(e._resource){r.next=2;break}return r.abrupt("return");case 2:return n=e._resource,o=ua(n),t&&Object.keys(t).forEach((function(e){-1===sa.indexOf(e)&&(o=ua(n),n+="".concat(o).concat(e,"=").concat(t[e]))})),e._forceHost&&e._origin&&!t.host&&(o=ua(n),n+="".concat(o,"host=").concat(e._origin)),p("WhipWhepSignalingHelper","[whipwhep-teardown]"),r.next=9,fetch(n,{method:"DELETE",mode:"cors"});case 9:e._url=void 0,e._origin=void 0,e._resource=void 0,e._forceHost=!1,e._enableSignalingChannel=!1;case 14:case"end":return r.stop()}}),r)}))()})),function(){return i.apply(this,arguments)})},{key:"post",value:(o=ra((function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return ea().mark((function t(){return ea().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return p("WhipWhepSignalingHelper","[whipwhep] transport called."),e&&p("WhipWhepSignalingHelper","[whipwhep:post]\r\n ".concat(JSON.stringify(e,null,2))),t.abrupt("return",!0);case 3:case"end":return t.stop()}}),t)}))()})),function(){return o.apply(this,arguments)})}])&&oa(t.prototype,r),n&&oa(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}(),ha=Object.freeze({EMPTY:"Empty",VIDEO:"Video",AUDIO:"Audio",FULL:"Video/Audio"});function pa(e){return(pa="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function va(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */va=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function u(e,t,r,o){var i=t&&t.prototype instanceof d?t:d,a=Object.create(i.prototype),s=new O(o||[]);return n(a,"_invoke",{value:w(e,r,s)}),a}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var f={};function d(){}function h(){}function p(){}var v={};c(v,i,(function(){return this}));var y=Object.getPrototypeOf,m=y&&y(y(k([])));m&&m!==t&&r.call(m,i)&&(v=m);var b=p.prototype=d.prototype=Object.create(v);function g(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function _(e,t){var o;n(this,"_invoke",{value:function(n,i){function a(){return new t((function(o,a){!function n(o,i,a,s){var c=l(e[o],e,i);if("throw"!==c.type){var u=c.arg,f=u.value;return f&&"object"==pa(f)&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,a,s)}),(function(e){n("throw",e,a,s)})):t.resolve(f).then((function(e){u.value=e,a(u)}),(function(e){return n("throw",e,a,s)}))}s(c.arg)}(n,i,o,a)}))}return o=o?o.then(a,a):a()}})}function w(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return P()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var s=S(a,r);if(s){if(s===f)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=l(e,t,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===f)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function S(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,S(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),f;var o=l(n,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,f;var i=o.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,f):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,f)}function E(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 C(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function O(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(E,this),this.reset(!0)}function k(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 n=-1,o=function t(){for(;++n=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),C(r),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;C(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:k(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},e}function ya(e,t,r,n,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}function ma(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){ya(i,n,o,a,s,"next",e)}function s(e){ya(i,n,o,a,s,"throw",e)}a(void 0)}))}}function ba(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function ga(e,t){for(var r=0;r2&&void 0!==arguments[2])||arguments[2];ba(this,g),r=b.call(this);var o=e?co(e):La;return o.mediaElementId=t?t.id:La.mediaElementId,o.trickleIce=n,r._whipHelper=void 0,r._videoMuted=!0,r._audioMuted=!0,r._videoUnmuteHandler=r._onVideoUnmute.bind(Oa(r)),r._audioUnmuteHandler=r._onAudioUnmute.bind(Oa(r)),e&&r._internalConnect(o),r}return t=g,(r=[{key:"_runMuteCheck",value:(m=ma(va().mark((function e(){var t,r=this;return va().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.getPeerConnection()){e.next=2;break}return e.abrupt("return");case 2:return e.prev=2,e.next=5,this.getPeerConnection().getStats();case 5:e.sent.forEach((function(e){var t=e.type,n=e.kind,o=e.bytesReceived;"inbound-rtp"!==t&&"inboundrtp"!==t||("video"===n?r._videoMuted=o<=0:"audio"===n&&(r._audioMuted=o<=0))})),t={data:{streamingMode:(n=!this._videoMuted,o=!this._audioMuted,n&&o?ha.FULL:n?ha.VIDEO:o?ha.AUDIO:ha.EMPTY),method:"onMetaData"},type:"metadata",method:"onMetaData",eventTimestamp:(new Date).getTime()},this.onMetaData(t),p("WHEPClient","[metadata]:: ".concat(JSON.stringify(t,null,2))),e.next=16;break;case 12:e.prev=12,e.t0=e.catch(2),console.warn(e.t0),v("WHEPClient",e.t0.message||e.t0);case 16:case"end":return e.stop()}var n,o}),e,this,[[2,12]])}))),function(){return m.apply(this,arguments)})},{key:"_onVideoUnmute",value:function(e){var t=this;e.target.removeEventListener("unmute",this._videoUnmuteHandler);var r=setTimeout(ma(va().mark((function e(){return va().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:clearTimeout(r),t._runMuteCheck();case 2:case"end":return e.stop()}}),e)}))),1e3)}},{key:"_onAudioUnmute",value:function(e){var t=this;e.target.removeEventListener("unmute",this._audioUnmuteHandler);var r=setTimeout(ma(va().mark((function e(){return va().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:clearTimeout(r),t._runMuteCheck();case 2:case"end":return e.stop()}}),e)}))),1e3)}},{key:"_switchWhipWhepHandler",value:function(e){this._options.host=e,this._options.protocol="ws",this._options.port=5080;var t=this._options,r=t.protocol,n=t.host,o=t.port,i=t.app,a=t.streamName,s=t.subscriptionId,c=t.enableChannelSignaling,u=t.disableProxy,l=r.match(/^http/)?r:"ws"===r?"http":"https",f="".concat(l,"://").concat(n,":").concat(o,"/").concat(i);this._whipUrl="".concat(f,"/whep/endpoint/").concat(a,"?requestId=").concat(s),this._whipHelper=new da(this._whipUrl,c,u)}},{key:"_glomSourceHandlerAPI",value:function(e){var t=this;_a(ka(g.prototype),"_glomSourceHandlerAPI",this).call(this,e),e.on("loadedmetadata",(function(){t._runMuteCheck()})),e.on(xt.PLAYBACK_STATE_CHANGE,(function(){t._runMuteCheck()}))}},{key:"_internalConnect",value:(h=ma(va().mark((function e(t){return va().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.init(t);case 2:return e.next=4,this.subscribe();case 4:case"end":return e.stop()}}),e,this)}))),function(e){return h.apply(this,arguments)})},{key:"waitToGatherIce",value:(d=ma(va().mark((function e(t){return va().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){if("complete"===t.iceGatheringState)t.addIceCandidate({candidate:""}).then((function(){e({local:t.localDescription})})).catch((function(r){y("WHEPClient",r.message||r),e({local:t.localDescription})}));else{var r=setTimeout((function(){clearTimeout(r),t.addIceCandidate({candidate:""}).then((function(){e({local:t.localDescription})})).catch((function(r){y("WHEPClient",r.message||r),e({local:t.localDescription})}))}),5e3);t.addEventListener("icegatheringstatechange",(function(){"complete"===t.iceGatheringState&&(clearTimeout(r),t.addIceCandidate({candidate:""}).then((function(){e({local:t.localDescription})})).catch((function(r){y("WHEPClient",r.message||r),e({local:t.localDescription})})))}))}})));case 1:case"end":return e.stop()}}),e)}))),function(e){return d.apply(this,arguments)})},{key:"_sendCandidate",value:function(e){p("WHEPClient","[sendcandidate]"),this.trigger(new Zt(Mt.CANDIDATE_START,this,e))}},{key:"_postOffer",value:(f=ma((function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return va().mark((function n(){var o,i,a,s,c,u,l,f,d;return va().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,o=t._options,i=o.maintainStreamVariant,a=o.videoEncoding,s=o.audioEncoding,c=o.connectionParams,u=o.postEmptyOffer,l=o.mungeOffer,f=Ta(Ta({},c),{},{doNotSwitch:i}),void 0!==a&&a!==ho.NONE&&(f.videoEncoding=a),void 0!==s&&s!==fo.NONE&&(f.audioEncoding=s),d="",u||(d=e.sdp,l&&(d=l(d)),r||(d=rt(d),d=ot(d)),d=bt(d)),n.next=9,t._whipHelper.postSDPOffer(d,f,!1);case 9:return n.abrupt("return",n.sent);case 12:n.prev=12,n.t0=n.catch(0),y("WHEPClient",n.t0.message||n.t0),n.t0 instanceof U?t.onStreamUnavailable(n.t0):(t.trigger(new Zt(xt.CONNECT_FAILURE,t)),t.unsubscribe(),t._subscriptionResolver.reject("Stream failure."));case 16:case"end":return n.stop()}}),n,null,[[0,12]])}))()})),function(e){return f.apply(this,arguments)})},{key:"_postEmptyOffer",value:(l=ma(va().mark((function e(){var t,r,n,o,i,a;return va().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,t=this._options,r=t.maintainStreamVariant,n=t.videoEncoding,o=t.audioEncoding,i=t.connectionParams,a=Ta(Ta({},i),{},{doNotSwitch:r}),void 0!==n&&n!==ho.NONE&&(a.videoEncoding=n),void 0!==o&&o!==fo.NONE&&(a.audioEncoding=o),e.next=7,this._whipHelper.postSDPOffer("",a,!1);case 7:return e.abrupt("return",e.sent);case 10:throw e.prev=10,e.t0=e.catch(0),y("WHEPClient",e.t0.message||e.t0),this.onStreamUnavailable(e.t0),e.t0;case 15:case"end":return e.stop()}}),e,this,[[0,10]])}))),function(){return l.apply(this,arguments)})},{key:"_postAnswer",value:(u=ma(va().mark((function e(t,r,n){var o,i,a,s,c;return va().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=this._options,i=o.mungeAnswer,a=o.connectionParams,p("WHEPClient","[sendanswer]: streamname(".concat(t,"), subscriptionid(").concat(r,")")),s=n.sdp,c=s,i&&(c=i(c)),e.next=7,this._whipHelper.postSDPAnswer(c,a);case 7:return e.abrupt("return",e.sent);case 8:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return u.apply(this,arguments)})},{key:"_postCandidateFragments",value:(c=ma(va().mark((function e(t){var r,n;return va().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=this._options.connectionParams,n=_t(t,void 0,!0),e.next=4,this._whipHelper.trickle(n,r);case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"_requestOffer",value:(s=ma(va().mark((function e(){var t,r,n,o,i,a,s,c,u,l,f,d,h,v,m,b,g,_,w,S,E,C,O;return va().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(p("WHEPClient","[requestoffer]"),t=this._options,r=t.trickleIce,n=t.postEmptyOffer,o=t.streamName,i=t.subscriptionId,a=t.mungeOffer,s=t.mungeAnswer,c=this.getPeerConnection(),u=void 0,e.prev=4,!n){e.next=18;break}return this.trigger(new Zt(Mt.OFFER_START,this)),e.next=9,this._postEmptyOffer();case 9:return l=e.sent,f=l.sdp,this.trigger(new Zt(Mt.OFFER_END,this)),d=new At({type:"offer",sdp:f}),p("WHEPClient","[requestoffer:empty:remote] ".concat(JSON.stringify(d,null,2))),e.next=16,c.setRemoteDescription(d);case 16:e.next=36;break;case 18:return c.addTransceiver("video",{direction:"recvonly"}),c.addTransceiver("audio",{direction:"recvonly"}),this.trigger(new Zt(Mt.OFFER_START,this)),e.next=23,c.createOffer();case 23:return h=e.sent,this.trigger(new Zt(Mt.OFFER_END,this)),e.next=27,this._postOffer(h,r);case 27:return v=e.sent,m=v.sdp,b=bt(m),a&&(b=a(b)),u=vt(b),g=new At({type:"offer",sdp:b}),p("WHEPClient","[requestoffer:remote] ".concat(JSON.stringify(g,null,2))),e.next=36,c.setRemoteDescription(g);case 36:return e.next=38,c.createAnswer();case 38:if((_=e.sent).sdp=s?s(_.sdp):_.sdp,_.sdp=yt(_.sdp,u),!r||!c.canTrickleIceCandidates){e.next=60;break}return p("WHEPClient","[trickle:ice] enabled"),_.sdp=nt(_.sdp),_.sdp=gt(_.sdp),e.next=47,c.setLocalDescription(_);case 47:return p("WHEPClient","[create:answer:local] ".concat(JSON.stringify({type:"answer",sdp:_.sdp},null,2))),this.trigger(new Zt(Mt.ANSWER_START,this,_)),e.next=51,this._postAnswer(o,i,_);case 51:return this.trigger(new Zt(Mt.ANSWER_END,this)),e.next=54,this.waitToGatherIce(c);case 54:return w=e.sent,S=w.local,e.next=58,this._postCandidateFragments(S.sdp);case 58:e.next=76;break;case 60:return p("WHEPClient","[trickle:ice] disabled"),_.sdp=rt(_.sdp),_.sdp=gt(_.sdp),e.next=65,c.setLocalDescription(_);case 65:return e.next=67,this.waitToGatherIce(c);case 67:return E=e.sent,C=E.local,O=rt(C.sdp),O=ot(O),p("WHEPClient","[create:answer:local] ".concat(JSON.stringify({type:"answer",sdp:O},null,2))),this.trigger(new Zt(Mt.ANSWER_START,this,{type:"answer",sdp:O})),e.next=75,this._postAnswer(o,i,{type:"answer",sdp:O});case 75:this.trigger(new Zt(Mt.ANSWER_END,this));case 76:e.next=82;break;case 78:throw e.prev=78,e.t0=e.catch(4),y("WHEPClient",e.t0),e.t0;case 82:case"end":return e.stop()}}),e,this,[[4,78]])}))),function(){return s.apply(this,arguments)})},{key:"_disconnect",value:function(){this._whipHelper&&this._whipHelper.tearDown(),this._whipHelper=void 0,_a(ka(g.prototype),"_disconnect",this).call(this)}},{key:"init",value:(a=ma((function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;return va().mark((function n(){var o,i,a,s,c,u,l,f,d,h,p,v,y;return va().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(We()){n.next=4;break}throw new Error("Cannot create WebRTC playback instance. Your environment does not support WebRTC and/or WebSockets.");case 4:return t._disconnect(),t._options=Ta(Ta({},La),e),t._options.subscriptionId=t._options.subscriptionId||Te(),o=t._options,i=o.endpoint,a=o.protocol,s=o.host,c=o.port,u=o.app,l=o.streamName,f=o.subscriptionId,d=o.enableChannelSignaling,h=o.disableProxy,(p=o.stats)&&t.monitorStats(p),v=a.match(/^http/)?a:"ws"===a?"http":"https",y="".concat(v,"://").concat(s,":").concat(c,"/").concat(u),t._whipUrl=i?"".concat(i,"?requestId=").concat(f):"".concat(y,"/whep/endpoint/").concat(l,"?requestId=").concat(f),t._whipHelper=new da(t._whipUrl,d,h),t._peerHelper=new Zn(t),t._messageTransport=t._whipHelper,t._mediaTransform=r,t._mediaTransform&&!Ke()&&(t.trigger(new Zt(Mt.UNSUPPORTED_FEATURE,t,{feature:"Insertable Streams",message:"You provided Media Transforms for track processing, but your current browser does not support the Insertable Streams API."})),t._mediaTransform=void 0),n.abrupt("return",t);case 18:case"end":return n.stop()}}),n)}))()})),function(e){return a.apply(this,arguments)})},{key:"subscribe",value:(i=ma(va().mark((function e(){var t,r,n,o,i,a,s,c,u,l,f,d,h,p,v,m,b;return va().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=this._options,r=t.mediaElementId,n=t.rtcConfiguration,o=t.liveSeek,i=t.connectionParams,a=this._options,s=a.enableChannelSignaling,c=a.dataChannelConfiguration,(u=s&&Ye())&&!c&&(c={name:"red5pro"},this._options.dataChannelConfiguration=c),this._options.enableChannelSignaling=u,this._options.signalingSocketOnly=this._options.enableChannelSignaling,e.prev=6,this._setViewIfNotExist(this._view,r),e.next=10,this._getViewResolverPromise();case 10:return l=e.sent,o&&o.enabled?(f=o.hlsjsRef,d=o.usePlaybackControlsUI,h=o.options,me.supportsNonNativeHLS(f)?this._sourceHandler=new nn(l.view,this.getType(),h,d):(y("WHEPClient","Could not utilize the 'LiveSeek' request. This feature requires either native HLS playback or hls.js as a depenency."),this.trigger(new Zt(Mt.LIVE_SEEK_UNSUPPORTED,this,{feature:"Live Seek",message:"Live Seek requires integration with the HLS.JS plugin in order work properly. Most likely you are viewing this on a browser that does not support the use of HLS.JS."})),this._sourceHandler=new zr(l.view,this.getType()))):this._sourceHandler=new zr(l.view,this.getType()),this._glomSourceHandlerAPI(this._sourceHandler),this._initHandler(this._options,this._sourceHandler),this._getAvailabilityResolverPromise().catch((function(){})),p=i||{},e.next=18,this._whipHelper.getOptions(p);case 18:return(v=e.sent)&&(v.links&&(this._options.rtcConfiguration=Ta(Ta({},n),{},{iceServers:v.links})),v.origin&&this.trigger(new Zt(Mt.HOST_ENDPOINT_CHANGED,this,{endpoint:v.origin,iceServers:v.links})),v.statisticsEndpoint&&this.trigger(new Zt(xt.STATISTICS_ENDPOINT_CHANGE,this,{statisticsEndpoint:v.statisticsEndpoint}))),m=this._options.enableChannelSignaling?c:void 0,b=n,void 0===n.encodedInsertableStreams&&(b=Object.assign(n,{encodedInsertableStreams:!!this._mediaTransform})),this._connect(b,m,this._options.iceServers),this._connectionClosed=!1,e.abrupt("return",this._getSubscriptionResolverPromise());case 28:throw e.prev=28,e.t0=e.catch(6),this.trigger(new Zt(xt.CONNECT_FAILURE),this,e.t0),e.t0;case 32:case"end":return e.stop()}}),e,this,[[6,28]])}))),function(){return i.apply(this,arguments)})},{key:"onAnswerMediaStream",value:(o=ma((function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;return va().mark((function r(){return va().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:_a(ka(g.prototype),"onAnswerMediaStream",e).call(e,t),t.getTracks().forEach((function(t){"video"===t.kind?(e._videoMuted=t.muted,t.muted&&t.addEventListener("unmute",e._videoUnmuteHandler)):"audio"===t.kind&&(e._audioMuted=t.muted,t.muted&&t.addEventListener("unmute",e._audioUnmuteHandler))})),e._runMuteCheck();case 4:case"end":return r.stop()}}),r)}))()})),function(){return o.apply(this,arguments)})},{key:"onPeerConnectionOpen",value:function(){var e=this._options.enableChannelSignaling;_a(ka(g.prototype),"onPeerConnectionOpen",this).call(this),this._subscriptionResolver.resolve(this),e||this.trigger(new Zt(xt.SUBSCRIBE_START,this)),this._playIfAutoplaySet(this._options,this._view),this._startSeekable(this._options,this._view)}},{key:"onDataChannelOpen",value:function(e){var t=this._options.dataChannelConfiguration;if(_a(ka(g.prototype),"onDataChannelOpen",this).call(this,e),t){var r=t.name;_a(ka(g.prototype),"onDataChannelAvailable",this).call(this,r)}else _a(ka(g.prototype),"onDataChannelAvailable",this).call(this);this.trigger(new Zt(xt.SUBSCRIBE_START,this))}},{key:"getConnection",value:function(){}}])&&ga(t.prototype,r),n&&ga(t,n),Object.defineProperty(t,"prototype",{writable:!1}),g}(hi);function ja(e){return(ja="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Ha(e){return function(e){if(Array.isArray(e))return Ia(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return Ia(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return Ia(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Ia(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r2&&void 0!==arguments[2]?arguments[2]:null,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;p("R5ProPublisherSourceHandler","[addsource]");var o=this;this._swfId=e,this._embedFuture=E.createIfNotExist(this._embedFuture);var i=this._embedFuture;return t.swf=r||t.swf,t.minFlashVersion=n||t.minFlashVersion,pi(this.video,this.holder).then((function(r){p("R5ProPublisherSourceHandler","[element:complete]");var n={buffer:null!=t.buffer?t.buffer:1,streamMode:t.streamMode,streamName:t.streamName,appName:t.app,host:t.host};return t.backgroundColor&&(n.backgroundColor=t.backgroundColor),t.context&&(n.roomName=t.context),"100%"!==t.embedWidth&&"100%"!==t.embedHeight||(n.autosize=!0),void 0!==t.connectionParams&&(n.connectionParams=encodeURIComponent(JSON.stringify(t.connectionParams))),n=Ka(t.mediaConstraints,n),vi(e,t,n,me.getSwfObject(),r)})).then((function(){p("R5ProPublisherSourceHandler","[embed:complete]"),i.resolve(o)})).catch((function(e){return i.reject(e)})),i.promise}},{key:"connect",value:function(e){p("R5ProPublisherSourceHandler","[connect]");var t=me.getEmbedObject(this._swfId);t?t.connect(e):v("R5ProPublisherSourceHandler","Could not determine embedded element with swf id: "+this._swfId+".")}},{key:"disconnect",value:function(){p("R5ProPublisherSourceHandler","[disconnect]");try{var e=me.getEmbedObject(this._swfId);e&&e.disconnect()}catch(e){}this.cleanUp()}},{key:"send",value:function(e,t){var r=me.getEmbedObject(this._swfId);r&&r.send(e,t)}},{key:"setMediaQuality",value:function(e){var t=me.getEmbedObject(this._swfId);if(t&&e.video&&"boolean"!=typeof e.video){var r=isNaN(e.video.width)?Number.isNaN:Pe(e.video.width),n=isNaN(e.video.height)?Number.isNaN:Pe(e.video.height);t.updateResolution(r,n)}}},{key:"getType",value:function(){return this._publisherType}}])&&za(t.prototype,r),n&&za(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function qa(e){return(qa="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Xa(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Qa(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:"red5pro-publisher";Xa(this,e);try{this._targetElement=me.resolveElement(t)}catch(e){throw y("R5ProPublishView","Could not instantiate a new instance of Red5ProPublisher. Reason: ".concat(e.message)),e}}var t,r,n;return t=e,(r=[{key:"attachPublisher",value:function(e){p("R5ProPublishView","[attachpublisher]"),e.setView(this,me.getElementId(this._targetElement))}},{key:"preview",value:function(e){var t=this.isAutoplay;p("R5ProPublishView","[preview]: autoplay(".concat(t,")")),me.setVideoSource(this._targetElement,e,t)}},{key:"unpreview",value:function(){me.setVideoSource(this._targetElement,null,this.isAutoplay)}},{key:"isAutoplay",get:function(){return me.hasAttributeDefined(this._targetElement,"autoplay")}},{key:"view",get:function(){return this._targetElement}}])&&Qa(t.prototype,r),n&&Qa(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}(),Za=Object.freeze({RTMP:"rtmp",RTC:"rtc"}),es=Object.freeze({LIVE:"live",RECORD:"record",APPEND:"append"}),ts=(Object.freeze({OPUS:"Opus",PCMU:"PCMU",PCMA:"PCMA"}),Object.freeze({VP8:"VP8",VP9:"VP9",H264:"H264"}));function rs(e){return(rs="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function ns(e,t){for(var r=0;r0&&void 0!==arguments[0])||arguments[0],r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;is(this,e),as(this,"audio",t),as(this,"video",r||new ss)}));function ls(e){return(ls="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function fs(e,t){for(var r=0;r0&&void 0!==arguments[0])||arguments[0],r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;is(this,e),as(this,"audio",t),as(this,"video",r||new cs)})))},ms=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&ds(e,t)}(i,e);var t,r,n,o=hs(i);function i(){var e;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,i),(e=o.call(this))._options=void 0,e._view=void 0,e._sourceHandler=void 0,e._elementId=void 0,e._connectFuture=void 0,e}return t=i,(r=[{key:"_setViewIfNotExist",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;if(void 0===e&&void 0!==t){var r=new $a(t);r.attachPublisher(this)}}},{key:"setView",value:function(e,t){var r=this;return this._view=e,this._elementId=t,void 0!==this._sourceHandler&&(this._sourceHandler.disconnect(),this._sourceHandler=void 0),this._view&&(this._sourceHandler=new Ja(this._view.view,this.getType())),this._options&&this._sourceHandler&&this._sourceHandler.addSource(this._elementId,this._options).catch((function(e){y("RTMPPublisher","Could not establish proper RTMP publisher: ".concat(e)),r.trigger(new $t(It.EMBED_FAILURE,r))})),this}},{key:"_setUpConnectCallback",value:function(e){var t=this;window.setActiveId=function(r){p("RTMPPublisher","Embed and connect() complete for publisher swf. successId(".concat(r,").")),e.resolve(t),t.trigger(new $t(It.EMBED_SUCCESS,t)),t._tearDownConnectCallback()}}},{key:"_tearDownConnectCallback",value:function(){window.setActiveId=void 0}},{key:"_establishExtIntHandlers",value:function(){var e=this,t=this._options.streamName,r=function(e){return["publisher",e,t.split("-").join("_")].join("_")};window[r("r5proConnectClosed")]=function(){e.trigger(new $t(Nt.CONNECTION_CLOSED,e))},window[r("r5proConnectSuccess")]=function(){return e.trigger(new $t(Nt.CONNECT_SUCCESS,e))},window[r("r5proUnpublishSuccess")]=function(){return e.trigger(new $t(Nt.UNPUBLISH_SUCCESS,e))},window[r("r5proPublishStart")]=function(){e._connectFuture.resolve(e),e.trigger(new $t(Nt.PUBLISH_START,e))},window[r("r5proPublishMetadata")]=function(t){return e.trigger(new $t(Nt.PUBLISH_METADATA,e,t))},window[r("r5proPublishInsufficientBW")]=function(t){return e.trigger(new $t(Nt.PUBLISH_INSUFFICIENT_BANDWIDTH,e,t))},window[r("r5proPublishSufficientBW")]=function(t){return e.trigger(new $t(Nt.PUBLISH_SUFFICIENT_BANDWIDTH,e,t))},window[r("r5proPublishRecoveringBW")]=function(t){return e.trigger(new $t(Nt.PUBLISH_RECOVERING_BANDWIDTH,e,t))},window[r("r5proConnectFailure")]=function(){e._connectFuture.reject(Nt.CONNECT_FAILURE),e.trigger(new $t(Nt.CONNECT_FAILURE,e))},window[r("r5proPublishFail")]=function(){e._connectFuture.reject(Nt.PUBLISH_FAIL),e.trigger(new $t(Nt.PUBLISH_FAIL,e))},window[r("r5proPublishInvalidName")]=function(){e._connectFuture.reject(Nt.PUBLISH_INVALID_NAME),e.trigger(new $t(Nt.PUBLISH_INVALID_NAME,e))}}},{key:"init",value:function(e){var t=this,r=new S,n=e.minFlashVersion||ys.minFlashVersion;if(me.supportsFlashVersion(n)){this._options=Object.assign({},ys,e);try{me.injectScript(this._options.swfobjectURL).then((function(){return p("RTMPPublisher","SWFObject embedded."),t._sourceHandler?(p("RTMPPublisher","Publish handler established."),t._sourceHandler.addSource(t._elementId,t._options)):(p("RTMPPublisher","Publish handler not established."),!0)})).then((function(){t._setViewIfNotExist(t._view,t._options.mediaElementId),r.resolve(t)})).catch((function(e){y("RTMPPublisher","Could not embed Flash-based RTMP Publisher. Reason: ".concat(e)),t._sourceHandler&&t._sourceHandler.disconnect(),r.reject(e),t.trigger(new $t(It.EMBED_FAILURE,t))}))}catch(e){r.reject("Could not inject Flash-based Publisher into the page. Reason: ".concat(e.message)),t.trigger(new $t(It.EMBED_FAILURE,t))}}else r.reject("Could not resolve RTMPPublisher instance. Requires minimum Flash Player install of ".concat(n));return r.promise}},{key:"publish",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=r||new S;this._setUpConnectCallback(n),this._options.streamName=t||this._options.streamName;var o=this._options;try{var i=this._sourceHandler;this._sourceHandler.getEmbedOperation().then((function(){p("RTMPPublisher","[handler:embed:complete]"),me.getEmbedObject(e._elementId)&&e._establishExtIntHandlers();var t=0;!function e(){var r;r=setTimeout((function(){try{clearTimeout(r),i.connect(JSON.stringify(o))}catch(r){if(t++>100)throw r;e()}}),300)}()})).catch((function(t){n.reject(t),e.trigger(new $t(Nt.CONNECT_FAILURE,e))}))}catch(e){y("RTMPPublisher","[handler:embed:error]"),n.reject("Could not initiate connection sequence. Reason: ".concat(e.message)),this.trigger(new $t(Nt.CONNECT_FAILURE,this)),this._tearDownConnectCallback()}return this._connectFuture=n,n.promise}},{key:"unpublish",value:function(){var e=new S;try{me.getEmbedObject(this._elementId).unpublish(),e.resolve()}catch(t){y("RTMPPublisher","Could not initiate publish sequence. Reason: ".concat(t.message)),e.reject(t.message)}return this._connectFuture=void 0,e.promise}},{key:"send",value:function(e,t){this._sourceHandler.send(e,"string"==typeof t?t:JSON.stringify(t))}},{key:"setMediaQuality",value:function(e){this._sourceHandler&&this._sourceHandler.setMediaQuality(e)}},{key:"overlayOptions",value:function(e){this._options=Object.assign(this._options,e)}},{key:"getConnection",value:function(){return this._sourceHandler}},{key:"getOptions",value:function(){return this._options}},{key:"getType",value:function(){return Za.RTMP.toUpperCase()}}])&&fs(t.prototype,r),n&&fs(t,n),Object.defineProperty(t,"prototype",{writable:!1}),i}(H);function bs(e){return(bs="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function gs(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function _s(e){for(var t=1;t=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),C(r),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;C(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:k(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},e}function js(e,t,r,n,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}function Hs(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:null,r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;p("R5ProPublishPeer","[createoffer]");var o=n||new S;return this._peerConnection.createOffer().then((function(n){e.setLocalDescription(n,t).then((function(){var i=n.sdp;t&&(i=ht(t,i)),r&&(i=st(i),i=ct(i),i=ft(i),i=dt(i)),n.sdp=i,e._responder.onSDPSuccess(),o.resolve(n)})).catch((function(t){e._responder.onSDPError(t),o.reject(t)}))})).catch((function(e){p("R5ProPublishPeer","[createoffer:error]"),o.reject(e)})),o.hasOwnProperty("promise")?o.promise:o}},{key:"createOfferWithoutSetLocal",value:(o=function(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){js(i,n,o,a,s,"next",e)}function s(e){js(i,n,o,a,s,"throw",e)}a(void 0)}))}}((function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return Ns().mark((function n(){var o,i;return Ns().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return p("R5ProPublishPeer","[createoffer:withoutlocal]"),n.prev=1,n.next=4,e._peerConnection.createOffer();case 4:return o=n.sent,i=o.sdp,t&&(i=ht(t,i)),r&&(i=st(i),i=ct(i),i=ft(i),i=dt(i)),o.sdp=i,e._responder.onSDPSuccess(),n.abrupt("return",o);case 13:throw n.prev=13,n.t0=n.catch(1),p("R5ProPublishPeer","[createoffer:error]"),e._responder.onSDPError(n.t0),n.t0;case 18:case"end":return n.stop()}}),n,null,[[1,13]])}))()})),function(){return o.apply(this,arguments)})},{key:"postUnpublish",value:function(e){var t=this.post({unpublish:e});return p("R5ProPublishPeer","[peerconnection:unpublish] complete: ".concat(t)),t}},{key:"postUnjoin",value:function(e,t){return p("R5ProPublishPeer","[peerconnection:leavegroup]"),this.post({leaveGroup:e,streamName:t})}}])&&Hs(t.prototype,r),n&&Hs(t,n),Object.defineProperty(t,"prototype",{writable:!1}),a}(Wn),Vs={endpoint:void 0,protocol:"wss",port:443,app:"live",streamMode:es.LIVE,keyFramerate:3e3,mediaElementId:"red5pro-publisher",rtcConfiguration:{iceServers:[{urls:"stun:stun2.l.google.com:19302"}],iceCandidatePoolSize:2,bundlePolicy:"max-bundle"},iceServers:void 0,iceTransport:po.UDP,bandwidth:{audio:56,video:512},clearMediaOnUnpublish:!1,mediaConstraints:new us,onGetUserMedia:void 0,signalingSocketOnly:!0,dataChannelConfiguration:void 0,forceVP8:!1,socketSwitchDelay:1e3,bypassAvailable:!1,stats:void 0};function Gs(e){return(Gs="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Ws(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function Ys(e){for(var t=1;t-1){if(t===Nt.STATISTICS_ENDPOINT_CHANGE){var o=n.statisticsEndpoint;r.updateEndpoint(o,!1)}r.postEvent(t)}})),t.on(Ht.HOST_ENDPOINT_CHANGED,(function(e){var t=e.data,n=t.endpoint,o=t.iceServers;r.appendClientDetails({node:n,iceServers:o})})),t.getPeerConnection()?r.start(r.client.getPeerConnection()):t.on(Ht.PEER_CONNECTION_AVAILABLE,(function(e){var t=e.data;r.start(t)})),r}return t=i,(r=[{key:"_handleStatsReport",value:function(e){var t=e.type,r=this.config.include,n=r&&r.length>0;if(n&&r.indexOf(t)>=-1)this.post(e);else if(!n)if(t===To.CODEC){var o=e.id,i=e.clockRate,a=e.mimeType,s=e.payloadType;this.post({id:o,type:t,clockRate:i,mimeType:a,payloadType:s})}else if(t===To.CANDIDATE_PAIR){var c=e.availableOutgoingBitrate,u=e.currentRoundTripTime,l=e.totalRoundTripTime,f=e.state;this.post({type:t,availableOutgoingBitrate:c,currentRoundTripTime:u,totalRoundTripTime:l,state:f})}else if(t===To.MEDIA_SOURCE){var d=e.kind;if("audio"===d)this.post({type:t,kind:d});else if("video"===d){var h=e.framesPerSecond,p=e.height,v=e.width;this.post({type:t,kind:d,framesPerSecond:h,height:p,width:v})}}else if([To.OUTBOUND,"outboundrtp"].indexOf(t)>-1){var y=e.timestamp,m=e.kind,b=e.codecId,g=e.mediaType,_=e.active,w=e.bytesSent,S={type:t,kind:m,codecId:b,mediaType:g,active:_,bytesSent:w,packetsSent:e.packetsSent,totalPacketsSendDelay:e.totalPacketsSendDelay};if("audio"===m){if(this.lastAudioReport){var E=this.lastAudioReport,C=8*(w-E.bytesSent)/(y-E.timestamp);this.estimatedAudioBitrate=C}this.post(Ys(Ys({},S),{},{estimatedBitrate:Math.floor(this.estimatedAudioBitrate)})),this.lastAudioReport=e}else if("video"===m){var O=e.firCount,k=e.pliCount,P=e.frameWidth,T=e.frameHeight,R=e.framesEncoded,A=e.framesPerSecond,L=e.framesSent,N=e.keyFramesEncoded,j=e.qualityLimitationReason,H=e.qualityLimitationDurations,I=Ys(Ys({},S),{},{firCount:O,pliCount:k,frameWidth:P,frameHeight:T,framesEncoded:R,framesPerSecond:A,framesSent:L,keyFramesEncoded:N});if("none"!==j&&(I=Ys(Ys({},I),{},{qualityLimitationReason:j,qualityLimitationDurations:H})),this.lastVideoReport){var x=this.lastVideoReport,D=8*(w-x.bytesSent)/(y-x.timestamp);this.estimatedVideoBitrate=D}this.post(Ys(Ys({},I),{},{estimatedBitrate:Math.floor(this.estimatedVideoBitrate)})),this.lastVideoReport=e}}}}])&&zs(t.prototype,r),n&&zs(t,n),Object.defineProperty(t,"prototype",{writable:!1}),i}(Fo);function rc(e){return(rc="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function nc(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function oc(e){for(var t=1;t=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),C(r),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;C(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:k(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},e}function sc(e,t,r,n,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}function cc(e,t){for(var r=0;r1)&&"video"===t[0].kind};void 0!==e.onGetUserMedia?(bc("Requesting gUM from user-defined configuration:onGetUserMedia."),e.onGetUserMedia().then((function(n){if(r(n))return bc("We received a MediaStream with mismatching track listing. Trying again..."),void t._gum(e);t.trigger(new $t(Ht.CONSTRAINTS_ACCEPTED,t,wc(n))),t._streamFuture.resolve(n)})).catch((function(r){_c("Could not resolve MediaStream from provided gUM. Error - ".concat(r)),t.trigger(new $t(Ht.CONSTRAINTS_REJECTED,t,{constraints:e.mediaConstraints})),t._streamFuture.reject(r)}))):(bc("Requesting gUM using mediaConstraints: ".concat(JSON.stringify(e.mediaConstraints,null,2))),this._peerHelper.getUserMedia(e.mediaConstraints,this._gUMRejectionHandler).then((function(n){if(r(n.media))return bc("We received a MediaStream with mismatching track listing. Trying again..."),void t._gum(e);bc("Found valid constraints: ".concat(JSON.stringify(n.constraints,null,2))),t.trigger(new $t(Ht.CONSTRAINTS_ACCEPTED,t,wc(n.media))),t.trigger(new $t(Nt.DIMENSION_CHANGE,t,n.constraints)),t._streamFuture.resolve(n.media)})).catch((function(r){bc("Could not find valid constraint resolutions from: ".concat(JSON.stringify(r.constraints,null,2))),_c("Could not resolve MediaStream from provided mediaConstraints. Error - ".concat(r.error)),bc("Attempting to find resolutions from original provided constraints: ".concat(JSON.stringify(r.constraints,null,2))),t.trigger(new $t(Ht.CONSTRAINTS_REJECTED,t,{constraints:r.constraints})),e.onGetUserMedia=function(){return t._peerHelper.forceUserMedia(r.constraints)},t._gum(e)})))}},{key:"_onGUMRejection",value:function(e){this.trigger(new $t(Ht.CONSTRAINTS_REJECTED,this,{constraints:e}))}},{key:"_onOrientationChange",value:function(e){this.getMessageTransport()&&this.getMessageTransport().post({send:{method:"onMetaData",data:{deviceOrientation:e}}})}},{key:"_onMediaStreamReceived",value:function(e){this._mediaStream=e,this.trigger(new $t(Ht.MEDIA_STREAM_AVAILABLE,this,e)),this._view&&this._view.preview(this._mediaStream)}},{key:"_setViewIfNotExist",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;if(void 0===e&&void 0!==t){var r=new $a(t);r.attachPublisher(this)}}},{key:"_requestAvailability",value:function(e){return bc("[requestavailability]"),this._availableFuture=E.createIfNotExist(this._availableFuture),this._options.bypassAvailable?this._availableFuture.resolve(!0):this._socketHelper.post({isAvailable:e,bundle:!0}),this._availableFuture.promise}},{key:"_createPeerConnection",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;return bc("[createpeeer]"),this._peerFuture=void 0,this._peerFuture=E.createIfNotExist(this._peerFuture),r&&e&&(gc("The iceServers configuration property is considered deprecated. Please use the rtcConfiguration configuration property upon which you can assign iceServers. Reference: https://www.red5pro.com/docs/streaming/migrationguide.html"),e.iceServers=r),void 0!==e?this._peerHelper.setUpWithPeerConfiguration(e,t,this._peerFuture):this._peerHelper.setUp(r,this._peerFuture,this._options.rtcpMuxPolicy)}},{key:"_createOffer",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return bc("[createoffer]"),this._offerFuture=void 0,this._offerFuture=E.createIfNotExist(this._offerFuture),this._peerHelper.createOffer(e,t,!1,this._offerFuture),this._offerFuture.promise}},{key:"_setRemoteDescription",value:function(e){return bc("[setremotedescription]"),this._peerHelper.setRemoteDescription(e)}},{key:"_sendOffer",value:function(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];bc("[sendoffer]");var o={handleOffer:t,transport:r,data:{sdp:e}};return n&&(o.videoEncoding=ts.VP8),this._sendOfferFuture=void 0,this._sendOfferFuture=E.createIfNotExist(this._sendOffFuture),this._socketHelper.post(o),this._sendOfferFuture.promise}},{key:"_sendCandidate",value:function(e,t){bc("[sendcandidate]"),this._socketHelper.post({handleCandidate:t,data:{candidate:e}})}},{key:"_requestPublish",value:function(e,t,r){return bc("[requestpublish]"),this._publishFuture=void 0,this._publishFuture=E.createIfNotExist(this._publishFuture),this._socketHelper.post({publish:e,mode:t,keyFramerate:r}),this._publishFuture.promise}},{key:"_requestUnpublish",value:function(e){return this._unpublishFuture=void 0,this._unpublishFuture=E.createIfNotExist(this._unpublishFuture),this.getMessageTransport().postUnpublish(e)||this._unpublishFuture.resolve(),this._unpublishFuture.promise}},{key:"_setUpMediaTransform",value:(o=function(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){sc(i,n,o,a,s,"next",e)}function s(e){sc(i,n,o,a,s,"throw",e)}a(void 0)}))}}(ac().mark((function e(t,r,n){var o,i,a,s,c,u,l,f;return ac().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t){e.next=16;break}if(o=this._mediaTransform,i=o.audio,a=o.video,s=o.worker,c=r.getSenders().find((function(e){return e.track&&"video"===e.track.kind})),u=r.getSenders().find((function(e){return e.track&&"audio"===e.track.kind})),!c||!a&&!s){e.next=15;break}return e.prev=5,e.next=8,Eo(t,c,n);case 8:(l=e.sent).generator&&(this._mediaStream.addTrack(l.generator),this._mediaStream.removeTrack(this._mediaStream.getVideoTracks()[0])),e.next=15;break;case 12:e.prev=12,e.t0=e.catch(5),this.trigger(new $t(Ht.TRANSFORM_ERROR,this,{type:"video",error:e.t0}));case 15:if(u&&(i||s))try{(f=Oo(t,u,n)).generator&&(this._mediaStream.addTrack(f.generator),this._mediaStream.removeTrack(this._mediaStream.getAudioTracks()[0]))}catch(e){this.trigger(new $t(Ht.TRANSFORM_ERROR,this,{type:"audio",error:e}))}case 16:case"end":return e.stop()}}),e,this,[[5,12]])}))),function(e,t,r){return o.apply(this,arguments)})},{key:"init",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;this._streamFuture=void 0;var r=new S,n=e.stats;return We()&&Lt()?(this._options=oc(oc({},mc),e),this._peerHelper=new Bs(this),this._socketHelper=new As(this),this._messageTransport=this._messageTransport||this._socketHelper,this._mediaTransform=t,this._mediaTransform&&!Ke()&&(this.trigger(new $t(Ht.UNSUPPORTED_FEATURE,this,{feature:"Insertable Streams",message:"You provided Media Transforms for track processing, but your current browser does not support the Insertable Streams API."})),this._mediaTransform=void 0),n&&this.monitorStats(n),this._getMediaStream().then(this._onMediaStreamReceived.bind(this)).catch((function(e){gc("[gum]: ".concat(e))})),this._gum(this._options),this._setViewIfNotExist(this._view,this._options.mediaElementId),r.resolve(this)):r.reject("Cannot create WebRTC playback instance. Your environment does not support WebRTC and/or WebSockets."),r.promise}},{key:"initWithStream",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;bc("[initWithStream]"),this._streamFuture=void 0;var n=new S,o=e.stats;if(We()&&Lt()){this._mediaTransform=r,this._mediaTransform&&!Ke()&&(this.trigger(new $t(Ht.UNSUPPORTED_FEATURE,this,{feature:"Insertable Streams",message:"You provided Media Transforms for track processing, but your current browser does not support the Insertable Streams API."})),this._mediaTransform=void 0),o&&this.monitorStats(o),this._options=oc(oc({},mc),e),this._peerHelper=new Bs(this),this._socketHelper=new As(this),this._messageTransport=this._messageTransport||this._socketHelper,this._setViewIfNotExist(this._view,this._options.mediaElementId);var i=this._getMediaStream();i.then(this._onMediaStreamReceived.bind(this)).catch((function(e){gc("[gum]: ".concat(e))})),this._streamFuture.resolve(t),n.resolve(this)}else n.reject("Cannot create WebRTC playback instance. Your environment does not support WebRTC and/or WebSockets.");return n.promise}},{key:"setView",value:function(e){return this._view=e,this._mediaStream&&this._view&&this._view.preview(this._mediaStream),this}},{key:"preview",value:function(){var e=this;bc("[preview]");var t=new Promise((function(t){t(e)}));return this._setViewIfNotExist(this._view,this._options.mediaElementId),t}},{key:"unpreview",value:function(){bc("[unpreview]"),this._mediaStream&&this._mediaStream.getTracks().forEach((function(e){e.stop()})),this._view&&this._view.unpreview(),this._view=void 0}},{key:"publish",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;bc("[publish]"),this._options.streamName=t||this._options.streamName;var n=r||new S,o=new S,i=ao(this._options,{id:this._options.streamName});this._trickleEndFuture=this._getTrickleEnd(),this._peerHelper||(this._peerHelper=new Bs(this)),this._socketHelper?this._socketHelper.clearRetry():(this._socketHelper=new As(this),this._messageTransport=this._socketHelper),this._socketHelper.setUp(i,o);var a=this._options,s=a.rtcConfiguration,c=a.signalingSocketOnly,u=a.dataChannelConfiguration,l=c&&Ye();return l&&!u&&(u={name:"red5pro"}),this._options.signalingSocketOnly=l,this._publishFuture=E.createIfNotExist(this._publishFuture),this._publishFuture.promise.catch((function(t){me.removeOrientationChangeHandler(e._onOrientationChange),n.reject(t),e.trigger(new $t(Nt.CONNECT_FAILURE,e,t))})),o.promise.then((function(){return e.trigger(new $t(Nt.CONNECT_SUCCESS,e)),e._getMediaStream()})).then((function(){return e._requestAvailability(e._options.streamName,e._options.streamType)})).then((function(){var t=s;return void 0===s.encodedInsertableStreams&&(t=Object.assign(s,{encodedInsertableStreams:!!e._mediaTransform})),e._createPeerConnection(t,u,e._options.iceServers)})).then((function(t){if(e.trigger(new $t(Ht.PEER_CONNECTION_AVAILABLE,e,t)),e._mediaStream.getTracks().forEach((function(r){t.addTrack(r,e._mediaStream)})),e._options.forceVP8){var r=e._mediaStream,n=RTCRtpSender.getCapabilities("video").codecs,o=n.findIndex((function(e){return"video/VP8"===e.mimeType}));if(o>-1){var i=n[o];n.splice(o,1),n.unshift(i),t.getTransceivers().find((function(e){return e.sender&&e.sender.track===r.getVideoTracks()[0]})).setCodecPreferences(n)}}return e._createOffer(e._options.bandwidth,e._options.forceVP8)})).then((function(t){var r=e._options,n=r.streamName,o=r.iceTransport,i=r.forceVP8;return e.trigger(new $t(Ht.OFFER_START,e,t)),e._sendOffer(t,n,o,i)})).then((function(t){return e._setRemoteDescription(t.sdp)})).then((function(t){return e.trigger(new $t(Ht.OFFER_END,e,t)),e._getTrickleEnd().promise})).then((function(){return e.trigger(new $t(Ht.ICE_TRICKLE_COMPLETE,e)),e._requestPublish(e._options.streamName,e._options.streamMode,e._options.keyFramerate)})).then((function(){e._setUpMediaTransform(e._mediaTransform,e.getPeerConnection(),e.getMediaStream()),me.addOrientationChangeHandler(e._onOrientationChange),n.resolve(e),e.trigger(new $t(Nt.PUBLISH_START,e))})).catch((function(t){me.removeOrientationChangeHandler(e._onOrientationChange),n.reject(t),e.trigger(new $t(Nt.CONNECT_FAILURE,e,t))})),n.hasOwnProperty("promise")?n.promise:n}},{key:"publishWithSocket",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;bc("[publishWithSocket]"),this._options.streamName=r||this._options.streamName;var o=n||new S,i=new S;return this._socketHelper=new As(this),this._socketHelper.setUpWithSocket(e,i),i.promise.then((function(){return t._requestPublish(t._options.streamName,t._options.streamMode,t._options.keyFramerate)})).then((function(){me.addOrientationChangeHandler(t._onOrientationChange),o.resolve(t),t.trigger(new $t(Nt.PUBLISH_START,t))})).catch((function(e){me.removeOrientationChangeHandler(t._onOrientationChange),o.reject(e),t.trigger(new $t(Nt.CONNECT_FAILURE,t,e))})),o.hasOwnProperty("promise")?o.promise:o}},{key:"unpublish",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];bc("[unpublish]");var r=function(){e._socketHelper&&(bc("[unpublish:teardown]"),e._socketHelper.tearDown()),e._peerHelper&&e._peerHelper.tearDown(),e._socketHelper=void 0,e._peerHelper=void 0,e._messageTransport=void 0};(this._options.clearMediaOnUnpublish||t)&&this.unpreview(),this._availableFuture=void 0,this._peerFuture=void 0,this._offerFuture=void 0,this._sendOfferFuture=void 0,this._trickleEndFuture=void 0,this._publishFuture=void 0;var n=this._requestUnpublish(this._options.streamName,this._options.groupName);return n.then((function(){e._unpublishFuture=void 0,r(),e.trigger(new $t(Nt.UNPUBLISH_SUCCESS,e)),e.unmonitorStats()})).catch((function(){e.unmonitorStats()})),me.removeOrientationChangeHandler(this._onOrientationChange),n}},{key:"monitorStats",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this._options,r=t.host,n=t.app,o=t.streamName,i=t.connectionParams;return this._statisticsConfiguration=oc(oc({},e),{host:r,app:n,streamName:o,connectionParams:i}),this._statsMonitor?gc("RTCPublisher"):this._statsMonitor=new tc(this._statisticsConfiguration,this),this}},{key:"unmonitorStats",value:function(){return this._statsMonitor&&(this._statsMonitor.dispose(),this._statsMonitor=void 0),this._statisticsConfiguration=void 0,this}},{key:"mute",value:function(){this.muteAudio()}},{key:"unmute",value:function(){this.unmuteAudio()}},{key:"muteAudio",value:function(){this.getMessageTransport().post({mute:{muteAudio:!0}})}},{key:"unmuteAudio",value:function(){this.getMessageTransport().post({mute:{muteAudio:!1}})}},{key:"muteVideo",value:function(){this.getMessageTransport().post({mute:{muteVideo:!0}})}},{key:"unmuteVideo",value:function(){this.getMessageTransport().post({mute:{muteVideo:!1}})}},{key:"send",value:function(e,t){this.getMessageTransport().post({send:{method:e,data:"string"==typeof t?JSON.parse(t):t}})}},{key:"callServer",value:function(e,t){return this.getMessageTransport().postAsync({callAdapter:{method:e,arguments:t}})}},{key:"sendLog",value:function(e,t){try{var r=Object.keys(l).find((function(t){return t.toLowerCase()===e.toLowerCase()}))?e:l.DEBUG,n="string"==typeof t?t:JSON.stringify(t);this.getMessageTransport().post({log:r.toUpperCase(),message:n})}catch(e){e.message,_c("RTCPublisher"),_c("RTCPublisher")}}},{key:"onStreamAvailable",value:function(e){bc("[onstreamavailable]: "+JSON.stringify(e,null,2)),this._availableFuture=E.createIfNotExist(this._availableFuture),this._availableFuture.reject("Stream with name ".concat(this._options.streamName," already has a broadcast session.")),this.trigger(new $t(Nt.PUBLISH_INVALID_NAME,this))}},{key:"onStreamUnavailable",value:function(e){bc("Stream ".concat(this._options.streamName," does not exist.")),bc("[onstreamunavailable]: "+JSON.stringify(e,null,2)),this._availableFuture=E.createIfNotExist(this._availableFuture),this._availableFuture.resolve(!0)}},{key:"onSocketMessage",value:function(e,t){this.trigger(new $t(Ht.SOCKET_MESSAGE,this,{socket:e,message:t}))}},{key:"onSocketMessageError",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;_c("Error in stream publish: ".concat(e,".\n[Optional detail]: ").concat(t)),this._publishFuture&&(this.trigger(new $t(Nt.PUBLISH_FAIL,this)),this._publishFuture.reject(e),this.unpublish())}},{key:"onSocketClose",value:function(e){bc("[onsocketclose]"),this._peerHelper&&this._peerHelper.tearDown(),this.trigger(new $t(Nt.CONNECTION_CLOSED,this,e))}},{key:"onConnectionClosed",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;this._connectionClosed||(bc("RTCPublisher"),this.unpublish(),this.trigger(new $t(Nt.CONNECTION_CLOSED,this,e)))}},{key:"onPeerConnectionFail",value:function(){bc("[onpeerconnectionfail]"),this.trigger(new $t(Nt.PUBLISH_FAIL,this)),this._publishFuture&&this._publishFuture.reject("Peer Connection Failed.")}},{key:"onPeerConnectionClose",value:function(e){bc("[onpeerconnectionclose]"),this._socketHelper&&(bc("[onpeerconnectionclose:teardown]"),this._socketHelper.tearDown()),this.onSocketClose(e)}},{key:"onPeerConnectionOpen",value:function(){bc("[onpeerconnection::open]"),this.trigger(new $t(Ht.PEER_CONNECTION_OPEN),this,this.getPeerConnection())}},{key:"onPeerConnectionTrackAdd",value:function(e){bc("[onpeerconnection::track]"),this.trigger(new $t(Ht.TRACK_ADDED,this,{track:e}))}},{key:"onSDPSuccess",value:function(e){var t=e?": "+JSON.stringify(e,null,2):"";bc("[onsdpsuccess]".concat(t))}},{key:"onSDPError",value:function(e){this.trigger(new $t(Nt.PUBLISH_FAIL,this));var t=e?": "+JSON.stringify(e,null,2):"";_c("[onsdperror]".concat(t))}},{key:"onSDPAnswer",value:function(e){bc("[sdpanswer]:: "+JSON.stringify(e,null,2)),this._sendOfferFuture=E.createIfNotExist(this._sendOfferFuture),this._sendOfferFuture.resolve(e)}},{key:"onAddIceCandidate",value:function(e){bc("[addicecandidate]"),this._peerHelper.addIceCandidate(e).then((function(){bc("[addicecandidate:success]")})).catch((function(e){gc("[addicecandidate:error] - ".concat(e))}))}},{key:"onIceCandidate",value:function(e){bc("[icecandidatetrickle]"),this._sendCandidate(e,this._options.streamName)}},{key:"onIceCandidateTrickleEnd",value:function(){bc("[icecandidatetrickle:end]")}},{key:"onEmptyCandidate",value:function(){bc("[icecandidatetrickle:empty]"),this.trigger(new $t(Ht.PEER_CANDIDATE_END))}},{key:"onPeerGatheringComplete",value:function(){bc("[icecandidategathering:end]"),this._socketHelper&&this._socketHelper.postEndOfCandidates(this._options.streamName)}},{key:"onSocketIceCandidateEnd",value:function(){bc("[socketicecandidate:end]"),this._getTrickleEnd().resolve()}},{key:"onPublisherStatus",value:function(e){bc("[publisherstatus] - "+JSON.stringify(e,null,2));var t=yc.exec(e.message),r=vc.exec(e.message);t&&t[1]===this._options.streamName?this._unpublishFuture.resolve():r&&r[1]===this._options.streamName?this._publishFuture.resolve():e.code&&"NetStream.Publish.IsAvailable"===e.code?this.trigger(new $t(Nt.PUBLISH_AVAILABLE,this.status)):this.trigger(new $t(Nt.PUBLISH_STATUS,this,e))}},{key:"onInsufficientBandwidth",value:function(e){this.trigger(new $t(Nt.PUBLISH_INSUFFICIENT_BANDWIDTH,this,e))}},{key:"onSufficientBandwidth",value:function(e){this.trigger(new $t(Nt.PUBLISH_SUFFICIENT_BANDWIDTH,this,e))}},{key:"onRecoveringBandwidth",value:function(e){this.trigger(new $t(Nt.PUBLISH_RECOVERING_BANDWIDTH,this,e))}},{key:"onSendReceived",value:function(e,t){"onMetaData"===e?this.onMetaData(t):this.trigger(new $t(Nt.PUBLISH_SEND_INVOKE,this,{methodName:e,data:t}))}},{key:"onStatisticsEndpoint",value:function(e){this.trigger(new $t(Nt.STATISTICS_ENDPOINT_CHANGE,this,{statisticsEndpoint:e}))}},{key:"onDataChannelAvailable",value:function(e){var t=this;if(bc("[ondatachannel::available]"),this._switchChannelRequest={switchChannel:e||"red5pro"},this._options.signalingSocketOnly)var r=setTimeout((function(){clearTimeout(r),t._socketHelper&&t._socketHelper.sever(t._switchChannelRequest),t._messageTransport=t._peerHelper,t.trigger(new er(Ut.CHANGE,t,{controller:t,transport:t._messageTransport}))}),this._socketHelper?this._options.socketSwitchDelay:100);this.trigger(new $t(Ht.DATA_CHANNEL_AVAILABLE,this,{name:e,dataChannel:this.getDataChannel()}))}},{key:"onDataChannelError",value:function(e,t){this.trigger(new $t(Ht.DATA_CHANNEL_ERROR,this,{dataChannel:e,error:t}))}},{key:"onDataChannelMessage",value:function(e,t){this.trigger(new $t(Ht.DATA_CHANNEL_MESSAGE,this,{dataChannel:e,message:t}))}},{key:"onDataChannelOpen",value:function(e){this.trigger(new $t(Ht.DATA_CHANNEL_OPEN,this,{dataChannel:e}))}},{key:"onDataChannelClose",value:function(e){this.trigger(new $t(Ht.DATA_CHANNEL_CLOSE,this,{dataChannel:e}))}},{key:"onMetaData",value:function(e){this.trigger(new $t(Nt.PUBLISH_METADATA,this,e))}},{key:"onStatsReport",value:function(e,t){this.trigger(new $t(Ht.STATS_REPORT,this,{connection:e,report:t}))}},{key:"overlayOptions",value:function(e){this._options=Object.assign(this._options,e)}},{key:"getMessageTransport",value:function(){return this._messageTransport}},{key:"getConnection",value:function(){return this._socketHelper}},{key:"getPeerConnection",value:function(){return this._peerHelper?this._peerHelper.connection:void 0}},{key:"getDataChannel",value:function(){return this._peerHelper?this._peerHelper.dataChannel:void 0}},{key:"getMediaStream",value:function(){return this._mediaStream}},{key:"getOptions",value:function(){return this._options}},{key:"getType",value:function(){return Za.RTC.toUpperCase()}}])&&cc(t.prototype,r),n&&cc(t,n),Object.defineProperty(t,"prototype",{writable:!1}),a}(H);function Ec(e){return(Ec="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Cc(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */Cc=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function u(e,t,r,o){var i=t&&t.prototype instanceof d?t:d,a=Object.create(i.prototype),s=new O(o||[]);return n(a,"_invoke",{value:w(e,r,s)}),a}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var f={};function d(){}function h(){}function p(){}var v={};c(v,i,(function(){return this}));var y=Object.getPrototypeOf,m=y&&y(y(k([])));m&&m!==t&&r.call(m,i)&&(v=m);var b=p.prototype=d.prototype=Object.create(v);function g(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function _(e,t){var o;n(this,"_invoke",{value:function(n,i){function a(){return new t((function(o,a){!function n(o,i,a,s){var c=l(e[o],e,i);if("throw"!==c.type){var u=c.arg,f=u.value;return f&&"object"==Ec(f)&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,a,s)}),(function(e){n("throw",e,a,s)})):t.resolve(f).then((function(e){u.value=e,a(u)}),(function(e){return n("throw",e,a,s)}))}s(c.arg)}(n,i,o,a)}))}return o=o?o.then(a,a):a()}})}function w(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return P()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var s=S(a,r);if(s){if(s===f)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=l(e,t,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===f)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function S(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,S(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),f;var o=l(n,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,f;var i=o.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,f):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,f)}function E(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 C(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function O(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(E,this),this.reset(!0)}function k(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 n=-1,o=function t(){for(;++n=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),C(r),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;C(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:k(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},e}function Oc(e,t,r,n,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}function kc(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){Oc(i,n,o,a,s,"next",e)}function s(e){Oc(i,n,o,a,s,"throw",e)}a(void 0)}))}}function Pc(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Tc(e,t){for(var r=0;r2&&void 0!==arguments[2])||arguments[2];Pc(this,h),r=d.call(this);var o=e?co(e):Fc;return o.mediaElementId=t?t.id:Fc.mediaElementId,o.trickleIce=n,r._whipHelper=void 0,e&&r._internalConnect(o),r}return t=h,(r=[{key:"_internalConnect",value:(f=kc(Cc().mark((function e(t){return Cc().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.init(t);case 2:return e.next=4,this.publish();case 4:case"end":return e.stop()}}),e,this)}))),function(e){return f.apply(this,arguments)})},{key:"waitToGatherIce",value:(l=kc(Cc().mark((function e(t){return Cc().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Uc("[waittogatherice]"),e.abrupt("return",new Promise((function(e,r){if("complete"===t.iceGatheringState)Uc("[waittogatherice] ice gathering state complete."),t.addIceCandidate(null).then((function(){e(t.localDescription)})).catch((function(r){Bc("Error adding null candidate: "+r.message||!1),e(t.localDescription)}));else{Uc("[waittogatherice] waiting...");var n=setTimeout((function(){clearTimeout(n),t.addIceCandidate(null).then((function(){e(t.localDescription)})).catch((function(r){Bc("Error adding null candidate: "+r.message||!1),e(t.localDescription)}))}),1e3);t.onicegatheringstatechange=function(){clearTimeout(n),Uc("[waittogatherice] ice gathering state complete."),"complete"===t.iceGatheringState&&t.addIceCandidate(null).then((function(){e(t.localDescription)})).catch((function(r){Bc("Error adding null candidate: "+r.message||!1),e(t.localDescription)}))}}})));case 2:case"end":return e.stop()}}),e)}))),function(e){return l.apply(this,arguments)})},{key:"_postOffer",value:(u=kc((function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return Cc().mark((function n(){var o,i,a,s,c,u,l,f,d;return Cc().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,o=e.sdp,i=t._options,a=i.mungeOffer,s=i.streamMode,c=i.keyFramerate,u=i.connectionParams,l=i.forceVP8,f=o,a&&(f=a(f)),r||(f=rt(f),f=ot(f)),d=xc(xc({},u),{},{mode:s,keyFramerate:c}),l&&(d.videoEncoding=ts.VP8),n.next=10,t._whipHelper.postSDPOffer(f,d);case 10:return n.abrupt("return",n.sent);case 13:throw n.prev=13,n.t0=n.catch(0),Vc(n.t0.message||n.t0),n.t0 instanceof U?t.onStreamAvailable(n.t0):t._publishFuture?t._publishFuture.reject(n.t0.message||n.t0):(t.trigger(new $t(Nt.CONNECT_FAILURE,t,Vc)),t.unpublish()),n.t0;case 18:case"end":return n.stop()}}),n,null,[[0,13]])}))()})),function(e){return u.apply(this,arguments)})},{key:"_postCandidateFragments",value:(c=kc(Cc().mark((function e(t){var r,n;return Cc().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=this._options.connectionParams,n=_t(t,void 0,!0),e.next=4,this._whipHelper.trickle(n,r);case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"_sendCandidate",value:function(e,t){Uc(JSON.stringify(e,null,2))}},{key:"_switchWhipWhepHandler",value:function(e){this._options.host=e,this._options.protocol="ws",this._options.port=5080;var t=this._options,r=t.protocol,n=t.host,o=t.port,i=t.app,a=t.streamName,s=t.enableChannelSignaling,c=t.disableProxy,u=r.match(/^http/)?r:"ws"===r?"http":"https";this._whipUrl="".concat(u,"://").concat(n,":").concat(o,"/").concat(i,"/whip/endpoint/").concat(a),this._whipHelper=new da(this._whipUrl,s,c)}},{key:"init",value:(s=kc(Cc().mark((function e(t){var r,n,o,i,a,s,c,u,l;return Cc().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this._options=xc(xc({},Fc),t),r=this._options,n=r.protocol,o=r.host,i=r.port,a=r.app,s=r.streamName,c=r.enableChannelSignaling,u=r.disableProxy,l=n.match(/^http/)?n:"ws"===n?"http":"https",this._whipUrl=t.endpoint?t.endpoint:"".concat(l,"://").concat(o,":").concat(i,"/").concat(a,"/whip/endpoint/").concat(s),this._whipHelper=new da(this._whipUrl,c,u),this._messageTransport=this._whipHelper,e.abrupt("return",Rc(Hc(h.prototype),"init",this).call(this,this._options));case 7:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"initWithStream",value:(a=kc(Cc().mark((function e(t,r){var n,o,i,a,s,c,u,l,f;return Cc().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this._options=xc(xc({},Fc),t),n=this._options,o=n.protocol,i=n.host,a=n.port,s=n.app,c=n.streamName,u=n.enableChannelSignaling,l=n.disableProxy,f="ws"===o?"http":"https",this._whipUrl=t.endpoint?t.endpoint:"".concat(f,"://").concat(i,":").concat(a,"/").concat(s,"/whip/endpoint/").concat(c),this._whipHelper=new da(this._whipUrl,u,l),this._messageTransport=this._whipHelper,e.abrupt("return",Rc(Hc(h.prototype),"initWithStream",this).call(this,this._options,r));case 7:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"publish",value:(i=kc((function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return Cc().mark((function n(){var o,i,a,s,c,u,l,f,d,h,p,v,y,m,b,g,_,w,S,E,C;return Cc().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return o=e._options,i=o.bandwidth,a=o.forceVP8,s=o.rtcConfiguration,c=o.enableChannelSignaling,u=o.dataChannelConfiguration,l=o.trickleIce,f=o.mungeAnswer,d=o.connectionParams,(h=c&&Ye())&&!u&&(u={name:"red5pro"},e._options.dataChannelConfiguration=u),e._options.enableChannelSignaling=h,e._options.signalingSocketOnly=e._options.enableChannelSignaling,n.prev=5,p=d||{},t&&(e._options.streamName=t),d&&(v=d.transcode)&&(p.transcode=v),n.next=11,e._whipHelper.getOptions(p);case 11:return(y=n.sent)&&(y.links&&(e._options.rtcConfiguration=xc(xc({},s),{},{iceServers:y.links})),y.origin&&e.trigger(new $t(Ht.HOST_ENDPOINT_CHANGED,e,{endpoint:y.origin,iceServers:y.links})),y.statisticsEndpoint&&e.trigger(new $t(Nt.STATISTICS_ENDPOINT_CHANGE,e,{statisticsEndpoint:y.statisticsEndpoint}))),m=e._options.enableChannelSignaling?u:void 0,n.next=16,e._createPeerConnection(s,m,e._options.iceServers);case 16:return b=n.sent,e.trigger(new $t(Ht.PEER_CONNECTION_AVAILABLE,e,b)),n.next=20,e._getMediaStream();case 20:return n.sent.getTracks().forEach((function(e){var t=b.addTransceiver(e,{direction:"sendonly"});if(t&&"video"===e.kind&&a)try{var r=RTCRtpSender.getCapabilities("video").codecs,n=r.findIndex((function(e){return"video/VP8"===e.mimeType}));if(n>-1){var o=r[n];r.splice(n,1),r.unshift(o),t.setCodecPreferences(r)}}catch(e){Uc("[forceVP8] Could not set codec preferences. ".concat(e.message||e))}})),n.next=24,e._peerHelper.createOfferWithoutSetLocal(i,a);case 24:return g=n.sent,n.next=27,e._peerHelper.setLocalDescription(g);case 27:if(l){n.next=31;break}return n.next=30,e.waitToGatherIce(b);case 30:g=n.sent;case 31:return e.trigger(new $t(Ht.OFFER_START,e,g)),n.next=34,e._postOffer(g,l);case 34:return _=n.sent,w=_.sdp,S=f?f(w):w,n.next=39,e._setRemoteDescription({type:"answer",sdp:it(S)});case 39:if(e.trigger(new $t(Ht.OFFER_END,e,S)),!l){n.next=47;break}return n.next=43,e.waitToGatherIce(b);case 43:return E=n.sent,C=E.sdp,n.next=47,e._postCandidateFragments(C);case 47:return e.trigger(new $t(Ht.ICE_TRICKLE_COMPLETE,e)),me.addOrientationChangeHandler(e._onOrientationChange),e._options.enableChannelSignaling||e.trigger(new $t(Nt.PUBLISH_START,e)),r&&r.resolve(e),n.abrupt("return",e);case 54:throw n.prev=54,n.t0=n.catch(5),Vc(n.t0),me.removeOrientationChangeHandler(e._onOrientationChange),e.trigger(new $t(Nt.CONNECT_FAILURE,e,n.t0)),r&&r.reject(n.t0),n.t0;case 61:case"end":return n.stop()}}),n,null,[[5,54]])}))()})),function(){return i.apply(this,arguments)})},{key:"unpublish",value:(o=kc((function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return Cc().mark((function r(){return Cc().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return Uc("[unpublish:teardown]"),e._whipHelper&&e._whipHelper.tearDown(),e._peerHelper&&e._peerHelper.tearDown(),e._whipHelper=void 0,e._peerHelper=void 0,e._messageTransport=void 0,(e._options.clearMediaOnUnpublish||t)&&e.unpreview(),e.trigger(new $t(Nt.UNPUBLISH_SUCCESS,e)),e.unmonitorStats(),me.removeOrientationChangeHandler(e._onOrientationChange),r.abrupt("return",e);case 11:case"end":return r.stop()}}),r)}))()})),function(){return o.apply(this,arguments)})},{key:"onDataChannelOpen",value:function(e){var t=this._options.dataChannelConfiguration;if(Rc(Hc(h.prototype),"onDataChannelOpen",this).call(this,e),t){var r=t.name;Rc(Hc(h.prototype),"onDataChannelAvailable",this).call(this,r)}else Rc(Hc(h.prototype),"onDataChannelAvailable",this).call(this);this.trigger(new $t(Nt.PUBLISH_START,this))}},{key:"getConnection",value:function(){}}])&&Tc(t.prototype,r),n&&Tc(t,n),Object.defineProperty(t,"prototype",{writable:!1}),h}(Sc);function Wc(e){return(Wc="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Yc(e){return function(e){if(Array.isArray(e))return zc(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return zc(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return zc(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function zc(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r-1;){var n=new AudioContext,o=n.createMediaStreamDestination();n.createMediaStreamSource(e).connect(o),e.addTrack(o.stream.getAudioTracks()[0])}}},{key:"_createOffer",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return p("[createoffer]"),this._offerFuture=void 0,this._offerFuture=E.createIfNotExist(this._offerFuture),this._peerHelper.createOffer(e,t,!0,this._offerFuture),this._offerFuture.promise}},{key:"_sendOffer",value:function(e,t,r){var n=this._options.groupName;return this._sendOfferFuture=void 0,this._sendOfferFuture=E.createIfNotExist(this._sendOffFuture),this._socketHelper.post({joinGroup:n,streamName:t,transport:r,data:{sdp:e}}),this._sendOfferFuture.promise}},{key:"_requestPublish",value:function(e,t,r){var n=this._options.autoGenerateMediaStream;return this._publishFuture=void 0,this._publishFuture=E.createIfNotExist(this._publishFuture),this._publishFuture.resolve(),n&&(this._conferenceStream=this._startReceivers(),this.trigger(new tr(Bt.MEDIA_STREAM,this,{stream:this._conferenceStream}))),this._publishFuture.promise}},{key:"unpublish",value:function(){return this._conferenceStream&&this._conferenceStream.getTracks().forEach((function(e){return e.stop()})),nu(cu(i.prototype),"unpublish",this).call(this)}},{key:"_requestUnpublish",value:function(e){var t=this._options.groupName;return this._unpublishFuture=void 0,this._unpublishFuture=E.createIfNotExist(this._unpublishFuture),this.getMessageTransport().postUnjoin(t,e)||this._unpublishFuture.resolve(),this._unpublishFuture.promise}},{key:"_startReceivers",value:function(){var e=this.getPeerConnection().getTransceivers().map((function(e){if("recvonly"===e.currentDirection)return e.receiver.track})).filter((function(e){return e})),t=this._options.mixAudioDown,r=this._conferenceStream||new MediaStream;if(t){var n=new AudioContext,o=e.map((function(e){if("audio"===e.kind)return n.createMediaStreamSource(new MediaStream([e]))})).filter((function(e){return e})),i=n.createMediaStreamDestination();o.forEach((function(e){return e.connect(i)})),i.stream.getTracks().forEach((function(e){return r.addTrack(e)}))}else e.forEach((function(e){return r.addTrack(e)}));return e.forEach((function(e){"video"===e.kind&&r.addTrack(e)})),r}},{key:"init",value:function(e){return nu(cu(i.prototype),"init",this).call(this,Object.assign(fu,e))}},{key:"initWithStream",value:function(e,t){return nu(cu(i.prototype),"initWithStream",this).call(this,Object.assign(fu,e),t)}},{key:"onPeerConnectionTrackAdd",value:function(e){var t=this._options.autoGenerateMediaStream;t&&"audio"===e.kind?this._audioTracks.push(e):t&&"video"===e.kind&&this._videoTracks.push(e),nu(cu(i.prototype),"onPeerConnectionTrackAdd",this).call(this,e)}},{key:"_onMediaStreamReceived",value:function(e){this._packStreamWithAudio(e,3),nu(cu(i.prototype),"_onMediaStreamReceived",this).call(this,e)}},{key:"onSDPAnswer",value:function(e){var t=this._options.streamName;this.overlayOptions({streamName:e.participantId,participantId:e.participantId,publisherName:t}),this._sendOfferFuture=E.createIfNotExist(this._sendOfferFuture),this._sendOfferFuture.resolve(e)}},{key:"onPublisherStatus",value:function(e){p(this._name,"[publisherstatus] - "+JSON.stringify(e,null,2));var t=lu.exec(e.message),r=uu.exec(e.message);t&&t[1]===this._options.groupName?this._unpublishFuture.resolve():r&&r[1]===this._options.streamName?this._publishFuture.resolve():v(this._name,"Publisher status received, but could not handle.")}}])&&ru(t.prototype,r),n&&ru(t,n),Object.defineProperty(t,"prototype",{writable:!1}),i}(Sc),hu=Wa,pu=hi,vu=Na,yu=ji,mu=$i,bu=eu,gu=Sc,_u=Gc,wu=ms,Su=Nt,Eu=Ht,Cu=jt,Ou=xt,ku=Mt,Pu=Ft,Tu=Dt,Ru=Ut,Au=Bt,Lu=fo,Nu=ho,ju=po,Hu=vo;f("".concat("error")||!1);var Iu=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];l.hasOwnProperty(e.toUpperCase())&&(f(e,t),console&&console.log("Red5 Pro SDK Version ".concat("13.0.0")))},xu=l,Du=function(){return a}}])})); \ No newline at end of file diff --git a/src/webapps/live/proxy-publisher.html b/src/webapps/live/proxy-publisher.html index 470d1579..cf00292b 100644 --- a/src/webapps/live/proxy-publisher.html +++ b/src/webapps/live/proxy-publisher.html @@ -23,123 +23,127 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --> - - - - - - - - - - - - - - - -
- -
- - -
- -
-
Connecting...
- - - - - + + + - + diff --git a/src/webapps/live/proxy-subscriber.html b/src/webapps/live/proxy-subscriber.html index c583748a..40424d80 100644 --- a/src/webapps/live/proxy-subscriber.html +++ b/src/webapps/live/proxy-subscriber.html @@ -405,6 +405,23 @@ 'background: #222; color: #ebefd0', 'background: #fff; color: #222' ) + console.log( + '%c [stats] ' + '%c : Flag to turn on stats monitoring. Optional.', + 'background: #222; color: #ebefd0', + 'background: #fff; color: #222' + ) + console.log( + '%c [statsendpoint] ' + + '%c : Endpoint to deliver stats (if flag is on). Set to URL if endpoint available. Do not set at all if only sending over DC. Set to `null` if not sending over DC. Optional.', + 'background: #222; color: #ebefd0', + 'background: #fff; color: #222' + ) + console.log( + '%c [statsinterval] ' + + '%c : Number in milliseconds to poll for stats monitoring (if flag is on). Optional.', + 'background: #222; color: #ebefd0', + 'background: #fff; color: #222' + ) console.log( '%c [dc] ' + '%c : Request to switch from socket to RTCDataChannel after signalling is complete. Optional.', @@ -525,11 +542,28 @@ var smPort = isSecure ? '' : '5080' var wsProtocol = isSecure ? 'wss' : 'ws' var wsPort = isSecure ? 443 : 5080 + var useStats = false + var statsEndpoint = getParameterByName('statsendpoint') + var statsInterval = getParameterByName('statsinterval') var preferWhipWhep = true if (getParameterByName('whipwhep')) { var whipwhep = getParameterByName('whipwhep') preferWhipWhep = whipwhep === '1' || whipwhep === 'true' } + if (getParameterByName('stats')) { + var stats = getParameterByName('stats') + useStats = stats === '1' || stats === 'true' + if (!statsInterval) { + statsInterval = undefined + } else if (statsInterval === 'null') { + statsInterval = null + } + if (statsInterval && !isNaN(statsInterval)) { + statsInterval = parseInt(statsInterval, 10) + } else { + statsInterval = 5000 + } + } var switchToDC = true if (getParameterByName('dc')) { var dc = getParameterByName('dc') @@ -548,6 +582,12 @@ signalingSocketOnly: switchToDC, enableChannelSignaling: switchToDC, socketSwitchDelay: !isNaN(switchDelay) ? switchDelay : 5000, + stats: !useStats + ? undefined + : { + interval: statsInterval, + endpoint: statsEndpoint, + }, } var hlsConfig = { host: host, diff --git a/webapps.json b/webapps.json index 014b947e..2c9b22d1 100644 --- a/webapps.json +++ b/webapps.json @@ -9,7 +9,7 @@ }, "r5pro-testbed": { "repositoryUrl": "git@github.com:red5pro/streaming-html5.git", - "branch": "epic/LAB" + "branch": "feature/stats_RED5DEV-1280" }, "truetime": { "datasync": {