-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef MS_RTC_PLUGIN_HPP | ||
#define MS_RTC_PLUGIN_HPP | ||
|
||
class Worker; | ||
|
||
namespace RTC | ||
{ | ||
class Plugin | ||
{ | ||
public: | ||
virtual ~Plugin() = default; | ||
}; | ||
} // namespace RTC | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -375,6 +375,32 @@ namespace Utils | |
} | ||
} | ||
}; | ||
|
||
template <typename... Args> | ||
class Event | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ggarber
Author
Owner
|
||
{ | ||
public: | ||
// Typedef for the function signature. | ||
typedef std::function<void(Args...)> Listener; | ||
void operator()(Args... args) const | ||
{ | ||
for (auto& listener : this->listeners) | ||
{ | ||
listener(args...); | ||
} | ||
} | ||
void operator+=(const Listener& listener) | ||
{ | ||
this->listeners.push_back(listener); | ||
} | ||
void operator-=(const Listener& listener) | ||
{ | ||
std::remove(listeners.begin(), listeners.end(), listener); | ||
} | ||
private: | ||
std::vector<Listener> listeners; | ||
}; | ||
|
||
} // namespace Utils | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,6 +165,7 @@ common_sources = [ | |
'src/RTC/RTCP/XR.cpp', | ||
'src/RTC/RTCP/XrDelaySinceLastRr.cpp', | ||
'src/RTC/RTCP/XrReceiverReferenceTime.cpp', | ||
'plugins/DataPing/Plugin.cpp' | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ggarber
Author
Owner
|
||
] | ||
|
||
cpp = meson.get_compiler('cpp') | ||
|
@@ -264,7 +265,7 @@ libmediasoup_worker = library( | |
install_tag: 'libmediasoup-worker', | ||
dependencies: dependencies, | ||
sources: common_sources, | ||
include_directories: include_directories('include'), | ||
include_directories: include_directories('include', 'plugins'), | ||
cpp_args: cpp_args, | ||
link_whole: link_whole, | ||
) | ||
|
@@ -276,7 +277,7 @@ executable( | |
install_tag: 'mediasoup-worker', | ||
dependencies: dependencies, | ||
sources: common_sources + ['src/main.cpp'], | ||
include_directories: include_directories('include'), | ||
include_directories: include_directories('include', 'plugins'), | ||
cpp_args: cpp_args + ['-DMS_EXECUTABLE'], | ||
) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "Plugin.hpp" | ||
|
||
#include <iostream> | ||
|
||
#include "Worker.hpp" | ||
#include "RTC/Router.hpp" | ||
#include "RTC/DataProducer.hpp" | ||
#include "RTC/DataConsumer.hpp" | ||
|
||
DataPingPlugin::DataPingPlugin(Worker* worker) | ||
{ | ||
worker->RouterCreated += [&](RTC::Router* router) | ||
{ | ||
std::cerr << "RouterCreated" << std::endl; | ||
|
||
router->TransportCreated += [&](RTC::Transport* transport) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ggarber
Author
Owner
|
||
{ | ||
std::cerr << "TransportCreated" << std::endl; | ||
|
||
transport->DataProducerCreated += [&](RTC::DataProducer* producer) | ||
{ | ||
producer->Data += [&](uint32_t id, const uint8_t* data, size_t len) | ||
{ | ||
auto isPing = len == 4 && std::string((const char*)data, len) == "ping"; | ||
if (!isPing) | ||
{ | ||
return; | ||
} | ||
for (auto [ consumerTransport, consumer ] : this->consumers) | ||
{ | ||
if (consumerTransport == transport && | ||
consumer->GetSctpStreamParameters().streamId == producer->GetSctpStreamParameters().streamId) | ||
{ | ||
consumer->SendMessage(id, data, len); | ||
} | ||
} | ||
// TBD: Implement support to stop processing of this message. | ||
// return false; | ||
}; | ||
}; | ||
|
||
transport->DataConsumerCreated += [&](RTC::DataConsumer* dataConsumer) | ||
{ | ||
this->consumers.push_back({ transport, dataConsumer }); | ||
}; | ||
|
||
transport->DataConsumerClosed += [&](RTC::DataConsumer* dataConsumer) | ||
{ | ||
for (auto it = this->consumers.begin(); it != this->consumers.end(); ++it) | ||
{ | ||
if (it->dataConsumer == dataConsumer) | ||
{ | ||
this->consumers.erase(it); | ||
break; | ||
} | ||
} | ||
}; | ||
|
||
}; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include "RTC/Plugin.hpp" | ||
#include "RTC/Transport.hpp" | ||
#include "RTC/DataConsumer.hpp" | ||
|
||
#include <vector> | ||
|
||
class DataPingPlugin: public RTC::Plugin | ||
{ | ||
public: | ||
DataPingPlugin(Worker* worker); | ||
|
||
private: | ||
struct ConsumerInfo | ||
{ | ||
RTC::Transport* transport; | ||
RTC::DataConsumer* dataConsumer; | ||
}; | ||
std::vector<ConsumerInfo> consumers; | ||
}; | ||
|
||
// RTC::Plugin* CreatePlugin(Worker* worker); |
I don't think this template/class should be defined in
Utils.hpp
.