mirror of
https://github.com/jellyfin/jellyfin-web.git
synced 2024-11-17 19:08:18 -07:00
1 line
8.2 KiB
JavaScript
1 line
8.2 KiB
JavaScript
define(["appSettings","browser","events"],function(appSettings,browser,events){"use strict";function getBaseProfileOptions(item){var disableHlsVideoAudioCodecs=[];return item&&(!browser.edge&&canPlayNativeHls()||(disableHlsVideoAudioCodecs.push("mp3"),disableHlsVideoAudioCodecs.push("ac3"),disableHlsVideoAudioCodecs.push("eac3"))),{enableMkvProgressive:!1,disableHlsVideoAudioCodecs:disableHlsVideoAudioCodecs}}function canPlayNativeHls(){var media=document.createElement("video");return!(!media.canPlayType("application/x-mpegURL").replace(/no/,"")&&!media.canPlayType("application/vnd.apple.mpegURL").replace(/no/,""))}function getDeviceProfileForWindowsUwp(item){return new Promise(function(resolve,reject){require(["browserdeviceprofile","environments/windows-uwp/mediacaps"],function(profileBuilder,uwpMediaCaps){var profileOptions=getBaseProfileOptions(item);profileOptions.supportsDts=uwpMediaCaps.supportsDTS(),profileOptions.supportsTrueHd=uwpMediaCaps.supportsDolby(),profileOptions.audioChannels=uwpMediaCaps.getAudioChannels(),resolve(profileBuilder(profileOptions))})})}function getDeviceProfile(item,options){return options=options||{},self.Windows?getDeviceProfileForWindowsUwp(item):new Promise(function(resolve,reject){require(["browserdeviceprofile"],function(profileBuilder){var profile=profileBuilder(getBaseProfileOptions(item));item&&!options.isRetry&&"allcomplexformats"!==appSettings.get("subtitleburnin")&&(browser.orsay||browser.tizen||(profile.SubtitleProfiles.push({Format:"ass",Method:"External"}),profile.SubtitleProfiles.push({Format:"ssa",Method:"External"}))),resolve(profile)})})}function getCapabilities(){return getDeviceProfile().then(function(profile){var supportsPersistentIdentifier=!!browser.edgeUwp,caps={PlayableMediaTypes:["Audio","Video"],SupportsPersistentIdentifier:supportsPersistentIdentifier,DeviceProfile:profile};return caps})}function generateDeviceId(){return new Promise(function(resolve,reject){require(["cryptojs-sha1"],function(){var keys=[];keys.push(navigator.userAgent),keys.push((new Date).getTime()),resolve(CryptoJS.SHA1(keys.join("|")).toString())})})}function getDeviceId(){var key="_deviceId2",deviceId=appSettings.get(key);return deviceId?Promise.resolve(deviceId):generateDeviceId().then(function(deviceId){return appSettings.set(key,deviceId),deviceId})}function getDeviceName(){var deviceName;return deviceName=browser.tizen?"Samsung Smart TV":browser.web0S?"LG Smart TV":browser.operaTv?"Opera TV":browser.xboxOne?"Xbox One":browser.ps4?"Sony PS4":browser.chrome?"Chrome":browser.edge?"Edge":browser.firefox?"Firefox":browser.msie?"Internet Explorer":"Web Browser",browser.ipad?deviceName+=" Ipad":browser.iphone?deviceName+=" Iphone":browser.android&&(deviceName+=" Android"),deviceName}function supportsVoiceInput(){return!browser.tv&&(window.SpeechRecognition||window.webkitSpeechRecognition||window.mozSpeechRecognition||window.oSpeechRecognition||window.msSpeechRecognition)}function supportsFullscreen(){if(browser.tv)return!1;var element=document.documentElement;return!!(element.requestFullscreen||element.mozRequestFullScreen||element.webkitRequestFullscreen||element.msRequestFullscreen)||!!document.createElement("video").webkitEnterFullscreen}function getSyncProfile(){return new Promise(function(resolve,reject){require(["browserdeviceprofile","appSettings"],function(profileBuilder,appSettings){var profile=profileBuilder();profile.MaxStaticMusicBitrate=appSettings.maxStaticMusicBitrate(),resolve(profile)})})}function getDefaultLayout(){return"desktop"}function supportsHtmlMediaAutoplay(){if(browser.edgeUwp||browser.tizen||browser.web0S||browser.orsay||browser.operaTv||browser.ps4||browser.xboxOne)return!0;if(browser.mobile)return!1;var savedResult=appSettings.get(htmlMediaAutoplayAppStorageKey);return"true"===savedResult||"false"!==savedResult&&null}function isXboxUWP(){return!1}function cueSupported(){try{var video=document.createElement("video"),style=document.createElement("style");style.textContent="video::cue {background: inherit}",document.body.appendChild(style),document.body.appendChild(video);var cue=window.getComputedStyle(video,"::cue").background;return document.body.removeChild(style),document.body.removeChild(video),!!cue.length}catch(err){return console.log("Error detecting cue support:"+err),!1}}function onAppVisible(){_isHidden&&(_isHidden=!1,console.log("triggering app resume event"),events.trigger(appHost,"resume"))}function onAppHidden(){_isHidden||(_isHidden=!0,console.log("app is hidden"))}var htmlMediaAutoplayAppStorageKey="supportshtmlmediaautoplay0",supportedFeatures=function(){var features=["sharing"];return browser.edgeUwp||browser.tv||browser.xboxOne||browser.ps4||isXboxUWP()||features.push("filedownload"),browser.operaTv||browser.tizen||browser.orsay||browser.web0s?features.push("exit"):(features.push("exitmenu"),features.push("plugins")),browser.operaTv||browser.tizen||browser.orsay||browser.web0s||browser.ps4||(features.push("externallinks"),features.push("externalpremium")),browser.operaTv||features.push("externallinkdisplay"),supportsVoiceInput()&&features.push("voiceinput"),!(browser.tv||browser.xboxOne||browser.ps4||isXboxUWP()),supportsHtmlMediaAutoplay()&&(features.push("htmlaudioautoplay"),features.push("htmlvideoautoplay")),browser.edgeUwp&&(isXboxUWP()||features.push("sync")),supportsFullscreen()&&features.push("fullscreenchange"),(browser.chrome||browser.edge&&!browser.slow)&&(browser.noAnimation||browser.edgeUwp||browser.xboxOne||features.push("imageanalysis")),Dashboard.isConnectMode()&&features.push("multiserver"),(browser.tv||browser.xboxOne||browser.ps4||browser.mobile||isXboxUWP())&&features.push("physicalvolumecontrol"),browser.tv||browser.xboxOne||browser.ps4||isXboxUWP()||features.push("remotecontrol"),!(browser.operaTv||browser.tizen||browser.orsay||browser.web0s||browser.edgeUwp),features.push("otherapppromotions"),features.push("targetblank"),browser.orsay||browser.tizen||browser.msie||!(browser.firefox||browser.ps4||browser.edge||cueSupported())||features.push("subtitleappearancesettings"),browser.orsay||browser.tizen||features.push("subtitleburnsettings"),browser.tv||browser.ps4||browser.xboxOne||isXboxUWP()||features.push("fileinput"),Dashboard.isConnectMode()&&features.push("displaylanguage"),features}();supportedFeatures.indexOf("htmlvideoautoplay")===-1&&supportsHtmlMediaAutoplay()!==!1&&require(["autoPlayDetect"],function(autoPlayDetect){autoPlayDetect.supportsHtmlMediaAutoplay().then(function(){appSettings.set(htmlMediaAutoplayAppStorageKey,"true"),supportedFeatures.push("htmlvideoautoplay"),supportedFeatures.push("htmlaudioautoplay")},function(){appSettings.set(htmlMediaAutoplayAppStorageKey,"false")})});var appInfo,visibilityChange,visibilityState,version=window.dashboardVersion||"3.0",appHost={getWindowState:function(){return document.windowState||"Normal"},setWindowState:function(state){alert("setWindowState is not supported and should not be called")},exit:function(){if(browser.tizen)try{tizen.application.getCurrentApplication().exit()}catch(err){console.log("error closing application: "+err)}else window.close()},supports:function(command){return supportedFeatures.indexOf(command.toLowerCase())!==-1},appInfo:function(){return appInfo?Promise.resolve(appInfo):getDeviceId().then(function(deviceId){return appInfo={deviceId:deviceId,deviceName:getDeviceName(),appName:"Emby Mobile",appVersion:version}})},getCapabilities:getCapabilities,preferVisualCards:browser.android||browser.chrome,moreIcon:browser.safari||browser.edge?"dots-horiz":"dots-vert",getSyncProfile:getSyncProfile,getDefaultLayout:getDefaultLayout,getDeviceProfile:getDeviceProfile};"undefined"!=typeof document.visibilityState?(visibilityChange="visibilitychange",visibilityState="hidden"):"undefined"!=typeof document.mozHidden?(visibilityChange="mozvisibilitychange",visibilityState="mozVisibilityState"):"undefined"!=typeof document.msHidden?(visibilityChange="msvisibilitychange",visibilityState="msVisibilityState"):"undefined"!=typeof document.webkitHidden&&(visibilityChange="webkitvisibilitychange",visibilityState="webkitVisibilityState");var _isHidden=!1;return document.addEventListener(visibilityChange,function(){document[visibilityState]?onAppHidden():onAppVisible()}),window.addEventListener("focus",onAppVisible),window.addEventListener("blur",onAppHidden),appHost}); |