The Free Software Media System - Server Backend & API
Display client version in the dashboard
Luke Pulverenti66624293ac22
diff --git a/MediaBrowser.Api/BaseApiService.cs b/MediaBrowser.Api/BaseApiService.csindex 193a23b3e5..06e9c80e80 100644--- a/MediaBrowser.Api/BaseApiService.cs+++ b/MediaBrowser.Api/BaseApiService.cs@@ -286,13 +286,21 @@ namespace MediaBrowser.Api}}- var deviceId = auth["DeviceId"];- var device = auth["Device"];- var client = auth["Client"];+ string deviceId;+ string device;+ string client;+ string version;- if (!string.IsNullOrEmpty(client) && !string.IsNullOrEmpty(deviceId) && !string.IsNullOrEmpty(device))+ auth.TryGetValue("DeviceId", out deviceId);+ auth.TryGetValue("Device", out device);+ auth.TryGetValue("Client", out client);+ auth.TryGetValue("Version", out version);++ version = version ?? "0.0.0.0";++ if (!string.IsNullOrEmpty(client) && !string.IsNullOrEmpty(deviceId) && !string.IsNullOrEmpty(device) && !string.IsNullOrEmpty(version)){- SessionManager.LogConnectionActivity(client, deviceId, device, user);+ SessionManager.LogConnectionActivity(client, version, deviceId, device, user);}}}diff --git a/MediaBrowser.Api/SessionsService.cs b/MediaBrowser.Api/SessionsService.csindex a682d670d4..bbd1fd9857 100644--- a/MediaBrowser.Api/SessionsService.cs+++ b/MediaBrowser.Api/SessionsService.cs@@ -1,6 +1,5 @@using MediaBrowser.Common.Extensions;using MediaBrowser.Controller.Dto;-using MediaBrowser.Controller.Library;using MediaBrowser.Controller.Session;using MediaBrowser.Model.Net;using MediaBrowser.Model.Session;@@ -106,6 +105,31 @@ namespace MediaBrowser.Apipublic PlayCommand PlayCommand { get; set; }}+ [Route("/Sessions/{Id}/Playing/{Command}", "POST")]+ [Api(("Issues a playstate command to a client"))]+ public class SendPlaystateCommand : IReturnVoid+ {+ /// <summary>+ /// Gets or sets the id.+ /// </summary>+ /// <value>The id.</value>+ [ApiMember(Name = "Id", Description = "Session Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]+ public Guid Id { get; set; }++ /// <summary>+ /// Gets or sets the position to seek to+ /// </summary>+ [ApiMember(Name = "SeekPosition", Description = "The position to seek to.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]+ public long? SeekPosition { get; set; }++ /// <summary>+ /// Gets or sets the play command.+ /// </summary>+ /// <value>The play command.</value>+ [ApiMember(Name = "Command", Description = "The command to send - stop, pause, unpause, nexttrack, previoustrack, seek.", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]+ public PlaystateCommand Command { get; set; }+ }+/// <summary>/// Class SessionsService/// </summary>@@ -142,6 +166,56 @@ namespace MediaBrowser.Apireturn ToOptimizedResult(result.Select(SessionInfoDtoBuilder.GetSessionInfoDto).ToList());}+ public void Post(SendPlaystateCommand request)+ {+ var task = SendPlaystateCommand(request);++ Task.WaitAll(task);+ }++ private async Task SendPlaystateCommand(SendPlaystateCommand request)+ {+ var session = _sessionManager.Sessions.FirstOrDefault(i => i.Id == request.Id);++ if (session == null)+ {+ throw new ResourceNotFoundException(string.Format("Session {0} not found.", request.Id));+ }++ if (!session.SupportsRemoteControl)+ {+ throw new ArgumentException(string.Format("Session {0} does not support remote control.", session.Id));+ }++ var socket = session.WebSockets.OrderByDescending(i => i.LastActivityDate).FirstOrDefault(i => i.State == WebSocketState.Open);++ if (socket != null)+ {+ try+ {+ await socket.SendAsync(new WebSocketMessage<PlayStateRequest>+ {+ MessageType = "Playstate",++ Data = new PlayStateRequest+ {+ Command = request.Command,+ SeekPosition = request.SeekPosition+ }++ }, CancellationToken.None).ConfigureAwait(false);+ }+ catch (Exception ex)+ {+ Logger.ErrorException("Error sending web socket message", ex);+ }+ }+ else+ {+ throw new InvalidOperationException("The requested session does not have an open web socket.");+ }+ }+/// <summary>/// Posts the specified request./// </summary>diff --git a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs b/MediaBrowser.Api/UserLibrary/UserLibraryService.csindex 6f5ed8cba4..951415694e 100644--- a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs+++ b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs@@ -586,6 +586,25 @@ namespace MediaBrowser.Api.UserLibraryTask.WaitAll(task);}+ private SessionInfo GetSession()+ {+ var auth = RequestFilterAttribute.GetAuthorization(RequestContext);++ string deviceId;+ string client;+ string version;++ auth.TryGetValue("DeviceId", out deviceId);+ auth.TryGetValue("Client", out client);+ auth.TryGetValue("Version", out version);++ version = version ?? "0.0.0.0";++ return _sessionManager.Sessions.First(i => string.Equals(i.DeviceId, deviceId) &&+ string.Equals(i.Client, client) &&+ string.Equals(i.ApplicationVersion, version));+ }+/// <summary>/// Posts the specified request./// </summary>@@ -596,12 +615,7 @@ namespace MediaBrowser.Api.UserLibraryvar item = DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, user.Id);- var auth = RequestFilterAttribute.GetAuthorization(RequestContext);-- if (auth != null)- {- _sessionManager.OnPlaybackStart(user, item, auth["Client"], auth["DeviceId"], auth["Device"] ?? string.Empty);- }+ _sessionManager.OnPlaybackStart(item, GetSession().Id);}/// <summary>@@ -614,14 +628,9 @@ namespace MediaBrowser.Api.UserLibraryvar item = DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, user.Id);- var auth = RequestFilterAttribute.GetAuthorization(RequestContext);-- if (auth != null)- {- var task = _sessionManager.OnPlaybackProgress(user, item, request.PositionTicks, request.IsPaused, auth["Client"], auth["DeviceId"], auth["Device"] ?? string.Empty);+ var task = _sessionManager.OnPlaybackProgress(item, request.PositionTicks, request.IsPaused, GetSession().Id);- Task.WaitAll(task);- }+ Task.WaitAll(task);}/// <summary>@@ -634,14 +643,9 @@ namespace MediaBrowser.Api.UserLibraryvar item = DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, user.Id);- var auth = RequestFilterAttribute.GetAuthorization(RequestContext);-- if (auth != null)- {- var task = _sessionManager.OnPlaybackStopped(user, item, request.PositionTicks, auth["Client"], auth["DeviceId"], auth["Device"] ?? string.Empty);+ var task = _sessionManager.OnPlaybackStopped(item, request.PositionTicks, GetSession().Id);- Task.WaitAll(task);- }+ Task.WaitAll(task);}/// <summary>diff --git a/MediaBrowser.Controller/Dto/DtoBuilder.cs b/MediaBrowser.Controller/Dto/DtoBuilder.csindex d1a0465cd3..7167447e40 100644--- a/MediaBrowser.Controller/Dto/DtoBuilder.cs+++ b/MediaBrowser.Controller/Dto/DtoBuilder.cs@@ -381,9 +381,9 @@ namespace MediaBrowser.Controller.Dtoif (parentWithImage != null){- dto.ParentLogoItemId = GetClientItemId(parentWithImage);+ dto.ParentArtItemId = GetClientItemId(parentWithImage);- dto.ParentLogoImageTag = GetImageCacheTag(parentWithImage, ImageType.Art, parentWithImage.GetImage(ImageType.Art));+ dto.ParentArtImageTag = GetImageCacheTag(parentWithImage, ImageType.Art, parentWithImage.GetImage(ImageType.Art));}}diff --git a/MediaBrowser.Controller/Dto/SessionInfoDtoBuilder.cs b/MediaBrowser.Controller/Dto/SessionInfoDtoBuilder.csindex 27e6a8d95d..b2ce4a6bad 100644--- a/MediaBrowser.Controller/Dto/SessionInfoDtoBuilder.cs+++ b/MediaBrowser.Controller/Dto/SessionInfoDtoBuilder.cs@@ -28,7 +28,8 @@ namespace MediaBrowser.Controller.DtoNowViewingContext = session.NowViewingContext,NowViewingItemId = session.NowViewingItemId,NowViewingItemName = session.NowViewingItemName,- NowViewingItemType = session.NowViewingItemType+ NowViewingItemType = session.NowViewingItemType,+ ApplicationVersion = session.ApplicationVersion};if (session.NowPlayingItem != null)diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csprojindex 3d2b46712f..814f6d5a11 100644--- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj+++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj@@ -70,7 +70,7 @@<Compile Include="..\SharedVersion.cs"><Link>Properties\SharedVersion.cs</Link></Compile>- <Compile Include="Configuration\IServerConfigurationManager.cs" />+ <Compile Include="Notifications\Configuration\IServerConfigurationManager.cs" /><Compile Include="Dto\SessionInfoDtoBuilder.cs" /><Compile Include="Entities\Audio\MusicAlbumDisc.cs" /><Compile Include="Entities\Audio\MusicGenre.cs" />diff --git a/MediaBrowser.Controller/Configuration/IServerConfigurationManager.cs b/MediaBrowser.Controller/Notifications/Configuration/IServerConfigurationManager.cssimilarity index 100%rename from MediaBrowser.Controller/Configuration/IServerConfigurationManager.csrename to MediaBrowser.Controller/Notifications/Configuration/IServerConfigurationManager.csdiff --git a/MediaBrowser.Controller/Session/ISessionManager.cs b/MediaBrowser.Controller/Session/ISessionManager.csindex f28721f5ff..2af2bbec90 100644--- a/MediaBrowser.Controller/Session/ISessionManager.cs+++ b/MediaBrowser.Controller/Session/ISessionManager.cs@@ -36,49 +36,42 @@ namespace MediaBrowser.Controller.Session/// Logs the user activity./// </summary>/// <param name="clientType">Type of the client.</param>+ /// <param name="appVersion">The app version.</param>/// <param name="deviceId">The device id.</param>/// <param name="deviceName">Name of the device.</param>/// <param name="user">The user.</param>/// <returns>Task.</returns>/// <exception cref="System.ArgumentNullException">user</exception>- Task LogConnectionActivity(string clientType, string deviceId, string deviceName, User user);+ Task<SessionInfo> LogConnectionActivity(string clientType, string appVersion, string deviceId, string deviceName, User user);/// <summary>/// Used to report that playback has started for an item/// </summary>- /// <param name="user">The user.</param>/// <param name="item">The item.</param>- /// <param name="clientType">Type of the client.</param>- /// <param name="deviceId">The device id.</param>- /// <param name="deviceName">Name of the device.</param>+ /// <param name="sessionId">The session id.</param>+ /// <returns>Task.</returns>/// <exception cref="System.ArgumentNullException"></exception>- Task OnPlaybackStart(User user, BaseItem item, string clientType, string deviceId, string deviceName);+ Task OnPlaybackStart(BaseItem item, Guid sessionId);/// <summary>/// Used to report playback progress for an item/// </summary>- /// <param name="user">The user.</param>/// <param name="item">The item.</param>/// <param name="positionTicks">The position ticks.</param>/// <param name="isPaused">if set to <c>true</c> [is paused].</param>- /// <param name="clientType">Type of the client.</param>- /// <param name="deviceId">The device id.</param>- /// <param name="deviceName">Name of the device.</param>+ /// <param name="sessionId">The session id.</param>/// <returns>Task.</returns>/// <exception cref="System.ArgumentNullException"></exception>- Task OnPlaybackProgress(User user, BaseItem item, long? positionTicks, bool isPaused, string clientType, string deviceId, string deviceName);+ Task OnPlaybackProgress(BaseItem item, long? positionTicks, bool isPaused, Guid sessionId);/// <summary>/// Used to report that playback has ended for an item/// </summary>- /// <param name="user">The user.</param>/// <param name="item">The item.</param>/// <param name="positionTicks">The position ticks.</param>- /// <param name="clientType">Type of the client.</param>- /// <param name="deviceId">The device id.</param>- /// <param name="deviceName">Name of the device.</param>+ /// <param name="sessionId">The session id.</param>/// <returns>Task.</returns>/// <exception cref="System.ArgumentNullException"></exception>- Task OnPlaybackStopped(User user, BaseItem item, long? positionTicks, string clientType, string deviceId, string deviceName);+ Task OnPlaybackStopped(BaseItem item, long? positionTicks, Guid sessionId);}}\ No newline at end of filediff --git a/MediaBrowser.Controller/Session/SessionInfo.cs b/MediaBrowser.Controller/Session/SessionInfo.csindex e49b526241..177573de6a 100644--- a/MediaBrowser.Controller/Session/SessionInfo.cs+++ b/MediaBrowser.Controller/Session/SessionInfo.cs@@ -101,6 +101,12 @@ namespace MediaBrowser.Controller.Session/// <value>The web socket.</value>public List<IWebSocketConnection> WebSockets { get; set; }+ /// <summary>+ /// Gets or sets the application version.+ /// </summary>+ /// <value>The application version.</value>+ public string ApplicationVersion { get; set; }+/// <summary>/// Gets a value indicating whether this instance is active./// </summary>diff --git a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csprojindex 9c534f9160..95fea4071d 100644--- a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj+++ b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj@@ -268,6 +268,9 @@<Compile Include="..\MediaBrowser.Model\Querying\ThemeSongsResult.cs"><Link>Querying\ThemeSongsResult.cs</Link></Compile>+ <Compile Include="..\MediaBrowser.Model\Querying\UserQuery.cs">+ <Link>Querying\UserQuery.cs</Link>+ </Compile><Compile Include="..\MediaBrowser.Model\Search\SearchHint.cs"><Link>Search\SearchHint.cs</Link></Compile>@@ -286,8 +289,8 @@<Compile Include="..\MediaBrowser.Model\Session\PlayRequest.cs"><Link>Session\PlayRequest.cs</Link></Compile>- <Compile Include="..\MediaBrowser.Model\Session\PlaystateRequest.cs">- <Link>Session\PlaystateRequest.cs</Link>+ <Compile Include="..\MediaBrowser.Model\Session\PlaystateCommand.cs">+ <Link>Session\PlaystateCommand.cs</Link></Compile><Compile Include="..\MediaBrowser.Model\Session\SessionInfoDto.cs"><Link>Session\SessionInfoDto.cs</Link>diff --git a/MediaBrowser.Model/ApiClient/IApiClient.cs b/MediaBrowser.Model/ApiClient/IApiClient.csindex 4ec7b14e1b..990f63f843 100644--- a/MediaBrowser.Model/ApiClient/IApiClient.cs+++ b/MediaBrowser.Model/ApiClient/IApiClient.cs@@ -100,6 +100,12 @@ namespace MediaBrowser.Model.ApiClient/// <returns>Task{UserDto[]}.</returns>Task<UserDto[]> GetUsersAsync();+ /// <summary>+ /// Gets the public users async.+ /// </summary>+ /// <returns>Task{UserDto[]}.</returns>+ Task<UserDto[]> GetPublicUsersAsync();+/// <summary>/// Gets active client sessions./// </summary>@@ -358,6 +364,14 @@ namespace MediaBrowser.Model.ApiClient/// <returns>Task.</returns>Task SendBrowseCommandAsync(string sessionId, string itemId, string itemName, string itemType, string context);+ /// <summary>+ /// Sends the playstate command async.+ /// </summary>+ /// <param name="sessionId">The session id.</param>+ /// <param name="request">The request.</param>+ /// <returns>Task.</returns>+ Task SendPlaystateCommandAsync(string sessionId, PlayStateRequest request);+/// <summary>/// Sends the play command async./// </summary>diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csprojindex da01da4754..14313d4214 100644--- a/MediaBrowser.Model/MediaBrowser.Model.csproj+++ b/MediaBrowser.Model/MediaBrowser.Model.csproj@@ -72,9 +72,10 @@<Compile Include="Entities\BaseItemInfo.cs" /><Compile Include="Querying\NextUpQuery.cs" /><Compile Include="Querying\SimilarItemsQuery.cs" />+ <Compile Include="Querying\UserQuery.cs" /><Compile Include="Session\BrowseRequest.cs" /><Compile Include="Session\PlayRequest.cs" />- <Compile Include="Session\PlaystateRequest.cs" />+ <Compile Include="Session\PlaystateCommand.cs" /><Compile Include="Entities\ImageDownloadOptions.cs" /><Compile Include="Logging\ILogManager.cs" /><Compile Include="MediaInfo\BlurayDiscInfo.cs" />diff --git a/MediaBrowser.Model/Querying/UserQuery.cs b/MediaBrowser.Model/Querying/UserQuery.csnew file mode 100644index 0000000000..48dbd30aa9--- /dev/null+++ b/MediaBrowser.Model/Querying/UserQuery.cs@@ -0,0 +1,9 @@++namespace MediaBrowser.Model.Querying+{+ public class UserQuery+ {+ public bool? IsHidden { get; set; }+ public bool? IsDisabled { get; set; }+ }+}diff --git a/MediaBrowser.Model/Session/PlaystateRequest.cs b/MediaBrowser.Model/Session/PlaystateCommand.cssimilarity index 66%rename from MediaBrowser.Model/Session/PlaystateRequest.csrename to MediaBrowser.Model/Session/PlaystateCommand.csindex 78551060ff..01f7068ac7 100644--- a/MediaBrowser.Model/Session/PlaystateRequest.cs+++ b/MediaBrowser.Model/Session/PlaystateCommand.cs@@ -1,25 +1,6 @@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>@@ -50,4 +31,11 @@ namespace MediaBrowser.Model.Session/// </summary>Seek}++ public class PlayStateRequest+ {+ public PlaystateCommand Command { get; set; }++ public long? SeekPosition { get; set; }+ }}diff --git a/MediaBrowser.Model/Session/SessionInfoDto.cs b/MediaBrowser.Model/Session/SessionInfoDto.csindex 294e6a2642..93d531806f 100644--- a/MediaBrowser.Model/Session/SessionInfoDto.cs+++ b/MediaBrowser.Model/Session/SessionInfoDto.cs@@ -22,6 +22,12 @@ namespace MediaBrowser.Model.Session/// </summary>/// <value>The name of the user.</value>public string UserName { get; set; }++ /// <summary>+ /// Gets or sets the application version.+ /// </summary>+ /// <value>The application version.</value>+ public string ApplicationVersion { get; set; }/// <summary>/// Gets or sets the type of the client.diff --git a/MediaBrowser.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs b/MediaBrowser.Server.Implementations/ScheduledTasks/ChapterImagesTask.csindex 79ea89ac65..0aaafec836 100644--- a/MediaBrowser.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs+++ b/MediaBrowser.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs@@ -121,7 +121,7 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks}}}-+/// <summary>/// Creates the triggers that define when the task will run/// </summary>@@ -148,13 +148,15 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasksvar numComplete = 0;- var failHistoryPath = Path.Combine(_kernel.FFMpegManager.VideoImagesDataPath, "failures.json");+ var failHistoryPath = Path.Combine(_kernel.FFMpegManager.VideoImagesDataPath, "failures.txt");List<string> previouslyFailedImages;-+try{- previouslyFailedImages = _jsonSerializer.DeserializeFromFile<List<string>>(failHistoryPath);+ previouslyFailedImages = File.ReadAllText(failHistoryPath)+ .Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)+ .ToList();}catch (FileNotFoundException){@@ -184,7 +186,7 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasksDirectory.CreateDirectory(parentPath);}- _jsonSerializer.SerializeToFile(previouslyFailedImages, failHistoryPath);+ File.WriteAllText(failHistoryPath, string.Join("|", previouslyFailedImages.ToArray()));}numComplete++;diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.csindex d9f28915a9..fde1eba9d6 100644--- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs+++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs@@ -94,13 +94,32 @@ namespace MediaBrowser.Server.Implementations.Session/// Logs the user activity./// </summary>/// <param name="clientType">Type of the client.</param>+ /// <param name="appVersion">The app version.</param>/// <param name="deviceId">The device id.</param>/// <param name="deviceName">Name of the device.</param>/// <param name="user">The user.</param>/// <returns>Task.</returns>+ /// <exception cref="System.UnauthorizedAccessException"></exception>/// <exception cref="System.ArgumentNullException">user</exception>- public Task LogConnectionActivity(string clientType, string deviceId, string deviceName, User user)+ public async Task<SessionInfo> LogConnectionActivity(string clientType, string appVersion, string deviceId, string deviceName, User user){+ if (string.IsNullOrEmpty(clientType))+ {+ throw new ArgumentNullException("clientType");+ }+ if (string.IsNullOrEmpty(appVersion))+ {+ throw new ArgumentNullException("appVersion");+ }+ if (string.IsNullOrEmpty(deviceId))+ {+ throw new ArgumentNullException("deviceId");+ }+ if (string.IsNullOrEmpty(deviceName))+ {+ throw new ArgumentNullException("deviceName");+ }+if (user != null && user.Configuration.IsDisabled){throw new UnauthorizedAccessException(string.Format("The {0} account is currently disabled. Please consult with your administrator.", user.Name));@@ -108,11 +127,13 @@ namespace MediaBrowser.Server.Implementations.Sessionvar activityDate = DateTime.UtcNow;- GetConnection(clientType, deviceId, deviceName, user).LastActivityDate = activityDate;+ var session = GetSessionInfo(clientType, appVersion, deviceId, deviceName, user);++ session.LastActivityDate = activityDate;if (user == null){- return _trueTaskResult;+ return session;}var lastActivityDate = user.LastActivityDate;@@ -122,50 +143,42 @@ namespace MediaBrowser.Server.Implementations.Session// Don't log in the db anymore frequently than 10 secondsif (lastActivityDate.HasValue && (activityDate - lastActivityDate.Value).TotalSeconds < 10){- return _trueTaskResult;+ return session;}// Save this directly. No need to fire off all the events for this.- return _userRepository.SaveUser(user, CancellationToken.None);+ await _userRepository.SaveUser(user, CancellationToken.None).ConfigureAwait(false);++ return session;}/// <summary>/// Updates the now playing item id./// </summary>- /// <param name="user">The user.</param>- /// <param name="clientType">Type of the client.</param>- /// <param name="deviceId">The device id.</param>- /// <param name="deviceName">Name of the device.</param>+ /// <param name="session">The session.</param>/// <param name="item">The item.</param>/// <param name="isPaused">if set to <c>true</c> [is paused].</param>/// <param name="currentPositionTicks">The current position ticks.</param>- private void UpdateNowPlayingItemId(User user, string clientType, string deviceId, string deviceName, BaseItem item, bool isPaused, long? currentPositionTicks = null)+ private void UpdateNowPlayingItem(SessionInfo session, BaseItem item, bool isPaused, long? currentPositionTicks = null){- var conn = GetConnection(clientType, deviceId, deviceName, user);-- conn.IsPaused = isPaused;- conn.NowPlayingPositionTicks = currentPositionTicks;- conn.NowPlayingItem = item;- conn.LastActivityDate = DateTime.UtcNow;+ session.IsPaused = isPaused;+ session.NowPlayingPositionTicks = currentPositionTicks;+ session.NowPlayingItem = item;+ session.LastActivityDate = DateTime.UtcNow;}/// <summary>/// Removes the now playing item id./// </summary>- /// <param name="user">The user.</param>- /// <param name="clientType">Type of the client.</param>- /// <param name="deviceId">The device id.</param>- /// <param name="deviceName">Name of the device.</param>+ /// <param name="session">The session.</param>/// <param name="item">The item.</param>- private void RemoveNowPlayingItemId(User user, string clientType, string deviceId, string deviceName, BaseItem item)+ private void RemoveNowPlayingItem(SessionInfo session, BaseItem item){- var conn = GetConnection(clientType, deviceId, deviceName, user);-- if (conn.NowPlayingItem != null && conn.NowPlayingItem.Id == item.Id)+ if (session.NowPlayingItem != null && session.NowPlayingItem.Id == item.Id){- conn.NowPlayingItem = null;- conn.NowPlayingPositionTicks = null;- conn.IsPaused = null;+ session.NowPlayingItem = null;+ session.NowPlayingPositionTicks = null;+ session.IsPaused = null;}}@@ -173,23 +186,24 @@ namespace MediaBrowser.Server.Implementations.Session/// Gets the connection./// </summary>/// <param name="clientType">Type of the client.</param>+ /// <param name="appVersion">The app version.</param>/// <param name="deviceId">The device id.</param>/// <param name="deviceName">Name of the device.</param>/// <param name="user">The user.</param>/// <returns>SessionInfo.</returns>- private SessionInfo GetConnection(string clientType, string deviceId, string deviceName, User user)+ private SessionInfo GetSessionInfo(string clientType, string appVersion, string deviceId, string deviceName, User user){- var key = clientType + deviceId;+ var key = clientType + deviceId + appVersion;var connection = _activeConnections.GetOrAdd(key, keyName => new SessionInfo{Client = clientType,DeviceId = deviceId,+ ApplicationVersion = appVersion,Id = Guid.NewGuid()});connection.DeviceName = deviceName;-connection.User = user;return connection;@@ -198,28 +212,25 @@ namespace MediaBrowser.Server.Implementations.Session/// <summary>/// Used to report that playback has started for an item/// </summary>- /// <param name="user">The user.</param>/// <param name="item">The item.</param>- /// <param name="clientType">Type of the client.</param>- /// <param name="deviceId">The device id.</param>- /// <param name="deviceName">Name of the device.</param>- /// <exception cref="System.ArgumentNullException">- /// </exception>- public async Task OnPlaybackStart(User user, BaseItem item, string clientType, string deviceId, string deviceName)+ /// <param name="sessionId">The session id.</param>+ /// <returns>Task.</returns>+ /// <exception cref="System.ArgumentNullException"></exception>+ public async Task OnPlaybackStart(BaseItem item, Guid sessionId){- if (user == null)- {- throw new ArgumentNullException();- }if (item == null){throw new ArgumentNullException();}- UpdateNowPlayingItemId(user, clientType, deviceId, deviceName, item, false);+ var session = Sessions.First(i => i.Id.Equals(sessionId));++ UpdateNowPlayingItem(session, item, false);var key = item.GetUserDataKey();+ var user = session.User;+var data = _userDataRepository.GetUserData(user.Id, key);data.PlayCount++;@@ -248,27 +259,25 @@ namespace MediaBrowser.Server.Implementations.Session/// <param name="item">The item.</param>/// <param name="positionTicks">The position ticks.</param>/// <param name="isPaused">if set to <c>true</c> [is paused].</param>- /// <param name="clientType">Type of the client.</param>- /// <param name="deviceId">The device id.</param>- /// <param name="deviceName">Name of the device.</param>+ /// <param name="sessionId">The session id.</param>/// <returns>Task.</returns>/// <exception cref="System.ArgumentNullException">/// </exception>- public async Task OnPlaybackProgress(User user, BaseItem item, long? positionTicks, bool isPaused, string clientType, string deviceId, string deviceName)+ public async Task OnPlaybackProgress(BaseItem item, long? positionTicks, bool isPaused, Guid sessionId){- if (user == null)- {- throw new ArgumentNullException();- }if (item == null){throw new ArgumentNullException();}- UpdateNowPlayingItemId(user, clientType, deviceId, deviceName, item, isPaused, positionTicks);+ var session = Sessions.First(i => i.Id.Equals(sessionId));++ UpdateNowPlayingItem(session, item, isPaused, positionTicks);var key = item.GetUserDataKey();+ var user = session.User;+if (positionTicks.HasValue){var data = _userDataRepository.GetUserData(user.Id, key);@@ -282,36 +291,33 @@ namespace MediaBrowser.Server.Implementations.SessionItem = item,User = user,PlaybackPositionTicks = positionTicks+}, _logger);}/// <summary>/// Used to report that playback has ended for an item/// </summary>- /// <param name="user">The user.</param>/// <param name="item">The item.</param>/// <param name="positionTicks">The position ticks.</param>- /// <param name="clientType">Type of the client.</param>- /// <param name="deviceId">The device id.</param>- /// <param name="deviceName">Name of the device.</param>+ /// <param name="sessionId">The session id.</param>/// <returns>Task.</returns>- /// <exception cref="System.ArgumentNullException">- /// </exception>- public async Task OnPlaybackStopped(User user, BaseItem item, long? positionTicks, string clientType, string deviceId, string deviceName)+ /// <exception cref="System.ArgumentNullException"></exception>+ public async Task OnPlaybackStopped(BaseItem item, long? positionTicks, Guid sessionId){- if (user == null)- {- throw new ArgumentNullException();- }if (item == null){throw new ArgumentNullException();}- RemoveNowPlayingItemId(user, clientType, deviceId, deviceName, item);+ var session = Sessions.First(i => i.Id.Equals(sessionId));++ RemoveNowPlayingItem(session, item);var key = item.GetUserDataKey();+ var user = session.User;+var data = _userDataRepository.GetUserData(user.Id, key);if (positionTicks.HasValue)diff --git a/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs b/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.csindex c649fd4747..d712bbc60c 100644--- a/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs+++ b/MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs@@ -103,7 +103,7 @@ namespace MediaBrowser.Server.Implementations.Session{var item = DtoBuilder.GetItemByClientId(message.Data, _userManager, _libraryManager);- _sessionManager.OnPlaybackStart(_userManager.GetUserById(session.User.Id), item, session.Client, session.DeviceId, session.DeviceName);+ _sessionManager.OnPlaybackStart(item, session.Id);}}else if (string.Equals(message.MessageType, "PlaybackProgress", StringComparison.OrdinalIgnoreCase))@@ -130,7 +130,7 @@ namespace MediaBrowser.Server.Implementations.Sessionvar isPaused = vals.Length > 2 && string.Equals(vals[2], "true", StringComparison.OrdinalIgnoreCase);- _sessionManager.OnPlaybackProgress(_userManager.GetUserById(session.User.Id), item, positionTicks, isPaused, session.Client, session.DeviceId, session.DeviceName);+ _sessionManager.OnPlaybackProgress(item, positionTicks, isPaused, session.Id);}}else if (string.Equals(message.MessageType, "PlaybackStopped", StringComparison.OrdinalIgnoreCase))@@ -155,7 +155,7 @@ namespace MediaBrowser.Server.Implementations.Session}}- _sessionManager.OnPlaybackStopped(_userManager.GetUserById(session.User.Id), item, positionTicks, session.Client, session.DeviceId, session.DeviceName);+ _sessionManager.OnPlaybackStopped(item, positionTicks, session.Id);}}diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.csindex 89aaec4b21..184354a226 100644--- a/MediaBrowser.WebDashboard/Api/DashboardService.cs+++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs@@ -512,6 +512,12 @@ namespace MediaBrowser.WebDashboard.Apivar newLineBytes = Encoding.UTF8.GetBytes(Environment.NewLine);+ var versionString = string.Format("window.dashboardVersion='{0}';", GetType().Assembly.GetName().Version);+ var versionBytes = Encoding.UTF8.GetBytes(versionString);++ await memoryStream.WriteAsync(versionBytes, 0, versionBytes.Length).ConfigureAwait(false);+ await memoryStream.WriteAsync(newLineBytes, 0, newLineBytes.Length).ConfigureAwait(false);+await AppendResource(memoryStream, "thirdparty/autoNumeric.js", newLineBytes).ConfigureAwait(false);await AppendResource(memoryStream, "thirdparty/html5slider.js", newLineBytes).ConfigureAwait(false);diff --git a/MediaBrowser.WebDashboard/ApiClient.js b/MediaBrowser.WebDashboard/ApiClient.jsindex 8b602610a0..3117b4b006 100644--- a/MediaBrowser.WebDashboard/ApiClient.js+++ b/MediaBrowser.WebDashboard/ApiClient.js@@ -10,8 +10,9 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {* @param {String} serverHostName* @param {String} serverPortNumber* @param {String} clientName+ * @param {String} applicationVersion*/- return function (serverProtocol, serverHostName, serverPortNumber, clientName) {+ return function (serverProtocol, serverHostName, serverPortNumber, clientName, applicationVersion) {if (!serverProtocol) {throw new Error("Must supply a serverProtocol, e.g. http:");@@ -120,7 +121,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {if (clientName) {- var auth = 'MediaBrowser Client="' + clientName + '", Device="' + deviceName + '", DeviceId="' + deviceId + '"';+ var auth = 'MediaBrowser Client="' + clientName + '", Device="' + deviceName + '", DeviceId="' + deviceId + '", Version="' + applicationVersion + '"';if (currentUserId) {auth += ', UserId="' + currentUserId + '"';@@ -3277,11 +3278,11 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {/*** Provides a friendly way to create an api client instance using information from the browser's current url*/-MediaBrowser.ApiClient.create = function (clientName) {+MediaBrowser.ApiClient.create = function (clientName, applicationVersion) {var loc = window.location;- return new MediaBrowser.ApiClient(loc.protocol, loc.hostname, loc.port, clientName);+ return new MediaBrowser.ApiClient(loc.protocol, loc.hostname, loc.port, clientName, applicationVersion);};/**diff --git a/MediaBrowser.WebDashboard/packages.config b/MediaBrowser.WebDashboard/packages.configindex a1b6ec005d..bb1b35f247 100644--- a/MediaBrowser.WebDashboard/packages.config+++ b/MediaBrowser.WebDashboard/packages.config@@ -1,6 +1,6 @@<?xml version="1.0" encoding="utf-8"?><packages>- <package id="MediaBrowser.ApiClient.Javascript" version="3.0.139" targetFramework="net45" />+ <package id="MediaBrowser.ApiClient.Javascript" version="3.0.141" targetFramework="net45" /><package id="ServiceStack.Common" version="3.9.54" targetFramework="net45" /><package id="ServiceStack.Text" version="3.9.54" targetFramework="net45" /></packages>\ No newline at end of file