Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Auto Cast Feature #1909

Merged
merged 4 commits into from Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -329,6 +329,7 @@
"src/plugins/youtubePlayer/plugin.js",
"src/scripts/alphanumericshortcuts.js",
"src/scripts/autoBackdrops.js",
"src/scripts/autocast.js",
"src/scripts/browser.js",
"src/scripts/clientUtils.js",
"src/scripts/datetime.js",
Expand Down
19 changes: 19 additions & 0 deletions src/components/playback/playerSelectionMenu.js
Expand Up @@ -6,6 +6,7 @@ import playbackManager from 'playbackManager';
import appRouter from 'appRouter';
import globalize from 'globalize';
import appHost from 'apphost';
import * as autocast from 'autocast';

function mirrorItem(info, player) {
var item = info.item;
Expand Down Expand Up @@ -221,6 +222,14 @@ function showActivePlayerMenuInternal(dialogHelper, playerInfo) {

html += '</div>';

if (autocast.supported()) {
html += '<div><label class="checkboxContainer">';
var checkedHtmlAC = autocast.isEnabled() ? ' checked' : '';
html += '<input type="checkbox" is="emby-checkbox" class="chkAutoCast"' + checkedHtmlAC + '/>';
html += '<span>' + globalize.translate('EnableAutoCast') + '</span>';
html += '</label></div>';
}

html += '<div style="margin-top:1em;display:flex;justify-content: flex-end;">';

html += '<button is="emby-button" type="button" class="button-flat btnRemoteControl promptDialogButton">' + globalize.translate('HeaderRemoteControl') + '</button>';
Expand All @@ -237,6 +246,12 @@ function showActivePlayerMenuInternal(dialogHelper, playerInfo) {
chkMirror.addEventListener('change', onMirrorChange);
}

var chkAutoCast = dlg.querySelector('.chkAutoCast');

if (chkAutoCast) {
chkAutoCast.addEventListener('change', onAutoCastChange);
}

var destination = '';

var btnRemoteControl = dlg.querySelector('.btnRemoteControl');
Expand Down Expand Up @@ -269,6 +284,10 @@ function onMirrorChange() {
playbackManager.enableDisplayMirroring(this.checked);
}

function onAutoCastChange() {
autocast.enable(this.checked);
}

document.addEventListener('viewshow', function (e) {
var state = e.detail.state || {};
var item = state.item;
Expand Down
47 changes: 47 additions & 0 deletions src/scripts/autocast.js
@@ -0,0 +1,47 @@
import events from 'events';
import playbackManager from 'playbackManager';

export function supported() {
return typeof(Storage) !== 'undefined';
}

export function enable(enabled) {
if (!supported()) return;

if (enabled) {
const currentPlayerInfo = playbackManager.getPlayerInfo();

if (currentPlayerInfo && currentPlayerInfo.id) {
localStorage.setItem('autocastPlayerId', currentPlayerInfo.id);
}
} else {
localStorage.removeItem('autocastPlayerId');
}
}

export function isEnabled() {
if (!supported()) return false;

const playerId = localStorage.getItem('autocastPlayerId');
const currentPlayerInfo = playbackManager.getPlayerInfo();

return (currentPlayerInfo && playerId && currentPlayerInfo.id === playerId);
}

function onOpen() {
const playerId = localStorage.getItem('autocastPlayerId');

playbackManager.getTargets().then(function (targets) {
for (var i = 0; i < targets.length; i++) {
if (targets[i].id == playerId) {
playbackManager.trySetActivePlayer(targets[i].playerName, targets[i]);
break;
}
}
});
}

const apiClient = window.connectionManager.currentApiClient();
if (apiClient && supported()) {
events.on(apiClient, 'websocketopen', onOpen);
}
2 changes: 2 additions & 0 deletions src/scripts/libraryMenu.js
Expand Up @@ -52,6 +52,7 @@ import 'flexStyles';

lazyLoadViewMenuBarImages();
bindMenuEvents();
updateCastIcon();
}

function getCurrentApiClient() {
Expand Down Expand Up @@ -996,6 +997,7 @@ import 'flexStyles';
};

window.LibraryMenu = LibraryMenu;
renderHeader();

export default LibraryMenu;

Expand Down
1 change: 1 addition & 0 deletions src/scripts/site.js
Expand Up @@ -581,6 +581,7 @@ function initClient() {
define('webSettings', [scriptsPath + '/settings/webSettings'], returnFirstDependency);
define('appSettings', [scriptsPath + '/settings/appSettings'], returnFirstDependency);
define('userSettings', [scriptsPath + '/settings/userSettings'], returnFirstDependency);
define('autocast', [scriptsPath + '/autocast'], returnFirstDependency);

define('mediaSession', [componentsPath + '/playback/mediasession'], returnFirstDependency);
define('actionsheet', [componentsPath + '/actionSheet/actionSheet'], returnFirstDependency);
Expand Down
1 change: 1 addition & 0 deletions src/strings/en-us.json
Expand Up @@ -183,6 +183,7 @@
"EditImages": "Edit images",
"EditMetadata": "Edit metadata",
"EditSubtitles": "Edit subtitles",
"EnableAutoCast": "Set as Default",
"EnableBackdropsHelp": "Display backdrops in the background of some pages while browsing the library.",
"EnableCinemaMode": "Cinema mode",
"EnableColorCodedBackgrounds": "Color coded backgrounds",
Expand Down