2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
20#include "web/websocket/server/GroupsManager.h"
22#include "web/websocket/server/SubProtocol.h"
24#ifndef DOXYGEN_SHOULD_SKIP_THIS
42 group = subProtocol->getName();
45 if (subProtocol
->group != group) {
46 const std::string newChannel = subProtocol->getName() +
"/" + group;
48 groups[newChannel].insert(subProtocol);
50 if (!subProtocol
->group.empty()) {
54 subProtocol
->group = newChannel;
59 if (groups.contains(subProtocol->group)) {
60 groups[subProtocol->group].erase(subProtocol);
62 if (groups[subProtocol->group].empty()) {
63 groups.erase(subProtocol->group);
73 std::size_t messageLength,
75 if (groups.contains(group)) {
76 for (
const SubProtocol* client : groups[group]) {
77 if (client != excludedClient) {
78 client->sendMessage(message, messageLength);
85 if (groups.contains(group)) {
86 for (
const SubProtocol* client : groups[group]) {
87 if (client != excludedClient) {
88 client->sendMessage(message);
96 std::size_t messageLength,
98 if (groups.contains(group)) {
99 for (
const SubProtocol* client : groups[group]) {
100 if (client != excludedClient) {
101 client->sendMessageStart(message, messageLength);
108 sendBroadcastStart(group, message.data(), message.length(), excludedClient);
113 std::size_t messageLength,
115 if (groups.contains(group)) {
116 for (
const SubProtocol* client : groups[group]) {
117 if (client != excludedClient) {
118 client->sendMessageFrame(message, messageLength);
125 sendBroadcastFrame(group, message.data(), message.length(), excludedClient);
130 std::size_t messageLength,
132 if (groups.contains(group)) {
133 for (
const SubProtocol* client : groups[group]) {
134 if (client != excludedClient) {
135 client->sendMessageEnd(message, messageLength);
142 sendBroadcastEnd(group, message.data(), message.length(), excludedClient);
146 const std::function<
void(
const SubProtocol*)>& sendToClient,
148 if (groups.contains(group)) {
149 for (
const SubProtocol* client : groups[group]) {
150 if (client != excludedClient) {
151 sendToClient(client);
static GroupsManager * groupsManager
void sendBroadcast(const std::string &group, const char *message, std::size_t messageLength, const SubProtocol *excludedClient)
static GroupsManager * instance()
void sendBroadcastEnd(const std::string &group, const std::string &message, const SubProtocol *excludedClient)
void sendBroadcastFrame(const std::string &group, const std::string &message, const SubProtocol *excludedClient)
void sendBroadcastStart(const std::string &group, const std::string &message, const SubProtocol *excludedClient)
void forEachClient(const std::string &group, const std::function< void(const SubProtocol *)> &sendToClient, const SubProtocol *excludedClient)
void sendBroadcastStart(const std::string &group, const char *message, std::size_t messageLength, const SubProtocol *excludedClient)
void subscribe(SubProtocol *subProtocol, std::string group="")
void sendBroadcastEnd(const std::string &group, const char *message, std::size_t messageLength, const SubProtocol *excludedClient)
void sendBroadcast(const std::string &group, const std::string &message, const SubProtocol *excludedClient)
void unsubscribe(SubProtocol *subProtocol)
void sendBroadcastFrame(const std::string &group, const char *message, std::size_t messageLength, const SubProtocol *excludedClient)