2013-05-28 18:45:39 -07:00
|
|
|
|
(function (window, document, $) {
|
|
|
|
|
|
2013-12-26 12:24:12 -07:00
|
|
|
|
function showMenu(sessions, options) {
|
2013-07-11 13:25:12 -07:00
|
|
|
|
|
2014-02-18 22:21:03 -07:00
|
|
|
|
var html = '<div data-role="popup" data-transition="slidedown" class="remoteControlFlyout" data-theme="a">';
|
2013-07-11 13:25:12 -07:00
|
|
|
|
|
2013-12-24 11:37:29 -07:00
|
|
|
|
html += '<a href="#" data-rel="back" data-role="button" data-icon="delete" data-iconpos="notext" class="ui-btn-right" data-theme="b">Close</a>';
|
|
|
|
|
|
|
|
|
|
html += '<div class="ui-bar-b" style="text-align:center;">';
|
2013-07-11 13:25:12 -07:00
|
|
|
|
html += '<div style="margin:.5em 0;">Remote Control</div>';
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
2013-12-24 11:37:29 -07:00
|
|
|
|
html += '<div style="padding: 1em;">';
|
2013-07-11 13:25:12 -07:00
|
|
|
|
|
|
|
|
|
html += '<div class="sessionsPopupContent">';
|
|
|
|
|
|
|
|
|
|
// Add controls here
|
2014-01-16 20:13:12 -07:00
|
|
|
|
html += '<div>';
|
2013-07-11 13:25:12 -07:00
|
|
|
|
html += '<select id="selectSession" name="selectSession" data-mini="true"></select></div>';
|
|
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
html += '<div class="nowPlayingInfo" style="margin:1em 0;">';
|
|
|
|
|
|
|
|
|
|
html += '<div class="nowPlaying" style="display:none;">';
|
|
|
|
|
|
2014-03-21 11:40:38 -07:00
|
|
|
|
html += getPlaybackHtml(sessions.currentSession);
|
2013-07-11 13:25:12 -07:00
|
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
html += '<p class="nothingPlaying" style="display:none;">Nothing is currently playing.</p>';
|
|
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
2014-01-16 20:13:12 -07:00
|
|
|
|
html += '<div class="commandsCollapsible" data-role="collapsible" data-collapsed="true" data-mini="true" style="margin-top: 1em;display:none;">';
|
|
|
|
|
html += '<h4>Send Command</h4>';
|
|
|
|
|
html += '<div>';
|
|
|
|
|
|
2013-08-28 20:20:22 -07:00
|
|
|
|
html += '<p class="sessionButtons" style="text-align:center;">';
|
|
|
|
|
|
2014-01-16 20:13:12 -07:00
|
|
|
|
html += '<button class="btnGoHome" type="button" data-icon="home" data-mini="true" data-inline="true">Go Home</button>';
|
|
|
|
|
html += '<button class="btnGoToSettings" type="button" data-icon="gear" data-mini="true" data-inline="true">View Settings</button>';
|
2013-08-28 20:20:22 -07:00
|
|
|
|
|
|
|
|
|
html += '</p>';
|
|
|
|
|
|
2013-08-27 22:44:43 -07:00
|
|
|
|
html += '<p style="text-align:center;">';
|
|
|
|
|
|
2013-08-28 20:20:22 -07:00
|
|
|
|
html += '<div><label for="txtMessage">Message text</label></div>';
|
2013-09-24 08:08:51 -07:00
|
|
|
|
|
2013-12-26 12:24:12 -07:00
|
|
|
|
html += '<input id="txtMessage" name="txtMessage" type="text" />';
|
2013-09-24 08:08:51 -07:00
|
|
|
|
|
2014-01-16 20:13:12 -07:00
|
|
|
|
html += '<button type="button" data-icon="mail" class="btnSendMessage" data-mini="true">Send Message</button>';
|
2013-08-27 22:44:43 -07:00
|
|
|
|
|
|
|
|
|
html += '</p>';
|
|
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
2013-07-11 13:25:12 -07:00
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
$(document.body).append(html);
|
|
|
|
|
|
2014-02-18 22:21:03 -07:00
|
|
|
|
var popup = $('.remoteControlFlyout').popup({ history: false, tolerance: 0, corners: false }).trigger('create').popup("open").on("popupafterclose", function () {
|
2013-07-11 13:25:12 -07:00
|
|
|
|
|
|
|
|
|
if (ApiClient.isWebSocketOpen()) {
|
|
|
|
|
ApiClient.sendWebSocketMessage("SessionsStop");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(ApiClient).off("websocketmessage.remotecontrol");
|
|
|
|
|
|
|
|
|
|
$(this).off("popupafterclose").remove();
|
2014-02-18 22:21:03 -07:00
|
|
|
|
|
|
|
|
|
$('.remoteControlFlyout').popup("destroy").remove();
|
2013-07-11 13:25:12 -07:00
|
|
|
|
});
|
|
|
|
|
|
2013-12-26 12:24:12 -07:00
|
|
|
|
renderSessionsInControlMenu(popup, sessions, options);
|
|
|
|
|
updateSessionInfo(popup, sessions, options);
|
2013-07-11 13:25:12 -07:00
|
|
|
|
|
|
|
|
|
if (ApiClient.isWebSocketOpen()) {
|
2013-07-12 12:56:40 -07:00
|
|
|
|
ApiClient.sendWebSocketMessage("SessionsStart", "1000,1000");
|
2013-07-11 13:25:12 -07:00
|
|
|
|
|
|
|
|
|
$(ApiClient).on("websocketmessage.remotecontrol", function (e, msg) {
|
|
|
|
|
|
|
|
|
|
if (msg.MessageType === "Sessions") {
|
|
|
|
|
|
|
|
|
|
// Update existing data
|
|
|
|
|
updateSessionInfo(popup, msg.Data);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
2013-07-11 13:43:37 -07:00
|
|
|
|
|
2013-08-27 22:44:43 -07:00
|
|
|
|
$('.btnGoHome', popup).on('click', function () {
|
|
|
|
|
|
|
|
|
|
var id = $('#selectSession', popup).val();
|
|
|
|
|
|
|
|
|
|
ApiClient.sendSystemCommand(id, 'GoHome');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnGoToSettings', popup).on('click', function () {
|
|
|
|
|
|
|
|
|
|
var id = $('#selectSession', popup).val();
|
|
|
|
|
|
|
|
|
|
ApiClient.sendSystemCommand(id, 'GoToSettings');
|
|
|
|
|
});
|
|
|
|
|
|
2013-08-28 20:20:22 -07:00
|
|
|
|
$('.btnSendMessage', popup).on('click', function () {
|
|
|
|
|
|
|
|
|
|
var id = $('#selectSession', popup).val();
|
|
|
|
|
|
|
|
|
|
var messageText = $('#txtMessage', popup).val();
|
2013-09-24 08:08:51 -07:00
|
|
|
|
|
2013-08-28 20:20:22 -07:00
|
|
|
|
if (messageText) {
|
2013-09-24 08:08:51 -07:00
|
|
|
|
Dashboard.getCurrentUser().done(function (user) {
|
2013-08-28 20:20:22 -07:00
|
|
|
|
|
|
|
|
|
ApiClient.sendMessageCommand(id, {
|
|
|
|
|
Header: "Message from " + user.Name,
|
|
|
|
|
Text: messageText
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
$('#txtMessage', popup)[0].focus();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2013-08-27 22:44:43 -07:00
|
|
|
|
$('.btnVolumeDown', popup).on('click', function () {
|
|
|
|
|
|
|
|
|
|
var id = $('#selectSession', popup).val();
|
|
|
|
|
|
|
|
|
|
ApiClient.sendSystemCommand(id, 'VolumeDown');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnVolumeUp', popup).on('click', function () {
|
|
|
|
|
|
|
|
|
|
var id = $('#selectSession', popup).val();
|
|
|
|
|
|
|
|
|
|
ApiClient.sendSystemCommand(id, 'VolumeUp');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnToggleMute', popup).on('click', function () {
|
|
|
|
|
|
|
|
|
|
var id = $('#selectSession', popup).val();
|
|
|
|
|
|
|
|
|
|
ApiClient.sendSystemCommand(id, 'ToggleMute');
|
|
|
|
|
});
|
|
|
|
|
|
2013-07-11 13:43:37 -07:00
|
|
|
|
$('.btnStop', popup).on('click', function () {
|
|
|
|
|
|
|
|
|
|
var id = $('#selectSession', popup).val();
|
|
|
|
|
|
|
|
|
|
ApiClient.sendPlayStateCommand(id, 'Stop');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnPause', popup).on('click', function () {
|
|
|
|
|
|
|
|
|
|
var id = $('#selectSession', popup).val();
|
|
|
|
|
|
|
|
|
|
ApiClient.sendPlayStateCommand(id, 'Pause');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnPlay', popup).on('click', function () {
|
|
|
|
|
|
|
|
|
|
var id = $('#selectSession', popup).val();
|
|
|
|
|
|
|
|
|
|
ApiClient.sendPlayStateCommand(id, 'Unpause');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnNextTrack', popup).on('click', function () {
|
|
|
|
|
|
|
|
|
|
var id = $('#selectSession', popup).val();
|
|
|
|
|
|
|
|
|
|
ApiClient.sendPlayStateCommand(id, 'NextTrack');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnPreviousTrack', popup).on('click', function () {
|
|
|
|
|
|
|
|
|
|
var id = $('#selectSession', popup).val();
|
|
|
|
|
|
|
|
|
|
ApiClient.sendPlayStateCommand(id, 'PreviousTrack');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$("#positionSlider", popup).on("slidestart", function () {
|
|
|
|
|
|
|
|
|
|
this.isSliding = true;
|
|
|
|
|
|
|
|
|
|
}).on("slidestop", function () {
|
|
|
|
|
|
|
|
|
|
var id = $('#selectSession', popup).val();
|
|
|
|
|
|
|
|
|
|
var percent = $(this).val();
|
|
|
|
|
|
|
|
|
|
var duration = parseInt($(this).attr('data-duration'));
|
|
|
|
|
|
|
|
|
|
var position = duration * percent / 100;
|
|
|
|
|
|
|
|
|
|
ApiClient.sendPlayStateCommand(id, 'Seek',
|
|
|
|
|
{
|
2013-07-20 07:57:33 -07:00
|
|
|
|
SeekPositionTicks: parseInt(position)
|
2013-07-11 13:43:37 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.isSliding = false;
|
|
|
|
|
});
|
2014-03-20 12:12:10 -07:00
|
|
|
|
|
|
|
|
|
$('.btnFullscreen', popup).on('click', function () {
|
|
|
|
|
|
|
|
|
|
var id = $('#selectSession', popup).val();
|
|
|
|
|
|
|
|
|
|
ApiClient.sendPlayStateCommand(id, 'Fullscreen');
|
|
|
|
|
});
|
2013-07-11 13:25:12 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-21 11:40:38 -07:00
|
|
|
|
function getPlaybackHtml(session) {
|
2013-07-11 13:25:12 -07:00
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
2013-07-12 12:56:40 -07:00
|
|
|
|
html += '<p class="nowPlayingTitle" style="text-align:center;margin:1.5em 0 0;"></p>';
|
2013-07-11 13:25:12 -07:00
|
|
|
|
|
2013-07-12 12:56:40 -07:00
|
|
|
|
html += '<p class="nowPlayingImage" style="text-align:center;margin-top:.5em;"></p>';
|
2013-07-11 13:25:12 -07:00
|
|
|
|
|
2013-07-12 12:56:40 -07:00
|
|
|
|
html += '<div style="text-align:center;margin: 1em 0;">';
|
2013-07-11 13:25:12 -07:00
|
|
|
|
|
|
|
|
|
html += '<div style="text-align:right;vertical-align:middle;padding-right:20px;font-weight: bold;">';
|
|
|
|
|
html += '<span class="nowPlayingTime"></span>';
|
|
|
|
|
html += '<span> / </span>';
|
|
|
|
|
html += '<span class="duration"></span>';
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
2014-01-04 08:41:35 -07:00
|
|
|
|
html += '<div class="remotePositionSliderContainer"><input type="range" name="positionSlider" id="positionSlider" min="0" max="100" value="50" step=".1" style="display:none;" /></div>';
|
2013-07-11 13:25:12 -07:00
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
html += '<div style="text-align:center; margin: 0 0 2em;">';
|
2013-12-24 11:37:29 -07:00
|
|
|
|
html += '<button class="btnPreviousTrack" type="button" data-icon="previous-track" data-inline="true" data-iconpos="notext">Previous track</button>';
|
2013-07-11 13:25:12 -07:00
|
|
|
|
html += '<span class="btnPauseParent"><button class="btnPause" type="button" data-icon="pause" data-inline="true" data-iconpos="notext">Pause</button></span>';
|
|
|
|
|
html += '<span class="btnPlayParent"><button class="btnPlay" type="button" data-icon="play" data-inline="true" data-iconpos="notext">Play</button></span>';
|
|
|
|
|
html += '<button class="btnStop" type="button" data-icon="stop" data-inline="true" data-iconpos="notext">Stop</button>';
|
2013-12-24 11:37:29 -07:00
|
|
|
|
html += '<button class="btnNextTrack" type="button" data-icon="next-track" data-inline="true" data-iconpos="notext">Next track</button>';
|
2013-08-27 22:44:43 -07:00
|
|
|
|
html += '<button class="btnVolumeDown" type="button" data-icon="volume-down" data-inline="true" data-iconpos="notext">Decrease volume</button>';
|
|
|
|
|
html += '<button class="btnVolumeUp" type="button" data-icon="volume-up" data-inline="true" data-iconpos="notext">Increase volume</button>';
|
|
|
|
|
html += '<button class="btnToggleMute" type="button" data-icon="volume-off" data-inline="true" data-iconpos="notext">Toggle mute</button>';
|
2014-03-21 11:40:38 -07:00
|
|
|
|
|
|
|
|
|
if (session && session.SupportsFullscreenToggle) {
|
|
|
|
|
html += '<button class="btnFullscreen" type="button" data-icon="action" data-inline="true" data-iconpos="notext">Toggle fullscreen</button>';
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-11 13:25:12 -07:00
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return html;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateSessionInfo(popup, sessions) {
|
|
|
|
|
|
|
|
|
|
var id = $('#selectSession', popup).val();
|
|
|
|
|
|
|
|
|
|
// don't display the current session
|
|
|
|
|
var session = sessions.filter(function (s) {
|
|
|
|
|
return s.Id == id;
|
|
|
|
|
})[0];
|
|
|
|
|
|
2013-07-11 13:46:18 -07:00
|
|
|
|
if (!session) {
|
|
|
|
|
|
|
|
|
|
$('.nothingPlaying', popup).hide();
|
|
|
|
|
$('.nowPlaying', popup).hide();
|
2013-08-27 22:52:00 -07:00
|
|
|
|
$('.commandsCollapsible', popup).hide();
|
2013-07-11 13:46:18 -07:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (session.NowPlayingItem) {
|
2013-07-11 13:25:12 -07:00
|
|
|
|
|
2013-08-27 22:52:00 -07:00
|
|
|
|
$('.commandsCollapsible', popup).show();
|
2013-07-11 13:25:12 -07:00
|
|
|
|
$('.nothingPlaying', popup).hide();
|
|
|
|
|
|
|
|
|
|
var elem = $('.nowPlaying', popup).show();
|
|
|
|
|
|
|
|
|
|
updateNowPlaying(elem, session);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
2013-08-27 22:52:00 -07:00
|
|
|
|
$('.commandsCollapsible', popup).show();
|
2013-07-11 13:25:12 -07:00
|
|
|
|
$('.nothingPlaying', popup).show();
|
|
|
|
|
$('.nowPlaying', popup).hide();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateNowPlaying(elem, session) {
|
|
|
|
|
|
|
|
|
|
var item = session.NowPlayingItem;
|
|
|
|
|
|
|
|
|
|
$('.nowPlayingTitle', elem).html(item.Name);
|
|
|
|
|
|
|
|
|
|
var imageContainer = $('.nowPlayingImage', elem);
|
|
|
|
|
|
|
|
|
|
if (item.PrimaryImageTag) {
|
|
|
|
|
imageContainer.show();
|
|
|
|
|
|
|
|
|
|
var img = $('img', imageContainer)[0];
|
|
|
|
|
|
|
|
|
|
var imgUrl = ApiClient.getImageUrl(item.Id, {
|
2013-07-12 12:56:40 -07:00
|
|
|
|
maxheight: 300,
|
2013-07-11 13:25:12 -07:00
|
|
|
|
type: 'Primary',
|
|
|
|
|
tag: item.PrimaryImageTag
|
|
|
|
|
});
|
2013-07-11 13:43:37 -07:00
|
|
|
|
|
2013-07-11 13:25:12 -07:00
|
|
|
|
if (!img || img.src.toLowerCase().indexOf(imgUrl.toLowerCase()) == -1) {
|
2013-07-12 12:56:40 -07:00
|
|
|
|
imageContainer.html('<img style="max-height:150px;" src="' + imgUrl + '" />');
|
2013-07-11 13:25:12 -07:00
|
|
|
|
}
|
2013-07-11 13:43:37 -07:00
|
|
|
|
|
2013-07-11 13:25:12 -07:00
|
|
|
|
} else {
|
|
|
|
|
imageContainer.hide();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-24 08:08:51 -07:00
|
|
|
|
if (session.CanSeek) {
|
2014-01-04 08:41:35 -07:00
|
|
|
|
$('.remotePositionSliderContainer', elem).show();
|
2013-09-24 08:08:51 -07:00
|
|
|
|
} else {
|
2014-01-04 08:41:35 -07:00
|
|
|
|
$('.remotePositionSliderContainer', elem).hide();
|
2013-09-24 08:08:51 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-11 13:25:12 -07:00
|
|
|
|
var time = session.NowPlayingPositionTicks || 0;
|
|
|
|
|
var duration = item.RunTimeTicks || 0;
|
|
|
|
|
|
|
|
|
|
var percent = duration ? 100 * time / duration : 0;
|
|
|
|
|
|
2013-07-11 13:43:37 -07:00
|
|
|
|
var slider = $('#positionSlider', elem);
|
2013-09-24 08:08:51 -07:00
|
|
|
|
|
2013-07-11 13:43:37 -07:00
|
|
|
|
if (!slider[0].isSliding) {
|
|
|
|
|
slider.val(percent).slider('refresh');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
slider.attr('data-duration', duration);
|
2013-07-11 13:25:12 -07:00
|
|
|
|
|
|
|
|
|
$('.nowPlayingTime', elem).html(Dashboard.getDisplayTime(time));
|
|
|
|
|
$('.duration', elem).html(Dashboard.getDisplayTime(duration));
|
|
|
|
|
|
|
|
|
|
if (session.IsPaused) {
|
|
|
|
|
$('.btnPauseParent', elem).hide();
|
|
|
|
|
$('.btnPlayParent', elem).show();
|
|
|
|
|
} else {
|
|
|
|
|
$('.btnPauseParent', elem).show();
|
|
|
|
|
$('.btnPlayParent', elem).hide();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-26 12:24:12 -07:00
|
|
|
|
function renderSessionsInControlMenu(popup, sessions, options) {
|
2013-07-11 13:25:12 -07:00
|
|
|
|
|
2013-12-26 12:24:12 -07:00
|
|
|
|
options = options || {};
|
2014-01-03 21:53:49 -07:00
|
|
|
|
|
2013-07-11 13:25:12 -07:00
|
|
|
|
var deviceId = ApiClient.deviceId();
|
|
|
|
|
|
|
|
|
|
// don't display the current session
|
|
|
|
|
sessions = sessions.filter(function (s) {
|
|
|
|
|
return s.DeviceId != deviceId && s.SupportsRemoteControl;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var elem = $('#selectSession', popup);
|
|
|
|
|
|
2013-12-26 12:24:12 -07:00
|
|
|
|
var currentValue = options.sessionId || elem.val();
|
2013-07-11 13:25:12 -07:00
|
|
|
|
|
|
|
|
|
if (currentValue) {
|
|
|
|
|
|
|
|
|
|
// Make sure the session is still active
|
|
|
|
|
var currentSession = sessions.filter(function (s) {
|
|
|
|
|
return s.Id == currentValue;
|
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
|
|
if (!currentSession) {
|
|
|
|
|
currentValue = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!currentValue && sessions.length) {
|
|
|
|
|
currentValue = sessions[0].Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
|
|
for (var i = 0, length = sessions.length; i < length; i++) {
|
|
|
|
|
|
|
|
|
|
var session = sessions[i];
|
|
|
|
|
|
2014-01-03 21:53:49 -07:00
|
|
|
|
var text = session.DeviceName;
|
2013-07-11 13:25:12 -07:00
|
|
|
|
|
|
|
|
|
if (session.UserName) {
|
|
|
|
|
text += ' - ' + session.UserName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
html += '<option value="' + session.Id + '">' + text + '</option>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
elem.html(html).val(currentValue).selectmenu('refresh');
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-28 21:00:24 -07:00
|
|
|
|
function remoteControl() {
|
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
2013-09-19 13:03:14 -07:00
|
|
|
|
var sessionQuery = {
|
|
|
|
|
SupportsRemoteControl: true,
|
|
|
|
|
ControllableByUserId: Dashboard.getCurrentUserId()
|
|
|
|
|
};
|
|
|
|
|
|
2013-12-26 12:24:12 -07:00
|
|
|
|
self.showMenu = function (options) {
|
2013-09-19 13:03:14 -07:00
|
|
|
|
ApiClient.getSessions(sessionQuery).done(function (sessions) {
|
2013-07-11 13:25:12 -07:00
|
|
|
|
|
2013-12-26 12:24:12 -07:00
|
|
|
|
showMenu(sessions, options);
|
2013-07-11 13:25:12 -07:00
|
|
|
|
|
|
|
|
|
});
|
2013-05-28 18:45:39 -07:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.RemoteControl = new remoteControl();
|
|
|
|
|
|
2014-03-29 11:20:42 -07:00
|
|
|
|
function sendPlayCommand(options, playType) {
|
|
|
|
|
|
|
|
|
|
var sessionId = MediaController.getPlayerInfo().id;
|
|
|
|
|
|
|
|
|
|
var ids = options.ids || options.items.map(function (i) {
|
|
|
|
|
return i.Id;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var remoteOptions = {
|
|
|
|
|
ItemIds: ids.join(','),
|
|
|
|
|
|
|
|
|
|
PlayCommand: playType
|
|
|
|
|
};
|
2014-04-06 10:53:23 -07:00
|
|
|
|
|
2014-03-29 11:20:42 -07:00
|
|
|
|
if (options.startPositionTicks) {
|
|
|
|
|
remoteOptions.startPositionTicks = options.startPositionTicks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ApiClient.sendPlayCommand(sessionId, remoteOptions);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-29 09:58:49 -07:00
|
|
|
|
function remoteControlPlayer() {
|
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
self.name = 'Remote Control';
|
|
|
|
|
|
|
|
|
|
self.play = function (options) {
|
|
|
|
|
|
2014-03-29 11:20:42 -07:00
|
|
|
|
sendPlayCommand(options, 'PlayNow');
|
2014-03-29 09:58:49 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.shuffle = function (id) {
|
|
|
|
|
|
2014-03-29 11:20:42 -07:00
|
|
|
|
sendPlayCommand({ ids: [id] }, 'PlayShuffle');
|
2014-03-29 09:58:49 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.instantMix = function (id) {
|
|
|
|
|
|
2014-03-29 11:20:42 -07:00
|
|
|
|
sendPlayCommand({ ids: [id] }, 'PlayInstantMix');
|
2014-03-29 09:58:49 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.queue = function (options) {
|
|
|
|
|
|
2014-03-29 11:20:42 -07:00
|
|
|
|
sendPlayCommand(options, 'PlayNext');
|
2014-03-29 09:58:49 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.queueNext = function (options) {
|
|
|
|
|
|
2014-03-29 11:20:42 -07:00
|
|
|
|
sendPlayCommand(options, 'PlayLast');
|
2014-03-29 09:58:49 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.canQueueMediaType = function (mediaType) {
|
|
|
|
|
|
2014-03-29 11:20:42 -07:00
|
|
|
|
return mediaType == 'Audio' || mediaType == 'Video';
|
2014-03-29 09:58:49 -07:00
|
|
|
|
};
|
|
|
|
|
|
2014-04-05 10:01:04 -07:00
|
|
|
|
self.stop = function () {
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.mute = function () {
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.unMute = function () {
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.toggleMute = function () {
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2014-03-29 09:58:49 -07:00
|
|
|
|
self.getTargets = function () {
|
|
|
|
|
|
|
|
|
|
var deferred = $.Deferred();
|
|
|
|
|
|
2014-03-29 12:02:43 -07:00
|
|
|
|
var sessionQuery = {
|
|
|
|
|
SupportsRemoteControl: true,
|
|
|
|
|
ControllableByUserId: Dashboard.getCurrentUserId()
|
|
|
|
|
};
|
2014-03-29 09:58:49 -07:00
|
|
|
|
|
2014-03-29 12:02:43 -07:00
|
|
|
|
ApiClient.getSessions(sessionQuery).done(function (sessions) {
|
2014-03-29 11:20:42 -07:00
|
|
|
|
|
|
|
|
|
var targets = sessions.filter(function (s) {
|
2014-03-29 09:58:49 -07:00
|
|
|
|
|
|
|
|
|
return s.DeviceId != ApiClient.deviceId();
|
|
|
|
|
|
2014-03-29 11:20:42 -07:00
|
|
|
|
}).map(function (s) {
|
2014-03-29 09:58:49 -07:00
|
|
|
|
return {
|
|
|
|
|
name: s.DeviceName,
|
|
|
|
|
id: s.Id,
|
2014-03-29 11:20:42 -07:00
|
|
|
|
playerName: self.name,
|
|
|
|
|
appName: s.Client,
|
2014-04-05 10:01:04 -07:00
|
|
|
|
playableMediaTypes: s.PlayableMediaTypes,
|
|
|
|
|
isLocalPlayer: false
|
2014-03-29 09:58:49 -07:00
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
deferred.resolveWith(null, [targets]);
|
|
|
|
|
|
2014-03-29 11:20:42 -07:00
|
|
|
|
}).fail(function () {
|
|
|
|
|
|
2014-03-29 09:58:49 -07:00
|
|
|
|
deferred.reject();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return deferred.promise();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MediaController.registerPlayer(new remoteControlPlayer());
|
|
|
|
|
|
2014-04-06 10:53:23 -07:00
|
|
|
|
function onWebSocketMessageReceived(e, msg) {
|
|
|
|
|
|
|
|
|
|
if (msg.MessageType === "SessionEnded") {
|
|
|
|
|
|
|
|
|
|
console.log("Server reports another session ended");
|
|
|
|
|
|
|
|
|
|
if (MediaController.getPlayerInfo().id == msg.Data.Id) {
|
|
|
|
|
MediaController.setDefaultPlayerActive();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(ApiClient).on("websocketmessage", onWebSocketMessageReceived);
|
|
|
|
|
|
2013-05-28 18:45:39 -07:00
|
|
|
|
})(window, document, jQuery);
|