Dealing with REFERs

From reSIProcate
Revision as of 08:11, 9 December 2005 by Sgodin (talk | contribs) (Moved all REFER content to one page)
Jump to navigation Jump to search

Initiating REFER Requests

Use the InviteSession::refer(referTo) API - this will cause a REFER message to be sent to the other party.


Handling REFER Requests

If an application wishes to process the REFER request it should use the dum->makeInviteSessionFromRefer API.

Sample Code:

void onRefer(InviteSessionHandle is, ServerSubscriptionHandle ss, const SipMessage& msg)
{
   ss->send(ss->accept(202));  // accept refer request
   SdpContents sdpOffer;
   ...  // build sdpOffer
   dum->send(dum->makeInviteSessionFromRefer(msg, ss, sdpOffer);  // send new INVITE
}


Handling REFER with Replaces Requests

Sending REFER with Replaces

Use the InviteSession::refer(referTo, sessionToReplace) API - this will cause a REFER message to be sent to the other party that contains a Replaces header specifying the session to replace.

Receiving REFER with Replaces

For an application standpoint, this is handled in the exact same manner as receiving a REFER request without a Replaces header. If an application wishes to process the REFER request it should use the dum->makeInviteSessionFromRefer API.

Sample Code:

void onRefer(InviteSessionHandle is, ServerSubscriptionHandle ss, const SipMessage& msg)
{
   ss->send(ss->accept(202));  // accept refer request
   SdpContents sdpOffer;
   ...  // build sdpOffer
   dum->send(dum->makeInviteSessionFromRefer(msg, ss, sdpOffer);  // send new INVITE
} 

Receiving INVITE with Replaces

When you receive an INVITE request (via the onNewSession callback) you may wish to see if a Replace header is present, in order for this new INVITE session to "take over" an existing session. In order to accomplish this you can use a convience function on the DialogUsageManager called findInviteSession which takes a Replaces header as an argument.

Sample Code:

void onNewSession(ServerInviteSession sis, InviteSession::OfferAnswerType oat, const SipMessage& msg)
{
   if(msg->exits(h_Replaces))
   {
      pair<InviteSessionHandle, int> presult;
      presult = dum->findInviteSession(msg->header(h_Replaces));
      if(presult != InviteSessionHandle::NotValid())
      {
          ... // Do stuff in app to swap contexts
          Presult.first->end(); // end original session
      }
   }
   ...continue with app specific stuff
}