aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Lavado <anthony@lavado.ca>2020-02-11 23:56:47 -0500
committerGitHub <noreply@github.com>2020-02-11 23:56:47 -0500
commit00073c162a33672e64b2abcf6c561174acfab183 (patch)
tree888ca227d0226f1add7cb3e2d9b6a9d6ace8594a
parent662e1164c916098fd39469569c64f88126bedc65 (diff)
parentf93edb7ade68588f4e2e7e05932b3266105ea91a (diff)
Merge pull request #2363 from dkanada/view
Add session view endpoint
-rw-r--r--Emby.Server.Implementations/Session/SessionManager.cs54
-rw-r--r--MediaBrowser.Api/Session/SessionsService.cs28
-rw-r--r--MediaBrowser.Api/UserLibrary/PlaystateService.cs4
-rw-r--r--MediaBrowser.Api/UserService.cs2
-rw-r--r--MediaBrowser.Controller/Session/SessionInfo.cs7
5 files changed, 49 insertions, 46 deletions
diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs
index 0bba19f2a..e2cee5b03 100644
--- a/Emby.Server.Implementations/Session/SessionManager.cs
+++ b/Emby.Server.Implementations/Session/SessionManager.cs
@@ -67,17 +67,17 @@ namespace Emby.Server.Implementations.Session
public event EventHandler<GenericEventArgs<AuthenticationResult>> AuthenticationSucceeded;
/// <summary>
- /// Occurs when [playback start].
+ /// Occurs when playback has started.
/// </summary>
public event EventHandler<PlaybackProgressEventArgs> PlaybackStart;
/// <summary>
- /// Occurs when [playback progress].
+ /// Occurs when playback has progressed.
/// </summary>
public event EventHandler<PlaybackProgressEventArgs> PlaybackProgress;
/// <summary>
- /// Occurs when [playback stopped].
+ /// Occurs when playback has stopped.
/// </summary>
public event EventHandler<PlaybackStopEventArgs> PlaybackStopped;
@@ -690,7 +690,7 @@ namespace Emby.Server.Implementations.Session
}
/// <summary>
- /// Used to report playback progress for an item
+ /// Used to report playback progress for an item.
/// </summary>
/// <returns>Task.</returns>
public async Task OnPlaybackProgress(PlaybackProgressInfo info, bool isAutomated)
@@ -1383,20 +1383,16 @@ namespace Emby.Server.Implementations.Session
user = _userManager.GetUserByName(request.Username);
}
- if (user != null)
+ if (user == null)
{
- // TODO: Move this to userManager?
- if (!string.IsNullOrEmpty(request.DeviceId)
- && !_deviceManager.CanAccessDevice(user, request.DeviceId))
- {
- throw new SecurityException("User is not allowed access from this device.");
- }
+ AuthenticationFailed?.Invoke(this, new GenericEventArgs<AuthenticationRequest>(request));
+ throw new SecurityException("Invalid username or password entered.");
}
- if (user == null)
+ if (!string.IsNullOrEmpty(request.DeviceId)
+ && !_deviceManager.CanAccessDevice(user, request.DeviceId))
{
- AuthenticationFailed?.Invoke(this, new GenericEventArgs<AuthenticationRequest>(request));
- throw new SecurityException("Invalid user or password entered.");
+ throw new SecurityException("User is not allowed access from this device.");
}
if (enforcePassword)
@@ -1439,14 +1435,13 @@ namespace Emby.Server.Implementations.Session
DeviceId = deviceId,
UserId = user.Id,
Limit = 1
-
}).Items.FirstOrDefault();
- var allExistingForDevice = _authRepo.Get(new AuthenticationInfoQuery
- {
- DeviceId = deviceId
-
- }).Items;
+ var allExistingForDevice = _authRepo.Get(
+ new AuthenticationInfoQuery
+ {
+ DeviceId = deviceId
+ }).Items;
foreach (var auth in allExistingForDevice)
{
@@ -1503,7 +1498,6 @@ namespace Emby.Server.Implementations.Session
{
Limit = 1,
AccessToken = accessToken
-
}).Items.FirstOrDefault();
if (existing != null)
@@ -1696,23 +1690,24 @@ namespace Emby.Server.Implementations.Session
throw new ArgumentNullException(nameof(itemId));
}
- //var item = _libraryManager.GetItemById(new Guid(itemId));
+ var item = _libraryManager.GetItemById(new Guid(itemId));
- //var info = GetItemInfo(item, null, null);
+ var info = GetItemInfo(item, null);
- //ReportNowViewingItem(sessionId, info);
+ ReportNowViewingItem(sessionId, info);
}
public void ReportNowViewingItem(string sessionId, BaseItemDto item)
{
- //var session = GetSession(sessionId);
+ var session = GetSession(sessionId);
- //session.NowViewingItem = item;
+ session.NowViewingItem = item;
}
public void ReportTranscodingInfo(string deviceId, TranscodingInfo info)
{
- var session = Sessions.FirstOrDefault(i => string.Equals(i.DeviceId, deviceId));
+ var session = Sessions.FirstOrDefault(i =>
+ string.Equals(i.DeviceId, deviceId, StringComparison.OrdinalIgnoreCase));
if (session != null)
{
@@ -1727,8 +1722,9 @@ namespace Emby.Server.Implementations.Session
public SessionInfo GetSession(string deviceId, string client, string version)
{
- return Sessions.FirstOrDefault(i => string.Equals(i.DeviceId, deviceId) &&
- string.Equals(i.Client, client));
+ return Sessions.FirstOrDefault(i =>
+ string.Equals(i.DeviceId, deviceId, StringComparison.OrdinalIgnoreCase)
+ && string.Equals(i.Client, client, StringComparison.OrdinalIgnoreCase));
}
public SessionInfo GetSessionByAuthenticationToken(AuthenticationInfo info, string deviceId, string remoteEndpoint, string appVersion)
diff --git a/MediaBrowser.Api/Session/SessionsService.cs b/MediaBrowser.Api/Session/SessionsService.cs
index 9aa7b2c88..054371321 100644
--- a/MediaBrowser.Api/Session/SessionsService.cs
+++ b/MediaBrowser.Api/Session/SessionsService.cs
@@ -230,6 +230,17 @@ namespace MediaBrowser.Api.Session
public string Id { get; set; }
}
+ [Route("/Sessions/Viewing", "POST", Summary = "Reports that a session is viewing an item")]
+ [Authenticated]
+ public class ReportViewing : IReturnVoid
+ {
+ [ApiMember(Name = "SessionId", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
+ public string SessionId { get; set; }
+
+ [ApiMember(Name = "ItemId", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
+ public string ItemId { get; set; }
+ }
+
[Route("/Sessions/Logout", "POST", Summary = "Reports that a session has ended")]
[Authenticated]
public class ReportSessionEnded : IReturnVoid
@@ -276,7 +287,7 @@ namespace MediaBrowser.Api.Session
public class SessionsService : BaseApiService
{
/// <summary>
- /// The _session manager.
+ /// The session manager.
/// </summary>
private readonly ISessionManager _sessionManager;
@@ -438,14 +449,12 @@ namespace MediaBrowser.Api.Session
public Task Post(SendSystemCommand request)
{
var name = request.Command;
-
if (Enum.TryParse(name, true, out GeneralCommandType commandType))
{
name = commandType.ToString();
}
var currentSession = GetSession(_sessionContext);
-
var command = new GeneralCommand
{
Name = name,
@@ -518,16 +527,13 @@ namespace MediaBrowser.Api.Session
{
request.Id = GetSession(_sessionContext).Id;
}
+
_sessionManager.ReportCapabilities(request.Id, new ClientCapabilities
{
PlayableMediaTypes = SplitValue(request.PlayableMediaTypes, ','),
-
SupportedCommands = SplitValue(request.SupportedCommands, ','),
-
SupportsMediaControl = request.SupportsMediaControl,
-
SupportsSync = request.SupportsSync,
-
SupportsPersistentIdentifier = request.SupportsPersistentIdentifier
});
}
@@ -538,7 +544,15 @@ namespace MediaBrowser.Api.Session
{
request.Id = GetSession(_sessionContext).Id;
}
+
_sessionManager.ReportCapabilities(request.Id, request);
}
+
+ public void Post(ReportViewing request)
+ {
+ request.SessionId = GetSession(_sessionContext).Id;
+
+ _sessionManager.ReportNowViewingItem(request.SessionId, request.ItemId);
+ }
}
}
diff --git a/MediaBrowser.Api/UserLibrary/PlaystateService.cs b/MediaBrowser.Api/UserLibrary/PlaystateService.cs
index 9d1cf5d9e..d0faca163 100644
--- a/MediaBrowser.Api/UserLibrary/PlaystateService.cs
+++ b/MediaBrowser.Api/UserLibrary/PlaystateService.cs
@@ -103,10 +103,6 @@ namespace MediaBrowser.Api.UserLibrary
[ApiMember(Name = "MediaSourceId", Description = "The id of the MediaSource", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public string MediaSourceId { get; set; }
- /// <summary>
- /// Gets or sets a value indicating whether this <see cref="UpdateUserItemRating" /> is likes.
- /// </summary>
- /// <value><c>true</c> if likes; otherwise, <c>false</c>.</value>
[ApiMember(Name = "CanSeek", Description = "Indicates if the client can seek", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "POST")]
public bool CanSeek { get; set; }
diff --git a/MediaBrowser.Api/UserService.cs b/MediaBrowser.Api/UserService.cs
index ac140150b..401514349 100644
--- a/MediaBrowser.Api/UserService.cs
+++ b/MediaBrowser.Api/UserService.cs
@@ -240,7 +240,7 @@ namespace MediaBrowser.Api
public class UserService : BaseApiService
{
/// <summary>
- /// The _user manager
+ /// The user manager.
/// </summary>
private readonly IUserManager _userManager;
private readonly ISessionManager _sessionMananger;
diff --git a/MediaBrowser.Controller/Session/SessionInfo.cs b/MediaBrowser.Controller/Session/SessionInfo.cs
index 6e8385cf8..f1f10a3a3 100644
--- a/MediaBrowser.Controller/Session/SessionInfo.cs
+++ b/MediaBrowser.Controller/Session/SessionInfo.cs
@@ -107,6 +107,8 @@ namespace MediaBrowser.Controller.Session
public BaseItem FullNowPlayingItem { get; set; }
+ public BaseItemDto NowViewingItem { get; set; }
+
/// <summary>
/// Gets or sets the device id.
/// </summary>
@@ -239,11 +241,6 @@ namespace MediaBrowser.Controller.Session
SessionControllers = controllers.ToArray();
}
- public bool ContainsUser(string userId)
- {
- return ContainsUser(new Guid(userId));
- }
-
public bool ContainsUser(Guid userId)
{
if (UserId.Equals(userId))