update session listener
This commit is contained in:
parent
3c92842bce
commit
f988539e13
|
@ -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 ToOptimizedResult(new LiveMediaInfoResult
|
||||
{
|
||||
MediaSources = mediaSources.ToList()
|
||||
});
|
||||
return GetPlaybackInfo(request.Id, request.UserId);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1687,16 +1687,11 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
AccessToken = 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);
|
||||
|
|
|
@ -85,7 +85,8 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
|
||||
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);
|
||||
|
||||
|
@ -98,6 +99,11 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
|
||||
private Task<SessionInfo> GetSession(NameValueCollection queryString, string remoteEndpoint)
|
||||
{
|
||||
if (queryString == null)
|
||||
{
|
||||
throw new ArgumentNullException("queryString");
|
||||
}
|
||||
|
||||
var token = queryString["api_key"];
|
||||
if (string.IsNullOrWhiteSpace(token))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user