Skip to content

Commit

Permalink
feat: websocket can receive port in url (#1287)
Browse files Browse the repository at this point in the history
* feat: websocket can now receive port and encryption setting from uri

* check for ws or wss scheme
  • Loading branch information
paulpach authored and miwarnec committed Dec 9, 2019
1 parent 06946cf commit c8ad118
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Assets/Mirror/Runtime/Transport/Websocket/WebsocketTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace Mirror.Websocket
{
public class WebsocketTransport : Transport
{
public const string Scheme = "ws";
public const string SecureScheme = "wss";


protected Client client = new Client();
protected Server server = new Server();
Expand Down Expand Up @@ -61,6 +64,21 @@ public override void ClientConnect(string host)
}
}

public override void ClientConnect(Uri uri)
{
if (uri.Scheme != Scheme && uri.Scheme != SecureScheme)
throw new ArgumentException($"Invalid url {uri}, use {Scheme}://host:port or {SecureScheme}://host:port instead", nameof(uri));

if (uri.IsDefaultPort)
{
UriBuilder uriBuilder = new UriBuilder(uri);
uriBuilder.Port = port;
uri = uriBuilder.Uri;
}

client.Connect(uri);
}

public override bool ClientSend(int channelId, ArraySegment<byte> segment)
{
client.Send(segment);
Expand Down

0 comments on commit c8ad118

Please sign in to comment.