@@ -488,6 +488,48 @@ void FlutterWebRTC::HandleMethodCall(
488
488
const std::string track_id = findString (params, " trackId" );
489
489
MediaStreamTrackSwitchCamera (track_id, std::move (result));
490
490
} else if (method_call.method_name ().compare (" setVolume" ) == 0 ) {
491
+ auto args = method_call.arguments ();
492
+ if (!args) {
493
+ result->Error (" Bad Arguments" , " setVolume() Null arguments received" );
494
+ return ;
495
+ }
496
+
497
+ const EncodableMap params = GetValue<EncodableMap>(*args);
498
+ const std::string trackId = findString (params, " trackId" );
499
+ const std::optional<double > volume = maybeFindDouble (params, " volume" );
500
+
501
+ if (trackId.empty ()) {
502
+ result->Error (" Bad Arguments" , " setVolume() Empty track provided" );
503
+ return ;
504
+ }
505
+
506
+ if (!volume.has_value ()) {
507
+ result->Error (" Bad Arguments" , " setVolume() No volume provided" );
508
+ return ;
509
+ }
510
+
511
+ if (volume.value () < 0 ) {
512
+ result->Error (" Bad Arguments" , " setVolume() Volume must be positive" );
513
+ return ;
514
+ }
515
+
516
+ RTCMediaTrack* track = MediaTrackForId (trackId);
517
+ if (nullptr == track) {
518
+ result->Error (" setVolume" , " setVolume() Unable to find provided track" );
519
+ return ;
520
+ }
521
+
522
+ std::string kind = track->kind ().std_string ();
523
+ if (0 != kind.compare (" audio" )) {
524
+ result->Error (" setVolume" ,
525
+ " setVolume() Only audio tracks can have volume set" );
526
+ return ;
527
+ }
528
+
529
+ auto audioTrack = static_cast <RTCAudioTrack*>(track);
530
+ audioTrack->SetVolume (volume.value ());
531
+
532
+ result->Success ();
491
533
} else if (method_call.method_name ().compare (" getLocalDescription" ) == 0 ) {
492
534
if (!method_call.arguments ()) {
493
535
result->Error (" Bad Arguments" , " Null constraints arguments received" );
0 commit comments