@ -62,7 +62,7 @@ namespace MediaBrowser.Server.Implementations.Library
}
}
}
/// <summary>
/// Gets all connections.
/// </summary>
@ -71,7 +71,7 @@ namespace MediaBrowser.Server.Implementations.Library
{
get { return _activeConnections . Where ( c = > GetUserById ( c . UserId ) ! = null ) . OrderByDescending ( c = > c . LastActivityDate ) ; }
}
/// <summary>
/// Gets the active connections.
/// </summary>
@ -172,7 +172,7 @@ namespace MediaBrowser.Server.Implementations.Library
return Users . FirstOrDefault ( u = > u . Id = = id ) ;
}
/// <summary>
/// Authenticates a User and returns a result indicating whether or not it succeeded
/// </summary>
@ -222,10 +222,11 @@ namespace MediaBrowser.Server.Implementations.Library
/// </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>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException">user</exception>
public Task LogUserActivity ( User user , ClientType clientType , string device Name)
public Task LogUserActivity ( User user , ClientType clientType , string device Id, string device Name)
{
if ( user = = null )
{
@ -236,7 +237,7 @@ namespace MediaBrowser.Server.Implementations.Library
user . LastActivityDate = activityDate ;
LogConnection ( user . Id , clientType , device Name, activityDate ) ;
LogConnection ( user . Id , clientType , device Id, device Name, activityDate ) ;
// Save this directly. No need to fire off all the events for this.
return Kernel . UserRepository . SaveUser ( user , CancellationToken . None ) ;
@ -247,15 +248,17 @@ namespace MediaBrowser.Server.Implementations.Library
/// </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="item">The item.</param>
/// <param name="currentPositionTicks">The current position ticks.</param>
private void UpdateNowPlayingItemId ( User user , ClientType clientType , string device Name, BaseItem item , long? currentPositionTicks = null )
private void UpdateNowPlayingItemId ( User user , ClientType clientType , string device Id, string device Name, BaseItem item , long? currentPositionTicks = null )
{
var conn = GetConnection ( user . Id , clientType , device Name) ;
var conn = GetConnection ( user . Id , clientType , device Id, device Name) ;
conn . NowPlayingPositionTicks = currentPositionTicks ;
conn . NowPlayingItem = DtoBuilder . GetBaseItemInfo ( item ) ;
conn . LastActivityDate = DateTime . UtcNow ;
}
/// <summary>
@ -263,11 +266,12 @@ namespace MediaBrowser.Server.Implementations.Library
/// </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="item">The item.</param>
private void RemoveNowPlayingItemId ( User user , ClientType clientType , string device Name, BaseItem item )
private void RemoveNowPlayingItemId ( User user , ClientType clientType , string device Id, string device Name, BaseItem item )
{
var conn = GetConnection ( user . Id , clientType , device Name) ;
var conn = GetConnection ( user . Id , clientType , device Id, device Name) ;
if ( conn . NowPlayingItem ! = null & & conn . NowPlayingItem . Id . Equals ( item . Id . ToString ( ) ) )
{
@ -281,11 +285,12 @@ namespace MediaBrowser.Server.Implementations.Library
/// </summary>
/// <param name="userId">The user id.</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="lastActivityDate">The last activity date.</param>
private void LogConnection ( Guid userId , ClientType clientType , string device Name, DateTime lastActivityDate )
private void LogConnection ( Guid userId , ClientType clientType , string device Id, string device Name, DateTime lastActivityDate )
{
GetConnection ( userId , clientType , device Name) . LastActivityDate = lastActivityDate ;
GetConnection ( userId , clientType , device Id, device Name) . LastActivityDate = lastActivityDate ;
}
/// <summary>
@ -293,11 +298,12 @@ namespace MediaBrowser.Server.Implementations.Library
/// </summary>
/// <param name="userId">The user id.</param>
/// <param name="clientType">Type of the client.</param>
/// <param name="deviceId">The device id.</param>
/// <param name="deviceName">Name of the device.</param>
/// <returns>ClientConnectionInfo.</returns>
private ClientConnectionInfo GetConnection ( Guid userId , ClientType clientType , string device Name)
private ClientConnectionInfo GetConnection ( Guid userId , ClientType clientType , string device Id, string device Name)
{
var conn = _activeConnections . FirstOrDefault ( c = > c . UserId = = userId & & c . ClientType = = clientType & & string . Equals ( device Name, c . DeviceName , StringComparison . OrdinalIgnoreCase ) ) ;
var conn = _activeConnections . FirstOrDefault ( c = > c . UserId = = userId & & c . ClientType = = clientType & & string . Equals ( device Id, c . DeviceId ) ) ;
if ( conn = = null )
{
@ -305,7 +311,8 @@ namespace MediaBrowser.Server.Implementations.Library
{
UserId = userId ,
ClientType = clientType ,
DeviceName = deviceName
DeviceName = deviceName ,
DeviceId = deviceId
} ;
_activeConnections . Add ( conn ) ;
@ -524,9 +531,10 @@ namespace MediaBrowser.Server.Implementations.Library
/// <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 void OnPlaybackStart ( User user , BaseItem item , ClientType clientType , string device Name)
public void OnPlaybackStart ( User user , BaseItem item , ClientType clientType , string device Id, string device Name)
{
if ( user = = null )
{
@ -537,7 +545,7 @@ namespace MediaBrowser.Server.Implementations.Library
throw new ArgumentNullException ( ) ;
}
UpdateNowPlayingItemId ( user , clientType , device Name, item ) ;
UpdateNowPlayingItemId ( user , clientType , device Id, device Name, item ) ;
// Nothing to save here
// Fire events to inform plugins
@ -555,10 +563,11 @@ namespace MediaBrowser.Server.Implementations.Library
/// <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>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException"></exception>
public async Task OnPlaybackProgress ( User user , BaseItem item , long? positionTicks , ClientType clientType , string device Name)
public async Task OnPlaybackProgress ( User user , BaseItem item , long? positionTicks , ClientType clientType , string device Id, string device Name)
{
if ( user = = null )
{
@ -569,7 +578,7 @@ namespace MediaBrowser.Server.Implementations.Library
throw new ArgumentNullException ( ) ;
}
UpdateNowPlayingItemId ( user , clientType , device Name, item , positionTicks ) ;
UpdateNowPlayingItemId ( user , clientType , device Id, device Name, item , positionTicks ) ;
if ( positionTicks . HasValue )
{
@ -594,10 +603,11 @@ namespace MediaBrowser.Server.Implementations.Library
/// <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>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException"></exception>
public async Task OnPlaybackStopped ( User user , BaseItem item , long? positionTicks , ClientType clientType , string device Name)
public async Task OnPlaybackStopped ( User user , BaseItem item , long? positionTicks , ClientType clientType , string device Id, string device Name)
{
if ( user = = null )
{
@ -608,7 +618,7 @@ namespace MediaBrowser.Server.Implementations.Library
throw new ArgumentNullException ( ) ;
}
RemoveNowPlayingItemId ( user , clientType , device Name, item ) ;
RemoveNowPlayingItemId ( user , clientType , device Id, device Name, item ) ;
var data = item . GetUserData ( user , true ) ;