@@ -41,7 +41,10 @@ class WHIP {
41
41
}
42
42
this .mode = mode;
43
43
pc = await createPeerConnection ({'sdpSemantics' : 'unified-plan' });
44
- pc! .onIceCandidate = onicecandidate;
44
+ pc? .onIceCandidate = onicecandidate;
45
+ pc? .onIceConnectionState = (state) {
46
+ print ('state: ${state .toString ()}' );
47
+ };
45
48
pc! .onTrack = (RTCTrackEvent event) => onTrack? .call (event);
46
49
switch (mode) {
47
50
case WhipMode .kSend:
@@ -64,14 +67,16 @@ class WHIP {
64
67
var desc = await pc! .createOffer ();
65
68
setPreferredCodec (desc, videoCodec: videoCodec);
66
69
await pc! .setLocalDescription (desc);
70
+
67
71
var offer = await pc! .getLocalDescription ();
68
- log.debug ('Sending offer: $offer ' );
72
+ final sdp = offer! .sdp;
73
+ log.debug ('Sending offer: $sdp ' );
69
74
var respose = await httpPost (Uri .parse (url),
70
75
headers: {
71
76
'Content-Type' : 'application/sdp' ,
72
77
if (headers != null ) ...headers!
73
78
},
74
- body: offer ! . sdp);
79
+ body: sdp);
75
80
76
81
if (respose.statusCode != 200 && respose.statusCode != 201 ) {
77
82
throw Exception ('Failed to send offer: ${respose .statusCode }' );
@@ -115,10 +120,7 @@ class WHIP {
115
120
}
116
121
117
122
void onicecandidate (RTCIceCandidate ? candidate) async {
118
- if (resourceURL == null ) {
119
- throw 'Resource url not found!' ;
120
- }
121
- if (candidate == null ) {
123
+ if (candidate == null || resourceURL == null ) {
122
124
return ;
123
125
}
124
126
log.debug ('Sending candidate: ${candidate .toMap ().toString ()}' );
0 commit comments