Skip to content

Commit

Permalink
Add auto-cast feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
iwalton3 committed Sep 7, 2020
1 parent f31801c commit e9caf5e
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -177,6 +177,7 @@
"src/components/remotecontrol/remotecontrol.js",
"src/components/sanatizefilename.js",
"src/components/scrollManager.js",
"src/components/autocast.js",
"src/plugins/experimentalWarnings/plugin.js",
"src/plugins/sessionPlayer/plugin.js",
"src/plugins/htmlAudioPlayer/plugin.js",
Expand Down
49 changes: 49 additions & 0 deletions src/components/autocast.js
@@ -0,0 +1,49 @@
import events from 'events';
import playbackManager from 'playbackManager';

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

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

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

if (currentPlayerInfo && currentPlayerInfo.id && 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() {
if (!supported()) return;

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) {
events.on(apiClient, 'websocketopen', onOpen);
}
21 changes: 21 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 @@ -219,6 +220,16 @@ function showActivePlayerMenuInternal(dialogHelper, playerInfo) {
html += '</label>';
}

html += '</div><div>';

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

html += '</div>';

html += '<div style="margin-top:1em;display:flex;justify-content: flex-end;">';
Expand All @@ -237,6 +248,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 +286,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
8 changes: 8 additions & 0 deletions src/scripts/libraryMenu.js
Expand Up @@ -52,6 +52,7 @@ import 'flexStyles';

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

function getCurrentApiClient() {
Expand Down Expand Up @@ -910,6 +911,12 @@ import 'flexStyles';
}
}

function ensureHeader() {
return new Promise(function (resolve) {
window.connectionManager.user(getCurrentApiClient()).then(updateUserInHeader).then(resolve);
});
}

let currentPageType;
pageClassOn('pagebeforeshow', 'page', function (e) {
if (!this.classList.contains('withTabs')) {
Expand Down Expand Up @@ -996,6 +1003,7 @@ import 'flexStyles';
};

window.LibraryMenu = LibraryMenu;
renderHeader();

export default LibraryMenu;

Expand Down
1 change: 1 addition & 0 deletions src/scripts/site.js
Expand Up @@ -591,6 +591,7 @@ function initClient() {
define('metadataEditor', [componentsPath + '/metadataEditor/metadataEditor'], returnFirstDependency);
define('personEditor', [componentsPath + '/metadataEditor/personEditor'], returnFirstDependency);
define('playerSelectionMenu', [componentsPath + '/playback/playerSelectionMenu'], returnFirstDependency);
define('autocast', [componentsPath + '/autocast'], returnFirstDependency);
define('playerSettingsMenu', [componentsPath + '/playback/playersettingsmenu'], returnFirstDependency);
define('playMethodHelper', [componentsPath + '/playback/playmethodhelper'], returnFirstDependency);
define('brightnessOsd', [componentsPath + '/playback/brightnessosd'], 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

0 comments on commit e9caf5e

Please sign in to comment.