How to transfer an incoming call using blind transfer?

download Download: blind-transfer.zip

This example demonstrates how to implement blind transfer functionality into your softphone. To use this example, you need to have Ozeki VoIP SIP SDK installed, and a reference to ozeki.dll should be added to your visual studio project. It's also recommended to visit the SIP INVITE article before you begin to study how to perform blind transfer.

transferring an incoming call with blind transfer after the call has been accepted
Figure 1 - Transferring an incoming call with blind transfer, after the call has been accepted

What is the blind transfer? When is it needed?

When the called user is not the desired end-point for a communication, for example in case of a call center, the call is transferred to another VoIP client. This transfer can be made by intentionally choosing a callee (attended call transfer) or by using blind transfer. Blind transfer means that the call will be transferred to a randomly chosen end-point, basically the first available agent (Figure 1).

The call transfer can be done automatically by a call center server application or it can be coordinated by a human operator. In case of a blind transfer the first option is the most usual.

How to blind transfer an incoming call using C#?

The whole softphone functionality and the initialization is the same as in the case of any softphone application. The only change is the call is transferring to the another number. You can see that blind transferring a call only means that you specify the number you transfer the call to and call the transfer method of the call object.

During the transfer the call state will be Transferring and when the transfer is successful, the softphone exits the call and the other two parties can communicate with each other.

As for the remote party, during the transfer, it is set to hold and it gets back to the call when the transfer is completed - in that case the communication will be continued with the third party - or when the transfer cannot be done - in that case the communication will be set back with the original communication peer.

Any other part of the softphone is exactly the same as in the case of a simple softphone, you can use any of the previously written softphone examples for this purpose and extend it with the transfer function.

Blind transfer example in C#?

using System;
using Ozeki.VoIP;

namespace Blind_transfer
{
    class Program
    {
        static ISoftPhone softphone;   // softphone object
        static IPhoneLine phoneLine;   // phoneline object
        static IPhoneCall call;

        private static void Main(string[] args)
        {
            // Create a softphone object with RTP port range 5000-10000
            softphone = SoftPhoneFactory.CreateSoftPhone(5000, 10000);

            // SIP account registration data, (supplied by your VoIP service provider)
            var registrationRequired = true;
            var userName = "858";
            var displayName = "858";
            var authenticationId = "858";
            var registerPassword = "858";
            var domainHost = "192.168.115.100";
            var domainPort = 5060;

            var account = new SIPAccount(registrationRequired, displayName, userName, authenticationId, registerPassword, domainHost, domainPort);

            // Send SIP regitration request
            RegisterAccount(account);

            // Prevents the termination of the application
            Console.ReadLine();
        }

        static void RegisterAccount(SIPAccount account)
        {
            try
            {
                phoneLine = softphone.CreatePhoneLine(account);
                phoneLine.RegistrationStateChanged += line_RegStateChanged;
                softphone.RegisterPhoneLine(phoneLine);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error during SIP registration: " + ex);
            }
        }

        static void line_RegStateChanged(object sender, RegistrationStateChangedArgs e)
        {
            if (e.State == RegState.NotRegistered || e.State == RegState.Error)
                Console.WriteLine("Registration failed!");

            if (e.State == RegState.RegistrationSucceeded)
            {
                Console.WriteLine("Registration succeeded - Online!");
                CreateCall();
            }
        }
  
        static void CreateCall()  
        {  
            var numberToDial = "853";  
            call = softphone.CreateCallObject(phoneLine, numberToDial);  
            call.CallStateChanged += call_CallStateChanged;  
            call.Start();
        }

        static void call_CallStateChanged(object sender, CallStateChangedArgs e)  
        {  
            Console.WriteLine("Call state: {0}.", e.State); 

             if (e.State == CallState.Answered)
             {
                 call.BlindTransfer("895");  
             }
        }  
    }  
}

Communication through the network

After the call has been established between two parties, the blindtransfer can begin. The transfer is done with REFER and NOTIFY SIP requests and the 202 Accepted sip message.
REFER sip request utilizes the Refer-To Header field to pass contact information such as URI INFO provided in the request, and the 202 Accepted message indicates that the request has been accepted for processing, but the processing has not been completed yet.
Sip NOTIFY message informs the subscriber of the state of the resource.
The following whireshark logs are introducing the SIP messages made after the call has been accepted, and the ACK message has been sent:

Step 1: The REFER request is being sent to the other party to notify that about the transfer intent (UDP message, Softphone -> PBX)

REFER sip:1001@192.168.112.215:5060 SIP/2.0
Via: SIP/2.0/UDP 192.168.112.215:7712;branch=z9hG4bK3a079c4d-dc1d-4cfc-ae5a-
79cf9b5aaf99;rport
To: <sip:1001@192.168.112.215>;tag=wethuuar
From: "1000"<sip:1000@192.168.112.215>;tag=ylduydlc
CSeq: 3 REFER
Call-ID: hblklpuqsrpyxcrpmytbmdojhljegvgtoxklnhovsicypvicya
Max-Forwards: 70
Contact: <sip:1000@192.168.112.215:7712>
User-Agent: Ozeki VoIP SIP SDK v10.1.8
Content-Length: 0
Refer-To: <sip:1003@192.168.112.215>
Referred-By: "1000"<sip:1000@192.168.112.215>

Step 2: The PBX indicates with sip 202 Accepted message that the client has accepted the request (UDP message, PBX -> Softphone).

SIP/2.0 202 Accepted
Via: SIP/2.0/UDP 192.168.112.215:7712;branch=z9hG4bK42a77cd5-9546-49e9-a97a-
15d1f9e940b7;rport=7712;
received=192.168.112.215
From: "1000"<sip:1000@192.168.112.215>;tag=ylduydlc
Call-ID: hblklpuqsrpyxcrpmytbmdojhljegvgtoxklnhovsicypvicya
CSeq: 4 REFER
To: <sip:1001@192.168.112.215>;tag=wethuuar
User-Agent: Ozeki Phone System XE v5.3.1
Content-Length: 0
Expires: 200

Step 3: The PBX indicates that the client has sent the NOTIFY request (UDP message, PBX -> Softphone)

NOTIFY sip:1000@192.168.112.215:7712 SIP/2.0
Via: SIP/2.0/UDP 192.168.112.215:5060;branch=z9hG4bKd96ca108-5b6c-4a50-a003-
1ebccc5954be;rport
To: "1000"<sip:1000@192.168.112.215>;tag=ylduydlc
From: <sip:1001@192.168.112.215>;tag=wethuuar
CSeq: 2 NOTIFY
Call-ID: hblklpuqsrpyxcrpmytbmdojhljegvgtoxklnhovsicypvicya
Max-Forwards: 70
Contact: <sip:1000@192.168.112.215:7712>
User-Agent: Ozeki Phone System XE v5.3.1
Event: refer
Subscription-State: terminated;reason=noresource
Content-Type: message/sipfrag
Content-Length: 14

SIP/2.0 200 OK

Step 4: The softphone sends a 200 OK message to indicate that the request was successful (UDP message, Softphone -> PBX

SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.112.215:5060;branch=z9hG4bKd96ca108-5b6c-4a50-a003-
1ebccc5954be;rport=5060;
received=192.168.112.215
From: <sip:1001@192.168.112.215>;tag=wethuuar
Call-ID: hblklpuqsrpyxcrpmytbmdojhljegvgtoxklnhovsicypvicya
CSeq: 2 NOTIFY
To: "1000"<sip:1000@192.168.112.215>;tag=ylduydlc
User-Agent: Ozeki VoIP SIP SDK v10.1.8
Content-Length: 0

Step 5: The softphone steps out from the call by sending the BYE request via the PBX (UDP message, Softphone -> PBX)

BYE sip:1000@192.168.112.215:7712 SIP/2.0
Via: SIP/2.0/UDP 192.168.112.215:5060;branch=z9hG4bKb1c869fc-3e2b-4aef-ab65-
39b9d41a9bb4;rport
To: "1000"<sip:1000@192.168.112.215>;tag=ylduydlc
From: <sip:1001@192.168.112.215>;tag=wethuuar
CSeq: 3 BYE
Call-ID: hblklpuqsrpyxcrpmytbmdojhljegvgtoxklnhovsicypvicya
Max-Forwards: 70
Contact: <sip:1000@192.168.112.215:7712;rinstance=873e493fa244d94b>
User-Agent: Ozeki Phone System XE v5.3.1
Content-Length: 0

Step 6: The other party sends the 200 OK message via the PBX to the softphone (UDP message, PBX -> Softphone)

SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.112.215:5060;branch=z9hG4bKb1c869fc-3e2b-4aef-ab65-
39b9d41a9bb4;rport=5060;
received=192.168.112.215
From: <sip:1001@192.168.112.215>;tag=wethuuar
Call-ID: hblklpuqsrpyxcrpmytbmdojhljegvgtoxklnhovsicypvicya
CSeq: 3 BYE
To: "1000"<sip:1000@192.168.112.215>;tag=ylduydlc
User-Agent: Ozeki VoIP SIP SDK v10.1.8
Content-Length: 0

Related Pages

More information