senza-sdk 4.0.9 → 4.0.10
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/lifecycle.js +31 -0
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:()=>J,auth:()=>V,deviceManager:()=>A,envInfo:()=>se,getClientAssertion:()=>de,getConnectReason:()=>Z,getDeviceInfo:()=>oe,getPlatformInfo:()=>ee,getTriggerEvent:()=>Y,init:()=>K,initSequence:()=>p,isRunningE2E:()=>ne,lifecycle:()=>_,messageManager:()=>M,platformManager:()=>R,remotePlayer:()=>k,setTimezone:()=>te,showSequence:()=>h,uiReady:()=>ie,writeLicenseResponse:()=>re});var n={};e.r(n),e.d(n,{ClientAssertionError:()=>ae,ConnectReason:()=>W,alarmManager:()=>J,auth:()=>V,deviceManager:()=>A,envInfo:()=>se,getClientAssertion:()=>de,getConnectReason:()=>Z,getDeviceInfo:()=>oe,getPlatformInfo:()=>ee,getTriggerEvent:()=>Y,init:()=>K,initSequence:()=>p,isRunningE2E:()=>ne,lifecycle:()=>_,messageManager:()=>M,platformManager:()=>R,remotePlayer:()=>k,setTimezone:()=>te,showSequence:()=>h,uiReady:()=>ie,writeLicenseResponse:()=>re});const i={version:"4.0.9"},{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 _.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 k=new I;"undefined"!=typeof window&&(window.remotePlayer=k,Object.defineProperty(window,"senzaRemotePlayer",{value:k,writable:!1,configurable:!1}));class O extends EventTarget{constructor(){super(),"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.dispatchEvent(t)}))}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=k.getConfiguration(),i=k._selectedAudioTrack||n.preferredAudioLanguage||"",o=k._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")}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 _=new O,E={};let $,N,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");N=JSON.parse(e),F=Date.now()}catch(e){d.error(e)}}class C extends EventTarget{constructor(){super(),E.level=0,E.quality=0,E.ssid="unknown",E.bssid="unknown","undefined"!=typeof document&&document.addEventListener("wifiSignalReport",(e=>{d.log("Got wifiSignalReport",JSON.stringify(e.detail)),E.level=e.detail.level,E.quality=e.detail.quality,E.ssid=e.detail.ssid,E.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 E}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()]),{...$,...N}}}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 J=new D;"undefined"!=typeof window&&(window.alarmManager=J,Object.defineProperty(window,"senzaAlarmManager",{value:J,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,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 M=new Q;let x,X;"undefined"!=typeof window&&(window.messageManager=M,Object.defineProperty(window,"senzaMessageManager",{value:M,writable:!1,configurable:!1})),_.getState()?.then((e=>{X=e})),_.addEventListener("onstatechange",(e=>{X=e.state}));const U=e=>{"background"!==X&&"inTransitionToBackground"!==X||(x&&clearTimeout(x),x=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.`),x=0}),500))};"undefined"!=typeof document&&document.addEventListener("keydown",U),k.addEventListener("error",U),k.addEventListener("ended",U);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 k._init(t?.settings?.["ui-streamer"],i);const o=t?.settings?.["ui-streamer"]?.devSequence;o&&(p({lifecycle:_,remotePlayer:k}),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,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:()=>J,auth:()=>V,deviceManager:()=>A,envInfo:()=>se,getClientAssertion:()=>de,getConnectReason:()=>Z,getDeviceInfo:()=>oe,getPlatformInfo:()=>ee,getTriggerEvent:()=>Y,init:()=>K,initSequence:()=>p,isRunningE2E:()=>ne,lifecycle:()=>_,messageManager:()=>M,platformManager:()=>R,remotePlayer:()=>k,setTimezone:()=>te,showSequence:()=>h,uiReady:()=>ie,writeLicenseResponse:()=>re});var n={};e.r(n),e.d(n,{ClientAssertionError:()=>ae,ConnectReason:()=>W,alarmManager:()=>J,auth:()=>V,deviceManager:()=>A,envInfo:()=>se,getClientAssertion:()=>de,getConnectReason:()=>Z,getDeviceInfo:()=>oe,getPlatformInfo:()=>ee,getTriggerEvent:()=>Y,init:()=>K,initSequence:()=>p,isRunningE2E:()=>ne,lifecycle:()=>_,messageManager:()=>M,platformManager:()=>R,remotePlayer:()=>k,setTimezone:()=>te,showSequence:()=>h,uiReady:()=>ie,writeLicenseResponse:()=>re});const i={version:"4.0.10"},{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 S extends Error{constructor(e,t){super(t),this.code=e,this.msg=t}}function T(){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 S(6500,"Cannot call load() if remote player is not initialized");if(e&&window.cefQuery){const n=await _.getState();if("background"===n||"inTransitionToBackground"===n)throw new S(6002,"Cannot call load() while in state 'background' or 'inTransitionToBackground'");if(this._loadMode===this.LoadMode.LOADING)throw new S(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 S(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 S(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 S(6500,"Cannot call unload() if remote player is not initialized");if(window.cefQuery){if(this._loadMode===this.LoadMode.LOADING)throw new S(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 S(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 S(6e3,`unload reached timeout of ${f} ms`))}),f,u)}))}d.error("remotePlayer unload: window.cefQuery is undefined")}play(){if(!this._isInitialized)throw new S(6500,"Cannot call play() if remote player is not initialized");if(window.cefQuery){if(this._loadMode!==this.LoadMode.LOADED)throw new S(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 S(e,i))}})}))}return d.error("remotePlayer play: window.cefQuery is undefined"),Promise.resolve(void 0)}pause(){if(!this._isInitialized)throw new S(6500,"Cannot call pause() if remote player is not initialized");if(window.cefQuery){if(this._loadMode!==this.LoadMode.LOADED)throw new S(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 S(e,i))}})}))}return d.error("remotePlayer pause: window.cefQuery is undefined"),Promise.resolve(void 0)}getAssetUri(){if(!this._isInitialized)throw new S(6500,"Cannot call getAssetUri() if remote player is not initialized");return this._loadedUrl}getLoadMode(){if(!this._isInitialized)throw new S(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 T()?.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 T()?.assetDuration}get textTrackVisibility(){return this._textTrackVisibility}getPresentationStartTimeAsDate(){return void 0===this._availabilityStartTime?null:new Date(1e3*this._availabilityStartTime)}}const k=new I;"undefined"!=typeof window&&(window.remotePlayer=k,Object.defineProperty(window,"senzaRemotePlayer",{value:k,writable:!1,configurable:!1}));class O extends EventTarget{constructor(){super(),"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.dispatchEvent(t)}))}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=k.getConfiguration(),i=k._selectedAudioTrack||n.preferredAudioLanguage||"",o=k._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 _=new O,E={};let $,N,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");N=JSON.parse(e),F=Date.now()}catch(e){d.error(e)}}class C extends EventTarget{constructor(){super(),E.level=0,E.quality=0,E.ssid="unknown",E.bssid="unknown","undefined"!=typeof document&&document.addEventListener("wifiSignalReport",(e=>{d.log("Got wifiSignalReport",JSON.stringify(e.detail)),E.level=e.detail.level,E.quality=e.detail.quality,E.ssid=e.detail.ssid,E.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 E}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()]),{...$,...N}}}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 J=new D;"undefined"!=typeof window&&(window.alarmManager=J,Object.defineProperty(window,"senzaAlarmManager",{value:J,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,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 M=new Q;let x,U;"undefined"!=typeof window&&(window.messageManager=M,Object.defineProperty(window,"senzaMessageManager",{value:M,writable:!1,configurable:!1})),_.getState()?.then((e=>{U=e})),_.addEventListener("onstatechange",(e=>{U=e.state}));const X=e=>{"background"!==U&&"inTransitionToBackground"!==U||(x&&clearTimeout(x),x=setTimeout((()=>{"background"!==U&&"inTransitionToBackground"!==U||d.log(`${e.type} event received while in '${U}' state and there was no call to lifecycle.moveToForeground() for 500 ms. Make sure to call it if you want to move to foreground.`),x=0}),500))};"undefined"!=typeof document&&document.addEventListener("keydown",X),k.addEventListener("error",X),k.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 k._init(t?.settings?.["ui-streamer"],i);const o=t?.settings?.["ui-streamer"]?.devSequence;o&&(p({lifecycle:_,remotePlayer:k}),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})()));
|
package/package.json
CHANGED
package/src/lifecycle.js
CHANGED
|
@@ -130,6 +130,37 @@ class Lifecycle extends EventTarget {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
/**
|
|
134
|
+
* @experimental
|
|
135
|
+
* moveToUiStandby ui goes into standby: last ui frame displayed, ui resources are released
|
|
136
|
+
* @example
|
|
137
|
+
* lifecycle.moveToUiStandby();
|
|
138
|
+
*/
|
|
139
|
+
moveToUiStandby() {
|
|
140
|
+
if (window.cefQuery) {
|
|
141
|
+
return new Promise((resolve, reject) => {
|
|
142
|
+
const FCID = getFCID();
|
|
143
|
+
const request = { target: "TC", waitForResponse: false, message: JSON.stringify({ type: "uiStandbyRequest", fcid: FCID }) };
|
|
144
|
+
const logger = sdkLogger.withFields({FCID});
|
|
145
|
+
logger.log("lifecycle moveToUiStandby: sending uiStandbyRequest");
|
|
146
|
+
window.cefQuery({
|
|
147
|
+
request: JSON.stringify(request),
|
|
148
|
+
persistent: false,
|
|
149
|
+
onSuccess: () => {
|
|
150
|
+
logger.log("[ moveToUiStandby ] moveToUiStandby successfully sent");
|
|
151
|
+
resolve(true);
|
|
152
|
+
},
|
|
153
|
+
onFailure: (code, msg) => {
|
|
154
|
+
logger.error(`[ moveToUiStandby ] moveToUiStandby failed: ${code} ${msg}`);
|
|
155
|
+
reject(`moveToUiStandby failed: ${code} ${msg}`);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
sdkLogger.warn("moveToUiStandby was called in local dev");
|
|
161
|
+
return Promise.resolve(true);
|
|
162
|
+
}
|
|
163
|
+
|
|
133
164
|
/** Switch Tenant
|
|
134
165
|
* Use this api to switch to another tenant (other than the home tenant) which will launch the application associated with the tenantId. The tenantId must be configured in the
|
|
135
166
|
* Senza platform. Switching to the home tenant should use the exitApplication().
|