mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
fixed web socket check-ins
This commit is contained in:
parent
369107bab8
commit
a1b45e9890
@ -98,12 +98,15 @@ namespace MediaBrowser.Api
|
|||||||
throw new ResourceNotFoundException(string.Format("Session {0} not found.", request.Id));
|
throw new ResourceNotFoundException(string.Format("Session {0} not found.", request.Id));
|
||||||
}
|
}
|
||||||
|
|
||||||
session.WebSocket.SendAsync(new WebSocketMessage<BrowseTo>
|
foreach (var socket in session.WebSockets)
|
||||||
{
|
{
|
||||||
MessageType = "Browse",
|
socket.SendAsync(new WebSocketMessage<BrowseTo>
|
||||||
Data = request
|
{
|
||||||
|
MessageType = "Browse",
|
||||||
|
Data = request
|
||||||
|
|
||||||
}, CancellationToken.None);
|
}, CancellationToken.None);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using MediaBrowser.Common.Net;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Model.Net;
|
using MediaBrowser.Model.Net;
|
||||||
using System;
|
using System;
|
||||||
@ -10,6 +12,11 @@ namespace MediaBrowser.Controller.Session
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class SessionInfo
|
public class SessionInfo
|
||||||
{
|
{
|
||||||
|
public SessionInfo()
|
||||||
|
{
|
||||||
|
WebSockets = new List<IWebSocketConnection>();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the id.
|
/// Gets or sets the id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -86,7 +93,7 @@ namespace MediaBrowser.Controller.Session
|
|||||||
/// Gets or sets the web socket.
|
/// Gets or sets the web socket.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The web socket.</value>
|
/// <value>The web socket.</value>
|
||||||
public IWebSocketConnection WebSocket { get; set; }
|
public List<IWebSocketConnection> WebSockets { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether this instance is active.
|
/// Gets a value indicating whether this instance is active.
|
||||||
@ -96,9 +103,9 @@ namespace MediaBrowser.Controller.Session
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (WebSocket != null)
|
if (WebSockets.Count > 0)
|
||||||
{
|
{
|
||||||
return WebSocket.State == WebSocketState.Open;
|
return WebSockets.Any(i => i.State == WebSocketState.Open);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (DateTime.UtcNow - LastActivityDate).TotalMinutes <= 5;
|
return (DateTime.UtcNow - LastActivityDate).TotalMinutes <= 5;
|
||||||
@ -113,7 +120,7 @@ namespace MediaBrowser.Controller.Session
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return WebSocket != null && WebSocket.State == WebSocketState.Open;
|
return WebSockets.Any(i => i.State == WebSocketState.Open);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ using MediaBrowser.Model.Logging;
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using MediaBrowser.Model.Net;
|
||||||
|
|
||||||
namespace MediaBrowser.Server.Implementations.Session
|
namespace MediaBrowser.Server.Implementations.Session
|
||||||
{
|
{
|
||||||
@ -66,12 +67,15 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||||||
|
|
||||||
if (session != null)
|
if (session != null)
|
||||||
{
|
{
|
||||||
session.WebSocket = message.Connection;
|
var sockets = session.WebSockets.Where(i => i.State == WebSocketState.Open).ToList();
|
||||||
|
sockets.Add(message.Connection);
|
||||||
|
|
||||||
|
session.WebSockets = sockets;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (string.Equals(message.MessageType, "Context", StringComparison.OrdinalIgnoreCase))
|
else if (string.Equals(message.MessageType, "Context", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSocket == message.Connection);
|
var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSockets.Contains(message.Connection));
|
||||||
|
|
||||||
if (session != null)
|
if (session != null)
|
||||||
{
|
{
|
||||||
@ -84,7 +88,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||||||
}
|
}
|
||||||
else if (string.Equals(message.MessageType, "PlaybackStart", StringComparison.OrdinalIgnoreCase))
|
else if (string.Equals(message.MessageType, "PlaybackStart", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSocket == message.Connection);
|
var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSockets.Contains(message.Connection));
|
||||||
|
|
||||||
if (session != null && session.UserId.HasValue)
|
if (session != null && session.UserId.HasValue)
|
||||||
{
|
{
|
||||||
@ -95,7 +99,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||||||
}
|
}
|
||||||
else if (string.Equals(message.MessageType, "PlaybackProgress", StringComparison.OrdinalIgnoreCase))
|
else if (string.Equals(message.MessageType, "PlaybackProgress", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSocket == message.Connection);
|
var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSockets.Contains(message.Connection));
|
||||||
|
|
||||||
if (session != null && session.UserId.HasValue)
|
if (session != null && session.UserId.HasValue)
|
||||||
{
|
{
|
||||||
@ -122,7 +126,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||||||
}
|
}
|
||||||
else if (string.Equals(message.MessageType, "PlaybackStopped", StringComparison.OrdinalIgnoreCase))
|
else if (string.Equals(message.MessageType, "PlaybackStopped", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSocket == message.Connection);
|
var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSockets.Contains(message.Connection));
|
||||||
|
|
||||||
if (session != null && session.UserId.HasValue)
|
if (session != null && session.UserId.HasValue)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user