0

I use the flutter_webrtc package to handle VOIP calls. I ran the example project from their GitHub and it worked fine until I separated the logic from the UI. Now I'm facing this problem,

Incoming calls are expected to be in CallStateEnum.INITIATION mode at the beginning, which is the behavior I am experiencing, but it is likely to go to CallStateEnum.CONNECTING state after that, instead it goes directly to CallStateEnum.PROGRESS state.

Here is the function that I have overridden from SipUaHelperListener.

  @override
  void callStateChanged(sip.Call newCall, sip.CallState state) {
    call = newCall;

    if (state.state == sip.CallStateEnum.CALL_INITIATION) {

      Navigator.pushNamed(context, '/callscreen');
      startTimer();
      initRenderers();
      update();
    } else {

      if (state.state == sip.CallStateEnum.HOLD ||
          state.state == sip.CallStateEnum.UNHOLD) {
        hold.value = state.state == sip.CallStateEnum.HOLD;
        holdOriginator = state.originator;
        return;
      }

      if (state.state == sip.CallStateEnum.MUTED) {
        if (state.audio!) audioMuted.value = true;
        if (state.video!) videoMuted.value = true;
        return;
      }

      if (state.state == sip.CallStateEnum.UNMUTED) {
        if (state.audio!) audioMuted.value = false;
        if (state.video!) videoMuted.value = false;

        return;
      }

      if (state.state != sip.CallStateEnum.STREAM) {
        callState = state.state;
      }

      switch (state.state) {
        case sip.CallStateEnum.STREAM:
          handelStreams(state);
          break;
        case sip.CallStateEnum.ENDED:
        case sip.CallStateEnum.FAILED:
          backToDialPad();
          break;
        case sip.CallStateEnum.UNMUTED:
        case sip.CallStateEnum.MUTED:
        case sip.CallStateEnum.CONNECTING:
        case sip.CallStateEnum.PROGRESS:
        case sip.CallStateEnum.ACCEPTED:
        case sip.CallStateEnum.CONFIRMED:
        case sip.CallStateEnum.HOLD:
        case sip.CallStateEnum.UNHOLD:
        case sip.CallStateEnum.NONE:
        case sip.CallStateEnum.CALL_INITIATION:
        case sip.CallStateEnum.REFER:
          break;
      }
      update();
    }
  }

This function was being used on two screens (Dialpad & CallScreen) separately, that implemented SIPHelperListner. I have separated the logic by this condition.

if (state.state == sip.CallStateEnum.CALL_INITIATION) {

// User is currently on Dialpad
// Push the Call Screen

}else {

// User is on CallScreen
// Handle call state changes.

}
Siddharth Mehra
  • 1,691
  • 1
  • 9
  • 32
ASAD HAMEED
  • 2,296
  • 1
  • 20
  • 36

0 Answers0