The Free Software Media System - Server Backend & API
update session listener
Luke Pulverentif988539e13e9
diff --git a/MediaBrowser.Api/Playback/MediaInfoService.cs b/MediaBrowser.Api/Playback/MediaInfoService.csindex dfb5086b9b..5adb76cc58 100644--- a/MediaBrowser.Api/Playback/MediaInfoService.cs+++ b/MediaBrowser.Api/Playback/MediaInfoService.cs@@ -1,7 +1,10 @@using MediaBrowser.Controller.Library;using MediaBrowser.Controller.Net;+using MediaBrowser.Model.Dlna;+using MediaBrowser.Model.Dto;using MediaBrowser.Model.MediaInfo;using ServiceStack;+using System.Collections.Generic;using System.Linq;using System.Threading;using System.Threading.Tasks;@@ -38,24 +41,34 @@ namespace MediaBrowser.Api.Playback_mediaSourceManager = mediaSourceManager;}- public async Task<object> Get(GetPlaybackInfo request)+ public Task<object> Get(GetPlaybackInfo request){- var mediaSources = await _mediaSourceManager.GetPlayackMediaSources(request.Id, request.UserId, true, CancellationToken.None).ConfigureAwait(false);+ return GetPlaybackInfo(request.Id, request.UserId);+ }- return ToOptimizedResult(new LiveMediaInfoResult- {- MediaSources = mediaSources.ToList()- });+ public Task<object> Get(GetLiveMediaInfo request)+ {+ return GetPlaybackInfo(request.Id, request.UserId);}- public async Task<object> Get(GetLiveMediaInfo request)+ private async Task<object> GetPlaybackInfo(string id, string userId){- var mediaSources = await _mediaSourceManager.GetPlayackMediaSources(request.Id, request.UserId, true, CancellationToken.None).ConfigureAwait(false);+ IEnumerable<MediaSourceInfo> mediaSources;+ var result = new LiveMediaInfoResult();- return ToOptimizedResult(new LiveMediaInfoResult+ try{- MediaSources = mediaSources.ToList()- });+ mediaSources = await _mediaSourceManager.GetPlayackMediaSources(id, userId, true, CancellationToken.None).ConfigureAwait(false);+ }+ catch (PlaybackException ex)+ {+ mediaSources = new List<MediaSourceInfo>();+ result.ErrorCode = ex.ErrorCode;+ }++ result.MediaSources = mediaSources.ToList();++ return ToOptimizedResult(result);}}}diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.csindex 76e97ff485..8a21ed6bdd 100644--- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs+++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs@@ -1687,16 +1687,11 @@ namespace MediaBrowser.Server.Implementations.SessionAccessToken = token});- if (result.Items.Length == 0)- {- return null;- }-- var info = result.Items[0];+ var info = result.Items.FirstOrDefault();if (info == null){- return null;+ return Task.FromResult<SessionInfo>(null);}return GetSessionByAuthenticationToken(info, deviceId, remoteEndpoint, null);diff --git a/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs b/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.csindex dda4c2b90f..b8cab0c199 100644--- a/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs+++ b/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs@@ -85,7 +85,8 @@ namespace MediaBrowser.Server.Implementations.Sessionasync void _httpServer_WebSocketConnecting(object sender, WebSocketConnectingEventArgs e){- if (e.QueryString.AllKeys.Contains("api_key", StringComparer.OrdinalIgnoreCase))+ var token = e.QueryString["api_key"];+ if (!string.IsNullOrWhiteSpace(token)){var session = await GetSession(e.QueryString, e.Endpoint).ConfigureAwait(false);@@ -98,6 +99,11 @@ namespace MediaBrowser.Server.Implementations.Sessionprivate Task<SessionInfo> GetSession(NameValueCollection queryString, string remoteEndpoint){+ if (queryString == null)+ {+ throw new ArgumentNullException("queryString");+ }+var token = queryString["api_key"];if (string.IsNullOrWhiteSpace(token)){