flutter-webrtc / dart-sip-ua

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

"Call initialize before setting the stream" #413

Open Vinayak006 opened 11 months ago

Vinayak006 commented 11 months ago

Describe the bug When I make a call, I get the error "Call initialize before setting the stream". I am using the asterisk test server.

To Reproduce Steps to reproduce the behaviour:

  1. Make a call

Expected behaviour A call must be created and a connection must be established.

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

abdulrahumanea commented 9 months ago

getting same error. any solution?

emosto commented 8 months ago

I can confirm this behavior. It happens often, but not always. It seems to be usually appearing the first time the app is started after other apps are being used, or the first time user agrees with the permissions. Smells to me like a race condition, but I'm not expert in the code.

Will be more than glad to help debug the issue and fix it, because it is definitely a show stopper for the project I am working.

turbobuilt commented 3 months ago

Ok, I figured out the problem. Technically, this isn't a bug. When you use RTCVideoRenderer, you have to call and await initialize(). So you can't just make it in the render function, it has to be created before, and it has to be initialized and awaite before use:

// create temp variable while initializng
var tempRenderer = RTCVideoRenderer()
await tempRenderer.initialize()
tempRenderer!.srcObject = ...
// now set your real item
renderer = tempRenderer;
// setstate, etc

Then in your render function

if(renderer == null)
return Container()

so you don't errors before it's ready

kritika6785 commented 3 months ago
 void _handelStreams(CallState event) async {
    MediaStream? stream = event.stream;
    if (event.originator == 'local') {
      if (_localRenderer != null) {
        await _localRenderer!.initialize();
        _localRenderer!.srcObject = stream;
      }
      _localStream = stream;
      if (!kIsWeb && !WebRTC.platformIsDesktop) {

        stream?.getAudioTracks().first.enableSpeakerphone(false);
      }
    }
    if (event.originator == 'remote') {
      if (_remoteRenderer != null) {
        await _remoteRenderer!.initialize();
        _remoteRenderer!.srcObject = stream;
      }
      _remoteStream = stream;
    }
    setState(() {
      _resizeLocalVideo();
    });
  }

instead of initializing the _localRenderer and _remoteRenderer in _initRenderers() , do initialize it after the stream has been intialized.

TetrixGauss commented 2 months ago

Thank you @turbobuilt !! You did it!