diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-05-25 20:53:51 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-05-25 20:53:51 -0400 |
| commit | 3a587a5d088dcb9926978a524a6e2571286df19f (patch) | |
| tree | 5e56aaaf6fd030cfd610b9d3870a1121f7197821 /MediaBrowser.Api/SessionsService.cs | |
| parent | de25a426801e5ab0e0d1a77c9735e1b621a7d89e (diff) | |
updated browse to command
Diffstat (limited to 'MediaBrowser.Api/SessionsService.cs')
| -rw-r--r-- | MediaBrowser.Api/SessionsService.cs | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/MediaBrowser.Api/SessionsService.cs b/MediaBrowser.Api/SessionsService.cs index 03b90fc99..0bf0c06c6 100644 --- a/MediaBrowser.Api/SessionsService.cs +++ b/MediaBrowser.Api/SessionsService.cs @@ -51,10 +51,17 @@ namespace MediaBrowser.Api /// Artist name, genre name, item Id, etc /// </summary> /// <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")] - public string ItemIdentifier { get; set; } + [ApiMember(Name = "ItemId", Description = "The Id of the item.", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")] + 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> /// 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. /// This is optional to supply and clients are free to ignore it. @@ -105,7 +112,7 @@ namespace MediaBrowser.Api /// </summary> /// <param name="request">The request.</param> /// <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); @@ -114,14 +121,27 @@ namespace MediaBrowser.Api 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); + + if (socket != null) { - socket.SendAsync(new WebSocketMessage<BrowseTo> + try { - MessageType = "Browse", - Data = request + await socket.SendAsync(new WebSocketMessage<BrowseTo> + { + MessageType = "Browse", + Data = request - }, CancellationToken.None); + }, 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."); } } } |
