1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

add new playback checkin endpoints

This commit is contained in:
Luke Pulverenti 2014-04-15 22:17:48 -04:00
parent 9d82e0b573
commit 41a068e1b7
6 changed files with 84 additions and 514 deletions

View file

@ -857,8 +857,8 @@ progress {
display: inline-block; display: inline-block;
position: relative; position: relative;
margin: 5px; margin: 5px;
width: 250px; width: 275px;
height: 140.625px; height: 154.6875px;
} }
.sessionNowPlayingContent { .sessionNowPlayingContent {

View file

@ -211,7 +211,7 @@
var className = nowPlayingItem ? 'activeSession' : 'notPlayingSession activeSession'; var className = nowPlayingItem ? 'activeSession' : 'notPlayingSession activeSession';
html += '<a class="' + className + '" id="' + rowId + '" href="nowplaying.html">'; html += '<a class="' + className + '" id="' + rowId + '" href="nowplaying.html?id=' + connection.Id + '">';
html += '<div class="sessionNowPlayingContent"'; html += '<div class="sessionNowPlayingContent"';
@ -262,9 +262,10 @@
} }
html += '</div>'; html += '</div>';
if (nowPlayingItem) { if (nowPlayingItem && nowPlayingItem.RunTimeTicks) {
var value = (100 * connection.NowPlayingPositionTicks) / nowPlayingItem.RunTimeTicks; var position = connection.PlayState.PositionTicks || 0;
var value = (100 * position) / nowPlayingItem.RunTimeTicks;
html += '<progress class="itemProgressBar" min="0" max="100" value="' + value + '"></progress>'; html += '<progress class="itemProgressBar" min="0" max="100" value="' + value + '"></progress>';
} else { } else {
@ -284,12 +285,12 @@
getNowPlayingName: function (session) { getNowPlayingName: function (session) {
var nowPlayingItem = session.NowPlayingItem; var nowPlayingItem = session.NowPlayingItem;
if (!nowPlayingItem) { if (!nowPlayingItem) {
return 'Last seen ' + humane_date(session.LastActivityDate); return 'Last seen ' + humane_date(session.LastActivityDate);
} }
var topText = nowPlayingItem.Name; var topText = nowPlayingItem.Name;
if (nowPlayingItem.MediaType == 'Video') { if (nowPlayingItem.MediaType == 'Video') {
@ -339,7 +340,7 @@
if (session.UserId && session.UserPrimaryImageTag) { if (session.UserId && session.UserPrimaryImageTag) {
return ApiClient.getUserImageUrl(session.UserId, { return ApiClient.getUserImageUrl(session.UserId, {
tag: session.UserPrimaryImageTag, tag: session.UserPrimaryImageTag,
height: 24, height: 24,
type: 'Primary' type: 'Primary'
@ -368,7 +369,8 @@
if (nowPlayingItem && nowPlayingItem.RunTimeTicks) { if (nowPlayingItem && nowPlayingItem.RunTimeTicks) {
var value = (100 * session.NowPlayingPositionTicks) / nowPlayingItem.RunTimeTicks; var position = session.PlayState.PositionTicks || 0;
var value = (100 * position) / nowPlayingItem.RunTimeTicks;
$('progress', row).show().val(value); $('progress', row).show().val(value);
} else { } else {

View file

@ -2,11 +2,11 @@
var enableMirrorMode; var enableMirrorMode;
var currentDisplayInfo; var currentDisplayInfo;
function mirrorItem(info) { function mirrorItem(info) {
var item = info.item; var item = info.item;
MediaController.getCurrentPlayer().displayContent({ MediaController.getCurrentPlayer().displayContent({
itemName: item.Name, itemName: item.Name,
@ -345,6 +345,8 @@
html += '<form><h3>Select Player:</h3>'; html += '<form><h3>Select Player:</h3>';
html += '<fieldset data-role="controlgroup" data-mini="true">'; html += '<fieldset data-role="controlgroup" data-mini="true">';
var checkedHtml;
for (var i = 0, length = targets.length; i < length; i++) { for (var i = 0, length = targets.length; i < length; i++) {
var target = targets[i]; var target = targets[i];
@ -352,7 +354,7 @@
var id = 'radioPlayerTarget' + i; var id = 'radioPlayerTarget' + i;
var isChecked = target.id == playerInfo.id; var isChecked = target.id == playerInfo.id;
var checkedHtml = isChecked ? ' checked="checked"' : ''; checkedHtml = isChecked ? ' checked="checked"' : '';
var mirror = (!target.isLocalPlayer && target.supportedCommands.indexOf('DisplayContent') != -1) ? 'true' : 'false'; var mirror = (!target.isLocalPlayer && target.supportedCommands.indexOf('DisplayContent') != -1) ? 'true' : 'false';
@ -370,7 +372,7 @@
html += '<p class="fieldDescription">All plays will be sent to the selected player.</p>'; html += '<p class="fieldDescription">All plays will be sent to the selected player.</p>';
var checkedHtml = enableMirrorMode ? ' checked="checked"' : ''; checkedHtml = enableMirrorMode ? ' checked="checked"' : '';
html += '<div style="margin-top:1.5em;" class="fldMirrorMode"><label for="chkEnableMirrorMode">Enable Mirror Mode</label><input type="checkbox" class="chkEnableMirrorMode" id="chkEnableMirrorMode" data-mini="true"' + checkedHtml + ' /></div>'; html += '<div style="margin-top:1.5em;" class="fldMirrorMode"><label for="chkEnableMirrorMode">Enable Mirror Mode</label><input type="checkbox" class="chkEnableMirrorMode" id="chkEnableMirrorMode" data-mini="true"' + checkedHtml + ' /></div>';
html += '</form>'; html += '</form>';
@ -401,7 +403,7 @@
$('.chkEnableMirrorMode', elem).on().on('change', function () { $('.chkEnableMirrorMode', elem).on().on('change', function () {
enableMirrorMode = this.checked; enableMirrorMode = this.checked;
if (this.checked && currentDisplayInfo) { if (this.checked && currentDisplayInfo) {
mirrorItem(currentDisplayInfo); mirrorItem(currentDisplayInfo);

View file

@ -1029,7 +1029,15 @@
self.updateCanClientSeek(playerElement); self.updateCanClientSeek(playerElement);
ApiClient.reportPlaybackStart(Dashboard.getCurrentUserId(), item.Id, mediaSource.Id, true, item.MediaType); ApiClient.reportPlaybackStart({
itemId: item.Id,
QueueableMediaTypes: item.MediaType,
CanSeek: mediaSource.RunTimeTicks != null,
MediaSourceId: mediaSource.Id,
IsPaused: playerElement.paused,
IsMuted: playerElement.volume == 0,
VolumeLevel: playerElement.volume * 100
});
self.startProgressInterval(item.Id, mediaSource.Id); self.startProgressInterval(item.Id, mediaSource.Id);
@ -1064,7 +1072,13 @@
var item = currentItem; var item = currentItem;
var mediaSource = currentMediaSource; var mediaSource = currentMediaSource;
ApiClient.reportPlaybackStopped(Dashboard.getCurrentUserId(), item.Id, mediaSource.Id, position); ApiClient.reportPlaybackStopped({
itemId: item.Id,
mediaSourceId: mediaSource.Id,
positionTicks: position
});
if (item.MediaType == "Video") { if (item.MediaType == "Video") {
ApiClient.stopActiveEncodings(); ApiClient.stopActiveEncodings();
@ -1105,7 +1119,14 @@
function sendProgressUpdate(itemId, mediaSourceId) { function sendProgressUpdate(itemId, mediaSourceId) {
ApiClient.reportPlaybackProgress(Dashboard.getCurrentUserId(), itemId, mediaSourceId, self.getCurrentTicks(), currentMediaElement.paused, currentMediaElement.volume == 0); ApiClient.reportPlaybackProgress({
itemId: itemId,
MediaSourceId: mediaSourceId,
IsPaused: currentMediaElement.paused,
IsMuted: currentMediaElement.volume == 0,
VolumeLevel: currentMediaElement.volume * 100,
PositionTicks: self.getCurrentTicks()
});
} }
function clearProgressInterval() { function clearProgressInterval() {

View file

@ -1,416 +1,5 @@
(function (window, document, $) { (function (window, document, $) {
function showMenu(sessions, options) {
var html = '<div data-role="popup" data-transition="slidedown" class="remoteControlFlyout" data-theme="a">';
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;">';
html += '<div style="margin:.5em 0;">Remote Control</div>';
html += '</div>';
html += '<div style="padding: 1em;">';
html += '<div class="sessionsPopupContent">';
// Add controls here
html += '<div>';
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;">';
html += getPlaybackHtml(sessions.currentSession);
html += '</div>';
html += '<p class="nothingPlaying" style="display:none;">Nothing is currently playing.</p>';
html += '</div>';
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>';
html += '<p class="sessionButtons" style="text-align:center;">';
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>';
html += '</p>';
html += '<p style="text-align:center;">';
html += '<div><label for="txtMessage">Message text</label></div>';
html += '<input id="txtMessage" name="txtMessage" type="text" />';
html += '<button type="button" data-icon="mail" class="btnSendMessage" data-mini="true">Send Message</button>';
html += '</p>';
html += '</div>';
html += '</div>';
html += '</div>';
html += '</div>';
$(document.body).append(html);
var popup = $('.remoteControlFlyout').popup({ history: false, tolerance: 0, corners: false }).trigger('create').popup("open").on("popupafterclose", function () {
if (ApiClient.isWebSocketOpen()) {
ApiClient.sendWebSocketMessage("SessionsStop");
}
$(ApiClient).off("websocketmessage.remotecontrol");
$(this).off("popupafterclose").remove();
$('.remoteControlFlyout').popup("destroy").remove();
});
renderSessionsInControlMenu(popup, sessions, options);
updateSessionInfo(popup, sessions, options);
if (ApiClient.isWebSocketOpen()) {
ApiClient.sendWebSocketMessage("SessionsStart", "1000,1000");
$(ApiClient).on("websocketmessage.remotecontrol", function (e, msg) {
if (msg.MessageType === "Sessions") {
// Update existing data
updateSessionInfo(popup, msg.Data);
}
});
}
$('.btnGoHome', popup).on('click', function () {
var id = $('#selectSession', popup).val();
ApiClient.sendCommand(id, 'GoHome');
});
$('.btnGoToSettings', popup).on('click', function () {
var id = $('#selectSession', popup).val();
ApiClient.sendCommand(id, 'GoToSettings');
});
$('.btnSendMessage', popup).on('click', function () {
var id = $('#selectSession', popup).val();
var messageText = $('#txtMessage', popup).val();
if (messageText) {
Dashboard.getCurrentUser().done(function (user) {
ApiClient.sendMessageCommand(id, {
Header: "Message from " + user.Name,
Text: messageText
});
});
} else {
$('#txtMessage', popup)[0].focus();
}
});
$('.btnVolumeDown', popup).on('click', function () {
var id = $('#selectSession', popup).val();
ApiClient.sendCommand(id, 'VolumeDown');
});
$('.btnVolumeUp', popup).on('click', function () {
var id = $('#selectSession', popup).val();
ApiClient.sendCommand(id, 'VolumeUp');
});
$('.btnToggleMute', popup).on('click', function () {
var id = $('#selectSession', popup).val();
ApiClient.sendCommand(id, 'ToggleMute');
});
$('.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',
{
SeekPositionTicks: parseInt(position)
});
this.isSliding = false;
});
$('.btnFullscreen', popup).on('click', function () {
var id = $('#selectSession', popup).val();
ApiClient.sendPlayStateCommand(id, 'Fullscreen');
});
}
function getPlaybackHtml(session) {
var html = '';
html += '<p class="nowPlayingTitle" style="text-align:center;margin:1.5em 0 0;"></p>';
html += '<p class="nowPlayingImage" style="text-align:center;margin-top:.5em;"></p>';
html += '<div style="text-align:center;margin: 1em 0;">';
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>';
html += '<div class="remotePositionSliderContainer"><input type="range" name="positionSlider" id="positionSlider" min="0" max="100" value="50" step=".1" style="display:none;" /></div>';
html += '</div>';
html += '<div style="text-align:center; margin: 0 0 2em;">';
html += '<button class="btnPreviousTrack" type="button" data-icon="previous-track" data-inline="true" data-iconpos="notext">Previous track</button>';
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>';
html += '<button class="btnNextTrack" type="button" data-icon="next-track" data-inline="true" data-iconpos="notext">Next track</button>';
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>';
if (session && session.SupportsFullscreenToggle) {
html += '<button class="btnFullscreen" type="button" data-icon="action" data-inline="true" data-iconpos="notext">Toggle fullscreen</button>';
}
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];
if (!session) {
$('.nothingPlaying', popup).hide();
$('.nowPlaying', popup).hide();
$('.commandsCollapsible', popup).hide();
}
else if (session.NowPlayingItem) {
$('.commandsCollapsible', popup).show();
$('.nothingPlaying', popup).hide();
var elem = $('.nowPlaying', popup).show();
updateNowPlaying(elem, session);
} else {
$('.commandsCollapsible', popup).show();
$('.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, {
maxheight: 300,
type: 'Primary',
tag: item.PrimaryImageTag
});
if (!img || img.src.toLowerCase().indexOf(imgUrl.toLowerCase()) == -1) {
imageContainer.html('<img style="max-height:150px;" src="' + imgUrl + '" />');
}
} else {
imageContainer.hide();
}
if (session.CanSeek) {
$('.remotePositionSliderContainer', elem).show();
} else {
$('.remotePositionSliderContainer', elem).hide();
}
var time = session.NowPlayingPositionTicks || 0;
var duration = item.RunTimeTicks || 0;
var percent = duration ? 100 * time / duration : 0;
var slider = $('#positionSlider', elem);
if (!slider[0].isSliding) {
slider.val(percent).slider('refresh');
}
slider.attr('data-duration', duration);
$('.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();
}
}
function renderSessionsInControlMenu(popup, sessions, options) {
options = options || {};
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);
var currentValue = options.sessionId || elem.val();
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];
var text = session.DeviceName;
if (session.UserName) {
text += ' - ' + session.UserName;
}
html += '<option value="' + session.Id + '">' + text + '</option>';
}
elem.html(html).val(currentValue).selectmenu('refresh');
}
function remoteControl() {
var self = this;
var sessionQuery = {
SupportsRemoteControl: true,
ControllableByUserId: Dashboard.getCurrentUserId()
};
self.showMenu = function (options) {
ApiClient.getSessions(sessionQuery).done(function (sessions) {
showMenu(sessions, options);
});
};
}
window.RemoteControl = new remoteControl();
function sendPlayCommand(options, playType) { function sendPlayCommand(options, playType) {
var sessionId = MediaController.getPlayerInfo().id; var sessionId = MediaController.getPlayerInfo().id;
@ -554,7 +143,7 @@
var session = sessions.filter(function (s) { var session = sessions.filter(function (s) {
return s.Id == currentTargetId; return s.Id == currentTargetId;
})[0]; })[0];
if (session) { if (session) {
session = getPlayerState(session); session = getPlayerState(session);
} }
@ -649,12 +238,22 @@
function getPlayerState(session) { function getPlayerState(session) {
var state = { var state = {};
volumeLevel: session.VolumeLevel,
isMuted: session.IsMuted, var playerState = session.PlayState;
isPaused: session.IsPaused,
canSeek: session.CanSeek if (playerState) {
};
state.isMuted = playerState.IsMuted;
state.isPaused = playerState.IsPaused;
state.canSeek = playerState.CanSeek;
state.positionTicks = playerState.PositionTicks || 0;
state.mediaSource = playerState.MediaSourceId;
state.volumeLevel = playerState.VolumeLevel;
state.audioStreamIndex = playerState.AudioStreamIndex;
state.subtitleStreamIndex = playerState.SubtitleStreamIndex;
}
var item = session.NowPlayingItem; var item = session.NowPlayingItem;
@ -682,8 +281,6 @@
state.thumbItemId = item.ThumbItemId; state.thumbItemId = item.ThumbItemId;
state.thumbImageTag = item.ThumbImageTag; state.thumbImageTag = item.ThumbImageTag;
state.mediaSource = item.MediaSourceId;
state.positionTicks = session.NowPlayingPositionTicks || 0;
state.runtimeTicks = item.RunTimeTicks; state.runtimeTicks = item.RunTimeTicks;
} }

View file

@ -3600,48 +3600,30 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
* @param {String} userId * @param {String} userId
* @param {String} itemId * @param {String} itemId
*/ */
self.reportPlaybackStart = function (userId, itemId, mediaSourceId, canSeek, queueableMediaTypes) { self.reportPlaybackStart = function (options) {
if (!userId) { if (!options) {
throw new Error("null userId"); throw new Error("null options");
} }
if (!itemId) {
throw new Error("null itemId");
}
canSeek = canSeek || false;
queueableMediaTypes = queueableMediaTypes || '';
if (self.isWebSocketOpen()) { if (self.isWebSocketOpen()) {
var deferred = $.Deferred(); var deferred = $.Deferred();
var msg = [itemId, canSeek, queueableMediaTypes]; var msg = JSON.stringify(options);
if (mediaSourceId) { self.sendWebSocketMessage("ReportPlaybackStart", msg);
msg.push(mediaSourceId);
}
self.sendWebSocketMessage("PlaybackStart", msg.join('|'));
deferred.resolveWith(null, []); deferred.resolveWith(null, []);
return deferred.promise(); return deferred.promise();
} }
var params = { var url = self.getUrl("Sessions/Playing");
CanSeek: canSeek,
QueueableMediaTypes: queueableMediaTypes
};
if (mediaSourceId) {
params.mediaSourceId = mediaSourceId;
}
var url = self.getUrl("Users/" + userId + "/PlayingItems/" + itemId, params);
return self.ajax({ return self.ajax({
type: "POST", type: "POST",
data: JSON.stringify(options),
contentType: "application/json",
url: url url: url
}); });
}; };
@ -3651,50 +3633,30 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
* @param {String} userId * @param {String} userId
* @param {String} itemId * @param {String} itemId
*/ */
self.reportPlaybackProgress = function (userId, itemId, mediaSourceId, positionTicks, isPaused, isMuted) { self.reportPlaybackProgress = function (options) {
if (!userId) { if (!options) {
throw new Error("null userId"); throw new Error("null options");
}
if (!itemId) {
throw new Error("null itemId");
} }
if (self.isWebSocketOpen()) { if (self.isWebSocketOpen()) {
var deferred = $.Deferred(); var deferred = $.Deferred();
var msgData = itemId; var msg = JSON.stringify(options);
msgData += "|" + (positionTicks == null ? "" : positionTicks); self.sendWebSocketMessage("ReportPlaybackProgress", msg);
msgData += "|" + (isPaused == null ? "" : isPaused);
msgData += "|" + (isMuted == null ? "" : isMuted);
msgData += "|" + (mediaSourceId == null ? "" : mediaSourceId);
self.sendWebSocketMessage("PlaybackProgress", msgData);
deferred.resolveWith(null, []); deferred.resolveWith(null, []);
return deferred.promise(); return deferred.promise();
} }
var params = { var url = self.getUrl("Sessions/Playing/Progress");
isPaused: isPaused,
isMuted: isMuted
};
if (positionTicks) {
params.positionTicks = positionTicks;
}
if (mediaSourceId) {
params.mediaSourceId = mediaSourceId;
}
var url = self.getUrl("Users/" + userId + "/PlayingItems/" + itemId + "/Progress", params);
return self.ajax({ return self.ajax({
type: "POST", type: "POST",
data: JSON.stringify(options),
contentType: "application/json",
url: url url: url
}); });
}; };
@ -3704,44 +3666,30 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
* @param {String} userId * @param {String} userId
* @param {String} itemId * @param {String} itemId
*/ */
self.reportPlaybackStopped = function (userId, itemId, mediaSourceId, positionTicks) { self.reportPlaybackStopped = function (options) {
if (!userId) { if (!options) {
throw new Error("null userId"); throw new Error("null options");
}
if (!itemId) {
throw new Error("null itemId");
} }
if (self.isWebSocketOpen()) { if (self.isWebSocketOpen()) {
var deferred = $.Deferred(); var deferred = $.Deferred();
var msg = itemId; var msg = JSON.stringify(options);
msg += "|" + (positionTicks == null ? "" : positionTicks);
msg += "|" + (mediaSourceId == null ? "" : mediaSourceId);
self.sendWebSocketMessage("PlaybackStopped", msg); self.sendWebSocketMessage("ReportPlaybackStopped", msg);
deferred.resolveWith(null, []); deferred.resolveWith(null, []);
return deferred.promise(); return deferred.promise();
} }
var params = {}; var url = self.getUrl("Sessions/Playing/Stopped");
if (positionTicks) {
params.positionTicks = positionTicks;
}
if (mediaSourceId) {
params.mediaSourceId = mediaSourceId;
}
var url = self.getUrl("Users/" + userId + "/PlayingItems/" + itemId, params);
return self.ajax({ return self.ajax({
type: "DELETE", type: "POST",
data: JSON.stringify(options),
contentType: "application/json",
url: url url: url
}); });
}; };