@@ -19,12 +19,12 @@ namespace ix
19
19
ix::WebSocketServer server (port, hostname);
20
20
server.setTLSOptions (tlsOptions);
21
21
22
- server.setOnConnectionCallback ([&server](std::shared_ptr<ix::WebSocket> webSocket,
23
- std::shared_ptr<ConnectionState> connectionState,
24
- std::unique_ptr< ConnectionInfo> connectionInfo) {
25
- auto remoteIp = connectionInfo-> remoteIp ;
26
- webSocket-> setOnMessageCallback ([webSocket, connectionState, remoteIp, &server](
27
- const WebSocketMessagePtr& msg) {
22
+ server.setOnClientMessageCallback (
23
+ [&server]( std::shared_ptr<ConnectionState> connectionState,
24
+ ConnectionInfo& connectionInfo,
25
+ WebSocket& webSocket,
26
+ const WebSocketMessagePtr& msg) {
27
+ auto remoteIp = connectionInfo. remoteIp ;
28
28
if (msg->type == ix::WebSocketMessageType::Open)
29
29
{
30
30
spdlog::info (" ws_transfer: New connection" );
@@ -43,7 +43,7 @@ namespace ix
43
43
connectionState->getId (),
44
44
msg->closeInfo .code ,
45
45
msg->closeInfo .reason );
46
- auto remaining = server.getClients ().erase (webSocket) ;
46
+ auto remaining = server.getClients ().size () - 1 ;
47
47
spdlog::info (" ws_transfer: {} remaining clients" , remaining);
48
48
}
49
49
else if (msg->type == ix::WebSocketMessageType::Error)
@@ -65,7 +65,7 @@ namespace ix
65
65
size_t receivers = 0 ;
66
66
for (auto && client : server.getClients ())
67
67
{
68
- if (client != webSocket)
68
+ if (client. get () != & webSocket)
69
69
{
70
70
auto readyState = client->getReadyState ();
71
71
auto id = connectionState->getId ();
@@ -119,7 +119,6 @@ namespace ix
119
119
}
120
120
}
121
121
});
122
- });
123
122
124
123
auto res = server.listen ();
125
124
if (!res.first )
0 commit comments