strip wakeonlan from apiclient

This commit is contained in:
dkanada 2019-01-16 18:32:00 +09:00
parent 4e8fbe9627
commit 1b95ca7d14
2 changed files with 5 additions and 44 deletions

View File

@ -1,4 +1,4 @@
define(["events", "appStorage", "wakeOnLan"], function(events, appStorage, wakeOnLan) { define(["events", "appStorage"], function(events, appStorage) {
"use strict"; "use strict";
function redetectBitrate(instance) { function redetectBitrate(instance) {
@ -201,36 +201,6 @@ define(["events", "appStorage", "wakeOnLan"], function(events, appStorage, wakeO
ratio && (options.minScale && (ratio = Math.max(options.minScale, ratio)), options.width && (options.width = Math.round(options.width * ratio)), options.height && (options.height = Math.round(options.height * ratio)), options.maxWidth && (options.maxWidth = Math.round(options.maxWidth * ratio)), options.maxHeight && (options.maxHeight = Math.round(options.maxHeight * ratio))), options.quality = options.quality || instance.getDefaultImageQuality(options.type), instance.normalizeImageOptions && instance.normalizeImageOptions(options) ratio && (options.minScale && (ratio = Math.max(options.minScale, ratio)), options.width && (options.width = Math.round(options.width * ratio)), options.height && (options.height = Math.round(options.height * ratio)), options.maxWidth && (options.maxWidth = Math.round(options.maxWidth * ratio)), options.maxHeight && (options.maxHeight = Math.round(options.maxHeight * ratio))), options.quality = options.quality || instance.getDefaultImageQuality(options.type), instance.normalizeImageOptions && instance.normalizeImageOptions(options)
} }
function getCachedWakeOnLanInfo(instance) {
var serverId = instance.serverId(),
json = appStorage.getItem("server-" + serverId + "-wakeonlaninfo");
return json ? JSON.parse(json) : []
}
function refreshWakeOnLanInfoIfNeeded(instance) {
wakeOnLan.isSupported() && instance.accessToken() && !1 !== instance.enableAutomaticBitrateDetection && (console.log("refreshWakeOnLanInfoIfNeeded"), setTimeout(refreshWakeOnLanInfo.bind(instance), 1e4))
}
function refreshWakeOnLanInfo() {
var instance = this;
console.log("refreshWakeOnLanInfo"), instance.getWakeOnLanInfo().then(function(info) {
var serverId = instance.serverId();
return appStorage.setItem("server-" + serverId + "-wakeonlaninfo", JSON.stringify(info)), info
}, function(err) {
return []
})
}
function sendNextWakeOnLan(infos, index, resolve) {
if (index >= infos.length) return void resolve();
var info = infos[index];
console.log("sending wakeonlan to " + info.MacAddress), wakeOnLan.send(info).then(function(result) {
sendNextWakeOnLan(infos, index + 1, resolve)
}, function() {
sendNextWakeOnLan(infos, index + 1, resolve)
})
}
function compareVersions(a, b) { function compareVersions(a, b) {
a = a.split("."), b = b.split("."); a = a.split("."), b = b.split(".");
for (var i = 0, length = Math.max(a.length, b.length); i < length; i++) { for (var i = 0, length = Math.max(a.length, b.length); i < length; i++) {
@ -266,7 +236,7 @@ define(["events", "appStorage", "wakeOnLan"], function(events, appStorage, wakeO
} }
return this._serverAddress return this._serverAddress
}, ApiClient.prototype.onNetworkChange = function() { }, ApiClient.prototype.onNetworkChange = function() {
this.lastDetectedBitrate = 0, this.lastDetectedBitrateTime = 0, setSavedEndpointInfo(this, null), redetectBitrate(this), refreshWakeOnLanInfoIfNeeded(this) this.lastDetectedBitrate = 0, this.lastDetectedBitrateTime = 0, setSavedEndpointInfo(this, null), redetectBitrate(this)
}, ApiClient.prototype.getUrl = function(name, params, serverAddress) { }, ApiClient.prototype.getUrl = function(name, params, serverAddress) {
if (!name) throw new Error("Url name cannot be empty"); if (!name) throw new Error("Url name cannot be empty");
var url = serverAddress || this._serverAddress; var url = serverAddress || this._serverAddress;
@ -301,7 +271,7 @@ define(["events", "appStorage", "wakeOnLan"], function(events, appStorage, wakeO
} }
return this.fetchWithFailover(request, !0) return this.fetchWithFailover(request, !0)
}, ApiClient.prototype.setAuthenticationInfo = function(accessKey, userId) { }, ApiClient.prototype.setAuthenticationInfo = function(accessKey, userId) {
this._currentUser = null, this._serverInfo.AccessToken = accessKey, this._serverInfo.UserId = userId, redetectBitrate(this), refreshWakeOnLanInfoIfNeeded(this) this._currentUser = null, this._serverInfo.AccessToken = accessKey, this._serverInfo.UserId = userId, redetectBitrate(this)
}, ApiClient.prototype.serverInfo = function(info) { }, ApiClient.prototype.serverInfo = function(info) {
return info && (this._serverInfo = info), this._serverInfo return info && (this._serverInfo = info), this._serverInfo
}, ApiClient.prototype.getCurrentUserId = function() { }, ApiClient.prototype.getCurrentUserId = function() {
@ -360,7 +330,7 @@ define(["events", "appStorage", "wakeOnLan"], function(events, appStorage, wakeO
contentType: "application/json" contentType: "application/json"
}).then(function(result) { }).then(function(result) {
var afterOnAuthenticated = function() { var afterOnAuthenticated = function() {
redetectBitrate(instance), refreshWakeOnLanInfoIfNeeded(instance), resolve(result) redetectBitrate(instance), resolve(result)
}; };
instance.onAuthenticated ? instance.onAuthenticated(instance, result).then(afterOnAuthenticated) : afterOnAuthenticated() instance.onAuthenticated ? instance.onAuthenticated(instance, result).then(afterOnAuthenticated) : afterOnAuthenticated()
}, reject) }, reject)
@ -1579,19 +1549,10 @@ define(["events", "appStorage", "wakeOnLan"], function(events, appStorage, wakeO
return this.getJSON(this.getUrl("System/Endpoint")).then(function(endPointInfo) { return this.getJSON(this.getUrl("System/Endpoint")).then(function(endPointInfo) {
return setSavedEndpointInfo(instance, endPointInfo), endPointInfo return setSavedEndpointInfo(instance, endPointInfo), endPointInfo
}) })
}, ApiClient.prototype.getWakeOnLanInfo = function() {
return this.getJSON(this.getUrl("System/WakeOnLanInfo"))
}, ApiClient.prototype.getLatestItems = function(options) { }, ApiClient.prototype.getLatestItems = function(options) {
return options = options || {}, this.getJSON(this.getUrl("Users/" + this.getCurrentUserId() + "/Items/Latest", options)) return options = options || {}, this.getJSON(this.getUrl("Users/" + this.getCurrentUserId() + "/Items/Latest", options))
}, ApiClient.prototype.getFilters = function(options) { }, ApiClient.prototype.getFilters = function(options) {
return this.getJSON(this.getUrl("Items/Filters2", options)) return this.getJSON(this.getUrl("Items/Filters2", options))
}, ApiClient.prototype.supportsWakeOnLan = function() {
return !!wakeOnLan.isSupported() && getCachedWakeOnLanInfo(this).length > 0
}, ApiClient.prototype.wakeOnLan = function() {
var infos = getCachedWakeOnLanInfo(this);
return new Promise(function(resolve, reject) {
sendNextWakeOnLan(infos, 0, resolve)
})
}, ApiClient.prototype.setSystemInfo = function(info) { }, ApiClient.prototype.setSystemInfo = function(info) {
this._serverVersion = info.Version this._serverVersion = info.Version
}, ApiClient.prototype.serverVersion = function() { }, ApiClient.prototype.serverVersion = function() {

View File

@ -24,6 +24,6 @@ define(["events", "appStorage"], function(events, appStorage) {
var existing = list.filter(function(s) { var existing = list.filter(function(s) {
return s.Id === server.Id return s.Id === server.Id
})[0]; })[0];
return existing ? (existing.DateLastAccessed = Math.max(existing.DateLastAccessed || 0, server.DateLastAccessed || 0), existing.UserLinkType = server.UserLinkType, server.AccessToken && (existing.AccessToken = server.AccessToken, existing.UserId = server.UserId), server.ExchangeToken && (existing.ExchangeToken = server.ExchangeToken), server.RemoteAddress && (existing.RemoteAddress = server.RemoteAddress), server.ManualAddress && (existing.ManualAddress = server.ManualAddress), server.LocalAddress && (existing.LocalAddress = server.LocalAddress), server.Name && (existing.Name = server.Name), server.WakeOnLanInfos && server.WakeOnLanInfos.length && (existing.WakeOnLanInfos = server.WakeOnLanInfos), null != server.LastConnectionMode && (existing.LastConnectionMode = server.LastConnectionMode), server.ConnectServerId && (existing.ConnectServerId = server.ConnectServerId), existing) : (list.push(server), server) return existing ? (existing.DateLastAccessed = Math.max(existing.DateLastAccessed || 0, server.DateLastAccessed || 0), existing.UserLinkType = server.UserLinkType, server.AccessToken && (existing.AccessToken = server.AccessToken, existing.UserId = server.UserId), server.ExchangeToken && (existing.ExchangeToken = server.ExchangeToken), server.RemoteAddress && (existing.RemoteAddress = server.RemoteAddress), server.ManualAddress && (existing.ManualAddress = server.ManualAddress), server.LocalAddress && (existing.LocalAddress = server.LocalAddress), server.Name && (existing.Name = server.Name), null != server.LastConnectionMode && (existing.LastConnectionMode = server.LastConnectionMode), server.ConnectServerId && (existing.ConnectServerId = server.ConnectServerId), existing) : (list.push(server), server)
}, Credentials }, Credentials
}); });