@@ -27,7 +27,7 @@ class WHIP {
27
27
final String url;
28
28
String ? resourceURL;
29
29
Map <String , String >? headers = {};
30
- String videoCodec = 'vp8' ;
30
+ String ? videoCodec;
31
31
WHIP ({required this .url, this .headers});
32
32
33
33
Future <void > initlize (
@@ -40,7 +40,11 @@ class WHIP {
40
40
this .videoCodec = videoCodec.toLowerCase ();
41
41
}
42
42
this .mode = mode;
43
- pc = await createPeerConnection ({'sdpSemantics' : 'unified-plan' });
43
+ pc = await createPeerConnection ({
44
+ 'sdpSemantics' : 'unified-plan' ,
45
+ 'bundlePolicy' : 'max-bundle' ,
46
+ 'rtcpMuxPolicy' : 'require' ,
47
+ });
44
48
pc? .onIceCandidate = onicecandidate;
45
49
pc? .onIceConnectionState = (state) {
46
50
print ('state: ${state .toString ()}' );
@@ -49,12 +53,24 @@ class WHIP {
49
53
switch (mode) {
50
54
case WhipMode .kSend:
51
55
stream? .getTracks ().forEach ((track) async {
52
- await pc! .addTrack (track, stream);
56
+ await pc! .addTransceiver (
57
+ track: track,
58
+ kind: track.kind == 'audio'
59
+ ? RTCRtpMediaType .RTCRtpMediaTypeAudio
60
+ : RTCRtpMediaType .RTCRtpMediaTypeVideo ,
61
+ init: RTCRtpTransceiverInit (
62
+ direction: TransceiverDirection .SendOnly , streams: [stream]));
53
63
});
54
64
break ;
55
65
case WhipMode .kReceive:
56
- await pc! .addTransceiver (kind: RTCRtpMediaType .RTCRtpMediaTypeAudio );
57
- await pc! .addTransceiver (kind: RTCRtpMediaType .RTCRtpMediaTypeVideo );
66
+ await pc! .addTransceiver (
67
+ kind: RTCRtpMediaType .RTCRtpMediaTypeAudio ,
68
+ init: RTCRtpTransceiverInit (
69
+ direction: TransceiverDirection .RecvOnly ));
70
+ await pc! .addTransceiver (
71
+ kind: RTCRtpMediaType .RTCRtpMediaTypeVideo ,
72
+ init: RTCRtpTransceiverInit (
73
+ direction: TransceiverDirection .RecvOnly ));
58
74
break ;
59
75
}
60
76
log.debug ('Initlize whip connection: mode = $mode , stream = ${stream ?.id }' );
@@ -64,8 +80,12 @@ class WHIP {
64
80
Future <void > connect () async {
65
81
try {
66
82
setState (WhipState .kConnecting);
67
- var desc = await pc! .createOffer ();
68
- setPreferredCodec (desc, videoCodec: videoCodec);
83
+ var desc = await pc! .createOffer ({});
84
+
85
+ if (mode == WhipMode .kSend && videoCodec != null ) {
86
+ setPreferredCodec (desc, videoCodec: videoCodec! );
87
+ }
88
+
69
89
await pc! .setLocalDescription (desc);
70
90
71
91
var offer = await pc! .getLocalDescription ();
0 commit comments