@@ -27,7 +27,7 @@ class WHIP {
2727 final  String  url;
2828 String ?  resourceURL;
2929 Map <String , String >?  headers =  {};
30-  String  videoCodec= 'vp8' ;
30+  String ?  videoCodec;
3131 WHIP ({required  this .url, this .headers});
3232
3333 Future <void > initlize (
@@ -40,7 +40,11 @@ class WHIP {
4040 this .videoCodec =  videoCodec.toLowerCase ();
4141 }
4242 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+  });
4448 pc? .onIceCandidate =  onicecandidate;
4549 pc? .onIceConnectionState =  (state) {
4650 print ('state: ${state .toString ()}' );
@@ -49,12 +53,24 @@ class WHIP {
4953 switch  (mode) {
5054 case  WhipMode .kSend: 
5155 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]));
5363 });
5464 break ;
5565 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 ));
5874 break ;
5975 }
6076 log.debug ('Initlize whip connection: mode = $mode , stream = ${stream ?.id }' );
@@ -64,8 +80,12 @@ class WHIP {
6480 Future <void > connect () async  {
6581 try  {
6682 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+ 6989 await  pc! .setLocalDescription (desc);
7090
7191 var  offer =  await  pc! .getLocalDescription ();
0 commit comments