newInvite method
Creates and sends a new call invitation.
This method initiates an outgoing call to a destinationNumber (which can be
a SIP URI or a phone number).
callerName: The name to be displayed to the callee.callerNumber: The phone number or SIP URI of the caller.destinationNumber: The phone number or SIP URI to call.clientState: A custom string that can be used to store and retrieve state between applications. It is passed to the remote party.customHeaders: Optional custom SIP headers to add to the INVITE message.debug: Enables detailed logging for this specific call if set to true.
Returns a Call object representing the new outgoing call.
Implementation
Call newInvite(
String callerName,
String callerNumber,
String destinationNumber,
String clientState, {
Map<String, String> customHeaders = const {},
bool debug = false,
}) {
final Call inviteCall = _createCall()
..sessionCallerName = callerName
..sessionCallerNumber = callerNumber
..sessionDestinationNumber = destinationNumber
..sessionClientState = clientState;
customHeaders = customHeaders;
inviteCall.callId = const Uuid().v4();
final base64State = base64.encode(utf8.encode(clientState));
updateCall(inviteCall);
// Create the peer connection with debug enabled if requested
inviteCall.peerConnection =
Peer(inviteCall.txSocket, debug || _debug, this);
inviteCall.peerConnection?.invite(
callerName,
callerNumber,
destinationNumber,
base64State,
inviteCall.callId!,
inviteCall.sessid,
customHeaders,
);
if (debug) {
inviteCall.initCallMetrics();
} //play ringback tone
inviteCall.playAudio(_ringBackpath);
inviteCall.callHandler.changeState(CallState.newCall);
return inviteCall;
}