endCall method

void endCall(
  1. String? callID
)

Attempts to end the call identified via the callID

Implementation

void endCall(String? callID) {
  if (callId == null) {
    _logger.d("Call ID is null");
    return;
  }

  var uuid = const Uuid().v4();
  var byeDialogParams = ByeDialogParams(callId: callID ?? callId);

  var byeParams = SendByeParams(
      cause: CauseCode.USER_BUSY.name,
      causeCode: CauseCode.USER_BUSY.index + 1,
      dialogParams: byeDialogParams,
      sessid: sessid);

  var byeMessage = SendByeMessage(
      id: uuid,
      jsonrpc: JsonRPCConstant.jsonrpc,
      method: SocketMethod.BYE,
      params: byeParams);

  String jsonByeMessage = jsonEncode(byeMessage);

  if (_txClient.gatewayState != GatewayState.REGED) {
    _logger
        .d("Session end gateway not  registered ${_txClient.gatewayState}");
    return;
  } else {
    _logger.d("Session end peer connection null");
  }

  txSocket.send(jsonByeMessage);
  if (peerConnection != null) {
    peerConnection?.closeSession();
  } else {
    _logger.d("Session end peer connection null");
  }
  stopAudio();
  callHandler.changeState(CallState.done, this);
  callEnded();
  _txClient.calls.remove(callId);
  var message = TelnyxMessage(
      socketMethod: SocketMethod.BYE,
      message: ReceivedMessage(method: "telnyx_rtc.bye"));
  _txClient.onSocketMessageReceived.call(message);
}