mirror of
https://github.com/mii443/libdatachannel.git
synced 2025-08-22 15:15:28 +00:00
Introduced onOpen() callback in client example
This commit is contained in:
@ -222,9 +222,14 @@ shared_ptr<PeerConnection> 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<binary, string> data) {
|
||||
dc->onMessage([id](variant<binary, string> data) {
|
||||
if (holds_alternative<string>(data))
|
||||
cout << "Message from " << id << " received: " << get<string>(data) << endl;
|
||||
else
|
||||
@ -232,8 +237,6 @@ shared_ptr<PeerConnection> createPeerConnection(const Configuration &config,
|
||||
<< " received, size=" << get<binary>(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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user