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

update client sync

This commit is contained in:
Luke Pulverenti 2015-09-20 12:16:06 -04:00
parent 0db16cad5a
commit 8bf9a6f51e
12 changed files with 133 additions and 206 deletions

View file

@ -95,6 +95,13 @@
return deferred.promise(); return deferred.promise();
} }
function fileExists(path) {
var deferred = DeferredBuilder.Deferred();
deferred.resolveWith(null, [false]);
return deferred.promise();
}
window.LocalAssetManager = { window.LocalAssetManager = {
getLocalMediaSource: getLocalMediaSource, getLocalMediaSource: getLocalMediaSource,
saveOfflineUser: saveOfflineUser, saveOfflineUser: saveOfflineUser,
@ -110,7 +117,8 @@
downloadFile: downloadFile, downloadFile: downloadFile,
downloadSubtitles: downloadSubtitles, downloadSubtitles: downloadSubtitles,
hasImage: hasImage, hasImage: hasImage,
downloadImage: downloadImage downloadImage: downloadImage,
fileExists: fileExists
}; };
})(); })();

View file

@ -1,14 +0,0 @@
(function () {
window.FileSystemBridge = {
fileExists: function (path) {
return NativeFileSystem.fileExists(path);
},
translateFilePath: function (path) {
return 'file://' + NativeFileSystem.translateFilePath(path);
}
};
})();

View file

@ -1,14 +0,0 @@
(function () {
window.FileSystemBridge = {
fileExists: function (path) {
return false;
},
translateFilePath: function (path) {
return 'file://' + path;
}
};
})();

View file

@ -19,9 +19,9 @@
getLocalItem(itemId, serverId).done(function (localItem) { getLocalItem(itemId, serverId).done(function (localItem) {
if (localItem && localItem.MediaSources.length) { if (localItem && localItem.Item.MediaSources.length) {
var mediaSource = localItem.MediaSources[0]; var mediaSource = localItem.Item.MediaSources[0];
fileExists(mediaSource.Path).done(function (exists) { fileExists(mediaSource.Path).done(function (exists) {
@ -156,11 +156,11 @@
db.transaction(function (tx) { db.transaction(function (tx) {
tx.executeSql("SELECT json from offlineactions where ServerId=?", [serverId], function (tx, res) { tx.executeSql("SELECT Json from offlineactions where ServerId=?", [serverId], function (tx, res) {
var actions = []; var actions = [];
for (var i = 0, length = res.rows.length; i < length; i++) { for (var i = 0, length = res.rows.length; i < length; i++) {
actions.push(JSON.parse(res.rows.item(i).json)); actions.push(JSON.parse(res.rows.item(i).Json));
} }
deferred.resolveWith(null, [actions]); deferred.resolveWith(null, [actions]);
@ -260,7 +260,7 @@
var localItem = JSON.parse(res.rows.item(0).Json); var localItem = JSON.parse(res.rows.item(0).Json);
deferred.resolveWith(null, [item]); deferred.resolveWith(null, [localItem]);
} }
else { else {
deferred.resolveWith(null, [null]); deferred.resolveWith(null, [null]);
@ -350,7 +350,7 @@
var deferred = DeferredBuilder.Deferred(); var deferred = DeferredBuilder.Deferred();
Logger.log('Deleting ' + path); Logger.log('Deleting ' + path);
resolveLocalFileSystemURL(path, function (fileEntry) { resolveFile(path, function (fileEntry) {
fileEntry.remove(function () { fileEntry.remove(function () {
Logger.log('Deleted ' + path); Logger.log('Deleted ' + path);
@ -370,6 +370,14 @@
return deferred.promise(); return deferred.promise();
} }
function resolveFile(path, success, fail) {
getFileSystem().done(function (fileSystem) {
fileSystem.root.getFile(path, { create: false }, success, fail);
});
}
function createLocalItem(libraryItem, serverInfo, originalFileName) { function createLocalItem(libraryItem, serverInfo, originalFileName) {
var path = getDirectoryPath(libraryItem, serverInfo); var path = getDirectoryPath(libraryItem, serverInfo);
@ -379,9 +387,7 @@
var deferred = DeferredBuilder.Deferred(); var deferred = DeferredBuilder.Deferred();
getFileSystem().done(function (fileSystem) { var localPath = path.join('/');
var localPath = fileSystem.root.toURL() + "/" + path.join('/');
item.LocalPath = localPath; item.LocalPath = localPath;
@ -397,7 +403,6 @@
item.ItemId = libraryItem.Id; item.ItemId = libraryItem.Id;
item.Id = getLocalId(item.ServerId, item.ItemId); item.Id = getLocalId(item.ServerId, item.ItemId);
deferred.resolveWith(null, [item]); deferred.resolveWith(null, [item]);
});
return deferred.promise(); return deferred.promise();
} }
@ -405,7 +410,6 @@
function getDirectoryPath(item, server) { function getDirectoryPath(item, server) {
var parts = []; var parts = [];
parts.push("emby");
parts.push("sync"); parts.push("sync");
parts.push(server.Name); parts.push(server.Name);
@ -463,11 +467,11 @@
getFileSystem().done(function (fileSystem) { getFileSystem().done(function (fileSystem) {
var targetFile = localPath; fileSystem.root.getFile(fileName, { create: true }, function (targetFile) {
var downloader = new BackgroundTransfer.BackgroundDownloader(); var downloader = new BackgroundTransfer.BackgroundDownloader();
// Create a new download operation. // Create a new download operation.
var download = downloader.createDownload(url, targetFile); var download = downloader.createDownload(url, targetFile.toURL());
// Start the download and persist the promise to be able to cancel the download. // Start the download and persist the promise to be able to cancel the download.
var downloadPromise = download.startAsync().then(function () { var downloadPromise = download.startAsync().then(function () {
@ -489,7 +493,7 @@
Logger.log('download progress: ' + value); Logger.log('download progress: ' + value);
}); });
});
}); });
return deferred.promise(); return deferred.promise();
@ -589,11 +593,9 @@
function getImageLocalPath(serverId, itemId, imageTag) { function getImageLocalPath(serverId, itemId, imageTag) {
var deferred = DeferredBuilder.Deferred(); var deferred = DeferredBuilder.Deferred();
getFileSystem().done(function (fileSystem) { var path = "images/" + serverId + "-" + itemId + "/" + imageTag;
var path = fileSystem.root.toURL() + "/emby/images/" + serverId + "/" + itemId + "/" + imageTag;
deferred.resolveWith(null, [path]); deferred.resolveWith(null, [path]);
});
return deferred.promise(); return deferred.promise();
} }
@ -602,12 +604,12 @@
var deferred = DeferredBuilder.Deferred(); var deferred = DeferredBuilder.Deferred();
resolveLocalFileSystemURL(path, function (fileEntry) { resolveFile(path, function (fileEntry) {
Logger.log('fileExists: true - path: ' + path);
deferred.resolveWith(null, [true]); deferred.resolveWith(null, [true]);
}, function () { }, function () {
Logger.log('fileExists: false - path: ' + path);
deferred.resolveWith(null, [false]); deferred.resolveWith(null, [false]);
}); });
@ -653,7 +655,8 @@
downloadFile: downloadFile, downloadFile: downloadFile,
downloadSubtitles: downloadSubtitles, downloadSubtitles: downloadSubtitles,
hasImage: hasImage, hasImage: hasImage,
downloadImage: downloadImage downloadImage: downloadImage,
fileExists: fileExists
}; };
})(); })();

View file

@ -207,7 +207,7 @@
} }
.viewMenuBar.semiTransparent { .viewMenuBar.semiTransparent {
background-color: rgba(18, 18, 18, .70); background-color: rgba(18, 18, 18, .65);
} }
.paperLibraryViewNav { .paperLibraryViewNav {

View file

@ -104,40 +104,6 @@
return profile; return profile;
} }
function validatePlaybackInfoResult(result) {
if (result.ErrorCode) {
MediaController.showPlaybackInfoErrorMessage(result.ErrorCode);
return false;
}
return true;
}
function getOptimalMediaSource(mediaType, versions) {
var optimalVersion = versions.filter(function (v) {
v.enableDirectPlay = MediaController.supportsDirectPlay(v);
return v.enableDirectPlay;
})[0];
if (!optimalVersion) {
optimalVersion = versions.filter(function (v) {
return v.SupportsDirectStream;
})[0];
}
return optimalVersion || versions.filter(function (s) {
return s.SupportsTranscoding;
})[0];
}
var currentMediaSource; var currentMediaSource;
var currentItem; var currentItem;
var basePlayerState; var basePlayerState;
@ -146,37 +112,13 @@
function getVideoStreamInfo(item) { function getVideoStreamInfo(item) {
var deferred = $.Deferred(); var deferred = $.Deferred();
Dashboard.showModalLoadingMsg();
var deviceProfile = getDeviceProfile(); var deviceProfile = getDeviceProfile();
var startPosition = 0; var startPosition = 0;
MediaController.getPlaybackInfo(item.Id, deviceProfile, startPosition).done(function (playbackInfoResult) { MediaPlayer.tryStartPlayback(deviceProfile, item, startPosition, function (mediaSource) {
if (validatePlaybackInfoResult(playbackInfoResult)) {
var mediaSource = getOptimalMediaSource(item.MediaType, playbackInfoResult.MediaSources);
if (mediaSource) {
if (mediaSource.RequiresOpening) {
MediaController.getLiveStream(item.Id, playbackInfoResult.PlaySessionId, deviceProfile, startPosition, mediaSource, null, null).done(function (openLiveStreamResult) {
openLiveStreamResult.MediaSource.enableDirectPlay = MediaController.supportsDirectPlay(openLiveStreamResult.MediaSource);
playInternalPostMediaSourceSelection(item, openLiveStreamResult.MediaSource, startPosition, deferred);
});
} else {
playInternalPostMediaSourceSelection(item, mediaSource, startPosition, deferred); playInternalPostMediaSourceSelection(item, mediaSource, startPosition, deferred);
}
} else {
Dashboard.hideModalLoadingMsg();
MediaController.showPlaybackInfoErrorMessage('NoCompatibleStream');
}
}
}); });
return deferred.promise(); return deferred.promise();

View file

@ -852,27 +852,36 @@
self.supportsDirectPlay = function (mediaSource) { self.supportsDirectPlay = function (mediaSource) {
var deferred = $.Deferred();
if (mediaSource.SupportsDirectPlay) { if (mediaSource.SupportsDirectPlay) {
if (mediaSource.Protocol == 'Http' && !mediaSource.RequiredHttpHeaders.length) { if (mediaSource.Protocol == 'Http' && !mediaSource.RequiredHttpHeaders.length) {
// If this is the only way it can be played, then allow it // If this is the only way it can be played, then allow it
if (!mediaSource.SupportsDirectStream && !mediaSource.SupportsTranscoding) { if (!mediaSource.SupportsDirectStream && !mediaSource.SupportsTranscoding) {
return true; deferred.resolveWith(null, [true]);
}
else {
var val = mediaSource.Path.toLowerCase().replace('https:', 'http').indexOf(ApiClient.serverAddress().toLowerCase().replace('https:', 'http').substring(0, 14)) == 0;
deferred.resolveWith(null, [val]);
} }
return mediaSource.Path.toLowerCase().replace('https:', 'http').indexOf(ApiClient.serverAddress().toLowerCase().replace('https:', 'http').substring(0, 14)) == 0;
} }
if (mediaSource.Protocol == 'File') { if (mediaSource.Protocol == 'File') {
var exists = FileSystemBridge.fileExists(mediaSource.Path); require(['localassetmanager'], function () {
Logger.log('FileSystemBridge.fileExists: path: ' + mediaSource.Path + ' result: ' + exists);
return exists;
}
}
return false; LocalAssetManager.fileExists(mediaSource.Path).done(function (exists) {
Logger.log('LocalAssetManager.fileExists: path: ' + mediaSource.Path + ' result: ' + exists);
deferred.resolveWith(null, [exists]);
});
});
}
}
else {
deferred.resolveWith(null, [false]);
}
return deferred.promise();
}; };
self.showPlayerSelection = showPlayerSelection; self.showPlayerSelection = showPlayerSelection;

View file

@ -878,9 +878,18 @@
function getOptimalMediaSource(mediaType, versions) { function getOptimalMediaSource(mediaType, versions) {
var optimalVersion = versions.filter(function (v) { var deferred = $.Deferred();
v.enableDirectPlay = MediaController.supportsDirectPlay(v); var promises = versions.map(function (v) {
return MediaController.supportsDirectPlay(v);
});
$.when.apply($, promises).done(function () {
for (var i = 0, length = versions.length; i < length; i++) {
versions[i].enableDirectPlay = arguments[i] || false;
}
var optimalVersion = versions.filter(function (v) {
return v.enableDirectPlay; return v.enableDirectPlay;
@ -894,9 +903,14 @@
})[0]; })[0];
} }
return optimalVersion || versions.filter(function (s) { optimalVersion = optimalVersion || versions.filter(function (s) {
return s.SupportsTranscoding; return s.SupportsTranscoding;
})[0]; })[0];
deferred.resolveWith(null, [optimalVersion]);
});
return deferred.promise();
} }
self.createStreamInfo = function (type, item, mediaSource, startPosition) { self.createStreamInfo = function (type, item, mediaSource, startPosition) {
@ -916,10 +930,6 @@
if (mediaSource.enableDirectPlay) { if (mediaSource.enableDirectPlay) {
mediaUrl = mediaSource.Path; mediaUrl = mediaSource.Path;
if (mediaSource.Protocol == 'File') {
mediaUrl = FileSystemBridge.translateFilePath(mediaUrl);
}
playMethod = 'DirectPlay'; playMethod = 'DirectPlay';
} else { } else {
@ -965,9 +975,6 @@
mediaUrl = mediaSource.Path; mediaUrl = mediaSource.Path;
if (mediaSource.Protocol == 'File') {
mediaUrl = FileSystemBridge.translateFilePath(mediaUrl);
}
playMethod = 'DirectPlay'; playMethod = 'DirectPlay';
} else { } else {
@ -1063,7 +1070,7 @@
} }
}; };
function playOnDeviceProfileCreated(deviceProfile, item, startPosition, callback) { self.tryStartPlayback = function (deviceProfile, item, startPosition, callback) {
if (item.MediaType === "Video") { if (item.MediaType === "Video") {
@ -1074,28 +1081,39 @@
if (validatePlaybackInfoResult(playbackInfoResult)) { if (validatePlaybackInfoResult(playbackInfoResult)) {
var mediaSource = getOptimalMediaSource(item.MediaType, playbackInfoResult.MediaSources); getOptimalMediaSource(item.MediaType, playbackInfoResult.MediaSources).done(function (mediaSource) {
if (mediaSource) { if (mediaSource) {
if (mediaSource.RequiresOpening) { if (mediaSource.RequiresOpening) {
MediaController.getLiveStream(item.Id, playbackInfoResult.PlaySessionId, deviceProfile, startPosition, mediaSource, null, null).done(function (openLiveStreamResult) { MediaController.getLiveStream(item.Id, playbackInfoResult.PlaySessionId, deviceProfile, startPosition, mediaSource, null, null).done(function (openLiveStreamResult) {
openLiveStreamResult.MediaSource.enableDirectPlay = MediaController.supportsDirectPlay(openLiveStreamResult.MediaSource); MediaController.supportsDirectPlay(openLiveStreamResult.MediaSource).done(function (result) {
openLiveStreamResult.MediaSource.enableDirectPlay = result;
callback(openLiveStreamResult.MediaSource);
});
playInternalPostMediaSourceSelection(item, openLiveStreamResult.MediaSource, startPosition, callback);
}); });
} else { } else {
playInternalPostMediaSourceSelection(item, mediaSource, startPosition, callback); callback(mediaSource);
} }
} else { } else {
Dashboard.hideModalLoadingMsg(); Dashboard.hideModalLoadingMsg();
MediaController.showPlaybackInfoErrorMessage('NoCompatibleStream'); MediaController.showPlaybackInfoErrorMessage('NoCompatibleStream');
} }
});
} }
}); });
};
function playOnDeviceProfileCreated(deviceProfile, item, startPosition, callback) {
self.tryStartPlayback(deviceProfile, item, startPosition, function (mediaSource) {
playInternalPostMediaSourceSelection(item, mediaSource, startPosition, callback);
});
} }
function playInternalPostMediaSourceSelection(item, mediaSource, startPosition, callback) { function playInternalPostMediaSourceSelection(item, mediaSource, startPosition, callback) {

View file

@ -1027,7 +1027,7 @@ var Dashboard = {
name: Globalize.translate('TabSync'), name: Globalize.translate('TabSync'),
href: "syncactivity.html", href: "syncactivity.html",
selected: page.classList.contains('syncConfigurationPage') || (isServicesPage && context == 'sync'), selected: page.classList.contains('syncConfigurationPage') || (isServicesPage && context == 'sync'),
icon: 'refresh' icon: 'sync'
}, { }, {
divider: true, divider: true,
name: Globalize.translate('TabExtras') name: Globalize.translate('TabExtras')
@ -1965,8 +1965,6 @@ var AppInfo = {};
return false; return false;
}); });
require(['filesystem']);
if (Dashboard.isRunningInCordova()) { if (Dashboard.isRunningInCordova()) {
require(['cordova/connectsdk', 'scripts/registrationservices', 'cordova/back']); require(['cordova/connectsdk', 'scripts/registrationservices', 'cordova/back']);
@ -2027,16 +2025,6 @@ var AppInfo = {};
define("localassetmanager", ["apiclient/localassetmanager"]); define("localassetmanager", ["apiclient/localassetmanager"]);
} }
if (Dashboard.isRunningInCordova() && $.browser.android) {
define("filesystem", ["cordova/android/filesystem"]);
}
else if (Dashboard.isRunningInCordova()) {
define("filesystem", ["cordova/filesystem"]);
}
else {
define("filesystem", ["thirdparty/filesystem"]);
}
if (Dashboard.isRunningInCordova() && $.browser.android) { if (Dashboard.isRunningInCordova() && $.browser.android) {
define("nativedirectorychooser", ["cordova/android/nativedirectorychooser"]); define("nativedirectorychooser", ["cordova/android/nativedirectorychooser"]);
} }

View file

@ -282,7 +282,7 @@
if (hasLocalSync()) { if (hasLocalSync()) {
var targetId = ApiClient.deviceId(); var targetId = ApiClient.deviceId();
data = data.filter(function (j) { data = data.filter(function (j) {
return TargetId = targetId; return j.TargetId == targetId;
}); });
} }
loadData(page, data); loadData(page, data);

View file

@ -3,7 +3,7 @@
} }
.viewMenuBar.semiTransparent { .viewMenuBar.semiTransparent {
background-color: rgba(27, 27, 27, .70); background-color: rgba(27, 27, 27, .65);
} }
.background-theme-b { .background-theme-b {

View file

@ -1,13 +0,0 @@
(function () {
window.FileSystemBridge = {
fileExists: function (path) {
return false;
},
translateFilePath: function (path) {
return 'file://' + path;
}
};
})();