-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnode.js
1 lines (1 loc) · 29.1 KB
/
node.js
1
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var i in r)("object"==typeof exports?exports:e)[i]=r[i]}}(global,(function(){return(()=>{"use strict";var e={798:(e,t,r)=>{r.d(t,{default:()=>ie});const i=require("qs");var s=r.n(i);const n="https://rest.boxcast.com";class a{static now(){return new Date}}var o=null;class h{static now(){if(null===o){if(o=!(!window.performance||!window.performance.now))try{window.performance.now()}catch(e){console.warn("Error calling window.performance.now():",e),o=!1}o||console.warn("Browser does not support performance API; MonotonicClock falling back to Clock")}return o?window.performance.now():a.now().getTime()}}var c={lastAuthToken:null};function l(){var e=function(e){for(var t="",r="0123456789ABCDEF",i=0;i<5;i++)t+=r.charAt(Math.floor(Math.random()*r.length));return t};return e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()}function d(e,t){const r=(e=e||{}).code||e.data&&e.data.code;let i=e.message;i=!i&&e.data?e.data.details||JSON.stringify(e.data):e.toString(),"[object MediaError]"===i&&(i="MediaError occurred");let s={message:i,code:r,data:e.data};return t&&(s.source=t),s}function u(e){var t,r,i,s,n,a,o;return s=this,n=void 0,o=function*(){const s=(null===(t=e.headers)||void 0===t?void 0:t.get("content-type"))&&0==(null===(r=e.headers)||void 0===r?void 0:r.get("content-type").indexOf("application/json"));let n={pagination:JSON.parse((null===(i=e.headers)||void 0===i?void 0:i.get("x-pagination"))||"{}")};return n.data=s?yield e.json():e,n},new((a=void 0)||(a=Promise))((function(e,t){function r(e){try{h(o.next(e))}catch(e){t(e)}}function i(e){try{h(o.throw(e))}catch(e){t(e)}}function h(t){var s;t.done?e(t.value):(s=t.value,s instanceof a?s:new a((function(e){e(s)}))).then(r,i)}h((o=o.apply(s,n||[])).next())}))}function f(){return{Authorization:`Bearer ${c.lastAuthToken}`}}var p,_=function(e,t,r,i){return new(r||(r=Promise))((function(s,n){function a(e){try{h(i.next(e))}catch(e){n(e)}}function o(e){try{h(i.throw(e))}catch(e){n(e)}}function h(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,o)}h((i=i.apply(e,t||[])).next())}))},E=function(e,t){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return t.get(e)};class g{constructor(e){p.set(this,void 0),function(e,t,r){if(!t.has(e))throw new TypeError("attempted to set private field on non-instance");t.set(e,r)}(this,p,e)}list(e,t={}){return _(this,void 0,void 0,(function*(){if(!e)return Promise.reject("channelId is required");const r=yield E(this,p).call(this,`${n}/channels/${e}/broadcasts?${s().stringify(t)}`);return yield u(r)}))}get(e){return _(this,void 0,void 0,(function*(){if(!e)return Promise.reject("broadcastId is required");const t=yield E(this,p).call(this,`${n}/broadcasts/${e}`);return yield t.json()}))}}p=new WeakMap;var m;class w{constructor(e){m.set(this,void 0),function(e,t,r){if(!t.has(e))throw new TypeError("attempted to set private field on non-instance");t.set(e,r)}(this,m,e)}list(e,t={}){return r=this,i=void 0,o=function*(){if(!e)return Promise.reject("accountId is required");const r=yield function(e,t){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return t.get(e)}(this,m).call(this,`${n}/accounts/${e}/channels?${s().stringify(t)}`);return yield u(r)},new((a=void 0)||(a=Promise))((function(e,t){function s(e){try{h(o.next(e))}catch(e){t(e)}}function n(e){try{h(o.throw(e))}catch(e){t(e)}}function h(t){var r;t.done?e(t.value):(r=t.value,r instanceof a?r:new a((function(e){e(r)}))).then(s,n)}h((o=o.apply(r,i||[])).next())}));var r,i,a,o}}m=new WeakMap;var v;class y{constructor(e){v.set(this,void 0),function(e,t,r){if(!t.has(e))throw new TypeError("attempted to set private field on non-instance");t.set(e,r)}(this,v,e)}get(e,t={}){return r=this,i=void 0,a=function*(){if(!e)return Promise.reject("broadcastId is required");try{const r=yield function(e,t){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return t.get(e)}(this,v).call(this,`${n}/broadcasts/${e}/view`,{params:t}),i=yield r.json();return i&&i.playlist&&i.status.indexOf("live")<0&&i.status.indexOf("recorded")<0&&(console.log("Playlist not yet ready; status is [",i.status,"] for ",i.playlist),i.playlist=""),i}catch(e){return Promise.reject(e)}},new((s=void 0)||(s=Promise))((function(e,t){function n(e){try{h(a.next(e))}catch(e){t(e)}}function o(e){try{h(a.throw(e))}catch(e){t(e)}}function h(t){var r;t.done?e(t.value):(r=t.value,r instanceof s?r:new s((function(e){e(r)}))).then(n,o)}h((a=a.apply(r,i||[])).next())}));var r,i,s,a}}v=new WeakMap;const T=require("base-64");var b,S=r.n(T),O=function(e,t,r,i){return new(r||(r=Promise))((function(s,n){function a(e){try{h(i.next(e))}catch(e){n(e)}}function o(e){try{h(i.throw(e))}catch(e){n(e)}}function h(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,o)}h((i=i.apply(e,t||[])).next())}))},N=function(e,t){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return t.get(e)};class k{constructor(e){b.set(this,void 0),function(e,t,r){if(!t.has(e))throw new TypeError("attempted to set private field on non-instance");t.set(e,r)}(this,b,e)}get resourceBase(){throw new Error("NotImplemented")}list(e={}){return O(this,void 0,void 0,(function*(){try{return u(yield N(this,b).call(this,`${n}/${this.resourceBase}`,{method:"GET",headers:Object.assign(Object.assign({},f()),{"Content-Type":"application/json"})}))}catch(e){throw new Error(`Error in list: ${e.message}`)}}))}get(e){return O(this,void 0,void 0,(function*(){if(!e)throw new Error("id is required");try{const t=yield N(this,b).call(this,`${n}/${this.resourceBase}/${e}`,{method:"GET",headers:Object.assign(Object.assign({},f()),{"Content-Type":"application/json"})});return"application/json; charset=utf-8"==t.headers.get("content-type")?t.json():t}catch(e){throw new Error(`Error in get: ${e.message}`)}}))}create(e={}){return O(this,void 0,void 0,(function*(){try{const t=yield N(this,b).call(this,`${n}/${this.resourceBase}`,{method:"POST",headers:Object.assign(Object.assign({},f()),{"Content-Type":"application/json"}),body:JSON.stringify(e)});return"application/json; charset=utf-8"==t.headers.get("content-type")?t.json():t}catch(e){throw new Error(`Error in create: ${e.message}`)}}))}update(e,t={}){return O(this,void 0,void 0,(function*(){if(!e)throw new Error("id is required");try{const r=yield N(this,b).call(this,`${n}/${this.resourceBase}/${e}`,{method:"PUT",headers:Object.assign(Object.assign({},f()),{"Content-Type":"application/json"}),body:JSON.stringify(t)});return"application/json; charset=utf-8"==r.headers.get("content-type")?r.json():r}catch(e){throw new Error(`Error in update: ${e.message}`)}}))}destroy(e){return O(this,void 0,void 0,(function*(){if(!e)throw new Error("id is required");try{const t=yield N(this,b).call(this,`${n}/${this.resourceBase}/${e}`,{method:"DELETE",headers:Object.assign(Object.assign({},f()),{"Content-Type":"application/json"})});return"application/json; charset=utf-8"==t.headers.get("content-type")?t.json():t}catch(e){throw new Error(`Error in destroy: ${e.message}`)}}))}}b=new WeakMap;var D;class A extends k{constructor(e){super(e),D.set(this,void 0),function(e,t,r){if(!t.has(e))throw new TypeError("attempted to set private field on non-instance");t.set(e,r)}(this,D,e)}get resourceBase(){return"broadcasts"}}D=new WeakMap;var I;class B extends k{constructor(e){super(e),I.set(this,void 0),function(e,t,r){if(!t.has(e))throw new TypeError("attempted to set private field on non-instance");t.set(e,r)}(this,I,e)}get resourceBase(){return"account/channels"}}I=new WeakMap;var R,M=function(e,t,r,i){return new(r||(r=Promise))((function(s,n){function a(e){try{h(i.next(e))}catch(e){n(e)}}function o(e){try{h(i.throw(e))}catch(e){n(e)}}function h(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,o)}h((i=i.apply(e,t||[])).next())}))},P=function(e,t){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return t.get(e)};class C{constructor(e){R.set(this,void 0),function(e,t,r){if(!t.has(e))throw new TypeError("attempted to set private field on non-instance");t.set(e,r)}(this,R,e)}logout(){c.lastAuthToken=null}authenticate(e,t){return M(this,void 0,void 0,(function*(){try{const r=new URLSearchParams({grant_type:"client_credentials",scope:"owner"}),i=yield P(this,R).call(this,"https://auth.boxcast.com/oauth2/token",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${S().encode(`${e}:${t}`)}`},body:r}),s=yield i.json();return c.lastAuthToken=s.access_token,s}catch(e){throw console.error("Error authenticating:",e),e}}))}account(){return M(this,void 0,void 0,(function*(){try{if(!c.lastAuthToken)throw new Error("Authentication is required");const e=yield P(this,R).call(this,`${n}/account`,{headers:f()});return yield e.json()}catch(e){throw console.error("Error fetching account:",e),e}}))}get broadcasts(){return new A(P(this,R))}get channels(){return new B(P(this,R))}}R=new WeakMap;var L,j=function(e,t){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return t.get(e)};class K{constructor(e){L.set(this,void 0),function(e,t,r){if(!t.has(e))throw new TypeError("attempted to set private field on non-instance");t.set(e,r)}(this,L,e),this.broadcasts=new g(j(this,L)),this.channels=new w(j(this,L)),this.auth=new C(j(this,L)),this.views=new y(j(this,L))}}L=new WeakMap;const H=require("platform");var x=r.n(H);const W="play".split(" "),U="pause buffer idle stop complete error".split(" "),$=function(){try{try{return localStorage.setItem("__sentinel__","foo"),"foo"===localStorage.getItem("__sentinel__")?(localStorage.removeItem("__sentinel__"),localStorage):sessionStorage}catch(e){return sessionStorage}}catch(e){return{getItem:function(e){return this[e]},setItem:function(e,t){this[e]=t}}}}();class q{constructor(e){this.browserState=e,this._queue=[],this.listeners={}}attach(e){const{video:t,broadcast:r,channel_id:i}=e;if(!t)throw Error("video is required");if(!r)throw Error("broadcast is required");return Object.keys(this.listeners).length>0&&this.detach(),this.player=t,this.broadcastInfo={channel_id:i||r.channel_id,account_id:r.account_id,is_live:"current"===r.timeframe,broadcast_id:r.id},this.lastReportAt=null,this.lastBufferStart=null,this.isPlaying=!1,this.isBuffering=!1,this.durationPlaying=0,this.activeBufferingDuration=0,this.totalDurationBuffering=0,this.currentLevelHeight=0,this.headers={},this.isSetup=!1,this.listeners=this._wireEvents(this.player),this}detach(){return Object.keys(this.listeners).forEach((e=>{this.player.removeEventListener(e,this.listeners[e],!0)})),this.listeners={},clearTimeout(this._waitForBufferingCheck),this}_wireEvents(e){const t={ended:()=>{this._handleNormalOperation(),this._report("complete"),this._handleBufferingEnd()},error:()=>{this._handlePlaybackError(this.player.error)},pause:()=>{this._handleNormalOperation(),this._report("pause"),this._handleBufferingEnd()},play:()=>{this._handleNormalOperation(),this._report("play"),this._handleBufferingEnd()},playing:()=>{this._handleNormalOperation(),this.isPlaying=!0,this._handleBufferingEnd()},resize:()=>{this._handleNormalOperation(),this._report("quality"),this._handleBufferingEnd()},seeking:()=>{this._handleNormalOperation(),this._report("seek",{offset:this.player.currentTime})},seeked:()=>{this._handleNormalOperation(),this._handleBufferingEnd()},timeupdate:()=>{this._reportTime()},stalled:()=>{this._handleBufferingStart()},waiting:()=>{this._handleBufferingStart()}};return Object.keys(t).forEach((r=>{e.addEventListener(r,t[r],!0)})),t}_isActuallyPlaying(){return!!(this.player.currentTime>0&&!this.player.paused&&!this.player.ended&&this.player.readyState>2)}_getCurrentTime(){return this.player.currentTime}_getCurrentLevelHeight(){return this.player.videoHeight}_handleBufferingStart(){this.isBuffering=!0,this.lastBufferStart=this.lastBufferStart||h.now(),this._waitForBufferingCheck||(this._waitForBufferingCheck=setTimeout((()=>{this._waitForBufferingCheck=null,this.isBuffering&&(this._isActuallyPlaying()?this._handleBufferingEnd():this._report("buffer"))}),500))}_handleNormalOperation(){this.stoppedHACK=!1}_handleBufferingEnd(){this.isBuffering=!1,this.lastBufferStart=null,clearTimeout(this._waitForBufferingCheck),this._waitForBufferingCheck=null,this.totalDurationBuffering+=this.activeBufferingDuration,this.activeBufferingDuration=0}_handlePlaybackError(e){this.stoppedHACK?console.warn("An error occurred, but playback is stopped so this should not be a problem",e):null===e?console.warn("An error event was fired, but the error was null"):this._report("error",Object.assign({},this.browserState,{error_object:d(e)}))}_setup(){var e=$.getItem("boxcast-viewer-id",null);e||(e=function(e){return!e||e.length<3?e||"":'"'===e[0]&&'"'===e[e.length-1]?e.substring(1,e.length-1):e}(l().replace(/-/g,"")),$.setItem("boxcast-viewer-id",e)),this.headers=Object.assign({view_id:l().replace(/-/g,""),viewer_id:e},this.broadcastInfo)}_reportTime(){this.isSetup&&this.isPlaying&&(h.now()-this.lastReportAt<=6e4||this._report("time"))}_report(e,t){this.isSetup||(this._setup(),this.isSetup=!0,this._report("setup",this.browserState));var r=h.now();this.isPlaying&&(this.durationPlaying+=r-(this.lastReportAt||r)),this.isBuffering&&(this.activeBufferingDuration=r-(this.lastBufferStart||r)),this.isPlaying=W.indexOf(e)>=0||this.isPlaying&&!(U.indexOf(e)>=0),this.lastReportAt=r;let i=a.now();t=t||{},(t=Object.assign({},this.headers,t)).timestamp=i.toISOString(),t.hour_of_day=i.getHours(),t.day_of_week=i.getDay(),t.action=e,t.position=this._getCurrentTime(),t.duration=Math.round(this.durationPlaying/1e3),t.duration_buffering=Math.round((this.totalDurationBuffering+this.activeBufferingDuration)/1e3),t.videoHeight=this._getCurrentLevelHeight(),this._getDvrIsUse&&(t.dvr=this._getDvrIsUse()),this._queue.push(t),this._dequeue()}_dequeue(){return e=this,t=void 0,i=function*(){var e=[];for(const t of this._queue)try{const e=yield fetch("https://metrics.boxcast.com/player/interaction",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!e.ok)throw new Error(`Failed to post metrics with status ${e.status}`)}catch(r){t.__attempts=(t.__attempts||0)+1,t.__attempts<=5?(console.warn("Unable to post metrics; will retry",d(r),t),e.push(t)):console.warn("Unable to post metrics; will not retry",d(r),t)}this._queue=e},new((r=void 0)||(r=Promise))((function(s,n){function a(e){try{h(i.next(e))}catch(e){n(e)}}function o(e){try{h(i.throw(e))}catch(e){n(e)}}function h(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,o)}h((i=i.apply(e,t||[])).next())}));var e,t,r,i}}class F extends q{attach(e){const{player:t,broadcast:r,channel_id:i}=e;if(!t)throw Error("player is required");if(!r)throw Error("broadcast is required");return this.player=t,this.broadcastInfo={channel_id:i||r.channel_id,account_id:r.account_id,is_live:"current"===r.timeframe,broadcast_id:r.id},this.lastReportAt=null,this.lastBufferStart=null,this.isPlaying=!1,this.isBuffering=!1,this.durationPlaying=0,this.activeBufferingDuration=0,this.totalDurationBuffering=0,this.currentLevelHeight=0,this.headers={},this.isSetup=!1,this.listeners=this._wireEvents(this.player),this}detach(){return Object.keys(this.listeners).forEach((e=>{this.player.off(e,this.listeners[e])})),this.listeners={},clearTimeout(this._waitForBufferingCheck),this}_wireEvents(e){const t={ended:()=>{this._handleNormalOperation(),this._report("complete"),this._handleBufferingEnd()},error:e=>{this._handlePlaybackError(e)},pause:()=>{this._handleNormalOperation(),this._report("pause"),this._handleBufferingEnd()},play:()=>{this._handleNormalOperation(),this._report("play"),this._handleBufferingEnd()},playing:()=>{this._handleNormalOperation(),this.isPlaying=!0,this._handleBufferingEnd()},resize:()=>{this._handleNormalOperation(),this._report("quality"),this._handleBufferingEnd()},seeking:()=>{this._handleNormalOperation(),this._report("seek",{offset:this._getCurrentTime()})},seeked:()=>{this._handleNormalOperation(),this._handleBufferingEnd()},timeupdate:()=>{this._reportTime()},stalled:()=>{this._handleBufferingStart()},waiting:()=>{this._handleBufferingStart()}};return Object.keys(t).forEach((r=>{e.on(r,t[r])})),t}_getCurrentTime(){return this.player.currentTime()}_getCurrentLevelHeight(){return this.player.videoHeight()}}class G extends q{get framework(){return("undefined"!=typeof window?window.cast:global.cast).framework}attach(e){const{playerManager:t,broadcastInfo:r}=e;if(!t)throw Error("playerManager is required");if(!r)throw Error("broadcastInfo is required");return this.playerManager=t,this.broadcastInfo=r,this.lastReportAt=null,this.lastBufferStart=null,this.isPlaying=!1,this.isBuffering=!1,this.durationPlaying=0,this.activeBufferingDuration=0,this.totalDurationBuffering=0,this.currentLevelHeight=0,this.headers={},this.isSetup=!1,this._wireEvents(),this}handleSegmentRequest(e){if(!e.url)return;const t=e.url.match(/\/(\d+)p\/\d+\.ts/);t&&t[1]&&(this.currentLevelHeight=parseInt(t[1],10))}_wireEvents(){this.playerManager.addEventListener(this.framework.events.EventType.ENDED,(e=>{this._handleNormalOperation(),this._report("complete"),this._handleBufferingEnd()})),this.playerManager.addEventListener(this.framework.events.EventType.MEDIA_FINISHED,(e=>{this._handleNormalOperation(),this._report("complete"),this._handleBufferingEnd()})),this.playerManager.addEventListener(this.framework.events.EventType.ERROR,(e=>{this._handleChromecastError(e)})),this.playerManager.addEventListener(this.framework.events.EventType.PAUSE,(e=>{this._handleNormalOperation(),this._report("pause"),this._handleBufferingEnd()})),this.playerManager.addEventListener(this.framework.events.EventType.PLAYING,(e=>{this._handleNormalOperation(),this._report("play"),this.isPlaying=!0,this._handleBufferingEnd()})),this.playerManager.addEventListener(this.framework.events.EventType.REQUEST_STOP,(e=>{this._handleNormalOperation(),this._report("stop"),this._handleBufferingEnd()})),this.playerManager.addEventListener(this.framework.events.EventType.SEEKED,(e=>{this._handleNormalOperation(),this._handleBufferingEnd()})),this.playerManager.addEventListener(this.framework.events.EventType.SEEKING,(e=>{e&&e.currentMediaTime&&(this._handleNormalOperation(),this._report("seek",{offset:e.currentMediaTime}))})),this.playerManager.addEventListener(this.framework.events.EventType.TIME_UPDATE,(e=>{e.currentMediaTime&&this.lastTimeUpdateTime&&e.currentMediaTime!==this.lastTimeUpdateTime&&(this._handleNormalOperation(),this._handleBufferingEnd()),this.lastTimeUpdateTime=e.currentMediaTime,this._reportTime()})),this.playerManager.addEventListener(this.framework.events.EventType.BUFFERING,(e=>{e.isBuffering?this._handleBufferingStart():(this._handleNormalOperation(),this._handleBufferingEnd())}))}_handleChromecastError(e){if(this.stoppedHACK)console.warn("An error occurred, but playback is stopped so this should not be a problem",e);else if(null===e)console.warn("An error event was fired, but the error was null");else{let t={};if(e.detailedErrorCode)switch(t.code=e.detailedErrorCode,e.detailedErrorCode){case this.framework.events.DetailedErrorCode.MEDIA_UNKNOWN:t.message="MEDIA_UNKNOWN";break;case this.framework.events.DetailedErrorCode.MEDIA_ABORTED:t.message="MEDIA_ABORTED";break;case this.framework.events.DetailedErrorCode.MEDIA_DECODE:t.message="MEDIA_DECODE";break;case this.framework.events.DetailedErrorCode.MEDIA_NETWORK:t.message="MEDIA_NETWORK";break;case this.framework.events.DetailedErrorCode.MEDIA_SRC_NOT_SUPPORTED:t.message="MEDIA_SRC_NOT_SUPPORTED";break;case this.framework.events.DetailedErrorCode.SOURCE_BUFFER_FAILURE:t.message="SOURCE_BUFFER_FAILURE";break;case this.framework.events.DetailedErrorCode.MEDIAKEYS_UNKNOWN:t.message="MEDIAKEYS_UNKNOWN";break;case this.framework.events.DetailedErrorCode.MEDIAKEYS_NETWORK:t.message="MEDIAKEYS_NETWORK";break;case this.framework.events.DetailedErrorCode.MEDIAKEYS_UNSUPPORTED:t.message="MEDIAKEYS_UNSUPPORTED";break;case this.framework.events.DetailedErrorCode.MEDIAKEYS_WEBCRYPTO:t.message="MEDIAKEYS_WEBCRYPTO";break;case this.framework.events.DetailedErrorCode.NETWORK_UNKNOWN:t.message="NETWORK_UNKNOWN";break;case this.framework.events.DetailedErrorCode.SEGMENT_NETWORK:t.message="SEGMENT_NETWORK";break;case this.framework.events.DetailedErrorCode.HLS_NETWORK_MASTER_PLAYLIST:t.message="HLS_NETWORK_MASTER_PLAYLIST";break;case this.framework.events.DetailedErrorCode.HLS_NETWORK_PLAYLIST:t.message="HLS_NETWORK_PLAYLIST";break;case this.framework.events.DetailedErrorCode.HLS_NETWORK_NO_KEY_RESPONSE:t.message="HLS_NETWORK_NO_KEY_RESPONSE";break;case this.framework.events.DetailedErrorCode.HLS_NETWORK_KEY_LOAD:t.message="HLS_NETWORK_KEY_LOAD";break;case this.framework.events.DetailedErrorCode.HLS_NETWORK_INVALID_SEGMENT:t.message="HLS_NETWORK_INVALID_SEGMENT";break;case this.framework.events.DetailedErrorCode.HLS_SEGMENT_PARSING:t.message="HLS_SEGMENT_PARSING";break;case this.framework.events.DetailedErrorCode.DASH_NETWORK:t.message="DASH_NETWORK";break;case this.framework.events.DetailedErrorCode.DASH_NO_INIT:t.message="DASH_NO_INIT";break;case this.framework.events.DetailedErrorCode.SMOOTH_NETWORK:t.message="SMOOTH_NETWORK";break;case this.framework.events.DetailedErrorCode.SMOOTH_NO_MEDIA_DATA:t.message="SMOOTH_NO_MEDIA_DATA";break;case this.framework.events.DetailedErrorCode.MANIFEST_UNKNOWN:t.message="MANIFEST_UNKNOWN";break;case this.framework.events.DetailedErrorCode.HLS_MANIFEST_MASTER:t.message="HLS_MANIFEST_MASTER";break;case this.framework.events.DetailedErrorCode.HLS_MANIFEST_PLAYLIST:t.message="HLS_MANIFEST_PLAYLIST";break;case this.framework.events.DetailedErrorCode.DASH_MANIFEST_UNKNOWN:t.message="DASH_MANIFEST_UNKNOWN";break;case this.framework.events.DetailedErrorCode.DASH_MANIFEST_NO_PERIODS:t.message="DASH_MANIFEST_NO_PERIODS";break;case this.framework.events.DetailedErrorCode.DASH_MANIFEST_NO_MIMETYPE:t.message="DASH_MANIFEST_NO_MIMETYPE";break;case this.framework.events.DetailedErrorCode.DASH_INVALID_SEGMENT_INFO:t.message="DASH_INVALID_SEGMENT_INFO";break;case this.framework.events.DetailedErrorCode.SMOOTH_MANIFEST:t.message="SMOOTH_MANIFEST";break;case this.framework.events.DetailedErrorCode.SEGMENT_UNKNOWN:t.message="SEGMENT_UNKNOWN";break;case this.framework.events.DetailedErrorCode.TEXT_UNKNOWN:t.message="TEXT_UNKNOWN";break;case this.framework.events.DetailedErrorCode.APP:t.message="APP";break;case this.framework.events.DetailedErrorCode.BREAK_CLIP_LOADING_ERROR:t.message="BREAK_CLIP_LOADING_ERROR";break;case this.framework.events.DetailedErrorCode.BREAK_SEEK_INTERCEPTOR_ERROR:t.message="BREAK_SEEK_INTERCEPTOR_ERROR";break;case this.framework.events.DetailedErrorCode.IMAGE_ERROR:t.message="IMAGE_ERROR";break;case this.framework.events.DetailedErrorCode.LOAD_INTERRUPTED:t.message="LOAD_INTERRUPTED";break;case this.framework.events.DetailedErrorCode.LOAD_FAILED:t.message="LOAD_FAILED";break;case this.framework.events.DetailedErrorCode.MEDIA_ERROR_MESSAGE:t.message="MEDIA_ERROR_MESSAGE";break;case this.framework.events.DetailedErrorCode.GENERIC:t.message="GENERIC"}if(e.error)try{t.data=JSON.stringify(e.error)}catch(e){}this._report("error",Object.assign({},this.browserState,{error_object:t}))}}_getCurrentTime(){return this.playerManager.getCurrentTimeSec()}_getCurrentLevelHeight(){return this.currentLevelHeight}_getDvrIsUse(){const e=this.playerManager.getLiveSeekableRange();return!(!e||!e.end||e.end-this.playerManager.getCurrentTimeSec()<30)}}var Y=function(e,t,r,i){return new(r||(r=Promise))((function(s,n){function a(e){try{h(i.next(e))}catch(e){n(e)}}function o(e){try{h(i.throw(e))}catch(e){n(e)}}function h(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,o)}h((i=i.apply(e,t||[])).next())}))};const J="play".split(" "),V="pause buffer complete error".split(" ");class z{constructor(e){this.browserState=e,this._queue=[]}attach(e){return Y(this,void 0,void 0,(function*(){const{broadcast:t,channel_id:r,AsyncStorage:i,debug:s}=e;if(!t)throw Error("broadcast is required");if(!i)throw Error("AsyncStorage is required");return this.storage=i,this.debug=s,this.broadcastInfo={channel_id:r||t.channel_id,account_id:t.account_id,is_live:"current"===t.timeframe,broadcast_id:t.id},this.lastAction=null,this.lastReportAt=null,this.lastBufferStart=null,this.isPlaying=!1,this.isBuffering=!1,this.durationPlaying=0,this.activeBufferingDuration=0,this.totalDurationBuffering=0,this.currentLevelHeight=0,this.headers={},this.isSetup=!1,this._bufferTimeoutHandle=null,yield this._initViewerID(),this}))}generateVideoEventProps(){return{onBuffer:this._onBuffer.bind(this),onError:this._onError.bind(this),onLoad:this._onLoad.bind(this),onProgress:this._onProgress.bind(this),onEnd:this._onEnd.bind(this),onPlaybackRateChange:this._onPlaybackRateChange.bind(this)}}_onBuffer(e){e.isBuffering?this._handleBufferingStart():this._handleBufferingEnd()}_onError(e){console.warn("onError:",e),this._handlePlaybackError(e)}_onLoad(e){this.debug&&console.log("onLoad:",e)}_onProgress(e){this._lastProgressTimestamp=e.currentTime,this._reportTime()}_onEnd(e){this._report("complete"),this._handleBufferingEnd()}_onPlaybackRateChange(e){0===e.playbackRate?(this._report("pause"),this._handleBufferingEnd()):1===e.playbackRate&&(this._report("play"),this._handleBufferingEnd())}_getCurrentTime(){return this._lastProgressTimestamp}_handleBufferingStart(){this.isBuffering=!0,this.lastBufferStart=this.lastBufferStart||h.now(),null==this._bufferTimeoutHandle&&(this.debug&&console.log("[analytics] Detected start of buffering"),this._bufferTimeoutHandle=setTimeout((()=>{this.isBuffering&&this._report("buffer")}),1e3))}_handleBufferingEnd(){this.isBuffering=!1,this.lastBufferStart=null,this.totalDurationBuffering+=this.activeBufferingDuration,this.activeBufferingDuration=0,clearTimeout(this._bufferTimeoutHandle),this._bufferTimeoutHandle=null,this.debug&&console.log("[analytics] Detected end of buffering")}_handlePlaybackError(e){null===e?console.warn("An error event was fired, but the error was null"):this._report("error",Object.assign({},this.browserState,{error_object:d(e)}))}_initViewerID(){return Y(this,void 0,void 0,(function*(){var e=yield this.storage.getItem("boxcast-viewer-id");e||(e=l().replace(/-/g,""),this.storage.setItem("boxcast-viewer-id",e)),this.headers=Object.assign({view_id:l().replace(/-/g,""),viewer_id:e},this.broadcastInfo)}))}_reportTime(){this.isSetup&&this.isPlaying&&(h.now()-this.lastReportAt<=6e4||this._report("time"))}_report(e,t){this.isSetup||(this.isSetup=!0,this._report("setup",this.browserState));var r=h.now();if(this.isPlaying&&(this.durationPlaying+=r-(this.lastReportAt||r)),this.isBuffering&&(this.activeBufferingDuration=r-(this.lastBufferStart||r)),this.isPlaying=J.indexOf(e)>=0||this.isPlaying&&!(V.indexOf(e)>=0),e===this.lastAction&&r-(this.lastReportAt||r)<1e3)return void(this.debug&&console.log(`[analytics] Ignoring ${e} due to debounce on last report`));this.lastReportAt=r,this.lastAction=e;let i=a.now();t=t||{},(t=Object.assign({},this.headers,t)).timestamp=i.toISOString(),t.hour_of_day=i.getHours(),t.day_of_week=i.getDay(),t.action=e,t.position=this._getCurrentTime(),t.duration=Math.round(this.durationPlaying/1e3),t.duration_buffering=Math.round((this.totalDurationBuffering+this.activeBufferingDuration)/1e3),this._queue.push(t),this._dequeue()}_dequeue(){var e=[];this._queue.forEach((t=>Y(this,void 0,void 0,(function*(){try{const e=yield fetch("https://metrics.boxcast.com/player/interaction",{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json"}});if(!e.ok)throw new Error(`Response status ${e.status}`);this.debug&&console.log("[analytics] Posted: ",t)}catch(r){t.__attempts=(t.__attempts||0)+1,t.__attempts<=5?(console.warn("Unable to post metrics; will retry",d(r),t),e.push(t)):console.warn("Unable to post metrics; will not retry",d(r),t)}})))),this._queue=e}}var X,Q={};function Z(){try{return window.location.hostname}catch(e){return""}}class ee{constructor(e){X.set(this,void 0),this.configure=e=>(Q=e,this),this.getState=()=>{var e={host:Z(),os:(x().os||"").toString(),browser_name:x().name,browser_version:x().version,player_version:"boxcast-sdk-js v2.0.2"};return Object.assign({},e,Q)},this.mode=e=>{switch(e){case"html5":return new q(this.getState());case"video.js":return new F(this.getState());case"chromecast":return new G(this.getState());case"react-native-video":return new z(this.getState())}throw Error(`Mode ${e} not supported`)},function(e,t,r){if(!t.has(e))throw new TypeError("attempted to set private field on non-instance");t.set(e,r)}(this,X,e)}}X=new WeakMap;var te,re=function(e,t){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return t.get(e)};te=new WeakMap;class ie extends class{constructor(e){te.set(this,void 0),function(e,t,r){if(!t.has(e))throw new TypeError("attempted to set private field on non-instance");t.set(e,r)}(this,te,e),this.api=new K(re(this,te)),this.analytics=new ee(re(this,te))}}{constructor(){super(r(786))}}},786:e=>{e.exports=require("node-fetch")}},t={};function r(i){if(t[i])return t[i].exports;var s=t[i]={exports:{}};return e[i](s,s.exports,r),s.exports}return r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var i in t)r.o(t,i)&&!r.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r(798)})().default}));