finding Replaces header Call-ID in dialog map
See original GitHub issueI am trying to figure the best way to find the Call-ID in the srf._dialogs
map when I get an INVITE or REFER with a Replaces header. In an attended transfer scenario, the endpoint sets up a dialog with the transferTarget and then sends a REFER to the transferee with a Replaces
header containing the Call-ID of the dialog with the transferTarget.
In this scenario, drachtio is acting as a B2BUA between all the endpoints (and media is just peer to peer for now), so I actually need to find the dialog of the other side of the call (UAS dialog if received on the UAC side, and vice versa).
I have a gist of a latter diagram and sip trace of a successful attended transfer through drachtio here.
I am wondering if there is a better way to find the dialog associated with the Call-ID in the replaces header than what I am doing below by looping through the map of dialogs:
// referParams has all the parsed elements of a refer header
findReplacesDialog(srf._dialogs, referParams.replacesCallId);
const findReplacesDialog = (dialogMap, replacesCallId) => {
var replacesDialog;
const dialogCallIds = Array.from(dialogMap.keys());
debug('Dialog Keys');
debug(dialogCallIds);
dialogCallIds.every((dialog, i) => {
const currentDialog = dialogMap.get(dialog);
const previousDialog = dialogMap.get(dialogCallIds[i-1]);
const nextDialog = dialogMap.get(dialogCallIds[i+1]);
debug('replacesCallId');
debug(replacesCallId);
debug('currentDialog.sip.callId');
debug(currentDialog.sip.callId);
if (nextDialog) { debug('nextDialog.sip.callId'); debug(nextDialog.sip.callId); }
if (previousDialog) { debug('previousDialog.sip.callId'); debug(previousDialog.sip.callId) }
if (currentDialog.sip.callId == replacesCallId) {
debug(`FOUND A MATCH!!!! ${dialog}`);
// drachtio adds ';uas' when it's the UAS of the dialog
if (dialog == `${replacesCallId};uas`) {
debug('UAS dialog: setting repalcesDialog equal to previousDialog');
replacesDialog = previousDialog;
return false;
} else {
debug('UAC dialog: setting repalcesDialog equal to nextDialog');
replacesDialog = nextDialog;
return false;
}
}
return true;
});
return replacesDialog;
};
Issue Analytics
- State:
- Created 4 years ago
- Comments:8
Top GitHub Comments
OK, just published drachtio-srf@4.4.7, which adds
Note: these functions require drachtio-server@v0.8.2-rc2 or above (currently the head of the ‘develop’ branch), which formats dialog ids as {Call-ID};from-tag={from-tag}.
additionally, if you have a reference to a dialog (uas or uac) that was created by
Srf#createB2BUA
thendialog.other
will be a reference to the paired dialog.So handling attended transfer should be a matter of:
findDialogByCallIDAndFromTag(callId, tag)
to retrieve the dialog being replaced, thenDialog#modify
ondialog.other
.I’ll leave this issue open for now until you have time to test.
I was able to test. This worked great! Thank you so much