advertisement

#3 How to develop a VoIP softphone in C# by using Ozeki VoIP SIP SDK - Part 3

61 %
39 %
advertisement
Information about #3 How to develop a VoIP softphone in C# by using Ozeki VoIP SIP SDK -...

Published on March 14, 2014

Author: ozekiltd

Source: slideshare.net

Description

Dig deeper: http://www.voip-sip-sdk.com

This presentation shows the final steps concerning to how to build a fully-functional softphone in C# in the most simplest way - by using the previously written components of Ozeki VoIP SIP SDK. Having done the SIP registration and after conducting some test calls, let’s learn how to control your calls.

This is the 3. part of the 3-part great softphone development turtorial series. For further example projects and demo software visit the official website of Ozeki VoIP SIP SDK: http://voip-sip-sdk.com/p_332-voip-sdk-developers-guide-voip.html

Get more information: http://www.voip-sip-sdk.com
... or ask for help via e-mail: info@voip-sip-sdk.com
advertisement

How to develop a VoIP softphone in C# by using OZEKI VoIP SIP SDK This presentation shows the final steps concerning to how to build a fully-functional softphone in C# in the most simplest way - by using the previously written components of Ozeki VoIP SIP SDK. Having done the SIP registration and after conducting some test calls, let’s learn how to control your calls. Part 1: SIP registration Part 2: Making and receiving calls Part 3: Controlling the calls 1/14

Previously on this series Windows PC .NET compatible development kit installed on your PC .NET Framework installed on your PC Ozeki VoIP SIP SDK installed on your PC In order to build a VoIP softphone application in C# you will need the followings: 2/14 Download free example source code for this project (Part 1) from http://voip-sip-sdk.com/p_539-sip-registration-voip.html! After studying the previous 2 tutorials, you need to be fully familiar with using VoIP development components. Now you have a console window which interacts with the user and handles your softphone with the provided opportunities. You also know how to make and accept calls, and how to handle the call states and events. Download free example source code for this project (Part 2) from http://voip-sip-sdk.com/p_540-making-and-accepting-calls-voip.html! Download free example source code for this project (Part 3) from http://voip-sip-sdk.com/p_541-controlling-the-call-voip.html!

Source code analysis 3/14 Classes: • Softphone.cs is used to introduce how to declare, define and initialize a softphone, how to handle some of the Ozeki VoIP SIP SDK's events and how to use some features. So the aim is creating a ‘telephone software’, which has the same functionalities (or much more), as an ordinary phone’s. • You will use the Program.cs class to create a new softphone, so you can use the functions and listen to the events placed here.

When the call state is ‘LocalHeld’, the devices stop. Please note that if the call is taken off from hold, then you will enter into the ‘InCall’ state (again), so you need to start the devices there as well. Since the call can enter into the InCall state several times during a call, this is the reason why you attach the media handlers at the ‘Answered’ state. Please also note that the hold function notifies the other client to do not send data (in this case: do not talk into the microphone). In the most of the cases you do not want your voice to be heard either by to other party while you are holding the call, so you do not need the microphone or the speaker either. This is the reason for stopping them. Handling the call states mediaReceiver.AttachToCall(call); mediaSender.AttachToCall(call); There are some changes in the method which handles the call states. You attach the media handlers to the call object only once, so the ideal state to do this is the ‘Answered’ state, since it occurs only once per a call. 4/14

In this method, first you need to check that you have an active communication or not (is the call object ‘null’ or not), then you can start to handle the ‘holding’ / ’unholding’ process. If there is an active call and you call this method, there can be two cases: if the call is in not in ‘LocalHeld’ state, that means you haven't put the call on hold yet, and you can put the call on hold. If the call is in the ‘LocalHeld’ state, it indicates that you are already holding the call, so you can take the call off hold. You can do it by checking the call state and using the commands introduced below: Putting the call on hold and taking off from hold (1) call.HoldCall(); call.UnholdCall(); 5/14

But the simplest way to do this: As you can see, with the ToggleHold() method you do not even need to check the call state or store/check that the call is held or not. This method does the work for you. Putting the call on hold and taking off from hold (2) 6/14 if (call != null) { call.ToggleHold(); }

This is a really simple function. If the call exists, you only need to use the HangUp() method of the call object, and then to set the call object to ‘null’. Hanging up the call if (call != null) { call.HangUp(); call = null; } 7/14

Transferring the call (1) This is another very simple function, when you would like to transfer the call to an other destination, to an other client. There are several ways to do this, for example you can transfer the call with one of the BlindTransfer() or the AttendedTransfer() methods, or you can forward the call with the ForwardCall() one. • BlindTransfer(): using this during a call, the third party's phone starts to ring, like it would be dialled first, and not yours. When the third party answers the call, you step out from that. • AttendedTransfer(): using this during a call, you can notify the third party about the incoming call by calling it, and then redirect the call. • ForwardCall(): without answering the call, you can set the softphone to redirect the incoming call to an other destination. (For example: if you leave your office, you can forward the calls incoming to your office phone to your mobile phone.) 8/14

This example uses the BlindTransfer() method for this purpose. As you can see, first you check, if the destination has been set, and of course you can only transfer an existing call. After that, you use the BlindTransfer() method of the call object with the other client's number as a string parameter. Transferring the call (2) if (call != null && !string.IsNullOrEmpty(destination)) { call.BlindTransfer(destination); } 9/14

Program.cs This class will introduce the usage of a softphone object, handles the console events, interacts with the user, and uses the opportunities provided by the Softphone class. In this example, the softphone asks the user for a number to dial, and for a number to transfer the call to. The application guides you through the following steps: • Asks the user for two numbers (to call, and to transfer to) • Makes a call and when it is answered, puts that on hold, immediately • Waits for a key to be pressed to take the call off hold • Takes the call off hold, than hangs up the call immediately • Waits for a key to be pressed, than it redials the last called number • When the call is answered, it will be transferred to the other number given by the user. You can handle everything with separated methods. These methods communicate with each other and make the source code more understandable and reusable. Transferring the call (3) 10/14

Three new string variables have been used in this example. You need to initialize them to empty: The numberToCall is the phone number needs to be dialed first and redialed when it is needed. The call will be transferred to the numberToTransfer phone number. The exampleSteps variable will guide you through the call events. You need this variable, since you would enter into the same states several times and that would cause troubles in the guiding. You can also follow the user interacts (it is mostly automatized this time) with the help of this variable by writing the user events to the console. Initialization numberToTransfer = string.Empty; numberToCall = string.Empty; exampleSteps = string.Empty; 11/14

This method asks the user about two phone numbers (as strings). By storing the last called number (and the last incoming one) and then using that number again to dial without setting the called number manually, you’ve just created a feature functioning just like the redial button of the traditional telephones. You need to call this method after the welcoming messages. When both numbers are given, the numberToCall will be dialed immediately, and the exampleSteps variable is being set to ‘Calling’, so in the console window you can see; the user is calling the number, and the call state is changing, too. Asking the user about phone numbers 12/14

The user can be guided through states by only pressing a few keys. For the guide you need to handle the actual state of the call and the value of the exampleSteps variable: • The first case, when the call is in ‘Answered’ state and the value of the variable is ‘Calling’. In this case, the softphone puts the call on hold, and sets the variable to ‘Held’. • The call enters to ‘LocalHeld’ state, sets the variable to ‘Unheld’ and takes the call off hold, when the user presses a button. • The call enters to ‘InCall’state (again), and if the variable is ‘Unheld’, changes that to ‘HangedUp’ and hangs up the call. • The call enters to ‘Completed’ state, and if the variable is ‘HangedUp’, changes that to ‘Redialed’, and waits for a key to be pressed. If that happens, it redials the last called number. • When the other phone answers the call, it enters into ‘Answered’ state, and if the variable is "Redialed", the call will be transferred to the other phone number immediately. The value of the variable is also changed to ‘Transfering’. By writing the exampleSteps value of the variable to the console, you can see what would happen, if a real user would use these functions, actions. Handling the call and the guide states 13/14

It was the last part of the ‘How to develop a VoIP softphone in C# by using OZEKI VoIP SIP SDK’ tutorial series. Find further example projects and demo software at the official website of Ozeki VoIP SIP SDK: http://voip-sip-sdk.com/p_332-voip-sdk-developers-guide-voip.html After studying this tutorial, you need be familiar with controlling calls by redialing, call holding, call transferring etc. However, these are only basic functions. You can write your own ones. You can handle more calls simultaneously, play audio files into the call as voice, you can create message recorder, IVR menu system, etc. Thank you for your attention! For more information please visit www.voip-sip-sdk.com or send an e-mail to info@voip-sip-sdk.com 14/14

Add a comment

Related pages

#3 How to develop a softphone by using Ozeki VoIP SIP SDK ...

... a softphone by using Ozeki VoIP SIP SDK. ... VoIP SIP SDK. This tutorial is the 3. part ... SIP PBX in C# by using Ozeki VoIP SIP SDK ...
Read more

#3 How to develop a SIP PBX in C# by using Ozeki VoIP SIP ...

... using Ozeki VoIP SIP SDK. This guide is the 3. part ... develop a SIP PBX in C# by using ... using Ozeki VoIP SIP SDK - Tutorial Part ...
Read more

Ozeki C# SIP Stack - VoIP SIP Softphone

Quick start guide Get started on using Ozeki VoIP SDK ... Course 1 How to develop a softphone in C#. ... using Ozeki VoIP SIP SDK. What is a softphone.
Read more

Ozeki C# VoIP SDK - A SIP SDK for software developers

A high performance VoIP SIP SDK for .Net developers to develop VoIP SIP ... on using Ozeki VoIP SDK ... to develop a softphone in C#.
Read more

How to build a VoIP softphone in C# - Documentation

In this section you can get to know: How to add reference to Ozeki VoIP SIP SDK in Microsoft Visual Studio ; How to create a console application softphone ...
Read more

Top 10 VoIP IP telephony interview questions and answers ...

Top 10 VoIP IP telephony interview questions and ... Ozeki VoIP SIP SDK has been used ... briefly how to create a softphone using C#.NET. (All parts of ...
Read more

Ozeki VoIP SIP SDK - Free download and software reviews ...

From VOIP SIP SDK: Ozeki .Net SDK for C# SIP WPF softphone development to make/receive VoIP calls. It supports basic telephony functions like make/receive ...
Read more