@@ -16,7 +16,11 @@ namespace nabto {
16
16
17
17
WebrtcConnectionPtr WebrtcConnection::create (SignalingStreamPtr sigStream, NabtoDevicePtr device, std::vector<struct TurnServer >& turnServers, EventQueuePtr queue, TrackEventCallback trackCb, CheckAccessCallback accessCb, DatachannelEventCallback datachannelCb)
18
18
{
19
- return std::make_shared<WebrtcConnection>(sigStream, device, turnServers, queue, trackCb, accessCb, datachannelCb);
19
+ auto ptr = std::make_shared<WebrtcConnection>(sigStream, device, turnServers, queue, trackCb, accessCb, datachannelCb);
20
+ if (ptr) {
21
+ ptr->init ();
22
+ }
23
+ return ptr;
20
24
}
21
25
22
26
WebrtcConnection::WebrtcConnection (SignalingStreamPtr sigStream, NabtoDevicePtr device, std::vector<struct TurnServer >& turnServers, EventQueuePtr queue, TrackEventCallback trackCb, CheckAccessCallback accessCb, DatachannelEventCallback datachannelCb)
@@ -32,6 +36,11 @@ WebrtcConnection::~WebrtcConnection()
32
36
}
33
37
}
34
38
39
+ void WebrtcConnection::init ()
40
+ {
41
+ createPeerConnection ();
42
+ }
43
+
35
44
void WebrtcConnection::stop ()
36
45
{
37
46
if (pc_) {
@@ -69,9 +78,14 @@ void WebrtcConnection::handleCandidate(rtc::Candidate cand)
69
78
void WebrtcConnection::handleDescription (rtc::Description desc)
70
79
{
71
80
NPLOGD << " Got Description: " << desc;
72
- if (!pc_) {
73
- createPeerConnection ();
81
+ auto ice = desc.iceOptions ();
82
+ canTrickle_ = false ;
83
+ for (auto & i : ice) {
84
+ if (i == " trickle" ) {
85
+ canTrickle_ = true ;
86
+ }
74
87
}
88
+
75
89
try {
76
90
// TODO: remove metadata from v2 but maybe keep for v1
77
91
nlohmann::json metadata;
@@ -84,9 +98,6 @@ void WebrtcConnection::handleDescription(rtc::Description desc)
84
98
85
99
void WebrtcConnection::handleOfferAnswer (const std::string& data, const nlohmann::json& metadata) {
86
100
NPLOGD << " Got Offer/Answer: " << data;
87
- if (!pc_) {
88
- createPeerConnection ();
89
- }
90
101
try {
91
102
nlohmann::json sdp = nlohmann::json::parse (data);
92
103
rtc::Description remDesc (sdp[" sdp" ].get <std::string>(), sdp[" type" ].get <std::string>());
@@ -348,9 +359,6 @@ NabtoDeviceConnectionRef WebrtcConnection::getConnectionRef() {
348
359
349
360
void WebrtcConnection::createTracks (const std::vector<MediaTrackPtr>& tracks)
350
361
{
351
- if (!pc_) {
352
- createPeerConnection ();
353
- }
354
362
for (auto t : tracks) {
355
363
auto sdp = t->getSdp ();
356
364
rtc::Description::Media media (sdp);
0 commit comments