senza-sdk 3.22.3 → 3.22.5
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/api.js +0 -6
- package/src/remotePlayer.js +0 -12
- package/src/keyPressIndicator.js +0 -14
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:()=>G,ConnectReason:()=>C,alarmManager:()=>I,auth:()=>A,deviceManager:()=>h,envInfo:()=>M,getClientAssertion:()=>j,getConnectReason:()=>R,getDeviceInfo:()=>U,getPlatformInfo:()=>X,getTriggerEvent:()=>J,init:()=>P,isRunningE2E:()=>Q,lifecycle:()=>c,messageManager:()=>k,platformManager:()=>S,remotePlayer:()=>p,setTimezone:()=>D,uiReady:()=>x,writeLicenseResponse:()=>z});var n={};e.r(n),e.d(n,{ClientAssertionError:()=>G,ConnectReason:()=>C,alarmManager:()=>I,auth:()=>A,deviceManager:()=>h,envInfo:()=>M,getClientAssertion:()=>j,getConnectReason:()=>R,getDeviceInfo:()=>U,getPlatformInfo:()=>X,getTriggerEvent:()=>J,init:()=>P,isRunningE2E:()=>Q,lifecycle:()=>c,messageManager:()=>k,platformManager:()=>S,remotePlayer:()=>p,setTimezone:()=>D,uiReady:()=>x,writeLicenseResponse:()=>z});const i={version:"3.22.3"},{version:s}=i;function o(){return Math.round(1e5*Math.random())+"-"+X().sessionInfo?.connectionId}class r{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 r({...this.logFields,...e})}formatLogString(e){let t="[hs-sdk] "+e.join(" ");return this.logFields&&(t+=" [log-fields] "+JSON.stringify(this.logFields)),t}}const a=new r({sdkVersion:s,url:window?.location?.href??""}),d=new class{sessionInfoStr="{}";get sessionInfoObj(){try{return JSON.parse(this.sessionInfoStr)}catch(e){return void a.warn("Failed to return sdk")}}setSessionInfoStr(e){try{JSON.parse(e)}catch(e){throw Error("Failed to parse sessionInfo")}this.sessionInfoStr=e}};class l extends EventTarget{constructor(){super(),"undefined"!=typeof document&&document.addEventListener("hs/uistatechange",(e=>{a.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&&window.cefQuery({request:"uiState",persistent:!1,onSuccess:t=>{a.log(`uiState request successfully returned '${t}'`),e(t)},onFailure:(e,n)=>{a.error(`uiState request failed: ${e} ${n}`),t(n)}})}));a.warn("lifecycle getState is not supported if NOT running e2e")}moveToForeground(){if(window.cefQuery){const e=o(),t=a.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 a.error("lifecycle moveToForeground: window.cefQuery is undefined")}moveToBackground(){if(window.cefQuery){const e=o(),t=a.withFields({FCID:e});t.log("lifecycle moveToBackground: sending play action"),window.cefQuery({request:JSON.stringify({action:"play",fcid:e}),persistent:!1,onSuccess:()=>{t.log("[ moveToBackground ] play successfully sent")},onFailure:(e,n)=>{t.error(`[ moveToBackground ] play failed: ${e} ${n}`)}})}else a.error("lifecycle moveToBackground: window.cefQuery is undefined")}switchTenant(e){if(e&&e.length>0){if(e===X().sessionInfo?.tenantId)return a.warn(`SwitchTenant requires a different tenantId than the current one. CurrentTenantId=${X().sessionInfo?.tenantId} and tenantId=${e}`),Promise.reject("SwitchTenant requires a different tenantId than the current one");const t=X().sessionInfo?.homeSessionInfo?.tenantInfo?.contentHubTenantId,n=X().sessionInfo?.homeSessionInfo?.tenantId;return a.log(`SwitchTenant for ${e}`),window.cefQuery?new Promise(((i,s)=>{const r=o(),d=a.withFields({FCID:r}),l={type:"reconnect",fcid:r,session:btoa(JSON.stringify({tenantId:e,...X().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:()=>{d.log("SwitchTenant request successfully sent"),i(!0)},onFailure:(e,t)=>{d.error(`SwitchTenant failed: ${e} ${t}`),s(`SwitchTenant failed: ${e} ${t}`)}})})):(a.warn("SwitchTenant is not supported if NOT running e2e"),Promise.reject("SwitchTenant is not supported if NOT running e2e"))}return a.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=o(),i=a.withFields({FCID:n});let s,r;const l=d.sessionInfoObj;l?.homeSessionInfo&&(l?.returnToTenantId||l?.homeSessionInfo.tenantId!==l?.tenantId)?(r={type:"reconnect",splashUrl:l?.homeSessionInfo.tenantInfo.tenantSettings.applicationSwitchSplashUrl,fcid:n},l?.returnToTenantId&&(l?.returnToTenantId===l?.homeSessionInfo.tenantInfo.contentHubTenantId&&(r.splashUrl=l?.homeSessionInfo.contentHubTenantInfo.tenantSettings.applicationSwitchSplashUrl),r.session=btoa(JSON.stringify({tenantId:l?.returnToTenantId}))),s={target:"TC",waitForResponse:!1,message:JSON.stringify(r)}):(r={type:"launchHomeApplication",fcid:n},s={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(r)}),window.cefQuery({request:JSON.stringify(s),persistent:!1,onSuccess:()=>{i.log(`exitApplication request with type: '${r.type}' successfully sent`),e(!0)},onFailure:(e,n)=>{i.error(`exitApplication request with type: '${r.type}' failed: ${e} ${n}`),t(`exitApplication request with type: '${r.type}' failed: ${e} ${n}`)}})})):(a.warn("exitApplication is not supported if NOT running e2e"),Promise.reject("exitApplication is not supported if NOT running e2e"))}}const c=new l,u=e=>JSON.parse(JSON.stringify(e));class f extends Error{constructor(e,t){super(t),this.code=e,this.msg=t}}function g(){const e=window.getPlaybackInfo?window.getPlaybackInfo():JSON.stringify({playbackPosition:0,assetDuration:0});let t;try{t=JSON.parse(e)}catch(n){a.error(`Playback Info parse failed. playbackStr = ${e}`),t={playbackPosition:0,assetDuration:0}}return t}class y 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,this._defaultAutoBackground=!0,"undefined"!=typeof document&&document.addEventListener("hs/playbackInfoEvent",(()=>{a.info("Got hs/playbackInfoEvent"),this.dispatchEvent(new Event("timeupdate"))})),"undefined"!=typeof document&&document.addEventListener("hs/playback",(e=>{a.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("EOS",(()=>{a.info("Got EOS event"),this.dispatchEvent(new Event("ended"))})),"undefined"!=typeof document&&document.addEventListener("hs/EOS",(()=>{a.info("Got hs/EOS event"),this.dispatchEvent(new Event("ended"))})),"undefined"!=typeof document&&document.addEventListener("hs/ui_inactive",(()=>{a.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?(a.info(`Adding ${e.detail} seconds to current time ${this._videoElement.currentTime}`),this._videoElement.playbackRate=1,this._videoElement.currentTime+=e.detail):a.warn("video element is NOT set")})),"undefined"!=typeof document&&document.addEventListener("ERR",(e=>{delete e?.detail?.type,delete e?.detail?.eventCode,a.info("Got ERR event",JSON.stringify(e?.detail)),this.dispatchEvent(new CustomEvent("error",e))})),"undefined"!=typeof document&&document.addEventListener("hs/ERR",(e=>{a.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=>{a.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 s=t.fcid,o=t.sessionId,r=new CustomEvent("license-request",{detail:{licenseRequest:i}});r.writeLicenseResponse=(e,t)=>{z(e,t,s,o)},this.dispatchEvent(r)}))}LoadMode=Object.freeze({NOT_LOADED:"notLoaded",LOADING:"loading",LOADED:"loaded"});async _init(e,t){let n={isLoaded:!1,playbackUrl:""};if(window.cefQuery){const e=o(),t=a.withFields({FCID:e}),i={type:"playerState",fcid:e},s={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(i)};try{const e=await new Promise(((e,n)=>{window.cefQuery({request:JSON.stringify(s),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._requestVideoFrameInfo=e?.requestVideoFrameInfo??!0,this._defaultAutoBackground=e?.playAutoBackground??!0;let i={};try{i=JSON.parse(t?.playbackMetadata||"{}")}catch(e){a.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 u(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=o(),n=a.withFields({fcid:t}),i=(e,n)=>{const s={type:"currentFramePTS",fcid:t,currentFramePTS:n.mediaTime.toString(),ptsSessionId:this._ptsSessionId},o={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(s)};window.cefQuery({request:JSON.stringify(o),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++,a.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 f(6500,"Cannot call load() if remote player is not initialized");if(e&&window.cefQuery){const n=await c.getState();if("background"===n||"inTransitionToBackground"===n)throw new f(6002,"Cannot call load() while in state 'background' or 'inTransitionToBackground'");if(this._loadMode===this.LoadMode.LOADING)throw new f(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,s)=>{this.currentTime=0;const r=o(),d=t??0,l=a.withFields({FCID:r,loadUrl:e,playbackPosition:d});l.log("remotePlayer load: sending setPlayableUri request");const c={type:"setPlayableUri",url:e,timeout:this._setPlayableUriTimeout,autoPlay:!1,playbackPosition:d,fcid:r},u={target:"TC",waitForResponse:!0,message:JSON.stringify(c)};let g=0;const y=Date.now(),p=window.cefQuery({request:JSON.stringify(u),persistent:!1,onSuccess:()=>{const i=Date.now()-y;l.withFields({duration:i}).log(`setPlayableUri completed successfully after ${i} ms`),t>0&&(this.currentTime=t),g&&(clearTimeout(g),g=0),this._changeLoadMode(this.LoadMode.LOADED),this._loadedUrl=e,this.dispatchEvent(new Event("canPlay")),n()},onFailure:(e,t)=>{const n=Date.now()-y;l.withFields({duration:n}).log(`setPlayableUri failed after ${n} ms. Error code: ${e}, error message: ${t}`),g&&(clearTimeout(g),g=0),99===e?this._changeLoadMode(i):(this._changeLoadMode(this.LoadMode.NOT_LOADED),this._loadedUrl=""),s(new f(e,t))}});l.log(`window.cefQuery for setPlayableUri returned query id ${p}`);const w=this._setPlayableUriTimeout+1e3;g=setTimeout((()=>{l.log(`setPlayableUri reached timeout of ${w} ms, canceling query id ${p}`),window.cefQueryCancel(p),this._changeLoadMode(this.LoadMode.NOT_LOADED),this._loadedUrl="",s(new f(6e3,`load reached timeout of ${w} ms`))}),w,p)}))}a.error("remotePlayer load: either window.cefQuery or url is undefined")}unload(){a.warn("unload() api is deprecated since version 3.14.0, no need to call unload() anymore at the end of playback")}play(e){if(!this._isInitialized)throw new f(6500,"Cannot call play() if remote player is not initialized");if(window.cefQuery){if(this._loadMode!==this.LoadMode.LOADED)throw new f(6001,"Cannot call play() if player is not loaded");const t=o(),n=a.withFields({FCID:t});n.log("remotePlayer play: sending play action");const i=this._selectedAudioTrack||this._config.preferredAudioLanguage||"";let s="";if(this._textTrackVisibility&&(s=this._selectedSubtitlesTrack||this._config.preferredSubtitlesLanguage||""),e??this._config.autoBackground??this._defaultAutoBackground)window.cefQuery({request:JSON.stringify({action:"play",fcid:t,audioLanguage:i,subtitlesLanguage:s}),persistent:!1,onSuccess:()=>{n.log("play action was successfully sent")},onFailure:(e,t)=>{n.log(`failed to send play action: ${e} ${t}`)}});else{const e={type:"remotePlayer.play",class:"remotePlayer",action:"play",fcid:t,audioLanguage:i,subtitlesLanguage:s,playbackPosition:this.currentTime},o={target:"TC",waitForResponse:!1,message:JSON.stringify(e)};window.cefQuery({request:JSON.stringify(o),persistent:!1,onSuccess:()=>{n.log("remotePlayer play request successfully sent")},onFailure:(e,t)=>{n.error(`remotePlayer play request failed: ${e} ${t}`)}})}}else a.error("remotePlayer play: window.cefQuery is undefined")}pause(){if(!this._isInitialized)throw new f(6500,"Cannot call pause() if remote player is not initialized");if(window.cefQuery){if(this._loadMode!==this.LoadMode.LOADED)throw new f(6001,"Cannot call pause() if player is not loaded");const e=o(),t=a.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)};window.cefQuery({request:JSON.stringify(i),persistent:!1,onSuccess:()=>{t.log("remotePlayer pause request successfully sent")},onFailure:(e,n)=>{t.error(`remotePlayer pause request failed: ${e} ${n}`)}})}else a.error("remotePlayer pause: window.cefQuery is undefined")}getAssetUri(){if(!this._isInitialized)throw new f(6500,"Cannot call getAssetUri() if remote player is not initialized");return this._loadedUrl}getLoadMode(){if(!this._isInitialized)throw new f(6500,"Cannot call getLoadMode() if remote player is not initialized");return this._loadMode}getTextTracks(){return u(this._availableTextTracks)}getAudioTracks(){return u(this._availableAudioTracks)}selectAudioTrack(e){for(const t of this.getAudioTracks())if(t.id===e)return void(this._selectedAudioTrack=e);a.warn(`Invalid audioTrackId ${e}`)}selectTextTrack(e){for(const t of this.getTextTracks())if(t.id===e)return void(this._selectedSubtitlesTrack=e);a.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 g()?.playbackPosition}set currentTime(e){!function(e){try{const t=JSON.stringify(e);window.setPlaybackInfo&&window.setPlaybackInfo(t)}catch(e){a.error("Playback Info to json string failed")}}({playbackPosition:e})}get duration(){return g()?.assetDuration}get textTrackVisibility(){return this._textTrackVisibility}getPresentationStartTimeAsDate(){return void 0===this._availabilityStartTime?null:new Date(1e3*this._availabilityStartTime)}}const p=new y;"undefined"!=typeof window&&(window.remotePlayer=p);const w={};class m extends EventTarget{constructor(){super(),w.level=0,w.quality=0,w.ssid="unknown",w.bssid="unknown","undefined"!=typeof document&&document.addEventListener("wifiSignalReport",(e=>{a.log("Got wifiSignalReport",JSON.stringify(e.detail)),w.level=e.detail.level,w.quality=e.detail.quality,w.ssid=e.detail.ssid,w.bssid=e.detail.bssid,this.dispatchEvent(new Event("wifiInfoUpdated"))}))}get deviceInfo(){const e=d.sessionInfoObj;return Q()&&e?{deviceId:e.deviceId,connectionId:e.connectionId,community:e.community,tenant:e.tenant,clientIp:e.clientIp,countryCode:e.general?.location?.["x-country-code"]}:(a.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 w}reboot(){return new Promise(((e,t)=>{if(window.cefQuery){const n=o(),i=a.withFields({FCID:n}),s={type:"reboot",fcid:n},r={target:"TC",waitForResponse:!1,message:JSON.stringify(s)};window.cefQuery({request:JSON.stringify(r),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 a.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=o(),i=a.withFields({FCID:n}),s={type:"resetWifi",fcid:n},r={target:"TC",waitForResponse:!1,message:JSON.stringify(s)};window.cefQuery({request:JSON.stringify(r),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=o(),s=a.withFields({FCID:i}),r={type:"externalCommand",data:{command:"forward",payload:e},fcid:i},d={target:"TC",waitForResponse:!1,message:JSON.stringify(r)};window.cefQuery({request:JSON.stringify(d),persistent:!1,onSuccess:()=>{s.log("externalCommand successfully sent"),t()},onFailure:(e,t)=>{s.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=o(),s=a.withFields({FCID:i}),r={type:"factoryReset",fcid:i,reboot:e},d={target:"TC",waitForResponse:!0,message:JSON.stringify(r)};let l=0;const c=window.cefQuery({request:JSON.stringify(d),persistent:!1,onSuccess:()=>{l&&clearTimeout(l),s.log("factoryReset successfully sent"),t(!0)},onFailure:(e,t)=>{l&&clearTimeout(l),s.error(`factoryReset failed: ${e} ${t}`),n(`factoryReset failed: ${e} ${t}`)}});l=setTimeout((()=>{s.error("factoryReset failed: reached timeout of 5000 ms"),window.cefQueryCancel(c),n("factoryReset failed: reached timeout of 5000 ms")}),5e3)}))}}const h=new m;class v extends EventTarget{constructor(){super()}get appConfig(){const e=d.sessionInfoObj,t=e.homeSessionInfo?.appConfig||{};return a.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:()=>{a.log("PlatformManager timezome is successfully set to",e)},onFailure:(t,n)=>{a.error(`PlatformManager error occurred setting timezone to ${e}: ${t} ${n}`)}})}}}const S=new v;class T extends EventTarget{constructor(){super(),"undefined"!=typeof document&&document.addEventListener("hs/alarmFiredEvent",(e=>{a.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=o(),s=a.withFields({alarmName:e,FCID:i});if(s.log(`addAlarm called for ${e} to be fired at ${t}`),window.cefQuery){const o={type:"addAlarm",fcid:i,alarmName:e,alarmTime:t,payload:n},r={target:"TC",waitForResponse:!1,message:JSON.stringify(o)};window.cefQuery({request:JSON.stringify(r),persistent:!1,onSuccess:()=>{s.log("addAlarm request successfully sent")},onFailure:(e,t)=>{s.error(`addAlarm failed: ${e} ${t}`)}})}else s.warn("addAlarm is not supported if NOT running e2e")}deleteAlarm(e){const t=o(),n=a.withFields({alarmName:e,FCID:t});if(n.log(`deleteAlarm called for ${e}`),window.cefQuery){const i={type:"deleteAlarm",fcid:t,alarmName:e},s={target:"TC",waitForResponse:!1,message:JSON.stringify(i)};window.cefQuery({request:JSON.stringify(s),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=o(),t=a.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 a.warn("deleteAllAlarms is not supported if NOT running e2e")}getActiveAlarms(){throw Error("NOT IMPLEMENTED")}}const I=new T;"undefined"!=typeof window&&(window.alarmManager=I);class b extends EventTarget{constructor(){super(),"undefined"!=typeof document&&document.addEventListener("hs/externalEvent",(e=>{a.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 a.log(`register called for ${e}`),new Promise(((t,n)=>{if(window.cefQuery){const i=o(),s=a.withFields({FCID:i}),r={type:"registerGroupEvent",fcid:i,groups:e},d={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(r)};window.cefQuery({request:JSON.stringify(d),persistent:!1,onSuccess:()=>{s.log("registerGroupEvent request successfully sent"),t(!0)},onFailure:(e,t)=>{s.error(`registerGroupEvent failed: ${e} ${t}`),n(`registerGroupEvent failed: ${e} ${t}`)}})}else a.warn("registerGroupEvent is not supported if NOT running e2e"),n("registerGroupEvent is not supported if NOT running e2e")}))}}const k=new b;let E,_;"undefined"!=typeof window&&(window.messageManager=k),c.getState()?.then((e=>{_=e})),c.addEventListener("onstatechange",(e=>{_=e.state}));const O=e=>{"background"!==_&&"inTransitionToBackground"!==_||(E&&clearTimeout(E),E=setTimeout((()=>{"background"!==_&&"inTransitionToBackground"!==_||a.log(`${e.type} event received while in '${_}' state and there was no call to lifecycle.moveToForeground() for 500 ms. Make sure to call it if you want to move to foreground.`),E=0}),500))};"undefined"!=typeof document&&document.addEventListener("keydown",O),p.addEventListener("error",O),p.addEventListener("ended",O);const{version:N}=i;let F;const $="1.0";"undefined"!=typeof document&&document.addEventListener("keydown",(e=>{a.log(`Got ${e.key} key`)}));const A={getToken:async function(){return F?Promise.resolve(F):(a.log("getToken wait for promise updateSession event"),new Promise((e=>{document.addEventListener("updateSession",(t=>{F=t.detail?.updateObj,a.log(`onUpdateSessionEvent: token= ${F}`),e(F)}),{once:!0})})))},forceTokenUpdate:function(){if(F=null,window.cefQuery){const e=o(),t=a.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 a.error("forceTokenUpdate: window.cefQuery is undefined")},getClientAssertion:j},C=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 q=C.UNKNOWN,L={};async function P(){if(a.log(`init ${N}`),window.diagnostics||a.error("[ init ] window.diagnostics is undefined"),window.cefQuery){await new Promise(((e,t)=>{window.cefQuery({request:"apiVersion "+$,persistent:!1,onSuccess:()=>{a.log("api version compatability check succeeded"),e()},onFailure:(e,n)=>{a.error("api version compatability check failed: "+n),t(n)}})}));const e=await new Promise((e=>{window.cefQuery({request:"sessionInfo",persistent:!1,onSuccess:t=>{a.log("sessionInfo request successfully returned "+t),e(t)},onFailure:(e,t)=>{a.error(`sessionInfo request failed: ${e} ${t}`)}})}));d.setSessionInfoStr(e);const t=JSON.parse(e);F=t?.settings?.webUI?.backendHeaders?.Authorization,a.log(`authToken: token = ${F}`),document.addEventListener("updateSession",(e=>{F=e.detail?.updateObj,a.log(`onUpdateSessionEvent: token = ${F}`)})),t?.settings?.["ui-streamer"]?.enableKeyPressDuration&&function(){const e=document.createElement("div");e.setAttribute("style","height: 8px; width: 8px; background-color: red; position: absolute; left: 0px; top: 0px; z-index: 9999;"),document.body.appendChild(e),document.addEventListener("keydown",(()=>{"red"===e.style.backgroundColor?e.style.backgroundColor="blue":"blue"===e.style.backgroundColor?e.style.backgroundColor="green":e.style.backgroundColor="red"}))}(),q=await new Promise((e=>{const t=o(),n=a.withFields({FCID:t}),i={type:"connectReason",fcid:t},s={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(i)};window.cefQuery({request:JSON.stringify(s),persistent:!1,onSuccess:t=>{n.log(`connectReason request successfully returned '${t}'`),e(t)},onFailure:(t,i)=>{n.error(`connectReason request failed: ${t} ${i}`),e(C.UNKNOWN)}})}));const n=await new Promise((e=>{const t=o(),n=a.withFields({FCID:t}),i={type:"triggerEvent",fcid:t},s={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(i)};window.cefQuery({request:JSON.stringify(s),persistent:!1,onSuccess:t=>{n.log(`triggerEvent request successfully returned '${t}'`),e(t)},onFailure:(t,i)=>{n.error(`triggerEvent request failed: ${t} ${i}`),e("")}})}));L={};let i={};if(n)try{i=JSON.parse(n),L.type=i.type,"keyPressEvent"===L.type?L.data={keyValue:i.keyValue}:"alarmFiredEvent"===L.type?L.data={alarmName:i.alarmName,payload:i.payload}:"userAlertEvent"===L.type?L.data={eventCode:i.eventCode,message:i.message}:"externalEvent"===L.type?L.data={eventName:i.eventName,payload:i.payload}:"videoPlaybackEvent"===L.type?L.data={eventCode:i.eventCode,errorCode:i.errorCode}:a.warn("unknown trigger event type",L.type)}catch(e){a.error(`failed to parse trigger event string ${n}: ${e.message}`)}await p._init(t?.settings?.["ui-streamer"],i)}else F=X().sessionInfo?.settings?.webUI?.backendHeaders?.Authorization,a.log(`authToken dummy: token = ${F}`);window.auth=A,window.close=()=>{a.warn("window.close is disabled on Senza platform. Use lifecycle.exitApplication() instead.")}}function R(){return q}function J(){return L}function X(){if("undefined"==typeof window||!window.diagnostics)return"undefined"==typeof window||window.diagnostics||a.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=d.sessionInfoObj,e}catch(e){a.error("Could not get platform info",e.stack)}}function D(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:()=>{a.log("timezome is successfully set to",e)},onFailure:(t,n)=>{a.error(`error occurred setting timezone to ${e}: ${t} ${n}`)}})}}function Q(){return!("undefined"==typeof window||!window.cefQuery)}function x(){window.cefQuery?window.cefQuery({request:"uiReady",persistent:!1,onSuccess:()=>{a.log("uiReady request successfully sent")},onFailure:(e,t)=>{a.error(`uiReady request failed: ${e} ${t}`)}}):a.error("uiReady: window.cefQuery is undefined")}function U(){const e=d.sessionInfoObj;return Q()?{deviceId:e.deviceId,connectionId:e.connectionId,community:e.community,tenant:e.tenant,clientIp:e.clientIp}:(a.log("getDeviceInfo running locally, returning dummy info"),{deviceId:"123456789",connectionId:"dummy",community:"LocalDev",tenant:"XXXXXX",clientIp:"0.0.0.0"})}const M={remoteBrowserIp:window.diagnostics?window.diagnostics().podIP:"127.0.0.1",sdkVersion:N};function z(e,t,n,i){if(200===e&&(t=window.btoa(String.fromCharCode.apply(null,new Uint8Array(t)))),window.cefQuery){const s={type:"updateLicense",sessionId:i,fcid:n};s[200===e?"response":"error"]=t;const o={target:"TC",waitForResponse:!1,message:JSON.stringify(s)};window.cefQuery({request:JSON.stringify(o),persistent:!1,onSuccess:()=>{a.log("updateLicense request successfully sent")},onFailure:(e,t)=>{a.error(`updateLicense request failed: ${e} ${t}`)}})}}class G extends Error{constructor(e,t){super(t),this.code=e}}function j(){if(window.cefQuery)return a.log("getClientAssertion is called"),new Promise(((e,t)=>{window.cefQuery({request:"client_assertion",persistent:!1,onSuccess:n=>{try{const t=JSON.parse(n);a.log(`client_assertion request successfully returned ${n}`),e(t)}catch(e){a.error(`Failed to parse client assertion ${n}`),t(new G(0,"Failed to parse client assertion"))}},onFailure:(e,n)=>{a.log(`client_assertion request failed: ${e} ${n}`),t(new G(e,n))}})}));a.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:()=>j,ConnectReason:()=>C,alarmManager:()=>I,auth:()=>A,deviceManager:()=>h,envInfo:()=>x,getClientAssertion:()=>G,getConnectReason:()=>R,getDeviceInfo:()=>M,getPlatformInfo:()=>X,getTriggerEvent:()=>J,init:()=>L,isRunningE2E:()=>D,lifecycle:()=>c,messageManager:()=>k,platformManager:()=>T,remotePlayer:()=>p,setTimezone:()=>Q,uiReady:()=>U,writeLicenseResponse:()=>z});var n={};e.r(n),e.d(n,{ClientAssertionError:()=>j,ConnectReason:()=>C,alarmManager:()=>I,auth:()=>A,deviceManager:()=>h,envInfo:()=>x,getClientAssertion:()=>G,getConnectReason:()=>R,getDeviceInfo:()=>M,getPlatformInfo:()=>X,getTriggerEvent:()=>J,init:()=>L,isRunningE2E:()=>D,lifecycle:()=>c,messageManager:()=>k,platformManager:()=>T,remotePlayer:()=>p,setTimezone:()=>Q,uiReady:()=>U,writeLicenseResponse:()=>z});const i={version:"3.22.5"},{version:s}=i;function o(){return Math.round(1e5*Math.random())+"-"+X().sessionInfo?.connectionId}class r{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 r({...this.logFields,...e})}formatLogString(e){let t="[hs-sdk] "+e.join(" ");return this.logFields&&(t+=" [log-fields] "+JSON.stringify(this.logFields)),t}}const a=new r({sdkVersion:s,url:window?.location?.href??""}),d=new class{sessionInfoStr="{}";get sessionInfoObj(){try{return JSON.parse(this.sessionInfoStr)}catch(e){return void a.warn("Failed to return sdk")}}setSessionInfoStr(e){try{JSON.parse(e)}catch(e){throw Error("Failed to parse sessionInfo")}this.sessionInfoStr=e}};class l extends EventTarget{constructor(){super(),"undefined"!=typeof document&&document.addEventListener("hs/uistatechange",(e=>{a.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&&window.cefQuery({request:"uiState",persistent:!1,onSuccess:t=>{a.log(`uiState request successfully returned '${t}'`),e(t)},onFailure:(e,n)=>{a.error(`uiState request failed: ${e} ${n}`),t(n)}})}));a.warn("lifecycle getState is not supported if NOT running e2e")}moveToForeground(){if(window.cefQuery){const e=o(),t=a.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 a.error("lifecycle moveToForeground: window.cefQuery is undefined")}moveToBackground(){if(window.cefQuery){const e=o(),t=a.withFields({FCID:e});t.log("lifecycle moveToBackground: sending play action"),window.cefQuery({request:JSON.stringify({action:"play",fcid:e}),persistent:!1,onSuccess:()=>{t.log("[ moveToBackground ] play successfully sent")},onFailure:(e,n)=>{t.error(`[ moveToBackground ] play failed: ${e} ${n}`)}})}else a.error("lifecycle moveToBackground: window.cefQuery is undefined")}switchTenant(e){if(e&&e.length>0){if(e===X().sessionInfo?.tenantId)return a.warn(`SwitchTenant requires a different tenantId than the current one. CurrentTenantId=${X().sessionInfo?.tenantId} and tenantId=${e}`),Promise.reject("SwitchTenant requires a different tenantId than the current one");const t=X().sessionInfo?.homeSessionInfo?.tenantInfo?.contentHubTenantId,n=X().sessionInfo?.homeSessionInfo?.tenantId;return a.log(`SwitchTenant for ${e}`),window.cefQuery?new Promise(((i,s)=>{const r=o(),d=a.withFields({FCID:r}),l={type:"reconnect",fcid:r,session:btoa(JSON.stringify({tenantId:e,...X().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:()=>{d.log("SwitchTenant request successfully sent"),i(!0)},onFailure:(e,t)=>{d.error(`SwitchTenant failed: ${e} ${t}`),s(`SwitchTenant failed: ${e} ${t}`)}})})):(a.warn("SwitchTenant is not supported if NOT running e2e"),Promise.reject("SwitchTenant is not supported if NOT running e2e"))}return a.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=o(),i=a.withFields({FCID:n});let s,r;const l=d.sessionInfoObj;l?.homeSessionInfo&&(l?.returnToTenantId||l?.homeSessionInfo.tenantId!==l?.tenantId)?(r={type:"reconnect",splashUrl:l?.homeSessionInfo.tenantInfo.tenantSettings.applicationSwitchSplashUrl,fcid:n},l?.returnToTenantId&&(l?.returnToTenantId===l?.homeSessionInfo.tenantInfo.contentHubTenantId&&(r.splashUrl=l?.homeSessionInfo.contentHubTenantInfo.tenantSettings.applicationSwitchSplashUrl),r.session=btoa(JSON.stringify({tenantId:l?.returnToTenantId}))),s={target:"TC",waitForResponse:!1,message:JSON.stringify(r)}):(r={type:"launchHomeApplication",fcid:n},s={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(r)}),window.cefQuery({request:JSON.stringify(s),persistent:!1,onSuccess:()=>{i.log(`exitApplication request with type: '${r.type}' successfully sent`),e(!0)},onFailure:(e,n)=>{i.error(`exitApplication request with type: '${r.type}' failed: ${e} ${n}`),t(`exitApplication request with type: '${r.type}' failed: ${e} ${n}`)}})})):(a.warn("exitApplication is not supported if NOT running e2e"),Promise.reject("exitApplication is not supported if NOT running e2e"))}}const c=new l,u=e=>JSON.parse(JSON.stringify(e));class f extends Error{constructor(e,t){super(t),this.code=e,this.msg=t}}function g(){const e=window.getPlaybackInfo?window.getPlaybackInfo():JSON.stringify({playbackPosition:0,assetDuration:0});let t;try{t=JSON.parse(e)}catch(n){a.error(`Playback Info parse failed. playbackStr = ${e}`),t={playbackPosition:0,assetDuration:0}}return t}class y 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,this._defaultAutoBackground=!0,"undefined"!=typeof document&&document.addEventListener("hs/playbackInfoEvent",(()=>{a.info("Got hs/playbackInfoEvent"),this.dispatchEvent(new Event("timeupdate"))})),"undefined"!=typeof document&&document.addEventListener("hs/playback",(e=>{a.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",(()=>{a.info("Got hs/EOS event"),this.dispatchEvent(new Event("ended"))})),"undefined"!=typeof document&&document.addEventListener("hs/ui_inactive",(()=>{a.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?(a.info(`Adding ${e.detail} seconds to current time ${this._videoElement.currentTime}`),this._videoElement.playbackRate=1,this._videoElement.currentTime+=e.detail):a.warn("video element is NOT set")})),"undefined"!=typeof document&&document.addEventListener("hs/ERR",(e=>{a.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=>{a.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 s=t.fcid,o=t.sessionId,r=new CustomEvent("license-request",{detail:{licenseRequest:i}});r.writeLicenseResponse=(e,t)=>{z(e,t,s,o)},this.dispatchEvent(r)}))}LoadMode=Object.freeze({NOT_LOADED:"notLoaded",LOADING:"loading",LOADED:"loaded"});async _init(e,t){let n={isLoaded:!1,playbackUrl:""};if(window.cefQuery){const e=o(),t=a.withFields({FCID:e}),i={type:"playerState",fcid:e},s={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(i)};try{const e=await new Promise(((e,n)=>{window.cefQuery({request:JSON.stringify(s),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._requestVideoFrameInfo=e?.requestVideoFrameInfo??!0,this._defaultAutoBackground=e?.playAutoBackground??!0;let i={};try{i=JSON.parse(t?.playbackMetadata||"{}")}catch(e){a.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 u(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=o(),n=a.withFields({fcid:t}),i=(e,n)=>{const s={type:"currentFramePTS",fcid:t,currentFramePTS:n.mediaTime.toString(),ptsSessionId:this._ptsSessionId},o={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(s)};window.cefQuery({request:JSON.stringify(o),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++,a.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 f(6500,"Cannot call load() if remote player is not initialized");if(e&&window.cefQuery){const n=await c.getState();if("background"===n||"inTransitionToBackground"===n)throw new f(6002,"Cannot call load() while in state 'background' or 'inTransitionToBackground'");if(this._loadMode===this.LoadMode.LOADING)throw new f(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,s)=>{this.currentTime=0;const r=o(),d=t??0,l=a.withFields({FCID:r,loadUrl:e,playbackPosition:d});l.log("remotePlayer load: sending setPlayableUri request");const c={type:"setPlayableUri",url:e,timeout:this._setPlayableUriTimeout,autoPlay:!1,playbackPosition:d,fcid:r},u={target:"TC",waitForResponse:!0,message:JSON.stringify(c)};let g=0;const y=Date.now(),p=window.cefQuery({request:JSON.stringify(u),persistent:!1,onSuccess:()=>{const i=Date.now()-y;l.withFields({duration:i}).log(`setPlayableUri completed successfully after ${i} ms`),t>0&&(this.currentTime=t),g&&(clearTimeout(g),g=0),this._changeLoadMode(this.LoadMode.LOADED),this._loadedUrl=e,this.dispatchEvent(new Event("canPlay")),n()},onFailure:(e,t)=>{const n=Date.now()-y;l.withFields({duration:n}).log(`setPlayableUri failed after ${n} ms. Error code: ${e}, error message: ${t}`),g&&(clearTimeout(g),g=0),99===e?this._changeLoadMode(i):(this._changeLoadMode(this.LoadMode.NOT_LOADED),this._loadedUrl=""),s(new f(e,t))}});l.log(`window.cefQuery for setPlayableUri returned query id ${p}`);const w=this._setPlayableUriTimeout+1e3;g=setTimeout((()=>{l.log(`setPlayableUri reached timeout of ${w} ms, canceling query id ${p}`),window.cefQueryCancel(p),this._changeLoadMode(this.LoadMode.NOT_LOADED),this._loadedUrl="",s(new f(6e3,`load reached timeout of ${w} ms`))}),w,p)}))}a.error("remotePlayer load: either window.cefQuery or url is undefined")}unload(){a.warn("unload() api is deprecated since version 3.14.0, no need to call unload() anymore at the end of playback")}play(e){if(!this._isInitialized)throw new f(6500,"Cannot call play() if remote player is not initialized");if(window.cefQuery){if(this._loadMode!==this.LoadMode.LOADED)throw new f(6001,"Cannot call play() if player is not loaded");const t=o(),n=a.withFields({FCID:t});n.log("remotePlayer play: sending play action");const i=this._selectedAudioTrack||this._config.preferredAudioLanguage||"";let s="";if(this._textTrackVisibility&&(s=this._selectedSubtitlesTrack||this._config.preferredSubtitlesLanguage||""),e??this._config.autoBackground??this._defaultAutoBackground)window.cefQuery({request:JSON.stringify({action:"play",fcid:t,audioLanguage:i,subtitlesLanguage:s}),persistent:!1,onSuccess:()=>{n.log("play action was successfully sent")},onFailure:(e,t)=>{n.log(`failed to send play action: ${e} ${t}`)}});else{const e={type:"remotePlayer.play",class:"remotePlayer",action:"play",fcid:t,audioLanguage:i,subtitlesLanguage:s,playbackPosition:this.currentTime},o={target:"TC",waitForResponse:!1,message:JSON.stringify(e)};window.cefQuery({request:JSON.stringify(o),persistent:!1,onSuccess:()=>{n.log("remotePlayer play request successfully sent")},onFailure:(e,t)=>{n.error(`remotePlayer play request failed: ${e} ${t}`)}})}}else a.error("remotePlayer play: window.cefQuery is undefined")}pause(){if(!this._isInitialized)throw new f(6500,"Cannot call pause() if remote player is not initialized");if(window.cefQuery){if(this._loadMode!==this.LoadMode.LOADED)throw new f(6001,"Cannot call pause() if player is not loaded");const e=o(),t=a.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)};window.cefQuery({request:JSON.stringify(i),persistent:!1,onSuccess:()=>{t.log("remotePlayer pause request successfully sent")},onFailure:(e,n)=>{t.error(`remotePlayer pause request failed: ${e} ${n}`)}})}else a.error("remotePlayer pause: window.cefQuery is undefined")}getAssetUri(){if(!this._isInitialized)throw new f(6500,"Cannot call getAssetUri() if remote player is not initialized");return this._loadedUrl}getLoadMode(){if(!this._isInitialized)throw new f(6500,"Cannot call getLoadMode() if remote player is not initialized");return this._loadMode}getTextTracks(){return u(this._availableTextTracks)}getAudioTracks(){return u(this._availableAudioTracks)}selectAudioTrack(e){for(const t of this.getAudioTracks())if(t.id===e)return void(this._selectedAudioTrack=e);a.warn(`Invalid audioTrackId ${e}`)}selectTextTrack(e){for(const t of this.getTextTracks())if(t.id===e)return void(this._selectedSubtitlesTrack=e);a.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 g()?.playbackPosition}set currentTime(e){!function(e){try{const t=JSON.stringify(e);window.setPlaybackInfo&&window.setPlaybackInfo(t)}catch(e){a.error("Playback Info to json string failed")}}({playbackPosition:e})}get duration(){return g()?.assetDuration}get textTrackVisibility(){return this._textTrackVisibility}getPresentationStartTimeAsDate(){return void 0===this._availabilityStartTime?null:new Date(1e3*this._availabilityStartTime)}}const p=new y;"undefined"!=typeof window&&(window.remotePlayer=p);const w={};class m extends EventTarget{constructor(){super(),w.level=0,w.quality=0,w.ssid="unknown",w.bssid="unknown","undefined"!=typeof document&&document.addEventListener("wifiSignalReport",(e=>{a.log("Got wifiSignalReport",JSON.stringify(e.detail)),w.level=e.detail.level,w.quality=e.detail.quality,w.ssid=e.detail.ssid,w.bssid=e.detail.bssid,this.dispatchEvent(new Event("wifiInfoUpdated"))}))}get deviceInfo(){const e=d.sessionInfoObj;return D()&&e?{deviceId:e.deviceId,connectionId:e.connectionId,community:e.community,tenant:e.tenant,clientIp:e.clientIp,countryCode:e.general?.location?.["x-country-code"]}:(a.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 w}reboot(){return new Promise(((e,t)=>{if(window.cefQuery){const n=o(),i=a.withFields({FCID:n}),s={type:"reboot",fcid:n},r={target:"TC",waitForResponse:!1,message:JSON.stringify(s)};window.cefQuery({request:JSON.stringify(r),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 a.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=o(),i=a.withFields({FCID:n}),s={type:"resetWifi",fcid:n},r={target:"TC",waitForResponse:!1,message:JSON.stringify(s)};window.cefQuery({request:JSON.stringify(r),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=o(),s=a.withFields({FCID:i}),r={type:"externalCommand",data:{command:"forward",payload:e},fcid:i},d={target:"TC",waitForResponse:!1,message:JSON.stringify(r)};window.cefQuery({request:JSON.stringify(d),persistent:!1,onSuccess:()=>{s.log("externalCommand successfully sent"),t()},onFailure:(e,t)=>{s.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=o(),s=a.withFields({FCID:i}),r={type:"factoryReset",fcid:i,reboot:e},d={target:"TC",waitForResponse:!0,message:JSON.stringify(r)};let l=0;const c=window.cefQuery({request:JSON.stringify(d),persistent:!1,onSuccess:()=>{l&&clearTimeout(l),s.log("factoryReset successfully sent"),t(!0)},onFailure:(e,t)=>{l&&clearTimeout(l),s.error(`factoryReset failed: ${e} ${t}`),n(`factoryReset failed: ${e} ${t}`)}});l=setTimeout((()=>{s.error("factoryReset failed: reached timeout of 5000 ms"),window.cefQueryCancel(c),n("factoryReset failed: reached timeout of 5000 ms")}),5e3)}))}}const h=new m;class v extends EventTarget{constructor(){super()}get appConfig(){const e=d.sessionInfoObj,t=e.homeSessionInfo?.appConfig||{};return a.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:()=>{a.log("PlatformManager timezome is successfully set to",e)},onFailure:(t,n)=>{a.error(`PlatformManager error occurred setting timezone to ${e}: ${t} ${n}`)}})}}}const T=new v;class S extends EventTarget{constructor(){super(),"undefined"!=typeof document&&document.addEventListener("hs/alarmFiredEvent",(e=>{a.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=o(),s=a.withFields({alarmName:e,FCID:i});if(s.log(`addAlarm called for ${e} to be fired at ${t}`),window.cefQuery){const o={type:"addAlarm",fcid:i,alarmName:e,alarmTime:t,payload:n},r={target:"TC",waitForResponse:!1,message:JSON.stringify(o)};window.cefQuery({request:JSON.stringify(r),persistent:!1,onSuccess:()=>{s.log("addAlarm request successfully sent")},onFailure:(e,t)=>{s.error(`addAlarm failed: ${e} ${t}`)}})}else s.warn("addAlarm is not supported if NOT running e2e")}deleteAlarm(e){const t=o(),n=a.withFields({alarmName:e,FCID:t});if(n.log(`deleteAlarm called for ${e}`),window.cefQuery){const i={type:"deleteAlarm",fcid:t,alarmName:e},s={target:"TC",waitForResponse:!1,message:JSON.stringify(i)};window.cefQuery({request:JSON.stringify(s),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=o(),t=a.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 a.warn("deleteAllAlarms is not supported if NOT running e2e")}getActiveAlarms(){throw Error("NOT IMPLEMENTED")}}const I=new S;"undefined"!=typeof window&&(window.alarmManager=I);class b extends EventTarget{constructor(){super(),"undefined"!=typeof document&&document.addEventListener("hs/externalEvent",(e=>{a.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 a.log(`register called for ${e}`),new Promise(((t,n)=>{if(window.cefQuery){const i=o(),s=a.withFields({FCID:i}),r={type:"registerGroupEvent",fcid:i,groups:e},d={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(r)};window.cefQuery({request:JSON.stringify(d),persistent:!1,onSuccess:()=>{s.log("registerGroupEvent request successfully sent"),t(!0)},onFailure:(e,t)=>{s.error(`registerGroupEvent failed: ${e} ${t}`),n(`registerGroupEvent failed: ${e} ${t}`)}})}else a.warn("registerGroupEvent is not supported if NOT running e2e"),n("registerGroupEvent is not supported if NOT running e2e")}))}}const k=new b;let _,E;"undefined"!=typeof window&&(window.messageManager=k),c.getState()?.then((e=>{E=e})),c.addEventListener("onstatechange",(e=>{E=e.state}));const O=e=>{"background"!==E&&"inTransitionToBackground"!==E||(_&&clearTimeout(_),_=setTimeout((()=>{"background"!==E&&"inTransitionToBackground"!==E||a.log(`${e.type} event received while in '${E}' state and there was no call to lifecycle.moveToForeground() for 500 ms. Make sure to call it if you want to move to foreground.`),_=0}),500))};"undefined"!=typeof document&&document.addEventListener("keydown",O),p.addEventListener("error",O),p.addEventListener("ended",O);const{version:N}=i;let F;const $="1.0";"undefined"!=typeof document&&document.addEventListener("keydown",(e=>{a.log(`Got ${e.key} key`)}));const A={getToken:async function(){return F?Promise.resolve(F):(a.log("getToken wait for promise updateSession event"),new Promise((e=>{document.addEventListener("updateSession",(t=>{F=t.detail?.updateObj,a.log(`onUpdateSessionEvent: token= ${F}`),e(F)}),{once:!0})})))},forceTokenUpdate:function(){if(F=null,window.cefQuery){const e=o(),t=a.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 a.error("forceTokenUpdate: window.cefQuery is undefined")},getClientAssertion:G},C=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 q=C.UNKNOWN,P={};async function L(){if(a.log(`init ${N}`),window.diagnostics||a.error("[ init ] window.diagnostics is undefined"),window.cefQuery){await new Promise(((e,t)=>{window.cefQuery({request:"apiVersion "+$,persistent:!1,onSuccess:()=>{a.log("api version compatability check succeeded"),e()},onFailure:(e,n)=>{a.error("api version compatability check failed: "+n),t(n)}})}));const e=await new Promise((e=>{window.cefQuery({request:"sessionInfo",persistent:!1,onSuccess:t=>{a.log("sessionInfo request successfully returned "+t),e(t)},onFailure:(e,t)=>{a.error(`sessionInfo request failed: ${e} ${t}`)}})}));d.setSessionInfoStr(e);const t=JSON.parse(e);F=t?.settings?.webUI?.backendHeaders?.Authorization,a.log(`authToken: token = ${F}`),document.addEventListener("updateSession",(e=>{F=e.detail?.updateObj,a.log(`onUpdateSessionEvent: token = ${F}`)})),q=await new Promise((e=>{const t=o(),n=a.withFields({FCID:t}),i={type:"connectReason",fcid:t},s={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(i)};window.cefQuery({request:JSON.stringify(s),persistent:!1,onSuccess:t=>{n.log(`connectReason request successfully returned '${t}'`),e(t)},onFailure:(t,i)=>{n.error(`connectReason request failed: ${t} ${i}`),e(C.UNKNOWN)}})}));const n=await new Promise((e=>{const t=o(),n=a.withFields({FCID:t}),i={type:"triggerEvent",fcid:t},s={target:"UI-Streamer",waitForResponse:!1,message:JSON.stringify(i)};window.cefQuery({request:JSON.stringify(s),persistent:!1,onSuccess:t=>{n.log(`triggerEvent request successfully returned '${t}'`),e(t)},onFailure:(t,i)=>{n.error(`triggerEvent request failed: ${t} ${i}`),e("")}})}));P={};let i={};if(n)try{i=JSON.parse(n),P.type=i.type,"keyPressEvent"===P.type?P.data={keyValue:i.keyValue}:"alarmFiredEvent"===P.type?P.data={alarmName:i.alarmName,payload:i.payload}:"userAlertEvent"===P.type?P.data={eventCode:i.eventCode,message:i.message}:"externalEvent"===P.type?P.data={eventName:i.eventName,payload:i.payload}:"videoPlaybackEvent"===P.type?P.data={eventCode:i.eventCode,errorCode:i.errorCode}:a.warn("unknown trigger event type",P.type)}catch(e){a.error(`failed to parse trigger event string ${n}: ${e.message}`)}await p._init(t?.settings?.["ui-streamer"],i)}else F=X().sessionInfo?.settings?.webUI?.backendHeaders?.Authorization,a.log(`authToken dummy: token = ${F}`);window.auth=A,window.close=()=>{a.warn("window.close is disabled on Senza platform. Use lifecycle.exitApplication() instead.")}}function R(){return q}function J(){return P}function X(){if("undefined"==typeof window||!window.diagnostics)return"undefined"==typeof window||window.diagnostics||a.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=d.sessionInfoObj,e}catch(e){a.error("Could not get platform info",e.stack)}}function Q(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:()=>{a.log("timezome is successfully set to",e)},onFailure:(t,n)=>{a.error(`error occurred setting timezone to ${e}: ${t} ${n}`)}})}}function D(){return!("undefined"==typeof window||!window.cefQuery)}function U(){window.cefQuery?window.cefQuery({request:"uiReady",persistent:!1,onSuccess:()=>{a.log("uiReady request successfully sent")},onFailure:(e,t)=>{a.error(`uiReady request failed: ${e} ${t}`)}}):a.error("uiReady: window.cefQuery is undefined")}function M(){const e=d.sessionInfoObj;return D()?{deviceId:e.deviceId,connectionId:e.connectionId,community:e.community,tenant:e.tenant,clientIp:e.clientIp}:(a.log("getDeviceInfo running locally, returning dummy info"),{deviceId:"123456789",connectionId:"dummy",community:"LocalDev",tenant:"XXXXXX",clientIp:"0.0.0.0"})}const x={remoteBrowserIp:window.diagnostics?window.diagnostics().podIP:"127.0.0.1",sdkVersion:N};function z(e,t,n,i){if(200===e&&(t=window.btoa(String.fromCharCode.apply(null,new Uint8Array(t)))),window.cefQuery){const s={type:"updateLicense",sessionId:i,fcid:n};s[200===e?"response":"error"]=t;const o={target:"TC",waitForResponse:!1,message:JSON.stringify(s)};window.cefQuery({request:JSON.stringify(o),persistent:!1,onSuccess:()=>{a.log("updateLicense request successfully sent")},onFailure:(e,t)=>{a.error(`updateLicense request failed: ${e} ${t}`)}})}}class j extends Error{constructor(e,t){super(t),this.code=e}}function G(){if(window.cefQuery)return a.log("getClientAssertion is called"),new Promise(((e,t)=>{window.cefQuery({request:"client_assertion",persistent:!1,onSuccess:n=>{try{const t=JSON.parse(n);a.log(`client_assertion request successfully returned ${n}`),e(t)}catch(e){a.error(`Failed to parse client assertion ${n}`),t(new j(0,"Failed to parse client assertion"))}},onFailure:(e,n)=>{a.log(`client_assertion request failed: ${e} ${n}`),t(new j(e,n))}})}));a.warn("getClientAssertion is not supported if NOT running e2e")}return"undefined"!=typeof window&&(window.hs=n),t})()));
|
package/package.json
CHANGED
package/src/api.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { enableKeyPressIndicator } from "./keyPressIndicator";
|
|
2
|
-
|
|
3
1
|
import { getFCID, sdkLogger } from "./utils";
|
|
4
2
|
import pack from "../package.json";
|
|
5
3
|
import {sessionInfo} from "./SessionInfo";
|
|
@@ -110,10 +108,6 @@ export async function init() {
|
|
|
110
108
|
sdkLogger.log(`onUpdateSessionEvent: token = ${authToken}`);
|
|
111
109
|
});
|
|
112
110
|
|
|
113
|
-
if (sessionInfoObj?.settings?.["ui-streamer"]?.enableKeyPressDuration) {
|
|
114
|
-
enableKeyPressIndicator();
|
|
115
|
-
}
|
|
116
|
-
|
|
117
111
|
// Get connection reason
|
|
118
112
|
connectReason = await new Promise((resolve) => {
|
|
119
113
|
const FCID = getFCID();
|
package/src/remotePlayer.js
CHANGED
|
@@ -172,11 +172,6 @@ class RemotePlayer extends EventTarget {
|
|
|
172
172
|
* console.info("remotePlayer ended");
|
|
173
173
|
* });
|
|
174
174
|
*/
|
|
175
|
-
typeof document !== "undefined" && document.addEventListener("EOS", () => {
|
|
176
|
-
sdkLogger.info("Got EOS event");
|
|
177
|
-
this.dispatchEvent(new Event("ended"));
|
|
178
|
-
});
|
|
179
|
-
// we will remove the listener to EOS once ui-streamer will send hs/EOS
|
|
180
175
|
typeof document !== "undefined" && document.addEventListener("hs/EOS", () => {
|
|
181
176
|
sdkLogger.info("Got hs/EOS event");
|
|
182
177
|
this.dispatchEvent(new Event("ended"));
|
|
@@ -265,13 +260,6 @@ class RemotePlayer extends EventTarget {
|
|
|
265
260
|
* });
|
|
266
261
|
*
|
|
267
262
|
*/
|
|
268
|
-
typeof document !== "undefined" && document.addEventListener("ERR", (event) => {
|
|
269
|
-
delete event?.detail?.type; // type is always videoPlaybackEvent, so no need to pass it
|
|
270
|
-
delete event?.detail?.eventCode; // eventCode is always ERR, so no need to pass it
|
|
271
|
-
sdkLogger.info("Got ERR event", JSON.stringify(event?.detail));
|
|
272
|
-
this.dispatchEvent(new CustomEvent("error", event));
|
|
273
|
-
});
|
|
274
|
-
// we will remove the listener to ERR once ui-streamer will send hs/ERR
|
|
275
263
|
typeof document !== "undefined" && document.addEventListener("hs/ERR", (event) => {
|
|
276
264
|
sdkLogger.info("Got hs/ERR event");
|
|
277
265
|
delete event?.detail?.type; // type is always videoPlaybackEvent, so no need to pass it
|
package/src/keyPressIndicator.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export function enableKeyPressIndicator() {
|
|
2
|
-
const keyPressIndicator = document.createElement("div");
|
|
3
|
-
keyPressIndicator.setAttribute("style", "height: 8px; width: 8px; background-color: red; position: absolute; left: 0px; top: 0px; z-index: 9999;");
|
|
4
|
-
document.body.appendChild(keyPressIndicator);
|
|
5
|
-
document.addEventListener("keydown", () => {
|
|
6
|
-
if (keyPressIndicator.style.backgroundColor === "red") {
|
|
7
|
-
keyPressIndicator.style.backgroundColor = "blue";
|
|
8
|
-
} else if (keyPressIndicator.style.backgroundColor === "blue") {
|
|
9
|
-
keyPressIndicator.style.backgroundColor = "green";
|
|
10
|
-
} else { // background color is green
|
|
11
|
-
keyPressIndicator.style.backgroundColor = "red";
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
}
|