senza-sdk 4.1.1-cbc8a98.0 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +1 -1
- package/package.json +1 -1
- package/src/deviceManager.js +10 -10
- package/src/lifecycle.js +71 -42
package/dist/bundle.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.senza=t():e.senza=t()}(this,(()=>(()=>{"use strict";var e={d:(t,n)=>{for(var i in n)e.o(n,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:n[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{ClientAssertionError:()=>ae,ConnectReason:()=>W,alarmManager:()=>Q,auth:()=>V,deviceManager:()=>A,envInfo:()=>se,getClientAssertion:()=>de,getConnectReason:()=>Z,getDeviceInfo:()=>oe,getPlatformInfo:()=>ee,getTriggerEvent:()=>Y,init:()=>K,initSequence:()=>p,isRunningE2E:()=>ne,lifecycle:()=>k,messageManager:()=>U,platformManager:()=>R,remotePlayer:()=>O,setTimezone:()=>te,showSequence:()=>h,uiReady:()=>ie,writeLicenseResponse:()=>re});var n={};e.r(n),e.d(n,{ClientAssertionError:()=>ae,ConnectReason:()=>W,alarmManager:()=>Q,auth:()=>V,deviceManager:()=>A,envInfo:()=>se,getClientAssertion:()=>de,getConnectReason:()=>Z,getDeviceInfo:()=>oe,getPlatformInfo:()=>ee,getTriggerEvent:()=>Y,init:()=>K,initSequence:()=>p,isRunningE2E:()=>ne,lifecycle:()=>k,messageManager:()=>U,platformManager:()=>R,remotePlayer:()=>O,setTimezone:()=>te,showSequence:()=>h,uiReady:()=>ie,writeLicenseResponse:()=>re});const i={version:"4.1.0"},{version:o}=i,s=5;function r(){return Math.round(1e5*Math.random())+"-"+ee().sessionInfo?.connectionId}class a{constructor(e){this.logFields=e}debug(...e){console.debug(this.formatLogString(e))}log(...e){console.log(this.formatLogString(e))}info(...e){console.info(this.formatLogString(e))}warn(...e){console.warn(this.formatLogString(e))}error(...e){console.error(this.formatLogString(e))}withFields(e){return new a({...this.logFields,...e})}formatLogString(e){let t="[hs-sdk] "+e.join(" ");return this.logFields&&(t+=" [log-fields] "+JSON.stringify(this.logFields)),t}}const d=new a({sdkVersion:o,url:window?.location?.href??""});async function l(e){if(window.cefQuery)return new Promise(((t,n)=>{const i=r(),o=d.withFields({FCID:i}),a={type:"restRequest",name:e,method:"GET",fcid:i},l={target:"TC",waitForResponse:!0,message:JSON.stringify(a)};let c=0;const u=window.cefQuery({request:JSON.stringify(l),persistent:!1,onSuccess:n=>{c&&clearTimeout(c),o.info(`Got restResponse for ${e}: ${n}`),t(n)},onFailure:(t,i)=>{c&&clearTimeout(c);const s=`failed to get restResponse for ${e}: ${t} ${i}`;o.error(s),n(s)}});c=setTimeout((()=>{window.cefQueryCancel(u);const t=`failed to get restResponse for ${e}: reached timeout of ${1e3*s} ms`;o.error(t),n(t)}),1e3*s)}));d.error("getRestResponse: window.cefQuery is undefined")}const c=new class{sessionInfoStr="{}";get sessionInfoObj(){try{return JSON.parse(this.sessionInfoStr)}catch(e){return void d.warn("Failed to return sdk")}}setSessionInfoStr(e){try{JSON.parse(e)}catch(e){throw Error("Failed to parse sessionInfo")}this.sessionInfoStr=e}},u={BACK:27,HOME:36,LEFT:37,RIGHT:39,UP:38,DOWN:40,ENTER:13},f={root:{top:"5vh",left:"82vw",height:"90vh",fontSize:"16px",width:"16vw",position:"fixed",zIndex:1e4,overflow:"hidden",visibility:"hidden"},item:{backgroundColor:"white",color:"black",fontSize:"12px",display:"flex",padding:"6px",border:"1px solid black",borderTop:"none"},item_key:{borderTopLeftRadius:"6px",borderTopRightRadius:"6px",marginTop:"20px",borderBottom:"3px solid black"},component:{fontWeight:"bold",width:"5vw"},component_key:{fontWeight:"normal",color:"darkgray"},id:{textAlign:"left",fontWeight:"normal",flex:1},id_key:{fontWeight:"bold"},time:{fontVariantNumeric:"tabular-nums",width:"3vw"},time_key:{fontWeight:"bold"}};let g=performance.now();const y=(e,t)=>"key"===t?new Date(e).toLocaleTimeString("en-US",{hour12:!1}):`${(e/1e3).toFixed(2)}s`,w=(e,t,n)=>{Object.entries(e).forEach((([e,i])=>{Object.getOwnPropertyNames(Object.getPrototypeOf(i)).forEach((o=>{if(n&&n(o))return;const s=i[o];"function"==typeof s&&(i[o]=function(...n){return t(e,o,...n),s.apply(this,n)})}))}))},m=(e,t)=>{e.innerHTML="",t.forEach(((n,i)=>{const o=document.createElement("div");Object.assign(o.style,{...f.item,...f[`item_${n?.component}`]}),["component","id","time"].forEach((e=>{if(n[e]){const t=document.createElement("div");Object.assign(t.style,f[e],f[`${e}_${n.component}`]),t.textContent="time"===e?y(n.time,n.component):n[e],o.appendChild(t)}})),e.appendChild(o),i===t.length-1&&o.scrollIntoView({behavior:"smooth"})}))},p=e=>{if(!e)return void d.error("No components to sequence");let t=document.getElementById("sequence-container");if(t)return;t=(()=>{const e=document.createElement("div");return e.id="sequence-container",Object.assign(e.style,f.root),document.body.appendChild(e),e})();const n=new Proxy([],{set:(e,i,o)=>(e[i]=o,"length"!==i&&m(t,n),!0)});window.printSequence=()=>(e=>{const t=e.map((e=>{const t=e.separator?"\n":"",n=e?.time?` ${y(e.time,e?.component)}`:"";if(e.args){const i=e.args.map((e=>"object"==typeof e?"object":e)).join(", ");return`${t}${e.component}.${e.id}(${i})${n}`}return`\n${e.component}: ${e.id}${n}`}));d.log("sequence:\n",t.join("\n"))})(n),((e,t)=>{t.push({component:"key",id:"BOOT",time:Date.now()}),w(e,((e,n,...i)=>{t.push({component:e,id:n,args:i,time:performance.now()-g})}),(e=>e.startsWith("_")||e.startsWith("get"))),(e=>{window.addEventListener("keydown",(t=>{var n;e.push({component:"key",id:(n=t.keyCode,Object.entries(u).find((([,e])=>e===n))?.[0]||String(n)),time:Date.now()}),g=performance.now()}))})(t),d.log("Sequence initialized.")})(e,n),m(t,n)},h=(e=!0)=>{const t=document.getElementById("sequence-container");t?t.style.visibility=e?"visible":"hidden":d.error("Sequence not initialized")},v=e=>JSON.parse(JSON.stringify(e));class T extends Error{constructor(e,t){super(t),this.code=e,this.msg=t}}function S(){const e=window.getPlaybackInfo?window.getPlaybackInfo():JSON.stringify({playbackPosition:0,assetDuration:0});let t;try{t=JSON.parse(e)}catch(n){d.error(`Playback Info parse failed. playbackStr = ${e}`),t={playbackPosition:0,assetDuration:0}}return t}function b(e){try{const t=JSON.stringify(e);window.setPlaybackInfo&&window.setPlaybackInfo(t)}catch(e){d.error("Playback Info to json string failed")}}class I extends EventTarget{constructor(){super(),this._config={preferredAudioLanguage:"",preferredSubtitlesLanguage:""},this._selectedAudioTrack="",this._selectedSubtitlesTrack="",this._availableAudioTracks=[],this._availableTextTracks=[],this._textTrackVisibility=!1,this._ptsSessionId=0,this._videoElement=void 0,this._isInitialized=!1,"undefined"!=typeof document&&document.addEventListener("hs/playbackInfoEvent",(()=>{d.info("Got hs/playbackInfoEvent"),this.dispatchEvent(new Event("timeupdate"))})),"undefined"!=typeof document&&document.addEventListener("hs/playback",(e=>{d.info("Got hs/playback event with detail",JSON.stringify(e?.detail)),this._availabilityStartTime=e?.detail?.availabilityStartTime,this._updateTracks(e?.detail),this.dispatchEvent(new Event("tracksupdate"))})),"undefined"!=typeof document&&document.addEventListener("hs/EOS",(()=>{d.info("Got hs/EOS event"),this.dispatchEvent(new Event("ended"))})),"undefined"!=typeof document&&document.addEventListener("hs/ui_inactive",(()=>{d.info("Got hs/ui_inactive event")})),"undefined"!=typeof document&&document.addEventListener("hs/senzaPlayerSetRate",(e=>{this._videoElement&&(this._videoElement.playbackRate=e.detail.rate)})),"undefined"!=typeof document&&document.addEventListener("hs/senzaPlayerSetTime",(e=>{this._videoElement?(d.info(`Adding ${e.detail} seconds to current time ${this._videoElement.currentTime}`),this._videoElement.playbackRate=1,this._videoElement.currentTime+=e.detail):d.warn("video element is NOT set")})),"undefined"!=typeof document&&document.addEventListener("hs/ERR",(e=>{d.info("Got hs/ERR event"),delete e?.detail?.type,delete e?.detail?.eventCode,this.dispatchEvent(new CustomEvent("error",e))})),"undefined"!=typeof document&&document.addEventListener("hs/getLicense",(e=>{d.info("Got hs/getLicense event");const t=e?.detail,n=Uint8Array.from(t.request,(e=>e.charCodeAt(0))),i=new ArrayBuffer(n.byteLength);new Uint8Array(i).set(n),this.licenseRequest=i;const o=t.fcid,s=t.sessionId,r=new CustomEvent("license-request",{detail:{licenseRequest:i}});r.writeLicenseResponse=(e,t)=>{re(e,t,o,s)},this.dispatchEvent(r)}))}LoadMode=Object.freeze({NOT_LOADED:"notLoaded",LOADING:"loading",LOADED:"loaded",UNLOADING:"unloading"});async _init(e,t){let n={isLoaded:!1,playbackUrl:""};if(window.cefQuery){const e=r(),t=d.withFields({FCID:e}),i={type:"playerState",fcid:e},o={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(i)};try{const e=await new Promise(((e,n)=>{window.cefQuery({request:JSON.stringify(o),persistent:!1,onSuccess:n=>{t.log("playerState request successfully returned",n),e(n)},onFailure:(e,i)=>{t.error(`playerState request failed: ${e} ${i}`),n()}})}));n=JSON.parse(e)}catch{t.error("either failed to get or failed to parse player state")}}this._loadMode=n?.isLoaded?this.LoadMode.LOADED:this.LoadMode.NOT_LOADED,this._loadedUrl=n?.playbackUrl||"",this._isInitialized=!0,this._setPlayableUriTimeout=e?.setPlayableUriTimeout??5e3,this._unloadTimeout=e?.unloadTimeout??5e3,this._requestVideoFrameInfo=e?.requestVideoFrameInfo??!0;let i={};try{i=JSON.parse(t?.playbackMetadata||"{}")}catch(e){d.error(`failed to parse playbackMetadata: ${e.message}`)}this._availabilityStartTime=i.availabilityStartTime,this._updateTracks(i)}_updateTracks(e){if(this._availableAudioTracks=e?.availableAudioTracks||this._availableAudioTracks,this._availableTextTracks=e?.availableSubtitlesTracks||this._availableTextTracks,"VOD"===e?.assetType&&(this._availableTextTracks=function(e){if(!e||e.length<1)return e;e.sort(((e,t)=>e.lang.toLowerCase()>t.lang.toLowerCase()?1:-1));const t=[{lang:"af",id:"*:af"},{lang:"ar",id:"*:ar"},{lang:"az",id:"*:az"},{lang:"bg",id:"*:bg"},{lang:"bs",id:"*:bs"},{lang:"ca",id:"*:ca"},{lang:"cs",id:"*:cs"},{lang:"cy",id:"*:cy"},{lang:"da",id:"*:da"},{lang:"de",id:"*:de"},{lang:"el",id:"*:el"},{lang:"en",id:"*:en"},{lang:"es",id:"*:es"},{lang:"es-MX",id:"*:es-MX"},{lang:"et",id:"*:et"},{lang:"fi",id:"*:fi"},{lang:"fr",id:"*:fr"},{lang:"fr-CA",id:"*:fr-CA"},{lang:"ga",id:"*:ga"},{lang:"ha",id:"*:ha"},{lang:"he",id:"*:he"},{lang:"hr",id:"*:hr"},{lang:"ht",id:"*:ht"},{lang:"hu",id:"*:hu"},{lang:"id",id:"*:id"},{lang:"is",id:"*:is"},{lang:"it",id:"*:it"},{lang:"kk",id:"*:kk"},{lang:"lt",id:"*:lt"},{lang:"lv",id:"*:lv"},{lang:"mk",id:"*:mk"},{lang:"mn",id:"*:mn"},{lang:"ms",id:"*:ms"},{lang:"mt",id:"*:mt"},{lang:"nl",id:"*:nl"},{lang:"no",id:"*:no"},{lang:"pl",id:"*:pl"},{lang:"pt",id:"*:pt"},{lang:"pt-PT",id:"*:pt-PT"},{lang:"ro",id:"*:ro"},{lang:"ru",id:"*:ru"},{lang:"sk",id:"*:sk"},{lang:"sl",id:"*:sl"},{lang:"so",id:"*:so"},{lang:"sq",id:"*:sq"},{lang:"sr",id:"*:sr"},{lang:"sv",id:"*:sv"},{lang:"sw",id:"*:sw"},{lang:"tl",id:"*:tl"},{lang:"tr",id:"*:tr"},{lang:"uk",id:"*:uk"},{lang:"uz",id:"*:uz"},{lang:"vi",id:"*:vi"},{lang:"zh",id:"*:zh"}],n=[...e];for(const i of t)e.find((e=>e.lang===i.lang))||(i.autoTranslate=!0,n.push(i));return n}(this._availableTextTracks)),this._availableAudioTracks){const e=this._availableAudioTracks.find((e=>!0===e.selected));this._selectedAudioTrack=e?.id||""}if(this._availableTextTracks){const e=this._availableTextTracks.find((e=>!0===e.selected));e?(this._selectedSubtitlesTrack=e.id,this._textTrackVisibility=!0):(this._selectedSubtitlesTrack="",this._textTrackVisibility=!1)}}getConfiguration(){return v(this._config)}configure(e){Object.entries(e).forEach((([e,t])=>{void 0!==this._config[e]&&(this._config[e]=t)}))}_changeLoadMode(e){this._loadMode!==e&&(this._loadMode=e,this.dispatchEvent(new Event("onloadmodechange")))}_handle_video_frame_info(e){if(!this._requestVideoFrameInfo||void 0===e)return void(this._videoElement=void 0);const t=r(),n=d.withFields({fcid:t}),i=(e,n)=>{const o={type:"currentFramePTS",fcid:t,currentFramePTS:n.mediaTime.toString(),ptsSessionId:this._ptsSessionId},s={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(o)};window.cefQuery({request:JSON.stringify(s),persistent:!1}),this._videoElement?.requestVideoFrameCallback(i)};n.log("handle_video_frame_pts: requesting video frame info"),void 0!==this._videoElement&&this._videoElement===e||(e.requestVideoFrameCallback(i),e.addEventListener("loadstart",(e=>{this._ptsSessionId++,d.info("videoElement, loadstart ptsSessionId=",this._ptsSessionId," event=",e)}))),this._videoElement=e}_reset(){this._availableAudioTracks=[],this._availableTextTracks=[],this._selectedAudioTrack="",this._selectedSubtitlesTrack="",this._availabilityStartTime=void 0}registerVideoElement(e){this.attach(e)}attach(e){this._handle_video_frame_info(e)}async load(e,t){if(!this._isInitialized)throw new T(6500,"Cannot call load() if remote player is not initialized");if(e&&window.cefQuery){const n=await k.getState();if("background"===n||"inTransitionToBackground"===n)throw new T(6002,"Cannot call load() while in state 'background' or 'inTransitionToBackground'");if(this._loadMode===this.LoadMode.LOADING)throw new T(6501,"Cannot call load() while previous load is still in progress");this._reset();const i=this._loadMode;return this._changeLoadMode(this.LoadMode.LOADING),new Promise(((n,o)=>{b({playbackPosition:0});const s=r(),a=t??0,l=d.withFields({FCID:s,loadUrl:e,playbackPosition:a});l.log("remotePlayer load: sending setPlayableUri request");const c={type:"setPlayableUri",url:e,timeout:this._setPlayableUriTimeout,autoPlay:!1,playbackPosition:a,fcid:s},u={target:"TC",waitForResponse:!0,message:JSON.stringify(c)};let f=0;const g=Date.now(),y=window.cefQuery({request:JSON.stringify(u),persistent:!1,onSuccess:()=>{const i=Date.now()-g;l.withFields({duration:i}).log(`setPlayableUri completed successfully after ${i} ms`),t>0&&b({playbackPosition:t}),f&&(clearTimeout(f),f=0),this._changeLoadMode(this.LoadMode.LOADED),this._loadedUrl=e,this.dispatchEvent(new Event("canplay")),n()},onFailure:(e,t)=>{const n=Date.now()-g;l.withFields({duration:n}).log(`setPlayableUri failed after ${n} ms. Error code: ${e}, error message: ${t}`),f&&(clearTimeout(f),f=0),99===e?this._changeLoadMode(i):(this._changeLoadMode(this.LoadMode.NOT_LOADED),this._loadedUrl=""),o(new T(e,t))}});l.log(`window.cefQuery for setPlayableUri returned query id ${y}`);const w=this._setPlayableUriTimeout+1e3;f=setTimeout((()=>{l.log(`setPlayableUri reached timeout of ${w} ms, canceling query id ${y}`),window.cefQueryCancel(y),this._changeLoadMode(this.LoadMode.NOT_LOADED),this._loadedUrl="",o(new T(6e3,`load reached timeout of ${w} ms`))}),w,y)}))}d.error("remotePlayer load: either window.cefQuery or url is undefined")}async unload(){if(!this._isInitialized)throw new T(6500,"Cannot call unload() if remote player is not initialized");if(window.cefQuery){if(this._loadMode===this.LoadMode.LOADING)throw new T(6502,"Cannot call unload() while load is still in progress");const e=this._loadMode;return this._changeLoadMode(this.LoadMode.UNLOADING),new Promise(((t,n)=>{const i=r(),o=d.withFields({FCID:i});o.log("remotePlayer unload");const s={type:"remotePlayer.unload",class:"remotePlayer",action:"unload",fcid:i},a={target:"TC",waitForResponse:!0,message:JSON.stringify(s)};let l=0;const c=Date.now(),u=window.cefQuery({request:JSON.stringify(a),persistent:!1,onSuccess:()=>{const e=Date.now()-c;o.withFields({duration:e}).log(`unload completed successfully after ${e} ms`),l&&(clearTimeout(l),l=0),this._reset(),this._changeLoadMode(this.LoadMode.NOT_LOADED),this._loadedUrl=void 0,t()},onFailure:(t,i)=>{const s=Date.now()-c;o.withFields({duration:s}).log(`unload failed after ${s} ms. Error code: ${t}, error message: ${i}`),l&&(clearTimeout(l),l=0),this._changeLoadMode(e),n(new T(t,i))}});o.log(`window.cefQuery for unload returned query id ${u}`);const f=this._unloadTimeout+1e3;l=setTimeout((()=>{o.log(`unload reached timeout of ${f} ms, canceling query id ${u}`),window.cefQueryCancel(u),this._changeLoadMode(e),n(new T(6e3,`unload reached timeout of ${f} ms`))}),f,u)}))}d.error("remotePlayer unload: window.cefQuery is undefined")}play(){if(!this._isInitialized)throw new T(6500,"Cannot call play() if remote player is not initialized");if(window.cefQuery){if(this._loadMode!==this.LoadMode.LOADED)throw new T(6001,"Cannot call play() if player is not loaded");const e=r(),t=d.withFields({FCID:e});t.log("remotePlayer play: sending play action");const n=this._selectedAudioTrack||this._config.preferredAudioLanguage||"";let i="";this._textTrackVisibility&&(i=this._selectedSubtitlesTrack||this._config.preferredSubtitlesLanguage||"");const o={type:"remotePlayer.play",class:"remotePlayer",action:"play",fcid:e,audioLanguage:n,subtitlesLanguage:i,playbackPosition:this.currentTime},s={target:"TC",waitForResponse:!1,message:JSON.stringify(o)};return new Promise(((e,n)=>{window.cefQuery({request:JSON.stringify(s),persistent:!1,onSuccess:()=>{t.log("remotePlayer play request successfully sent"),e()},onFailure:(e,i)=>{t.error(`remotePlayer play request failed: ${e} ${i}`),n(new T(e,i))}})}))}return d.error("remotePlayer play: window.cefQuery is undefined"),Promise.resolve(void 0)}pause(){if(!this._isInitialized)throw new T(6500,"Cannot call pause() if remote player is not initialized");if(window.cefQuery){if(this._loadMode!==this.LoadMode.LOADED)throw new T(6001,"Cannot call pause() if player is not loaded");const e=r(),t=d.withFields({FCID:e});t.log("remotePlayer pause: sending pause request");const n={type:"remotePlayer.pause",class:"remotePlayer",action:"pause",fcid:e},i={target:"TC",waitForResponse:!1,message:JSON.stringify(n)};return new Promise(((e,n)=>{window.cefQuery({request:JSON.stringify(i),persistent:!1,onSuccess:()=>{t.log("remotePlayer pause request successfully sent"),e()},onFailure:(e,i)=>{t.error(`remotePlayer pause request failed: ${e} ${i}`),n(new T(e,i))}})}))}return d.error("remotePlayer pause: window.cefQuery is undefined"),Promise.resolve(void 0)}getAssetUri(){if(!this._isInitialized)throw new T(6500,"Cannot call getAssetUri() if remote player is not initialized");return this._loadedUrl}getLoadMode(){if(!this._isInitialized)throw new T(6500,"Cannot call getLoadMode() if remote player is not initialized");return this._loadMode}getTextTracks(){return v(this._availableTextTracks)}getAudioTracks(){return v(this._availableAudioTracks)}selectAudioTrack(e){for(const t of this.getAudioTracks())if(t.id===e)return void(this._selectedAudioTrack=e);d.warn(`Invalid audioTrackId ${e}`)}selectTextTrack(e){for(const t of this.getTextTracks())if(t.id===e)return void(this._selectedSubtitlesTrack=e);d.warn(`Invalid textTrackId ${e}`)}setTextTrackVisibility(e){const t=this._textTrackVisibility;if("boolean"!=typeof e)throw new TypeError("visible parameter must be a boolean");const n=e;n!==t&&(this._textTrackVisibility=n,n||(this._selectedSubtitlesTrack=""))}get currentTime(){return S()?.playbackPosition}set currentTime(e){if(b({playbackPosition:e}),window.cefQuery){const t=r(),n=d.withFields({FCID:t});n.log("setting remotePlayer currentTime");const i={type:"remotePlayer.seek",class:"remotePlayer",action:"seek",playbackPosition:e,fcid:t},o={target:"TC",waitForResponse:!1,message:JSON.stringify(i)};window.cefQuery({request:JSON.stringify(o),persistent:!1,onSuccess:()=>{n.log("remotePlayer seek request successfully sent")},onFailure:(e,t)=>{n.error(`remotePlayer seek request failed: ${e} ${t}`)}})}else d.error("setting remotePlayer currentTime: window.cefQuery is undefined")}get duration(){return S()?.assetDuration}get textTrackVisibility(){return this._textTrackVisibility}getPresentationStartTimeAsDate(){return void 0===this._availabilityStartTime?null:new Date(1e3*this._availabilityStartTime)}}const O=new I;"undefined"!=typeof window&&(window.remotePlayer=O,Object.defineProperty(window,"senzaRemotePlayer",{value:O,writable:!1,configurable:!1}));class _ extends EventTarget{UiState=Object.freeze({UNKNOWN:"unknown",FOREGROUND:"foreground",IN_TRANSITION_TO_FOREGROUND:"inTransitionToForeground",BACKGROUND:"background",IN_TRANSITION_TO_BACKGROUND:"inTransitionToBackground"});constructor(){super(),this._isInitialized=!1,"undefined"!=typeof document&&document.addEventListener("hs/uistatechange",(e=>{d.log("Got hs/uistatechange",e.detail);const t=new Event("onstatechange");t.state=e.detail,this._state=t.state,this.dispatchEvent(t)}))}async _init(){window.cefQuery&&(this._state=await new Promise((e=>{window.cefQuery({request:"uiState",persistent:!1,onSuccess:t=>{d.log(`uiState request successfully returned '${t}'`),e(t)},onFailure:(t,n)=>{d.error(`uiState request failed: ${t} ${n}`),e(this.UiState.UNKNOWN)}})})),this._isInitialized=!0)}get state(){return this._isInitialized||(this._state=this.UiState.UNKNOWN),this._state}getState(){if(window.cefQuery)return new Promise(((e,t)=>{window.cefQuery({request:"uiState",persistent:!1,onSuccess:t=>{d.log(`uiState request successfully returned '${t}'`),e(t)},onFailure:(e,n)=>{d.error(`uiState request failed: ${e} ${n}`),t(n)}})}));d.warn("lifecycle getState is not supported if NOT running e2e")}moveToForeground(){if(window.cefQuery){const e=r(),t=d.withFields({FCID:e});t.log("lifecycle moveToForeground: sending uiActiveRequest action"),window.cefQuery({request:JSON.stringify({action:"uiActiveRequest",fcid:e}),persistent:!1,onSuccess:()=>{t.log("uiActiveRequest successfully sent")},onFailure:(e,n)=>{t.error(`uiActiveRequest failed: ${e} ${n}`)}})}else d.error("lifecycle moveToForeground: window.cefQuery is undefined")}moveToBackground(){if(window.cefQuery){const e=r(),t=d.withFields({FCID:e});t.log("lifecycle moveToBackground: sending play action");const n=O.getConfiguration(),i=O._selectedAudioTrack||n.preferredAudioLanguage||"",o=O._selectedSubtitlesTrack||n.preferredSubtitlesLanguage||"";window.cefQuery({request:JSON.stringify({action:"play",fcid:e,audioLanguage:i,subtitlesLanguage:o}),persistent:!1,onSuccess:()=>{t.log("[ moveToBackground ] play successfully sent")},onFailure:(e,n)=>{t.error(`[ moveToBackground ] play failed: ${e} ${n}`)}})}else d.error("lifecycle moveToBackground: window.cefQuery is undefined")}moveToUiStandby(){return window.cefQuery?new Promise(((e,t)=>{const n=r(),i={target:"TC",waitForResponse:!1,message:JSON.stringify({type:"uiStandbyRequest",fcid:n})},o=d.withFields({FCID:n});o.log("lifecycle moveToUiStandby: sending uiStandbyRequest"),window.cefQuery({request:JSON.stringify(i),persistent:!1,onSuccess:()=>{o.log("[ moveToUiStandby ] moveToUiStandby successfully sent"),e(!0)},onFailure:(e,n)=>{o.error(`[ moveToUiStandby ] moveToUiStandby failed: ${e} ${n}`),t(`moveToUiStandby failed: ${e} ${n}`)}})})):(d.warn("moveToUiStandby was called in local dev"),Promise.resolve(!0))}switchTenant(e){if(e&&e.length>0){if(e===ee().sessionInfo?.tenantId)return d.warn(`SwitchTenant requires a different tenantId than the current one. CurrentTenantId=${ee().sessionInfo?.tenantId} and tenantId=${e}`),Promise.reject("SwitchTenant requires a different tenantId than the current one");const t=ee().sessionInfo?.homeSessionInfo?.tenantInfo?.contentHubTenantId,n=ee().sessionInfo?.homeSessionInfo?.tenantId;return d.log(`SwitchTenant for ${e}`),window.cefQuery?new Promise(((i,o)=>{const s=r(),a=d.withFields({FCID:s}),l={type:"reconnect",fcid:s,session:btoa(JSON.stringify({tenantId:e,...ee().sessionInfo?.tenantId===t&&e!==n&&{returnToTenantId:t}}))},c={target:"TC",waitForResponse:!1,message:JSON.stringify(l)};window.cefQuery({request:JSON.stringify(c),persistent:!1,onSuccess:()=>{a.log("SwitchTenant request successfully sent"),i(!0)},onFailure:(e,t)=>{a.error(`SwitchTenant failed: ${e} ${t}`),o(`SwitchTenant failed: ${e} ${t}`)}})})):(d.warn("SwitchTenant is not supported if NOT running e2e"),Promise.reject("SwitchTenant is not supported if NOT running e2e"))}return d.warn("SwitchTenant requires a valid tenantId string parameter"),Promise.reject("SwitchTenant requires a valid tenantId string parameter")}exitApplication(){return window.cefQuery?new Promise(((e,t)=>{const n=r(),i=d.withFields({FCID:n});let o,s;const a=c.sessionInfoObj;a?.homeSessionInfo&&(a?.returnToTenantId||a?.homeSessionInfo.tenantId!==a?.tenantId)?(s={type:"reconnect",splashUrl:a?.homeSessionInfo.tenantInfo.tenantSettings.applicationSwitchSplashUrl,fcid:n},a?.returnToTenantId&&(a?.returnToTenantId===a?.homeSessionInfo.tenantInfo.contentHubTenantId&&(s.splashUrl=a?.homeSessionInfo.contentHubTenantInfo.tenantSettings.applicationSwitchSplashUrl),s.session=btoa(JSON.stringify({tenantId:a?.returnToTenantId}))),o={target:"TC",waitForResponse:!1,message:JSON.stringify(s)}):(s={type:"launchHomeApplication",fcid:n},o={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(s)}),window.cefQuery({request:JSON.stringify(o),persistent:!1,onSuccess:()=>{i.log(`exitApplication request with type: '${s.type}' successfully sent`),e(!0)},onFailure:(e,n)=>{i.error(`exitApplication request with type: '${s.type}' failed: ${e} ${n}`),t(`exitApplication request with type: '${s.type}' failed: ${e} ${n}`)}})})):(d.warn("exitApplication is not supported if NOT running e2e"),Promise.reject("exitApplication is not supported if NOT running e2e"))}}const k=new _,N={};let E,$,F=0;async function P(){if(!E)try{const e=await l("wifi-ap-data");E=JSON.parse(e)}catch(e){d.error(e)}}async function q(){if(F+5e3<Date.now())try{const e=await l("wifi-status");$=JSON.parse(e),F=Date.now()}catch(e){d.error(e)}}class C extends EventTarget{constructor(){super(),N.level=0,N.quality=0,N.ssid="unknown",N.bssid="unknown","undefined"!=typeof document&&document.addEventListener("wifiSignalReport",(e=>{d.log("Got wifiSignalReport",JSON.stringify(e.detail)),N.level=e.detail.level,N.quality=e.detail.quality,N.ssid=e.detail.ssid,N.bssid=e.detail.bssid,this.dispatchEvent(new Event("wifiInfoUpdated"))}))}get deviceInfo(){const e=c.sessionInfoObj;return ne()&&e?{deviceId:e.deviceId,connectionId:e.connectionId,community:e.community,tenant:e.tenant,clientIp:e.clientIp,countryCode:e.general?.location?.["x-country-code"]}:(d.log("getDeviceInfo running locally, returning dummy info"),{deviceId:"123456789",connectionId:"dummy",community:"LocalDev",tenant:"XXXXXX",clientIp:"0.0.0.0",countryCode:"XX"})}get wifiInfo(){return N}reboot(){return new Promise(((e,t)=>{if(window.cefQuery){const n=r(),i=d.withFields({FCID:n}),o={type:"reboot",fcid:n},s={target:"TC",waitForResponse:!1,message:JSON.stringify(o)};window.cefQuery({request:JSON.stringify(s),persistent:!1,onSuccess:()=>{i.log("reboot request successfully sent"),e(!0)},onFailure:(e,n)=>{i.error(`reboot failed: ${e} ${n}`),t(`reboot failed: ${e} ${n}`)}})}else d.warn("reboot is not supported if NOT running e2e"),t("reboot is not supported if NOT running e2e")}))}clearWifi(){return new Promise(((e,t)=>{const n=r(),i=d.withFields({FCID:n}),o={type:"resetWifi",fcid:n},s={target:"TC",waitForResponse:!1,message:JSON.stringify(o)};window.cefQuery({request:JSON.stringify(s),persistent:!1,onSuccess:()=>{i.log("clearWifi successfully sent"),e(!0)},onFailure:(e,n)=>{i.error(`clearWifi failed: ${e} ${n}`),t(`clearWifi failed: ${e} ${n}`)}})}))}sendDataToDevice(e){if("string"!=typeof e)throw new Error("data must be of type 'string'");return new Promise(((t,n)=>{const i=r(),o=d.withFields({FCID:i}),s={type:"externalCommand",data:{command:"forward",payload:e},fcid:i},a={target:"TC",waitForResponse:!1,message:JSON.stringify(s)};window.cefQuery({request:JSON.stringify(a),persistent:!1,onSuccess:()=>{o.log("externalCommand successfully sent"),t()},onFailure:(e,t)=>{o.error(`externalCommand failed: ${e} ${t}`),n(`externalCommand failed: ${e} ${t}`)}})}))}async factoryReset(e=!0){if("boolean"!=typeof e)throw new Error("reboot param must be of type 'boolean'");return new Promise(((t,n)=>{const i=r(),o=d.withFields({FCID:i}),s={type:"factoryReset",fcid:i,reboot:e},a={target:"TC",waitForResponse:!0,message:JSON.stringify(s)};let l=0;const c=window.cefQuery({request:JSON.stringify(a),persistent:!1,onSuccess:()=>{l&&clearTimeout(l),o.log("factoryReset successfully sent"),t(!0)},onFailure:(e,t)=>{l&&clearTimeout(l),o.error(`factoryReset failed: ${e} ${t}`),n(`factoryReset failed: ${e} ${t}`)}});l=setTimeout((()=>{o.error("factoryReset failed: reached timeout of 5000 ms"),window.cefQueryCancel(c),n("factoryReset failed: reached timeout of 5000 ms")}),5e3)}))}async getWifiInfo(){return await Promise.all([P(),q()]),{...E,...$}}}const A=new C;"undefined"!=typeof window&&Object.defineProperty(window,"senzaDeviceManager",{value:A,writable:!1,configurable:!1});class L extends EventTarget{constructor(){super()}get appConfig(){const e=c.sessionInfoObj,t=e.homeSessionInfo?.appConfig||{};return d.info("PlatformManager get appConfig: \n"+JSON.stringify(t,null,2)),t}setTimezone(e){if(window.cefQuery){const t={message:JSON.stringify({type:"setTimeZone",timezone:e}),waitForResponse:!1,target:"UI-Streamer"};window.cefQuery({request:JSON.stringify(t),persistent:!1,onSuccess:()=>{d.log("PlatformManager timezome is successfully set to",e)},onFailure:(t,n)=>{d.error(`PlatformManager error occurred setting timezone to ${e}: ${t} ${n}`)}})}}}const R=new L;class D extends EventTarget{constructor(){super(),"undefined"!=typeof document&&document.addEventListener("hs/alarmFiredEvent",(e=>{d.log("Got hs/alarmFiredEvent",JSON.stringify(e.detail)),e.detail?.alarmName&&this.dispatchEvent(new CustomEvent(e.detail.alarmName,{detail:e.detail.payload}))}))}addAlarm(e,t,n=""){if("string"!=typeof n)throw Error("data must be a string");const i=r(),o=d.withFields({alarmName:e,FCID:i});if(o.log(`addAlarm called for ${e} to be fired at ${t}`),window.cefQuery){const s={type:"addAlarm",fcid:i,alarmName:e,alarmTime:t,payload:n},r={target:"TC",waitForResponse:!1,message:JSON.stringify(s)};window.cefQuery({request:JSON.stringify(r),persistent:!1,onSuccess:()=>{o.log("addAlarm request successfully sent")},onFailure:(e,t)=>{o.error(`addAlarm failed: ${e} ${t}`)}})}else o.warn("addAlarm is not supported if NOT running e2e")}deleteAlarm(e){const t=r(),n=d.withFields({alarmName:e,FCID:t});if(n.log(`deleteAlarm called for ${e}`),window.cefQuery){const i={type:"deleteAlarm",fcid:t,alarmName:e},o={target:"TC",waitForResponse:!1,message:JSON.stringify(i)};window.cefQuery({request:JSON.stringify(o),persistent:!1,onSuccess:()=>{n.log("deleteAlarm request successfully sent")},onFailure:(e,t)=>{n.error(`deleteAlarm failed: ${e} ${t}`)}})}else n.warn("deleteAlarm is not supported if NOT running e2e")}deleteAllAlarms(){if(window.cefQuery){const e=r(),t=d.withFields({FCID:e}),n={type:"deleteAllAlarms",fcid:e},i={target:"TC",waitForResponse:!1,message:JSON.stringify(n)};window.cefQuery({request:JSON.stringify(i),persistent:!1,onSuccess:()=>{t.log("deleteAllAlarms request successfully sent")},onFailure:(e,n)=>{t.error(`deleteAllAlarms failed: ${e} ${n}`)}})}else d.warn("deleteAllAlarms is not supported if NOT running e2e")}getActiveAlarms(){throw Error("NOT IMPLEMENTED")}}const Q=new D;"undefined"!=typeof window&&(window.alarmManager=Q,Object.defineProperty(window,"senzaAlarmManager",{value:Q,writable:!1,configurable:!1}));class J extends EventTarget{constructor(){super(),"undefined"!=typeof document&&document.addEventListener("hs/externalEvent",(e=>{d.log("Got hs/externalEvent",JSON.stringify(e.detail)),this.dispatchEvent(new CustomEvent("message",{detail:{eventName:e.detail.eventName,payload:e.detail.payload,fcid:e.detail.fcid}}))}))}async registerGroups(e){return d.log(`register called for ${e}`),new Promise(((t,n)=>{if(window.cefQuery){const i=r(),o=d.withFields({FCID:i}),s={type:"registerGroupEvent",fcid:i,groups:e},a={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(s)};window.cefQuery({request:JSON.stringify(a),persistent:!1,onSuccess:()=>{o.log("registerGroupEvent request successfully sent"),t(!0)},onFailure:(e,t)=>{o.error(`registerGroupEvent failed: ${e} ${t}`),n(`registerGroupEvent failed: ${e} ${t}`)}})}else d.warn("registerGroupEvent is not supported if NOT running e2e"),n("registerGroupEvent is not supported if NOT running e2e")}))}}const U=new J;let M,x;"undefined"!=typeof window&&(window.messageManager=U,Object.defineProperty(window,"senzaMessageManager",{value:U,writable:!1,configurable:!1})),k.getState()?.then((e=>{x=e})),k.addEventListener("onstatechange",(e=>{x=e.state}));const X=e=>{"background"!==x&&"inTransitionToBackground"!==x||(M&&clearTimeout(M),M=setTimeout((()=>{"background"!==x&&"inTransitionToBackground"!==x||d.log(`${e.type} event received while in '${x}' state and there was no call to lifecycle.moveToForeground() for 500 ms. Make sure to call it if you want to move to foreground.`),M=0}),500))};"undefined"!=typeof document&&document.addEventListener("keydown",X),O.addEventListener("error",X),O.addEventListener("ended",X);const{version:z}=i;let j;const G="1.0";"undefined"!=typeof document&&document.addEventListener("keydown",(e=>{d.log(`Got ${e.key} key`)}));const V={getToken:async function(){return j?Promise.resolve(j):(d.log("getToken wait for promise updateSession event"),new Promise((e=>{document.addEventListener("updateSession",(t=>{j=t.detail?.updateObj,d.log(`onUpdateSessionEvent: token= ${j}`),e(j)}),{once:!0})})))},forceTokenUpdate:function(){if(j=null,window.cefQuery){const e=r(),t=d.withFields({FCID:e});t.log("forceTokenUpdate: sending updateSessionRequest");const n={type:"updateSessionRequest",updateKey:"authorization",parentPath:"settings.webUI.backendHeaders.Authorization",fcid:e},i={target:"TC",waitForResponse:!1,message:JSON.stringify(n)};window.cefQuery({request:JSON.stringify(i),persistent:!1,onSuccess:()=>{t.log("updateSessionRequest successfully sent")},onFailure:(e,n)=>{t.error(`updateSessionRequest failed: ${e} ${n}`)}})}else d.error("forceTokenUpdate: window.cefQuery is undefined")},getClientAssertion:de},W=Object.freeze({UNKNOWN:"unknown",INITIAL_CONNECTION:"initial_connection",UI_RELEASE:"ui_release",UI_TERMINATION:"ui_termination",WEBRTC_ERROR:"webrtc_error",UI_WATCHDOG:"ui_watchdog"});let B=W.UNKNOWN,H={};async function K(){if(d.log(`init ${z}`),window.diagnostics||d.error("[ init ] window.diagnostics is undefined"),window.cefQuery){await new Promise(((e,t)=>{window.cefQuery({request:"apiVersion "+G,persistent:!1,onSuccess:()=>{d.log("api version compatability check succeeded"),e()},onFailure:(e,n)=>{d.error("api version compatability check failed: "+n),t(n)}})}));const e=await new Promise((e=>{window.cefQuery({request:"sessionInfo",persistent:!1,onSuccess:t=>{d.log("sessionInfo request successfully returned "+t),e(t)},onFailure:(e,t)=>{d.error(`sessionInfo request failed: ${e} ${t}`)}})}));c.setSessionInfoStr(e);const t=JSON.parse(e);j=t?.settings?.webUI?.backendHeaders?.Authorization,d.log(`authToken: token = ${j}`),document.addEventListener("updateSession",(e=>{j=e.detail?.updateObj,d.log(`onUpdateSessionEvent: token = ${j}`)})),B=await new Promise((e=>{const t=r(),n=d.withFields({FCID:t}),i={type:"connectReason",fcid:t},o={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(i)};window.cefQuery({request:JSON.stringify(o),persistent:!1,onSuccess:t=>{n.log(`connectReason request successfully returned '${t}'`),e(t)},onFailure:(t,i)=>{n.error(`connectReason request failed: ${t} ${i}`),e(W.UNKNOWN)}})}));const n=await new Promise((e=>{const t=r(),n=d.withFields({FCID:t}),i={type:"triggerEvent",fcid:t},o={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(i)};window.cefQuery({request:JSON.stringify(o),persistent:!1,onSuccess:t=>{n.log(`triggerEvent request successfully returned '${t}'`),e(t)},onFailure:(t,i)=>{n.error(`triggerEvent request failed: ${t} ${i}`),e("")}})}));H={};let i={};if(n)try{i=JSON.parse(n),H.type=i.type,"keyPressEvent"===H.type?H.data={keyValue:i.keyValue}:"alarmFiredEvent"===H.type?H.data={alarmName:i.alarmName,payload:i.payload}:"userAlertEvent"===H.type?H.data={eventCode:i.eventCode,message:i.message}:"externalEvent"===H.type?H.data={eventName:i.eventName,payload:i.payload}:"videoPlaybackEvent"===H.type?H.data={eventCode:i.eventCode,errorCode:i.errorCode}:d.warn("unknown trigger event type",H.type)}catch(e){d.error(`failed to parse trigger event string ${n}: ${e.message}`)}await O._init(t?.settings?.["ui-streamer"],i),await k._init();const o=t?.settings?.["ui-streamer"]?.devSequence;o&&(p({lifecycle:k,remotePlayer:O}),h(!0))}else j=ee().sessionInfo?.settings?.webUI?.backendHeaders?.Authorization,d.log(`authToken dummy: token = ${j}`);window.auth=V,Object.defineProperty(window,"senzaAuth",{value:V,writable:!1,configurable:!1}),window.close=()=>{d.warn("window.close is disabled on Senza platform. Use lifecycle.exitApplication() instead.")}}function Z(){return B}function Y(){return H}function ee(){if("undefined"==typeof window||!window.diagnostics)return"undefined"==typeof window||window.diagnostics||d.error("[ getPlatformInfo ] window.diagnostics is undefined"),{version:"X.X.XX-X",pod:"ui-streamer-X.X.XX-X-QWERT-ASDFG-XXX-XXXXXX-XXXXX",podIP:"0.0.0.0",sessionInfo:{userAgent:"SynamediaSenza/XX.YY.ZZ",connectionId:"dummy",deviceId:"123456789",community:"LocalDev",tenant:"XXXXXX",tenantId:"XXXXXX",manifest:{transcontainer:"X.X.XX-X"},settings:{webUI:{backendHeaders:{Authorization:"Bearer dummytoken"}}},homeSessionInfo:{tenantId:"XXXXXX",community:"LocalDev"}}};try{const e=window.diagnostics()||{};return e.sessionInfo=c.sessionInfoObj,e}catch(e){d.error("Could not get platform info",e.stack)}}function te(e){if(window.cefQuery){const t={message:JSON.stringify({type:"setTimeZone",timezone:e}),waitForResponse:!1,target:"UI-Streamer"};window.cefQuery({request:JSON.stringify(t),persistent:!1,onSuccess:()=>{d.log("timezome is successfully set to",e)},onFailure:(t,n)=>{d.error(`error occurred setting timezone to ${e}: ${t} ${n}`)}})}}function ne(){return!("undefined"==typeof window||!window.cefQuery)}function ie(){window.cefQuery?window.cefQuery({request:"uiReady",persistent:!1,onSuccess:()=>{d.log("uiReady request successfully sent")},onFailure:(e,t)=>{d.error(`uiReady request failed: ${e} ${t}`)}}):d.error("uiReady: window.cefQuery is undefined")}function oe(){const e=c.sessionInfoObj;return ne()?{deviceId:e.deviceId,connectionId:e.connectionId,community:e.community,tenant:e.tenant,clientIp:e.clientIp}:(d.log("getDeviceInfo running locally, returning dummy info"),{deviceId:"123456789",connectionId:"dummy",community:"LocalDev",tenant:"XXXXXX",clientIp:"0.0.0.0"})}const se={remoteBrowserIp:window.diagnostics?window.diagnostics().podIP:"127.0.0.1",sdkVersion:z};function re(e,t,n,i){if(200===e&&(t=window.btoa(String.fromCharCode.apply(null,new Uint8Array(t)))),window.cefQuery){const o={type:"updateLicense",sessionId:i,fcid:n};o[200===e?"response":"error"]=t;const s={target:"TC",waitForResponse:!1,message:JSON.stringify(o)};window.cefQuery({request:JSON.stringify(s),persistent:!1,onSuccess:()=>{d.log("updateLicense request successfully sent")},onFailure:(e,t)=>{d.error(`updateLicense request failed: ${e} ${t}`)}})}}class ae extends Error{constructor(e,t){super(t),this.code=e}}function de(){if(window.cefQuery)return d.log("getClientAssertion is called"),new Promise(((e,t)=>{window.cefQuery({request:"client_assertion",persistent:!1,onSuccess:n=>{try{const t=JSON.parse(n);d.log(`client_assertion request successfully returned ${n}`),e(t)}catch(e){d.error(`Failed to parse client assertion ${n}`),t(new ae(0,"Failed to parse client assertion"))}},onFailure:(e,n)=>{d.log(`client_assertion request failed: ${e} ${n}`),t(new ae(e,n))}})}));d.warn("getClientAssertion is not supported if NOT running e2e")}return"undefined"!=typeof window&&(window.hs=n),t})()));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.senza=t():e.senza=t()}(this,(()=>(()=>{"use strict";var e={d:(t,i)=>{for(var n in i)e.o(i,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:i[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{ClientAssertionError:()=>ae,ConnectReason:()=>V,alarmManager:()=>U,auth:()=>B,deviceManager:()=>A,envInfo:()=>se,getClientAssertion:()=>de,getConnectReason:()=>Z,getDeviceInfo:()=>oe,getPlatformInfo:()=>ee,getTriggerEvent:()=>Y,init:()=>K,initSequence:()=>p,isRunningE2E:()=>ie,lifecycle:()=>N,messageManager:()=>J,platformManager:()=>L,remotePlayer:()=>_,setTimezone:()=>te,showSequence:()=>h,uiReady:()=>ne,writeLicenseResponse:()=>re});var i={};e.r(i),e.d(i,{ClientAssertionError:()=>ae,ConnectReason:()=>V,alarmManager:()=>U,auth:()=>B,deviceManager:()=>A,envInfo:()=>se,getClientAssertion:()=>de,getConnectReason:()=>Z,getDeviceInfo:()=>oe,getPlatformInfo:()=>ee,getTriggerEvent:()=>Y,init:()=>K,initSequence:()=>p,isRunningE2E:()=>ie,lifecycle:()=>N,messageManager:()=>J,platformManager:()=>L,remotePlayer:()=>_,setTimezone:()=>te,showSequence:()=>h,uiReady:()=>ne,writeLicenseResponse:()=>re});const n={version:"4.1.2"},{version:o}=n,s=5;function r(){return Math.round(1e5*Math.random())+"-"+ee().sessionInfo?.connectionId}class a{constructor(e){this.logFields=e}debug(...e){console.debug(this.formatLogString(e))}log(...e){console.log(this.formatLogString(e))}info(...e){console.info(this.formatLogString(e))}warn(...e){console.warn(this.formatLogString(e))}error(...e){console.error(this.formatLogString(e))}withFields(e){return new a({...this.logFields,...e})}formatLogString(e){let t="[hs-sdk] "+e.join(" ");return this.logFields&&(t+=" [log-fields] "+JSON.stringify(this.logFields)),t}}const d=new a({sdkVersion:o,url:window?.location?.href??""});async function l(e){if(window.cefQuery)return new Promise(((t,i)=>{const n=r(),o=d.withFields({FCID:n}),a={type:"restRequest",name:e,method:"GET",fcid:n},l={target:"TC",waitForResponse:!0,message:JSON.stringify(a)};let c=0;const u=window.cefQuery({request:JSON.stringify(l),persistent:!1,onSuccess:i=>{c&&clearTimeout(c),o.info(`Got restResponse for ${e}: ${i}`),t(i)},onFailure:(t,n)=>{c&&clearTimeout(c);const s=`failed to get restResponse for ${e}: ${t} ${n}`;o.error(s),i(s)}});c=setTimeout((()=>{window.cefQueryCancel(u);const t=`failed to get restResponse for ${e}: reached timeout of ${1e3*s} ms`;o.error(t),i(t)}),1e3*s)}));d.error("getRestResponse: window.cefQuery is undefined")}const c=new class{sessionInfoStr="{}";get sessionInfoObj(){try{return JSON.parse(this.sessionInfoStr)}catch(e){return void d.warn("Failed to return sdk")}}setSessionInfoStr(e){try{JSON.parse(e)}catch(e){throw Error("Failed to parse sessionInfo")}this.sessionInfoStr=e}},u={BACK:27,HOME:36,LEFT:37,RIGHT:39,UP:38,DOWN:40,ENTER:13},f={root:{top:"5vh",left:"82vw",height:"90vh",fontSize:"16px",width:"16vw",position:"fixed",zIndex:1e4,overflow:"hidden",visibility:"hidden"},item:{backgroundColor:"white",color:"black",fontSize:"12px",display:"flex",padding:"6px",border:"1px solid black",borderTop:"none"},item_key:{borderTopLeftRadius:"6px",borderTopRightRadius:"6px",marginTop:"20px",borderBottom:"3px solid black"},component:{fontWeight:"bold",width:"5vw"},component_key:{fontWeight:"normal",color:"darkgray"},id:{textAlign:"left",fontWeight:"normal",flex:1},id_key:{fontWeight:"bold"},time:{fontVariantNumeric:"tabular-nums",width:"3vw"},time_key:{fontWeight:"bold"}};let g=performance.now();const y=(e,t)=>"key"===t?new Date(e).toLocaleTimeString("en-US",{hour12:!1}):`${(e/1e3).toFixed(2)}s`,w=(e,t,i)=>{Object.entries(e).forEach((([e,n])=>{Object.getOwnPropertyNames(Object.getPrototypeOf(n)).forEach((o=>{if(i&&i(o))return;const s=n[o];"function"==typeof s&&(n[o]=function(...i){return t(e,o,...i),s.apply(this,i)})}))}))},m=(e,t)=>{e.innerHTML="",t.forEach(((i,n)=>{const o=document.createElement("div");Object.assign(o.style,{...f.item,...f[`item_${i?.component}`]}),["component","id","time"].forEach((e=>{if(i[e]){const t=document.createElement("div");Object.assign(t.style,f[e],f[`${e}_${i.component}`]),t.textContent="time"===e?y(i.time,i.component):i[e],o.appendChild(t)}})),e.appendChild(o),n===t.length-1&&o.scrollIntoView({behavior:"smooth"})}))},p=e=>{if(!e)return void d.error("No components to sequence");let t=document.getElementById("sequence-container");if(t)return;t=(()=>{const e=document.createElement("div");return e.id="sequence-container",Object.assign(e.style,f.root),document.body.appendChild(e),e})();const i=new Proxy([],{set:(e,n,o)=>(e[n]=o,"length"!==n&&m(t,i),!0)});window.printSequence=()=>(e=>{const t=e.map((e=>{const t=e.separator?"\n":"",i=e?.time?` ${y(e.time,e?.component)}`:"";if(e.args){const n=e.args.map((e=>"object"==typeof e?"object":e)).join(", ");return`${t}${e.component}.${e.id}(${n})${i}`}return`\n${e.component}: ${e.id}${i}`}));d.log("sequence:\n",t.join("\n"))})(i),((e,t)=>{t.push({component:"key",id:"BOOT",time:Date.now()}),w(e,((e,i,...n)=>{t.push({component:e,id:i,args:n,time:performance.now()-g})}),(e=>e.startsWith("_")||e.startsWith("get"))),(e=>{window.addEventListener("keydown",(t=>{var i;e.push({component:"key",id:(i=t.keyCode,Object.entries(u).find((([,e])=>e===i))?.[0]||String(i)),time:Date.now()}),g=performance.now()}))})(t),d.log("Sequence initialized.")})(e,i),m(t,i)},h=(e=!0)=>{const t=document.getElementById("sequence-container");t?t.style.visibility=e?"visible":"hidden":d.error("Sequence not initialized")},T=e=>JSON.parse(JSON.stringify(e));class v extends Error{constructor(e,t){super(t),this.code=e,this.msg=t}}function S(){const e=window.getPlaybackInfo?window.getPlaybackInfo():JSON.stringify({playbackPosition:0,assetDuration:0});let t;try{t=JSON.parse(e)}catch(i){d.error(`Playback Info parse failed. playbackStr = ${e}`),t={playbackPosition:0,assetDuration:0}}return t}function b(e){try{const t=JSON.stringify(e);window.setPlaybackInfo&&window.setPlaybackInfo(t)}catch(e){d.error("Playback Info to json string failed")}}class I extends EventTarget{constructor(){super(),this._config={preferredAudioLanguage:"",preferredSubtitlesLanguage:""},this._selectedAudioTrack="",this._selectedSubtitlesTrack="",this._availableAudioTracks=[],this._availableTextTracks=[],this._textTrackVisibility=!1,this._ptsSessionId=0,this._videoElement=void 0,this._isInitialized=!1,"undefined"!=typeof document&&document.addEventListener("hs/playbackInfoEvent",(()=>{d.info("Got hs/playbackInfoEvent"),this.dispatchEvent(new Event("timeupdate"))})),"undefined"!=typeof document&&document.addEventListener("hs/playback",(e=>{d.info("Got hs/playback event with detail",JSON.stringify(e?.detail)),this._availabilityStartTime=e?.detail?.availabilityStartTime,this._updateTracks(e?.detail),this.dispatchEvent(new Event("tracksupdate"))})),"undefined"!=typeof document&&document.addEventListener("hs/EOS",(()=>{d.info("Got hs/EOS event"),this.dispatchEvent(new Event("ended"))})),"undefined"!=typeof document&&document.addEventListener("hs/ui_inactive",(()=>{d.info("Got hs/ui_inactive event")})),"undefined"!=typeof document&&document.addEventListener("hs/senzaPlayerSetRate",(e=>{this._videoElement&&(this._videoElement.playbackRate=e.detail.rate)})),"undefined"!=typeof document&&document.addEventListener("hs/senzaPlayerSetTime",(e=>{this._videoElement?(d.info(`Adding ${e.detail} seconds to current time ${this._videoElement.currentTime}`),this._videoElement.playbackRate=1,this._videoElement.currentTime+=e.detail):d.warn("video element is NOT set")})),"undefined"!=typeof document&&document.addEventListener("hs/ERR",(e=>{d.info("Got hs/ERR event"),delete e?.detail?.type,delete e?.detail?.eventCode,this.dispatchEvent(new CustomEvent("error",e))})),"undefined"!=typeof document&&document.addEventListener("hs/getLicense",(e=>{d.info("Got hs/getLicense event");const t=e?.detail,i=Uint8Array.from(t.request,(e=>e.charCodeAt(0))),n=new ArrayBuffer(i.byteLength);new Uint8Array(n).set(i),this.licenseRequest=n;const o=t.fcid,s=t.sessionId,r=new CustomEvent("license-request",{detail:{licenseRequest:n}});r.writeLicenseResponse=(e,t)=>{re(e,t,o,s)},this.dispatchEvent(r)}))}LoadMode=Object.freeze({NOT_LOADED:"notLoaded",LOADING:"loading",LOADED:"loaded",UNLOADING:"unloading"});async _init(e,t){let i={isLoaded:!1,playbackUrl:""};if(window.cefQuery){const e=r(),t=d.withFields({FCID:e}),n={type:"playerState",fcid:e},o={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(n)};try{const e=await new Promise(((e,i)=>{window.cefQuery({request:JSON.stringify(o),persistent:!1,onSuccess:i=>{t.log("playerState request successfully returned",i),e(i)},onFailure:(e,n)=>{t.error(`playerState request failed: ${e} ${n}`),i()}})}));i=JSON.parse(e)}catch{t.error("either failed to get or failed to parse player state")}}this._loadMode=i?.isLoaded?this.LoadMode.LOADED:this.LoadMode.NOT_LOADED,this._loadedUrl=i?.playbackUrl||"",this._isInitialized=!0,this._setPlayableUriTimeout=e?.setPlayableUriTimeout??5e3,this._unloadTimeout=e?.unloadTimeout??5e3,this._requestVideoFrameInfo=e?.requestVideoFrameInfo??!0;let n={};try{n=JSON.parse(t?.playbackMetadata||"{}")}catch(e){d.error(`failed to parse playbackMetadata: ${e.message}`)}this._availabilityStartTime=n.availabilityStartTime,this._updateTracks(n)}_updateTracks(e){if(this._availableAudioTracks=e?.availableAudioTracks||this._availableAudioTracks,this._availableTextTracks=e?.availableSubtitlesTracks||this._availableTextTracks,"VOD"===e?.assetType&&(this._availableTextTracks=function(e){if(!e||e.length<1)return e;e.sort(((e,t)=>e.lang.toLowerCase()>t.lang.toLowerCase()?1:-1));const t=[{lang:"af",id:"*:af"},{lang:"ar",id:"*:ar"},{lang:"az",id:"*:az"},{lang:"bg",id:"*:bg"},{lang:"bs",id:"*:bs"},{lang:"ca",id:"*:ca"},{lang:"cs",id:"*:cs"},{lang:"cy",id:"*:cy"},{lang:"da",id:"*:da"},{lang:"de",id:"*:de"},{lang:"el",id:"*:el"},{lang:"en",id:"*:en"},{lang:"es",id:"*:es"},{lang:"es-MX",id:"*:es-MX"},{lang:"et",id:"*:et"},{lang:"fi",id:"*:fi"},{lang:"fr",id:"*:fr"},{lang:"fr-CA",id:"*:fr-CA"},{lang:"ga",id:"*:ga"},{lang:"ha",id:"*:ha"},{lang:"he",id:"*:he"},{lang:"hr",id:"*:hr"},{lang:"ht",id:"*:ht"},{lang:"hu",id:"*:hu"},{lang:"id",id:"*:id"},{lang:"is",id:"*:is"},{lang:"it",id:"*:it"},{lang:"kk",id:"*:kk"},{lang:"lt",id:"*:lt"},{lang:"lv",id:"*:lv"},{lang:"mk",id:"*:mk"},{lang:"mn",id:"*:mn"},{lang:"ms",id:"*:ms"},{lang:"mt",id:"*:mt"},{lang:"nl",id:"*:nl"},{lang:"no",id:"*:no"},{lang:"pl",id:"*:pl"},{lang:"pt",id:"*:pt"},{lang:"pt-PT",id:"*:pt-PT"},{lang:"ro",id:"*:ro"},{lang:"ru",id:"*:ru"},{lang:"sk",id:"*:sk"},{lang:"sl",id:"*:sl"},{lang:"so",id:"*:so"},{lang:"sq",id:"*:sq"},{lang:"sr",id:"*:sr"},{lang:"sv",id:"*:sv"},{lang:"sw",id:"*:sw"},{lang:"tl",id:"*:tl"},{lang:"tr",id:"*:tr"},{lang:"uk",id:"*:uk"},{lang:"uz",id:"*:uz"},{lang:"vi",id:"*:vi"},{lang:"zh",id:"*:zh"}],i=[...e];for(const n of t)e.find((e=>e.lang===n.lang))||(n.autoTranslate=!0,i.push(n));return i}(this._availableTextTracks)),this._availableAudioTracks){const e=this._availableAudioTracks.find((e=>!0===e.selected));this._selectedAudioTrack=e?.id||""}if(this._availableTextTracks){const e=this._availableTextTracks.find((e=>!0===e.selected));e?(this._selectedSubtitlesTrack=e.id,this._textTrackVisibility=!0):(this._selectedSubtitlesTrack="",this._textTrackVisibility=!1)}}getConfiguration(){return T(this._config)}configure(e){Object.entries(e).forEach((([e,t])=>{void 0!==this._config[e]&&(this._config[e]=t)}))}_changeLoadMode(e){this._loadMode!==e&&(this._loadMode=e,this.dispatchEvent(new Event("onloadmodechange")))}_handle_video_frame_info(e){if(!this._requestVideoFrameInfo||void 0===e)return void(this._videoElement=void 0);const t=r(),i=d.withFields({fcid:t}),n=(e,i)=>{const o={type:"currentFramePTS",fcid:t,currentFramePTS:i.mediaTime.toString(),ptsSessionId:this._ptsSessionId},s={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(o)};window.cefQuery({request:JSON.stringify(s),persistent:!1}),this._videoElement?.requestVideoFrameCallback(n)};i.log("handle_video_frame_pts: requesting video frame info"),void 0!==this._videoElement&&this._videoElement===e||(e.requestVideoFrameCallback(n),e.addEventListener("loadstart",(e=>{this._ptsSessionId++,d.info("videoElement, loadstart ptsSessionId=",this._ptsSessionId," event=",e)}))),this._videoElement=e}_reset(){this._availableAudioTracks=[],this._availableTextTracks=[],this._selectedAudioTrack="",this._selectedSubtitlesTrack="",this._availabilityStartTime=void 0}registerVideoElement(e){this.attach(e)}attach(e){this._handle_video_frame_info(e)}async load(e,t){if(!this._isInitialized)throw new v(6500,"Cannot call load() if remote player is not initialized");if(e&&window.cefQuery){const i=await N.getState();if("background"===i||"inTransitionToBackground"===i)throw new v(6002,"Cannot call load() while in state 'background' or 'inTransitionToBackground'");if(this._loadMode===this.LoadMode.LOADING)throw new v(6501,"Cannot call load() while previous load is still in progress");this._reset();const n=this._loadMode;return this._changeLoadMode(this.LoadMode.LOADING),new Promise(((i,o)=>{b({playbackPosition:0});const s=r(),a=t??0,l=d.withFields({FCID:s,loadUrl:e,playbackPosition:a});l.log("remotePlayer load: sending setPlayableUri request");const c={type:"setPlayableUri",url:e,timeout:this._setPlayableUriTimeout,autoPlay:!1,playbackPosition:a,fcid:s},u={target:"TC",waitForResponse:!0,message:JSON.stringify(c)};let f=0;const g=Date.now(),y=window.cefQuery({request:JSON.stringify(u),persistent:!1,onSuccess:()=>{const n=Date.now()-g;l.withFields({duration:n}).log(`setPlayableUri completed successfully after ${n} ms`),t>0&&b({playbackPosition:t}),f&&(clearTimeout(f),f=0),this._changeLoadMode(this.LoadMode.LOADED),this._loadedUrl=e,this.dispatchEvent(new Event("canplay")),i()},onFailure:(e,t)=>{const i=Date.now()-g;l.withFields({duration:i}).log(`setPlayableUri failed after ${i} ms. Error code: ${e}, error message: ${t}`),f&&(clearTimeout(f),f=0),99===e?this._changeLoadMode(n):(this._changeLoadMode(this.LoadMode.NOT_LOADED),this._loadedUrl=""),o(new v(e,t))}});l.log(`window.cefQuery for setPlayableUri returned query id ${y}`);const w=this._setPlayableUriTimeout+1e3;f=setTimeout((()=>{l.log(`setPlayableUri reached timeout of ${w} ms, canceling query id ${y}`),window.cefQueryCancel(y),this._changeLoadMode(this.LoadMode.NOT_LOADED),this._loadedUrl="",o(new v(6e3,`load reached timeout of ${w} ms`))}),w,y)}))}d.error("remotePlayer load: either window.cefQuery or url is undefined")}async unload(){if(!this._isInitialized)throw new v(6500,"Cannot call unload() if remote player is not initialized");if(window.cefQuery){if(this._loadMode===this.LoadMode.LOADING)throw new v(6502,"Cannot call unload() while load is still in progress");const e=this._loadMode;return this._changeLoadMode(this.LoadMode.UNLOADING),new Promise(((t,i)=>{const n=r(),o=d.withFields({FCID:n});o.log("remotePlayer unload");const s={type:"remotePlayer.unload",class:"remotePlayer",action:"unload",fcid:n},a={target:"TC",waitForResponse:!0,message:JSON.stringify(s)};let l=0;const c=Date.now(),u=window.cefQuery({request:JSON.stringify(a),persistent:!1,onSuccess:()=>{const e=Date.now()-c;o.withFields({duration:e}).log(`unload completed successfully after ${e} ms`),l&&(clearTimeout(l),l=0),this._reset(),this._changeLoadMode(this.LoadMode.NOT_LOADED),this._loadedUrl=void 0,t()},onFailure:(t,n)=>{const s=Date.now()-c;o.withFields({duration:s}).log(`unload failed after ${s} ms. Error code: ${t}, error message: ${n}`),l&&(clearTimeout(l),l=0),this._changeLoadMode(e),i(new v(t,n))}});o.log(`window.cefQuery for unload returned query id ${u}`);const f=this._unloadTimeout+1e3;l=setTimeout((()=>{o.log(`unload reached timeout of ${f} ms, canceling query id ${u}`),window.cefQueryCancel(u),this._changeLoadMode(e),i(new v(6e3,`unload reached timeout of ${f} ms`))}),f,u)}))}d.error("remotePlayer unload: window.cefQuery is undefined")}play(){if(!this._isInitialized)throw new v(6500,"Cannot call play() if remote player is not initialized");if(window.cefQuery){if(this._loadMode!==this.LoadMode.LOADED)throw new v(6001,"Cannot call play() if player is not loaded");const e=r(),t=d.withFields({FCID:e});t.log("remotePlayer play: sending play action");const i=this._selectedAudioTrack||this._config.preferredAudioLanguage||"";let n="";this._textTrackVisibility&&(n=this._selectedSubtitlesTrack||this._config.preferredSubtitlesLanguage||"");const o={type:"remotePlayer.play",class:"remotePlayer",action:"play",fcid:e,audioLanguage:i,subtitlesLanguage:n,playbackPosition:this.currentTime},s={target:"TC",waitForResponse:!1,message:JSON.stringify(o)};return new Promise(((e,i)=>{window.cefQuery({request:JSON.stringify(s),persistent:!1,onSuccess:()=>{t.log("remotePlayer play request successfully sent"),e()},onFailure:(e,n)=>{t.error(`remotePlayer play request failed: ${e} ${n}`),i(new v(e,n))}})}))}return d.error("remotePlayer play: window.cefQuery is undefined"),Promise.resolve(void 0)}pause(){if(!this._isInitialized)throw new v(6500,"Cannot call pause() if remote player is not initialized");if(window.cefQuery){if(this._loadMode!==this.LoadMode.LOADED)throw new v(6001,"Cannot call pause() if player is not loaded");const e=r(),t=d.withFields({FCID:e});t.log("remotePlayer pause: sending pause request");const i={type:"remotePlayer.pause",class:"remotePlayer",action:"pause",fcid:e},n={target:"TC",waitForResponse:!1,message:JSON.stringify(i)};return new Promise(((e,i)=>{window.cefQuery({request:JSON.stringify(n),persistent:!1,onSuccess:()=>{t.log("remotePlayer pause request successfully sent"),e()},onFailure:(e,n)=>{t.error(`remotePlayer pause request failed: ${e} ${n}`),i(new v(e,n))}})}))}return d.error("remotePlayer pause: window.cefQuery is undefined"),Promise.resolve(void 0)}getAssetUri(){if(!this._isInitialized)throw new v(6500,"Cannot call getAssetUri() if remote player is not initialized");return this._loadedUrl}getLoadMode(){if(!this._isInitialized)throw new v(6500,"Cannot call getLoadMode() if remote player is not initialized");return this._loadMode}getTextTracks(){return T(this._availableTextTracks)}getAudioTracks(){return T(this._availableAudioTracks)}selectAudioTrack(e){for(const t of this.getAudioTracks())if(t.id===e)return void(this._selectedAudioTrack=e);d.warn(`Invalid audioTrackId ${e}`)}selectTextTrack(e){for(const t of this.getTextTracks())if(t.id===e)return void(this._selectedSubtitlesTrack=e);d.warn(`Invalid textTrackId ${e}`)}setTextTrackVisibility(e){const t=this._textTrackVisibility;if("boolean"!=typeof e)throw new TypeError("visible parameter must be a boolean");const i=e;i!==t&&(this._textTrackVisibility=i,i||(this._selectedSubtitlesTrack=""))}get currentTime(){return S()?.playbackPosition}set currentTime(e){if(b({playbackPosition:e}),window.cefQuery){const t=r(),i=d.withFields({FCID:t});i.log("setting remotePlayer currentTime");const n={type:"remotePlayer.seek",class:"remotePlayer",action:"seek",playbackPosition:e,fcid:t},o={target:"TC",waitForResponse:!1,message:JSON.stringify(n)};window.cefQuery({request:JSON.stringify(o),persistent:!1,onSuccess:()=>{i.log("remotePlayer seek request successfully sent")},onFailure:(e,t)=>{i.error(`remotePlayer seek request failed: ${e} ${t}`)}})}else d.error("setting remotePlayer currentTime: window.cefQuery is undefined")}get duration(){return S()?.assetDuration}get textTrackVisibility(){return this._textTrackVisibility}getPresentationStartTimeAsDate(){return void 0===this._availabilityStartTime?null:new Date(1e3*this._availabilityStartTime)}}const _=new I;"undefined"!=typeof window&&(window.remotePlayer=_,Object.defineProperty(window,"senzaRemotePlayer",{value:_,writable:!1,configurable:!1}));class O extends EventTarget{UiState=Object.freeze({UNKNOWN:"unknown",FOREGROUND:"foreground",IN_TRANSITION_TO_FOREGROUND:"inTransitionToForeground",BACKGROUND:"background",IN_TRANSITION_TO_BACKGROUND:"inTransitionToBackground"});constructor(){super(),this._isInitialized=!1,this._inTransition=!1,"undefined"!=typeof document&&document.addEventListener("hs/uistatechange",(e=>{d.log("Got hs/uistatechange",e.detail);const t=new Event("onstatechange");t.state=e.detail,this._state=t.state,this.dispatchEvent(t)}))}async _init(){window.cefQuery&&(this._state=await new Promise((e=>{window.cefQuery({request:"uiState",persistent:!1,onSuccess:t=>{d.log(`uiState request successfully returned '${t}'`),e(t)},onFailure:(t,i)=>{d.error(`uiState request failed: ${t} ${i}`),e(this.UiState.UNKNOWN)}})})),this._isInitialized=!0)}get state(){return this._isInitialized||(this._state=this.UiState.UNKNOWN),this._state}getState(){if(window.cefQuery)return new Promise(((e,t)=>{window.cefQuery({request:"uiState",persistent:!1,onSuccess:t=>{d.log(`uiState request successfully returned '${t}'`),e(t)},onFailure:(e,i)=>{d.error(`uiState request failed: ${e} ${i}`),t(i)}})}));d.warn("lifecycle getState is not supported if NOT running e2e")}moveToForeground(){return window.cefQuery?this._inTransition||this._state===this.UiState.FOREGROUND||this._state===this.UiState.IN_TRANSITION_TO_FOREGROUND?(d.warn(`lifecycle moveToForeground: No need to transition to foreground, state: ${this._state} transition: ${this._inTransition}`),Promise.resolve(!1)):(this._inTransition=!0,new Promise(((e,t)=>{const i=r(),n=d.withFields({FCID:i});n.log("lifecycle moveToForeground: sending uiActiveRequest action"),window.cefQuery({request:JSON.stringify({action:"uiActiveRequest",fcid:i}),persistent:!1,onSuccess:()=>{n.log("uiActiveRequest successfully sent"),this._inTransition=!1,e(!0)},onFailure:(e,i)=>{this._inTransition=!1,n.error(`uiActiveRequest failed: ${e} ${i}`),t(`uiActiveRequest failed: ${e} ${i}`)}})}))):(d.warn("lifecycle moveToForeground: window.cefQuery is undefined"),Promise.resolve(!1))}moveToBackground(){return window.cefQuery?this._inTransition||this._state===this.UiState.BACKGROUND||this._state===this.UiState.IN_TRANSITION_TO_BACKGROUND?(d.warn(`lifecycle moveToBackground: No need to transition to background, state: ${this._state} transition: ${this._inTransition}`),Promise.resolve(!1)):(this._inTransition=!0,new Promise(((e,t)=>{const i=r(),n=d.withFields({FCID:i});n.log("lifecycle moveToBackground: sending play action");const o=_.getConfiguration(),s=_._selectedAudioTrack||o.preferredAudioLanguage||"",a=_._selectedSubtitlesTrack||o.preferredSubtitlesLanguage||"";window.cefQuery({request:JSON.stringify({action:"play",fcid:i,audioLanguage:s,subtitlesLanguage:a}),persistent:!1,onSuccess:()=>{n.log("[ moveToBackground ] play successfully sent"),this._inTransition=!1,e(!0)},onFailure:(e,i)=>{this._inTransition=!1,n.error(`[ moveToBackground ] play failed: ${e} ${i}`),t(`[ moveToBackground ] play failed: ${e} ${i}`)}})}))):(d.warn("lifecycle moveToBackground: window.cefQuery is undefined"),Promise.resolve(!1))}moveToUiStandby(){return window.cefQuery?new Promise(((e,t)=>{const i=r(),n={target:"TC",waitForResponse:!1,message:JSON.stringify({type:"uiStandbyRequest",fcid:i})},o=d.withFields({FCID:i});o.log("lifecycle moveToUiStandby: sending uiStandbyRequest"),window.cefQuery({request:JSON.stringify(n),persistent:!1,onSuccess:()=>{o.log("[ moveToUiStandby ] moveToUiStandby successfully sent"),e(!0)},onFailure:(e,i)=>{o.error(`[ moveToUiStandby ] moveToUiStandby failed: ${e} ${i}`),t(`moveToUiStandby failed: ${e} ${i}`)}})})):(d.warn("moveToUiStandby was called in local dev"),Promise.resolve(!0))}switchTenant(e){if(e&&e.length>0){if(e===ee().sessionInfo?.tenantId)return d.warn(`SwitchTenant requires a different tenantId than the current one. CurrentTenantId=${ee().sessionInfo?.tenantId} and tenantId=${e}`),Promise.reject("SwitchTenant requires a different tenantId than the current one");const t=ee().sessionInfo?.homeSessionInfo?.tenantInfo?.contentHubTenantId,i=ee().sessionInfo?.homeSessionInfo?.tenantId;return d.log(`SwitchTenant for ${e}`),window.cefQuery?new Promise(((n,o)=>{const s=r(),a=d.withFields({FCID:s}),l={type:"reconnect",fcid:s,session:btoa(JSON.stringify({tenantId:e,...ee().sessionInfo?.tenantId===t&&e!==i&&{returnToTenantId:t}}))},c={target:"TC",waitForResponse:!1,message:JSON.stringify(l)};window.cefQuery({request:JSON.stringify(c),persistent:!1,onSuccess:()=>{a.log("SwitchTenant request successfully sent"),n(!0)},onFailure:(e,t)=>{a.error(`SwitchTenant failed: ${e} ${t}`),o(`SwitchTenant failed: ${e} ${t}`)}})})):(d.warn("SwitchTenant is not supported if NOT running e2e"),Promise.reject("SwitchTenant is not supported if NOT running e2e"))}return d.warn("SwitchTenant requires a valid tenantId string parameter"),Promise.reject("SwitchTenant requires a valid tenantId string parameter")}exitApplication(){return window.cefQuery?new Promise(((e,t)=>{const i=r(),n=d.withFields({FCID:i});let o,s;const a=c.sessionInfoObj;a?.homeSessionInfo&&(a?.returnToTenantId||a?.homeSessionInfo.tenantId!==a?.tenantId)?(s={type:"reconnect",splashUrl:a?.homeSessionInfo.tenantInfo.tenantSettings.applicationSwitchSplashUrl,fcid:i},a?.returnToTenantId&&(a?.returnToTenantId===a?.homeSessionInfo.tenantInfo.contentHubTenantId&&(s.splashUrl=a?.homeSessionInfo.contentHubTenantInfo.tenantSettings.applicationSwitchSplashUrl),s.session=btoa(JSON.stringify({tenantId:a?.returnToTenantId}))),o={target:"TC",waitForResponse:!1,message:JSON.stringify(s)}):(s={type:"launchHomeApplication",fcid:i},o={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(s)}),window.cefQuery({request:JSON.stringify(o),persistent:!1,onSuccess:()=>{n.log(`exitApplication request with type: '${s.type}' successfully sent`),e(!0)},onFailure:(e,i)=>{n.error(`exitApplication request with type: '${s.type}' failed: ${e} ${i}`),t(`exitApplication request with type: '${s.type}' failed: ${e} ${i}`)}})})):(d.warn("exitApplication is not supported if NOT running e2e"),Promise.reject("exitApplication is not supported if NOT running e2e"))}}const N=new O,k={};let $,E,F=0;async function P(){if(!$)try{const e=await l("wifi-ap-data");$=JSON.parse(e)}catch(e){d.error(e)}}async function q(){if(F+5e3<Date.now())try{const e=await l("wifi-status");E=JSON.parse(e),F=Date.now()}catch(e){d.error(e)}}class C extends EventTarget{constructor(){super(),k.level=0,k.quality=0,k.ssid="unknown",k.bssid="unknown","undefined"!=typeof document&&document.addEventListener("wifiSignalReport",(e=>{d.log("Got wifiSignalReport",JSON.stringify(e.detail)),k.level=e.detail.level,k.quality=e.detail.quality,k.ssid=e.detail.ssid,k.bssid=e.detail.bssid,this.dispatchEvent(new Event("wifiInfoUpdated"))}))}get deviceInfo(){const e=c.sessionInfoObj;return ie()&&e?{deviceId:e.deviceId,connectionId:e.connectionId,community:e.community,tenant:e.tenant,clientIp:e.clientIp,countryCode:e.general?.location?.["x-country-code"]}:(d.log("getDeviceInfo running locally, returning dummy info"),{deviceId:"123456789",connectionId:"dummy",community:"LocalDev",tenant:"XXXXXX",clientIp:"0.0.0.0",countryCode:"XX"})}get wifiInfo(){return k}reboot(){return new Promise(((e,t)=>{if(window.cefQuery){const i=r(),n=d.withFields({FCID:i}),o={type:"reboot",fcid:i},s={target:"TC",waitForResponse:!1,message:JSON.stringify(o)};window.cefQuery({request:JSON.stringify(s),persistent:!1,onSuccess:()=>{n.log("reboot request successfully sent"),e(!0)},onFailure:(e,i)=>{n.error(`reboot failed: ${e} ${i}`),t(`reboot failed: ${e} ${i}`)}})}else d.warn("reboot is not supported if NOT running e2e"),t("reboot is not supported if NOT running e2e")}))}clearWifi(){return new Promise(((e,t)=>{const i=r(),n=d.withFields({FCID:i}),o={type:"resetWifi",fcid:i},s={target:"TC",waitForResponse:!1,message:JSON.stringify(o)};window.cefQuery({request:JSON.stringify(s),persistent:!1,onSuccess:()=>{n.log("clearWifi successfully sent"),e(!0)},onFailure:(e,i)=>{n.error(`clearWifi failed: ${e} ${i}`),t(`clearWifi failed: ${e} ${i}`)}})}))}sendDataToDevice(e){if("string"!=typeof e)throw new Error("data must be of type 'string'");return new Promise(((t,i)=>{const n=r(),o=d.withFields({FCID:n}),s={type:"externalCommand",data:{command:"forward",payload:e},fcid:n},a={target:"TC",waitForResponse:!1,message:JSON.stringify(s)};window.cefQuery({request:JSON.stringify(a),persistent:!1,onSuccess:()=>{o.log("externalCommand successfully sent"),t()},onFailure:(e,t)=>{o.error(`externalCommand failed: ${e} ${t}`),i(`externalCommand failed: ${e} ${t}`)}})}))}async factoryReset(e=!0){if("boolean"!=typeof e)throw new Error("reboot param must be of type 'boolean'");return new Promise(((t,i)=>{const n=r(),o=d.withFields({FCID:n}),s={type:"factoryReset",fcid:n,reboot:e},a={target:"TC",waitForResponse:!0,message:JSON.stringify(s)};let l=0;const c=window.cefQuery({request:JSON.stringify(a),persistent:!1,onSuccess:()=>{l&&clearTimeout(l),o.log("factoryReset successfully sent"),t(!0)},onFailure:(e,t)=>{l&&clearTimeout(l),o.error(`factoryReset failed: ${e} ${t}`),i(`factoryReset failed: ${e} ${t}`)}});l=setTimeout((()=>{o.error("factoryReset failed: reached timeout of 5000 ms"),window.cefQueryCancel(c),i("factoryReset failed: reached timeout of 5000 ms")}),5e3)}))}async getWifiInfo(){return await Promise.all([P(),q()]),{...$,...E}}}const A=new C;"undefined"!=typeof window&&Object.defineProperty(window,"senzaDeviceManager",{value:A,writable:!1,configurable:!1});class R extends EventTarget{constructor(){super()}get appConfig(){const e=c.sessionInfoObj,t=e.homeSessionInfo?.appConfig||{};return d.info("PlatformManager get appConfig: \n"+JSON.stringify(t,null,2)),t}setTimezone(e){if(window.cefQuery){const t={message:JSON.stringify({type:"setTimeZone",timezone:e}),waitForResponse:!1,target:"UI-Streamer"};window.cefQuery({request:JSON.stringify(t),persistent:!1,onSuccess:()=>{d.log("PlatformManager timezome is successfully set to",e)},onFailure:(t,i)=>{d.error(`PlatformManager error occurred setting timezone to ${e}: ${t} ${i}`)}})}}}const L=new R;class D extends EventTarget{constructor(){super(),"undefined"!=typeof document&&document.addEventListener("hs/alarmFiredEvent",(e=>{d.log("Got hs/alarmFiredEvent",JSON.stringify(e.detail)),e.detail?.alarmName&&this.dispatchEvent(new CustomEvent(e.detail.alarmName,{detail:e.detail.payload}))}))}addAlarm(e,t,i=""){if("string"!=typeof i)throw Error("data must be a string");const n=r(),o=d.withFields({alarmName:e,FCID:n});if(o.log(`addAlarm called for ${e} to be fired at ${t}`),window.cefQuery){const s={type:"addAlarm",fcid:n,alarmName:e,alarmTime:t,payload:i},r={target:"TC",waitForResponse:!1,message:JSON.stringify(s)};window.cefQuery({request:JSON.stringify(r),persistent:!1,onSuccess:()=>{o.log("addAlarm request successfully sent")},onFailure:(e,t)=>{o.error(`addAlarm failed: ${e} ${t}`)}})}else o.warn("addAlarm is not supported if NOT running e2e")}deleteAlarm(e){const t=r(),i=d.withFields({alarmName:e,FCID:t});if(i.log(`deleteAlarm called for ${e}`),window.cefQuery){const n={type:"deleteAlarm",fcid:t,alarmName:e},o={target:"TC",waitForResponse:!1,message:JSON.stringify(n)};window.cefQuery({request:JSON.stringify(o),persistent:!1,onSuccess:()=>{i.log("deleteAlarm request successfully sent")},onFailure:(e,t)=>{i.error(`deleteAlarm failed: ${e} ${t}`)}})}else i.warn("deleteAlarm is not supported if NOT running e2e")}deleteAllAlarms(){if(window.cefQuery){const e=r(),t=d.withFields({FCID:e}),i={type:"deleteAllAlarms",fcid:e},n={target:"TC",waitForResponse:!1,message:JSON.stringify(i)};window.cefQuery({request:JSON.stringify(n),persistent:!1,onSuccess:()=>{t.log("deleteAllAlarms request successfully sent")},onFailure:(e,i)=>{t.error(`deleteAllAlarms failed: ${e} ${i}`)}})}else d.warn("deleteAllAlarms is not supported if NOT running e2e")}getActiveAlarms(){throw Error("NOT IMPLEMENTED")}}const U=new D;"undefined"!=typeof window&&(window.alarmManager=U,Object.defineProperty(window,"senzaAlarmManager",{value:U,writable:!1,configurable:!1}));class Q extends EventTarget{constructor(){super(),"undefined"!=typeof document&&document.addEventListener("hs/externalEvent",(e=>{d.log("Got hs/externalEvent",JSON.stringify(e.detail)),this.dispatchEvent(new CustomEvent("message",{detail:{eventName:e.detail.eventName,payload:e.detail.payload,fcid:e.detail.fcid}}))}))}async registerGroups(e){return d.log(`register called for ${e}`),new Promise(((t,i)=>{if(window.cefQuery){const n=r(),o=d.withFields({FCID:n}),s={type:"registerGroupEvent",fcid:n,groups:e},a={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(s)};window.cefQuery({request:JSON.stringify(a),persistent:!1,onSuccess:()=>{o.log("registerGroupEvent request successfully sent"),t(!0)},onFailure:(e,t)=>{o.error(`registerGroupEvent failed: ${e} ${t}`),i(`registerGroupEvent failed: ${e} ${t}`)}})}else d.warn("registerGroupEvent is not supported if NOT running e2e"),i("registerGroupEvent is not supported if NOT running e2e")}))}}const J=new Q;let M,x;"undefined"!=typeof window&&(window.messageManager=J,Object.defineProperty(window,"senzaMessageManager",{value:J,writable:!1,configurable:!1})),N.getState()?.then((e=>{x=e})),N.addEventListener("onstatechange",(e=>{x=e.state}));const X=e=>{"background"!==x&&"inTransitionToBackground"!==x||(M&&clearTimeout(M),M=setTimeout((()=>{"background"!==x&&"inTransitionToBackground"!==x||d.log(`${e.type} event received while in '${x}' state and there was no call to lifecycle.moveToForeground() for 500 ms. Make sure to call it if you want to move to foreground.`),M=0}),500))};"undefined"!=typeof document&&document.addEventListener("keydown",X),_.addEventListener("error",X),_.addEventListener("ended",X);const{version:z}=n;let j;const G="1.0";"undefined"!=typeof document&&document.addEventListener("keydown",(e=>{d.log(`Got ${e.key} key`)}));const B={getToken:async function(){return j?Promise.resolve(j):(d.log("getToken wait for promise updateSession event"),new Promise((e=>{document.addEventListener("updateSession",(t=>{j=t.detail?.updateObj,d.log(`onUpdateSessionEvent: token= ${j}`),e(j)}),{once:!0})})))},forceTokenUpdate:function(){if(j=null,window.cefQuery){const e=r(),t=d.withFields({FCID:e});t.log("forceTokenUpdate: sending updateSessionRequest");const i={type:"updateSessionRequest",updateKey:"authorization",parentPath:"settings.webUI.backendHeaders.Authorization",fcid:e},n={target:"TC",waitForResponse:!1,message:JSON.stringify(i)};window.cefQuery({request:JSON.stringify(n),persistent:!1,onSuccess:()=>{t.log("updateSessionRequest successfully sent")},onFailure:(e,i)=>{t.error(`updateSessionRequest failed: ${e} ${i}`)}})}else d.error("forceTokenUpdate: window.cefQuery is undefined")},getClientAssertion:de},V=Object.freeze({UNKNOWN:"unknown",INITIAL_CONNECTION:"initial_connection",UI_RELEASE:"ui_release",UI_TERMINATION:"ui_termination",WEBRTC_ERROR:"webrtc_error",UI_WATCHDOG:"ui_watchdog"});let W=V.UNKNOWN,H={};async function K(){if(d.log(`init ${z}`),window.diagnostics||d.error("[ init ] window.diagnostics is undefined"),window.cefQuery){await new Promise(((e,t)=>{window.cefQuery({request:"apiVersion "+G,persistent:!1,onSuccess:()=>{d.log("api version compatability check succeeded"),e()},onFailure:(e,i)=>{d.error("api version compatability check failed: "+i),t(i)}})}));const e=await new Promise((e=>{window.cefQuery({request:"sessionInfo",persistent:!1,onSuccess:t=>{d.log("sessionInfo request successfully returned "+t),e(t)},onFailure:(e,t)=>{d.error(`sessionInfo request failed: ${e} ${t}`)}})}));c.setSessionInfoStr(e);const t=JSON.parse(e);j=t?.settings?.webUI?.backendHeaders?.Authorization,d.log(`authToken: token = ${j}`),document.addEventListener("updateSession",(e=>{j=e.detail?.updateObj,d.log(`onUpdateSessionEvent: token = ${j}`)})),W=await new Promise((e=>{const t=r(),i=d.withFields({FCID:t}),n={type:"connectReason",fcid:t},o={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(n)};window.cefQuery({request:JSON.stringify(o),persistent:!1,onSuccess:t=>{i.log(`connectReason request successfully returned '${t}'`),e(t)},onFailure:(t,n)=>{i.error(`connectReason request failed: ${t} ${n}`),e(V.UNKNOWN)}})}));const i=await new Promise((e=>{const t=r(),i=d.withFields({FCID:t}),n={type:"triggerEvent",fcid:t},o={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(n)};window.cefQuery({request:JSON.stringify(o),persistent:!1,onSuccess:t=>{i.log(`triggerEvent request successfully returned '${t}'`),e(t)},onFailure:(t,n)=>{i.error(`triggerEvent request failed: ${t} ${n}`),e("")}})}));H={};let n={};if(i)try{n=JSON.parse(i),H.type=n.type,"keyPressEvent"===H.type?H.data={keyValue:n.keyValue}:"alarmFiredEvent"===H.type?H.data={alarmName:n.alarmName,payload:n.payload}:"userAlertEvent"===H.type?H.data={eventCode:n.eventCode,message:n.message}:"externalEvent"===H.type?H.data={eventName:n.eventName,payload:n.payload}:"videoPlaybackEvent"===H.type?H.data={eventCode:n.eventCode,errorCode:n.errorCode}:d.warn("unknown trigger event type",H.type)}catch(e){d.error(`failed to parse trigger event string ${i}: ${e.message}`)}await _._init(t?.settings?.["ui-streamer"],n),await N._init();const o=t?.settings?.["ui-streamer"]?.devSequence;o&&(p({lifecycle:N,remotePlayer:_}),h(!0))}else j=ee().sessionInfo?.settings?.webUI?.backendHeaders?.Authorization,d.log(`authToken dummy: token = ${j}`);window.auth=B,Object.defineProperty(window,"senzaAuth",{value:B,writable:!1,configurable:!1}),window.close=()=>{d.warn("window.close is disabled on Senza platform. Use lifecycle.exitApplication() instead.")}}function Z(){return W}function Y(){return H}function ee(){if("undefined"==typeof window||!window.diagnostics)return"undefined"==typeof window||window.diagnostics||d.error("[ getPlatformInfo ] window.diagnostics is undefined"),{version:"X.X.XX-X",pod:"ui-streamer-X.X.XX-X-QWERT-ASDFG-XXX-XXXXXX-XXXXX",podIP:"0.0.0.0",sessionInfo:{userAgent:"SynamediaSenza/XX.YY.ZZ",connectionId:"dummy",deviceId:"123456789",community:"LocalDev",tenant:"XXXXXX",tenantId:"XXXXXX",manifest:{transcontainer:"X.X.XX-X"},settings:{webUI:{backendHeaders:{Authorization:"Bearer dummytoken"}}},homeSessionInfo:{tenantId:"XXXXXX",community:"LocalDev"}}};try{const e=window.diagnostics()||{};return e.sessionInfo=c.sessionInfoObj,e}catch(e){d.error("Could not get platform info",e.stack)}}function te(e){if(window.cefQuery){const t={message:JSON.stringify({type:"setTimeZone",timezone:e}),waitForResponse:!1,target:"UI-Streamer"};window.cefQuery({request:JSON.stringify(t),persistent:!1,onSuccess:()=>{d.log("timezome is successfully set to",e)},onFailure:(t,i)=>{d.error(`error occurred setting timezone to ${e}: ${t} ${i}`)}})}}function ie(){return!("undefined"==typeof window||!window.cefQuery)}function ne(){window.cefQuery?window.cefQuery({request:"uiReady",persistent:!1,onSuccess:()=>{d.log("uiReady request successfully sent")},onFailure:(e,t)=>{d.error(`uiReady request failed: ${e} ${t}`)}}):d.error("uiReady: window.cefQuery is undefined")}function oe(){const e=c.sessionInfoObj;return ie()?{deviceId:e.deviceId,connectionId:e.connectionId,community:e.community,tenant:e.tenant,clientIp:e.clientIp}:(d.log("getDeviceInfo running locally, returning dummy info"),{deviceId:"123456789",connectionId:"dummy",community:"LocalDev",tenant:"XXXXXX",clientIp:"0.0.0.0"})}const se={remoteBrowserIp:window.diagnostics?window.diagnostics().podIP:"127.0.0.1",sdkVersion:z};function re(e,t,i,n){if(200===e&&(t=window.btoa(String.fromCharCode.apply(null,new Uint8Array(t)))),window.cefQuery){const o={type:"updateLicense",sessionId:n,fcid:i};o[200===e?"response":"error"]=t;const s={target:"TC",waitForResponse:!1,message:JSON.stringify(o)};window.cefQuery({request:JSON.stringify(s),persistent:!1,onSuccess:()=>{d.log("updateLicense request successfully sent")},onFailure:(e,t)=>{d.error(`updateLicense request failed: ${e} ${t}`)}})}}class ae extends Error{constructor(e,t){super(t),this.code=e}}function de(){if(window.cefQuery)return d.log("getClientAssertion is called"),new Promise(((e,t)=>{window.cefQuery({request:"client_assertion",persistent:!1,onSuccess:i=>{try{const t=JSON.parse(i);d.log(`client_assertion request successfully returned ${i}`),e(t)}catch(e){d.error(`Failed to parse client assertion ${i}`),t(new ae(0,"Failed to parse client assertion"))}},onFailure:(e,i)=>{d.log(`client_assertion request failed: ${e} ${i}`),t(new ae(e,i))}})}));d.warn("getClientAssertion is not supported if NOT running e2e")}return"undefined"!=typeof window&&(window.hs=i),t})()));
|
package/package.json
CHANGED
package/src/deviceManager.js
CHANGED
|
@@ -264,16 +264,16 @@ class DeviceManager extends EventTarget {
|
|
|
264
264
|
/**
|
|
265
265
|
* Get Wi-Fi info - access point data and status (the status is cached for 5 seconds)
|
|
266
266
|
* @returns {Object} Wi-Fi info
|
|
267
|
-
* @property {string} ssid
|
|
268
|
-
* @property {string} bssid
|
|
269
|
-
* @property {string} standard
|
|
270
|
-
* @property {string} security
|
|
271
|
-
* @property {string} device-mac
|
|
272
|
-
* @property {string} device-ip4
|
|
273
|
-
* @property {number} channel
|
|
274
|
-
* @property {number} width
|
|
275
|
-
* @property {number} level
|
|
276
|
-
* @property {number} quality
|
|
267
|
+
* @property {string} ssid the name of the Wi-Fi network that the device is connected to
|
|
268
|
+
* @property {string} bssid the unique identifier of the Wi-Fi access point
|
|
269
|
+
* @property {string} standard the Wi-Fi standard in use, such as 802.11a/b/g/n/ac/ax
|
|
270
|
+
* @property {string} security the type of security protocol used by the Wi-Fi network, such as WEP, WPA, WPA2, or WPA3
|
|
271
|
+
* @property {string} device-mac the MAC address of the device
|
|
272
|
+
* @property {string} device-ip4 the IPv4 address assigned to the device on the Wi-Fi network
|
|
273
|
+
* @property {number} channel the number of the Wi-Fi channel currently being used
|
|
274
|
+
* @property {number} width width of the Wi-Fi channel in megahertz, e.g. 20MHz or 40 MHz channel
|
|
275
|
+
* @property {number} level a measure of the received signal strength, in the range 0 to 100 (the higher, the better). The level value is 100+RSSI (RSSI is the signal strength, measured in decibels)
|
|
276
|
+
* @property {number} quality a measure of the signal quality, in the range 0 to 100 (the higher, the better). The quality value is derived from the signal EVM.
|
|
277
277
|
* */
|
|
278
278
|
async getWifiInfo() {
|
|
279
279
|
await Promise.all([getWifiApData(), getWifiStatus()]);
|
package/src/lifecycle.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getPlatformInfo } from "./api";
|
|
2
2
|
import { getFCID, sdkLogger } from "./utils";
|
|
3
|
-
import {sessionInfo} from "./SessionInfo";
|
|
4
|
-
import {remotePlayer} from "./remotePlayer";
|
|
3
|
+
import { sessionInfo } from "./SessionInfo";
|
|
4
|
+
import { remotePlayer } from "./remotePlayer";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Lifecycle is a singleton class that manages the application lifecycle states:<br>
|
|
@@ -44,6 +44,7 @@ class Lifecycle extends EventTarget {
|
|
|
44
44
|
* @private
|
|
45
45
|
*/
|
|
46
46
|
this._isInitialized = false;
|
|
47
|
+
this._inTransition = false;
|
|
47
48
|
|
|
48
49
|
typeof document !== "undefined" && document.addEventListener("hs/uistatechange", (e) => {
|
|
49
50
|
sdkLogger.log("Got hs/uistatechange", e.detail);
|
|
@@ -124,25 +125,38 @@ class Lifecycle extends EventTarget {
|
|
|
124
125
|
* the application is moved from foreground to inTransitionToBackground and eventually to background.
|
|
125
126
|
* The application will need to call moveToForeground when it receives an event that needs the UI to be displayed again,
|
|
126
127
|
* for example a key press, a playback end-of-file or a playback error.
|
|
128
|
+
* @return {Promise} Promise which is resolved when the moveToForeground command has been successfully processed.
|
|
129
|
+
* Failure to process the moveToForeground command will result in the promise being rejected.
|
|
127
130
|
*/
|
|
128
131
|
moveToForeground() {
|
|
129
132
|
if (window.cefQuery) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
133
|
+
if (this._inTransition || this._state === this.UiState.FOREGROUND || this._state === this.UiState.IN_TRANSITION_TO_FOREGROUND) {
|
|
134
|
+
sdkLogger.warn(`lifecycle moveToForeground: No need to transition to foreground, state: ${this._state} transition: ${this._inTransition}`);
|
|
135
|
+
return Promise.resolve(false);
|
|
136
|
+
}
|
|
137
|
+
this._inTransition = true;
|
|
138
|
+
return new Promise((resolve, reject) => {
|
|
139
|
+
const FCID = getFCID();
|
|
140
|
+
const logger = sdkLogger.withFields({ FCID });
|
|
141
|
+
logger.log("lifecycle moveToForeground: sending uiActiveRequest action");
|
|
142
|
+
window.cefQuery({
|
|
143
|
+
request: JSON.stringify({ action: "uiActiveRequest", fcid: FCID }),
|
|
144
|
+
persistent: false,
|
|
145
|
+
onSuccess: () => {
|
|
146
|
+
logger.log("uiActiveRequest successfully sent");
|
|
147
|
+
this._inTransition = false;
|
|
148
|
+
resolve(true);
|
|
149
|
+
},
|
|
150
|
+
onFailure: (code, msg) => {
|
|
151
|
+
this._inTransition = false;
|
|
152
|
+
logger.error(`uiActiveRequest failed: ${code} ${msg}`);
|
|
153
|
+
reject(`uiActiveRequest failed: ${code} ${msg}`);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
142
156
|
});
|
|
143
|
-
} else {
|
|
144
|
-
sdkLogger.error("lifecycle moveToForeground: window.cefQuery is undefined");
|
|
145
157
|
}
|
|
158
|
+
sdkLogger.warn("lifecycle moveToForeground: window.cefQuery is undefined");
|
|
159
|
+
return Promise.resolve(false);
|
|
146
160
|
}
|
|
147
161
|
|
|
148
162
|
/**
|
|
@@ -155,28 +169,41 @@ class Lifecycle extends EventTarget {
|
|
|
155
169
|
* remotePlayer.load("https://example.com/video.mp4", 0);
|
|
156
170
|
* remotePlayer.play(false);
|
|
157
171
|
* lifecycle.moveToBackground();
|
|
172
|
+
* @return {Promise} Promise which is resolved when the moveToBackground command has been successfully processed.
|
|
173
|
+
* Failure to process the moveToBackground command will result in the promise being rejected.
|
|
158
174
|
*/
|
|
159
175
|
moveToBackground() {
|
|
160
176
|
if (window.cefQuery) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
177
|
+
if (this._inTransition || this._state === this.UiState.BACKGROUND || this._state === this.UiState.IN_TRANSITION_TO_BACKGROUND) {
|
|
178
|
+
sdkLogger.warn(`lifecycle moveToBackground: No need to transition to background, state: ${this._state} transition: ${this._inTransition}`);
|
|
179
|
+
return Promise.resolve(false);
|
|
180
|
+
}
|
|
181
|
+
this._inTransition = true;
|
|
182
|
+
return new Promise((resolve, reject) => {
|
|
183
|
+
const FCID = getFCID();
|
|
184
|
+
const logger = sdkLogger.withFields({ FCID });
|
|
185
|
+
logger.log("lifecycle moveToBackground: sending play action");
|
|
186
|
+
const configuration = remotePlayer.getConfiguration();
|
|
187
|
+
const audioLanguage = remotePlayer._selectedAudioTrack || configuration.preferredAudioLanguage || "";
|
|
188
|
+
const subtitlesLanguage = remotePlayer._selectedSubtitlesTrack || configuration.preferredSubtitlesLanguage || "";
|
|
189
|
+
window.cefQuery({
|
|
190
|
+
request: JSON.stringify({ action: "play", fcid: FCID, audioLanguage, subtitlesLanguage }),
|
|
191
|
+
persistent: false,
|
|
192
|
+
onSuccess: () => {
|
|
193
|
+
logger.log("[ moveToBackground ] play successfully sent");
|
|
194
|
+
this._inTransition = false;
|
|
195
|
+
resolve(true);
|
|
196
|
+
},
|
|
197
|
+
onFailure: (code, msg) => {
|
|
198
|
+
this._inTransition = false;
|
|
199
|
+
logger.error(`[ moveToBackground ] play failed: ${code} ${msg}`);
|
|
200
|
+
reject(`[ moveToBackground ] play failed: ${code} ${msg}`);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
176
203
|
});
|
|
177
|
-
} else {
|
|
178
|
-
sdkLogger.error("lifecycle moveToBackground: window.cefQuery is undefined");
|
|
179
204
|
}
|
|
205
|
+
sdkLogger.warn("lifecycle moveToBackground: window.cefQuery is undefined");
|
|
206
|
+
return Promise.resolve(false);
|
|
180
207
|
}
|
|
181
208
|
|
|
182
209
|
/**
|
|
@@ -190,7 +217,7 @@ class Lifecycle extends EventTarget {
|
|
|
190
217
|
return new Promise((resolve, reject) => {
|
|
191
218
|
const FCID = getFCID();
|
|
192
219
|
const request = { target: "TC", waitForResponse: false, message: JSON.stringify({ type: "uiStandbyRequest", fcid: FCID }) };
|
|
193
|
-
const logger = sdkLogger.withFields({FCID});
|
|
220
|
+
const logger = sdkLogger.withFields({ FCID });
|
|
194
221
|
logger.log("lifecycle moveToUiStandby: sending uiStandbyRequest");
|
|
195
222
|
window.cefQuery({
|
|
196
223
|
request: JSON.stringify(request),
|
|
@@ -231,14 +258,16 @@ class Lifecycle extends EventTarget {
|
|
|
231
258
|
if (window.cefQuery) {
|
|
232
259
|
return new Promise((resolve, reject) => {
|
|
233
260
|
const FCID = getFCID();
|
|
234
|
-
const logger = sdkLogger.withFields({FCID});
|
|
261
|
+
const logger = sdkLogger.withFields({ FCID });
|
|
235
262
|
const message = {
|
|
236
263
|
type: "reconnect",
|
|
237
264
|
fcid: FCID,
|
|
238
|
-
session: btoa(JSON.stringify({
|
|
239
|
-
|
|
265
|
+
session: btoa(JSON.stringify({
|
|
266
|
+
tenantId,
|
|
267
|
+
...getPlatformInfo().sessionInfo?.tenantId === contentHubTenantId && tenantId !== homeTenantId && { returnToTenantId: contentHubTenantId }
|
|
268
|
+
}))
|
|
240
269
|
};
|
|
241
|
-
const request = {target: "TC", waitForResponse: false, message: JSON.stringify(message)};
|
|
270
|
+
const request = { target: "TC", waitForResponse: false, message: JSON.stringify(message) };
|
|
242
271
|
window.cefQuery({
|
|
243
272
|
request: JSON.stringify(request),
|
|
244
273
|
persistent: false,
|
|
@@ -269,7 +298,7 @@ class Lifecycle extends EventTarget {
|
|
|
269
298
|
if (window.cefQuery) {
|
|
270
299
|
return new Promise((resolve, reject) => {
|
|
271
300
|
const FCID = getFCID();
|
|
272
|
-
const logger = sdkLogger.withFields({FCID});
|
|
301
|
+
const logger = sdkLogger.withFields({ FCID });
|
|
273
302
|
let request;
|
|
274
303
|
let message;
|
|
275
304
|
const sessionInfoObj = sessionInfo.sessionInfoObj;
|
|
@@ -284,15 +313,15 @@ class Lifecycle extends EventTarget {
|
|
|
284
313
|
if (sessionInfoObj?.returnToTenantId === sessionInfoObj?.homeSessionInfo.tenantInfo.contentHubTenantId) {
|
|
285
314
|
message.splashUrl = sessionInfoObj?.homeSessionInfo.contentHubTenantInfo.tenantSettings.applicationSwitchSplashUrl;
|
|
286
315
|
}
|
|
287
|
-
message.session = btoa(JSON.stringify({tenantId: sessionInfoObj?.returnToTenantId}));
|
|
316
|
+
message.session = btoa(JSON.stringify({ tenantId: sessionInfoObj?.returnToTenantId }));
|
|
288
317
|
}
|
|
289
|
-
request = {target: "TC", waitForResponse: false, message: JSON.stringify(message)};
|
|
318
|
+
request = { target: "TC", waitForResponse: false, message: JSON.stringify(message) };
|
|
290
319
|
} else {
|
|
291
320
|
message = {
|
|
292
321
|
type: "launchHomeApplication",
|
|
293
322
|
fcid: FCID
|
|
294
323
|
};
|
|
295
|
-
request = {target: "UI-Streamer", waitForResponse: false, message: JSON.stringify(message)};
|
|
324
|
+
request = { target: "UI-Streamer", waitForResponse: false, message: JSON.stringify(message) };
|
|
296
325
|
}
|
|
297
326
|
|
|
298
327
|
window.cefQuery({
|