TaCode Tuesdays: How to Develop a Cloud-Based Conference Call Mobile Application

Posted by Alex Misevski on December 6, 2016

Welcome back to TaCode Tuesdays! This is the only place you can find snippets of code for use in your very own text/voice apps, along with a weekly dose of taco puns. I’m a developer here at Zang and not only am I a big fan of tacos (if that wasn’t already apparent), I’m also a fan of open source. My goal is to share a new app idea each week that you're free to use “as is” or modify and use as the basis for your next app.

In the last few weeks, I detailed how you can detect and minimize the threat of fraud in your voice and SMS apps—you can get the free code here, and as always, if you’d like to learn how to get started on Zang, take a look at our very first post.

Let’s Taco 'Bout The App!

 

Almost everyone brings their devices to work – in fact 87 percent of us do, according to a recent study by Kaspersky. Bring your own device (BYOD) has gained momentum as businesses see its advantages, including increased employee satisfaction, productivity, and engagement, and a reduction in capital expenditures and overhead costs.

Due to wide adoption of BYOD, workforce mobility almost became a necessity. In a mobile workforce, employees can work from home or a different geographic location entirely, or even attend meetings while in transit. To support this, companies often try to find a right combination of processes and tools. For instance, it is not enough to issue corporate laptops and smart phones – rather applications that support a more flexible working style must be bundled with them.

Conference call applications are just one of the many productivity apps that can help create a mobile workforce. To date, the market offers a variety of apps allowing free calls over the internet. There’s conferencecalling.com and freeconferencecall.com; then there’s the old champ - Skype, with a new variant for Business. GoToMeeting, UberConference, and WebEx are also industry leaders. However, all of these apps provide conference call capabilities as long as you’re connected to the internet. What if your employee is deployed abroad where internet connection is very weak? What if your business involves missions to remote areas where there is simply no internet capability?

The simple solution is to have an internet and Public Switched Telephone Network (PSTN) based conference call application that can be switched through a simple configuration. 

Creating a PSTN-based Call App

 

Internet enabled conference call apps are already ubiquitous; but seldom can you find one that’s PSTN-based.
Microsoft offers PSTN calling through Skype for Business but with a hefty premium; it can go as high as $11/minute. For most businesses, paying a huge amount for a conference call doesn’t make sense. In cases where the market doesn’t offer a cost-efficient alternative, one would be better off building an app from scratch.

When building your own conference app, there are a few things that you have to consider:

  1. You must find a cloud provider that offers cost efficient yet reliable PSTN-based outbound and inbound call APIs. Zang charges only $0.015/minute for outbound and $0.01/minute for inbound calls.
  2. Make sure you purchase a phone number that can be dialed-in to initiate the conference call. Zang also offers this for as low as $1/month.
  3. Consider which mobile platform you would want the app to be – Android or iOS? Although both have their merits, it’s better to choose the one you have more experience with. If you’re going to use Zang, you can use which ever platform you choose because its APIs are technology agnostic.

For the sake of this tutorial, we will be developing a basic conference call mobile application using Zang in iOS. Here are the basic requirements:

  1. Zang SID and Zang Auth Token. Don’t have one yet? You can get a free trial here.
  2. Intermediate knowledge of Objective C particularly data parsing using different formats
  3. Intermediate knowledge of XML
  4. Studied Zang Developer API documentation



Step 1: Create a Zang.io account and use the Zang SID and Auth Token to access the Developer Dashboard. You can start here. Basically, all you need to do is sign-up. Once you’re in the system, Zang will give you $3 (for free) to start using the APIs. Your Account SID and Auth Token will immediately be displayed on your Dashboard once you sign-in for the first time.

 

Step 2: Create an InboundXML document in the InboundXML Editor (Developers >InboundXML Editor) and save it. In our case, enter the InboundXML <Conference> tag example shown below.

 
 
<Response>
<Dial>
<Conference startConferenceOnEnter="true" callbackUrl="http://webhookr.com/conf-callback" hangupOnStar="true" maxParticipants="5">ZangExampleChat</Conference>
</Dial>
</Response>
 

Step 3: Invoke the call using Zang XML. The diagram below shows how the InboundXML <Conference> tag is implemented.

 

 A set of users invoke the conference number by calling it. The virtual conference call server plays music until two callers are in the same room. Take note that the maximum number of users allowed is five. When callers exit the room, the <Conference> attribute of “endConferenceOnExit” is supplied to the parent tag.

Step 3.1 Generate your InboundXML document using Objective C
Support for XML documents is built directly into Apple's OS X operating system, if your application "speaks" XML, it is assumed that it can communicate with any application on any other platform. Zang supports two types of data file formats: JSON and XML. To use Zang's InboundXML facility we need to create XML documents.

The primary object for creating an XML document is called NSXMLDocument, and inside this object is a root object of type NSXMLNode. The root NSXMLNode can contain attributes and children that are also NSXMLNodes (or the child class NSXMLElement).There are 2 steps to follow for your InboundXML:

  1. Create the InboundXML document
  2. Send the InboundXML document
Step 3.1.1 Create the InboundXML Document
The following code snippet creates the desired InboundXML format for the InboundXML <Conference> tag. 
 
-(NSData *) createXMLRequest
{
NSXMLElement *root = [[NSXMLElement alloc] initWithName:@"Response"]; // <Response>
NSXMLElement *childElement1 = [[NSXMLElement alloc] initWithName:@"Dial"]; //<Dial>


NSXMLElement *childElement2 = [[NSXMLElement alloc] initWithName:@"Conference"]; //<Conference>
[childElement2 addAttribute:[NSXMLNode attributeWithName:@"startConferenceOnEnter" stringValue:@"true"]];
[childElement2 addAttribute:[NSXMLNode attributeWithName:@"callbackUrl" stringValue:@"http://webhookr.com/conf-callback"]];
[childElement2 addAttribute:[NSXMLNode attributeWithName:@"hangupOnStar" stringValue:@"true"]];
[childElement2 addAttribute:[NSXMLNode attributeWithName:@"maxParticipants" stringValue:@"5"]];
[childElement2 setStringValue:@"ZangExampleChat"];
[childElement1 addChild:childElement2];

[childElement2 release];
NSXMLDocument *xmlRequest = [NSXMLDocument documentWithRootElement:root];
[root release];
NSLog(@"XML Document\n%@", xmlRequest);
return [xmlRequest XMLData];

 

In this example we constructed a root node that is an NSXMLElement, and added attributes to that element that are NSXMLNode objects. We also added children to the root element of both NSXMLElement objects and NSXMLNode objects. We can use the Apple System Log facility called NSLog to provide logs for error messages. The output from the NSLog statement is as follows:
 
<Response>
<Dial>
<Conference startConferenceOnEnter="true" callbackUrl="http://webhookr.com/conf-callback" hangupOnStar="true" maxParticipants="5">ZangExampleChat
</Conference>
</Dial>
</Response>
 
At the end of this method, the XMLDocument must be returned as a NSData object that is ready to be transmitted to the server.

3.1.2 Send the InboundXML Document
Sending the XML document to a server is a matter of opening an NSURLConnection and posting the document. The NSURLConnection object makes it very simple to talk to any HTTP Server on the Internet to either retrieve data or post data to the Zang server.
  • First step is to define the Zang.io URL (i.e. https://api.zang.io/v2/Accounts/{AccountSid}/Callsa) with your AccountSid;
  • Then, define the type of HTTP request method to be used. For this purpose, we will be using POST;
  • Next, define the HTTP Content Type definition. This is mainly used to specify the nature of the data in the body of an entity. It is also a way of identifying files on the Internet according to their nature or format. For this purpose, we will be using XML.
  • Then send the ‘data’ via the urlRequest setHTTPBody command.
  • Finally create an instance of the NSURLConnection using its initWithRequest setter property. The interface for the NSURLConnection is sparse, providing only the controls to start and cancel asynchronous loads of a URL request. For a synchronous request, the method sendSynchronousRequest can be used.
 
 
After the NSXMLDocument object is constructed from the NSData, the elements and nodes can be extracted from it and processed as needed. The Objective C NSData class provide methods to easily save their contents to a disk. It also has the option of saving the data atomically, so there’s a guarantee that the data will be stored or an error will be thrown if something goes wrong. Atomic writing begins by transcribing the data to a temporary file. Then, once the request is fired, the handler should immediately receive a server response. From this point, the handler should be pinged several times while you append the latest data to the response data variable.

Note as well that for this implementation, we are using an asynchronous request. In most cases, this is the more preferred approach, as it prevents the user interface from freezing, most especially when someone is performing gestures or when the screen suddenly becomes unresponsive.


Tips for Successful Implementation

The modern workforce’s way of doing work has changed, and the wide adoption of BYOD is a perfect example.
However, successful implementation requires the right combination of processes and tools. Conference call applications are just one of the many productivity apps that can help in creating a mobile workforce. However, most apps only work through the internet, and those which operate through PSTN are a bit expensive. In this scenario, it would be wise to create a custom made conference call application utilizing a Communications Platform as a Service (cPaaS) such as Zang. Creating a custom made conference call application just requires you to call already existing Zang APIs and implement them on the platform of your choice – Android, iOS and even the web.
 
Well, that’s it for this week! If you have any thoughts about the app or just want to share some taco puns, you can comment below.  I'll be back soon with another installment of TaCode Tuesday. If you want a reminder, sign up to get notifications of new blog posts.
 

Topics: Communication Apps, Ideas, TaCode Tuesday, cPaaS