(ws) port ws transfer to the new server API

This commit is contained in:
Benjamin Sergeant 2020-07-24 11:52:16 -07:00
parent 0f026c5da2
commit e78019dad6
4 changed files with 14 additions and 11 deletions

View File

@ -1,6 +1,10 @@
# Changelog # Changelog
All changes to this project will be documented in this file. All changes to this project will be documented in this file.
## [9.10.3] - 2020-07-24
(ws) port ws transfer to the new server API
## [9.10.2] - 2020-07-24 ## [9.10.2] - 2020-07-24
(websocket client) reset WebSocketTransport onClose callback in the WebSocket destructor (websocket client) reset WebSocketTransport onClose callback in the WebSocket destructor

View File

@ -6,4 +6,4 @@
#pragma once #pragma once
#define IX_WEBSOCKET_VERSION "9.10.2" #define IX_WEBSOCKET_VERSION "9.10.3"

View File

@ -238,7 +238,7 @@ install_cmake_for_linux:
doc: doc:
mkdocs gh-deploy mkdocs gh-deploy
change: change: format
vim ixwebsocket/IXWebSocketVersion.h docs/CHANGELOG.md vim ixwebsocket/IXWebSocketVersion.h docs/CHANGELOG.md
.PHONY: test .PHONY: test

View File

@ -19,12 +19,12 @@ namespace ix
ix::WebSocketServer server(port, hostname); ix::WebSocketServer server(port, hostname);
server.setTLSOptions(tlsOptions); server.setTLSOptions(tlsOptions);
server.setOnConnectionCallback([&server](std::shared_ptr<ix::WebSocket> webSocket, server.setOnClientMessageCallback(
std::shared_ptr<ConnectionState> connectionState, [&server](std::shared_ptr<ConnectionState> connectionState,
std::unique_ptr<ConnectionInfo> connectionInfo) { ConnectionInfo& connectionInfo,
auto remoteIp = connectionInfo->remoteIp; WebSocket& webSocket,
webSocket->setOnMessageCallback([webSocket, connectionState, remoteIp, &server]( const WebSocketMessagePtr& msg) {
const WebSocketMessagePtr& msg) { auto remoteIp = connectionInfo.remoteIp;
if (msg->type == ix::WebSocketMessageType::Open) if (msg->type == ix::WebSocketMessageType::Open)
{ {
spdlog::info("ws_transfer: New connection"); spdlog::info("ws_transfer: New connection");
@ -43,7 +43,7 @@ namespace ix
connectionState->getId(), connectionState->getId(),
msg->closeInfo.code, msg->closeInfo.code,
msg->closeInfo.reason); msg->closeInfo.reason);
auto remaining = server.getClients().erase(webSocket); auto remaining = server.getClients().size() - 1;
spdlog::info("ws_transfer: {} remaining clients", remaining); spdlog::info("ws_transfer: {} remaining clients", remaining);
} }
else if (msg->type == ix::WebSocketMessageType::Error) else if (msg->type == ix::WebSocketMessageType::Error)
@ -65,7 +65,7 @@ namespace ix
size_t receivers = 0; size_t receivers = 0;
for (auto&& client : server.getClients()) for (auto&& client : server.getClients())
{ {
if (client != webSocket) if (client.get() != &webSocket)
{ {
auto readyState = client->getReadyState(); auto readyState = client->getReadyState();
auto id = connectionState->getId(); auto id = connectionState->getId();
@ -119,7 +119,6 @@ namespace ix
} }
} }
}); });
});
auto res = server.listen(); auto res = server.listen();
if (!res.first) if (!res.first)