2013-05-09 13:45:46 -04:00
|
|
|
|
using MediaBrowser.Common.Net;
|
2013-05-09 13:38:02 -04:00
|
|
|
|
using MediaBrowser.Controller.Session;
|
|
|
|
|
using System;
|
2013-05-09 13:45:46 -04:00
|
|
|
|
using System.Linq;
|
2013-05-09 13:38:02 -04:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Server.Implementations.Session
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class SessionWebSocketListener
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class SessionWebSocketListener : IWebSocketListener
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _true task result
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly Task _trueTaskResult = Task.FromResult(true);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _session manager
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly ISessionManager _sessionManager;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="SessionWebSocketListener"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sessionManager">The session manager.</param>
|
|
|
|
|
public SessionWebSocketListener(ISessionManager sessionManager)
|
|
|
|
|
{
|
|
|
|
|
_sessionManager = sessionManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Processes the message.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message">The message.</param>
|
|
|
|
|
/// <returns>Task.</returns>
|
|
|
|
|
public Task ProcessMessage(WebSocketMessageInfo message)
|
|
|
|
|
{
|
2013-05-09 17:05:07 -04:00
|
|
|
|
if (string.Equals(message.MessageType, "Identity", StringComparison.OrdinalIgnoreCase))
|
2013-05-09 13:38:02 -04:00
|
|
|
|
{
|
|
|
|
|
var vals = message.Data.Split('|');
|
|
|
|
|
|
2013-05-09 17:05:07 -04:00
|
|
|
|
var client = vals[0];
|
|
|
|
|
var deviceId = vals[1];
|
2013-05-09 13:38:02 -04:00
|
|
|
|
|
|
|
|
|
var session = _sessionManager.AllConnections.FirstOrDefault(i => string.Equals(i.DeviceId, deviceId) && string.Equals(i.Client, client));
|
|
|
|
|
|
|
|
|
|
if (session != null)
|
|
|
|
|
{
|
|
|
|
|
((SessionManager)_sessionManager).IdentifyWebSocket(session.Id, message.Connection);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _trueTaskResult;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|