Explorar el Código

added model classes for remote control

Luke Pulverenti hace 12 años
padre
commit
35a7986b3f

+ 4 - 3
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
     /// </summary>
     [Route("/Sessions", "GET")]
     [Api(("Gets a list of sessions"))]
-    public class GetSessions : IReturn<List<SessionInfo>>
+    public class GetSessions : IReturn<List<SessionInfoDto>>
     {
         /// <summary>
         /// 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());
         }
     }
 }

+ 1 - 1
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

+ 1 - 1
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");
         }
 
         /// <summary>

+ 45 - 0
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
+{
+    /// <summary>
+    /// Class SessionInfoDtoBuilder
+    /// </summary>
+    public static class SessionInfoDtoBuilder
+    {
+        /// <summary>
+        /// Gets the session info dto.
+        /// </summary>
+        /// <param name="session">The session.</param>
+        /// <returns>SessionInfoDto.</returns>
+        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;
+        }
+    }
+}

+ 1 - 1
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,

+ 2 - 0
MediaBrowser.Controller/MediaBrowser.Controller.csproj

@@ -70,6 +70,7 @@
       <Link>Properties\SharedVersion.cs</Link>
     </Compile>
     <Compile Include="Configuration\IServerConfigurationManager.cs" />
+    <Compile Include="Dto\SessionInfoDtoBuilder.cs" />
     <Compile Include="Session\ISessionManager.cs" />
     <Compile Include="Drawing\ImageExtensions.cs" />
     <Compile Include="Drawing\ImageHeader.cs" />
@@ -191,6 +192,7 @@
     <Compile Include="Providers\FolderProviderFromXml.cs" />
     <Compile Include="Providers\ImageFromMediaLocationProvider.cs" />
     <Compile Include="Providers\MediaInfo\FFProbeVideoInfoProvider.cs" />
+    <Compile Include="Session\SessionInfo.cs" />
     <Compile Include="Sorting\IBaseItemComparer.cs" />
     <Compile Include="Sorting\IUserBaseItemComparer.cs" />
     <Compile Include="Updates\IInstallationManager.cs" />

+ 11 - 4
MediaBrowser.Model/Session/SessionInfo.cs → 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
 {
     /// <summary>
     /// Class SessionInfo
@@ -18,7 +19,7 @@ namespace MediaBrowser.Model.Session
         /// Gets or sets the user id.
         /// </summary>
         /// <value>The user id.</value>
-        public string UserId { get; set; }
+        public Guid? UserId { get; set; }
 
         /// <summary>
         /// Gets or sets the type of the client.
@@ -42,7 +43,7 @@ namespace MediaBrowser.Model.Session
         /// Gets or sets the now playing item.
         /// </summary>
         /// <value>The now playing item.</value>
-        public BaseItemInfo NowPlayingItem { get; set; }
+        public BaseItem NowPlayingItem { get; set; }
 
         /// <summary>
         /// Gets or sets the now playing position ticks.
@@ -55,5 +56,11 @@ namespace MediaBrowser.Model.Session
         /// </summary>
         /// <value>The device id.</value>
         public string DeviceId { get; set; }
+
+        /// <summary>
+        /// Gets or sets the web socket.
+        /// </summary>
+        /// <value>The web socket.</value>
+        public IWebSocketConnection WebSocket { get; set; }
     }
 }

+ 4 - 1
MediaBrowser.Model/MediaBrowser.Model.csproj

@@ -56,7 +56,9 @@
     <Compile Include="Querying\ArtistsQuery.cs" />
     <Compile Include="Querying\ItemsByNameQuery.cs" />
     <Compile Include="Entities\BaseItemInfo.cs" />
-    <Compile Include="Session\SessionInfo.cs" />
+    <Compile Include="Session\BrowseRequest.cs" />
+    <Compile Include="Session\PlayRequest.cs" />
+    <Compile Include="Session\PlaystateRequest.cs" />
     <Compile Include="Entities\ImageDownloadOptions.cs" />
     <Compile Include="Logging\ILogManager.cs" />
     <Compile Include="MediaInfo\BlurayDiscInfo.cs" />
@@ -92,6 +94,7 @@
     <Compile Include="Search\SearchHintResult.cs" />
     <Compile Include="Serialization\IJsonSerializer.cs" />
     <Compile Include="Serialization\IXmlSerializer.cs" />
+    <Compile Include="Session\SessionInfoDto.cs" />
     <Compile Include="Updates\CheckForUpdateResult.cs" />
     <Compile Include="Updates\PackageTargetSystem.cs" />
     <Compile Include="Updates\InstallationInfo.cs" />

+ 37 - 0
MediaBrowser.Model/Session/BrowseRequest.cs

@@ -0,0 +1,37 @@
+
+namespace MediaBrowser.Model.Session
+{
+    /// <summary>
+    /// Class BrowseRequest
+    /// </summary>
+    public class BrowseRequest
+    {
+        /// <summary>
+        /// Artist, Genre, Studio, Person, or any kind of BaseItem
+        /// </summary>
+        /// <value>The type of the item.</value>
+        public string ItemType { get; set; }
+
+        /// <summary>
+        /// Artist name, genre name, item Id, etc
+        /// </summary>
+        /// <value>The item identifier.</value>
+        public string ItemIdentifier { get; set; }
+
+        /// <summary>
+        /// 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.
+        /// </summary>
+        /// <value>The context.</value>
+        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";
+    }
+}

+ 46 - 0
MediaBrowser.Model/Session/PlayRequest.cs

@@ -0,0 +1,46 @@
+
+namespace MediaBrowser.Model.Session
+{
+    /// <summary>
+    /// Class PlayRequest
+    /// </summary>
+    public class PlayRequest
+    {
+        /// <summary>
+        /// Gets or sets the item ids.
+        /// </summary>
+        /// <value>The item ids.</value>
+        public string[] ItemIds { get; set; }
+
+        /// <summary>
+        /// Gets or sets the start position ticks that the first item should be played at
+        /// </summary>
+        /// <value>The start position ticks.</value>
+        public long? StartPositionTicks { get; set; }
+
+        /// <summary>
+        /// Gets or sets the play command.
+        /// </summary>
+        /// <value>The play command.</value>
+        public PlayCommand PlayCommand { get; set; }
+    }
+
+    /// <summary>
+    /// Enum PlayCommand
+    /// </summary>
+    public enum PlayCommand
+    {
+        /// <summary>
+        /// The play now
+        /// </summary>
+        PlayNow,
+        /// <summary>
+        /// The play next
+        /// </summary>
+        PlayNext,
+        /// <summary>
+        /// The play last
+        /// </summary>
+        PlayLast
+    }
+}

+ 53 - 0
MediaBrowser.Model/Session/PlaystateRequest.cs

@@ -0,0 +1,53 @@
+
+namespace MediaBrowser.Model.Session
+{
+    /// <summary>
+    /// Class PlaystateRequest
+    /// </summary>
+    public class PlaystateRequest
+    {
+        /// <summary>
+        /// Gets or sets the command.
+        /// </summary>
+        /// <value>The command.</value>
+        public PlaystateCommand Command { get; set; }
+
+        /// <summary>
+        /// Gets or sets the seek position.
+        /// Only applicable to seek commands.
+        /// </summary>
+        /// <value>The seek position.</value>
+        public long SeekPosition { get; set; }
+    }
+
+    /// <summary>
+    /// Enum PlaystateCommand
+    /// </summary>
+    public enum PlaystateCommand
+    {
+        /// <summary>
+        /// The stop
+        /// </summary>
+        Stop,
+        /// <summary>
+        /// The pause
+        /// </summary>
+        Pause,
+        /// <summary>
+        /// The unpause
+        /// </summary>
+        Unpause,
+        /// <summary>
+        /// The next track
+        /// </summary>
+        NextTrack,
+        /// <summary>
+        /// The previous track
+        /// </summary>
+        PreviousTrack,
+        /// <summary>
+        /// The seek
+        /// </summary>
+        Seek
+    }
+}

+ 62 - 0
MediaBrowser.Model/Session/SessionInfoDto.cs

@@ -0,0 +1,62 @@
+using MediaBrowser.Model.Entities;
+using System;
+
+namespace MediaBrowser.Model.Session
+{
+    public class SessionInfoDto
+    {
+        /// <summary>
+        /// Gets or sets the id.
+        /// </summary>
+        /// <value>The id.</value>
+        public Guid Id { get; set; }
+
+        /// <summary>
+        /// Gets or sets the user id.
+        /// </summary>
+        /// <value>The user id.</value>
+        public string UserId { get; set; }
+
+        /// <summary>
+        /// Gets or sets the type of the client.
+        /// </summary>
+        /// <value>The type of the client.</value>
+        public string Client { get; set; }
+
+        /// <summary>
+        /// Gets or sets the last activity date.
+        /// </summary>
+        /// <value>The last activity date.</value>
+        public DateTime LastActivityDate { get; set; }
+
+        /// <summary>
+        /// Gets or sets the name of the device.
+        /// </summary>
+        /// <value>The name of the device.</value>
+        public string DeviceName { get; set; }
+
+        /// <summary>
+        /// Gets or sets the now playing item.
+        /// </summary>
+        /// <value>The now playing item.</value>
+        public BaseItemInfo NowPlayingItem { get; set; }
+
+        /// <summary>
+        /// Gets or sets the now playing position ticks.
+        /// </summary>
+        /// <value>The now playing position ticks.</value>
+        public long? NowPlayingPositionTicks { get; set; }
+
+        /// <summary>
+        /// Gets or sets the device id.
+        /// </summary>
+        /// <value>The device id.</value>
+        public string DeviceId { get; set; }
+
+        /// <summary>
+        /// Gets or sets a value indicating whether [supports remote control].
+        /// </summary>
+        /// <value><c>true</c> if [supports remote control]; otherwise, <c>false</c>.</value>
+        public bool SupportsRemoteControl { get; set; }
+    }
+}

+ 1 - 0
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;

+ 1 - 1
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");
 

+ 9 - 7
MediaBrowser.Server.Implementations/Session/SessionManager.cs

@@ -41,9 +41,6 @@ namespace MediaBrowser.Server.Implementations.Session
         private readonly ConcurrentDictionary<string, SessionInfo> _activeConnections =
             new ConcurrentDictionary<string, SessionInfo>(StringComparer.OrdinalIgnoreCase);
 
-        private readonly ConcurrentDictionary<Guid, IWebSocketConnection> _websocketConnections =
-         new ConcurrentDictionary<Guid, IWebSocketConnection>();
-        
         /// <summary>
         /// Occurs when [playback start].
         /// </summary>
@@ -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
         /// <param name="webSocket">The web socket.</param>
         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;
+            }
         }
     }
 }

+ 1 - 1
MediaBrowser.ServerApplication/EntryPoints/WebSocketEvents.cs

@@ -326,7 +326,7 @@ namespace MediaBrowser.ServerApplication.EntryPoints
         /// <param name="e">The e.</param>
         void userManager_UserDeleted(object sender, GenericEventArgs<User> e)
         {
-            _serverManager.SendWebSocketMessage("UserDeleted", e.Argument.Id.ToString());
+            _serverManager.SendWebSocketMessage("UserDeleted", e.Argument.Id.ToString("N"));
         }
 
         /// <summary>

+ 1 - 1
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");
         }
     }
 }

+ 1 - 1
MediaBrowser.WebDashboard/Api/DashboardInfo.cs

@@ -33,7 +33,7 @@ namespace MediaBrowser.WebDashboard.Api
         /// Gets or sets the active connections.
         /// </summary>
         /// <value>The active connections.</value>
-        public SessionInfo[] ActiveConnections { get; set; }
+        public SessionInfoDto[] ActiveConnections { get; set; }
 
         /// <summary>
         /// Gets or sets the users.

+ 2 - 2
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()
             };

+ 3 - 3
Nuget/MediaBrowser.Common.Internal.nuspec

@@ -2,7 +2,7 @@
 <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
     <metadata>
         <id>MediaBrowser.Common.Internal</id>
-        <version>3.0.94</version>
+        <version>3.0.97</version>
         <title>MediaBrowser.Common.Internal</title>
         <authors>Luke</authors>
         <owners>ebr,Luke,scottisafool</owners>
@@ -12,9 +12,9 @@
         <description>Contains common components shared by Media Browser Theatre and Media Browser Server. Not intended for plugin developer consumption.</description>
         <copyright>Copyright © Media Browser 2013</copyright>
         <dependencies>
-            <dependency id="MediaBrowser.Common" version="3.0.94" />
+            <dependency id="MediaBrowser.Common" version="3.0.97" />
             <dependency id="NLog" version="2.0.1.2" />
-            <dependency id="ServiceStack.Text" version="3.9.94" />
+            <dependency id="ServiceStack.Text" version="3.9.97" />
             <dependency id="SimpleInjector" version="2.2.1" />
         </dependencies>
     </metadata>

+ 1 - 1
Nuget/MediaBrowser.Common.nuspec

@@ -2,7 +2,7 @@
 <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
     <metadata>
         <id>MediaBrowser.Common</id>
-        <version>3.0.94</version>
+        <version>3.0.97</version>
         <title>MediaBrowser.Common</title>
         <authors>Media Browser Team</authors>
         <owners>ebr,Luke,scottisafool</owners>

+ 2 - 2
Nuget/MediaBrowser.Server.Core.nuspec

@@ -2,7 +2,7 @@
 <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
     <metadata>
         <id>MediaBrowser.Server.Core</id>
-        <version>3.0.94</version>
+        <version>3.0.97</version>
         <title>Media Browser.Server.Core</title>
         <authors>Media Browser Team</authors>
         <owners>ebr,Luke,scottisafool</owners>
@@ -12,7 +12,7 @@
         <description>Contains core components required to build plugins for Media Browser Server.</description>
         <copyright>Copyright © Media Browser 2013</copyright>
         <dependencies>
-            <dependency id="MediaBrowser.Common" version="3.0.94" />
+            <dependency id="MediaBrowser.Common" version="3.0.97" />
         </dependencies>
     </metadata>
     <files>