UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
room.cpp
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2021 CESNET, z. s. p. o.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, is permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * 3. Neither the name of CESNET nor the names of its contributors may be
21 * used to endorse or promote products derived from this software without
22 * specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
26 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
28 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37#include <functional>
38#include <iostream>
39#include "room.hpp"
40
41Room::Room(std::string name) : name(std::move(name)) { }
42
43void Room::addClient(std::shared_ptr<Client>&& client){
44 assert(!isFull());
45
46 Client *clientPtr = client.get();
47
48 for(auto& [c, _] : clients){
49 c->sendMsg(clientPtr->getClientName());
50 c->sendMsg(clientPtr->getSdpDesc());
51
52 clientPtr->sendMsg(c->getClientName());
53 clientPtr->sendMsg(c->getSdpDesc());
54 for(const auto& candidate : c->getCandidates()){
55 clientPtr->sendMsg(candidate);
56 }
57 }
58
59 clients.insert({clientPtr, std::move(client)});
60
61 using namespace std::placeholders;
62 clientPtr->readCandidate(
63 std::bind(&Room::onClientCandidate, shared_from_this(), _1, _2));
64
65}
66
70 std::cerr << "Unexpected disconnect";
72 std::cerr << "Client is disconnecting";
73 else
74 std::cerr << "Error reading candidate";
75
76 std::cerr << ", removing client " << client.getClientName() << std::endl;
77
78 clients.erase(&client);
79 return;
80 }
81
82 std::cout << "Client candidate recieved" << std::endl;
83
84 for(auto& [c, cu] : clients){
85 if(&client == c)
86 continue;
87
88 c->sendMsg(client.getCandidates().back());
89 }
90
91 using namespace std::placeholders;
92 client.readCandidate(
93 std::bind(&Room::onClientCandidate, shared_from_this(), _1, _2));
94}
void sendMsg(std::string_view msg)
Definition client.cpp:123
void readCandidate(CompletionCallback onComplete)
Definition client.cpp:93
std::string getSdpDesc()
Definition client.hpp:63
std::string getClientName()
Definition client.hpp:61
bool isFull() const
Definition room.hpp:51
std::map< Client *, std::shared_ptr< Client > > clients
Definition room.hpp:58
void addClient(std::shared_ptr< Client > &&client)
Definition room.cpp:43
void onClientCandidate(Client &client, CompletionStatus success)
Definition room.cpp:67
Room(std::string name)
Definition room.cpp:41
const char * name
Definition settings.cpp:193
CompletionStatus