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.preferredCodecs
: Optional list of preferred audio codecs in order of preference. If any codec in the list is not supported by the platform or remote party, the system will automatically fall back to a supported codec.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 {},
List<AudioCodec>? preferredCodecs,
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,
getForceRelayCandidate(),
);
// Convert AudioCodec objects to Map format for the peer connection
List<Map<String, dynamic>>? codecMaps;
if (preferredCodecs != null && preferredCodecs.isNotEmpty) {
codecMaps = preferredCodecs.map((codec) => codec.toJson()).toList();
}
inviteCall.peerConnection?.invite(
callerName,
callerNumber,
destinationNumber,
base64State,
inviteCall.callId!,
inviteCall.sessid,
customHeaders,
preferredCodecs: codecMaps,
);
if (debug) {
inviteCall.initCallMetrics();
} //play ringback tone
inviteCall.playAudio(_ringBackpath);
inviteCall.callHandler.changeState(CallState.newCall);
return inviteCall;
}