|
Getting Started |
Top Previous Next |
|
The ASTA SIP Toolkit provides developers with a quick and easy way to create VOIP and Instant Message Applications that include VOIP presence support.
The ASTA SIP Toolkit provides a base class for SIP applications
Some of the features of the endpoint class include:
The easiest way to use endpoint class is to create an instance of it a and then create handlers for some of their events and to run the application to get a feel for how it all flows.
We will will review some common tasks below.
Registration
Let suppose you want to create a softphone application. The first thing to do is to make our softphone addressable i.e. make it available for calls to/from remote parties.
In the SIP world it this is done through assigning the user name a realm name. SIP addresses look like email addresses – for example sip:1573920@inphonex.com.
You can obtain such public SIP addresses from various SIP/VoIP providers – such as www.sipphone.com, www.inphonex.com, or www.FreeWorldDialup.com. You can also get them from your corporate SIP PBX if they are available.
The obtained SIP address should be assigned to the Contact property.
An example using C#
mEndPoint = new AstaSIPEndPoint(); mEndPoint.Contact = “sip:354453@proxy01.sipphone.com”;
Also you should register the name on the SIP server where you have gotten your SIP address. For this you use the Register method.
mEndPoint.Register();
Please be aware – this method is an asynchronous method and returns immediately.
You can be notified when the event is finished by one of two events – OnRegisterSuccess or OnRegisterFailed.
mEndPoint.OnRegisterSuccess += new SIPEndPoint.OnRegisterSuccessEvent(Frm_OnRegisterSuccess); mEndPoint.OnRegisterFailed += new SIPEndPoint.OnRegisterFailedEvent(Frm_OnRegisterFailed);
private void Frm_OnRegisterSuccess(string contact, int expires) { SetStatus("Ready"); }
private void Frm_OnRegisterFailed(int responseCode, string contact) { SetStatus("Failed to register"); }
Note: – don’t expect the event handler to run in the same thread as Register() call. In the current version handlers run in their own thread.
The one exception is when using the COM Version of ASTA SIP – all handlers runs in the same thread as the method that initiated them. It is done to support VB6's single –threaded architecture.
Call management
Making an outgoing call.
The next task is to make our first call.
You can initiate this through the method MakeCall
String callID = mEndPoint.MakeCall(“sip:myfriend@provider.com”);
This code will initiate the call to sip:myfriend@provider.com and returns the ID of the call.
Like the Register() method MakeCall() is asynchronous. You can get the result through the OnConnected or OnTerminatedevents.
mEndPoint.OnTerminated += new SIPEndPoint.OnTerminatedEvent(Frm_OnTerminated); mEndPoint.OnConnected += new SIPEndPoint.OnConnectedEvent(Frm_OnConnected);
private void Frm_OnTerminated(string remoteParty, string reason, int responseCode, string callToken) { SetStatus(“Call failed. Response code is “ + responseCode.ToString()); }
private void FrmIM_OnConnected(string remoteParty, string callToken) { SetStatus(“Call succeeded.”); }
Call terminating
The callToken in parameter list has the same value as returned from corresponding MakeCall and means “ID of the call”.
A Call can be terminated or cancelled (if not established yet) through the method Hangup(). The OnTerminated event will be called. But there is an exception – if the application is terminating – this event will not be called. It is done to avoid hard-to-catch threading errors.
Handling incoming calls.
How are incoming calls acknowledged? The event OnInvite is fired on an incoming call. You can handle it using methods
AcceptCall() or RejectCall(). Please see the sample code below.
mEndPoint.OnInvite += new SIPEndPoint.OnInviteEvent(Frm_OnInvite); private void FrmIM_OnInvite(string remoteParty, string callToken) { if (MessageBox.Show("Incoming call from " + remoteParty + ". Accept?", "Incoming call", MessageBoxButtons.YesNo) == DialogResult.Yes) { mEndPoint.AcceptCall(callToken); } else { mEndPoint.RejectCall(callToken); } }
Application terminating.
Please don’t forget to unregister softphone on exit. It can be done through the Unregister method. OnRegisterRemoved event will be fired when this task will be finished.
mEndPoint.OnRegisterRemoved += new SIPEndPoint.OnRegisterRemovedEvent(Frm_OnRegisterRemoved); private void FrmIM_OnRegisterRemoved(String contactName) { }
|