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;
  }

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

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

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

  final 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);
  final message = TelnyxMessage(
    socketMethod: SocketMethod.bye,
    message: ReceivedMessage(method: 'telnyx_rtc.bye'),
  );
  _txClient.onSocketMessageReceived.call(message);
}