From 093ee4c8664238747e235ad8fd3b0c97e4750709 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 27 Apr 2014 21:57:29 -0400 Subject: [PATCH] support sending nav commands --- dashboard-ui/nowplaying.html | 1 - dashboard-ui/scripts/chromecast.js | 38 ++++++++++++++++ dashboard-ui/scripts/mediaplayer.js | 45 ++++++++++++++++++- dashboard-ui/scripts/nowplayingpage.js | 5 ++- dashboard-ui/scripts/remotecontrol.js | 37 ++++++++++----- dashboard-ui/scripts/site.js | 35 ++++++++++----- .../thirdparty/mediabrowser.apiclient.js | 9 +--- 7 files changed, 138 insertions(+), 32 deletions(-) diff --git a/dashboard-ui/nowplaying.html b/dashboard-ui/nowplaying.html index 3e4041300..9adbf8585 100644 --- a/dashboard-ui/nowplaying.html +++ b/dashboard-ui/nowplaying.html @@ -48,7 +48,6 @@ - diff --git a/dashboard-ui/scripts/chromecast.js b/dashboard-ui/scripts/chromecast.js index 8c0f9a708..ed6729e86 100644 --- a/dashboard-ui/scripts/chromecast.js +++ b/dashboard-ui/scripts/chromecast.js @@ -1374,6 +1374,44 @@ castPlayer.setReceiverVolume(false, vol / 100); }; + self.sendCommand = function (cmd) { + + // Full list + // https://github.com/MediaBrowser/MediaBrowser/blob/master/MediaBrowser.Model/Session/GeneralCommand.cs#L23 + + switch (cmd.Name) { + + case 'VolumeUp': + self.volumeUp(); + break; + case 'VolumeDown': + self.volumeDown(); + break; + case 'Mute': + self.mute(); + break; + case 'Unmute': + self.unMute(); + break; + case 'ToggleMute': + self.toggleMute(); + break; + case 'SetVolume': + self.setVolume(cmd.Arguments.Volume); + break; + case 'SetAudioStreamIndex': + break; + case 'SetSubtitleStreamIndex': + break; + case 'ToggleFullscreen': + break; + default: + // Not player-related + Dashboard.processGeneralCommand(cmd); + } + + }; + self.getPlayerState = function () { var deferred = $.Deferred(); diff --git a/dashboard-ui/scripts/mediaplayer.js b/dashboard-ui/scripts/mediaplayer.js index b3e20ef8c..1c3be5bdf 100644 --- a/dashboard-ui/scripts/mediaplayer.js +++ b/dashboard-ui/scripts/mediaplayer.js @@ -726,6 +726,49 @@ }); }; + self.sendCommand = function (cmd) { + + // Full list + // https://github.com/MediaBrowser/MediaBrowser/blob/master/MediaBrowser.Model/Session/GeneralCommand.cs#L23 + + switch (cmd.Name) { + + case 'VolumeUp': + self.volumeUp(); + break; + case 'VolumeDown': + self.volumeDown(); + break; + case 'Mute': + self.mute(); + break; + case 'Unmute': + self.unMute(); + break; + case 'ToggleMute': + self.toggleMute(); + break; + case 'SetVolume': + self.setVolume(cmd.Arguments.Volume); + break; + case 'SetAudioStreamIndex': + break; + case 'SetSubtitleStreamIndex': + break; + case 'ToggleFullscreen': + + if (currentItem && currentItem.MediaType == 'Video') { + self.toggleFullscreen(); + } + + break; + default: + // Not player-related + Dashboard.processGeneralCommand(cmd); + } + + }; + self.pause = function () { currentMediaElement.pause(); @@ -998,7 +1041,7 @@ state.NowPlayingItem = state.NowPlayingItem || {}; var nowPlayingItem = state.NowPlayingItem; - + nowPlayingItem.Id = item.Id; nowPlayingItem.MediaType = item.MediaType; nowPlayingItem.Type = item.Type; diff --git a/dashboard-ui/scripts/nowplayingpage.js b/dashboard-ui/scripts/nowplayingpage.js index eae107fed..02edadabd 100644 --- a/dashboard-ui/scripts/nowplayingpage.js +++ b/dashboard-ui/scripts/nowplayingpage.js @@ -14,7 +14,9 @@ $('.btnCommand', page).on('click', function () { - + currentPlayer.sendCommand({ + Name: this.getAttribute('data-command') + }); }); } @@ -95,6 +97,7 @@ var page = this; + $('.radioTabButton', page).checked(false).checkboxradio('refresh'); $('.radioTabButton:first', page).checked(true).checkboxradio('refresh').trigger('change'); $(function () { diff --git a/dashboard-ui/scripts/remotecontrol.js b/dashboard-ui/scripts/remotecontrol.js index 15dfc6a13..82a1ed0ed 100644 --- a/dashboard-ui/scripts/remotecontrol.js +++ b/dashboard-ui/scripts/remotecontrol.js @@ -28,19 +28,32 @@ ApiClient.sendPlayStateCommand(sessionId, command, options); } - function sendCommand(command, options) { - - var sessionId = MediaController.getPlayerInfo().id; - - ApiClient.sendCommand(sessionId, command, options); - } - function remoteControlPlayer() { var self = this; self.name = 'Remote Control'; + function sendCommandByName(name, options) { + + var command = { + Name: name + }; + + if (options) { + command.Arguments = options; + } + + self.sendCommand(command); + } + + self.sendCommand = function (command) { + + var sessionId = MediaController.getPlayerInfo().id; + + ApiClient.sendCommand(sessionId, command); + }; + self.play = function (options) { sendPlayCommand(options, 'PlayNow'); @@ -99,19 +112,19 @@ }; self.mute = function () { - sendCommand('Mute'); + sendCommandByName('Mute'); }; self.unMute = function () { - sendCommand('Unmute'); + sendCommandByName('Unmute'); }; self.toggleMute = function () { - sendCommand('ToggleMute'); + sendCommandByName('ToggleMute'); }; self.setVolume = function (vol) { - sendCommand('SetVolume', { + sendCommandByName('SetVolume', { Volume: vol @@ -120,7 +133,7 @@ self.displayContent = function (options) { - sendCommand('DisplayContent', { + sendCommandByName('DisplayContent', { ItemName: options.itemName, ItemType: options.itemType, diff --git a/dashboard-ui/scripts/site.js b/dashboard-ui/scripts/site.js index d7e84f20a..02c781a45 100644 --- a/dashboard-ui/scripts/site.js +++ b/dashboard-ui/scripts/site.js @@ -830,6 +830,28 @@ var Dashboard = { }, + processGeneralCommand: function (cmd) { + + // Full list + // https://github.com/MediaBrowser/MediaBrowser/blob/master/MediaBrowser.Model/Session/GeneralCommand.cs#L23 + + if (cmd.Name === 'GoHome') { + Dashboard.navigate('index.html'); + } + else if (cmd.Name === 'GoToSettings') { + Dashboard.navigate('dashboard.html'); + } + else if (cmd.Name === 'DisplayContent') { + Dashboard.onBrowseCommand(cmd.Arguments); + } + else if (cmd.Name === 'GoToSearch') { + Search.showSearchPanel($.mobile.activePage); + } + else { + console.log('Unrecognized command: ' + cmd.Name); + } + }, + onWebSocketMessageReceived: function (e, data) { var msg = data; @@ -911,15 +933,7 @@ var Dashboard = { var cmd = msg.Data; - if (cmd.Name === 'GoHome') { - Dashboard.navigate('index.html'); - } - else if (cmd.Name === 'GoToSettings') { - Dashboard.navigate('dashboard.html'); - } - else if (cmd.Name === 'DisplayContent') { - Dashboard.onBrowseCommand(cmd.Arguments); - } + Dashboard.processGeneralCommand(cmd); } else if (msg.MessageType === "MessageCommand") { @@ -1283,7 +1297,8 @@ var Dashboard = { "ToggleFullscreen", "SetAudioStreamIndex", "SetSubtitleStreamIndex", - "DisplayContent" + "DisplayContent", + "GoToSearch" ]; } diff --git a/dashboard-ui/thirdparty/mediabrowser.apiclient.js b/dashboard-ui/thirdparty/mediabrowser.apiclient.js index 7bb7877b9..d99a1040e 100644 --- a/dashboard-ui/thirdparty/mediabrowser.apiclient.js +++ b/dashboard-ui/thirdparty/mediabrowser.apiclient.js @@ -3057,7 +3057,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi }); }; - self.sendCommand = function (sessionId, command, options) { + self.sendCommand = function (sessionId, command) { if (!sessionId) { throw new Error("null sessionId"); @@ -3074,12 +3074,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi url: url }; - options = { - Arguments: options || {}, - Name: command - }; - - ajaxOptions.data = JSON.stringify(options); + ajaxOptions.data = JSON.stringify(command); ajaxOptions.contentType = "application/json"; return self.ajax(ajaxOptions);