Presentation is loading. Please wait.

Presentation is loading. Please wait.

How to develop a VoIP softphone in C# by using OZEKI VoIP SIP SDK This presentation demonstrates the first steps concerning to how to develop a fully-functional.

Similar presentations


Presentation on theme: "How to develop a VoIP softphone in C# by using OZEKI VoIP SIP SDK This presentation demonstrates the first steps concerning to how to develop a fully-functional."— Presentation transcript:

1 How to develop a VoIP softphone in C# by using OZEKI VoIP SIP SDK This presentation demonstrates the first steps concerning to how to develop a fully-functional softphone in C# in the most simplest way - by using the previously written components of Ozeki VoIP SIP SDK. Part 1  Part 1: SIP registration Part 2: Making and receiving calls Part 3: Controlling the calls 1/15

2 What you need Windows PC.NET compatible development kit (e.g. MS Visual Studio) 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/15 Download free example source code for this project from http://voip-sip-sdk.com/p_539-sip-registration-voip.html !

3 Create a new Microsoft Visual Studio project and add VoIP components to your references 1.Open Visual Studio and create a new project by clicking on File then New project 2.As this softphone will be a simple console application, in the next window you need to select the Visual C# Console Application option 3.After you have specified a name for your new project, click on the OK button 4.To achieve and use the VoIP components of the SDK, add them to your references For this, you need to right-click on References than select the Add references option. After this, browse the SDK.dll file that can be found where the SDK has been installed to. Select the.dll and click on the OK button Having done these steps, you can find a new line at the end of the References folder: ‘VoIPSDK’. This line indicates that now you can use the tools provided by the SDK. 3/15

4 For separating the softphone from the user interface, two classes are used: 1.Softphone.cs: The implementation of the softphone goes here (including its events, methods, functions, variables) This class 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. 2.Program.cs : The class with the Main() method (this class controls the console window, interacts with the user by using a softphone object) 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. Write the code Classes 4/15

5 In the ‘using section’ you need to add some extra lines, as well as: Without these lines you would have to use the namespace information as a label for all tools of the SDK. Write the code Source code analysis using Ozeki.Network.Nat; using Ozeki.VoIP; using Ozeki.VoIP.SDK; 5/15

6 In a constructor, you also need to initialize this softphone with default parameters: You need to set the port range, indicated by the first two parameters as the minimum port's and the maximum port's number. This is the port's interval. The third parameter is the listening port. If you have any firewall rule that restricts the usable ports, you can set the usable port range here, which will be used during the calls. These are sample ports only in the example, but a softphone with these parameters can be used in the most of the cases. (If you are handling conference calls or handling a lot of lines simultaneously, you will need a wide port range.) Write the code Softphone.cs ISoftPhone softphone; // softphone object IPhoneLine phoneLine; // phoneline object softphone = SoftPhoneFactory.CreateSoftPhone(5000, 10000, 5060); Create a softphone and a phone line object from the ISoftPhone and the IPhoneLine interfaces: 6/15

7 In order to create the SIP account, set the followings: RegistrationRequired: Is the registration required or not? This field needs to be set to ‘true’, if you would like to receive incoming calls DisplayName: A name to be displayed at the called client. UserName: If an other client dials this name (number), the SIP account will be getting called AuthenticationId: An identifier to the PBX, like a login name RegisterPassword: The password that registers to the PBX. It works in pair with the authentication ID DomainHost: For example a domain name, an IP address DomainPort: Port number The last two values define the PBX address where the softphone will be registered. You will get the values of these parameters from the user, in the Program.cs file. Write the code Registration to the PBX var account = SIPAccount(registrationRequired, displayName, userName, authenticationId, registerPassword, domainHost, domainPort); 7/15

8 If you want to communicate through firewall, you need to set the right NAT Traversal method: In this example, it has been set to ‘None’. This is enough for communication on local network. An other option for the NAT Traversal method is setting it to ‘STUN’. This way, you can define the Stun server with a NatRemoteServer object by giving the server IP, the username and password to use as parameters: You can set automated detection on that IP address you would like to use. If you set the configuration to ‘None’, but you also set a NatRemoteServer object with the public IP, you will use the local address on the local network and the public on others: Write the code NAT (Network Address Translation) Traversal var natConfiguration = NatConfiguration(NatTraversalMethod.None); natConfiguration.StunServer = new NatRemoteServer(serverIP, username, password); natConfiguration.AutoDetect = true; 8/15

9 In order to communicate (and to register to the PBX) you need to create a phone line by using the previously created SIP account and the NAT Traversal setup: When the application is running, the state of the phone line can change. To follow these changes, you need to listen to this change event: When the phone line has been created, you have to call the RegisterPhoneLine() method to register the phone line to the softphone. If the registration is set to required, this method will also send the SIP REGISTER command. You only need to use the following line: Write the code PhoneLine phoneLine = softphone.CreatePhoneLine(account, natConfiguration) phoneLine.PhoneLineStateChanged += phoneLine_PhoneLineStateChanged; softphone.RegisterPhoneLine(phoneLine); 9/15

10 10/15 The phone line event can be in several states, for example: RegistrationFailed: occurs, when registration is needed, but it failed. The phone is unable to communicate through the PBX NoRegNeeded: there is no communication with the server, until the first (made) call. If you have set any invalid information during the SIP account creation, you can not even make calls. Since your softphone is not registered to the server, you can not receive any calls, even with valid SIP account RegistrationSucceeded: occurs, when registration is needed, and succeeded. The phone is able to receive and make calls RegistrationTimedOut: some PBXs define for how long a client can be registered to it. If that time is up, the state of the phone line changes to this Write the code Events

11 This class will introduce the usage of a softphone object, it handles the console events, interacts with the user and uses the opportunities provided by the Softphone class. In this example, the softphone can only register to a PBX by the values given by the user. First of all, you need to create a softphone object. You can handle everything with separated methods. These methods are communicating with each other, and making the source code more understandable and reusable. Write the code Program.cs static Softphone mySoftphone; 11/15

12 In order to initialize your softphone, you need to call an initializer method with the following lines: Call this method in the Main() method. Now, there is a new softphone available to use, and it is already following the states of the phone. You will see how to handle the states below, after you have done with the greeting and the registration process. Write the code Initialization mySoftphone = new Softphone(); mySoftphone.PhoneLineStateChanged += mySoftphone_PhoneLineStateChanged; Showing a greeting message In a few lines you can introduce the application to the user. It is preferred to say a few sentences about the features available. After your softphone has been initialized, call this method to introduce the application in the Main() method. 12/15

13 As you could see at the Softphone class, you need a configured SIP account in order to use the softphone for communication. The user needs to enter valid values to create a SIP account and to register to a PBX. This procedure can be done using such simple commands as: Write the code Creating the SIP account by the user's input and registering to a PBX Console.WriteLine(); Console.ReadLine(); 13/15

14 You are subscribed to get notified if the state of the phone line has been changed. At the mySoftphone_PhoneLineStateChanged method you can set what happens in case of each state. If the registration is failed, the SIP account details should be provided again. States for this case: or The "RegistrationFailed" state occurs, when the registration is simply unsuccessful, for example, if the user set up invalid SIP account during the registration. The "RegistrationTimedOut" state occurs, if the registration request takes too long. If the registration has succeeded or there is no need for registration, you can notify the user about that. Note, if there is no need for registration, but you could not reach the PBX (or you could, but with invalid SIP account), you will not notice that until you make your first call. The states to use: Write the code Handling of the phone line states PhoneLineState.RegistrationTimedOut PhoneLineState.RegistrationFailed PhoneLineState.RegistrationSucceeded PhoneLineState.NoRegNeeded 14/15

15 Check the 2. part of the ‘How to develop a VoIP softphone in C# by using OZEKI VoIP SIP SDK’ tutorial series and get to know how to make and receive calls using your softphone! After studying this tutorial, you need be familiar with adding VoIP components to your references and creating a Softphone class that provides a softphone object to the user usign the input setups. Now you have a console window which interacts with the user and handles your softphone with the provided opportunities. Part 1 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 15/15


Download ppt "How to develop a VoIP softphone in C# by using OZEKI VoIP SIP SDK This presentation demonstrates the first steps concerning to how to develop a fully-functional."

Similar presentations


Ads by Google