I got Dialog undefined. Console Error after Transfer Call using SIP-0.21.2.min.js and
function transferCall(session, transferTarget) {
console.log("Initiating call transfer...");
console.log("Session", session);
console.log("Transfer Target", transferTarget);
console.log("Session state:", session.state);
try {
// Ensure the session is in an established state
if (session.state !== SIP.SessionState.Established) {
console.error("Session is not in an established state.");
return;
}
// Ensure the session has a valid dialog
if (!session._dialog) {
console.error("Session dialog is undefined.");
return;
}
// Create the target URI for the transfer target
const targetURI = SIP.UserAgent.makeURI(`sip:${transferTarget}@${session.remoteIdentity.uri.host}`);
console.log("Target URI:", targetURI);
if (!targetURI) {
console.error("Invalid target URI.");
return;
}
// Create a new session for the transfer target
const newSession = new SIP.Inviter(session.userAgent, targetURI);
// Options for the refer request
const transferOptions = {
requestDelegate: {
onAccept: function() {
console.log("Transfer accepted.");
// Handle successful transfer
resumeCall(session);
},
onReject: function(response) {
console.error(`Transfer rejected: ${response.message.reasonPhrase}`);
}
}
};
// Send the REFER request to transfer the call
console.log("Sending REFER request to transfer call...");
session.refer(newSession, transferOptions).catch(function(error) {
console.error("Failed to send REFER:", error);
});
} catch (error) {
console.error("Exception during call transfer:", error);
}
}
This is my Transfer function and here session is equal to invitation and transferTarget is Agent Extension number. Need Fix of Dialog undefined error and here I connected Asterisk Server. Here resumeCall(session); is ToggleHoldButtun Function after connected to other agent call will be resumed.