aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Session
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Server.Implementations/Session')
-rw-r--r--Emby.Server.Implementations/Session/FirebaseSessionController.cs131
-rw-r--r--Emby.Server.Implementations/Session/SessionManager.cs77
-rw-r--r--Emby.Server.Implementations/Session/SessionWebSocketListener.cs10
-rw-r--r--Emby.Server.Implementations/Session/WebSocketController.cs2
4 files changed, 36 insertions, 184 deletions
diff --git a/Emby.Server.Implementations/Session/FirebaseSessionController.cs b/Emby.Server.Implementations/Session/FirebaseSessionController.cs
deleted file mode 100644
index cfe513305..000000000
--- a/Emby.Server.Implementations/Session/FirebaseSessionController.cs
+++ /dev/null
@@ -1,131 +0,0 @@
-using MediaBrowser.Controller.Session;
-using MediaBrowser.Model.Net;
-using MediaBrowser.Common.Net;
-using MediaBrowser.Model.Serialization;
-using System;
-using System.Threading;
-using System.Threading.Tasks;
-using System.Text;
-using MediaBrowser.Common;
-
-namespace Emby.Server.Implementations.Session
-{
- public class FirebaseSessionController : ISessionController
- {
- private readonly IHttpClient _httpClient;
- private readonly IJsonSerializer _json;
- private readonly ISessionManager _sessionManager;
-
- public SessionInfo Session { get; private set; }
-
- private readonly string _token;
-
- private IApplicationHost _appHost;
- private string _senderId;
- private string _applicationId;
-
- public FirebaseSessionController(IHttpClient httpClient,
- IApplicationHost appHost,
- IJsonSerializer json,
- SessionInfo session,
- string token, ISessionManager sessionManager)
- {
- _httpClient = httpClient;
- _json = json;
- _appHost = appHost;
- Session = session;
- _token = token;
- _sessionManager = sessionManager;
-
- _applicationId = _appHost.GetValue("firebase_applicationid");
- _senderId = _appHost.GetValue("firebase_senderid");
- }
-
- public static bool IsSupported(IApplicationHost appHost)
- {
- return !string.IsNullOrEmpty(appHost.GetValue("firebase_applicationid")) && !string.IsNullOrEmpty(appHost.GetValue("firebase_senderid"));
- }
-
- public bool IsSessionActive
- {
- get
- {
- return (DateTime.UtcNow - Session.LastActivityDate).TotalDays <= 3;
- }
- }
-
- public bool SupportsMediaControl
- {
- get { return true; }
- }
-
- public async Task SendMessage<T>(string name, string messageId, T data, ISessionController[] allControllers, CancellationToken cancellationToken)
- {
- if (!IsSessionActive)
- {
- return;
- }
-
- if (string.IsNullOrEmpty(_senderId) || string.IsNullOrEmpty(_applicationId))
- {
- return;
- }
-
- foreach (var controller in allControllers)
- {
- // Don't send if there's an active web socket connection
- if ((controller is WebSocketController) && controller.IsSessionActive)
- {
- return;
- }
- }
-
- var msg = new WebSocketMessage<T>
- {
- Data = data,
- MessageType = name,
- MessageId = messageId,
- ServerId = _appHost.SystemId
- };
-
- var req = new FirebaseBody<T>
- {
- to = _token,
- data = msg
- };
-
- var byteArray = Encoding.UTF8.GetBytes(_json.SerializeToString(req));
-
- var enableLogging = false;
-
-#if DEBUG
- enableLogging = true;
-#endif
-
- var options = new HttpRequestOptions
- {
- Url = "https://fcm.googleapis.com/fcm/send",
- RequestContentType = "application/json",
- RequestContentBytes = byteArray,
- CancellationToken = cancellationToken,
- LogRequest = enableLogging,
- LogResponse = enableLogging,
- LogErrors = enableLogging
- };
-
- options.RequestHeaders["Authorization"] = string.Format("key={0}", _applicationId);
- options.RequestHeaders["Sender"] = string.Format("id={0}", _senderId);
-
- using (var response = await _httpClient.Post(options).ConfigureAwait(false))
- {
-
- }
- }
- }
-
- internal class FirebaseBody<T>
- {
- public string to { get; set; }
- public WebSocketMessage<T> data { get; set; }
- }
-}
diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs
index a2102dc45..7321e9f86 100644
--- a/Emby.Server.Implementations/Session/SessionManager.cs
+++ b/Emby.Server.Implementations/Session/SessionManager.cs
@@ -15,10 +15,9 @@ using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Events;
using MediaBrowser.Model.Library;
-using MediaBrowser.Model.Logging;
+using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Session;
-using MediaBrowser.Model.Users;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
@@ -248,18 +247,17 @@ namespace Emby.Server.Implementations.Session
}
catch (Exception ex)
{
- _logger.ErrorException("Error updating user", ex);
+ _logger.LogError("Error updating user", ex);
}
}
}
if ((activityDate - lastActivityDate).TotalSeconds > 10)
{
- EventHelper.FireEventIfNotNull(SessionActivity, this, new SessionEventArgs
+ SessionActivity?.Invoke(this, new SessionEventArgs
{
SessionInfo = session
-
- }, _logger);
+ });
}
return session;
@@ -528,7 +526,7 @@ namespace Emby.Server.Implementations.Session
foreach (var session in idle)
{
- _logger.Debug("Session {0} has gone idle while playing", session.Id);
+ _logger.LogDebug("Session {0} has gone idle while playing", session.Id);
try
{
@@ -543,7 +541,7 @@ namespace Emby.Server.Implementations.Session
}
catch (Exception ex)
{
- _logger.Debug("Error calling OnPlaybackStopped", ex);
+ _logger.LogDebug("Error calling OnPlaybackStopped", ex);
}
}
@@ -693,7 +691,7 @@ namespace Emby.Server.Implementations.Session
}
}
- EventHelper.FireEventIfNotNull(PlaybackProgress, this, new PlaybackProgressEventArgs
+ PlaybackProgress?.Invoke(this, new PlaybackProgressEventArgs
{
Item = libraryItem,
Users = users,
@@ -707,8 +705,7 @@ namespace Emby.Server.Implementations.Session
PlaySessionId = info.PlaySessionId,
IsAutomated = isAutomated,
Session = session
-
- }, _logger);
+ });
if (!isAutomated)
{
@@ -847,7 +844,7 @@ namespace Emby.Server.Implementations.Session
{
var msString = info.PositionTicks.HasValue ? (info.PositionTicks.Value / 10000).ToString(CultureInfo.InvariantCulture) : "unknown";
- _logger.Info("Playback stopped reported by app {0} {1} playing {2}. Stopped at {3} ms",
+ _logger.LogInformation("Playback stopped reported by app {0} {1} playing {2}. Stopped at {3} ms",
session.Client,
session.ApplicationVersion,
info.Item.Name,
@@ -882,7 +879,7 @@ namespace Emby.Server.Implementations.Session
}
catch (Exception ex)
{
- _logger.ErrorException("Error closing live stream", ex);
+ _logger.LogError("Error closing live stream", ex);
}
}
@@ -1095,7 +1092,7 @@ namespace Emby.Server.Implementations.Session
if (item == null)
{
- _logger.Error("A non-existant item Id {0} was passed into TranslateItemForPlayback", id);
+ _logger.LogError("A non-existant item Id {0} was passed into TranslateItemForPlayback", id);
return new List<BaseItem>();
}
@@ -1151,7 +1148,7 @@ namespace Emby.Server.Implementations.Session
if (item == null)
{
- _logger.Error("A non-existant item Id {0} was passed into TranslateItemForInstantMix", id);
+ _logger.LogError("A non-existant item Id {0} was passed into TranslateItemForInstantMix", id);
return new List<BaseItem>();
}
@@ -1222,7 +1219,7 @@ namespace Emby.Server.Implementations.Session
}
catch (Exception ex)
{
- _logger.ErrorException("Error in SendRestartRequiredNotification.", ex);
+ _logger.LogError("Error in SendRestartRequiredNotification.", ex);
}
}, cancellationToken)).ToArray();
@@ -1249,7 +1246,7 @@ namespace Emby.Server.Implementations.Session
}
catch (Exception ex)
{
- _logger.ErrorException("Error in SendServerShutdownNotification.", ex);
+ _logger.LogError("Error in SendServerShutdownNotification.", ex);
}
}, cancellationToken)).ToArray();
@@ -1266,7 +1263,7 @@ namespace Emby.Server.Implementations.Session
{
CheckDisposed();
- _logger.Debug("Beginning SendServerRestartNotification");
+ _logger.LogDebug("Beginning SendServerRestartNotification");
var sessions = Sessions.ToList();
@@ -1278,7 +1275,7 @@ namespace Emby.Server.Implementations.Session
}
catch (Exception ex)
{
- _logger.ErrorException("Error in SendServerRestartNotification.", ex);
+ _logger.LogError("Error in SendServerRestartNotification.", ex);
}
}, cancellationToken)).ToArray();
@@ -1399,7 +1396,7 @@ namespace Emby.Server.Implementations.Session
if (result == null)
{
- EventHelper.FireEventIfNotNull(AuthenticationFailed, this, new GenericEventArgs<AuthenticationRequest>(request), _logger);
+ AuthenticationFailed?.Invoke(this, new GenericEventArgs<AuthenticationRequest>(request));
throw new SecurityException("Invalid user or password entered.");
}
@@ -1424,7 +1421,7 @@ namespace Emby.Server.Implementations.Session
ServerId = _appHost.SystemId
};
- EventHelper.FireEventIfNotNull(AuthenticationSucceeded, this, new GenericEventArgs<AuthenticationResult>(returnResult), _logger);
+ AuthenticationSucceeded?.Invoke(this, new GenericEventArgs<AuthenticationResult>(returnResult));
return returnResult;
}
@@ -1462,7 +1459,7 @@ namespace Emby.Server.Implementations.Session
if (existing != null)
{
- _logger.Info("Reissuing access token: " + existing.AccessToken);
+ _logger.LogInformation("Reissuing access token: " + existing.AccessToken);
return existing.AccessToken;
}
@@ -1481,7 +1478,7 @@ namespace Emby.Server.Implementations.Session
UserName = user.Name
};
- _logger.Info("Creating new access token for user {0}", user.Id);
+ _logger.LogInformation("Creating new access token for user {0}", user.Id);
_authRepo.Create(newToken);
return newToken.AccessToken;
@@ -1513,7 +1510,7 @@ namespace Emby.Server.Implementations.Session
{
CheckDisposed();
- _logger.Info("Logging out access token {0}", existing.AccessToken);
+ _logger.LogInformation("Logging out access token {0}", existing.AccessToken);
_authRepo.Delete(existing);
@@ -1529,7 +1526,7 @@ namespace Emby.Server.Implementations.Session
}
catch (Exception ex)
{
- _logger.ErrorException("Error reporting session ended", ex);
+ _logger.LogError("Error reporting session ended", ex);
}
}
}
@@ -1577,21 +1574,12 @@ namespace Emby.Server.Implementations.Session
{
session.Capabilities = capabilities;
- if (!string.IsNullOrEmpty(capabilities.PushToken))
- {
- if (string.Equals(capabilities.PushTokenType, "firebase", StringComparison.OrdinalIgnoreCase) && FirebaseSessionController.IsSupported(_appHost))
- {
- EnsureFirebaseController(session, capabilities.PushToken);
- }
- }
-
if (saveCapabilities)
{
- EventHelper.FireEventIfNotNull(CapabilitiesChanged, this, new SessionEventArgs
+ CapabilitiesChanged?.Invoke(this, new SessionEventArgs
{
SessionInfo = session
-
- }, _logger);
+ });
try
{
@@ -1599,16 +1587,11 @@ namespace Emby.Server.Implementations.Session
}
catch (Exception ex)
{
- _logger.ErrorException("Error saving device capabilities", ex);
+ _logger.LogError("Error saving device capabilities", ex);
}
}
}
- private void EnsureFirebaseController(SessionInfo session, string token)
- {
- session.EnsureController<FirebaseSessionController>(s => new FirebaseSessionController(_httpClient, _appHost, _jsonSerializer, s, token, this));
- }
-
private ClientCapabilities GetSavedCapabilities(string deviceId)
{
return _deviceManager.GetCapabilities(deviceId);
@@ -1692,7 +1675,7 @@ namespace Emby.Server.Implementations.Session
}
catch (Exception ex)
{
- _logger.ErrorException("Error getting {0} image info", ex, type);
+ _logger.LogError("Error getting {0} image info", ex, type);
return null;
}
}
@@ -1818,7 +1801,7 @@ namespace Emby.Server.Implementations.Session
}
catch (Exception ex)
{
- _logger.ErrorException("Error sending message", ex);
+ _logger.LogError("Error sending message", ex);
}
}, cancellationToken)).ToArray();
@@ -1840,7 +1823,7 @@ namespace Emby.Server.Implementations.Session
}
catch (Exception ex)
{
- _logger.ErrorException("Error sending message", ex);
+ _logger.LogError("Error sending message", ex);
}
}, cancellationToken)).ToArray();
@@ -1862,7 +1845,7 @@ namespace Emby.Server.Implementations.Session
}
catch (Exception ex)
{
- _logger.ErrorException("Error sending message", ex);
+ _logger.LogError("Error sending message", ex);
}
}, cancellationToken)).ToArray();
@@ -1886,7 +1869,7 @@ namespace Emby.Server.Implementations.Session
}
catch (Exception ex)
{
- _logger.ErrorException("Error sending message", ex);
+ _logger.LogError("Error sending message", ex);
}
}, cancellationToken)).ToArray();
diff --git a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs b/Emby.Server.Implementations/Session/SessionWebSocketListener.cs
index 9ab4753fb..3bb022b32 100644
--- a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs
+++ b/Emby.Server.Implementations/Session/SessionWebSocketListener.cs
@@ -1,7 +1,7 @@
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Events;
-using MediaBrowser.Model.Logging;
+using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Session;
using System;
@@ -40,14 +40,14 @@ namespace Emby.Server.Implementations.Session
/// Initializes a new instance of the <see cref="SessionWebSocketListener" /> class.
/// </summary>
/// <param name="sessionManager">The session manager.</param>
- /// <param name="logManager">The log manager.</param>
+ /// <param name="loggerFactory">The logger factory.</param>
/// <param name="json">The json.</param>
/// <param name="httpServer">The HTTP server.</param>
/// <param name="serverManager">The server manager.</param>
- public SessionWebSocketListener(ISessionManager sessionManager, ILogManager logManager, IJsonSerializer json, IHttpServer httpServer)
+ public SessionWebSocketListener(ISessionManager sessionManager, ILoggerFactory loggerFactory, IJsonSerializer json, IHttpServer httpServer)
{
_sessionManager = sessionManager;
- _logger = logManager.GetLogger(GetType().Name);
+ _logger = loggerFactory.CreateLogger(GetType().Name);
_json = json;
_httpServer = httpServer;
httpServer.WebSocketConnected += _serverManager_WebSocketConnected;
@@ -63,7 +63,7 @@ namespace Emby.Server.Implementations.Session
}
else
{
- _logger.Warn("Unable to determine session based on url: {0}", e.Argument.Url);
+ _logger.LogWarning("Unable to determine session based on url: {0}", e.Argument.Url);
}
}
diff --git a/Emby.Server.Implementations/Session/WebSocketController.cs b/Emby.Server.Implementations/Session/WebSocketController.cs
index ddac9660f..bdae5cf8f 100644
--- a/Emby.Server.Implementations/Session/WebSocketController.cs
+++ b/Emby.Server.Implementations/Session/WebSocketController.cs
@@ -1,7 +1,7 @@
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.Logging;
+using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Session;
using MediaBrowser.Model.System;