-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathobservers.h
More file actions
120 lines (90 loc) · 3.81 KB
/
observers.h
File metadata and controls
120 lines (90 loc) · 3.81 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// No-op implementations of most webrtc::*Observer methods. For the ones we do care about in the
// example, we supply a callback in the constructor.
//
// Author: brian@brkho.com
#ifndef WEBRTC_EXAMPLE_SERVER_OBSERVERS_H
#define WEBRTC_EXAMPLE_SERVER_OBSERVERS_H
#include <webrtc/api/peerconnectioninterface.h>
#include <functional>
// PeerConnection events.
class PeerConnectionObserver : public webrtc::PeerConnectionObserver {
public:
// Constructor taking a few callbacks.
PeerConnectionObserver(std::function<void(webrtc::DataChannelInterface*)> on_data_channel,
std::function<void(const webrtc::IceCandidateInterface*)> on_ice_candidate) :
on_data_channel{on_data_channel}, on_ice_candidate{on_ice_candidate} {}
// Override signaling change.
void OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState /* new_state */) {}
// Override adding a stream.
void OnAddStream(webrtc::MediaStreamInterface* /* stream */) {}
// Override removing a stream.
void OnRemoveStream(webrtc::MediaStreamInterface* /* stream */) {}
// Override data channel change.
void OnDataChannel(webrtc::DataChannelInterface* channel) {
on_data_channel(channel);
}
// Override renegotiation.
void OnRenegotiationNeeded() {}
// Override ICE connection change.
void OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState /* new_state */) {}
// Override ICE gathering change.
void OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState /* new_state */) {}
// Override ICE candidate.
void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
on_ice_candidate(candidate);
}
private:
std::function<void(webrtc::DataChannelInterface*)> on_data_channel;
std::function<void(const webrtc::IceCandidateInterface*)> on_ice_candidate;
};
// DataChannel events.
class DataChannelObserver : public webrtc::DataChannelObserver {
public:
// Constructor taking a callback.
DataChannelObserver(std::function<void(const webrtc::DataBuffer&)> on_message) :
on_message{on_message} {}
// Change in state of the Data Channel.
void OnStateChange() {}
// Message received.
void OnMessage(const webrtc::DataBuffer& buffer) {
on_message(buffer);
}
// Buffered amount change.
void OnBufferedAmountChange(uint64_t /* previous_amount */) {}
private:
std::function<void(const webrtc::DataBuffer&)> on_message;
};
// Create SessionDescription events.
class CreateSessionDescriptionObserver : public webrtc::CreateSessionDescriptionObserver {
public:
// Constructor taking a callback.
CreateSessionDescriptionObserver(std::function<void(webrtc::SessionDescriptionInterface*)>
on_success) : on_success{on_success} {}
// Successfully created a session description.
void OnSuccess(webrtc::SessionDescriptionInterface* desc) {
on_success(desc);
}
// Failure to create a session description.
void OnFailure(const std::string& /* error */) {}
// Unimplemented virtual function.
int AddRef() const { return 0; }
// Unimplemented virtual function.
int Release() const { return 0; }
private:
std::function<void(webrtc::SessionDescriptionInterface*)> on_success;
};
// Set SessionDescription events.
class SetSessionDescriptionObserver : public webrtc::SetSessionDescriptionObserver {
public:
// Default constructor.
SetSessionDescriptionObserver() {}
// Successfully set a session description.
void OnSuccess() {}
// Failure to set a sesion description.
void OnFailure(const std::string& /* error */) {}
// Unimplemented virtual function.
int AddRef() const { return 0; }
// Unimplemented virtual function.
int Release() const { return 0; }
};
#endif // WEBRTC_EXAMPLE_SERVER_OBSERVERS_H