1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

auto-organize fix

This commit is contained in:
Luke Pulverenti 2015-06-08 17:32:20 -04:00
parent bbfda77868
commit f64e0c7c53
54 changed files with 838 additions and 666 deletions

View file

@ -30,62 +30,6 @@
//initAjax();
}
var baseAjaxMethod;
var currentId = 0;
function getNewRequestId() {
var id = currentId++;
return id.toString();
}
function initAjax() {
baseAjaxMethod = AjaxApi.ajax;
AjaxApi.ajax = sendRequest;
}
function sendRequest(request) {
if (request.data || request.contentType || request.dataType != 'json') {
return baseAjaxMethod(request);
}
var deferred = DeferredBuilder.Deferred();
var id = getNewRequestId();
request.headers = request.headers || {};
if (request.dataType == 'json') {
request.headers.accept = 'application/json';
}
var requestHeaders = [];
for (name in request.headers) {
requestHeaders.push(name + "=" + request.headers[name]);
}
ApiClientBridge.sendRequest(request.url, request.type, requestHeaders.join('|||||'), "window.AndroidAjax.onResponse", id);
Events.on(AndroidAjax, 'response' + id, function (e, status, response) {
Events.off(AndroidAjax, 'response' + id);
response = decodeURIComponent(response);
if (status >= 400) {
alert(status);
deferred.reject();
}
else if (request.dataType == 'json') {
deferred.resolveWith(null, [JSON.parse(response)]);
}
else {
deferred.resolveWith(null, [response]);
}
});
return deferred.promise();
}
Events.on(ConnectionManager.credentialProvider(), 'credentialsupdated', updateCredentials);
updateCredentials();

View file

@ -0,0 +1,84 @@
(function (globalScope, localStorage, sessionStorage) {
function myStore(defaultObject) {
var self = this;
self.localData = {};
var isDefaultAvailable;
if (defaultObject) {
try {
defaultObject.setItem('_test', '0');
isDefaultAvailable = true;
} catch (e) {
}
}
self.setItem = function (name, value) {
if (isDefaultAvailable) {
defaultObject.setItem(name, value);
} else {
self.localData[name] = value;
}
};
self.getItem = function (name) {
if (isDefaultAvailable) {
return defaultObject.getItem(name);
}
return self.localData[name];
};
self.removeItem = function (name) {
if (isDefaultAvailable) {
defaultObject.removeItem(name);
} else {
self.localData[name] = null;
}
};
}
function preferencesStore() {
var self = this;
self.setItem = function (name, value) {
AndroidSharedPreferences.set(name, value);
};
self.getItem = function (name) {
return AndroidSharedPreferences.get(name);
};
self.removeItem = function (name) {
AndroidSharedPreferences.remove(name);
};
function migrateKey(key) {
var json = localStorage.getItem(key);
if (json) {
self.setItem(key, json);
localStorage.removeItem(key);
}
}
function migrate() {
migrateKey('servercredentials3');
}
migrate();
}
globalScope.appStorage = new preferencesStore();
globalScope.sessionStore = new myStore(sessionStorage);
})(window, window.localStorage, window.sessionStorage);

24
dashboard-ui/thirdparty/cordova/back.js vendored Normal file
View file

@ -0,0 +1,24 @@
(function () {
Dashboard.exit = function () {
if (navigator.app && navigator.app.exitApp) {
navigator.app.exitApp();
} else {
Dashboard.logout();
}
};
function onBackKeyDown(e) {
if (Dashboard.exitOnBack()) {
e.preventDefault();
Dashboard.exit();
}
else {
history.back();
}
}
document.addEventListener("backbutton", onBackKeyDown, false);
})();

View file

@ -1,14 +1,15 @@
(function () {
var PlayerName = "Chromecast";
var ApplicationID = "2D4B1DA3";
var currentWebAppSession;
var currentDevice;
function chromecastPlayer() {
var self = this;
var PlayerName = "Chromecast";
var ApplicationID = "2D4B1DA3";
var currentWebAppSession;
var currentDevice;
var currentDeviceId;
// MediaController needs this
self.name = PlayerName;
@ -301,9 +302,7 @@
self.getTargets = function () {
var manager = ConnectSDK.discoveryManager;
return manager.getDeviceList().filter(function (d) {
return ConnectHelper.getDeviceList().filter(function (d) {
return isChromecast(d.getModelName()) || isChromecast(d.getFriendlyName());
@ -469,6 +468,7 @@
MediaController.setActivePlayer(PlayerName, convertDeviceToTarget(device));
currentDevice = device;
currentDeviceId = device.getId();
$(castPlayer).trigger('connect');
@ -584,7 +584,7 @@
var deferred = $.Deferred();
var device = ConnectSDK.discoveryManager.getDeviceList().filter(function (d) {
var device = ConnectHelper.getDeviceList().filter(function (d) {
return d.getId() == target.id;
})[0];
@ -629,22 +629,31 @@
$(MediaController).on('playerchange', function (e, newPlayer, newTarget) {
if (currentDevice) {
if (newTarget.id != currentDevice.getId()) {
if (newTarget.id != currentDeviceId) {
if (currentWebAppSession) {
console.log('Disconnecting from chromecast');
currentDevice.disconnect();
//currentDevice.disconnect();
currentDevice = null;
currentDeviceId = null;
}
}
}
});
function onResume() {
var deviceId = currentDeviceId;
if (deviceId) {
self.tryPair({
id: deviceId
});
}
}
document.addEventListener("resume", onResume, false);
}
function initSdk() {
MediaController.registerPlayer(new chromecastPlayer());
}
initSdk();
MediaController.registerPlayer(new chromecastPlayer());
})();

View file

@ -12,11 +12,25 @@
// new ConnectSDK.CapabilityFilter(["MediaPlayer.Display.Video", "MediaControl.Pause"])
//]);
manager.on('devicelistchanged', onDeviceListChanged);
manager.startDiscovery();
requirejs(['thirdparty/cordova/chromecast', 'thirdparty/cordova/generaldevice']);
}
function onDeviceListChanged(list) {
}
function getDeviceList() {
return ConnectSDK.discoveryManager.getDeviceList();
}
window.ConnectHelper = {
getDeviceList: getDeviceList
};
Dashboard.ready(initSdk);
})();

View file

@ -400,9 +400,7 @@
self.getTargets = function () {
var manager = ConnectSDK.discoveryManager;
return manager.getDeviceList().filter(function (d) {
return ConnectHelper.getDeviceList().filter(function (d) {
return isValid(d);
@ -506,7 +504,7 @@
var deferred = $.Deferred();
var device = ConnectSDK.discoveryManager.getDeviceList().filter(function (d) {
var device = ConnectHelper.getDeviceList().filter(function (d) {
return d.getId() == target.id;
})[0];

View file

@ -0,0 +1,28 @@
(function () {
// Handle the volume down button
//
function onVolumeDownKeyDown() {
MediaController.volumeDown();
}
// Handle the volume up button
//
function onVolumeUpKeyDown() {
MediaController.volumeUp();
}
$(MediaController).on('playerchange', function (e, newPlayer, newTarget) {
document.removeEventListener("volumedownbutton", onVolumeDownKeyDown, false);
document.removeEventListener("volumeupbutton", onVolumeUpKeyDown, false);
if (!newPlayer.localPlayer) {
document.addEventListener("volumedownbutton", onVolumeDownKeyDown, false);
document.addEventListener("volumeupbutton", onVolumeUpKeyDown, false);
}
});
})();

View file

@ -0,0 +1,87 @@
(function (globalScope) {
function getResultCode(result) {
if (result != null && result.resultCode != null) {
return result.resultCode;
}
return result;
}
function closeSocket(socketId) {
try {
chrome.sockets.udp.close(socketId);
} catch (err) {
}
}
function stringToArrayBuffer(string) {
// UTF-16LE
var buf = new ArrayBuffer(string.length * 2);
var bufView = new Uint16Array(buf);
for (var i = 0, strLen = string.length; i < strLen; i++) {
bufView[i] = string.charCodeAt(i);
}
return buf;
}
// https://github.com/agnat/node_wake_on_lan/blob/master/wake_on_lan.js
globalScope.WakeOnLan = {
send: function (info) {
var deferred = DeferredBuilder.Deferred();
var chrome = globalScope.chrome;
if (!chrome) {
deferred.resolve();
return deferred.promise();
}
var port = info.Port || 9;
//chrome.sockets.udp.create(function (createInfo) {
// if (!createInfo) {
// console.log('create fail');
// return;
// }
// if (!createInfo.socketId) {
// console.log('create fail');
// return;
// }
// var socketId = createInfo.socketId;
// console.log('chrome.sockets.udp.bind');
// chrome.sockets.udp.bind(createInfo.socketId, '0.0.0.0', 0, function (bindResult) {
// if (getResultCode(bindResult) != 0) {
// console.log('bind fail: ' + bindResult);
// deferred.resolve();
// closeSocket(socketId);
// }
// var data = stringToArrayBuffer('who is EmbyServer?');
// console.log('chrome.sockets.udp.send');
// chrome.sockets.udp.send(createInfo.socketId, data, '255.255.255.255', port, function (sendResult) {
// deferred.resolve();
// closeSocket(socketId);
// });
// });
//});
deferred.resolve();
return deferred.promise();
}
};
})(window);