1 #ifndef OPENTERA_WEBRTC_NATIVE_CLIENT_DATA_CHANNEL_CLIENT_H
2 #define OPENTERA_WEBRTC_NATIVE_CLIENT_DATA_CHANNEL_CLIENT_H
4 #include <OpenteraWebrtcNativeClient/WebrtcClient.h>
5 #include <OpenteraWebrtcNativeClient/Utils/ClassMacro.h>
6 #include <OpenteraWebrtcNativeClient/Configurations/DataChannelConfiguration.h>
8 #include <api/data_channel_interface.h>
19 std::function<void(
const Client&)> m_onDataChannelOpened;
20 std::function<void(
const Client&)> m_onDataChannelClosed;
21 std::function<void(
const Client&,
const std::string&)> m_onDataChannelError;
22 std::function<void(
const Client&,
const uint8_t*, std::size_t)> m_onDataChannelMessageBinary;
23 std::function<void(
const Client&,
const std::string&)> m_onDataChannelMessageString;
35 bool sendTo(
const uint8_t* data, std::size_t size,
const std::vector<std::string>& ids);
36 bool sendTo(
const std::string& message,
const std::vector<std::string>& ids);
37 bool sendToAll(
const uint8_t* data, std::size_t size);
38 bool sendToAll(
const std::string& message);
44 const std::function<
void(
const Client&,
const uint8_t*, std::size_t)>& callback);
48 bool sendTo(
const webrtc::DataBuffer& buffer,
const std::vector<std::string>& ids);
49 bool sendToAll(
const webrtc::DataBuffer& buffer);
51 std::unique_ptr<PeerConnectionHandler>
52 createPeerConnectionHandler(
const std::string&
id,
const Client& peerClient,
bool isCaller)
override;
62 inline bool DataChannelClient::sendTo(
const uint8_t* data,
size_t size,
const std::vector<std::string>& ids)
64 return sendTo(webrtc::DataBuffer(rtc::CopyOnWriteBuffer(data, size),
true), ids);
73 inline bool DataChannelClient::sendTo(
const std::string& message,
const std::vector<std::string>& ids)
75 return sendTo(webrtc::DataBuffer(message), ids);
84 inline bool DataChannelClient::sendToAll(
const uint8_t* data,
size_t size)
86 return sendToAll(webrtc::DataBuffer(rtc::CopyOnWriteBuffer(data, size),
true));
94 inline bool DataChannelClient::sendToAll(
const std::string& message)
96 return sendToAll(webrtc::DataBuffer(message));
113 callSync(getInternalClientThread(), [
this, &callback]() { m_onDataChannelOpened = callback; });
130 callSync(getInternalClientThread(), [
this, &callback]() { m_onDataChannelClosed = callback; });
149 callSync(getInternalClientThread(), [
this, &callback]() { m_onDataChannelError = callback; });
167 const std::function<
void(
const Client&,
const uint8_t*, std::size_t)>& callback)
169 callSync(getInternalClientThread(), [
this, &callback]() { m_onDataChannelMessageBinary = callback; });
186 const std::function<
void(
const Client&,
const std::string&)>& callback)
188 callSync(getInternalClientThread(), [
this, &callback]() { m_onDataChannelMessageString = callback; });
Represents a peer client.
Definition: Client.h:14
Represents a client for data channel communication.
Definition: DataChannelClient.h:16
void setOnDataChannelError(const std::function< void(const Client &, const std::string &)> &callback)
Sets the callback that is called when a data channel error occurs.
Definition: DataChannelClient.h:147
DataChannelClient(SignalingServerConfiguration signalingServerConfiguration, WebrtcConfiguration webrtcConfiguration, DataChannelConfiguration dataChannelConfiguration)
Creates a data channel client with the specified configurations.
Definition: DataChannelClient.cpp:14
void setOnDataChannelMessageBinary(const std::function< void(const Client &, const uint8_t *, std::size_t)> &callback)
Sets the callback that is called when binary data are received.
Definition: DataChannelClient.h:166
void setOnDataChannelClosed(const std::function< void(const Client &)> &callback)
Sets the callback that is called when a data channel closes.
Definition: DataChannelClient.h:128
void setOnDataChannelOpened(const std::function< void(const Client &)> &callback)
Sets the callback that is called when a data channel opens.
Definition: DataChannelClient.h:111
void setOnDataChannelMessageString(const std::function< void(const Client &, const std::string &)> &callback)
Sets the callback that is called when a string message is received.
Definition: DataChannelClient.h:185
Represents a data channel configuration.
Definition: DataChannelConfiguration.h:14
Represents a signaling server configuration.
Definition: SignalingServerConfiguration.h:14
Represents the base class of DataChannelClient and StreamClient.
Definition: WebrtcClient.h:29
Represents a WebRTC peer connection configuration.
Definition: WebrtcConfiguration.h:14