mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-18 08:06:35 +00:00
Add upnp configuration
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
using Fleck;
|
||||
using MediaBrowser.Common.Net;
|
||||
using System;
|
||||
using IWebSocketServer = MediaBrowser.Common.Net.IWebSocketServer;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.WebSocket
|
||||
{
|
||||
public class FleckServer : IWebSocketServer
|
||||
{
|
||||
private WebSocketServer _server;
|
||||
|
||||
public void Start(int portNumber)
|
||||
{
|
||||
var server = new WebSocketServer("ws://localhost:" + portNumber);
|
||||
|
||||
server.Start(socket =>
|
||||
{
|
||||
socket.OnOpen = () => OnClientConnected(socket);
|
||||
});
|
||||
|
||||
_server = server;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
_server.Dispose();
|
||||
}
|
||||
|
||||
private void OnClientConnected(Fleck.IWebSocketConnection context)
|
||||
{
|
||||
if (WebSocketConnected != null)
|
||||
{
|
||||
var socket = new FleckWebSocket(context);
|
||||
|
||||
WebSocketConnected(this, new WebSocketConnectEventArgs
|
||||
{
|
||||
WebSocket = socket,
|
||||
Endpoint = context.ConnectionInfo.ClientIpAddress + ":" + context.ConnectionInfo.ClientPort
|
||||
});
|
||||
}
|
||||
}
|
||||
public event EventHandler<WebSocketConnectEventArgs> WebSocketConnected;
|
||||
|
||||
public int Port
|
||||
{
|
||||
get { return _server.Port; }
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_server.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Model.Net;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using IWebSocketConnection = Fleck.IWebSocketConnection;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.WebSocket
|
||||
{
|
||||
public class FleckWebSocket : IWebSocket
|
||||
{
|
||||
private readonly IWebSocketConnection _connection;
|
||||
|
||||
public FleckWebSocket(IWebSocketConnection connection)
|
||||
{
|
||||
_connection = connection;
|
||||
|
||||
_connection.OnMessage = OnReceiveData;
|
||||
}
|
||||
|
||||
public WebSocketState State
|
||||
{
|
||||
get { return _connection.IsAvailable ? WebSocketState.Open : WebSocketState.Closed; }
|
||||
}
|
||||
|
||||
private void OnReceiveData(string data)
|
||||
{
|
||||
if (OnReceive != null)
|
||||
{
|
||||
OnReceive(data);
|
||||
}
|
||||
}
|
||||
|
||||
public Task SendAsync(byte[] bytes, WebSocketMessageType type, bool endOfMessage, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.Run(() => _connection.Send(bytes));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_connection.Close();
|
||||
}
|
||||
|
||||
public Action<byte[]> OnReceiveBytes { get; set; }
|
||||
public Action<string> OnReceive { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user