From bbbc8ca4e6de394f71b81152eaca5fd47b3a8f96 Mon Sep 17 00:00:00 2001 From: Paul-Louis Ageneau Date: Wed, 14 Apr 2021 21:54:42 +0200 Subject: [PATCH] Introduced onOpen() callback in client example --- examples/client/main.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/client/main.cpp b/examples/client/main.cpp index 78af56c..854a038 100644 --- a/examples/client/main.cpp +++ b/examples/client/main.cpp @@ -222,9 +222,14 @@ shared_ptr createPeerConnection(const Configuration &config, cout << "DataChannel from " << id << " received with label \"" << dc->label() << "\"" << endl; + dc->onOpen([wdc = make_weak_ptr(dc)]() { + if (auto dc = wdc.lock()) + dc->send("Hello from " + localId); + }); + dc->onClosed([id]() { cout << "DataChannel from " << id << " closed" << endl; }); - dc->onMessage([id, wdc = make_weak_ptr(dc)](variant data) { + dc->onMessage([id](variant data) { if (holds_alternative(data)) cout << "Message from " << id << " received: " << get(data) << endl; else @@ -232,8 +237,6 @@ shared_ptr createPeerConnection(const Configuration &config, << " received, size=" << get(data).size() << endl; }); - dc->send("Hello from " + localId); - dataChannelMap.emplace(id, dc); }); @@ -251,4 +254,3 @@ string randomId(size_t length) { generate(id.begin(), id.end(), [&]() { return characters.at(dist(rng)); }); return id; } -