diff --git a/src/webapps/live/lib/red5pro/PUBLISHER_README.md b/src/webapps/live/lib/red5pro/PUBLISHER_README.md index 5a26f262..0ded824e 100644 --- a/src/webapps/live/lib/red5pro/PUBLISHER_README.md +++ b/src/webapps/live/lib/red5pro/PUBLISHER_README.md @@ -21,6 +21,7 @@ This document describes how to use the Red5 Pro WebRTC SDK to start a broadcast * [Configuration Parameters](#webrtc-configuration-parameters) * [Example](#webrtc-example) * [Lifecycle Events](#lifecycle-events) +* [Monitoring Statistics](#monitoring-statistics) * [Stream Manager 2.0](#stream-manager-20) # Requirements @@ -383,6 +384,7 @@ The following events are common across all Publisher implementations from the Re | PUBLISH_SUFFICIENT_BANDWIDTH | 'Publish.SufficientBW' | When the current broadcast session has sufficient bandwidth conditions from previously experiencing network issues. | | CONNECTION_CLOSED | 'Publisher.Connection.Closed' | Invoked when a close to the connection is detected. | | DIMENSION_CHANGE | 'Publisher.Video.DimensionChange' | Notification when the Camera resolution has been set or change. | +| STATISTICS_ENDPOINT_CHANGE | 'Publisher.StatisticsEndpoint.Change' | Notification that the server has signaled a change in endpoint to deliver WebRTC Statistics based on RTCStatsReports. _Statistics are only reported after calling [monitorStats](#monitoring-statistics)._ | ## WebRTC Publisher Events @@ -403,10 +405,111 @@ The following events are specific to the `RTCPublisher` implementation and acces | DATA_CHANNEL_MESSAGE | 'WebRTC.DataChannel.Message' | When a message has been delivered over the underlying `RTCDataChannel` when `signalingSocketOnly` configuration is used. | | UNSUPPORTED_FEATURE | 'WebRTC.Unsupported.Feature' | Notification that a feature attempting to use in WebRTC is not supported or available in the current browser that the SDK is being employed. e.g., [Insertable Streams](#insertable-streams). | | TRANSFORM_ERROR | 'WebRTC.Transform.Error' | An error has occurred while trying to apply transform to a media track. See [Insertable Streams](#insertable-streams)| +| STATS_REPORT | 'WebRTC.Stats.Report' | An RTCStatsReport has been captured by the WebRTC client based on configurations from calling [monitorStats](#monitoring-statistics). | -# Stream Manager 2.0 +# Monitoring Statistics + +Both the `RTCPublisher` and `WHIPClient` publisher clients support the ability to monitor and POST statistics report data based on the underlying `RTCPeerConnection` of the clients. + +## Stats Configuration + +The configuration used for statistics monitoring has the following structure: + +```js +{ + // Optional. + // If provided, it will POST stats to this endpoint. + // If undefined, it will post stats to message transport. + // If null, it will only emit status events. + endpoint: undefined, + additionalHeaders: undefined, + interval: 5000, // Interval to poll stats, in milliseconds. + include: [], // Empty array allows SDK to be judicious about what stats to include. +} +``` + +### endpoint + +* If the `endpoint` is defined, the SDK will attempt to make `POST` requests with a JSON body representing each individual report. +* If the `endpoint` is left `undefined`, the SDK will post metadata with type `stats-report` on the underlying message transport (such as the DataChannel or WebSocket). +* If the `endpoint` is set to `null`, the SDK will only emit events with the metadata on the `WebRTC.StatsReport` event. + +### additionalHeaders + +By default, if an `endpoint` is defined, the `POST` request body will be in JSON and have the `{ 'Content-Type': 'application/json' }` header set. If requirements - such as authentication - are required, a map of additional headers can be provided to be sent along with the request. + +### interval + +The polling interval (in milliseconds) to access the `RTCStatsReport` from the underlying `RTCPeerConnection` of the publisher client. + +### include + +An array of static type strings. These directly map to the listing of type available for `RTCStatsReport` objects. If left empty or undefined, the SDK will report the statistics it deems suitable for tracking proper broadcast conditions. + +> More information about the statistic types are available at [https://developer.mozilla.org/en-US/docs/Web/API/RTCStatsReport#the_statistic_types](https://developer.mozilla.org/en-US/docs/Web/API/RTCStatsReport#the_statistic_types) -> This section provides information that relate to the release of Stream Manager 2.0 and its integration with WHIP/WHEP clients. +## Invocation + +To start statistics monitoring, you have a couple of options: + +* You can provide a `stats` attribute with the [stats configuration object](#stats-configuration) to the [init configuration](#webrtc-configuration-parameters). +* You can call `monitorStats` on the publisher client with the optional [stats configuration object](#stats-configuration) parameter. + +> Additionally, you can stop monitoring by calling `unmonitorStats` on the publisher client. + +## Additional Information + +Attached to the metadata that is reported are additional properties that pertain to the publisher client. + +As well, Along with the metadata releated to the `RTCStatsReport` objects emitted by the underlying `RTCPeerConnection`, the statistics monitoring also sends out a few event and action metadata related to the operation of a publisher client. + +> See the following section for examples. + +## Example of Statistics Metdata + +The following is an example of a statistics metadata that is emitted in a `WebRTC.StatsReport` event and POSTed to any defined optional endpoint: + +```json +{ + "name": "RTCPublisherStats", + "created": 1727788393007, + "device": { + "browser": "chrome", + "version": 129, + "appVersion": "5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36", + "platform": "MacIntel", + "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36", + "vendor": "Google Inc." + }, + "client": { + "host": "myred5.deploy", + "app": "live", + "streamName": "stream1" + }, + "type": "stats-report", + "timestamp": 1727788398015, + "data": { + "type": "outbound-rtp", + "kind": "video", + "codecId": "COT01_106_level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f;sps-pps-idr-in-keyframe=1", + "mediaType": "video", + "active": true, + "bytesSent": 323380, + "packetsSent": 335, + "firCount": 0, + "pliCount": 3, + "frameWidth": 640, + "frameHeight": 480, + "framesEncoded": 136, + "framesPerSecond": 30, + "framesSent": 136, + "keyFramesEncoded": 4, + "estimatedBitrate": 0 + } +} +``` + +# Stream Manager 2.0 The Stream Manager 2.0 simplifies the proxying of web clients to Origin and Edge nodes. As such, an initialization configuration property called `endpoint` was added to the WebRTC SDK. This `endpoint` value should be the full URL path to the proxy endpoint on the Stream Manager as is used as such: diff --git a/src/webapps/live/lib/red5pro/README.md b/src/webapps/live/lib/red5pro/README.md index a840630f..6af1e90d 100644 --- a/src/webapps/live/lib/red5pro/README.md +++ b/src/webapps/live/lib/red5pro/README.md @@ -234,10 +234,9 @@ With the Stream Manager 2.0 Release, the `endpoint` init configuration property # Requirements +The **Red5 Pro WebRTC SDK** is intended to communicate with a [Red5 Pro Server](https://www.red5pro.com/), which allows for broadcasting and consuming live streams utilizing [WebRTC](https://developer.mozilla.org/en-US/docs/Web/Guide/API/WebRTC) and other protocols, including [RTMP](https://en.wikipedia.org/wiki/Real_Time_Messaging_Protocol) and [HLS](https://en.wikipedia.org/wiki/HTTP_Live_Streaming). -The **Red5 Pro WebRTC SDK** is intended to communicate with a [Red5 Pro Server](https://www.red5.net/red5-pro/low-latency-streaming-software/), which allows for broadcasting and consuming live streams utilizing [WebRTC](https://developer.mozilla.org/en-US/docs/Web/Guide/API/WebRTC) and other protocols, including [RTMP](https://en.wikipedia.org/wiki/Real_Time_Messaging_Protocol) and [HLS](https://en.wikipedia.org/wiki/HTTP_Live_Streaming). - -As such, you will need a distribution of the [Red5 Pro Server](https://www.red5.net/) running locally or accessible from the web, such as [Amazon Web Services](https://www.red5.net//docs/server/awsinstall/). +As such, you will need a distribution of the [Red5 Pro Server](https://www.red5pro.com/) running locally or accessible from the web, such as [Amazon Web Services](https://www.red5pro.com/docs/server/awsinstall/). > **[Click here to start using the Red5 Pro Server today!](https://account.red5.net/login)** diff --git a/src/webapps/live/lib/red5pro/SUBSCRIBER_README.md b/src/webapps/live/lib/red5pro/SUBSCRIBER_README.md index 3254c948..9e6e8a88 100644 --- a/src/webapps/live/lib/red5pro/SUBSCRIBER_README.md +++ b/src/webapps/live/lib/red5pro/SUBSCRIBER_README.md @@ -28,6 +28,7 @@ This document describes how to use the Red5 Pro WebRTC SDK to subscribe to a bro * [Other Information](#other-information) * [Autoplay Restrictions](#autoplay-restrictions) * [Insertable Streams](#insertable-streams) +* [Monitoring Statistics](#monitoring-statistics) * [Stream Manager 2.0 Integration](#stream-manager-20) # Requirements @@ -564,7 +565,7 @@ To subscribe to all events from a subscriber: function handleSubscriberEvent (event) { // The name of the event: const { type } = event - // The dispatching publisher instance: + // The dispatching subscriber instance: const { subscriber } = event // Optional data releated to the event (not available on all events): const { data } = event @@ -612,6 +613,7 @@ The following events are common across all Subscriber implementations from the R | FULL_SCREEN_STATE_CHANGE | 'Subscribe.FullScreen.Change' | Invoked when a change in fullscreen state occurs during playback. | | AUTO_PLAYBACK_FAILURE | 'Subscribe.Autoplay.Failure' | Invoked when an attempt to `autoplay` on a media element throws a browser exception; typically due to browser security restrictions and their autoplay policies. (WebRTC and HLS, only) [See section on Autoplay Restrictions](#autoplay-restrictions) | | AUTO_PLAYBACK_MUTED | 'Subscribe.Autoplay.Muted' | Invoked when an attempt to `autoplay` on a media element throws a browser exception and is muted based on the `muteOnAutoplayRestriction` config property; typically due to browser security restrictions and their autoplay policies. (WebRTC and HLS, only) [See section on Autoplay Restrictions](#autoplay-restrictions) | +| STATISTICS_ENDPOINT_CHANGE | 'Subscribe.StatisticsEndpoint.Change' | Notification that the server has signaled a change in endpoint to deliver WebRTC Statistics based on RTCStatsReports. _Statistics are only reported after calling [monitorStats](#monitoring-statistics)._ | ## WebRTC Subscriber Events @@ -643,6 +645,7 @@ The following events are specific to the `RTCSubscriber` implementation and acce | TRACK_ADDED | 'WebRTC.PeerConnection.OnTrack' | When a MediaTrack has become available on the underlying `RTCPeerConnection`. | | UNSUPPORTED_FEATURE | 'WebRTC.Unsupported.Feature' | Notification that a feature attempting to use in WebRTC is not supported or available in the current browser that the SDK is being employed. e.g., [Insertable Streams](#insertable-streams). | | TRANSFORM_ERROR | 'WebRTC.Transform.Error' | An error has occurred while trying to apply transform to a media track. See [Insertable Streams](#insertable-streams)| +| STATS_REPORT | 'WebRTC.Stats.Report' | An RTCStatsReport has been captured by the WebRTC client based on configurations from calling [monitorStats](#monitoring-statistics). | ## HLS Subscriber Events @@ -963,9 +966,116 @@ const config = { } ``` -# Stream Manager 2.0 +# Monitoring Statistics + +Both the `RTCSubscriber` and `WHEPClient` subscriber clients support the ability to monitor and POST statistics report data based on the underlying `RTCPeerConnection` of the clients. + +## Stats Configuration + +The configuration used for statistics monitoring has the following structure: + +```js +{ + // Optional. + // If provided, it will POST stats to this endpoint. + // If undefined, it will post stats to message transport. + // If null, it will only emit status events. + endpoint: undefined, + additionalHeaders: undefined, + interval: 5000, // Interval to poll stats, in milliseconds. + include: [], // Empty array allows SDK to be judicious about what stats to include. +} +``` + +### endpoint + +* If the `endpoint` is defined, the SDK will attempt to make `POST` requests with a JSON body representing each individual report. +* If the `endpoint` is left `undefined`, the SDK will post metadata with type `stats-report` on the underlying message transport (such as the DataChannel or WebSocket). +* If the `endpoint` is set to `null`, the SDK will only emit events with the metadata on the `WebRTC.StatsReport` event. + +### additionalHeaders + +By default, if an `endpoint` is defined, the `POST` request body will be in JSON and have the `{ 'Content-Type': 'application/json' }` header set. If requirements - such as authentication - are required, a map of additional headers can be provided to be sent along with the request. + +### interval + +The polling interval (in milliseconds) to access the `RTCStatsReport` from the underlying `RTCPeerConnection` of the subscriber client. + +### include + +An array of static type strings. These directly map to the listing of type available for `RTCStatsReport` objects. If left empty or undefined, the SDK will report the statistics it deems suitable for tracking proper broadcast conditions. + +> More information about the statistic types are available at [https://developer.mozilla.org/en-US/docs/Web/API/RTCStatsReport#the_statistic_types](https://developer.mozilla.org/en-US/docs/Web/API/RTCStatsReport#the_statistic_types) -> This section provides information that relate to the release of Stream Manager 2.0 and its integration with WHIP/WHEP clients. +## Invocation + +To start statistics monitoring, you have a couple of options: + +* You can provide a `stats` attribute with the [stats configuration object](#stats-configuration) to the [init configuration](#webrtc-configuration-parameters). +* You can call `monitorStats` on the subscriber client with the optional [stats configuration object](#stats-configuration) parameter. + +> Additionally, you can stop monitoring by calling `unmonitorStats` on the subscriber client. + +## Additional Information + +Attached to the metadata that is reported are additional properties that pertain to the subscriber client. + +As well, Along with the metadata releated to the `RTCStatsReport` objects emitted by the underlying `RTCPeerConnection`, the statistics monitoring also sends out a few event and action metadata related to the operation of a subscriber client. + +> See the following section for examples. + +## Example of Statistics Metdata + +The following is an example of a statistics metadata that is emitted in a `WebRTC.StatsReport` event and POSTed to any defined optional endpoint: + +```json +{ + "name": "RTCSubscriberStats", + "created": 1727789134165, + "device": { + "browser": "chrome", + "version": 129, + "appVersion": "5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36", + "platform": "MacIntel", + "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36", + "vendor": "Google Inc." + }, + "client": { + "host": "myred5.deploy", + "app": "live", + "streamName": "stream1", + "subscriptionId": "subscriber-922e" + }, + "type": "stats-report", + "timestamp": 1727789139169, + "data": { + "type": "inbound-rtp", + "kind": "video", + "codecId": "CIT01_102_level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f", + "jitter": 0.005, + "packetsLost": 0, + "packetsReceived": 439, + "bytesReceived": 412627, + "firCount": 0, + "frameWidth": 640, + "frameHeight": 480, + "framesDecoded": 143, + "framesDropped": 0, + "framesPerSecond": 30, + "framesReceived": 143, + "freezeCount": 0, + "keyFramesDecoded": 3, + "nackCount": 0, + "pauseCount": 0, + "pliCount": 0, + "totalFreezesDuration": 0, + "totalPausesDuration": 0, + "estimatedBitrate": 660 + } +} +``` + +# Stream Manager 2.0 The Stream Manager 2.0 simplifies the proxying of web clients to Origin and Edge nodes. As such, an initialization configuration property called `endpoint` was added to the WebRTC SDK. This `endpoint` value should be the full URL path to the proxy endpoint on the Stream Manager as is used as such: diff --git a/src/webapps/live/lib/red5pro/red5pro-sdk.min.js b/src/webapps/live/lib/red5pro/red5pro-sdk.min.js index 15697e64..07a57b4f 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: 14.0.0-release.b172 + * Version: 14.2.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(o){}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",NONE:"NONE"}),no=Object.freeze({VP8:"VP8",H264:"H264",H265:"H265",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=this;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),this._getViewResolverPromise().then((function(e){if(o&&o.enabled){var t=o.hlsjsRef,n=o.usePlaybackControlsUI,r=o.options;ve.supportsNonNativeHLS(t)?p._sourceHandler=new $n(e.view,p.getType(),r,n):(y("WHEPClient","Could not utilize the 'LiveSeek' request. This feature requires either native HLS playback or hls.js as a depenency."),p.trigger(new Xt(It.LIVE_SEEK_UNSUPPORTED,p,{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."})),p._sourceHandler=new Bn(e.view,p.getType()))}else p._sourceHandler=new Bn(e.view,p.getType());p._glomSourceHandlerAPI(p._sourceHandler),p._initHandler(p._options,p._sourceHandler)})).catch((function(){})),this._getAvailabilityResolverPromise().catch((function(){})),l=i||{},e.next=13,this._whipHelper.getOptions(l);case 13:return(d=e.sent)&&d.links&&(this._options.rtcConfiguration=Ai(Ai({},r),{},{iceServers:d.links})),d&&d.origin&&this.trigger(new Xt(It.HOST_ENDPOINT_CHANGED,this,{endpoint:d.origin})),h=this._options.enableChannelSignaling?c:void 0,f=r,void 0===r.encodedInsertableStreams&&(f=Object.assign(r,{encodedInsertableStreams:!!this._mediaTransform})),this._connect(f,h,this._options.iceServers),this._connectionClosed=!1,e.abrupt("return",this._getSubscriptionResolverPromise());case 24:throw e.prev=24,e.t0=e.catch(6),this.trigger(new Xt(jt.CONNECT_FAILURE),this,e.t0),e.t0;case 28:case"end":return e.stop()}}),e,this,[[6,24]])}))),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"}),ga=Object.freeze({VP8:"VP8",H264:"H264",H265:"H265"});function _a(e){return(_a="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 wa(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;Ca(this,e),ka(this,"audio",t),ka(this,"video",n||new Pa)}));function Ra(e){return(Ra="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 La(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;Ca(this,e),ka(this,"audio",t),ka(this,"video",n||new Oa)})))},xa=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=Na(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&&Ha(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||Ia.minFlashVersion;if(ve.supportsFlashVersion(r)){this._options=Object.assign({},Ia,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()}}])&&La(n.prototype,r),o&&La(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,o}(M);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 Ma(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 Fa(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 $a(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 Qa(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:null,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]: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>1&&void 0!==arguments[1]&&arguments[1];return Xa().mark((function r(){var o,i;return Xa().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){$a(i,r,o,a,s,"next",e)}function s(e){$a(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 as(e){return(as="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 ss(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 cs(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 ds(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 hs(e,t){for(var n=0;n1)&&"video"===t[0].kind};void 0!==e.onGetUserMedia?(gs("Requesting gUM from user-defined configuration:onGetUserMedia."),e.onGetUserMedia().then((function(r){if(n(r))return gs("We received a MediaStream with mismatching track listing. Trying again..."),void t._gum(e);t.trigger(new qt(At.CONSTRAINTS_ACCEPTED,t,Es(r))),t._streamFuture.resolve(r)})).catch((function(n){ws("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)}))):(gs("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 gs("We received a MediaStream with mismatching track listing. Trying again..."),void t._gum(e);gs("Found valid constraints: ".concat(JSON.stringify(r.constraints,null,2))),t.trigger(new qt(At.CONSTRAINTS_ACCEPTED,t,Es(r.media))),t.trigger(new qt(Rt.DIMENSION_CHANGE,t,r.constraints)),t._streamFuture.resolve(r.media)})).catch((function(n){gs("Could not find valid constraint resolutions from: ".concat(JSON.stringify(n.constraints,null,2))),ws("Could not resolve MediaStream from provided mediaConstraints. Error - ".concat(n.error)),gs("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 gs("[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 gs("[createpeeer]"),this._peerFuture=void 0,this._peerFuture=k.createIfNotExist(this._peerFuture),n&&e&&(_s("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;return gs("[createoffer]"),this._offerFuture=void 0,this._offerFuture=k.createIfNotExist(this._offerFuture),this._peerHelper.createOffer(e,!1,this._offerFuture),this._offerFuture.promise}},{key:"_setRemoteDescription",value:function(e){return gs("[setremotedescription]"),this._peerHelper.setRemoteDescription(e)}},{key:"_sendOffer",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:void 0,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0;gs("[sendoffer]");var i={handleOffer:t,transport:n,data:{sdp:e}};return r&&(i.videoEncoding=r),o&&(i.audioEncoding=o),this._sendOfferFuture=void 0,this._sendOfferFuture=k.createIfNotExist(this._sendOffFuture),this._socketHelper.post(i),this._sendOfferFuture.promise}},{key:"_sendCandidate",value:function(e,t){gs("[sendcandidate]"),this._socketHelper.post({handleCandidate:t,data:{candidate:e}})}},{key:"_requestPublish",value:function(e,t,n){return gs("[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=ls().mark((function e(t,n,r){var o,i,a,s,c,u,l,d;return ls().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){ds(i,r,o,a,s,"next",e)}function s(e){ds(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=cs(cs({},Ss),e),this._peerHelper=new is(this),this._socketHelper=new Ja(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){_s("[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;gs("[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=cs(cs({},Ss),e),this._peerHelper=new is(this),this._socketHelper=new Ja(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){_s("[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;gs("[preview]");var t=new Promise((function(t){t(e)}));return this._setViewIfNotExist(this._view,this._options.mediaElementId),t}},{key:"unpreview",value:function(){gs("[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;gs("[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 is(this)),this._socketHelper?this._socketHelper.clearRetry():(this._socketHelper=new Ja(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();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))}));var d=this._options,h=d.forceVP8,f=d.videoEncoding,p=d.audioEncoding;return h&&(f=ga.VP8,this._options.videoEncoding=f),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){return e.trigger(new qt(At.PEER_CONNECTION_AVAILABLE,e,t)),e._mediaStream.getTracks().forEach((function(n){t.addTrack(n,e._mediaStream)})),t.getTransceivers().forEach((function(e){if(e.sender&&e.sender.track){var t=e.sender.track.kind;if(f&&"video"===t&&e.setCodecPreferences){var n=RTCRtpSender.getCapabilities("video").codecs;try{var r=n.findIndex((function(e){return e.mimeType==="video/".concat(f)}));if(r>-1){var o=n.slice(0),i=n[r];o.splice(r,1),o.unshift(i),e.setCodecPreferences(o)}}catch(e){_s("[videoEncoding] Could not set codec preferences for ".concat(f,". ").concat(e.message||e))}}else if(p&&"audio"===t&&e.setCodecPreferences)try{var a=RTCRtpSender.getCapabilities("audio").codecs,s=a.findIndex((function(e){return e.mimeType==="audio/".concat(p)}));if(s>-1){var c=a[s];a.splice(s,1),a.unshift(c),e.setCodecPreferences(a)}}catch(e){_s("[audioEncoding] Could not set codec preferences for ".concat(p,". ").concat(e.message||e))}}})),e._createOffer(e._options.bandwidth)})).then((function(t){var n=e._options,r=n.streamName,o=n.iceTransport,i=n.videoEncoding,a=n.audioEncoding;return e.trigger(new qt(At.OFFER_START,e,t)),e._sendOffer(t,r,o,i,a)})).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;gs("[publishWithSocket]"),this._options.streamName=n||this._options.streamName;var o=r||new C,i=new C;return this._socketHelper=new Ja(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];gs("[unpublish]");var n=function(){e._socketHelper&&(gs("[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;ws("RTCPublisher"),ws("RTCPublisher")}}},{key:"onStreamAvailable",value:function(e){gs("[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){gs("Stream ".concat(this._options.streamName," does not exist.")),gs("[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;ws("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){gs("[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||(gs("RTCPublisher"),this.unpublish(),this.trigger(new qt(Rt.CONNECTION_CLOSED,this,e)))}},{key:"onPeerConnectionFail",value:function(){gs("[onpeerconnectionfail]"),this.trigger(new qt(Rt.PUBLISH_FAIL,this)),this._publishFuture&&this._publishFuture.reject("Peer Connection Failed.")}},{key:"onPeerConnectionClose",value:function(e){gs("[onpeerconnectionclose]"),this._socketHelper&&(gs("[onpeerconnectionclose:teardown]"),this._socketHelper.tearDown()),this.onSocketClose(e)}},{key:"onPeerConnectionOpen",value:function(){gs("[onpeerconnection::open]"),this.trigger(new qt(At.PEER_CONNECTION_OPEN),this,this.getPeerConnection())}},{key:"onPeerConnectionTrackAdd",value:function(e){gs("[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):"";gs("[onsdpsuccess]".concat(t))}},{key:"onSDPError",value:function(e){this.trigger(new qt(Rt.PUBLISH_FAIL,this));var t=e?": "+JSON.stringify(e,null,2):"";ws("[onsdperror]".concat(t))}},{key:"onSDPAnswer",value:function(e){gs("[sdpanswer]:: "+JSON.stringify(e,null,2)),this._sendOfferFuture=k.createIfNotExist(this._sendOfferFuture),this._sendOfferFuture.resolve(e)}},{key:"onAddIceCandidate",value:function(e){gs("[addicecandidate]"),this._peerHelper.addIceCandidate(e).then((function(){gs("[addicecandidate:success]")})).catch((function(e){_s("[addicecandidate:error] - ".concat(e))}))}},{key:"onIceCandidate",value:function(e){gs("[icecandidatetrickle]"),this._sendCandidate(e,this._options.streamName)}},{key:"onIceCandidateTrickleEnd",value:function(){gs("[icecandidatetrickle:end]")}},{key:"onEmptyCandidate",value:function(){gs("[icecandidatetrickle:empty]"),this.trigger(new qt(At.PEER_CANDIDATE_END))}},{key:"onPeerGatheringComplete",value:function(){gs("[icecandidategathering:end]"),this._socketHelper&&this._socketHelper.postEndOfCandidates(this._options.streamName)}},{key:"onSocketIceCandidateEnd",value:function(){gs("[socketicecandidate:end]"),this._getTrickleEnd().resolve()}},{key:"onPublisherStatus",value:function(e){gs("[publisherstatus] - "+JSON.stringify(e,null,2));var t=bs.exec(e.message),n=ys.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(gs("[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 ks(e){return(ks="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 Ps(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 Os(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 As(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);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 Ns(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function js(e,t){for(var n=0;n2&&void 0!==arguments[2])||arguments[2];Ns(this,t),r=Is(this,t);var i=e?Qr(e):Ws;return i.mediaElementId=n?n.id:Ws.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&&Us(e,t)}(t,e),n=t,(r=[{key:"_internalConnect",value:(h=As(Rs().mark((function e(t){return Rs().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=As(Rs().mark((function e(t){return Rs().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Bs("[waittogatherice]"),e.abrupt("return",new Promise((function(e,n){if("complete"===t.iceGatheringState)Bs("[waittogatherice] ice gathering state complete."),t.addIceCandidate(null).then((function(){e(t.localDescription)})).catch((function(n){Vs("Error adding null candidate: "+n.message||!1),e(t.localDescription)}));else{Bs("[waittogatherice] waiting...");var r=setTimeout((function(){clearTimeout(r),t.addIceCandidate(null).then((function(){e(t.localDescription)})).catch((function(n){Vs("Error adding null candidate: "+n.message||!1),e(t.localDescription)}))}),1e3);t.onicegatheringstatechange=function(){clearTimeout(r),Bs("[waittogatherice] ice gathering state complete."),"complete"===t.iceGatheringState&&t.addIceCandidate(null).then((function(){e(t.localDescription)})).catch((function(n){Vs("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=As((function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return Rs().mark((function r(){var o,i,a,s,c,u,l,d,h,f,p;return Rs().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=i.videoEncoding,h=i.audioEncoding,l&&!d&&(d=ga.VP8),f=o,a&&(f=a(f)),n||(f=Ze(f),f=tt(f)),p=Os(Os({},u),{},{mode:s,keyFramerate:c}),d&&(p.videoEncoding=d),h&&(p.audioEncoding=h),r.next=12,t._whipHelper.postSDPOffer(f,p);case 12:return r.abrupt("return",r.sent);case 15:throw r.prev=15,r.t0=r.catch(0),Gs(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,Gs)),t.unpublish()),r.t0;case 20:case"end":return r.stop()}}),r,null,[[0,15]])}))()})),function(e){return l.apply(this,arguments)})},{key:"_postCandidateFragments",value:(u=As(Rs().mark((function e(t){var n,r;return Rs().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){Bs(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=As(Rs().mark((function e(n){var r,o,i,a,s,c,u,l,d;return Rs().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this._options=Os(Os({},Ws),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",xs(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=As(Rs().mark((function e(n,r){var o,i,a,s,c,u,l,d,h;return Rs().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this._options=Os(Os({},Ws),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",xs(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=As((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 Rs().mark((function r(){var o,i,a,s,c,u,l,d,h,f,p,v,m,y,b,g,_,w,S,E,C,k,P;return Rs().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return o=e._options,i=o.bandwidth,a=o.forceVP8,s=o.videoEncoding,c=o.audioEncoding,u=o.rtcConfiguration,l=o.enableChannelSignaling,d=o.dataChannelConfiguration,h=o.trickleIce,f=o.mungeAnswer,p=o.connectionParams,a&&(s=ga.VP8,e._options.videoEncoding=s),(v=l&&Ve())&&!d&&(d={name:"red5pro"},e._options.dataChannelConfiguration=d),e._options.enableChannelSignaling=v,e._options.signalingSocketOnly=e._options.enableChannelSignaling,r.prev=6,m=p||{},t&&(e._options.streamName=t),p&&(y=p.transcode)&&(m.transcode=y),r.next=12,e._whipHelper.getOptions(m);case 12:return(b=r.sent)&&b.links&&(e._options.rtcConfiguration=Os(Os({},u),{},{iceServers:b.links})),b&&b.origin&&e.trigger(new qt(At.HOST_ENDPOINT_CHANGED,e,{endpoint:b.origin})),g=e._options.enableChannelSignaling?d:void 0,r.next=18,e._createPeerConnection(u,g,e._options.iceServers);case 18:return _=r.sent,e.trigger(new qt(At.PEER_CONNECTION_AVAILABLE,e,_)),r.next=22,e._getMediaStream();case 22:return r.sent.getTracks().forEach((function(e){var t=_.addTransceiver(e,{direction:"sendonly"}),n=e.kind;if(t&&"video"===n&&s&&t.setCodecPreferences)try{var r=RTCRtpSender.getCapabilities("video").codecs,o=r.findIndex((function(e){return e.mimeType==="video/".concat(s)}));if(o>-1){var i=r[o];r.splice(o,1),r.unshift(i),t.setCodecPreferences(r)}}catch(e){Vs("[videoEncoding] Could not set codec preferences for ".concat(s,". ").concat(e.message||e))}else if(t&&"audio"===n&&c&&t.setCodecPreferences)try{var a=RTCRtpSender.getCapabilities("audio").codecs,u=a.findIndex((function(e){return e.mimeType==="audio/".concat(c)}));if(u>-1){var l=a[u];a.splice(u,1),a.unshift(l),t.setCodecPreferences(a)}}catch(e){Vs("[audioEncoding] Could not set codec preferences for ".concat(c,". ").concat(e.message||e))}})),r.next=26,e._peerHelper.createOfferWithoutSetLocal(i);case 26:return w=r.sent,r.next=29,e._peerHelper.setLocalDescription(w);case 29:if(h){r.next=33;break}return r.next=32,e.waitToGatherIce(_);case 32:w=r.sent;case 33:return e.trigger(new qt(At.OFFER_START,e,w)),r.next=36,e._postOffer(w,h);case 36:return S=r.sent,E=S.sdp,C=f?f(E):E,r.next=41,e._setRemoteDescription({type:"answer",sdp:nt(C)});case 41:if(e.trigger(new qt(At.OFFER_END,e,C)),!h){r.next=49;break}return r.next=45,e.waitToGatherIce(_);case 45:return k=r.sent,P=k.sdp,r.next=49,e._postCandidateFragments(P);case 49: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 56:throw r.prev=56,r.t0=r.catch(6),Gs(r.t0),ve.removeOrientationChangeHandler(e._onOrientationChange),e.trigger(new qt(Rt.CONNECT_FAILURE,e,r.t0)),n&&n.reject(r.t0),r.t0;case 63:case"end":return r.stop()}}),r,null,[[6,56]])}))()})),function(){return a.apply(this,arguments)})},{key:"unpublish",value:(i=As((function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return Rs().mark((function n(){return Rs().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return Bs("[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(xs(t,"onDataChannelOpen",this,3)([e]),n){var r=n.name;xs(t,"onDataChannelAvailable",this,3)([r])}else xs(t,"onDataChannelAvailable",this,3)([]);this.trigger(new qt(Rt.PUBLISH_START,this))}},{key:"getConnection",value:function(){}}])&&js(n.prototype,r),o&&js(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,o,i,a,s,c,u,l,d,h}(Cs);function zs(e){return(zs="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){return function(e){if(Array.isArray(e))return Js(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 Js(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)?Js(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 Js(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;return v("[createoffer]"),this._offerFuture=void 0,this._offerFuture=k.createIfNotExist(this._offerFuture),this._peerHelper.createOffer(e,!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()})),sc(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 sc(t,"init",this,3)([Object.assign(pc,e)])}},{key:"initWithStream",value:function(e,n){return sc(t,"initWithStream",this,3)([Object.assign(pc,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),sc(t,"onPeerConnectionTrackAdd",this,3)([e])}},{key:"_onMediaStreamReceived",value:function(e){this._packStreamWithAudio(e,3),sc(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=fc.exec(e.message),n=hc.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.")}}])&&oc(n.prototype,r),o&&oc(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,o}(Cs),mc=ia,yc=Ao,bc=Ki,gc=Xo,_c=fi,wc=nc,Sc=Cs,Ec=Ys,Cc=xa,kc=Rt,Pc=At,Oc=Lt,Tc=jt,Rc=It,Lc=xt,Ac=Ht,Nc=Dt,jc=Mt,Hc=to,Ic=no,xc=ba,Dc=ga,Mc=ro,Fc=oo;h("".concat("error")||!1);var Uc=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("14.0.0-release.b172")))},Bc=d,Vc=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 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 f=i();a(o("bunyan usage error: %s:%s: attempt to log with an unbound log method: `this` is: %s",f.file,f.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(y).forEach((function(e){m[y[e]]=e})),g.prototype.addStream=function(e,t){switch(null==t&&(t=f),!(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 c,type:"raw"}),n){var i=n.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(r.nameFromLevel[e.level],": ").concat(e.msg);s.push(t)}}})),a=Object(r.createLogger)({level:e,name:"red5pro-sdk",streams:o})},f=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 n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),O(n),d}},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;O(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:T(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},e}function T(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)})),A(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=A(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,A(t).find(e,n,r,o,i,a)}))}else o.reject(a)},A(this).next=function(e,t){var n,r,o=e.next();return o.done||(r=o.value,n=t.get(r)),[r,n]}}var t,n,r;return t=e,(n=[{key:"create",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,o=new S;return A(this).find(this.listorder(e.slice()),t,n,o,r),o.promise}}])&&T(t.prototype,n),r&&T(t,r),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 n=0;n1&&(n=V.exec(e),r[1]===t&&n&&n.length>1)?n[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 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(o=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),C(n),d}},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;C(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:k(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},e}function J(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 q(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 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,de=!!document.documentMode,fe=ue?"edge"===window.adapter.browserDetails.browser.toLowerCase():!de&&!!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,n=e.adapter,r={appVersion:t.appVersion,platform:t.platform,userAgent:t.userAgent,vendor:t.vendor};return ue?X(X({},n.browserDetails),r):r},getGeoLocation:(ve=K().mark((function e(){var t,n;return K().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=window,!("geolocation"in(n=t.navigator))){e.next=3;break}return e.abrupt("return",new Promise((function(e){n.geolocation.getCurrentPosition((function(t){var n=t.coords;e(n)})).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(n,r){var o=ve.apply(e,t);function i(e){J(o,n,r,i,a,"next",e)}function a(e){J(o,n,r,i,a,"throw",e)}i(void 0)}))},function(){return ye.apply(this,arguments)}),getOrGenerateFingerprint:function(){var e,t=window.localStorage;if(t&&t.getItem("red5_fingerprint"))return t.getItem("red5_fingerprint");try{e=crypto.randomUUID()}catch(t){e="10000000-1000-4000-8000-100000000000".replace(/[018]/g,(function(e){return(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16)}))}return t.setItem("red5_fingerprint",e),e},getIsMoz:function(){return le},getIsEdge:function(){return fe},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 n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];try{e.srcObject=t}catch(n){v("[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 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,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&&(p("[window:orientation]","[addOrientationChangeHandler]","adding responder."),te.push(e),t&&ne()),1===te.length&&(p("[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&&(p("[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 o=t.parentNode;if(o){var i=o.clientWidth,a=o.clientHeight;t.style.width=r?a+"px":i+"px";var s=t.clientWidth,c=t.clientHeight,u=.5*(r?i-c:i-s);t.style.position="relative",t.style.left=u+"px"}n&&n(e(t,n,r))}},Ce=function(e,t,n){var r,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(r=0;r=t?e.apply(null,r):function(){var e=Array.prototype.slice.call(arguments,0);return n.apply(null,r.concat(e))}}},ke=Oe((function(e,t){for(var n=0,r=t.length,o=[];n=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),C(n),d}},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;C(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:k(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},e}function He(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 Ie(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);function a(e){He(i,r,o,a,s,"next",e)}function s(e){He(i,r,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 n=e.video.hasOwnProperty("width")?Me(e.video.width):0,r=e.video.hasOwnProperty("height")?Me(e.video.height):0,o=n===t.width&&r===t.height;return o&&p("[gum:isExact]","Found matching resolution for ".concat(t.width,", ").concat(t.height,".")),o})),Ue=Oe((function(e,t){var n=(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 n=Ue(t);return ke(n)(e)})),Ge=function e(t,n,r){if(0!=n.length){var o=n.shift();t.video.width={exact:o.width},t.video.height={exact:o.height},me.gUM(t).then((function(e){r.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,n,r)}))}else!function(e,t){e.video=!0,me.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(": ");p("[gum:getUserMedia]","Failure in getUserMedia: ".concat(r,". 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,r)},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,n,r){var o=new kt(t),i=new Pt(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}},qe=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}},Xe=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}},Qe=function(){var e=Ie(je().mark((function e(t,n,r){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: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)}}(),$e=function(){var e=Ie(je().mark((function e(t,n,r){var o,i,a,s;return je().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=new Ot({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)}}(),Ze=function(){var e=Ie(je().mark((function e(t,n,r){var o,i,a,s;return je().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=new Ot({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)}}(),et=function(e,t){var n=new S,r=Be(De);p("[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(": ");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,n=Ve(De)(e),r=Re(e);return Ge(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)){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){n.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){n.resolve({media:t,constraints:e})})).catch(o);return n.promise},tt=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")},nt=function(e){return tt(e,["a=ice-options:trickle"])},rt=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")},ot=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")},it=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")},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,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;)ut.lastIndex=0,ut.exec(t[r])&&t.splice(r,1);return t.join("\r\n")}return e})).join(t)},dt=function(e){return lt(e,"m=",/^audio/g)},ft=function(e){return lt(e,"m=",/^video/g)},ht=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},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,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="",f="a=mid:0",h=[];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)?h.push(e):n||h.push(e))})),r&&h[h.length-1]!==o&&h.push(o);var p=[l,d,t,f].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",CANDIDATE_CREATE:"WebRTC.Candidate.Create",CANDIDATE_RECEIVE:"WebRTC.Candidate.Receive",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_CREATE:"WebRTC.Candidate.Create",CANDIDATE_RECEIVE:"WebRTC.Candidate.Receive",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 n,r=zt(e);if(t){var o=zt(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return Yt(this,n)}}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 n=0;n1&&void 0!==arguments[1]?arguments[1]:void 0;Jt(this,e),this._type=t,this._data=n}return Xt(e,[{key:"type",get:function(){return this._type}},{key:"data",get:function(){return this._data}}]),e}(),$t=function(e){Vt(n,e);var t=Wt(n);function n(e,r,o){var i;return Jt(this,n),(i=t.call(this,e,o))._publisher=r,i}return Xt(n,[{key:"publisher",get:function(){return this._publisher}}]),n}(Qt),Zt=function(e){Vt(n,e);var t=Wt(n);function n(e,r,o){var i;return Jt(this,n),(i=t.call(this,e,o))._subscriber=r,i}return Xt(n,[{key:"subscriber",get:function(){return this._subscriber}}]),n}(Qt),en=function(e){Vt(n,e);var t=Wt(n);function n(e,r,o){var i;return Jt(this,n),(i=t.call(this,e,o))._name=r,i}return Xt(n,[{key:"name",get:function(){return this._name}}]),n}(Qt),tn=function(e){Vt(n,e);var t=Wt(n);function n(e,r,o){var i;return Jt(this,n),(i=t.call(this,e,o))._participant=r,i}return Xt(n,[{key:"participant",get:function(){return this._participant}}]),n}(Qt);function nn(e){return(nn="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 rn(e,t){for(var n=0;n1||"touchend"==e.type&&e.touches.length>0)){var t,n,r=me.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 un(ln.CHANGE_COMPLETE,this))}},{key:"_mousemove",value:function(e){var t=me.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 un(ln.CHANGE,this,o))}},{key:"_mousedown",value:function(e){this._eventStartPosition=me.getMouseXFromEvent(e),this.trigger(new un(ln.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}}])&&hn(t.prototype,n),r&&hn(t,r),Object.defineProperty(t,"prototype",{writable:!1}),i}(H),wn=Object.freeze({UNAVAILABLE:1e3,AVAILABLE:0,IDLE:1,PLAYING:2,PAUSED:3}),Sn=Object.freeze({1e3:"Playback.UNAVAILABLE",0:"Playback.AVAILABLE",1:"Playback.IDLE",2:"Playback.PLAYING",3:"Playback.PAUSED"}),En=Object.freeze({LIVE:0,VOD:1}),Cn=Object.freeze({0:"LiveSeek.LIVE",1:"LiveSeek.VOD"});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 kn(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Pn(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)&&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]: "+Sn[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===wn.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}}]),n}(xn);function Un(e){return(Un="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 Bn(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 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:n.message?n.message:n,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)}}])&&Bn(t.prototype,n),r&&Bn(t,r),Object.defineProperty(t,"prototype",{writable:!1}),i}(Dn);function Jn(e){return(Jn="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 qn(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */qn=function(){return e};var e={},t=Object.prototype,n=t.hasOwnProperty,r=Object.defineProperty||function(e,t,n){e[t]=n.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function c(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,n){return e[t]=n}}function u(e,t,n,o){var i=t&&t.prototype instanceof f?t:f,a=Object.create(i.prototype),s=new O(o||[]);return r(a,"_invoke",{value:w(e,n,s)}),a}function l(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var d={};function f(){}function h(){}function p(){}var v={};c(v,i,(function(){return this}));var y=Object.getPrototypeOf,m=y&&y(y(k([])));m&&m!==t&&n.call(m,i)&&(v=m);var b=p.prototype=f.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;r(this,"_invoke",{value:function(r,i){function a(){return new t((function(o,a){!function r(o,i,a,s){var c=l(e[o],e,i);if("throw"!==c.type){var u=c.arg,d=u.value;return d&&"object"==Jn(d)&&n.call(d,"__await")?t.resolve(d.__await).then((function(e){r("next",e,a,s)}),(function(e){r("throw",e,a,s)})):t.resolve(d).then((function(e){u.value=e,a(u)}),(function(e){return r("throw",e,a,s)}))}s(c.arg)}(r,i,o,a)}))}return o=o?o.then(a,a):a()}})}function w(e,t,n){var r="suspendedStart";return function(o,i){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw i;return P()}for(n.method=o,n.arg=i;;){var a=n.delegate;if(a){var s=S(a,n);if(s){if(s===d)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=l(e,t,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===d)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}function S(e,t){var n=t.method,r=e.iterator[n];if(void 0===r)return t.delegate=null,"throw"===n&&e.iterator.return&&(t.method="return",t.arg=void 0,S(e,t),"throw"===t.method)||"return"!==n&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+n+"' method")),d;var o=l(r,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,d;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,d):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,d)}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 r=-1,o=function t(){for(;++r=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),C(n),d}},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;C(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:k(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},e}function Xn(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 Qn(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function $n(e,t){for(var n=0;n3&&void 0!==arguments[3])||arguments[3];return Qn(this,a),(r=i.call(this)).media=e,r.clone=r.media.cloneNode(!0),r.parent=r.media.parentNode,r.holder=o?r._determineHolder(r.media):void 0,r.playerType=t,r.hlsOptions=n,r.subscriberId=void 0,r.hlsElement=void 0,r._usePlaybackControls=o,r._isVOD=!1,r._isSeekable=!1,r._isHLSPlaybackActive=!1,r._isFragLoading=!1,r._hlsRecoverFlop=!1,r._hlsRecoverAttempts=0,r._lastDurationUpdate=0,r._controls=void 0,r._resizeObserver=void 0,r._playbackNotificationCenter=r.media,r._pendingUnpublish=!1,r._wallOffset=NaN,r._averageSegmentDuration=6,r._manifestLoadTimeout=0,me.onFullScreenStateChange(r._handleFullScreenChange.bind(nr(r))),r.hls=void 0,r.hlsElement=void 0,r}return t=a,(n=[{key:"_determineHolder",value:function(e){if(e.parentNode.classList.contains("red5pro-media-container"))return e.parentNode;var t=e.parentNode,n=me.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:(o=function(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);function a(e){Xn(i,r,o,a,s,"next",e)}function s(e){Xn(i,r,o,a,s,"throw",e)}a(void 0)}))}}(qn().mark((function e(t){var n,r,o,i,a,s,c,u,l,d,f=this;return qn().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 Zt(Mt.LIVE_SEEK_ENABLED,void 0,{hlsElement:this.hlsElement,hlsControl:void 0})),this._onHLSDurationChange({target:this.hlsElement,duration:u*d}),this._manifestLoadTimeout=setTimeout((function(){clearTimeout(f._manifestLoadTimeout),f._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,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){v("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){v("Could not start playback: ".concat(e.message,"."))}t.style.display="none"}var i=e?En.VOD:En.LIVE;this.trigger(new Zt(Mt.LIVE_SEEK_CHANGE,void 0,{code:i,state:Cn[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){v("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(){p("RTCSeekableSourceHandler","[videoelement:event] canplay"),n&&n.enable(!0),t.trigger(new Zt(xt.PLAYBACK_STATE_CHANGE,void 0,{code:wn.AVAILABLE,state:Sn[wn.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(r){n&&n.getVolume()!==t.media.volume&&n.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 n=this,r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];t&&(t.on(me.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 Zt(Mt.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 Zt(Mt.LIVE_SEEK_ERROR,void 0,{hlsElement:e,hlsControl:t,error:o}))}else n.trigger(new Zt(Mt.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(me.getHLSClientEventEnum().MANIFEST_PARSED,(function(){try{e.pause()}catch(e){p("RTCSeekableSourceHandler","Could not pause seekable live stream: ".concat(e.message))}n.isSeekable=!0,n.trigger(new Zt(Mt.LIVE_SEEK_ENABLED,void 0,{hlsElement:e,hlsControl:t}))})),t.on(me.getHLSClientEventEnum().FRAG_LOADING,(function(r,o){var i=o.frag.stats,a=i.loaded,s=i.total;n.trigger(new Zt(Mt.LIVE_SEEK_LOADING,void 0,{hlsElement:e,hlsControl:t,progress:a/s*100})),(n.isHLSPlaybackActive||n._isFragLoading)&&(n._isFragLoading=a/s>=1)})),t.on(me.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 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(wn.PLAYING),this.trigger(new Zt(xt.PLAYBACK_STATE_CHANGE,void 0,{code:wn.PLAYING,state:Sn[wn.PLAYING]}))}},{key:"_onHLSPause",value:function(){p("RTCSeekableSourceHandler","[HLS:videoelement:event] pause");var e=this.getControls();e&&e.setState(wn.PAUSED),this.trigger(new Zt(xt.PLAYBACK_STATE_CHANGE,void 0,{code:wn.PAUSED,state:Sn[wn.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,n=e.controls,r=me.hasAttributeDefined(this.media,"muted");return n||this._usePlaybackControls?(this._controls=n?e.controls:new Fn(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(){p("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 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: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):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 n;(n=e&&this.hlsElement&&this.hlsElement.paused?this.hlsElement.play():this.media.play())?n.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}}])&&$n(t.prototype,n),r&&$n(t,r),Object.defineProperty(t,"prototype",{writable:!1}),a}(Dn);function ir(e){return(ir="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 ar(e,t){for(var n=0;n0;)n.post(n._pendingPostRequests.shift());n._responder&&n._responder.onSocketOpen&&n._responder.onSocketOpen(),n.trigger(new en(Ut.OPEN,n._name,{socket:n}))}else 0===e.readyState?++n._readyCheckCount>n._readyCheckLimit?(v(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()):(h(n._name,"WebSocket connection is still opening, will let it continue (".concat(n._readyCheckCount,")...")),n._onopenTimeout=n._resetOnopenTimeout(e,t)):h(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){v(n._name,"[websocketerror]: Error from WebSocket. ".concat(e.type,".")),n.clearRetry(),t.reject(e),n.trigger(new en(Ut.ERROR,n._name,{socket:n,error:e}))},e.onmessage=function(e){n.respond(e)},e.onclose=function(t){t.code>1e3?v(n._name,"[websocketclose]: ".concat(t.code)):p(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 en(Ut.CLOSE,n._name,{socket:n,event:t}))}}},{key:"_onUnexpectedSocketError",value:function(e){this._responder&&this._responder.onSocketClose&&this._responder.onSocketClose(e),this.trigger(new en(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 n=this,r=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),r&&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 n=this.getJsonFromSocketMessage(e);if(null===n)return v(this._name,"Determined websocket response not in correct format. Aborting message handle."),!0;if(p(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;"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}}])&&hr(t.prototype,n),r&&hr(t,r),Object.defineProperty(t,"prototype",{writable:!1}),i}(dr);function _r(e){return(_r="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){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 Sr(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 S;try{var o={iceServers:e,iceCandidatePoolSize:2,bundlePolicy:"max-bundle"};void 0!==n&&(o.rtcpMuxPolicy=n),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,r.resolve(i)}catch(e){v("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 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,r.resolve(o)}catch(e){v("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){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}}])&&Dr(t.prototype,n),r&&Dr(t,r),Object.defineProperty(t,"prototype",{writable:!1}),i}(dr);function Yr(e){return(Yr="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 zr(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;p("R5ProSubscriptionPeer","[peer.oniceconnectionstatechange] - State: ".concat(o)),"connected"===o&&me.getIsEdge()?(p("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(){p("R5ProSubscriptionPeer","[peer.oniceconnectionstatechange] - Reconnect timeout reached. Closing PeerConnection."),clearTimeout(n),r._responder.onPeerConnectionClose(t)}),5e3):n&&(p("R5ProSubscriptionPeer","[peer.oniceconnectionstatechange] - Clearing timeout for reconnect."),clearTimeout(n))},e.onicegatheringstatechange=function(){var t=e.iceGatheringState;p("R5ProSubscriptionPeer","[peer.onicegatheringstatechange] - State: ".concat(t)),"complete"===t&&r._responder.onPeerGatheringComplete()},e.onremovestream=function(){p("R5ProSubscriptionPeer","[peer.onremovestream]")}}},{key:"_onDataChannelMessage",value:function(e){var t=e;if(Kr($r(i.prototype),"_onDataChannelMessage",this).call(this,e))return!0;var n=this.getJsonFromSocketMessage(t);if(null===n)return v(this._name,"Determined websocket response not in correct format. Aborting message handle."),!0;p(this._name,"[datachannel-response]: "+JSON.stringify(n,null,2));var r=n.data;if(r&&"status"===r.type)return"NetStream.Play.UnpublishNotify"===r.code?(this._responder.onUnpublish(),this._responder.onConnectionClosed(),!0):(p("R5ProSubscriptionPeer","[datachannel.message] status :: ".concat(r.code)),this._responder.onSubscriberStatus(r),!0);if(r&&r.status&&"NetStream.Play.UnpublishNotify"===r.status)return this._responder.onUnpublish(),this._responder.onConnectionClosed(),!0;if(r&&"result"===r.type&&"Stream switch: Success"===r.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 n=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)})),n.resolve(e)})).catch(n.reject),n.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))}))}}])&&zr(t.prototype,n),r&&zr(t,r),Object.defineProperty(t,"prototype",{writable:!1}),i}(Wr);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 no(e,t){for(var n=0;n0&&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,n,r;return t=e,(n=[{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}}])&&no(t.prototype,n),r&&no(t,r),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(n,r){t[n]=encodeURIComponent(e[n])})),t},ao=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=e.wsprotocol||e.protocol,r=oo(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=io(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},so=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,f=n||("ws"===r?"http":"https"),h=o||(5080===i?5080:443),p=a?[s,a].join("/"):s,v=l||"4.0";return u&&"streammanager"===s?"".concat(f,"://").concat(d,":").concat(h,"/streammanager/api/").concat(v,"/file/").concat(u.app,"/").concat(c,".m3u8"):"".concat(f,"://").concat(d,":").concat(h,"/").concat(p,"/").concat(c,".m3u8")},co=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]}},uo=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,f=o||("ws"===i?"http":"https"),h=a||(5080===s?5080:443),p=c?[u,c].join("/"):u;if(n)return n;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(f,"://").concat(d,":").concat(h,"/").concat(p,"/").concat(l,".m3u8")},lo=Object.freeze({RTC:"rtc",RTMP:"rtmp",HLS:"hls"}),fo=Object.freeze({OPUS:"OPUS",NONE:"NONE"}),ho=Object.freeze({VP8:"VP8",H264:"H264",H265:"H265",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,n=t.hasOwnProperty,r=Object.defineProperty||function(e,t,n){e[t]=n.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function c(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,n){return e[t]=n}}function u(e,t,n,o){var i=t&&t.prototype instanceof f?t:f,a=Object.create(i.prototype),s=new O(o||[]);return r(a,"_invoke",{value:w(e,n,s)}),a}function l(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var d={};function f(){}function h(){}function p(){}var v={};c(v,i,(function(){return this}));var y=Object.getPrototypeOf,m=y&&y(y(k([])));m&&m!==t&&n.call(m,i)&&(v=m);var b=p.prototype=f.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;r(this,"_invoke",{value:function(r,i){function a(){return new t((function(o,a){!function r(o,i,a,s){var c=l(e[o],e,i);if("throw"!==c.type){var u=c.arg,d=u.value;return d&&"object"==bo(d)&&n.call(d,"__await")?t.resolve(d.__await).then((function(e){r("next",e,a,s)}),(function(e){r("throw",e,a,s)})):t.resolve(d).then((function(e){u.value=e,a(u)}),(function(e){return r("throw",e,a,s)}))}s(c.arg)}(r,i,o,a)}))}return o=o?o.then(a,a):a()}})}function w(e,t,n){var r="suspendedStart";return function(o,i){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw i;return P()}for(n.method=o,n.arg=i;;){var a=n.delegate;if(a){var s=S(a,n);if(s){if(s===d)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=l(e,t,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===d)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}function S(e,t){var n=t.method,r=e.iterator[n];if(void 0===r)return t.delegate=null,"throw"===n&&e.iterator.return&&(t.method="return",t.arg=void 0,S(e,t),"throw"===t.method)||"return"!==n&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+n+"' method")),d;var o=l(r,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,d;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,d):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,d)}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 r=-1,o=function t(){for(;++r=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),C(n),d}},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;C(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:k(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},e}function _o(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 wo(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);function a(e){_o(i,r,o,a,s,"next",e)}function s(e){_o(i,r,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,n,r){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(r.getVideoTracks()[0],o,c));case 9:return e.abrupt("return",$e(n,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,r.getVideoTracks()[0],i.video,c));case 18:return e.abrupt("return",qe(l,n,i.video,c));case 19:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),Co=function(){var e=wo(go().mark((function e(t,n,r){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(r,o,c));case 9:return e.abrupt("return",Ze(n,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,r,i.video,c));case 18:return e.abrupt("return",Xe(l,n,i.video,c));case 19:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),Oo=function(){var e=wo(go().mark((function e(t,n,r){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(r.getAudioTracks()[0],o,c));case 9:return e.abrupt("return",$e(n,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,r.getAudioTracks()[0],i.audio,c));case 18:return e.abrupt("return",qe(l,n,i.audio,c));case 19:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),ko=function(){var e=wo(go().mark((function e(t,n,r){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(r,o,c));case 9:return e.abrupt("return",Ze(n,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,r,i.audio,c));case 18:return e.abrupt("return",Xe(l,n,i.audio,c));case 19:case"end":return e.stop()}}),e)})));return function(t,n,r){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=/(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b) \d+ typ srflx/,Ao=function(e){var t=e.match(Ro);return t&&t.length>1?t[1]:null},Lo={endpoint:void 0,additionalHeaders:void 0,interval:5e3,include:[]};function No(e){return(No="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 jo(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */jo=function(){return e};var e={},t=Object.prototype,n=t.hasOwnProperty,r=Object.defineProperty||function(e,t,n){e[t]=n.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function c(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,n){return e[t]=n}}function u(e,t,n,o){var i=t&&t.prototype instanceof f?t:f,a=Object.create(i.prototype),s=new O(o||[]);return r(a,"_invoke",{value:w(e,n,s)}),a}function l(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var d={};function f(){}function h(){}function p(){}var v={};c(v,i,(function(){return this}));var y=Object.getPrototypeOf,m=y&&y(y(k([])));m&&m!==t&&n.call(m,i)&&(v=m);var b=p.prototype=f.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;r(this,"_invoke",{value:function(r,i){function a(){return new t((function(o,a){!function r(o,i,a,s){var c=l(e[o],e,i);if("throw"!==c.type){var u=c.arg,d=u.value;return d&&"object"==No(d)&&n.call(d,"__await")?t.resolve(d.__await).then((function(e){r("next",e,a,s)}),(function(e){r("throw",e,a,s)})):t.resolve(d).then((function(e){u.value=e,a(u)}),(function(e){return r("throw",e,a,s)}))}s(c.arg)}(r,i,o,a)}))}return o=o?o.then(a,a):a()}})}function w(e,t,n){var r="suspendedStart";return function(o,i){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw i;return P()}for(n.method=o,n.arg=i;;){var a=n.delegate;if(a){var s=S(a,n);if(s){if(s===d)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=l(e,t,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===d)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}function S(e,t){var n=t.method,r=e.iterator[n];if(void 0===r)return t.delegate=null,"throw"===n&&e.iterator.return&&(t.method="return",t.arg=void 0,S(e,t),"throw"===t.method)||"return"!==n&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+n+"' method")),d;var o=l(r,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,d;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,d):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,d)}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 r=-1,o=function t(){for(;++r=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),C(n),d}},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;C(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:k(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},e}function Ho(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 Io(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);function a(e){Ho(i,r,o,a,s,"next",e)}function s(e){Ho(i,r,o,a,s,"throw",e)}a(void 0)}))}}function xo(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 Do(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,n=this.config,r=this.connection;if(r&&"connected"===r.connectionState)try{r.getStats(null).then((function(o){o.forEach((function(o){null!==n.endpoint&&e._handleStatsReport(o),t&&t.onStatsReport&&t.onStatsReport(r,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=Do(Do({},this.identifier.client),e)}},{key:"start",value:(s=Io(jo().mark((function e(t){var n=this;return jo().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(){n.stopped||n._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=Io(jo().mark((function e(t){var n,r,o,i,a,s,c,u,l=this;return jo().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=Do(Do({},this.identifier),{},{type:"stats-report",timestamp:(new Date).getTime(),data:t}),r=this.config,o=r.endpoint,i=r.additionalHeaders,a={"Content-Type":"application/json"},i&&(a=Do(Do({},a),i)),!o){e.next=17;break}return e.prev=5,e.next=8,fetch(o,{method:"POST",headers:a,body:JSON.stringify(n)});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=31;break;case 17:if(!this.client||!this.client.getMessageTransport()){e.next=31;break}if(e.prev=18,c=!1,!(u=this.client.getMessageTransport())){e.next=25;break}return e.next=24,u.post(n);case 24:c=e.sent;case 25:c||(this.queue.push(n),this.client.on(Ut.CHANGE,(function(){l.client.off(Ut.CHANGE),l._emptyStatsReportQueue()})),v(this.NAME,"Failed to post stats data to message transport. Message transport is not available. Pushed to Queue.")),e.next=31;break;case 28:e.prev=28,e.t1=e.catch(18),e.t1(this.NAME,"Failed to post stats data to message transport. ".concat(e.t1.message||e.t1));case 31:case"end":return e.stop()}}),e,this,[[5,12],[18,28]])}))),function(e){return a.apply(this,arguments)})},{key:"postAction",value:(i=Io((function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;return jo().mark((function r(){return jo().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",t.post({action:{type:e,data:n,timestamp:(new Date).getTime()}}));case 1:case"end":return r.stop()}}),r)}))()})),function(e){return i.apply(this,arguments)})},{key:"postEvent",value:(o=Io((function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;return jo().mark((function r(){return jo().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",t.post({event:{type:e,data:n,timestamp:(new Date).getTime()}}));case 1:case"end":return r.stop()}}),r)}))()})),function(e){return o.apply(this,arguments)})},{key:"updateEndpoint",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=this.config.endpoint;t?this.config.endpoint=e:t||n||(this.config.endpoint=e)}},{key:"dispose",value:function(){this.stop(),this.connection=null,this.client=null}}])&&Mo(t.prototype,n),r&&Mo(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function Vo(e){return(Vo="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(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 Wo(e){for(var t=1;t-1)if(t===xt.STREAMING_MODE_CHANGE){var o=r.streamingMode,i=r.previousStreamingMode;n.postEvent(t,{data:{streamingMode:o,previousStreamingMode:i}})}else if(t===xt.PLAYBACK_STATE_CHANGE){var a=r.code,s=void 0;a===wn.AVAILABLE&&(s={timeToFirstFrameMS:(new Date).getTime()-n.startTime}),n.postEvent(Sn[a],s)}else{if(t===xt.STATISTICS_ENDPOINT_CHANGE){var c=r.statisticsEndpoint;n.updateEndpoint(c,!1)}n.postEvent(t)}})),t.on(Mt.CANDIDATE_CREATE,(function(e){var t=e.data.candidate.candidate,r=Ao(t);r&&(n.identifier.publicIP=r)})),t.on(Mt.HOST_ENDPOINT_CHANGED,(function(e){var t=e.data,r=t.endpoint,o=t.iceServers;n.appendClientDetails({node:r,iceServers:o})})),t.getPeerConnection()?n.start(n.client.getPeerConnection()):t.on(Mt.PEER_CONNECTION_AVAILABLE,(function(e){var t=e.data;n.start(t)})),n}return t=i,(n=[{key:"_handleStatsReport",value:function(e){var t=e.type,n=this.config.include,r=n&&n.length>0;if(r&&n.indexOf(t)>=-1)this.post(e);else if(!r)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,d=e.state;this.post({type:t,availableOutgoingBitrate:c,currentRoundTripTime:u,totalRoundTripTime:l,state:d})}else if([To.INBOUND,"inboundrtp"].indexOf(t)>-1){var f=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)/(f-w.timestamp);this.estimatedAudioBitrate=S}this.post(Wo(Wo({},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=Wo(Wo({},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)/(f-M.timestamp);this.estimatedVideoBitrate=F}this.post(Wo(Wo({},D),{},{estimatedBitrate:Math.floor(this.estimatedVideoBitrate)})),this.lastVideoReport=e}}}}])&&Yo(t.prototype,n),r&&Yo(t,r),Object.defineProperty(t,"prototype",{writable:!1}),i}(Bo);function ti(e){return(ti="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 ni(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 ri(e){for(var t=1;t=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),C(n),d}},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;C(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:k(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},e}function ai(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 si(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 ro(t);n.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,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;p("RTCSubscriber","[requestoffer]");var s={requestOffer:e,requestId:t,transport:n,datachannel:r,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,n){p("RTCSubscriber","[sendanswer]: streamname(".concat(e,"), subscriptionid(").concat(t,")")),this.trigger(new Zt(Mt.ANSWER_START,this,n)),this._socketHelper.post({handleAnswer:e,requestId:t,data:{sdp:n}})}},{key:"_sendCandidate",value:function(e){p("RTCSubscriber","[sendcandidate]"),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 n=e.streams,r=e.track,o=e.receiver,i=e.transceiver;o.playoutDelayHint=o.jitterBufferDelayHint=t._options.buffer,t.trigger(new Zt(Mt.TRACK_ADDED,t,{streams:n,track:r,receiver:o,transceiver:i}))}))}},{key:"_setUpMediaTransform",value:(o=function(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);function a(e){ai(i,r,o,a,s,"next",e)}function s(e){ai(i,r,o,a,s,"throw",e)}a(void 0)}))}}(ii().mark((function e(t,n){var r,o,i,a,s;return ii().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,Co(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 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,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 p("RTCSubscriber","[connect]"),r&&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=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 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,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=me.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(!me.supportsHLS()&&!me.supportsNonNativeHLS(a))throw new Error;var c=uo(e,o,i);this._sourceHandler.enableLiveSeek(c,n,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,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=new S,o=e.stats;if(We()&&Lt()){this._disconnect(),this._options=Object.assign({},pi,e),this._options.subscriptionId=this._options.subscriptionId||Te(),this._mediaTransform=n,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 Zr(this),this._socketHelper=new Nr(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(){r.resolve(t),t._connectionClosed=!1,t.trigger(new Zt(xt.CONNECT_SUCCESS,t))})).catch((function(e){r.reject(e),t.trigger(new Zt(xt.CONNECT_FAILURE,t,e))})),this._socketHelper.setUp(a,i)}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&&Ye();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;me.supportsNonNativeHLS(n)?e._sourceHandler=new or(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 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 Kn(t.view,e.getType()))}else e._sourceHandler=new Kn(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(){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,n=t.host,r=t.app,o=t.streamName,i=t.subscriptionId,a=t.connectionParams;return this._statisticsConfiguration=ri(ri({},e),{host:n,app:r,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 ei(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_CREATE,this,{candidate:e})),this._sendCandidate(e)}},{key:"onIceCandidateTrickleEnd",value:function(e){var t=this;p("RTCSubscriber","[onicetrickleend]"),this._getViewResolverPromise().then((function(n){n.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.trigger(new Zt(Mt.CANDIDATE_RECEIVE,this,{candidate:e})),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 n=t.enabled;n||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=hi.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 n=setTimeout((function(){clearTimeout(n),t._socketHelper&&t._socketHelper.sever(t._switchChannelRequest),t._messageTransport=t._peerHelper,t.trigger(new en(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,n=e.streamingMode,r=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!==n&&n!==r&&(this._streamingMode=n,this.trigger(new Zt(xt.STREAMING_MODE_CHANGE,this,{streamingMode:n,previousStreamingMode:r,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 n=e.baseURL,r=e.fullURL,o=t.split("/").pop(),i=t.substr(0,t.lastIndexOf("/".concat(o))),a=ri(ri({},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=uo(a,n,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 n="switchStreams"===e,r=this._options,o=r.app,i=r.streamName;if(n){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 n=Object.keys(l).find((function(t){return t.toLowerCase()===e.toLowerCase()}))?e:l.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 lo.RTC.toUpperCase()}}])&&si(t.prototype,n),r&&si(t,r),Object.defineProperty(t,"prototype",{writable:!1}),a}(Dn),yi=function(e,t){var n=new S,r=e.id;if("video"===e.nodeName.toLowerCase()){var o=me.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},mi=function(e,t,n,r,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 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 bi(e){return(bi="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 n=0;n2&&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=r||t.swf,t.minFlashVersion=o||t.minFlashVersion,this._setUpInitCallback(i);var u=this.media.classList;return yi(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:me.hasAttributeDefined(n.media,"muted"),autoplay:me.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=Oi(t.width)),t.height&&!isNaN(t.height)&&(o.height=Oi(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))),mi(e,t,o,me.getSwfObject(),r)})).then((function(){if(a||c){n._controls=a?t.controls:new Fn(n,n.holder),n.media.controls=!1,n._controls.setAsVOD(ki(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 Zt(xt.PLAYBACK_STATE_CHANGE,void 0,{code:wn.AVAILABLE,state:Sn[wn.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 n="string"==typeof e?encodeURIComponent(e):encodeURIComponent(JSON.stringify(e));this.getEmbeddedView().setABRVariants(n,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}}])&&gi(t.prototype,n),r&&gi(t,r),Object.defineProperty(t,"prototype",{writable:!1}),i}(Dn);function Ti(e){return(Ti="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 Ri(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 ro(t);n.attachSubscriber(this)}}},{key:"_establishExtIntHandlers",value:function(e){var t=this;p("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 Zt(xt.CONNECTION_CLOSED,t))},window[n("r5proConnectSuccess")]=function(){return t.trigger(new Zt(xt.CONNECT_SUCCESS,t))},window[n("r5proConnectFailure")]=function(){t.trigger(new Zt(xt.CONNECT_FAILURE,t))},window[n("r5proSubscribeStop")]=function(){return t.trigger(new Zt(xt.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 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[n("r5proSubscribeUnpublish")]=function(){t.onUnpublish()},window[n("r5proSubscribePublisherCongestion")]=function(e){return t.trigger(new Zt(xt.SUBSCRIBE_PUBLISHER_CONGESTION,t,JSON.parse(e)))},window[n("r5proSubscribePublisherRecovery")]=function(e){return t.trigger(new Zt(xt.SUBSCRIBE_PUBLISHER_RECOVERY,t,JSON.parse(e)))},window[n("r5proSubscribeSendInvoke")]=function(e){t.trigger(new Zt(xt.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 Zt(xt.SUBSCRIBE_START,t))},window[n("r5proSubscribeInvalidName")]=function(){t._subscriptionResolver.reject("NetStream.Play.StreamNotFound",t),t.trigger(new Zt(xt.SUBSCRIBE_INVALID_NAME,t))},window[n("r5proSubscribeFail")]=function(){t._subscriptionResolver.reject("NetStream.Failed",t),t.trigger(new Zt(xt.SUBSCRIBE_FAIL,t))},window[n("r5proSubscribeVolumeChange")]=function(e){t.trigger(new Zt(xt.VOLUME_CHANGE,t,{volume:JSON.parse(e).volume}))},window[n("r5proSubscribePlaybackStalled")]=function(){p("RTMPSubcriber","playback has stalled...")},window[n("r5proSubscribePlaybackTimeChange")]=function(e){var n=JSON.parse(e);t.trigger(new Zt(xt.PLAYBACK_TIME_UPDATE,t,{time:n.value,duration:n.duration}))},window[n("r5proSubscribePlaybackStateChange")]=function(e){var n=JSON.parse(e).code;t.trigger(new Zt(xt.PLAYBACK_STATE_CHANGE,t,{code:n,state:Sn[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 Zt(Ft.ABR_LEVEL_CHANGE,t,{level:r,stream:i}))}}},{key:"init",value:function(e){var t=this,n=new S,r=e.minFlashVersion||Hi.minFlashVersion;if(me.supportsFlashVersion(r)){this._options=Object.assign({},Hi,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(n){t._establishExtIntHandlers(n),e.resolve(t)})).catch((function(t){e.reject(t)})),t._getEmbedPromise()):(t._getViewResolverPromise().then((function(e){if(t._sourceHandler=new Pi(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 Zt(Ft.EMBED_FAILURE,t))}))}catch(e){n.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(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 p("RTMPSubcriber","[unsubscribe]"),new Promise((function(t,n){try{e._sourceHandler.disconnect(),t()}catch(e){n(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()}}])&&Ri(t.prototype,n),r&&Ri(t,r),Object.defineProperty(t,"prototype",{writable:!1}),i}(Dn);function xi(e){return(xi="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 Di(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 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:n.message?n.message:n,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)}}])&&Di(t.prototype,n),r&&Di(t,r),Object.defineProperty(t,"prototype",{writable:!1}),i}(Dn);function Wi(e){return(Wi="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 Yi(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 ro(t);n.attachSubscriber(this)}}},{key:"_initHandler",value:function(e){var t=this,n=this._options,r=n.streamName,o=n.mimeType,i=r.match(Zi)?r: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 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(Zi)?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,n=new S;if(me.supportsHLS())if(e.connectionParams&&!Lt())v("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({},$i,e);var r=new S;if(this._options.connectionParams)try{this._socketHelper=new gr(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=oo(n.port||("wss"===o?443:5080)),a="".concat(o,"://").concat(n.host,":").concat(i,"/").concat(n.app,"/");if(r){var s=io(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 Gi(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 Zt(xt.CONNECT_FAILURE,t,e))}))}else v("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(){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()}}])&&Yi(t.prototype,n),r&&Yi(t,r),Object.defineProperty(t,"prototype",{writable:!1}),i}(Dn);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 na(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */na=function(){return e};var e={},t=Object.prototype,n=t.hasOwnProperty,r=Object.defineProperty||function(e,t,n){e[t]=n.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function c(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,n){return e[t]=n}}function u(e,t,n,o){var i=t&&t.prototype instanceof f?t:f,a=Object.create(i.prototype),s=new O(o||[]);return r(a,"_invoke",{value:w(e,n,s)}),a}function l(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var d={};function f(){}function h(){}function p(){}var v={};c(v,i,(function(){return this}));var y=Object.getPrototypeOf,m=y&&y(y(k([])));m&&m!==t&&n.call(m,i)&&(v=m);var b=p.prototype=f.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;r(this,"_invoke",{value:function(r,i){function a(){return new t((function(o,a){!function r(o,i,a,s){var c=l(e[o],e,i);if("throw"!==c.type){var u=c.arg,d=u.value;return d&&"object"==ta(d)&&n.call(d,"__await")?t.resolve(d.__await).then((function(e){r("next",e,a,s)}),(function(e){r("throw",e,a,s)})):t.resolve(d).then((function(e){u.value=e,a(u)}),(function(e){return r("throw",e,a,s)}))}s(c.arg)}(r,i,o,a)}))}return o=o?o.then(a,a):a()}})}function w(e,t,n){var r="suspendedStart";return function(o,i){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw i;return P()}for(n.method=o,n.arg=i;;){var a=n.delegate;if(a){var s=S(a,n);if(s){if(s===d)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=l(e,t,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===d)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}function S(e,t){var n=t.method,r=e.iterator[n];if(void 0===r)return t.delegate=null,"throw"===n&&e.iterator.return&&(t.method="return",t.arg=void 0,S(e,t),"throw"===t.method)||"return"!==n&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+n+"' method")),d;var o=l(r,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,d;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,d):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,d)}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 r=-1,o=function t(){for(;++r=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),C(n),d}},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;C(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:k(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},e}function ra(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 oa(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);function a(e){ra(i,r,o,a,s,"next",e)}function s(e){ra(i,r,o,a,s,"throw",e)}a(void 0)}))}}function ia(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function aa(e,t){for(var n=0;n0}(e)?"&":"?"},fa=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)},ha=function(e){var t=e.split(":");return t.length>1?{protocol:t[0],host:t[1]}:{protocol:void 0,host:e}},pa=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];ia(this,e),p("WhipWhepSignalingHelper","[whipwhep] ".concat(t)),this._url=t,this._origin=void 0,this._forceHost=r,this._resource=void 0,this._enableSignalingChannel=n}var t,n,r,o,i,a,s,c,u;return t=e,(n=[{key:"getOptions",value:(u=oa((function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return na().mark((function n(){var r,o,i,a,s,c,u,l,d;return na().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return r="".concat(e._url).concat(da(e._url),"signal=").concat(e._enableSignalingChannel),t&&Object.keys(t).forEach((function(e){r+="&".concat(e,"=").concat(t[e])})),p("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=19;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))if(t.indexOf('rel="'.concat(la.ICE_SERVER,'"'))>-1){var r=fa(t),o=r.get("url"),i=ha(o),a=i.protocol,d=i.host,f=r.get("username"),h=r.get("credential");a&&d&&f&&h?u.push({username:f,credential:h,urls:o}):o&&u.push({urls:o})}else if(t.indexOf('rel="'.concat(la.STATISTICS,'"'))>-1){var p=fa(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)),n.abrupt("return",{links:u.length>0?u:void 0,origin:e._origin,statisticsEndpoint:l});case 19:return n.next=21,o.text();case 21:throw d=n.sent,Error("".concat(i,":: ").concat(d));case 23:n.next=29;break;case 25:throw n.prev=25,n.t0=n.catch(3),y("WhipWhepSignalingHelper",n.t0.message),n.t0;case 29:case"end":return n.stop()}}),n,null,[[3,25]])}))()})),function(){return u.apply(this,arguments)})},{key:"postSDPOffer",value:(c=oa((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 na().mark((function o(){var i,a,s,c,u,l,d,f,h;return na().wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return i="".concat(t._url).concat(da(t._url),"signal=").concat(t._enableSignalingChannel),n&&Object.keys(n).forEach((function(e){-1===ua.indexOf(e)&&(i+="&".concat(e,"=").concat(n[e]))})),t._forceHost&&t._origin&&!n.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,!(d=u.get("Location")||u.get("location"))){o.next=23;break}return d.match(/^(http|https)/)?t._resource=d:(p("WhipWhepSignalingHelper","[whipwhep-response] Location provided as relative path: ".concat(d)),(f=new URL(t._url)).pathname=d.split("?")[0],t._resource=f.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(!r||!sa.get(c)){o.next=35;break}if(p("WhipWhepSignalingHelper",sa.get(c)),404!==c&&409!==c){o.next=32;break}throw new U(sa.get(c));case 32:throw new Error(sa.get(c));case 35:if(r||!ca.get(c)){o.next=42;break}if(p("WhipWhepSignalingHelper",ca.get(c)),404!==c&&409!==c){o.next=39;break}throw new U(ca.get(c));case 39:throw new Error(ca.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=oa((function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return na().mark((function r(){var o,i,a,s,c;return na().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return p("WhipWhepSignalingHelper","[whipwhep:post-answer] ".concat(t._resource,": ")+JSON.stringify(e,null,2)),o=t._resource,i=da(o),n&&Object.keys(n).forEach((function(e){-1===ua.indexOf(e)&&(i=da(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(!ca.get(s)){r.next=19;break}throw p("WhipWhepSignalingHelper",ca.get(s)),new Error(ca.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 s.apply(this,arguments)})},{key:"trickle",value:(a=oa((function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return na().mark((function r(){var o,i,a,s,c,u;return na().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return p("WhipWhepSignalingHelper","[whipwhep-trickle] ".concat(t._resource,": ")+JSON.stringify(e,null,2)),o=t._resource,i=da(o),n&&Object.keys(n).forEach((function(e){-1===ua.indexOf(e)&&(i=da(o),o+="".concat(i).concat(e,"=").concat(n[e]))})),t._forceHost&&t._origin&&!n.host&&(i=da(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,p("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 a.apply(this,arguments)})},{key:"tearDown",value:(i=oa((function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return na().mark((function n(){var r,o;return na().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=da(r),t&&Object.keys(t).forEach((function(e){-1===ua.indexOf(e)&&(o=da(r),r+="".concat(o).concat(e,"=").concat(t[e]))})),e._forceHost&&e._origin&&!t.host&&(o=da(r),r+="".concat(o,"host=").concat(e._origin)),p("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 i.apply(this,arguments)})},{key:"post",value:(o=oa((function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return na().mark((function t(){return na().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(p("WhipWhepSignalingHelper","[whipwhep] transport called."),!e){t.next=3;break}return t.abrupt("return",!1);case 3:return t.abrupt("return",!0);case 4:case"end":return t.stop()}}),t)}))()})),function(){return o.apply(this,arguments)})}])&&aa(t.prototype,n),r&&aa(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}(),va=Object.freeze({EMPTY:"Empty",VIDEO:"Video",AUDIO:"Audio",FULL:"Video/Audio"});function ya(e){return(ya="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 ma(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ma=function(){return e};var e={},t=Object.prototype,n=t.hasOwnProperty,r=Object.defineProperty||function(e,t,n){e[t]=n.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function c(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,n){return e[t]=n}}function u(e,t,n,o){var i=t&&t.prototype instanceof f?t:f,a=Object.create(i.prototype),s=new O(o||[]);return r(a,"_invoke",{value:w(e,n,s)}),a}function l(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var d={};function f(){}function h(){}function p(){}var v={};c(v,i,(function(){return this}));var y=Object.getPrototypeOf,m=y&&y(y(k([])));m&&m!==t&&n.call(m,i)&&(v=m);var b=p.prototype=f.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;r(this,"_invoke",{value:function(r,i){function a(){return new t((function(o,a){!function r(o,i,a,s){var c=l(e[o],e,i);if("throw"!==c.type){var u=c.arg,d=u.value;return d&&"object"==ya(d)&&n.call(d,"__await")?t.resolve(d.__await).then((function(e){r("next",e,a,s)}),(function(e){r("throw",e,a,s)})):t.resolve(d).then((function(e){u.value=e,a(u)}),(function(e){return r("throw",e,a,s)}))}s(c.arg)}(r,i,o,a)}))}return o=o?o.then(a,a):a()}})}function w(e,t,n){var r="suspendedStart";return function(o,i){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw i;return P()}for(n.method=o,n.arg=i;;){var a=n.delegate;if(a){var s=S(a,n);if(s){if(s===d)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=l(e,t,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===d)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}function S(e,t){var n=t.method,r=e.iterator[n];if(void 0===r)return t.delegate=null,"throw"===n&&e.iterator.return&&(t.method="return",t.arg=void 0,S(e,t),"throw"===t.method)||"return"!==n&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+n+"' method")),d;var o=l(r,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,d;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,d):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,d)}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 r=-1,o=function t(){for(;++r=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),C(n),d}},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;C(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:k(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},e}function ba(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 ga(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);function a(e){ba(i,r,o,a,s,"next",e)}function s(e){ba(i,r,o,a,s,"throw",e)}a(void 0)}))}}function _a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function wa(e,t){for(var n=0;n2&&void 0!==arguments[2])||arguments[2];_a(this,g),n=b.call(this);var o=e?co(e):ja;return o.mediaElementId=t?t.id:ja.mediaElementId,o.trickleIce=r,n._whipHelper=void 0,n._videoMuted=!0,n._audioMuted=!0,n._videoUnmuteHandler=n._onVideoUnmute.bind(Pa(n)),n._audioUnmuteHandler=n._onAudioUnmute.bind(Pa(n)),e&&n._internalConnect(o),n}return t=g,(n=[{key:"_runMuteCheck",value:(m=ga(ma().mark((function e(){var t,n=this;return ma().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?va.FULL:r?va.VIDEO:o?va.AUDIO:va.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 r,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 n=setTimeout(ga(ma().mark((function e(){return ma().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(ga(ma().mark((function e(){return ma().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 pa(this._whipUrl,c,u)}},{key:"_glomSourceHandlerAPI",value:function(e){var t=this;Sa(Ta(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=ga(ma().mark((function e(t){return ma().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:(f=ga(ma().mark((function e(t){return ma().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 f.apply(this,arguments)})},{key:"_sendCandidate",value:function(e){p("WHEPClient","[sendcandidate]"),this.trigger(new Zt(Mt.CANDIDATE_CREATE,this,{candidate:e}))}},{key:"_postOffer",value:(d=ga((function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return ma().mark((function r(){var o,i,a,s,c,u,l,d,f,h;return ma().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.iceTransport,u=o.connectionParams,l=o.postEmptyOffer,d=o.mungeOffer,f=Aa(Aa({},u),{},{transport:c,doNotSwitch:i}),void 0!==a&&a!==ho.NONE&&(f.videoEncoding=a),void 0!==s&&s!==fo.NONE&&(f.audioEncoding=s),h="",l||(h=e.sdp,d&&(h=d(h)),n||(h=nt(h),h=ot(h)),h=bt(h)),r.next=9,t._whipHelper.postSDPOffer(h,f,!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 U?t.onStreamUnavailable(r.t0):(t.trigger(new Zt(xt.CONNECT_FAILURE,t)),t.unsubscribe(),t._subscriptionResolver.reject("Stream failure."));case 16:case"end":return r.stop()}}),r,null,[[0,12]])}))()})),function(e){return d.apply(this,arguments)})},{key:"_postEmptyOffer",value:(l=ga(ma().mark((function e(){var t,n,r,o,i,a,s;return ma().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,t=this._options,n=t.maintainStreamVariant,r=t.iceTransport,o=t.videoEncoding,i=t.audioEncoding,a=t.connectionParams,s=Aa(Aa({},a),{},{transport:r,doNotSwitch:n}),void 0!==o&&o!==ho.NONE&&(s.videoEncoding=o),void 0!==i&&i!==fo.NONE&&(s.audioEncoding=i),e.next=7,this._whipHelper.postSDPOffer("",s,!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=ga(ma().mark((function e(t,n,r){var o,i,a,s,c;return ma().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(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 u.apply(this,arguments)})},{key:"_postCandidateFragments",value:(c=ga(ma().mark((function e(t){var n,r;return ma().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this._options.connectionParams,r=_t(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 c.apply(this,arguments)})},{key:"_requestOffer",value:(s=ga(ma().mark((function e(){var t,n,r,o,i,a,s,c,u,l,d,f,h,v,m,b,g,_,w,S,E,C,O;return ma().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(p("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 Zt(Mt.OFFER_START,this)),e.next=9,this._postEmptyOffer();case 9:return l=e.sent,d=l.sdp,this.trigger(new Zt(Mt.OFFER_END,this)),f=new At({type:"offer",sdp:d}),p("WHEPClient","[requestoffer:empty:remote] ".concat(JSON.stringify(f,null,2))),e.next=16,c.setRemoteDescription(f);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,n);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),!n||!c.canTrickleIceCandidates){e.next=60;break}return p("WHEPClient","[trickle:ice] enabled"),_.sdp=rt(_.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=nt(_.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=nt(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,Sa(Ta(g.prototype),"_disconnect",this).call(this)}},{key:"init",value:(a=ga((function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;return ma().mark((function r(){var o,i,a,s,c,u,l,d,f,h,p,v,y;return ma().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(We()){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=Aa(Aa({},ja),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,d=o.subscriptionId,f=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(d):"".concat(y,"/whep/endpoint/").concat(l,"?requestId=").concat(d),t._whipHelper=new pa(t._whipUrl,f,h),t._peerHelper=new Zr(t),t._messageTransport=t._whipHelper,t._mediaTransform=n,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),r.abrupt("return",t);case 18:case"end":return r.stop()}}),r)}))()})),function(e){return a.apply(this,arguments)})},{key:"subscribe",value:(i=ga(ma().mark((function e(){var t,n,r,o,i,a,s,c,u,l,d,f,h,p=this;return ma().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=this._options,n=t.mediaElementId,r=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,n),this._getViewResolverPromise().then((function(e){if(o&&o.enabled){var t=o.hlsjsRef,n=o.usePlaybackControlsUI,r=o.options;me.supportsNonNativeHLS(t)?p._sourceHandler=new or(e.view,p.getType(),r,n):(y("WHEPClient","Could not utilize the 'LiveSeek' request. This feature requires either native HLS playback or hls.js as a depenency."),p.trigger(new Zt(Mt.LIVE_SEEK_UNSUPPORTED,p,{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."})),p._sourceHandler=new Kn(e.view,p.getType()))}else p._sourceHandler=new Kn(e.view,p.getType());p._glomSourceHandlerAPI(p._sourceHandler),p._initHandler(p._options,p._sourceHandler)})).catch((function(){})),this._getAvailabilityResolverPromise().catch((function(){})),l=i||{},e.next=13,this._whipHelper.getOptions(l);case 13:return(d=e.sent)&&(d.links&&(this._options.rtcConfiguration=Aa(Aa({},r),{},{iceServers:d.links})),d.origin&&this.trigger(new Zt(Mt.HOST_ENDPOINT_CHANGED,this,{endpoint:d.origin,iceServers:d.links})),d.statisticsEndpoint&&this.trigger(new Zt(xt.STATISTICS_ENDPOINT_CHANGE,this,{statisticsEndpoint:d.statisticsEndpoint}))),f=this._options.enableChannelSignaling?c:void 0,h=r,void 0===r.encodedInsertableStreams&&(h=Object.assign(r,{encodedInsertableStreams:!!this._mediaTransform})),this._connect(h,f,this._options.iceServers),this._connectionClosed=!1,e.abrupt("return",this._getSubscriptionResolverPromise());case 23:throw e.prev=23,e.t0=e.catch(6),this.trigger(new Zt(xt.CONNECT_FAILURE),this,e.t0),e.t0;case 27:case"end":return e.stop()}}),e,this,[[6,23]])}))),function(){return i.apply(this,arguments)})},{key:"onAnswerMediaStream",value:(o=ga((function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;return ma().mark((function n(){return ma().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:Sa(Ta(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 n.stop()}}),n)}))()})),function(){return o.apply(this,arguments)})},{key:"onPeerConnectionOpen",value:function(){var e=this._options.enableChannelSignaling;Sa(Ta(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(Sa(Ta(g.prototype),"onDataChannelOpen",this).call(this,e),t){var n=t.name;Sa(Ta(g.prototype),"onDataChannelAvailable",this).call(this,n)}else Sa(Ta(g.prototype),"onDataChannelAvailable",this).call(this);this.trigger(new Zt(xt.SUBSCRIBE_START,this))}},{key:"getConnection",value:function(){}}])&&wa(t.prototype,n),r&&wa(t,r),Object.defineProperty(t,"prototype",{writable:!1}),g}(vi);function Ia(e){return(Ia="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){return function(e){if(Array.isArray(e))return Da(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 Da(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Da(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 Da(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n2&&void 0!==arguments[2]?arguments[2]:null,r=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=n||t.swf,t.minFlashVersion=r||t.minFlashVersion,yi(this.video,this.holder).then((function(n){p("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=qa(t.mediaConstraints,r),mi(e,t,r,me.getSwfObject(),n)})).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 n=me.getEmbedObject(this._swfId);n&&n.send(e,t)}},{key:"setMediaQuality",value:function(e){var t=me.getEmbedObject(this._swfId);if(t&&e.video&&"boolean"!=typeof e.video){var n=isNaN(e.video.width)?Number.isNaN:Pe(e.video.width),r=isNaN(e.video.height)?Number.isNaN:Pe(e.video.height);t.updateResolution(n,r)}}},{key:"getType",value:function(){return this._publisherType}}])&&Ja(t.prototype,n),r&&Ja(t,r),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 $a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Za(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:"red5pro-publisher";$a(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,n,r;return t=e,(n=[{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}}])&&Za(t.prototype,n),r&&Za(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}(),ts=Object.freeze({RTMP:"rtmp",RTC:"rtc"}),ns=Object.freeze({LIVE:"live",RECORD:"record",APPEND:"append"}),rs=Object.freeze({OPUS:"OPUS"}),os=Object.freeze({VP8:"VP8",H264:"H264",H265:"H265"});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){for(var n=0;n0&&void 0!==arguments[0])||arguments[0],n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;cs(this,e),us(this,"audio",t),us(this,"video",n||new ls)}));function hs(e){return(hs="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 ps(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;cs(this,e),us(this,"audio",t),us(this,"video",n||new ds)})))},_s=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&&vs(e,t)}(i,e);var t,n,r,o=ys(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,(n=[{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 es(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 Xa(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 $t(It.EMBED_FAILURE,n))})),this}},{key:"_setUpConnectCallback",value:function(e){var t=this;window.setActiveId=function(n){p("RTMPPublisher","Embed and connect() complete for publisher swf. successId(".concat(n,").")),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,n=function(e){return["publisher",e,t.split("-").join("_")].join("_")};window[n("r5proConnectClosed")]=function(){e.trigger(new $t(Nt.CONNECTION_CLOSED,e))},window[n("r5proConnectSuccess")]=function(){return e.trigger(new $t(Nt.CONNECT_SUCCESS,e))},window[n("r5proUnpublishSuccess")]=function(){return e.trigger(new $t(Nt.UNPUBLISH_SUCCESS,e))},window[n("r5proPublishStart")]=function(){e._connectFuture.resolve(e),e.trigger(new $t(Nt.PUBLISH_START,e))},window[n("r5proPublishMetadata")]=function(t){return e.trigger(new $t(Nt.PUBLISH_METADATA,e,t))},window[n("r5proPublishInsufficientBW")]=function(t){return e.trigger(new $t(Nt.PUBLISH_INSUFFICIENT_BANDWIDTH,e,t))},window[n("r5proPublishSufficientBW")]=function(t){return e.trigger(new $t(Nt.PUBLISH_SUFFICIENT_BANDWIDTH,e,t))},window[n("r5proPublishRecoveringBW")]=function(t){return e.trigger(new $t(Nt.PUBLISH_RECOVERING_BANDWIDTH,e,t))},window[n("r5proConnectFailure")]=function(){e._connectFuture.reject(Nt.CONNECT_FAILURE),e.trigger(new $t(Nt.CONNECT_FAILURE,e))},window[n("r5proPublishFail")]=function(){e._connectFuture.reject(Nt.PUBLISH_FAIL),e.trigger(new $t(Nt.PUBLISH_FAIL,e))},window[n("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,n=new S,r=e.minFlashVersion||gs.minFlashVersion;if(me.supportsFlashVersion(r)){this._options=Object.assign({},gs,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),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 $t(It.EMBED_FAILURE,t))}))}catch(e){n.reject("Could not inject Flash-based Publisher into the page. Reason: ".concat(e.message)),t.trigger(new $t(It.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 S;this._setUpConnectCallback(r),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 n;n=setTimeout((function(){try{clearTimeout(n),i.connect(JSON.stringify(o))}catch(n){if(t++>100)throw n;e()}}),300)}()})).catch((function(t){r.reject(t),e.trigger(new $t(Nt.CONNECT_FAILURE,e))}))}catch(e){y("RTMPPublisher","[handler:embed:error]"),r.reject("Could not initiate connection sequence. Reason: ".concat(e.message)),this.trigger(new $t(Nt.CONNECT_FAILURE,this)),this._tearDownConnectCallback()}return this._connectFuture=r,r.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 ts.RTMP.toUpperCase()}}])&&ps(t.prototype,n),r&&ps(t,r),Object.defineProperty(t,"prototype",{writable:!1}),i}(H);function ws(e){return(ws="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 Ss(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 Es(e){for(var t=1;t=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),C(n),d}},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;C(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:k(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},e}function xs(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;n0&&void 0!==arguments[0]?arguments[0]:null,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;p("R5ProPublishPeer","[createoffer]");var o=r||new S;return this._peerConnection.createOffer().then((function(r){e.setLocalDescription(r,t).then((function(){var i=r.sdp;t&&(i=ht(t,i)),n&&(i=st(i),i=ct(i),i=dt(i),i=ft(i)),r.sdp=i,e._responder.onSDPSuccess(),o.resolve(r)})).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,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);function a(e){xs(i,r,o,a,s,"next",e)}function s(e){xs(i,r,o,a,s,"throw",e)}a(void 0)}))}}((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];return Is().mark((function r(){var o,i;return Is().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return p("R5ProPublishPeer","[createoffer:withoutlocal]"),r.prev=1,r.next=4,e._peerConnection.createOffer();case 4:return o=r.sent,i=o.sdp,t&&(i=ht(t,i)),n&&(i=st(i),i=ct(i),i=dt(i),i=ft(i)),o.sdp=i,e._responder.onSDPSuccess(),r.abrupt("return",o);case 13:throw r.prev=13,r.t0=r.catch(1),p("R5ProPublishPeer","[createoffer:error]"),e._responder.onSDPError(r.t0),r.t0;case 18:case"end":return r.stop()}}),r,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})}}])&&Ds(t.prototype,n),r&&Ds(t,r),Object.defineProperty(t,"prototype",{writable:!1}),a}(Wr),Ys={endpoint:void 0,protocol:"wss",port:443,app:"live",streamMode:ns.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 fs,onGetUserMedia:void 0,signalingSocketOnly:!0,dataChannelConfiguration:void 0,forceVP8:!1,socketSwitchDelay:1e3,bypassAvailable:!1,stats:void 0};function zs(e){return(zs="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 Js(e){for(var t=1;t-1){if(t===Nt.STATISTICS_ENDPOINT_CHANGE){var o=r.statisticsEndpoint;n.updateEndpoint(o,!1)}n.postEvent(t)}})),t.on(Ht.CANDIDATE_CREATE,(function(e){var t=e.data.candidate.candidate,r=Ao(t);r&&(n.identifier.publicIP=r)})),t.on(Ht.HOST_ENDPOINT_CHANGED,(function(e){var t=e.data,r=t.endpoint,o=t.iceServers;n.appendClientDetails({node:r,iceServers:o})})),t.getPeerConnection()?n.start(n.client.getPeerConnection()):t.on(Ht.PEER_CONNECTION_AVAILABLE,(function(e){var t=e.data;n.start(t)})),n}return t=i,(n=[{key:"_handleStatsReport",value:function(e){var t=e.type,n=this.config.include,r=n&&n.length>0;if(r&&n.indexOf(t)>=-1)this.post(e);else if(!r)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,d=e.state;this.post({type:t,availableOutgoingBitrate:c,currentRoundTripTime:u,totalRoundTripTime:l,state:d})}else if(t===To.MEDIA_SOURCE){var f=e.kind;if("audio"===f)this.post({type:t,kind:f});else if("video"===f){var h=e.framesPerSecond,p=e.height,v=e.width;this.post({type:t,kind:f,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(Js(Js({},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=Js(Js({},S),{},{firCount:O,pliCount:k,frameWidth:P,frameHeight:T,framesEncoded:R,framesPerSecond:A,framesSent:L,keyFramesEncoded:N});if("none"!==j&&(I=Js(Js({},I),{},{qualityLimitationReason:j,qualityLimitationDurations:H})),this.lastVideoReport){var x=this.lastVideoReport,D=8*(w-x.bytesSent)/(y-x.timestamp);this.estimatedVideoBitrate=D}this.post(Js(Js({},I),{},{estimatedBitrate:Math.floor(this.estimatedVideoBitrate)})),this.lastVideoReport=e}}}}])&&qs(t.prototype,n),r&&qs(t,r),Object.defineProperty(t,"prototype",{writable:!1}),i}(Bo);function ic(e){return(ic="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 ac(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 sc(e){for(var t=1;t=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),C(n),d}},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;C(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:k(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},e}function lc(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 dc(e,t){for(var n=0;n1)&&"video"===t[0].kind};void 0!==e.onGetUserMedia?(wc("Requesting gUM from user-defined configuration:onGetUserMedia."),e.onGetUserMedia().then((function(r){if(n(r))return wc("We received a MediaStream with mismatching track listing. Trying again..."),void t._gum(e);t.trigger(new $t(Ht.CONSTRAINTS_ACCEPTED,t,Cc(r))),t._streamFuture.resolve(r)})).catch((function(n){Ec("Could not resolve MediaStream from provided gUM. Error - ".concat(n)),t.trigger(new $t(Ht.CONSTRAINTS_REJECTED,t,{constraints:e.mediaConstraints})),t._streamFuture.reject(n)}))):(wc("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 wc("We received a MediaStream with mismatching track listing. Trying again..."),void t._gum(e);wc("Found valid constraints: ".concat(JSON.stringify(r.constraints,null,2))),t.trigger(new $t(Ht.CONSTRAINTS_ACCEPTED,t,Cc(r.media))),t.trigger(new $t(Nt.DIMENSION_CHANGE,t,r.constraints)),t._streamFuture.resolve(r.media)})).catch((function(n){wc("Could not find valid constraint resolutions from: ".concat(JSON.stringify(n.constraints,null,2))),Ec("Could not resolve MediaStream from provided mediaConstraints. Error - ".concat(n.error)),wc("Attempting to find resolutions from original provided constraints: ".concat(JSON.stringify(n.constraints,null,2))),t.trigger(new $t(Ht.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 $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 n=new es(t);n.attachPublisher(this)}}},{key:"_requestAvailability",value:function(e){return wc("[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,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;return wc("[createpeeer]"),this._peerFuture=void 0,this._peerFuture=E.createIfNotExist(this._peerFuture),n&&e&&(Sc("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;return wc("[createoffer]"),this._offerFuture=void 0,this._offerFuture=E.createIfNotExist(this._offerFuture),this._peerHelper.createOffer(e,!1,this._offerFuture),this._offerFuture.promise}},{key:"_setRemoteDescription",value:function(e){return wc("[setremotedescription]"),this._peerHelper.setRemoteDescription(e)}},{key:"_sendOffer",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:void 0,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0;wc("[sendoffer]");var i={handleOffer:t,transport:n,data:{sdp:e}};return r&&(i.videoEncoding=r),o&&(i.audioEncoding=o),this._sendOfferFuture=void 0,this._sendOfferFuture=E.createIfNotExist(this._sendOffFuture),this._socketHelper.post(i),this._sendOfferFuture.promise}},{key:"_sendCandidate",value:function(e,t){wc("[sendcandidate]"),this._socketHelper.post({handleCandidate:t,data:{candidate:e}})}},{key:"_requestPublish",value:function(e,t,n){return wc("[requestpublish]"),this._publishFuture=void 0,this._publishFuture=E.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=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,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);function a(e){lc(i,r,o,a,s,"next",e)}function s(e){lc(i,r,o,a,s,"throw",e)}a(void 0)}))}}(uc().mark((function e(t,n,r){var o,i,a,s,c,u,l,d;return uc().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,Eo(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 $t(Ht.TRANSFORM_ERROR,this,{type:"video",error:e.t0}));case 15:if(u&&(i||s))try{(d=Oo(t,u,r)).generator&&(this._mediaStream.addTrack(d.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,n){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 n=new S,r=e.stats;return We()&&Lt()?(this._options=sc(sc({},_c),e),this._peerHelper=new Ws(this),this._socketHelper=new js(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),r&&this.monitorStats(r),this._getMediaStream().then(this._onMediaStreamReceived.bind(this)).catch((function(e){Sc("[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;wc("[initWithStream]"),this._streamFuture=void 0;var r=new S,o=e.stats;if(We()&&Lt()){this._mediaTransform=n,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=sc(sc({},_c),e),this._peerHelper=new Ws(this),this._socketHelper=new js(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){Sc("[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;wc("[preview]");var t=new Promise((function(t){t(e)}));return this._setViewIfNotExist(this._view,this._options.mediaElementId),t}},{key:"unpreview",value:function(){wc("[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;wc("[publish]"),this._options.streamName=t||this._options.streamName;var r=n||new S,o=new S,i=ao(this._options,{id:this._options.streamName});this._trickleEndFuture=this._getTrickleEnd(),this._peerHelper||(this._peerHelper=new Ws(this)),this._socketHelper?this._socketHelper.clearRetry():(this._socketHelper=new js(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();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),r.reject(t),e.trigger(new $t(Nt.CONNECT_FAILURE,e,t))}));var d=this._options,f=d.forceVP8,h=d.videoEncoding,p=d.audioEncoding;return f&&(h=os.VP8,this._options.videoEncoding=h),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){return e.trigger(new $t(Ht.PEER_CONNECTION_AVAILABLE,e,t)),e._mediaStream.getTracks().forEach((function(n){t.addTrack(n,e._mediaStream)})),t.getTransceivers().forEach((function(e){if(e.sender&&e.sender.track){var t=e.sender.track.kind;if(h&&"video"===t&&e.setCodecPreferences){var n=RTCRtpSender.getCapabilities("video").codecs;try{var r=n.findIndex((function(e){return e.mimeType==="video/".concat(h)}));if(r>-1){var o=n.slice(0),i=n[r];o.splice(r,1),o.unshift(i),e.setCodecPreferences(o)}}catch(e){Sc("[videoEncoding] Could not set codec preferences for ".concat(h,". ").concat(e.message||e))}}else if(p&&"audio"===t&&e.setCodecPreferences)try{var a=RTCRtpSender.getCapabilities("audio").codecs,s=a.findIndex((function(e){return e.mimeType==="audio/".concat(p)}));if(s>-1){var c=a[s];a.splice(s,1),a.unshift(c),e.setCodecPreferences(a)}}catch(e){Sc("[audioEncoding] Could not set codec preferences for ".concat(p,". ").concat(e.message||e))}}})),e._createOffer(e._options.bandwidth)})).then((function(t){var n=e._options,r=n.streamName,o=n.iceTransport,i=n.videoEncoding,a=n.audioEncoding;return e.trigger(new $t(Ht.OFFER_START,e,t)),e._sendOffer(t,r,o,i,a)})).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),r.resolve(e),e.trigger(new $t(Nt.PUBLISH_START,e))})).catch((function(t){me.removeOrientationChangeHandler(e._onOrientationChange),r.reject(t),e.trigger(new $t(Nt.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;wc("[publishWithSocket]"),this._options.streamName=n||this._options.streamName;var o=r||new S,i=new S;return this._socketHelper=new js(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];wc("[unpublish]");var n=function(){e._socketHelper&&(wc("[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 $t(Nt.UNPUBLISH_SUCCESS,e)),e.unmonitorStats()})).catch((function(){e.unmonitorStats()})),me.removeOrientationChangeHandler(this._onOrientationChange),r}},{key:"monitorStats",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this._options,n=t.host,r=t.app,o=t.streamName,i=t.connectionParams;return this._statisticsConfiguration=sc(sc({},e),{host:n,app:r,streamName:o,connectionParams:i}),this._statsMonitor?Sc("RTCPublisher"):this._statsMonitor=new oc(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 n=Object.keys(l).find((function(t){return t.toLowerCase()===e.toLowerCase()}))?e:l.DEBUG,r="string"==typeof t?t:JSON.stringify(t);this.getMessageTransport().post({log:n.toUpperCase(),message:r})}catch(e){e.message,Ec("RTCPublisher"),Ec("RTCPublisher")}}},{key:"onStreamAvailable",value:function(e){wc("[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){wc("Stream ".concat(this._options.streamName," does not exist.")),wc("[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;Ec("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){wc("[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||(wc("RTCPublisher"),this.unpublish(),this.trigger(new $t(Nt.CONNECTION_CLOSED,this,e)))}},{key:"onPeerConnectionFail",value:function(){wc("[onpeerconnectionfail]"),this.trigger(new $t(Nt.PUBLISH_FAIL,this)),this._publishFuture&&this._publishFuture.reject("Peer Connection Failed.")}},{key:"onPeerConnectionClose",value:function(e){wc("[onpeerconnectionclose]"),this._socketHelper&&(wc("[onpeerconnectionclose:teardown]"),this._socketHelper.tearDown()),this.onSocketClose(e)}},{key:"onPeerConnectionOpen",value:function(){wc("[onpeerconnection::open]"),this.trigger(new $t(Ht.PEER_CONNECTION_OPEN),this,this.getPeerConnection())}},{key:"onPeerConnectionTrackAdd",value:function(e){wc("[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):"";wc("[onsdpsuccess]".concat(t))}},{key:"onSDPError",value:function(e){this.trigger(new $t(Nt.PUBLISH_FAIL,this));var t=e?": "+JSON.stringify(e,null,2):"";Ec("[onsdperror]".concat(t))}},{key:"onSDPAnswer",value:function(e){wc("[sdpanswer]:: "+JSON.stringify(e,null,2)),this._sendOfferFuture=E.createIfNotExist(this._sendOfferFuture),this._sendOfferFuture.resolve(e)}},{key:"onAddIceCandidate",value:function(e){wc("[addicecandidate]"),this.trigger(new $t(Ht.PEER_CANDIDATE_RECEIVE,this,{candidate:e})),this._peerHelper.addIceCandidate(e).then((function(){wc("[addicecandidate:success]")})).catch((function(e){Sc("[addicecandidate:error] - ".concat(e))}))}},{key:"onIceCandidate",value:function(e){wc("[icecandidatetrickle]"),this.trigger(new $t(Ht.CANDIDATE_CREATE,this,{candidate:e})),this._sendCandidate(e,this._options.streamName)}},{key:"onIceCandidateTrickleEnd",value:function(){wc("[icecandidatetrickle:end]")}},{key:"onEmptyCandidate",value:function(){wc("[icecandidatetrickle:empty]"),this.trigger(new $t(Ht.PEER_CANDIDATE_END))}},{key:"onPeerGatheringComplete",value:function(){wc("[icecandidategathering:end]"),this._socketHelper&&this._socketHelper.postEndOfCandidates(this._options.streamName)}},{key:"onSocketIceCandidateEnd",value:function(){wc("[socketicecandidate:end]"),this._getTrickleEnd().resolve()}},{key:"onPublisherStatus",value:function(e){wc("[publisherstatus] - "+JSON.stringify(e,null,2));var t=gc.exec(e.message),n=bc.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 $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(wc("[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 en(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 ts.RTC.toUpperCase()}}])&&dc(t.prototype,n),r&&dc(t,r),Object.defineProperty(t,"prototype",{writable:!1}),a}(H);function kc(e){return(kc="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 Pc(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */Pc=function(){return e};var e={},t=Object.prototype,n=t.hasOwnProperty,r=Object.defineProperty||function(e,t,n){e[t]=n.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function c(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,n){return e[t]=n}}function u(e,t,n,o){var i=t&&t.prototype instanceof f?t:f,a=Object.create(i.prototype),s=new O(o||[]);return r(a,"_invoke",{value:w(e,n,s)}),a}function l(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var d={};function f(){}function h(){}function p(){}var v={};c(v,i,(function(){return this}));var y=Object.getPrototypeOf,m=y&&y(y(k([])));m&&m!==t&&n.call(m,i)&&(v=m);var b=p.prototype=f.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;r(this,"_invoke",{value:function(r,i){function a(){return new t((function(o,a){!function r(o,i,a,s){var c=l(e[o],e,i);if("throw"!==c.type){var u=c.arg,d=u.value;return d&&"object"==kc(d)&&n.call(d,"__await")?t.resolve(d.__await).then((function(e){r("next",e,a,s)}),(function(e){r("throw",e,a,s)})):t.resolve(d).then((function(e){u.value=e,a(u)}),(function(e){return r("throw",e,a,s)}))}s(c.arg)}(r,i,o,a)}))}return o=o?o.then(a,a):a()}})}function w(e,t,n){var r="suspendedStart";return function(o,i){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw i;return P()}for(n.method=o,n.arg=i;;){var a=n.delegate;if(a){var s=S(a,n);if(s){if(s===d)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=l(e,t,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===d)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}function S(e,t){var n=t.method,r=e.iterator[n];if(void 0===r)return t.delegate=null,"throw"===n&&e.iterator.return&&(t.method="return",t.arg=void 0,S(e,t),"throw"===t.method)||"return"!==n&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+n+"' method")),d;var o=l(r,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,d;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,d):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,d)}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 r=-1,o=function t(){for(;++r=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),C(n),d}},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;C(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:k(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},e}function Tc(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 Rc(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);function a(e){Tc(i,r,o,a,s,"next",e)}function s(e){Tc(i,r,o,a,s,"throw",e)}a(void 0)}))}}function Ac(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Lc(e,t){for(var n=0;n2&&void 0!==arguments[2])||arguments[2];Ac(this,h),n=f.call(this);var o=e?co(e):Vc;return o.mediaElementId=t?t.id:Vc.mediaElementId,o.trickleIce=r,n._whipHelper=void 0,e&&n._internalConnect(o),n}return t=h,(n=[{key:"_internalConnect",value:(d=Rc(Pc().mark((function e(t){return Pc().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 d.apply(this,arguments)})},{key:"waitToGatherIce",value:(l=Rc(Pc().mark((function e(t){return Pc().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Gc("[waittogatherice]"),e.abrupt("return",new Promise((function(e,n){if("complete"===t.iceGatheringState)Gc("[waittogatherice] ice gathering state complete."),t.addIceCandidate(null).then((function(){e(t.localDescription)})).catch((function(n){Wc("Error adding null candidate: "+n.message||!1),e(t.localDescription)}));else{Gc("[waittogatherice] waiting...");var r=setTimeout((function(){clearTimeout(r),t.addIceCandidate(null).then((function(){e(t.localDescription)})).catch((function(n){Wc("Error adding null candidate: "+n.message||!1),e(t.localDescription)}))}),1e3);t.onicegatheringstatechange=function(){clearTimeout(r),Gc("[waittogatherice] ice gathering state complete."),"complete"===t.iceGatheringState&&t.addIceCandidate(null).then((function(){e(t.localDescription)})).catch((function(n){Wc("Error adding null candidate: "+n.message||!1),e(t.localDescription)}))}}})));case 2:case"end":return e.stop()}}),e)}))),function(e){return l.apply(this,arguments)})},{key:"_postOffer",value:(u=Rc((function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return Pc().mark((function r(){var o,i,a,s,c,u,l,d,f,h,p,v;return Pc().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.iceTransport,l=i.connectionParams,d=i.forceVP8,f=i.videoEncoding,h=i.audioEncoding,d&&!f&&(f=os.VP8),p=o,a&&(p=a(p)),n||(p=nt(p),p=ot(p)),v=Fc(Fc({},l),{},{mode:s,transport:u,keyFramerate:c}),f&&(v.videoEncoding=f),h&&(v.audioEncoding=h),r.next=12,t._whipHelper.postSDPOffer(p,v);case 12:return r.abrupt("return",r.sent);case 15:throw r.prev=15,r.t0=r.catch(0),Yc(r.t0.message||r.t0),r.t0 instanceof U?t.onStreamAvailable(r.t0):t._publishFuture?t._publishFuture.reject(r.t0.message||r.t0):(t.trigger(new $t(Nt.CONNECT_FAILURE,t,Yc)),t.unpublish()),r.t0;case 20:case"end":return r.stop()}}),r,null,[[0,15]])}))()})),function(e){return u.apply(this,arguments)})},{key:"_postCandidateFragments",value:(c=Rc(Pc().mark((function e(t){var n,r;return Pc().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this._options.connectionParams,r=_t(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 c.apply(this,arguments)})},{key:"_sendCandidate",value:function(e,t){Gc(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 pa(this._whipUrl,s,c)}},{key:"init",value:(s=Rc(Pc().mark((function e(t){var n,r,o,i,a,s,c,u,l;return Pc().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this._options=Fc(Fc({},Vc),t),n=this._options,r=n.protocol,o=n.host,i=n.port,a=n.app,s=n.streamName,c=n.enableChannelSignaling,u=n.disableProxy,l=r.match(/^http/)?r:"ws"===r?"http":"https",this._whipUrl=t.endpoint?t.endpoint:"".concat(l,"://").concat(o,":").concat(i,"/").concat(a,"/whip/endpoint/").concat(s),this._whipHelper=new pa(this._whipUrl,c,u),this._messageTransport=this._whipHelper,e.abrupt("return",Nc(Dc(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=Rc(Pc().mark((function e(t,n){var r,o,i,a,s,c,u,l,d;return Pc().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this._options=Fc(Fc({},Vc),t),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="ws"===o?"http":"https",this._whipUrl=t.endpoint?t.endpoint:"".concat(d,"://").concat(i,":").concat(a,"/").concat(s,"/whip/endpoint/").concat(c),this._whipHelper=new pa(this._whipUrl,u,l),this._messageTransport=this._whipHelper,e.abrupt("return",Nc(Dc(h.prototype),"initWithStream",this).call(this,this._options,n));case 7:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"publish",value:(i=Rc((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 Pc().mark((function r(){var o,i,a,s,c,u,l,d,f,h,p,v,y,m,b,g,_,w,S,E,C,O,k;return Pc().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return o=e._options,i=o.bandwidth,a=o.forceVP8,s=o.videoEncoding,c=o.audioEncoding,u=o.rtcConfiguration,l=o.enableChannelSignaling,d=o.dataChannelConfiguration,f=o.trickleIce,h=o.mungeAnswer,p=o.connectionParams,a&&(s=os.VP8,e._options.videoEncoding=s),(v=l&&Ye())&&!d&&(d={name:"red5pro"},e._options.dataChannelConfiguration=d),e._options.enableChannelSignaling=v,e._options.signalingSocketOnly=e._options.enableChannelSignaling,r.prev=6,y=p||{},t&&(e._options.streamName=t),p&&(m=p.transcode)&&(y.transcode=m),r.next=12,e._whipHelper.getOptions(y);case 12:return(b=r.sent)&&(b.links&&(e._options.rtcConfiguration=Fc(Fc({},u),{},{iceServers:b.links})),b.origin&&e.trigger(new $t(Ht.HOST_ENDPOINT_CHANGED,e,{endpoint:b.origin,iceServers:b.links})),b.statisticsEndpoint&&e.trigger(new $t(Nt.STATISTICS_ENDPOINT_CHANGE,e,{statisticsEndpoint:b.statisticsEndpoint}))),g=e._options.enableChannelSignaling?d:void 0,r.next=17,e._createPeerConnection(u,g,e._options.iceServers);case 17:return _=r.sent,e.trigger(new $t(Ht.PEER_CONNECTION_AVAILABLE,e,_)),r.next=21,e._getMediaStream();case 21:return r.sent.getTracks().forEach((function(e){var t=_.addTransceiver(e,{direction:"sendonly"}),n=e.kind;if(t&&"video"===n&&s&&t.setCodecPreferences)try{var r=RTCRtpSender.getCapabilities("video").codecs,o=r.findIndex((function(e){return e.mimeType==="video/".concat(s)}));if(o>-1){var i=r[o];r.splice(o,1),r.unshift(i),t.setCodecPreferences(r)}}catch(e){Wc("[videoEncoding] Could not set codec preferences for ".concat(s,". ").concat(e.message||e))}else if(t&&"audio"===n&&c&&t.setCodecPreferences)try{var a=RTCRtpSender.getCapabilities("audio").codecs,u=a.findIndex((function(e){return e.mimeType==="audio/".concat(c)}));if(u>-1){var l=a[u];a.splice(u,1),a.unshift(l),t.setCodecPreferences(a)}}catch(e){Wc("[audioEncoding] Could not set codec preferences for ".concat(c,". ").concat(e.message||e))}})),r.next=25,e._peerHelper.createOfferWithoutSetLocal(i);case 25:return w=r.sent,r.next=28,e._peerHelper.setLocalDescription(w);case 28:if(f){r.next=32;break}return r.next=31,e.waitToGatherIce(_);case 31:w=r.sent;case 32:return e.trigger(new $t(Ht.OFFER_START,e,w)),r.next=35,e._postOffer(w,f);case 35:return S=r.sent,E=S.sdp,C=h?h(E):E,r.next=40,e._setRemoteDescription({type:"answer",sdp:it(C)});case 40:if(e.trigger(new $t(Ht.OFFER_END,e,C)),!f){r.next=48;break}return r.next=44,e.waitToGatherIce(_);case 44:return O=r.sent,k=O.sdp,r.next=48,e._postCandidateFragments(k);case 48: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)),n&&n.resolve(e),r.abrupt("return",e);case 55:throw r.prev=55,r.t0=r.catch(6),Yc(r.t0),me.removeOrientationChangeHandler(e._onOrientationChange),e.trigger(new $t(Nt.CONNECT_FAILURE,e,r.t0)),n&&n.reject(r.t0),r.t0;case 62:case"end":return r.stop()}}),r,null,[[6,55]])}))()})),function(){return i.apply(this,arguments)})},{key:"unpublish",value:(o=Rc((function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return Pc().mark((function n(){return Pc().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return Gc("[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),n.abrupt("return",e);case 11:case"end":return n.stop()}}),n)}))()})),function(){return o.apply(this,arguments)})},{key:"onDataChannelOpen",value:function(e){var t=this._options.dataChannelConfiguration;if(Nc(Dc(h.prototype),"onDataChannelOpen",this).call(this,e),t){var n=t.name;Nc(Dc(h.prototype),"onDataChannelAvailable",this).call(this,n)}else Nc(Dc(h.prototype),"onDataChannelAvailable",this).call(this);this.trigger(new $t(Nt.PUBLISH_START,this))}},{key:"getConnection",value:function(){}}])&&Lc(t.prototype,n),r&&Lc(t,r),Object.defineProperty(t,"prototype",{writable:!1}),h}(Oc);function Kc(e){return(Kc="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 Jc(e){return function(e){if(Array.isArray(e))return qc(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 qc(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return qc(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 qc(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new 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;return p("[createoffer]"),this._offerFuture=void 0,this._offerFuture=E.createIfNotExist(this._offerFuture),this._peerHelper.createOffer(e,!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=E.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=E.createIfNotExist(this._publishFuture),this._publishFuture.resolve(),r&&(this._conferenceStream=this._startReceivers(),this.trigger(new tn(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()})),au(du(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,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 au(du(i.prototype),"init",this).call(this,Object.assign(pu,e))}},{key:"initWithStream",value:function(e,t){return au(du(i.prototype),"initWithStream",this).call(this,Object.assign(pu,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),au(du(i.prototype),"onPeerConnectionTrackAdd",this).call(this,e)}},{key:"_onMediaStreamReceived",value:function(e){this._packStreamWithAudio(e,3),au(du(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=hu.exec(e.message),n=fu.exec(e.message);t&&t[1]===this._options.groupName?this._unpublishFuture.resolve():n&&n[1]===this._options.streamName?this._publishFuture.resolve():v(this._name,"Publisher status received, but could not handle.")}}])&&iu(t.prototype,n),r&&iu(t,r),Object.defineProperty(t,"prototype",{writable:!1}),i}(Oc),yu=za,mu=vi,bu=Ha,gu=Ii,_u=ea,wu=ru,Su=Oc,Eu=zc,Cu=_s,Ou=Nt,ku=Ht,Pu=jt,Tu=xt,Ru=Mt,Au=Ft,Lu=Dt,Nu=Ut,ju=Bt,Hu=fo,Iu=ho,xu=rs,Du=os,Mu=po,Fu=vo;d("".concat("error")||!1);var Uu=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];l.hasOwnProperty(e.toUpperCase())&&(d(e,t),console&&console.log("Red5 Pro SDK Version ".concat("14.2.0")))},Bu=l,Vu=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 70c0e6fe..1a92cc78 100644 --- a/webapps.json +++ b/webapps.json @@ -1,7 +1,7 @@ { "r5pro-testbed": { "repositoryUrl": "git@github.com:red5pro/streaming-html5.git", - "branch": "develop" + "branch": "feature/stats_RED5DEV-1280" }, "truetime": { "datasync": {