Windows Phone 8 introduced support for building VOIP applications, which allows users to make audio and video calls utilizing their data connection.
This built-in support allows VOIP applications to seamlessly integrate with the native phone dialer, giving the same user experience to the user as a classic phone call (but with advanced capabilities like video).
A VOIP application running on Windows Phone involves an UI component, which runs as a foreground process, while the call management components run as a background process. The UI component is responsible for the user experience a Windows phone user interacts with.
The call management components involve the following four background agents (see http://www.codeguru.com/csharp/.net/wp7/article.php/c19821/Using-Background-Agents-in-your-Windows-Phone-75-Mango-Apps.htm for an earlier article, which covers background agents):
- VoipHttpIncomingCallTask – This agent is launched when an incoming call notification is received on the application’s Push channel.
- VoipForegroundLifetimeAgent – This agent keeps the background process alive while the UI application is active.
- VoipCallInProgressAgent – This agent runs as long as there is at least one active VOIP call.
- VoipKeepAliveTask – This agent is launched periodically and it allows the VOIP application to communicate with its cloud service.
Windows Phone 8 supports directly invoking a VOIP core library written in native code to maximize code reuse and reduce time for application development. The Windows Phone runtime assembly can call native APIs for audio and video processing. On the server side, there is a VOIP cloud service, which sends push notifications to the client.
Building a VOIP Application
Windows Phone 8 applications that desire to use VOIP functionality need to declare ID_CAP_VOIP in the application manifest file. This declared capability allows the application to access VOIP calling services.
In addition, VOIP applications must meet a few additional requirements:
- All VOIP calls must use the VoipCallCoordinator class, which resides in the Windows.Phone.Networking.Voip namespace. This class allows an application to manage VOIP calls.
- For incoming VOIP calls, only raw push notifications of type 4 must be used.
- The ringtone of the VOIP application must be 5-120 seconds, and the VOIP ringtone file size must be less than 2 MB.
To build a VOIP application on Windows Phone 8, you will need:
1. Assembly that represents the UI for the VOIP application. (#a)
2. Assembly that handles background agents, which will be used by the VOIP application. (#b)
3. Windows Phone Runtime assembly (#c) for the call management functions. This assembly will do the heavy lifting of connecting and managing VOIP calls.
4. To build a native core assembly (#d). Typically, application developers might already have one if they have a VOIP application on a competing platform, and can reuse this.
5. To build a VOIP cloud service (#e) if one does not exist already.
Here are the steps of building the application.
1. Create a push notification channel when the application (#a) is launched the first time. Check out http://www.codeguru.com/csharp/.net/wp7/article.php/c19769/Overview-of-Push-Notifications-Support-on-Windows-Phone.htm for an earlier article.
2. When the cloud VOIP service (#e) sends a push notification (for an incoming call), the Windows Phone operating system calls the VoidHttpIncomingCallTask agent (#b).
3. The VoidHttpIncomingCallTask agent (#b) loads the Windows Phone runtime assembly (#c) and calls its function, which handles the event raised when an incoming call is received. This function should then signal the application UI (#a) with the identity of the caller.
4. In the Windows.Phone.Networking.Voip.VoipPhoneCall.AnswerRequested event (in case the call is accepted), the application should connect to the cloud VOIP service to signal that the call has been started. To notify the Windows Phone Operating System that the VOIP call is active, the application needs to call Windows.Phone.Networking.Voip.VoipPhoneCall.NotifyCallActive().
In case the call is not accepted, write code in the Windows.Phone.Networking.Voip.VoipPhoneCall.RejectRequested event handler to notify the user and cleanup the resources.
5. If the call is connected (Windows.Phone.Networking.Voip.VoipPhoneCall.NotifyCallActive() has been called), the Windows Phone operating system will launch VoipCallInProgressAgent (#b) to allow resources to be allocated to VOIP audio and video processing. When the VoipCallInProgressAgent is called, the application should register the handlers for events like call is placed on hold, caller is muted, callee is muted, etc.
6. When the user terminates the call, the UI (#a) calls the Windows Phone Runtime assembly (#c) to call Windows.Phone.Networking.Voip.VoipPhoneCall.NotifyCallEnded() to end the call and free up resources.
7. For outgoing calls, when the UI application (#a) is launched, the VoipForegroundLifetimeAgent (#b) should be invoked, which loads the Windows Phone runtime assembly.
8. When the Windows Phone runtime assembly is successfully loaded and call request is made, the Windows Phone runtime assembly calls Windows.Phone.Networking.Voip.VoipCallCoordinator,RequestNewOutgoingCall(), which returns a VoipPhoneCall object. Register handlers for the AnswerRequested and RejectRequested events and when the call is connected, make a call to Windows.Phone.Networking.Voip.VoipPhoneCall.NotifyCallActive() to let the operating system know that the call is connected.
9. When the call is terminated in the UI (#a), the Windows Phone Runtime assembly (#c) to call Windows.Phone.Networking.Voip.VoipPhoneCall.NotifyCallEnded() to end the call and free up resources.
Implementing a VOIP application will be covered in a future topic.
In this article, we learned the fundamentals of building a VOIP application on Windows Phone 8. I hope you have found this information useful.
About the author
Vipul Patel is a Program Manager currently working at Amazon Corporation. He has formerly worked at Microsoft in the Lync team and in the .NET team (in the Base Class libraries and the Debugging and Profiling team). He can be reached at email@example.com