question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

finding Replaces header Call-ID in dialog map

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
davehortoncommented, May 9, 2019

OK, just published drachtio-srf@4.4.7, which adds

findDialogById(stackDialogId), and
findDialogByCallIDAndFromTag(callId, tag)

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 then dialog.other will be a reference to the paired dialog.

So handling attended transfer should be a matter of:

  • parsing the Refer-To header (I think I need to add a utility function somewhere to make that easier, probably in drachtio-sip), then
  • calling findDialogByCallIDAndFromTag(callId, tag) to retrieve the dialog being replaced, then
  • reinviting the paired dialog by calling Dialog#modify on dialog.other.

I’ll leave this issue open for now until you have time to test.

0reactions
byoungdalecommented, May 14, 2019

I was able to test. This worked great! Thank you so much

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding the SIP Replaces Header
This INVITE contains a Replaces header with the retrieved Call-ID, To tag, and From tag. Ellen's parked call will be replaced by the...
Read more >
The Session Inititation Protocol (SIP) "Replaces" Header
The UAC places the Call-ID, to-tag, and from-tag information for the target dialog in a single Replaces header field and sends the new...
Read more >
RFC 3261 SIP: Session Initiation Protocol - IETF
A valid SIP request formulated by a UAC MUST, at a minimum, contain the following header fields: To, From, CSeq, Call-ID, Max-Forwards, and...
Read more >
Windows 7 Dialog Boxes (Design basics) - Win32 apps
Dialog boxes consist of a title bar (to identify the command, feature, ... Open files; Save files; Open folders; Find or replace text ......
Read more >
React Query 3: A Guide to Fetching and Managing Data
Need to fetch data in React? Learn about React Query, an excellent server state management library for simplifying your data-fetching needs.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found