updated browse to command
This commit is contained in:
parent
de25a42680
commit
3a587a5d08
|
@ -51,9 +51,16 @@ namespace MediaBrowser.Api
|
||||||
/// Artist name, genre name, item Id, etc
|
/// Artist name, genre name, item Id, etc
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The item identifier.</value>
|
/// <value>The item identifier.</value>
|
||||||
[ApiMember(Name = "ItemIdentifier", Description = "The Id of the item, unless it is an Artist, Genre, Studio, or Person, in which case it should be the name.", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
|
[ApiMember(Name = "ItemId", Description = "The Id of the item.", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
|
||||||
public string ItemIdentifier { get; set; }
|
public string ItemId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the name of the item.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The name of the item.</value>
|
||||||
|
[ApiMember(Name = "ItemName", Description = "The name of the item.", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
|
||||||
|
public string ItemName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the context (Movies, Music, TvShows, etc)
|
/// Gets or sets the context (Movies, Music, TvShows, etc)
|
||||||
/// Applicable to genres, studios and persons only because the context of items and artists can be inferred.
|
/// Applicable to genres, studios and persons only because the context of items and artists can be inferred.
|
||||||
|
@ -105,7 +112,7 @@ namespace MediaBrowser.Api
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request">The request.</param>
|
/// <param name="request">The request.</param>
|
||||||
/// <exception cref="ResourceNotFoundException"></exception>
|
/// <exception cref="ResourceNotFoundException"></exception>
|
||||||
public void Post(BrowseTo request)
|
public async void Post(BrowseTo request)
|
||||||
{
|
{
|
||||||
var session = _sessionManager.Sessions.FirstOrDefault(i => i.Id == request.Id);
|
var session = _sessionManager.Sessions.FirstOrDefault(i => i.Id == request.Id);
|
||||||
|
|
||||||
|
@ -114,14 +121,27 @@ namespace MediaBrowser.Api
|
||||||
throw new ResourceNotFoundException(string.Format("Session {0} not found.", request.Id));
|
throw new ResourceNotFoundException(string.Format("Session {0} not found.", request.Id));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var socket in session.WebSockets)
|
var socket = session.WebSockets.OrderByDescending(i => i.LastActivityDate).FirstOrDefault(i => i.State == WebSocketState.Open);
|
||||||
{
|
|
||||||
socket.SendAsync(new WebSocketMessage<BrowseTo>
|
|
||||||
{
|
|
||||||
MessageType = "Browse",
|
|
||||||
Data = request
|
|
||||||
|
|
||||||
}, CancellationToken.None);
|
if (socket != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await socket.SendAsync(new WebSocketMessage<BrowseTo>
|
||||||
|
{
|
||||||
|
MessageType = "Browse",
|
||||||
|
Data = request
|
||||||
|
|
||||||
|
}, CancellationToken.None).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.ErrorException("Error sending web socket message", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("The requested session does not have an open web socket.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,12 @@ namespace MediaBrowser.Common.Net
|
||||||
{
|
{
|
||||||
public interface IWebSocketConnection : IDisposable
|
public interface IWebSocketConnection : IDisposable
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the last activity date.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The last activity date.</value>
|
||||||
|
DateTime LastActivityDate { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the receive action.
|
/// Gets or sets the receive action.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -50,6 +50,12 @@ namespace MediaBrowser.Server.Implementations.ServerManager
|
||||||
/// <value>The receive action.</value>
|
/// <value>The receive action.</value>
|
||||||
public Action<WebSocketMessageInfo> OnReceive { get; set; }
|
public Action<WebSocketMessageInfo> OnReceive { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the last activity date.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The last activity date.</value>
|
||||||
|
public DateTime LastActivityDate { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="WebSocketConnection" /> class.
|
/// Initializes a new instance of the <see cref="WebSocketConnection" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -90,6 +96,8 @@ namespace MediaBrowser.Server.Implementations.ServerManager
|
||||||
/// <param name="bytes">The bytes.</param>
|
/// <param name="bytes">The bytes.</param>
|
||||||
private void OnReceiveInternal(byte[] bytes)
|
private void OnReceiveInternal(byte[] bytes)
|
||||||
{
|
{
|
||||||
|
LastActivityDate = DateTime.UtcNow;
|
||||||
|
|
||||||
if (OnReceive == null)
|
if (OnReceive == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user