diff --git a/MediaBrowser.Api/SessionsService.cs b/MediaBrowser.Api/SessionsService.cs index 03a352307..590fd6f06 100644 --- a/MediaBrowser.Api/SessionsService.cs +++ b/MediaBrowser.Api/SessionsService.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Session; +using MediaBrowser.Controller.Dto; +using MediaBrowser.Controller.Session; using MediaBrowser.Model.Session; using ServiceStack.ServiceHost; using System.Collections.Generic; @@ -11,7 +12,7 @@ namespace MediaBrowser.Api /// [Route("/Sessions", "GET")] [Api(("Gets a list of sessions"))] - public class GetSessions : IReturn> + public class GetSessions : IReturn> { /// /// Gets or sets a value indicating whether this instance is recent. @@ -48,7 +49,7 @@ namespace MediaBrowser.Api { var result = request.IsRecent ? _sessionManager.RecentConnections : _sessionManager.AllConnections; - return ToOptimizedResult(result.ToList()); + return ToOptimizedResult(result.Select(SessionInfoDtoBuilder.GetSessionInfoDto).ToList()); } } } diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs index 3a7a57455..71168c219 100644 --- a/MediaBrowser.Common/Plugins/BasePlugin.cs +++ b/MediaBrowser.Common/Plugins/BasePlugin.cs @@ -304,7 +304,7 @@ namespace MediaBrowser.Common.Plugins AssemblyFileName = AssemblyFileName, ConfigurationDateLastModified = ConfigurationDateLastModified, Description = Description, - Id = Id.ToString(), + Id = Id.ToString("N"), EnableAutoUpdate = Configuration.EnableAutoUpdate, UpdateClass = Configuration.UpdateClass, ConfigurationFileName = ConfigurationFileName diff --git a/MediaBrowser.Controller/Dto/DtoBuilder.cs b/MediaBrowser.Controller/Dto/DtoBuilder.cs index 167ff2f78..ca08a3290 100644 --- a/MediaBrowser.Controller/Dto/DtoBuilder.cs +++ b/MediaBrowser.Controller/Dto/DtoBuilder.cs @@ -868,7 +868,7 @@ namespace MediaBrowser.Controller.Dto return GetClientItemId(indexFolder.Parent) + IndexFolderDelimeter + (indexFolder.IndexName ?? string.Empty) + IndexFolderDelimeter + indexFolder.Id; } - return item.Id.ToString(); + return item.Id.ToString("N"); } /// diff --git a/MediaBrowser.Controller/Dto/SessionInfoDtoBuilder.cs b/MediaBrowser.Controller/Dto/SessionInfoDtoBuilder.cs new file mode 100644 index 000000000..850af573f --- /dev/null +++ b/MediaBrowser.Controller/Dto/SessionInfoDtoBuilder.cs @@ -0,0 +1,45 @@ +using MediaBrowser.Controller.Session; +using MediaBrowser.Model.Net; +using MediaBrowser.Model.Session; + +namespace MediaBrowser.Controller.Dto +{ + /// + /// Class SessionInfoDtoBuilder + /// + public static class SessionInfoDtoBuilder + { + /// + /// Gets the session info dto. + /// + /// The session. + /// SessionInfoDto. + public static SessionInfoDto GetSessionInfoDto(SessionInfo session) + { + var dto = new SessionInfoDto + { + Client = session.Client, + DeviceId = session.DeviceId, + DeviceName = session.DeviceName, + Id = session.Id, + LastActivityDate = session.LastActivityDate, + NowPlayingPositionTicks = session.NowPlayingPositionTicks + }; + + if (session.NowPlayingItem != null) + { + dto.NowPlayingItem = DtoBuilder.GetBaseItemInfo(session.NowPlayingItem); + } + + if (session.UserId.HasValue) + { + dto.UserId = session.UserId.Value.ToString("N"); + } + + dto.SupportsRemoteControl = session.WebSocket != null && + session.WebSocket.State == WebSocketState.Open; + + return dto; + } + } +} diff --git a/MediaBrowser.Controller/Dto/UserDtoBuilder.cs b/MediaBrowser.Controller/Dto/UserDtoBuilder.cs index ad90a392c..892bd5dd0 100644 --- a/MediaBrowser.Controller/Dto/UserDtoBuilder.cs +++ b/MediaBrowser.Controller/Dto/UserDtoBuilder.cs @@ -41,7 +41,7 @@ namespace MediaBrowser.Controller.Dto var dto = new UserDto { - Id = user.Id.ToString(), + Id = user.Id.ToString("N"), Name = user.Name, HasPassword = !String.IsNullOrEmpty(user.Password), LastActivityDate = user.LastActivityDate, diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index c54a446fb..378011e34 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -70,6 +70,7 @@ Properties\SharedVersion.cs + @@ -191,6 +192,7 @@ + diff --git a/MediaBrowser.Model/Session/SessionInfo.cs b/MediaBrowser.Controller/Session/SessionInfo.cs similarity index 79% rename from MediaBrowser.Model/Session/SessionInfo.cs rename to MediaBrowser.Controller/Session/SessionInfo.cs index f74db9058..21c65df97 100644 --- a/MediaBrowser.Model/Session/SessionInfo.cs +++ b/MediaBrowser.Controller/Session/SessionInfo.cs @@ -1,7 +1,8 @@ -using MediaBrowser.Model.Entities; +using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Entities; using System; -namespace MediaBrowser.Model.Session +namespace MediaBrowser.Controller.Session { /// /// Class SessionInfo @@ -18,7 +19,7 @@ namespace MediaBrowser.Model.Session /// Gets or sets the user id. /// /// The user id. - public string UserId { get; set; } + public Guid? UserId { get; set; } /// /// Gets or sets the type of the client. @@ -42,7 +43,7 @@ namespace MediaBrowser.Model.Session /// Gets or sets the now playing item. /// /// The now playing item. - public BaseItemInfo NowPlayingItem { get; set; } + public BaseItem NowPlayingItem { get; set; } /// /// Gets or sets the now playing position ticks. @@ -55,5 +56,11 @@ namespace MediaBrowser.Model.Session /// /// The device id. public string DeviceId { get; set; } + + /// + /// Gets or sets the web socket. + /// + /// The web socket. + public IWebSocketConnection WebSocket { get; set; } } } diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index dbfe38698..979e0d55e 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -56,7 +56,9 @@ - + + + @@ -92,6 +94,7 @@ + diff --git a/MediaBrowser.Model/Session/BrowseRequest.cs b/MediaBrowser.Model/Session/BrowseRequest.cs new file mode 100644 index 000000000..3d10b3bfd --- /dev/null +++ b/MediaBrowser.Model/Session/BrowseRequest.cs @@ -0,0 +1,37 @@ + +namespace MediaBrowser.Model.Session +{ + /// + /// Class BrowseRequest + /// + public class BrowseRequest + { + /// + /// Artist, Genre, Studio, Person, or any kind of BaseItem + /// + /// The type of the item. + public string ItemType { get; set; } + + /// + /// Artist name, genre name, item Id, etc + /// + /// The item identifier. + public string ItemIdentifier { get; set; } + + /// + /// Gets or sets the context (Movies, Music, Tv, 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. + /// + /// The context. + public string Context { get; set; } + } + + public class ItemContext + { + public const string Music = "Music"; + public const string Movies = "Movies"; + public const string TvShows = "TvShows"; + public const string Games = "Games"; + } +} diff --git a/MediaBrowser.Model/Session/PlayRequest.cs b/MediaBrowser.Model/Session/PlayRequest.cs new file mode 100644 index 000000000..c9bb58693 --- /dev/null +++ b/MediaBrowser.Model/Session/PlayRequest.cs @@ -0,0 +1,46 @@ + +namespace MediaBrowser.Model.Session +{ + /// + /// Class PlayRequest + /// + public class PlayRequest + { + /// + /// Gets or sets the item ids. + /// + /// The item ids. + public string[] ItemIds { get; set; } + + /// + /// Gets or sets the start position ticks that the first item should be played at + /// + /// The start position ticks. + public long? StartPositionTicks { get; set; } + + /// + /// Gets or sets the play command. + /// + /// The play command. + public PlayCommand PlayCommand { get; set; } + } + + /// + /// Enum PlayCommand + /// + public enum PlayCommand + { + /// + /// The play now + /// + PlayNow, + /// + /// The play next + /// + PlayNext, + /// + /// The play last + /// + PlayLast + } +} diff --git a/MediaBrowser.Model/Session/PlaystateRequest.cs b/MediaBrowser.Model/Session/PlaystateRequest.cs new file mode 100644 index 000000000..4db06c3d6 --- /dev/null +++ b/MediaBrowser.Model/Session/PlaystateRequest.cs @@ -0,0 +1,53 @@ + +namespace MediaBrowser.Model.Session +{ + /// + /// Class PlaystateRequest + /// + public class PlaystateRequest + { + /// + /// Gets or sets the command. + /// + /// The command. + public PlaystateCommand Command { get; set; } + + /// + /// Gets or sets the seek position. + /// Only applicable to seek commands. + /// + /// The seek position. + public long SeekPosition { get; set; } + } + + /// + /// Enum PlaystateCommand + /// + public enum PlaystateCommand + { + /// + /// The stop + /// + Stop, + /// + /// The pause + /// + Pause, + /// + /// The unpause + /// + Unpause, + /// + /// The next track + /// + NextTrack, + /// + /// The previous track + /// + PreviousTrack, + /// + /// The seek + /// + Seek + } +} diff --git a/MediaBrowser.Model/Session/SessionInfoDto.cs b/MediaBrowser.Model/Session/SessionInfoDto.cs new file mode 100644 index 000000000..0548876a1 --- /dev/null +++ b/MediaBrowser.Model/Session/SessionInfoDto.cs @@ -0,0 +1,62 @@ +using MediaBrowser.Model.Entities; +using System; + +namespace MediaBrowser.Model.Session +{ + public class SessionInfoDto + { + /// + /// Gets or sets the id. + /// + /// The id. + public Guid Id { get; set; } + + /// + /// Gets or sets the user id. + /// + /// The user id. + public string UserId { get; set; } + + /// + /// Gets or sets the type of the client. + /// + /// The type of the client. + public string Client { get; set; } + + /// + /// Gets or sets the last activity date. + /// + /// The last activity date. + public DateTime LastActivityDate { get; set; } + + /// + /// Gets or sets the name of the device. + /// + /// The name of the device. + public string DeviceName { get; set; } + + /// + /// Gets or sets the now playing item. + /// + /// The now playing item. + public BaseItemInfo NowPlayingItem { get; set; } + + /// + /// Gets or sets the now playing position ticks. + /// + /// The now playing position ticks. + public long? NowPlayingPositionTicks { get; set; } + + /// + /// Gets or sets the device id. + /// + /// The device id. + public string DeviceId { get; set; } + + /// + /// Gets or sets a value indicating whether [supports remote control]. + /// + /// true if [supports remote control]; otherwise, false. + public bool SupportsRemoteControl { get; set; } + } +} diff --git a/MediaBrowser.Server.Implementations/Library/UserManager.cs b/MediaBrowser.Server.Implementations/Library/UserManager.cs index dc863ca4d..6f5725e1b 100644 --- a/MediaBrowser.Server.Implementations/Library/UserManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserManager.cs @@ -7,6 +7,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Persistence; +using MediaBrowser.Controller.Session; using MediaBrowser.Model.Logging; using System; using System.Collections.Concurrent; diff --git a/MediaBrowser.Server.Implementations/ScheduledTasks/AudioImagesTask.cs b/MediaBrowser.Server.Implementations/ScheduledTasks/AudioImagesTask.cs index b9a51ab78..d3ed270b8 100644 --- a/MediaBrowser.Server.Implementations/ScheduledTasks/AudioImagesTask.cs +++ b/MediaBrowser.Server.Implementations/ScheduledTasks/AudioImagesTask.cs @@ -216,7 +216,7 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks var filename = item.Album ?? string.Empty; - filename += album == null ? item.Id.ToString() + item.DateModified.Ticks : album.Id.ToString() + album.DateModified.Ticks; + filename += album == null ? item.Id.ToString("N") + item.DateModified.Ticks : album.Id.ToString() + album.DateModified.Ticks; var path = ImageCache.GetResourcePath(filename + "_primary", ".jpg"); diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs index 051c8fb68..99407e349 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs @@ -41,9 +41,6 @@ namespace MediaBrowser.Server.Implementations.Session private readonly ConcurrentDictionary _activeConnections = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); - private readonly ConcurrentDictionary _websocketConnections = - new ConcurrentDictionary(); - /// /// Occurs when [playback start]. /// @@ -133,7 +130,7 @@ namespace MediaBrowser.Server.Implementations.Session var conn = GetConnection(clientType, deviceId, deviceName, user); conn.NowPlayingPositionTicks = currentPositionTicks; - conn.NowPlayingItem = DtoBuilder.GetBaseItemInfo(item); + conn.NowPlayingItem = item; conn.LastActivityDate = DateTime.UtcNow; } @@ -149,7 +146,7 @@ namespace MediaBrowser.Server.Implementations.Session { var conn = GetConnection(clientType, deviceId, deviceName, user); - if (conn.NowPlayingItem != null && conn.NowPlayingItem.Id.Equals(item.Id.ToString())) + if (conn.NowPlayingItem != null && conn.NowPlayingItem.Id == item.Id) { conn.NowPlayingItem = null; conn.NowPlayingPositionTicks = null; @@ -177,7 +174,7 @@ namespace MediaBrowser.Server.Implementations.Session connection.DeviceName = deviceName; - connection.UserId = user == null ? null : user.Id.ToString(); + connection.UserId = user == null ? (Guid?)null : user.Id; return connection; } @@ -366,7 +363,12 @@ namespace MediaBrowser.Server.Implementations.Session /// The web socket. public void IdentifyWebSocket(Guid sessionId, IWebSocketConnection webSocket) { - _websocketConnections.AddOrUpdate(sessionId, webSocket, (key, existing) => webSocket); + var session = AllConnections.FirstOrDefault(i => i.Id == sessionId); + + if (session != null) + { + session.WebSocket = webSocket; + } } } } diff --git a/MediaBrowser.ServerApplication/EntryPoints/WebSocketEvents.cs b/MediaBrowser.ServerApplication/EntryPoints/WebSocketEvents.cs index 1ba4232d3..a4a43509d 100644 --- a/MediaBrowser.ServerApplication/EntryPoints/WebSocketEvents.cs +++ b/MediaBrowser.ServerApplication/EntryPoints/WebSocketEvents.cs @@ -326,7 +326,7 @@ namespace MediaBrowser.ServerApplication.EntryPoints /// The e. void userManager_UserDeleted(object sender, GenericEventArgs e) { - _serverManager.SendWebSocketMessage("UserDeleted", e.Argument.Id.ToString()); + _serverManager.SendWebSocketMessage("UserDeleted", e.Argument.Id.ToString("N")); } /// diff --git a/MediaBrowser.WebDashboard/Api/ConfigurationPageInfo.cs b/MediaBrowser.WebDashboard/Api/ConfigurationPageInfo.cs index 5cba80850..97bba0970 100644 --- a/MediaBrowser.WebDashboard/Api/ConfigurationPageInfo.cs +++ b/MediaBrowser.WebDashboard/Api/ConfigurationPageInfo.cs @@ -27,7 +27,7 @@ namespace MediaBrowser.WebDashboard.Api { Name = page.Name; ConfigurationPageType = page.ConfigurationPageType; - PluginId = page.Plugin.Id.ToString(); + PluginId = page.Plugin.Id.ToString("N"); } } } diff --git a/MediaBrowser.WebDashboard/Api/DashboardInfo.cs b/MediaBrowser.WebDashboard/Api/DashboardInfo.cs index 500464ed8..48670eb83 100644 --- a/MediaBrowser.WebDashboard/Api/DashboardInfo.cs +++ b/MediaBrowser.WebDashboard/Api/DashboardInfo.cs @@ -33,7 +33,7 @@ namespace MediaBrowser.WebDashboard.Api /// Gets or sets the active connections. /// /// The active connections. - public SessionInfo[] ActiveConnections { get; set; } + public SessionInfoDto[] ActiveConnections { get; set; } /// /// Gets or sets the users. diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs index b33c152f1..a0892060f 100644 --- a/MediaBrowser.WebDashboard/Api/DashboardService.cs +++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs @@ -210,7 +210,7 @@ namespace MediaBrowser.WebDashboard.Api var dtoBuilder = new UserDtoBuilder(logger); - var tasks = userManager.Users.Where(u => connections.Any(c => new Guid(c.UserId) == u.Id)).Select(dtoBuilder.GetUserDto); + var tasks = userManager.Users.Where(u => connections.Any(c => c.UserId.HasValue && c.UserId.Value == u.Id)).Select(dtoBuilder.GetUserDto); var users = await Task.WhenAll(tasks).ConfigureAwait(false); @@ -224,7 +224,7 @@ namespace MediaBrowser.WebDashboard.Api ApplicationUpdateTaskId = taskManager.ScheduledTasks.First(t => t.ScheduledTask.GetType().Name.Equals("SystemUpdateTask", StringComparison.OrdinalIgnoreCase)).Id, - ActiveConnections = connections, + ActiveConnections = connections.Select(SessionInfoDtoBuilder.GetSessionInfoDto).ToArray(), Users = users.ToArray() }; diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index 188a44335..56feae805 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.94 + 3.0.97 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,9 +12,9 @@ Contains common components shared by Media Browser Theatre and Media Browser Server. Not intended for plugin developer consumption. Copyright © Media Browser 2013 - + - + diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index 4c972ea13..0860c7c9c 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.94 + 3.0.97 MediaBrowser.Common Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index 503b7c0f6..ed83cc8d8 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.94 + 3.0.97 Media Browser.Server.Core Media Browser Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Media Browser Server. Copyright © Media Browser 2013 - +