Skip to content

Commit

Permalink
HTTP.Websocket -> Impl. custom MessageType to websocket event
Browse files Browse the repository at this point in the history
HTTP.Websocket -> Impl. custom MessageType to websocket event
  • Loading branch information
alec1o committed Jun 29, 2024
1 parent 320ba94 commit 8fb0088
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/http/interfaces/IHTTP.ServerTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public interface ServerTo
void WebsocketDataBroadcast(string data, HTTP.MessageType messageType);
void WebsocketDataBroadcast(string data, HTTP.MessageType messageType, Encoding encoding);

void WebsocketEventBroadcast(string name, byte[] data);
void WebsocketEventBroadcast(string name, string data);
void WebsocketEventBroadcast(string name, string data, Encoding encoding);
void WebsocketEventBroadcast(string name, byte[] data, HTTP.MessageType messageType);
void WebsocketEventBroadcast(string name, string data, HTTP.MessageType messageType);
void WebsocketEventBroadcast(string name, string data, HTTP.MessageType messageType, Encoding encoding);
}
}
}
2 changes: 1 addition & 1 deletion src/http/interfaces/IHTTP.WebSocketOn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface WebSocketOn : IOn<ClientWebSocket>
/// Handle (netly event) received
/// </summary>
/// <param name="callback">Callback</param>
void Event(Action<string, byte[]> callback);
void Event(Action<string, byte[], HTTP.MessageType> callback);

/// <summary>
/// Handle connection closed
Expand Down
6 changes: 3 additions & 3 deletions src/http/interfaces/IHTTP.WebSocketTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,22 @@ public interface WebSocketTo
/// </summary>
/// <param name="name">Event name</param>
/// <param name="buffer">Event buffer</param>
void Event(string name, byte[] buffer);
void Event(string name, byte[] buffer, HTTP.MessageType messageType);

/// <summary>
/// Send Netly event for server (string)
/// </summary>
/// <param name="name">Event name</param>
/// <param name="buffer">Event buffer</param>
void Event(string name, string buffer);
void Event(string name, string buffer, HTTP.MessageType messageType);

/// <summary>
/// Send Netly event for server (string)
/// </summary>
/// <param name="name">Event name</param>
/// <param name="buffer">Event buffer</param>
/// <param name="encoding">String encoding</param>
void Event(string name, string buffer, Encoding encoding);
void Event(string name, string buffer, HTTP.MessageType messageType, Encoding encoding);
}
}
}
12 changes: 6 additions & 6 deletions src/http/partials/Server/HTTP.ServerTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,27 @@ public void WebsocketDataBroadcast(string data, HTTP.MessageType messageType, En
}
}

public void WebsocketEventBroadcast(string name, byte[] data)
public void WebsocketEventBroadcast(string name, byte[] data, HTTP.MessageType messageType)
{
lock (_websocketListLock)
{
foreach (var ws in _websocketList) ws.To.Event(name, data);
foreach (var ws in _websocketList) ws.To.Event(name, data, messageType);
}
}

public void WebsocketEventBroadcast(string name, string data)
public void WebsocketEventBroadcast(string name, string data, HTTP.MessageType messageType)
{
lock (_websocketListLock)
{
foreach (var ws in _websocketList) ws.To.Event(name, data);
foreach (var ws in _websocketList) ws.To.Event(name, data, messageType);
}
}

public void WebsocketEventBroadcast(string name, string data, Encoding encoding)
public void WebsocketEventBroadcast(string name, string data, MessageType messageType, Encoding encoding)
{
lock (_websocketListLock)
{
foreach (var ws in _websocketList) ws.To.Event(name, data, encoding);
foreach (var ws in _websocketList) ws.To.Event(name, data, messageType, encoding);
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/http/partials/Websocket/HTTP.WebSocketTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,19 @@ public void Data(string buffer, HTTP.MessageType messageType, Encoding encoding)
Send(buffer.GetBytes(encoding), messageType);
}

public void Event(string name, byte[] buffer)
public void Event(string name, byte[] buffer, HTTP.MessageType messageType)
{
Send(NetlyEnvironment.EventManager.Create(name, buffer), MessageType.Binary);
Send(NetlyEnvironment.EventManager.Create(name, buffer), messageType);
}

public void Event(string name, string buffer)
public void Event(string name, string buffer, HTTP.MessageType messageType)
{
Send(NetlyEnvironment.EventManager.Create(name, buffer.GetBytes()), MessageType.Binary);
Send(NetlyEnvironment.EventManager.Create(name, buffer.GetBytes()), messageType);
}

public void Event(string name, string buffer, Encoding encoding)
public void Event(string name, string buffer, HTTP.MessageType messageType, Encoding encoding)
{
Send(NetlyEnvironment.EventManager.Create(name, buffer.GetBytes(encoding)), MessageType.Binary);
Send(NetlyEnvironment.EventManager.Create(name, buffer.GetBytes(encoding)), messageType);
}

private void Send(byte[] buffer, HTTP.MessageType type)
Expand Down Expand Up @@ -264,7 +264,7 @@ private async void ReceiveJob(object _)

if (eventData.data != null && eventData.name != null)
// Is Netly Event
_socket._on.OnEvent?.Invoke(null, (eventData.name, eventData.data));
_socket._on.OnEvent?.Invoke(null, (eventData.name, eventData.data, messageType));
else
// Is Default buffer
_socket._on.OnData?.Invoke(null, (data, messageType));
Expand Down

0 comments on commit 8fb0088

Please sign in to comment.