flutter-webrtc / dart-sip-ua

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

How to merge or mix 3 audiostream like conference call? #481

Open dmagic99 opened 1 month ago

Yukari-Tryhard commented 1 month ago

So first of all you need a media server to mix audio. For example Asterisk. And then you first make a call to Asterisk then refer all related call to that specific call

Yukari-Tryhard commented 1 month ago

This is my working code. Assume you have extension for Conference inside your asterisk:

  @override
  void callStateChanged(Call call, CallState callState) {
    callProvider.addCurrentCall(call);
    callProvider.updateCurrentCall(call);
    if (callState.state == CallStateEnum.CALL_INITIATION) {
      if (call.remote_identity!.contains("Conference")) {
        callProvider.addConferenceCall(call);
        // Refer each held call to the conference call
        for (var heldCall in callProvider.heldCalls) {
          heldCall.refer(call.remote_identity!);
        }
        callProvider.clearHeldCalls();
        callProvider.lastActiveCall!.refer(call.remote_identity!);
      }
      _navigationService.navigateTo(Routes.call, {"call": call});
    }
    if (callState.state == CallStateEnum.ENDED) {
      callProvider.removeCurrentCall(call);
    }
  }
dmagic99 commented 1 month ago

Could you please clarify what callProvider is? Is it part of this library? Could you explain it briefly

Tin-Primas commented 1 month ago

Could you please clarify what callProvider is? Is it part of this library? Could you explain it briefly

callProvider is just like it name imply. It's a provider for holding data and sharing it between components. Here is an example code:

class CallProvider with ChangeNotifier {
  List<Call> heldCalls = [];
  List<Call> currentCalls = [];
  Set<String> heldCallIds = {};
  Set<String> currentCallIds = {};
  String lastDialedNumber = '';
  Call? lastActiveCall;
  Call? activeConferenceCall;
  }