From 9527241917452625beca8dca4d23d5fa1461b888 Mon Sep 17 00:00:00 2001 From: KGT1 Date: Sat, 17 Apr 2021 05:10:05 +0200 Subject: [PATCH] fix broken apiclient --- patches/jellyfin-apiclient+1.6.0.patch | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/patches/jellyfin-apiclient+1.6.0.patch b/patches/jellyfin-apiclient+1.6.0.patch index 576882a..c434b2a 100644 --- a/patches/jellyfin-apiclient+1.6.0.patch +++ b/patches/jellyfin-apiclient+1.6.0.patch @@ -1,9 +1,11 @@ diff --git a/node_modules/jellyfin-apiclient/dist/jellyfin-apiclient.js b/node_modules/jellyfin-apiclient/dist/jellyfin-apiclient.js -index 43bbde3..5dba364 100644 +index 43bbde3..f1816ae 100644 --- a/node_modules/jellyfin-apiclient/dist/jellyfin-apiclient.js +++ b/node_modules/jellyfin-apiclient/dist/jellyfin-apiclient.js -@@ -1,2 +1,4 @@ +@@ -1,2 +1,6 @@ +const self = require('window') ++const fetch = require('node-fetch') ++const WebSocket = require('ws') + !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["jellyfin-apiclient"]=t():e["jellyfin-apiclient"]=t()}(self,(function(){return function(){"use strict";var e={628:function(e,t,r){function n(e,t){if(!e)throw new Error("obj cannot be null!");e._callbacks=e._callbacks||{};var r=e._callbacks[t];return r||(e._callbacks[t]=[],r=e._callbacks[t]),r}r.d(t,{default:function(){return he}});var i={on:function(e,t,r){n(e,t).push(r)},off:function(e,t,r){var i=n(e,t),a=i.indexOf(r);-1!==a&&i.splice(a,1)},trigger:function(e,t){var r={type:t},i=[];i.push(r);for(var a=arguments[2]||[],o=0,s=a.length;o=20?Promise.reject():function(e){var t=[],r=[],n=e.serverInfo();return n.LocalAddress&&-1===r.indexOf(n.LocalAddress)&&(t.push({url:n.LocalAddress,timeout:0}),r.push(t[t.length-1].url)),n.ManualAddress&&-1===r.indexOf(n.ManualAddress)&&(t.push({url:n.ManualAddress,timeout:100}),r.push(t[t.length-1].url)),n.RemoteAddress&&-1===r.indexOf(n.RemoteAddress)&&(t.push({url:n.RemoteAddress,timeout:200}),r.push(t[t.length-1].url)),console.log("tryReconnect: "+r.join("|")),new Promise((function(r,n){var i={};i.numAddresses=t.length,i.rejects=0,t.map((function(t){setTimeout((function(){i.resolved||function(e,t,r,n,i){console.log("getTryConnectPromise "+t),S(e.getUrl("system/info/public",null,t),{method:"GET",accept:"application/json"},15e3).then((function(){r.resolved||(r.resolved=!0,console.log("Reconnect succeeded to "+t),e.serverAddress(t),n())}),(function(){r.resolved||(console.log("Reconnect failed to "+t),r.rejects++,r.rejects>=r.numAddresses&&i())}))}(e,t.url,i,r,n)}),t.timeout)}))}))}(e).catch((function(r){return console.log("error in tryReconnectInternal: "+(r||"")),new Promise((function(r,n){setTimeout((function(){T(e,t+1).then(r,n)}),500)}))}))}function P(e,t){var r=e.serverId();if(!r)return null;var n=u.getItem("user-".concat(t,"-").concat(r));return n?JSON.parse(n):null}function U(e){E(this,e=JSON.parse(e.data))}var O={};function E(e,t){var r=t.MessageId;if(r){if(O[r])return;O[r]=!0}"UserDeleted"===t.MessageType?e._currentUser=null:"UserUpdated"===t.MessageType||"UserConfigurationUpdated"===t.MessageType?t.Data.Id===e.getCurrentUserId()&&(e._currentUser=null):"KeepAlive"===t.MessageType?console.debug("Received KeepAlive from server."):"ForceKeepAlive"===t.MessageType&&(console.debug("Received ForceKeepAlive from server. Timeout is ".concat(t.Data," seconds.")),e.sendWebSocketMessage("KeepAlive"),function(e,t){b(e),e.keepAliveInterval=setInterval((function(){e.sendWebSocketMessage("KeepAlive")}),1e3*t*.5),e.keepAliveInterval}(e,t.Data)),i.trigger(e,"message",[t])}function b(e){console.debug("Clearing KeepAlive for",e),e.keepAliveInterval&&(clearInterval(e.keepAliveInterval),e.keepAliveInterval=null)}function j(){console.log("web socket connection opened"),i.trigger(this,"websocketopen")}function N(){b(this),i.trigger(this,"websocketerror")}function A(e,t){if(!t)return e.lastDetectedBitrate?e.lastDetectedBitrate:Promise.reject();var r=Math.round(.7*t);if(e.getMaxBandwidth){var n=e.getMaxBandwidth();n&&(r=Math.min(r,n))}return e.lastDetectedBitrate=r,e.lastDetectedBitrateTime=(new Date).getTime(),r}function x(e,t,r,n){if(r>=t.length)return A(e,n);var i=t[r];return e.getDownloadSpeed(i.bytes).then((function(n){return n0&&void 0!==arguments[0]?arguments[0]:{};return e.channelIds&&e.channelIds.length>1800?this.ajax({type:"POST",url:this.getUrl("LiveTv/Programs"),data:JSON.stringify(e),contentType:"application/json",dataType:"json"}):this.ajax({type:"GET",url:this.getUrl("LiveTv/Programs",e),dataType:"json"})}},{key:"getLiveTvRecommendedPrograms",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.ajax({type:"GET",url:this.getUrl("LiveTv/Programs/Recommended",e),dataType:"json"})}},{key:"getLiveTvRecordings",value:function(e){var t=this.getUrl("LiveTv/Recordings",e||{});return this.getJSON(t)}},{key:"getLiveTvRecordingSeries",value:function(e){var t=this.getUrl("LiveTv/Recordings/Series",e||{});return this.getJSON(t)}},{key:"getLiveTvRecordingGroups",value:function(e){var t=this.getUrl("LiveTv/Recordings/Groups",e||{});return this.getJSON(t)}},{key:"getLiveTvRecordingGroup",value:function(e){if(!e)throw new Error("null id");var t=this.getUrl("LiveTv/Recordings/Groups/".concat(e));return this.getJSON(t)}},{key:"getLiveTvRecording",value:function(e,t){if(!e)throw new Error("null id");var r={};t&&(r.userId=t);var n=this.getUrl("LiveTv/Recordings/".concat(e),r);return this.getJSON(n)}},{key:"getLiveTvProgram",value:function(e,t){if(!e)throw new Error("null id");var r={};t&&(r.userId=t);var n=this.getUrl("LiveTv/Programs/".concat(e),r);return this.getJSON(n)}},{key:"deleteLiveTvRecording",value:function(e){if(!e)throw new Error("null id");var t=this.getUrl("LiveTv/Recordings/".concat(e));return this.ajax({type:"DELETE",url:t})}},{key:"cancelLiveTvTimer",value:function(e){if(!e)throw new Error("null id");var t=this.getUrl("LiveTv/Timers/".concat(e));return this.ajax({type:"DELETE",url:t})}},{key:"getLiveTvTimers",value:function(e){var t=this.getUrl("LiveTv/Timers",e||{});return this.getJSON(t)}},{key:"getLiveTvTimer",value:function(e){if(!e)throw new Error("null id");var t=this.getUrl("LiveTv/Timers/".concat(e));return this.getJSON(t)}},{key:"getNewLiveTvTimerDefaults",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.getUrl("LiveTv/Timers/Defaults",e);return this.getJSON(t)}},{key:"createLiveTvTimer",value:function(e){if(!e)throw new Error("null item");var t=this.getUrl("LiveTv/Timers");return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"updateLiveTvTimer",value:function(e){if(!e)throw new Error("null item");var t=this.getUrl("LiveTv/Timers/".concat(e.Id));return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"resetLiveTvTuner",value:function(e){if(!e)throw new Error("null id");var t=this.getUrl("LiveTv/Tuners/".concat(e,"/Reset"));return this.ajax({type:"POST",url:t})}},{key:"getLiveTvSeriesTimers",value:function(e){var t=this.getUrl("LiveTv/SeriesTimers",e||{});return this.getJSON(t)}},{key:"getLiveTvSeriesTimer",value:function(e){if(!e)throw new Error("null id");var t=this.getUrl("LiveTv/SeriesTimers/".concat(e));return this.getJSON(t)}},{key:"cancelLiveTvSeriesTimer",value:function(e){if(!e)throw new Error("null id");var t=this.getUrl("LiveTv/SeriesTimers/".concat(e));return this.ajax({type:"DELETE",url:t})}},{key:"createLiveTvSeriesTimer",value:function(e){if(!e)throw new Error("null item");var t=this.getUrl("LiveTv/SeriesTimers");return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"updateLiveTvSeriesTimer",value:function(e){if(!e)throw new Error("null item");var t=this.getUrl("LiveTv/SeriesTimers/".concat(e.Id));return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"getRegistrationInfo",value:function(e){var t=this.getUrl("Registrations/".concat(e));return this.getJSON(t)}},{key:"getSystemInfo",value:function(e){var t=this.getUrl("System/Info"),r=this;return this.getJSON(t).then((function(e){return r.setSystemInfo(e),Promise.resolve(e)}))}},{key:"getSyncStatus",value:function(){var e=this.getUrl("Sync/"+itemId+"/Status");return this.ajax({url:e,type:"POST",dataType:"json",contentType:"application/json",data:JSON.stringify({TargetId:this.deviceId()})})}},{key:"getPublicSystemInfo",value:function(){var e=this.getUrl("System/Info/Public"),t=this;return this.getJSON(e).then((function(e){return t.setSystemInfo(e),Promise.resolve(e)}))}},{key:"getInstantMixFromItem",value:function(e,t){var r=this.getUrl("Items/".concat(e,"/InstantMix"),t);return this.getJSON(r)}},{key:"getEpisodes",value:function(e,t){var r=this.getUrl("Shows/".concat(e,"/Episodes"),t);return this.getJSON(r)}},{key:"getDisplayPreferences",value:function(e,t,r){var n=this.getUrl("DisplayPreferences/".concat(e),{userId:t,client:r});return this.getJSON(n)}},{key:"updateDisplayPreferences",value:function(e,t,r,n){var i=this.getUrl("DisplayPreferences/".concat(e),{userId:r,client:n});return this.ajax({type:"POST",url:i,data:JSON.stringify(t),contentType:"application/json"})}},{key:"getSeasons",value:function(e,t){var r=this.getUrl("Shows/".concat(e,"/Seasons"),t);return this.getJSON(r)}},{key:"getSimilarItems",value:function(e,t){var r=this.getUrl("Items/".concat(e,"/Similar"),t);return this.getJSON(r)}},{key:"getCultures",value:function(){var e=this.getUrl("Localization/cultures");return this.getJSON(e)}},{key:"getCountries",value:function(){var e=this.getUrl("Localization/countries");return this.getJSON(e)}},{key:"getPlaybackInfo",value:function(e,t,r){var n={DeviceProfile:r};return this.ajax({url:this.getUrl("Items/".concat(e,"/PlaybackInfo"),t),type:"POST",data:JSON.stringify(n),contentType:"application/json",dataType:"json"})}},{key:"getLiveStreamMediaInfo",value:function(e){var t={LiveStreamId:e};return this.ajax({url:this.getUrl("LiveStreams/MediaInfo"),type:"POST",data:JSON.stringify(t),contentType:"application/json",dataType:"json"})}},{key:"getIntros",value:function(e){return this.getJSON(this.getUrl("Users/".concat(this.getCurrentUserId(),"/Items/").concat(e,"/Intros")))}},{key:"getDirectoryContents",value:function(e,t){if(!e)throw new Error("null path");if("string"!=typeof e)throw new Error("invalid path");(t=t||{}).path=e;var r=this.getUrl("Environment/DirectoryContents",t);return this.getJSON(r)}},{key:"getNetworkShares",value:function(e){if(!e)throw new Error("null path");var t={};t.path=e;var r=this.getUrl("Environment/NetworkShares",t);return this.getJSON(r)}},{key:"getParentPath",value:function(e){if(!e)throw new Error("null path");var t={};t.path=e;var r=this.getUrl("Environment/ParentPath",t);return this.ajax({type:"GET",url:r,dataType:"text"})}},{key:"getDrives",value:function(){var e=this.getUrl("Environment/Drives");return this.getJSON(e)}},{key:"getNetworkDevices",value:function(){var e=this.getUrl("Environment/NetworkDevices");return this.getJSON(e)}},{key:"cancelPackageInstallation",value:function(e){if(!e)throw new Error("null installationId");var t=this.getUrl("Packages/Installing/".concat(e));return this.ajax({type:"DELETE",url:t})}},{key:"refreshItem",value:function(e,t){if(!e)throw new Error("null itemId");var r=this.getUrl("Items/".concat(e,"/Refresh"),t||{});return this.ajax({type:"POST",url:r})}},{key:"installPlugin",value:function(e,t,r){if(!e)throw new Error("null name");var n={AssemblyGuid:t};r&&(n.version=r);var i=this.getUrl("Packages/Installed/".concat(e),n);return this.ajax({type:"POST",url:i})}},{key:"restartServer",value:function(){var e=this.getUrl("System/Restart");return this.ajax({type:"POST",url:e})}},{key:"shutdownServer",value:function(){var e=this.getUrl("System/Shutdown");return this.ajax({type:"POST",url:e})}},{key:"getPackageInfo",value:function(e,t){if(!e)throw new Error("null name");var r={AssemblyGuid:t},n=this.getUrl("Packages/".concat(e),r);return this.getJSON(n)}},{key:"getVirtualFolders",value:function(){var e="Library/VirtualFolders";return e=this.getUrl(e),this.getJSON(e)}},{key:"getPhysicalPaths",value:function(){var e=this.getUrl("Library/PhysicalPaths");return this.getJSON(e)}},{key:"getServerConfiguration",value:function(){var e=this.getUrl("System/Configuration");return this.getJSON(e)}},{key:"getDevicesOptions",value:function(){var e=this.getUrl("System/Configuration/devices");return this.getJSON(e)}},{key:"deleteDevice",value:function(e){var t=this.getUrl("Devices",{Id:e});return this.ajax({type:"DELETE",url:t})}},{key:"getContentUploadHistory",value:function(){var e=this.getUrl("Devices/CameraUploads",{DeviceId:this.deviceId()});return this.getJSON(e)}},{key:"getNamedConfiguration",value:function(e){var t=this.getUrl("System/Configuration/".concat(e));return this.getJSON(t)}},{key:"getScheduledTasks",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.getUrl("ScheduledTasks",e);return this.getJSON(t)}},{key:"startScheduledTask",value:function(e){if(!e)throw new Error("null id");var t=this.getUrl("ScheduledTasks/Running/".concat(e));return this.ajax({type:"POST",url:t})}},{key:"getScheduledTask",value:function(e){if(!e)throw new Error("null id");var t=this.getUrl("ScheduledTasks/".concat(e));return this.getJSON(t)}},{key:"getNextUpEpisodes",value:function(e){var t=this.getUrl("Shows/NextUp",e);return this.getJSON(t)}},{key:"stopScheduledTask",value:function(e){if(!e)throw new Error("null id");var t=this.getUrl("ScheduledTasks/Running/".concat(e));return this.ajax({type:"DELETE",url:t})}},{key:"getPluginConfiguration",value:function(e){if(!e)throw new Error("null Id");var t=this.getUrl("Plugins/".concat(e,"/Configuration"));return this.getJSON(t)}},{key:"getAvailablePlugins",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e.PackageType="UserInstalled";var t=this.getUrl("Packages",e);return this.getJSON(t)}},{key:"uninstallPlugin",value:function(e){if(!e)throw new Error("null Id");var t=this.getUrl("Plugins/".concat(e));return this.ajax({type:"DELETE",url:t})}},{key:"uninstallPluginByVersion",value:function(e,t){if(!e)throw new Error("null Id");if(!t)throw new Error("null Version");var r=this.getUrl("Plugins/".concat(e,"/").concat(t));return this.ajax({type:"DELETE",url:r})}},{key:"enablePlugin",value:function(e,t){if(!e)throw new Error("null Id");if(!t)throw new Error("null Id");var r=this.getUrl("Plugins/".concat(e,"/").concat(t,"/Enable"));return this.ajax({type:"POST",url:r})}},{key:"disablePlugin",value:function(e,t){if(!e)throw new Error("null Id");if(!t)throw new Error("null Version");var r=this.getUrl("Plugins/".concat(e,"/").concat(t,"/Disable"));return this.ajax({type:"POST",url:r})}},{key:"removeVirtualFolder",value:function(e,t){if(!e)throw new Error("null name");var r="Library/VirtualFolders";return r=this.getUrl(r,{refreshLibrary:!!t,name:e}),this.ajax({type:"DELETE",url:r})}},{key:"addVirtualFolder",value:function(e,t,r,n){if(!e)throw new Error("null name");var i={};t&&(i.collectionType=t),i.refreshLibrary=!!r,i.name=e;var a="Library/VirtualFolders";return a=this.getUrl(a,i),this.ajax({type:"POST",url:a,data:JSON.stringify({LibraryOptions:n}),contentType:"application/json"})}},{key:"updateVirtualFolderOptions",value:function(e,t){if(!e)throw new Error("null name");var r="Library/VirtualFolders/LibraryOptions";return r=this.getUrl(r),this.ajax({type:"POST",url:r,data:JSON.stringify({Id:e,LibraryOptions:t}),contentType:"application/json"})}},{key:"renameVirtualFolder",value:function(e,t,r){if(!e)throw new Error("null name");var n="Library/VirtualFolders/Name";return n=this.getUrl(n,{refreshLibrary:!!r,newName:t,name:e}),this.ajax({type:"POST",url:n})}},{key:"addMediaPath",value:function(e,t,r,n){if(!e)throw new Error("null virtualFolderName");if(!t)throw new Error("null mediaPath");var i="Library/VirtualFolders/Paths",a={Path:t};return r&&(a.NetworkPath=r),i=this.getUrl(i,{refreshLibrary:!!n}),this.ajax({type:"POST",url:i,data:JSON.stringify({Name:e,PathInfo:a}),contentType:"application/json"})}},{key:"updateMediaPath",value:function(e,t){if(!e)throw new Error("null virtualFolderName");if(!t)throw new Error("null pathInfo");var r="Library/VirtualFolders/Paths/Update";return r=this.getUrl(r),this.ajax({type:"POST",url:r,data:JSON.stringify({Name:e,PathInfo:t}),contentType:"application/json"})}},{key:"removeMediaPath",value:function(e,t,r){if(!e)throw new Error("null virtualFolderName");if(!t)throw new Error("null mediaPath");var n="Library/VirtualFolders/Paths";return n=this.getUrl(n,{refreshLibrary:!!r,path:t,name:e}),this.ajax({type:"DELETE",url:n})}},{key:"deleteUser",value:function(e){if(!e)throw new Error("null id");var t=this.getUrl("Users/".concat(e));return this.ajax({type:"DELETE",url:t})}},{key:"deleteUserImage",value:function(e,t,r){if(!e)throw new Error("null userId");if(!t)throw new Error("null imageType");var n=this.getUrl("Users/".concat(e,"/Images/").concat(t));return null!=r&&(n+="/".concat(r)),this.ajax({type:"DELETE",url:n})}},{key:"deleteItemImage",value:function(e,t,r){if(!t)throw new Error("null imageType");var n=this.getUrl("Items/".concat(e,"/Images"));return n+="/".concat(t),null!=r&&(n+="/".concat(r)),this.ajax({type:"DELETE",url:n})}},{key:"deleteItem",value:function(e){if(!e)throw new Error("null itemId");var t=this.getUrl("Items/".concat(e));return this.ajax({type:"DELETE",url:t})}},{key:"stopActiveEncodings",value:function(e){var t={deviceId:this.deviceId()};e&&(t.PlaySessionId=e);var r=this.getUrl("Videos/ActiveEncodings",t);return this.ajax({type:"DELETE",url:r})}},{key:"reportCapabilities",value:function(e){var t=this.getUrl("Sessions/Capabilities/Full");return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"updateItemImageIndex",value:function(e,t,r,n){if(!t)throw new Error("null imageType");var i={newIndex:n},a=this.getUrl("Items/".concat(e,"/Images/").concat(t,"/").concat(r,"/Index"),i);return this.ajax({type:"POST",url:a})}},{key:"getItemImageInfos",value:function(e){var t=this.getUrl("Items/".concat(e,"/Images"));return this.getJSON(t)}},{key:"getCriticReviews",value:function(e,t){if(!e)throw new Error("null itemId");var r=this.getUrl("Items/".concat(e,"/CriticReviews"),t);return this.getJSON(r)}},{key:"getItemDownloadUrl",value:function(e){if(!e)throw new Error("itemId cannot be empty");var t="Items/".concat(e,"/Download");return this.getUrl(t,{api_key:this.accessToken()})}},{key:"getSessions",value:function(e){var t=this.getUrl("Sessions",e);return this.getJSON(t)}},{key:"uploadUserImage",value:function(e,t,r){if(!e)throw new Error("null userId");if(!t)throw new Error("null imageType");if(!r)throw new Error("File must be an image.");if(!r.type.startsWith("image/"))throw new Error("File must be an image.");var n=this;return new Promise((function(i,a){var o=new FileReader;o.onerror=function(){a()},o.onabort=function(){a()},o.onload=function(o){var s=o.target.result.split(",")[1],l=n.getUrl("Users/".concat(e,"/Images/").concat(t));n.ajax({type:"POST",url:l,data:s,contentType:"image/".concat(r.name.substring(r.name.lastIndexOf(".")+1))}).then(i,a)},o.readAsDataURL(r)}))}},{key:"uploadItemImage",value:function(e,t,r){if(!e)throw new Error("null itemId");if(!t)throw new Error("null imageType");if(!r)throw new Error("File must be an image.");if(!r.type.startsWith("image/"))throw new Error("File must be an image.");var n=this.getUrl("Items/".concat(e,"/Images"));n+="/".concat(t);var i=this;return new Promise((function(e,t){var a=new FileReader;a.onerror=function(){t()},a.onabort=function(){t()},a.onload=function(a){var o=a.target.result.split(",")[1];i.ajax({type:"POST",url:n,data:o,contentType:"image/".concat(r.name.substring(r.name.lastIndexOf(".")+1))}).then(e,t)},a.readAsDataURL(r)}))}},{key:"uploadItemSubtitle",value:function(e,t,r,n){var i=this;if(!e)throw new SyntaxError("Missing itemId");if(!t)throw new SyntaxError("Missing language");if("boolean"!=typeof r)throw new TypeError("Parameter isForced must be a boolean.");if(!n)throw new SyntaxError("File must be a subtitle file.");var a=n.name.substring(n.name.lastIndexOf(".")+1).toLowerCase();if(!["sub","srt","vtt","ass","ssa"].includes(a))throw new Error("Invalid subtitle format.");var o=this.getUrl("Videos/".concat(e,"/Subtitles"));return new Promise((function(e,s){var l=new FileReader;l.onerror=function(){s()},l.onabort=function(){s()},l.onload=function(n){var l=n.target.result.split(",")[1];i.ajax({type:"POST",url:o,contentType:"application/json",data:JSON.stringify({language:t,format:a,isForced:r,data:l})}).then(e,s)},l.readAsDataURL(n)}))}},{key:"getInstalledPlugins",value:function(){var e=this.getUrl("Plugins",{});return this.getJSON(e)}},{key:"getUser",value:function(e){if(!e)throw new Error("Must supply a userId");var t=this.getUrl("Users/".concat(e));return this.getJSON(t)}},{key:"getStudio",value:function(e,t){if(!e)throw new Error("null name");var r={};t&&(r.userId=t);var n=this.getUrl("Studios/".concat(this.encodeName(e)),r);return this.getJSON(n)}},{key:"getGenre",value:function(e,t){if(!e)throw new Error("null name");var r={};t&&(r.userId=t);var n=this.getUrl("Genres/".concat(this.encodeName(e)),r);return this.getJSON(n)}},{key:"getMusicGenre",value:function(e,t){if(!e)throw new Error("null name");var r={};t&&(r.userId=t);var n=this.getUrl("MusicGenres/".concat(this.encodeName(e)),r);return this.getJSON(n)}},{key:"getArtist",value:function(e,t){if(!e)throw new Error("null name");var r={};t&&(r.userId=t);var n=this.getUrl("Artists/".concat(this.encodeName(e)),r);return this.getJSON(n)}},{key:"getPerson",value:function(e,t){if(!e)throw new Error("null name");var r={};t&&(r.userId=t);var n=this.getUrl("Persons/".concat(this.encodeName(e)),r);return this.getJSON(n)}},{key:"getPublicUsers",value:function(){var e=this.getUrl("users/public");return this.ajax({type:"GET",url:e,dataType:"json"},!1)}},{key:"getUsers",value:function(e){var t=this.getUrl("users",e||{});return this.getJSON(t)}},{key:"getParentalRatings",value:function(){var e=this.getUrl("Localization/ParentalRatings");return this.getJSON(e)}},{key:"getDefaultImageQuality",value:function(e){return"backdrop"===e.toLowerCase()?80:90}},{key:"getUserImageUrl",value:function(e,t){if(!e)throw new Error("null userId");t=t||{};var r="Users/".concat(e,"/Images/").concat(t.type);return null!=t.index&&(r+="/".concat(t.index)),J(this,t),delete t.type,delete t.index,this.getUrl(r,t)}},{key:"getImageUrl",value:function(e,t){if(!e)throw new Error("itemId cannot be empty");t=t||{};var r="Items/".concat(e,"/Images/").concat(t.type);return null!=t.index&&(r+="/".concat(t.index)),t.quality=t.quality||this.getDefaultImageQuality(t.type),this.normalizeImageOptions&&this.normalizeImageOptions(t),delete t.type,delete t.index,this.getUrl(r,t)}},{key:"getScaledImageUrl",value:function(e,t){if(!e)throw new Error("itemId cannot be empty");t=t||{};var r="Items/".concat(e,"/Images/").concat(t.type);return null!=t.index&&(r+="/".concat(t.index)),J(this,t),delete t.type,delete t.index,delete t.minScale,this.getUrl(r,t)}},{key:"getThumbImageUrl",value:function(e,t){if(!e)throw new Error("null item");return(t=t||{}).imageType="thumb",e.ImageTags&&e.ImageTags.Thumb?(t.tag=e.ImageTags.Thumb,this.getImageUrl(e.Id,t)):e.ParentThumbItemId?(t.tag=e.ImageTags.ParentThumbImageTag,this.getImageUrl(e.ParentThumbItemId,t)):null}},{key:"updateUserPassword",value:function(e,t,r){if(!e)return Promise.reject();var n=this.getUrl("Users/".concat(e,"/Password"));return this.ajax({type:"POST",url:n,data:JSON.stringify({CurrentPw:t||"",NewPw:r}),contentType:"application/json"})}},{key:"updateEasyPassword",value:function(e,t){if(e){var r=this.getUrl("Users/".concat(e,"/EasyPassword"));return this.ajax({type:"POST",url:r,data:JSON.stringify({NewPw:t}),contentType:"application/json"})}Promise.reject()}},{key:"resetUserPassword",value:function(e){if(!e)throw new Error("null userId");var t=this.getUrl("Users/".concat(e,"/Password"));return this.ajax({type:"POST",url:t,data:JSON.stringify({resetPassword:!0}),contentType:"application/json"})}},{key:"resetEasyPassword",value:function(e){if(!e)throw new Error("null userId");var t=this.getUrl("Users/".concat(e,"/EasyPassword"));return this.ajax({type:"POST",url:t,data:JSON.stringify({resetPassword:!0}),contentType:"application/json"})}},{key:"updateServerConfiguration",value:function(e){if(!e)throw new Error("null configuration");var t=this.getUrl("System/Configuration");return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"updateNamedConfiguration",value:function(e,t){if(!t)throw new Error("null configuration");var r=this.getUrl("System/Configuration/".concat(e));return this.ajax({type:"POST",url:r,data:JSON.stringify(t),contentType:"application/json"})}},{key:"updateItem",value:function(e){if(!e)throw new Error("null item");var t=this.getUrl("Items/".concat(e.Id));return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"updatePluginSecurityInfo",value:function(e){var t=this.getUrl("Plugins/SecurityInfo");return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"createUser",value:function(e){var t=this.getUrl("Users/New");return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json",headers:{accept:"application/json"}})}},{key:"updateUser",value:function(e){if(!e)throw new Error("null user");var t=this.getUrl("Users/".concat(e.Id));return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"updateUserPolicy",value:function(e,t){if(!e)throw new Error("null userId");if(!t)throw new Error("null policy");var r=this.getUrl("Users/".concat(e,"/Policy"));return this.ajax({type:"POST",url:r,data:JSON.stringify(t),contentType:"application/json"})}},{key:"updateUserConfiguration",value:function(e,t){if(!e)throw new Error("null userId");if(!t)throw new Error("null configuration");var r=this.getUrl("Users/".concat(e,"/Configuration"));return this.ajax({type:"POST",url:r,data:JSON.stringify(t),contentType:"application/json"})}},{key:"updateScheduledTaskTriggers",value:function(e,t){if(!e)throw new Error("null id");if(!t)throw new Error("null triggers");var r=this.getUrl("ScheduledTasks/".concat(e,"/Triggers"));return this.ajax({type:"POST",url:r,data:JSON.stringify(t),contentType:"application/json"})}},{key:"updatePluginConfiguration",value:function(e,t){if(!e)throw new Error("null Id");if(!t)throw new Error("null configuration");var r=this.getUrl("Plugins/".concat(e,"/Configuration"));return this.ajax({type:"POST",url:r,data:JSON.stringify(t),contentType:"application/json"})}},{key:"getAncestorItems",value:function(e,t){if(!e)throw new Error("null itemId");var r={};t&&(r.userId=t);var n=this.getUrl("Items/".concat(e,"/Ancestors"),r);return this.getJSON(n)}},{key:"getItems",value:function(e,t){var r;return r="string"===c(e).toString().toLowerCase()?this.getUrl("Users/".concat(e,"/Items"),t):this.getUrl("Items",t),this.getJSON(r)}},{key:"getResumableItems",value:function(e,t){return this.isMinServerVersion("3.2.33")?this.getJSON(this.getUrl("Users/".concat(e,"/Items/Resume"),t)):this.getItems(e,Object.assign({SortBy:"DatePlayed",SortOrder:"Descending",Filters:"IsResumable",Recursive:!0,CollapseBoxSetItems:!1,ExcludeLocationTypes:"Virtual"},t))}},{key:"getMovieRecommendations",value:function(e){return this.getJSON(this.getUrl("Movies/Recommendations",e))}},{key:"getUpcomingEpisodes",value:function(e){return this.getJSON(this.getUrl("Shows/Upcoming",e))}},{key:"getUserViews",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0,r=this.getUrl("Users/".concat(t||this.getCurrentUserId(),"/Views"),e);return this.getJSON(r)}},{key:"getArtists",value:function(e,t){if(!e)throw new Error("null userId");(t=t||{}).userId=e;var r=this.getUrl("Artists",t);return this.getJSON(r)}},{key:"getAlbumArtists",value:function(e,t){if(!e)throw new Error("null userId");(t=t||{}).userId=e;var r=this.getUrl("Artists/AlbumArtists",t);return this.getJSON(r)}},{key:"getGenres",value:function(e,t){if(!e)throw new Error("null userId");(t=t||{}).userId=e;var r=this.getUrl("Genres",t);return this.getJSON(r)}},{key:"getMusicGenres",value:function(e,t){if(!e)throw new Error("null userId");(t=t||{}).userId=e;var r=this.getUrl("MusicGenres",t);return this.getJSON(r)}},{key:"getPeople",value:function(e,t){if(!e)throw new Error("null userId");(t=t||{}).userId=e;var r=this.getUrl("Persons",t);return this.getJSON(r)}},{key:"getStudios",value:function(e,t){if(!e)throw new Error("null userId");(t=t||{}).userId=e;var r=this.getUrl("Studios",t);return this.getJSON(r)}},{key:"getLocalTrailers",value:function(e,t){if(!e)throw new Error("null userId");if(!t)throw new Error("null itemId");var r=this.getUrl("Users/".concat(e,"/Items/").concat(t,"/LocalTrailers"));return this.getJSON(r)}},{key:"getAdditionalVideoParts",value:function(e,t){if(!t)throw new Error("null itemId");var r={};e&&(r.userId=e);var n=this.getUrl("Videos/".concat(t,"/AdditionalParts"),r);return this.getJSON(n)}},{key:"getThemeMedia",value:function(e,t,r){if(!t)throw new Error("null itemId");var n={};e&&(n.userId=e),n.InheritFromParent=r||!1;var i=this.getUrl("Items/".concat(t,"/ThemeMedia"),n);return this.getJSON(i)}},{key:"getSearchHints",value:function(e){var t=this.getUrl("Search/Hints",e),r=this.serverId();return this.getJSON(t).then((function(e){return e.SearchHints.forEach((function(e){e.ServerId=r})),e}))}},{key:"getSpecialFeatures",value:function(e,t){if(!e)throw new Error("null userId");if(!t)throw new Error("null itemId");var r=this.getUrl("Users/".concat(e,"/Items/").concat(t,"/SpecialFeatures"));return this.getJSON(r)}},{key:"getDateParamValue",value:function(e){function t(e){return e<10?"0".concat(e):e}var r=e;return"".concat(r.getFullYear()).concat(t(r.getMonth()+1)).concat(t(r.getDate())).concat(t(r.getHours())).concat(t(r.getMinutes())).concat(t(r.getSeconds()))}},{key:"markPlayed",value:function(e,t,r){if(!e)throw new Error("null userId");if(!t)throw new Error("null itemId");var n={};r&&(n.DatePlayed=this.getDateParamValue(r));var i=this.getUrl("Users/".concat(e,"/PlayedItems/").concat(t),n);return this.ajax({type:"POST",url:i,dataType:"json"})}},{key:"markUnplayed",value:function(e,t){if(!e)throw new Error("null userId");if(!t)throw new Error("null itemId");var r=this.getUrl("Users/".concat(e,"/PlayedItems/").concat(t));return this.ajax({type:"DELETE",url:r,dataType:"json"})}},{key:"updateFavoriteStatus",value:function(e,t,r){if(!e)throw new Error("null userId");if(!t)throw new Error("null itemId");var n=this.getUrl("Users/".concat(e,"/FavoriteItems/").concat(t)),i=r?"POST":"DELETE";return this.ajax({type:i,url:n,dataType:"json"})}},{key:"updateUserItemRating",value:function(e,t,r){if(!e)throw new Error("null userId");if(!t)throw new Error("null itemId");var n=this.getUrl("Users/".concat(e,"/Items/").concat(t,"/Rating"),{likes:r});return this.ajax({type:"POST",url:n,dataType:"json"})}},{key:"getItemCounts",value:function(e){var t={};e&&(t.userId=e);var r=this.getUrl("Items/Counts",t);return this.getJSON(r)}},{key:"clearUserItemRating",value:function(e,t){if(!e)throw new Error("null userId");if(!t)throw new Error("null itemId");var r=this.getUrl("Users/".concat(e,"/Items/").concat(t,"/Rating"));return this.ajax({type:"DELETE",url:r,dataType:"json"})}},{key:"reportPlaybackStart",value:function(e){if(!e)throw new Error("null options");this.lastPlaybackProgressReport=0,this.lastPlaybackProgressReportTicks=null,g(this),w(this);var t=this.getUrl("Sessions/Playing");return this.ajax({type:"POST",data:JSON.stringify(e),contentType:"application/json",url:t})}},{key:"reportPlaybackProgress",value:function(e){if(!e)throw new Error("null options");var t=e.EventName||"timeupdate",r=h[t]||0,n=(new Date).getTime()-(this.lastPlaybackProgressReport||0),i=e.PositionTicks;if(n=5e7&&(r=0)}if(r<(void 0!==this.reportPlaybackProgressTimeout?this.reportPlaybackProgressTimeout:1e6)&&w(this),this.lastPlaybackProgressOptions=e,this.reportPlaybackProgressPromise)return Promise.resolve();var o,s=this,l=!1,u=function(){s.reportPlaybackProgressPromise===o&&(delete s.lastPlaybackProgressOptions,delete s.reportPlaybackProgressTimeout,delete s.reportPlaybackProgressPromise,delete s.reportPlaybackProgressCancel)},c=Math.max(0,r-n);return o=new Promise((function(e,t){return setTimeout(e,c)})).then((function(){return l?Promise.resolve():function(e){if(u(),!e)throw new Error("null options");s.lastPlaybackProgressReport=(new Date).getTime(),s.lastPlaybackProgressReportTicks=e.PositionTicks;var t=s.getUrl("Sessions/Playing/Progress");return s.ajax({type:"POST",data:JSON.stringify(e),contentType:"application/json",url:t})}(s.lastPlaybackProgressOptions)})).finally((function(){u()})),this.reportPlaybackProgressTimeout=r,this.reportPlaybackProgressPromise=o,this.reportPlaybackProgressCancel=function(){l=!0,u()},o}},{key:"reportOfflineActions",value:function(e){if(!e)throw new Error("null actions");var t=this.getUrl("Sync/OfflineActions");return this.ajax({type:"POST",data:JSON.stringify(e),contentType:"application/json",url:t})}},{key:"syncData",value:function(e){if(!e)throw new Error("null data");var t=this.getUrl("Sync/Data");return this.ajax({type:"POST",data:JSON.stringify(e),contentType:"application/json",url:t,dataType:"json"})}},{key:"getReadySyncItems",value:function(e){if(!e)throw new Error("null deviceId");var t=this.getUrl("Sync/Items/Ready",{TargetId:e});return this.getJSON(t)}},{key:"reportSyncJobItemTransferred",value:function(e){if(!e)throw new Error("null syncJobItemId");var t=this.getUrl("Sync/JobItems/".concat(e,"/Transferred"));return this.ajax({type:"POST",url:t})}},{key:"cancelSyncItems",value:function(e,t){if(!e)throw new Error("null itemIds");var r=this.getUrl("Sync/".concat(t||this.deviceId(),"/Items"),{ItemIds:e.join(",")});return this.ajax({type:"DELETE",url:r})}},{key:"reportPlaybackStopped",value:function(e){if(!e)throw new Error("null options");this.lastPlaybackProgressReport=0,this.lastPlaybackProgressReportTicks=null,v(this),w(this);var t=this.getUrl("Sessions/Playing/Stopped");return this.ajax({type:"POST",data:JSON.stringify(e),contentType:"application/json",url:t})}},{key:"sendPlayCommand",value:function(e,t){if(!e)throw new Error("null sessionId");if(!t)throw new Error("null options");var r=this.getUrl("Sessions/".concat(e,"/Playing"),t);return this.ajax({type:"POST",url:r})}},{key:"sendCommand",value:function(e,t){if(!e)throw new Error("null sessionId");if(!t)throw new Error("null command");var r={type:"POST",url:this.getUrl("Sessions/".concat(e,"/Command"))};return r.data=JSON.stringify(t),r.contentType="application/json",this.ajax(r)}},{key:"sendMessageCommand",value:function(e,t){if(!e)throw new Error("null sessionId");if(!t)throw new Error("null options");var r={type:"POST",url:this.getUrl("Sessions/".concat(e,"/Message"))};return r.data=JSON.stringify(t),r.contentType="application/json",this.ajax(r)}},{key:"sendPlayStateCommand",value:function(e,t,r){if(!e)throw new Error("null sessionId");if(!t)throw new Error("null command");var n=this.getUrl("Sessions/".concat(e,"/Playing/").concat(t),r||{});return this.ajax({type:"POST",url:n})}},{key:"getSyncPlayGroups",value:function(){var e=this.getUrl("SyncPlay/List");return this.ajax({type:"GET",url:e})}},{key:"createSyncPlayGroup",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.getUrl("SyncPlay/New");return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"joinSyncPlayGroup",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.getUrl("SyncPlay/Join");return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"leaveSyncPlayGroup",value:function(){var e=this.getUrl("SyncPlay/Leave");return this.ajax({type:"POST",url:e})}},{key:"sendSyncPlayPing",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.getUrl("SyncPlay/Ping");return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"requestSyncPlaySetNewQueue",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.getUrl("SyncPlay/SetNewQueue");return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"requestSyncPlaySetPlaylistItem",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.getUrl("SyncPlay/SetPlaylistItem");return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"requestSyncPlayRemoveFromPlaylist",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.getUrl("SyncPlay/RemoveFromPlaylist");return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"requestSyncPlayMovePlaylistItem",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.getUrl("SyncPlay/MovePlaylistItem");return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"requestSyncPlayQueue",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.getUrl("SyncPlay/Queue");return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"requestSyncPlayUnpause",value:function(){var e=this.getUrl("SyncPlay/Unpause");return this.ajax({type:"POST",url:e})}},{key:"requestSyncPlayPause",value:function(){var e=this.getUrl("SyncPlay/Pause");return this.ajax({type:"POST",url:e})}},{key:"requestSyncPlaySeek",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.getUrl("SyncPlay/Seek");return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"requestSyncPlayNextItem",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.getUrl("SyncPlay/NextItem");return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"requestSyncPlayPreviousItem",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.getUrl("SyncPlay/PreviousItem");return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"requestSyncPlaySetRepeatMode",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.getUrl("SyncPlay/SetRepeatMode");return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"requestSyncPlaySetShuffleMode",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.getUrl("SyncPlay/SetShuffleMode");return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"requestSyncPlayBuffering",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.getUrl("SyncPlay/Buffering");return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"requestSyncPlayReady",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.getUrl("SyncPlay/Ready");return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"requestSyncPlaySetIgnoreWait",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.getUrl("SyncPlay/SetIgnoreWait");return this.ajax({type:"POST",url:t,data:JSON.stringify(e),contentType:"application/json"})}},{key:"createPackageReview",value:function(e){var t=this.getUrl("Packages/Reviews/".concat(e.id),e);return this.ajax({type:"POST",url:t})}},{key:"getPackageReviews",value:function(e,t,r,n){if(!e)throw new Error("null packageId");var i={};t&&(i.MinRating=t),r&&(i.MaxRating=r),n&&(i.Limit=n);var a=this.getUrl("Packages/".concat(e,"/Reviews"),i);return this.getJSON(a)}},{key:"getSavedEndpointInfo",value:function(){return this._endPointInfo}},{key:"getEndpointInfo",value:function(){var e=this._endPointInfo;if(e)return Promise.resolve(e);var t=this;return this.getJSON(this.getUrl("System/Endpoint")).then((function(e){return k(t,e),e}))}},{key:"getLatestItems",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.getJSON(this.getUrl("Users/".concat(this.getCurrentUserId(),"/Items/Latest"),e))}},{key:"getFilters",value:function(e){return this.getJSON(this.getUrl("Items/Filters2",e))}},{key:"setSystemInfo",value:function(e){this._serverVersion=e.Version}},{key:"serverVersion",value:function(){return this._serverVersion}},{key:"isMinServerVersion",value:function(e){var t=this.serverVersion();return!!t&&function(e,t){e=e.split("."),t=t.split(".");for(var r=0,n=Math.max(e.length,t.length);ra)return 1}return 0}(t,e)>=0}},{key:"handleMessageReceived",value:function(e){E(this,e)}}])&&d(t.prototype,r),e}();function D(e){return(D="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function M(e,t){for(var r=0;rt.length&&0===e.indexOf(t))}function K(e,t){return z(e,t)?e.substr(t.length):e}function X(e){return e?W(e)?e:"local:".concat(e):null}function Y(e){e.Id=X(e.Id),e.SeriesId=X(e.SeriesId),e.SeasonId=X(e.SeasonId),e.AlbumId=X(e.AlbumId),e.ParentId=X(e.ParentId),e.ParentThumbItemId=X(e.ParentThumbItemId),e.ParentPrimaryImageItemId=X(e.ParentPrimaryImageItemId),e.PrimaryImageItemId=X(e.PrimaryImageItemId),e.ParentLogoItemId=X(e.ParentLogoItemId),e.ParentBackdropItemId=X(e.ParentBackdropItemId),e.ParentBackdropImageTags=null}function Z(e,t,r){return e.getLocalFolders(t,r).then((function(r){var n=null;return r.length>0&&(n={Name:e.downloadsTitleText||"Downloads",ServerId:t,Id:"localview",Type:"localview",IsFolder:!0}),Promise.resolve(n)}))}var $=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_(e,t)}(o,e);var t,r,n,i,a=(n=o,i=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,t=V(n);if(i){var r=V(this).constructor;e=Reflect.construct(t,arguments,r)}else e=t.apply(this,arguments);return F(this,e)});function o(e,t,r,n,i,s,l){var u;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),(u=a.call(this,e,t,r,n,i,s)).localAssetManager=l,u}return t=o,(r=[{key:"getPlaybackInfo",value:function(e,t,r){var n=function(){return R.prototype.getPlaybackInfo.call(i,e,t,r)};if(W(e))return this.localAssetManager.getLocalItem(this.serverId(),Q(e)).then((function(e){return{MediaSources:e.Item.MediaSources.map((function(e){return e.SupportsDirectPlay=!0,e.SupportsDirectStream=!1,e.SupportsTranscoding=!1,e.IsLocal=!0,e}))}}),n);var i=this;return this.localAssetManager.getLocalItem(this.serverId(),e).then((function(a){if(a){var o=a.Item.MediaSources.map((function(e){return e.SupportsDirectPlay=!0,e.SupportsDirectStream=!1,e.SupportsTranscoding=!1,e.IsLocal=!0,e}));return i.localAssetManager.fileExists(a.LocalPath).then((function(n){if(n){var a={MediaSources:o};return Promise.resolve(a)}return R.prototype.getPlaybackInfo.call(i,e,t,r)}),n)}return R.prototype.getPlaybackInfo.call(i,e,t,r)}),n)}},{key:"getItems",value:function(e,t){var r,n=this.serverInfo();if(n&&"localview"===t.ParentId)return this.getLocalFolders(n.Id,e).then((function(e){var t={Items:e,TotalRecordCount:e.length};return Promise.resolve(t)}));if(n&&t&&(W(t.ParentId)||W(t.SeriesId)||W(t.SeasonId)||q(t.ParentId)||W(t.AlbumIds)))return this.localAssetManager.getViewItems(n.Id,e,t).then((function(e){e.forEach((function(e){Y(e)}));var t={Items:e,TotalRecordCount:e.length};return Promise.resolve(t)}));if(t&&t.ExcludeItemIds&&t.ExcludeItemIds.length){var i=t.ExcludeItemIds.split(",");for(r=0;r0?Promise.resolve(r[0]):Promise.reject()})):W(t)&&(r=this.serverInfo())?this.localAssetManager.getLocalItem(r.Id,Q(t)).then((function(e){return Y(e.Item),Promise.resolve(e.Item)})):R.prototype.getItem.call(this,e,t)}},{key:"getLocalFolders",value:function(e){var t=this.serverInfo();return e=e||t.UserId,this.localAssetManager.getViews(t.Id,e)}},{key:"getNextUpEpisodes",value:function(e){return e.SeriesId&&W(e.SeriesId)?Promise.resolve({Items:[],TotalRecordCount:0}):R.prototype.getNextUpEpisodes.call(this,e)}},{key:"getSeasons",value:function(e,t){return W(e)?(t.SeriesId=e,t.IncludeItemTypes="Season",this.getItems(this.getCurrentUserId(),t)):R.prototype.getSeasons.call(this,e,t)}},{key:"getEpisodes",value:function(e,t){return W(t.SeasonId)||W(t.seasonId)||W(e)?(t.SeriesId=e,t.IncludeItemTypes="Episode",this.getItems(this.getCurrentUserId(),t)):R.prototype.getEpisodes.call(this,e,t)}},{key:"getLatestOfflineItems",value:function(e){e.SortBy="DateCreated",e.SortOrder="Descending";var t=this.serverInfo();return t?this.localAssetManager.getViewItems(t.Id,null,e).then((function(e){return e.forEach((function(e){Y(e)})),Promise.resolve(e)})):Promise.resolve([])}},{key:"getThemeMedia",value:function(e,t,r){return q(t)||W(t)||H(t)?Promise.reject():R.prototype.getThemeMedia.call(this,e,t,r)}},{key:"getSpecialFeatures",value:function(e,t){return W(t)?Promise.resolve([]):R.prototype.getSpecialFeatures.call(this,e,t)}},{key:"getSimilarItems",value:function(e,t){return W(e)?Promise.resolve({Items:[],TotalRecordCount:0}):R.prototype.getSimilarItems.call(this,e,t)}},{key:"updateFavoriteStatus",value:function(e,t,r){return W(t)?Promise.resolve():R.prototype.updateFavoriteStatus.call(this,e,t,r)}},{key:"getScaledImageUrl",value:function(e,t){if(W(e)||t&&t.itemid&&W(t.itemid)){var r=this.serverInfo(),n=Q(e);return this.localAssetManager.getImageUrl(r.Id,n,t)}return R.prototype.getScaledImageUrl.call(this,e,t)}},{key:"reportPlaybackStart",value:function(e){if(!e)throw new Error("null options");return W(e.ItemId)?Promise.resolve():R.prototype.reportPlaybackStart.call(this,e)}},{key:"reportPlaybackProgress",value:function(e){if(!e)throw new Error("null options");if(W(e.ItemId)){var t=this.serverInfo();if(t){var r=this;return this.localAssetManager.getLocalItem(t.Id,Q(e.ItemId)).then((function(t){var n=t.Item;return"Video"===n.MediaType||"AudioBook"===n.Type?(n.UserData=n.UserData||{},n.UserData.PlaybackPositionTicks=e.PositionTicks,n.UserData.PlayedPercentage=Math.min(n.RunTimeTicks?(e.PositionTicks||0)/n.RunTimeTicks*100:0,100),r.localAssetManager.addOrUpdateLocalItem(t)):Promise.resolve()}))}return Promise.resolve()}return R.prototype.reportPlaybackProgress.call(this,e)}},{key:"reportPlaybackStopped",value:function(e){if(!e)throw new Error("null options");if(W(e.ItemId)){var t=this.serverInfo(),r={Date:(new Date).getTime(),ItemId:Q(e.ItemId),PositionTicks:e.PositionTicks,ServerId:t.Id,Type:0,UserId:this.getCurrentUserId()};return this.localAssetManager.recordUserAction(r)}return R.prototype.reportPlaybackStopped.call(this,e)}},{key:"getIntros",value:function(e){return W(e)?Promise.resolve({Items:[],TotalRecordCount:0}):R.prototype.getIntros.call(this,e)}},{key:"getInstantMixFromItem",value:function(e,t){return W(e)?Promise.resolve({Items:[],TotalRecordCount:0}):R.prototype.getInstantMixFromItem.call(this,e,t)}},{key:"getItemDownloadUrl",value:function(e){if(W(e)){var t=this.serverInfo();if(t)return this.localAssetManager.getLocalItem(t.Id,Q(e)).then((function(e){return Promise.resolve(e.LocalPath)}))}return R.prototype.getItemDownloadUrl.call(this,e)}}])&&M(t.prototype,r),o}(R);function ee(e,t){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:{};!1!==t.reportCapabilities&&e.reportCapabilities(s),e.enableAutomaticBitrateDetection=t.enableAutomaticBitrateDetection,!1!==t.enableWebSocket&&(console.log("calling apiClient.ensureWebSocket"),e.ensureWebSocket())}function d(e,t,r){return l._getOrAddApiClient(e,t),(l.onLocalUserSignedIn?l.onLocalUserSignedIn.call(l,r):Promise.resolve()).then((function(){i.trigger(l,"localusersignedin",[r])}))}function h(e,t){return ae({type:"GET",url:ie(t,"System/Info"),dataType:"json",headers:{"X-MediaBrowser-Token":e.AccessToken}}).then((function(t){return ne(e,t),Promise.resolve()}),(function(){return e.UserId=null,e.AccessToken=null,Promise.resolve()}))}function v(e){var t={serverId:(e.serverInfo()||{}).Id};return e.logout().then((function(){i.trigger(l,"localusersignedout",[t])}),(function(){i.trigger(l,"localusersignedout",[t])}))}function f(e){if(e.Address&&e.EndpointAddress){var t=e.EndpointAddress.split(":")[0],r=e.Address.split(":");if(r.length>1){var n=r[r.length-1];isNaN(parseInt(n))||(t+=":".concat(n))}return se(t)}return null}function g(e,r,n,a,o,s){var u=arguments.length>6&&void 0!==arguments[6]?arguments[6]:{},v=t.credentials();if(!1===u.enableAutoLogin)e.UserId=null,e.AccessToken=null;else if(e.AccessToken&&o)return void h(e,a).then((function(){g(e,r,n,a,!1,s,u)}));ne(e,r),e.LastConnectionMode=n,!1!==u.updateDateLastAccessed&&(e.DateLastAccessed=(new Date).getTime()),t.addOrUpdateServer(v.Servers,e),t.credentials(v);var f={Servers:[]};f.ApiClient=l._getOrAddApiClient(e,a),f.ApiClient.setSystemInfo(r),f.State=e.AccessToken&&!1!==u.enableAutoLogin?"SignedIn":"ServerSignIn",f.Servers.push(e),f.ApiClient.enableAutomaticBitrateDetection=u.enableAutomaticBitrateDetection,f.ApiClient.updateServerInfo(e,a);var y=function(){s(f),i.trigger(l,"connected",[f])};"SignedIn"===f.State?(c(f.ApiClient,u),f.ApiClient.getCurrentUser().then((function(t){d(e,a,t).then(y,y)}),y)):y()}function y(e,t){var r={ManualAddress:e,LastConnectionMode:2};return l.connectToServer(r,t).then((function(e){return"Unavailable"===e.State?Promise.reject():e}))}this._apiClients=[],l._minServerVersion="3.2.33",l.appVersion=function(){return n},l.appName=function(){return r},l.capabilities=function(){return s},l.deviceId=function(){return o},l.credentialProvider=function(){return t},l.getServerInfo=function(e){return t.credentials().Servers.filter((function(t){return t.Id===e}))[0]},l.getLastUsedServer=function(){var e=t.credentials().Servers;return e.sort((function(e,t){return(t.DateLastAccessed||0)-(e.DateLastAccessed||0)})),e.length?e[0]:null},l.addApiClient=function(e){l._apiClients.push(e);var r=t.credentials().Servers.filter((function(t){return le(t.ManualAddress,e.serverAddress())||le(t.LocalAddress,e.serverAddress())||le(t.RemoteAddress,e.serverAddress())})),n=r.length?r[0]:e.serverInfo();if(n.DateLastAccessed=(new Date).getTime(),n.LastConnectionMode=2,n.ManualAddress=e.serverAddress(),e.manualAddressOnly&&(n.manualAddressOnly=!0),e.serverInfo(n),e.onAuthenticated=function(e,t){return u(e,t,{},!0)},!r.length){var a=t.credentials();a.Servers=[n],t.credentials(a)}i.trigger(l,"apiclientcreated",[e])},l.clearData=function(){console.log("connection manager clearing data");var e=t.credentials();e.Servers=[],t.credentials(e)},l._getOrAddApiClient=function(e,t){var s=l.getApiClient(e.Id);return s||(s=new R(t,r,n,a,o),l._apiClients.push(s),s.serverInfo(e),s.onAuthenticated=function(e,t){return u(e,t,{},!0)},i.trigger(l,"apiclientcreated",[s])),console.log("returning instance from getOrAddApiClient"),s},l.getOrCreateApiClient=function(e){var r=t.credentials().Servers.filter((function(t){return le(t.Id,e)}));if(!r.length)throw new Error("Server not found: ".concat(e));var n=r[0];return l._getOrAddApiClient(n,te(n,n.LastConnectionMode))},l.user=function(e){return new Promise((function(t,r){var n;e&&e.getCurrentUserId()&&e&&e.getCurrentUserId()&&e.getCurrentUser().then((function(e){var r=function(e){return e&&e.PrimaryImageTag?{url:l.getApiClient(e).getUserImageUrl(e.Id,{tag:e.PrimaryImageTag,type:"Primary"}),supportsParams:!0}:{url:null,supportsParams:!1}}(n=e);t({localUser:n,name:n?n.Name:null,imageUrl:r.url,supportsImageParams:r.supportsParams})}))}))},l.logout=function(){for(var e=[],r=0,n=l._apiClients.length;r=r.numAddresses&&i())}))}(n.url,n.mode,r,e,t)}),n.timeout)}))}))).then((function(n){var i=n.url,a=n.connectionMode;n=n.data,1===function(e,t){e=e.split("."),t=t.split(".");for(var r=0,n=Math.max(e.length,t.length);ra)return 1}return 0}(l.minServerVersion(),n.Version)?(console.log("minServerVersion requirement not met. Server version: "+n.Version),r({State:"ServerUpdateNeeded",Servers:[e]})):e.Id&&n.Id!==e.Id?(console.log("http request succeeded, but found a different server Id than what was expected"),re(0,r)):g(e,n,a,i,!0,r,t)}),(function(){re(0,r)}))}))},l.connectToAddress=function(e,t){if(!e)return Promise.reject();e=se(e);var r=[];/^[^:]+:\/\//.test(e)?r.push(e):(r.push("https://".concat(e)),r.push("http://".concat(e)));var n=0;return y(r[n],t).catch((function e(){return console.log("connectToAddress ".concat(r[n]," failed")),++n