jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/playback/playerselection.js

215 lines
6.6 KiB
JavaScript
Raw Normal View History

2017-01-20 10:52:37 -07:00
define(['appSettings', 'events', 'browser', 'loading', 'playbackManager', 'embyRouter', 'globalize', 'apphost'], function (appSettings, events, browser, loading, playbackManager, embyRouter, globalize, appHost) {
'use strict';
var currentDisplayInfo;
2017-01-02 23:51:36 -07:00
function mirrorItem(info, player) {
var item = info.item;
2017-01-02 23:51:36 -07:00
playbackManager.displayContent({
ItemName: item.Name,
ItemId: item.Id,
ItemType: item.Type,
Context: info.context
2017-01-02 23:51:36 -07:00
}, player);
}
function mirrorIfEnabled(info) {
info = info || currentDisplayInfo;
2017-01-02 23:51:36 -07:00
if (info && playbackManager.enableDisplayMirroring()) {
2017-01-02 23:51:36 -07:00
var player = playbackManager.getPlayerInfo();
2017-01-02 23:51:36 -07:00
if (player) {
2017-01-18 23:21:03 -07:00
if (!player.isLocalPlayer && player.supportedCommands.indexOf('DisplayContent') !== -1) {
2017-01-02 23:51:36 -07:00
mirrorItem(info, player);
}
}
}
}
2017-01-03 12:37:10 -07:00
function showPlayerSelection(button) {
2017-01-02 23:51:36 -07:00
var currentPlayerInfo = playbackManager.getPlayerInfo();
2017-01-02 23:51:36 -07:00
if (currentPlayerInfo) {
if (!currentPlayerInfo.isLocalPlayer) {
showActivePlayerMenu(currentPlayerInfo);
return;
}
}
2017-01-02 23:51:36 -07:00
var currentPlayerId = currentPlayerInfo ? currentPlayerInfo.id : null;
loading.show();
2017-01-02 23:51:36 -07:00
playbackManager.getTargets().then(function (targets) {
var menuItems = targets.map(function (t) {
var name = t.name;
2017-01-18 23:21:03 -07:00
if (t.appName && t.appName !== t.name) {
name += " - " + t.appName;
}
return {
name: name,
id: t.id,
2017-01-02 23:51:36 -07:00
selected: currentPlayerId === t.id
};
});
require(['actionsheet'], function (actionsheet) {
loading.hide();
var menuOptions = {
2017-01-18 23:21:03 -07:00
title: globalize.translate('sharedcomponents#HeaderSelectPlayer'),
items: menuItems,
positionTo: button,
resolveOnClick: true
};
// Unfortunately we can't allow the url to change or chromecast will throw a security error
// Might be able to solve this in the future by moving the dialogs to hashbangs
2017-01-20 10:52:37 -07:00
if (!(!browser.chrome || appHost.supports('castmenuhashchange'))) {
menuOptions.enableHistory = false;
}
actionsheet.show(menuOptions).then(function (id) {
var target = targets.filter(function (t) {
2017-01-18 23:21:03 -07:00
return t.id === id;
})[0];
2017-01-02 23:51:36 -07:00
playbackManager.trySetActivePlayer(target.playerName, target);
mirrorIfEnabled();
});
});
});
}
function showActivePlayerMenu(playerInfo) {
require(['dialogHelper', 'dialog', 'emby-checkbox', 'emby-button'], function (dialogHelper) {
showActivePlayerMenuInternal(dialogHelper, playerInfo);
});
}
function showActivePlayerMenuInternal(dialogHelper, playerInfo) {
var html = '';
var dialogOptions = {
removeOnClose: true
};
dialogOptions.modal = false;
dialogOptions.entryAnimationDuration = 160;
dialogOptions.exitAnimationDuration = 160;
dialogOptions.autoFocus = false;
var dlg = dialogHelper.createDialog(dialogOptions);
dlg.classList.add('promptDialog');
html += '<div class="promptDialogContent" style="padding:1.5em;">';
html += '<h2 style="margin-top:.5em;">';
html += (playerInfo.deviceName || playerInfo.name);
html += '</h2>';
html += '<div>';
2017-01-18 23:21:03 -07:00
if (playerInfo.supportedCommands.indexOf('DisplayContent') !== -1) {
html += '<label class="checkboxContainer">';
2017-01-02 23:51:36 -07:00
var checkedHtml = playbackManager.enableDisplayMirroring() ? ' checked' : '';
html += '<input type="checkbox" is="emby-checkbox" class="chkMirror"' + checkedHtml + '/>';
2017-01-18 23:21:03 -07:00
html += '<span>' + globalize.translate('sharedcomponents#EnableDisplayMirroring') + '</span>';
html += '</label>';
}
html += '</div>';
html += '<div style="margin-top:1em;display:flex;justify-content: flex-end;">';
2017-01-18 23:21:03 -07:00
html += '<button is="emby-button" type="button" class="button-flat button-accent-flat btnRemoteControl promptDialogButton">' + globalize.translate('sharedcomponents#HeaderRemoteControl') + '</button>';
html += '<button is="emby-button" type="button" class="button-flat button-accent-flat btnDisconnect promptDialogButton ">' + globalize.translate('sharedcomponents#Disconnect') + '</button>';
html += '<button is="emby-button" type="button" class="button-flat button-accent-flat btnCancel promptDialogButton">' + globalize.translate('sharedcomponents#ButtonCancel') + '</button>';
html += '</div>';
html += '</div>';
dlg.innerHTML = html;
var chkMirror = dlg.querySelector('.chkMirror');
if (chkMirror) {
chkMirror.addEventListener('change', onMirrorChange);
}
var destination = '';
var btnRemoteControl = dlg.querySelector('.btnRemoteControl');
if (btnRemoteControl) {
btnRemoteControl.addEventListener('click', function () {
destination = 'nowplaying.html';
dialogHelper.close(dlg);
});
}
dlg.querySelector('.btnDisconnect').addEventListener('click', function () {
2017-01-02 23:51:36 -07:00
playbackManager.disconnectFromPlayer();
dialogHelper.close(dlg);
});
dlg.querySelector('.btnCancel').addEventListener('click', function () {
dialogHelper.close(dlg);
});
dialogHelper.open(dlg).then(function () {
if (destination) {
2017-01-18 23:21:03 -07:00
embyRouter.show(destination);
}
});
}
function onMirrorChange() {
2017-01-02 23:51:36 -07:00
playbackManager.enableDisplayMirroring(this.checked);
}
2017-01-18 23:21:03 -07:00
document.addEventListener('viewbeforeshow', function () {
currentDisplayInfo = null;
});
2017-01-18 23:21:03 -07:00
document.addEventListener('viewshow', function (e) {
2017-01-18 23:21:03 -07:00
var state = e.detail.state || {};
var item = state.item;
if (item && item.ServerId) {
mirrorIfEnabled({
item: item
});
return;
}
});
events.on(appSettings, 'change', function (e, name) {
if (name === 'displaymirror') {
mirrorIfEnabled();
}
});
return {
show: showPlayerSelection
};
});