(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
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
(websocket client) reset WebSocketTransport onClose callback in the WebSocket destructor

View File

@ -6,4 +6,4 @@
#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:
mkdocs gh-deploy
change:
change: format
vim ixwebsocket/IXWebSocketVersion.h docs/CHANGELOG.md
.PHONY: test

View File

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