flutter-webrtc / dart-sip-ua

A dart-lang version of the SIP UA stack.
MIT License
339 stars 270 forks source link

When Camera turned OFF and then ON, remote device not get reflected with new stream. #434

Open Vinayak006 opened 7 months ago

Vinayak006 commented 7 months ago

Problem So when the camera is turned off, and then turned on, I don't know how to reflect changes to remote device

Code

Future<void> handleCamera(final String callId) async {
    // stopping the stream here
        localStream
            ?.getVideoTracks()
            .forEach((final MediaStreamTrack element) async {
          await element.stop();
        });
        call.mute(false);
        localVideoRenderer?.srcObject = null;
        localStream = null;
     // starting the stream
        final MediaStream mediaStream = await navigator.mediaDevices
            .getUserMedia(<String, dynamic>{"video": true});
        localVideoRenderer?.srcObject = mediaStream;
        localStream = mediaStream;
        call.unmute(false);
      }
  }

Expected behavior When local camera is turned on, remote device should get the new mediastream

System Infomation() Flutter SDK Version: 3.19.5 sip_ua Version: 0.5.8

VadimKV44 commented 7 months ago

I am not showing the remote video stream. I'm calling the mobile application from the site, the site has its own video stream and the video stream of the phone, but the video stream from the site is not displayed on the phone, can you tell me what the problem is? MediaStream? remoteStream; RTCVideoRenderer? remoteRenderer = RTCVideoRenderer(); EdgeInsetsGeometry? localVideoMargin; double? localVideoHeight; double? localVideoWidth; String error = ''; bool showError = false;

Call? _call; Call? get getCall => _call; set setCall(Call call) => _call = call;

void initRender(CallState callState) async { try { await remoteRenderer!.initialize(); _handelStreams(callState); } catch (e) { logger.e(e); showError = true; error = 'Ошибка при обработке видео'; } notifyListeners(); }

void _handelStreams(CallState event) async { MediaStream? stream = event.stream;

logger.i('MYLOGGER STATE: ${event.state}');
logger.i('MYLOGGER VIDEO: ${event.video}');
if (event.originator == 'remote') {
  try {
    logger.i('MYLOGGER STREAM: ${stream}');
    remoteRenderer?.srcObject = stream;
    remoteStream = stream;
    if (remoteStream!.getVideoTracks().isEmpty) {
      showError = true;
      error = 'Не найден видеопоток';
    }
  } catch (e) {
    logger.e(e);
    showError = true;
    error = 'Ошибка при обработке видео';
  }
}
notifyListeners();

}

Vinayak006 commented 7 months ago

You need call the "_handleStreams()" function in 'callStateChanged()' funtion, not inside the 'initRenderers()' @VadimKV44

VadimKV44 commented 6 months ago

@Vinayak006 I did as you said, but it didn't help. When making a video call, after accepting the call, there is also a black screen instead of a video, but the call itself ends after a few seconds. As I understood it in the video codec, flutter_webrtc has the V8 codec by default, and I receive a video stream in H264 format. I have been looking for a long time to change it, but I have not found it, please tell me if there is such a possibility at all?