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

beta fixes

This commit is contained in:
Luke Pulverenti 2015-05-11 15:59:59 -04:00
parent 9e9ffda3e6
commit bdc8187420
13 changed files with 203 additions and 18 deletions

View file

@ -0,0 +1,170 @@
(function () {
// Reports media playback to the device for lock screen control
var currentPlayer;
var lastPlayerState;
function updatePlayerState(state) {
if (!state.NowPlayingItem) {
hideNowPlayingBar();
return;
}
lastPlayerState = state;
var playState = state.PlayState || {};
var nameHtml = MediaController.getNowPlayingNameHtml(state.NowPlayingItem) || '';
var parts = nameHtml.split('<br/>');
var artist = parts.length == 1 ? '' : parts[0];
var title = parts[parts.length - 1];
var album = state.NowPlayingItem || '';
var duration = state.NowPlayingItem.RunTimeTicks ? (state.NowPlayingItem / 10000000) : 0;
var elapsedTime = playState.PositionTicks ? (playState.PositionTicks / 10000000) : 0;
var url = '';
var imgHeight = 100;
var nowPlayingItem = state.NowPlayingItem;
if (nowPlayingItem.PrimaryImageTag) {
url = ApiClient.getScaledImageUrl(nowPlayingItem.PrimaryImageItemId, {
type: "Primary",
height: imgHeight,
tag: nowPlayingItem.PrimaryImageTag
});
}
else if (nowPlayingItem.BackdropImageTag) {
url = ApiClient.getScaledImageUrl(nowPlayingItem.BackdropItemId, {
type: "Backdrop",
height: imgHeight,
tag: nowPlayingItem.BackdropImageTag,
index: 0
});
} else if (nowPlayingItem.ThumbImageTag) {
url = ApiClient.getScaledImageUrl(nowPlayingItem.ThumbImageItemId, {
type: "Thumb",
height: imgHeight,
tag: nowPlayingItem.ThumbImageTag
});
}
var params = [artist, title, album, url, duration, elapsedTime];
window.remoteControls.updateMetas(onUpdateMetasSuccess, onUpdateMetasFail, params);
}
function onStateChanged(e, state) {
//console.log('nowplaying event: ' + e.type);
var player = this;
if (player.isDefaultPlayer && state.NowPlayingItem && state.NowPlayingItem.MediaType == 'Video') {
return;
}
updatePlayerState(state);
}
function onPlaybackStart(e, state) {
console.log('nowplaying event: ' + e.type);
var player = this;
player.beginPlayerUpdates();
onStateChanged.call(player, e, state);
}
function onPlaybackStopped(e, state) {
console.log('nowplaying event: ' + e.type);
var player = this;
player.endPlayerUpdates();
hideNowPlayingBar();
}
function releaseCurrentPlayer() {
if (currentPlayer) {
$(currentPlayer).off('.cordovaremote');
currentPlayer.endPlayerUpdates();
currentPlayer = null;
hideNowPlayingBar();
}
}
function hideNowPlayingBar() {
var artist = "";
var title = "";
var album = "";
var image = "";
var duration = 0;
var elapsedTime = 0;
var params = [artist, title, album, image, duration, elapsedTime];
window.remoteControls.updateMetas(onUpdateMetasSuccess, onUpdateMetasFail, params);
}
function onUpdateMetasSuccess() {
console.log('onUpdateMetasSuccess');
}
function onUpdateMetasFail(fail) {
console.log('onUpdateMetasFail' + fail);
}
function bindToPlayer(player) {
releaseCurrentPlayer();
currentPlayer = player;
if (!player.isLocalPlayer) {
return;
}
player.getPlayerState().done(function (state) {
if (state.NowPlayingItem) {
player.beginPlayerUpdates();
}
onStateChanged.call(player, { type: 'init' }, state);
});
$(player).on('playbackstart.cordovaremote', onPlaybackStart)
.on('playbackstop.cordovaremote', onPlaybackStopped)
.on('playstatechange.cordovaremote', onStateChanged)
.on('positionchange.cordovaremote', onStateChanged);
}
document.addEventListener("deviceready", function () {
$(function () {
$(MediaController).on('playerchange', function () {
bindToPlayer(MediaController.getCurrentPlayer());
});
bindToPlayer(MediaController.getCurrentPlayer());
});
}, false);
})();

View file

@ -0,0 +1,109 @@
(function (globalScope) {
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;
}
function arrayBufferToString(buf) {
return String.fromCharCode.apply(null, new Uint16Array(buf));
}
globalScope.ServerDiscovery = {
findServers: function (timeoutMs) {
var deferred = DeferredBuilder.Deferred();
var servers = [];
// Expected server properties
// Name, Id, Address, EndpointAddress (optional)
var chrome = globalScope.chrome;
if (!chrome) {
deferred.resolveWith(null, [servers]);
return deferred.promise();
}
var isTimedOut = false;
var socketId;
var timeout = setTimeout(function () {
isTimedOut = true;
deferred.resolveWith(null, [servers]);
if (socketId) {
chrome.sockets.udp.onReceive.removeListener(onReceive);
chrome.sockets.udp.close(socketId);
}
}, timeoutMs);
function onReceive(info) {
console.log('ServerDiscovery message received');
console.log(info);
if (info.socketId == socketId) {
var json = arrayBufferToString(info.data);
var server = JSON.parse(json);
server.RemoteAddress = info.remoteAddress;
if (info.remotePort) {
server.RemoteAddress += ':' + info.remotePort;
}
servers.push(server);
}
}
var port = 7359;
chrome.sockets.udp.create(function (createInfo) {
socketId = createInfo.socketId;
chrome.sockets.udp.bind(createInfo.socketId, '0.0.0.0', port, function (result) {
var data = stringToArrayBuffer('who is EmbyServer?');
chrome.sockets.udp.send(createInfo.socketId, data, '255.255.255.255', port, function (result) {
if (result < 0) {
console.log('send fail: ' + result);
chrome.sockets.udp.close(createInfo.socketId);
if (!isTimedOut) {
clearTimeout(timeout);
deferred.resolveWith(null, [servers]);
}
} else {
console.log('sendTo: success ' + port);
if (!isTimedOut) {
chrome.sockets.udp.onReceive.addListener(onReceive);
}
}
});
});
});
return deferred.promise();
}
};
})(window);