update session listener

This commit is contained in:
Luke Pulverenti 2015-03-16 12:47:14 -04:00
parent 3c92842bce
commit f988539e13
3 changed files with 34 additions and 20 deletions

View file

@ -1,7 +1,10 @@
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.MediaInfo; using MediaBrowser.Model.MediaInfo;
using ServiceStack; using ServiceStack;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -38,24 +41,34 @@ namespace MediaBrowser.Api.Playback
_mediaSourceManager = mediaSourceManager; _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 async Task<object> Get(GetLiveMediaInfo request) public Task<object> Get(GetLiveMediaInfo 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 private async Task<object> GetPlaybackInfo(string id, string userId)
{
IEnumerable<MediaSourceInfo> mediaSources;
var result = 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);
} }
} }
} }

View file

@ -1687,16 +1687,11 @@ namespace MediaBrowser.Server.Implementations.Session
AccessToken = token AccessToken = token
}); });
if (result.Items.Length == 0) var info = result.Items.FirstOrDefault();
{
return null;
}
var info = result.Items[0];
if (info == null) if (info == null)
{ {
return null; return Task.FromResult<SessionInfo>(null);
} }
return GetSessionByAuthenticationToken(info, deviceId, remoteEndpoint, null); return GetSessionByAuthenticationToken(info, deviceId, remoteEndpoint, null);

View file

@ -85,7 +85,8 @@ namespace MediaBrowser.Server.Implementations.Session
async void _httpServer_WebSocketConnecting(object sender, WebSocketConnectingEventArgs e) async 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); var session = await GetSession(e.QueryString, e.Endpoint).ConfigureAwait(false);
@ -98,6 +99,11 @@ namespace MediaBrowser.Server.Implementations.Session
private Task<SessionInfo> GetSession(NameValueCollection queryString, string remoteEndpoint) private Task<SessionInfo> GetSession(NameValueCollection queryString, string remoteEndpoint)
{ {
if (queryString == null)
{
throw new ArgumentNullException("queryString");
}
var token = queryString["api_key"]; var token = queryString["api_key"];
if (string.IsNullOrWhiteSpace(token)) if (string.IsNullOrWhiteSpace(token))
{ {