Skip to content

Commit ef58cc6

Browse files
committed
Refactor onMessage event
1 parent a098a72 commit ef58cc6

File tree

3 files changed

+4
-26
lines changed

3 files changed

+4
-26
lines changed

Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
1515
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
1616
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
17-
[assembly: AssemblyVersion("0.1.0")]
17+
[assembly: AssemblyVersion("0.2.0")]
1818
// The following attributes are used to specify the signing key for the assembly,
1919
// if desired. See the Mono documentation for more information about signing.
2020
//[assembly: AssemblyDelaySign(false)]

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,10 @@ Convars available:
3131
### Add a listener to receive messages
3232

3333
```lua
34-
-- Create a listener with a string parameter
35-
AddEventHandler("my:listener", function(message)
34+
-- Add a new listener with a string parameter
35+
AddEventHandler("WebSocketServer:onMessage", function(message)
3636
print("Received message: " .. message)
3737
end)
38-
39-
-- Add your listener to WebSockerServer
40-
TriggerEvent("WebSocketServer:addListener", "my:listener");
4138
```
4239

4340
### Send a message to connected WebSocket clients

WebSocketServer.cs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,13 @@ private enum LogLevels { Debug, Info, Warn, Error };
1414
private LogLevels logLevel;
1515

1616
private string authorization;
17-
private List<string> events;
1817
private List<WebSocket> webSockets;
1918

2019
public WebSocketServer()
2120
{
2221
logLevel = Function.Call<string>(Hash.GET_CONVAR, "websocket_debug", "false") == "true" ? LogLevels.Debug : LogLevels.Info;
2322
authorization = Function.Call<string>(Hash.GET_CONVAR, "websocket_authorization", "");
2423

25-
events = new List<string>();
26-
EventHandlers["WebSocketServer:addListener"] += new Action<dynamic>((dynamic eventName) =>
27-
{
28-
lock (events)
29-
{
30-
if (!events.Contains((string) eventName))
31-
{
32-
events.Add((string) eventName);
33-
}
34-
}
35-
});
36-
3724
webSockets = new List<WebSocket>();
3825
EventHandlers["WebSocketServer:broadcast"] += new Action<dynamic>((dynamic message) =>
3926
{
@@ -94,13 +81,7 @@ public WebSocketServer()
9481
{
9582
Log("Received message: " + msg, LogLevels.Debug);
9683

97-
lock (events)
98-
{
99-
foreach (var eventName in events)
100-
{
101-
TriggerEvent(eventName, msg);
102-
}
103-
}
84+
TriggerEvent("WebSocketServer:onMessage", msg);
10485
};
10586

10687
try

0 commit comments

Comments
 (0)