forked from keroserene/go-webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datachannel.hpp
41 lines (31 loc) · 1.11 KB
/
datachannel.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef _DATACHANNEL_H_
#define _DATACHANNEL_H_
#include <_cgo_export.h> // Allow calling certain Go functions.
#include "webrtc/api/peerconnectioninterface.h"
#include "webrtc/api/datachannelinterface.h"
typedef rtc::scoped_refptr<webrtc::DataChannelInterface> DataChannel;
class CGoDataChannelObserver
: public webrtc::DataChannelObserver,
public rtc::RefCountInterface {
public:
explicit CGoDataChannelObserver(DataChannel dc) : dc(dc) {
assert(NULL != dc);
}
void OnStateChange() {
cgoChannelOnStateChange(goChannel);
}
void OnMessage(const webrtc::DataBuffer& buffer) {
auto data = reinterpret_cast<void*>(const_cast<unsigned char*>(
buffer.data.data()));
cgoChannelOnMessage(goChannel, data, buffer.size());
}
void OnBufferedAmountChange(uint64_t previous_amount) {
cgoChannelOnBufferedAmountChange(goChannel, previous_amount);
}
// Reference to external Go data.Channel required for callbacks.
int goChannel;
DataChannel dc;
protected:
~CGoDataChannelObserver() {}
}; // class DoDataChannelObserver
#endif // _DATACHANNEL_H