Add Option to configure websocket path (#198)

This path was hardcoded to /netcode which is not neccessary for
websocket connections, and is an oppinionated choice that breaks in
certain load balancer configurations such as using domains with certs
for WSS connections.

Web sockets are not required to listen on any path at all. This allows
users to delete the path but the default does not break backwards
compatability.
This commit is contained in:
Jason Spafford 2023-01-17 10:13:36 -05:00 коммит произвёл GitHub
Родитель c7246c7133
Коммит 30e981825b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 3 добавлений и 2 удалений

Просмотреть файл

@ -14,6 +14,7 @@ namespace Netcode.Transports.WebSocket
[Header("Transport")]
public string ConnectAddress = "127.0.0.1";
public string Path = "/netcode";
public ushort Port = 7777;
public bool SecureConnection = false;
public bool AllowForwardedRequest;
@ -112,7 +113,7 @@ namespace Netcode.Transports.WebSocket
}
var protocol = SecureConnection ? "wss" : "ws";
WebSocketClient = WebSocketClientFactory.Create($"{protocol}://{ConnectAddress}:{Port}/netcode");
WebSocketClient = WebSocketClientFactory.Create($"{protocol}://{ConnectAddress}:{Port}{Path}");
WebSocketClient.Connect();
IsStarted = true;
@ -129,7 +130,7 @@ namespace Netcode.Transports.WebSocket
WebSocketServer = new WebSocketServer(Port, SecureConnection);
WebSocketServer.AllowForwardedRequest = AllowForwardedRequest;
WebSocketServer.AddWebSocketService<WebSocketServerConnectionBehavior>("/netcode");
WebSocketServer.AddWebSocketService<WebSocketServerConnectionBehavior>(Path);
if (!string.IsNullOrEmpty(CertificateBase64String))
{
var bytes = Convert.FromBase64String(CertificateBase64String);