From e34f1c30d6a7227c9fbbdefc8c1a16ef3489a2e6 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Fri, 24 Jul 2020 14:35:07 -0700 Subject: [PATCH] (ws) port broadcast_server sub-command to the new server API --- docs/CHANGELOG.md | 4 ++++ ixwebsocket/IXWebSocketVersion.h | 2 +- ws/ws_broadcast_server.cpp | 15 +++++++-------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index d1776601..58445903 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All changes to this project will be documented in this file. +## [9.10.6] - 2020-07-24 + +(ws) port broadcast_server sub-command to the new server API + ## [9.10.5] - 2020-07-24 (unittest) port most unittests to the new server API diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index 24d3976c..76415b07 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "9.10.5" +#define IX_WEBSOCKET_VERSION "9.10.6" diff --git a/ws/ws_broadcast_server.cpp b/ws/ws_broadcast_server.cpp index b60eccbb..b154ef94 100644 --- a/ws/ws_broadcast_server.cpp +++ b/ws/ws_broadcast_server.cpp @@ -20,12 +20,12 @@ namespace ix ix::WebSocketServer server(port, hostname); server.setTLSOptions(tlsOptions); - server.setOnConnectionCallback([&server](std::shared_ptr webSocket, - std::shared_ptr connectionState, - std::unique_ptr connectionInfo) { - auto remoteIp = connectionInfo->remoteIp; - webSocket->setOnMessageCallback([webSocket, connectionState, remoteIp, &server]( - const WebSocketMessagePtr& msg) { + server.setOnClientMessageCallback( + [&server](std::shared_ptr connectionState, + ConnectionInfo& connectionInfo, + WebSocket& webSocket, + const WebSocketMessagePtr& msg) { + auto remoteIp = connectionInfo.remoteIp; if (msg->type == ix::WebSocketMessageType::Open) { spdlog::info("New connection"); @@ -63,7 +63,7 @@ namespace ix for (auto&& client : server.getClients()) { - if (client != webSocket) + if (client.get() != &webSocket) { client->send(msg->str, msg->binary, [](int current, int total) -> bool { spdlog::info("Step {} out of {}", current, total); @@ -82,7 +82,6 @@ namespace ix } } }); - }); auto res = server.listen(); if (!res.first)