-
Notifications
You must be signed in to change notification settings - Fork 76
/
datachannel.hpp
44 lines (34 loc) · 1.15 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
42
43
44
#ifndef _DATACHANNEL_H_
#define _DATACHANNEL_H_
#include <_cgo_export.h> // Allow calling certain Go functions.
#include <assert.h>
#include "api/peerconnectioninterface.h"
#include "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() {
dc->UnregisterObserver();
}
}; // class DoDataChannelObserver
#endif // _DATACHANNEL_H