initCall method

Future<void> initCall(
  1. CallSession call
)

init a peer call from group calls.

Implementation

Future<void> initCall(CallSession call) async {
  final opponentMemberId = call.opponentDeviceId;

  if (opponentMemberId == null) {
    throw Exception('Cannot init call without user id');
  }

  call.onCallStateChanged.stream.listen(((event) async {
    await onCallStateChanged(call, event);
  }));

  call.onCallReplaced.stream.listen((CallSession newCall) async {
    await replaceCall(call, newCall);
  });

  call.onCallStreamsChanged.stream.listen((call) async {
    await call.tryRemoveStopedStreams();
    await onStreamsChanged(call);
  });

  call.onCallHangupNotifierForGroupCalls.stream.listen((event) async {
    await onCallHangup(call);
  });

  call.onStreamAdd.stream.listen((stream) {
    if (!stream.isLocal()) {
      onStreamAdd.add(stream);
    }
  });

  call.onStreamRemoved.stream.listen((stream) {
    if (!stream.isLocal()) {
      onStreamRemoved.add(stream);
    }
  });
}