IntroductionIn this tutorial you'll see how easy it is to build a simple Softphone with SipekSdk. This document guides you from a scratch to a working Softphone. In less than an hour you will create the SIP application with one you can call and talk with anyone in the SIP world. If you don't believe, read on... The complete Instant Softphone source code is available at SVN repository http://sipekapps.googlecode.com/svn/trunk/Example_InstantSoftphone as a Example_InstantSoftphone project. Development Environment SetupThe SipekSdk project is built with Visual Studio 2005 for C#. You can use any newer version of VS by converting project files appropriately. Create new Project
A project window is opened with Form1 design view. Create Simple GUI FormNow we'll create a simple GUI for our Softphone. The look&feel is up to you. But for simple Softphone you'll need at least the controls below:
An example form: Using SipekSdkFirst prepare the project for SipekSdk. Import SipekSdk Library
Do the same with pjsipDll.dll !!! Get the pjsipDll.dll from SVN or build your own from sources. I encourage you to build the libraries on your own. For instructions see the relevant pages (SipekSdk, pjsipWrapper) Prepare Configuration SettingsImplement Config InterfaceBefore you start using SipekSdk it's necessary to set up the configuration data. The SipekSdk contains abstract configuration classes. In order to provide your configuration data you need to implement these classes and fill it with values. After that you just need to inject the classes into SipekSdk. The main configuration interface class is IConfiguratorInterface. The other configuration interface is IAccount used for SIP account configuration. SipekSdk actualy supports more than 1 account. In this tutorial we'll use only one. How to implement configuration for SipekSdk:
Now we have two interfaces implemented. Next step is to integrate account instance into PhoneConfig class and implement some settings.
In AccountConfig set the properties (hard coded) to connect to your SIP server. In the second part of tutorial I'll show you how to use .Net Application Settings mechanism to persist configuration settings. Define Callbacks/EventsNow as we finish with configuration settings we can proceed to defining callbacks. Callbacks are methods called from SIP stack informing us about Call state, Registration state etc,... SipekSdk defines Events listening to state updates of call or registration or about some other SIP event. Before we register callbacks, let's do some coding in Form1.cs:
Two (Callback) methods CallManager_CallStateRefresh and Instance_AccountStateChanged are ready for implementation. We'll do that later.
In next tutorial I'll show you how to implement Media (playing tones) and Timer handling. For now we'll let SipekSdk to handle (ie. ignore) it. Are you ready to do SipekSdk initialization?
Finish GUIImplement CallbacksHow to avoid synchronization problem: Fortunately there is another solution that solves this problem. See more details in advanced tutorial... The implementation of callbacks: private void OnRegistrationUpdate(int accountId, int accState) { textBoxRegState.Text = accState.ToString(); } private void OnStateUpdate(int sessionId) { textBoxCallState.Text = CallManager.getCall(sessionId).StateId.ToString(); } private void buttonMakeCall_Click(object sender, EventArgs e) } Be sure to enter correct configuration settings in PhoneConfig and Account properties, especially:
If you have SIP server up and running the Softphone should register. Check the "Registration status" value. 200 is OK Now you are ready to make your 1st call. Enter number or sip uri into textBoxDial and check the call status. For more advanced feature see advanced tutorial... Enjoy!!! |
