Flash API

This enables developers to quickly create their own Adobe Flash, Flex or AIR application based to utilize TringMe’s standards based APIs for telephony and messaging. Given the powerful functionality of Adobe Flash and the ease of use of TringMe’s APIs, developers will be able to produce compelling voice enabled apps using Adobe’s – Flash, Flex or AIR – technologies. For example, developers can create a fully-functional desktop or web-based phone on top of TringMe APIs using Adobe AIR technology.

TringMe uses standard NetStream and NetConnection interfaces which have been available since Flash 7. This allows even an inexperienced flash developer to develop new widgets by writing few lines of code.

Since NetConnection and NetStream are widely used and tons of documentation and help already are available on the web, readers are requested to refer those resources and we will not cover it here.

Making Call

Following is an implementation of Making Call which is simple as

  • 1. Create Flash NetConnection object
  • 2. Two NetStream Objects (A & B) attached them to NetConnection
  • 3. Create Microphone Object and attach it to a NetStream A
  • 4. Publish NetStream A
  • 5. Play NetStream B

Complete working source code of a minimal phone widget is below.

nc = new NetConnection();

// handle asynchronous notification and failures
nc.onStatus = ConnectStatus;
nc.connect(TringMeURI);

//Create NetStream A and attach it with Microphone
nsA = new NetStream(nc);
mic = new Microphone.get();
mic.setRate(8);
mic.setSilenceLevel(0);
nsA.attachAudio(mic);
nsA.publish(randomstreamname, "record");

//Create NetStream B and play
nsB = new NetStream(nc);
nsB.play("tring", -1);


NetConnection targetURI Specification

To make a Flash phone call, the URI string should be formatted in one of the below mentioned specifications:

Parameters
cookie cookie or channel can be passed, as obtained from 'login' or 'setchannel' API.
tag [Optional] User supplied parameter to associate a call in the Call Data Records (obtained by 'getcdr'). 'tag' is alphanumeric only (a-z, A-Z, 0-9), and all other characters will be replaced by 'X'.
callerid [Optional] caller id is passed only if destination is SIP. To use callerid on TringMe's network requires special activation due to the privacy & security issues
dtmf [Optional] DTMF
duration [Optional] Maximum duration of the call.
Sample Request URL
rtmp://sip.tringme.com/1234567890123 456789012345678901 /19125551212
Expected Response
OK <validity>'
Sample Responses
OK 86400

Ending Call

To end the call, close NetStream by calling close method.
Complete working source code of a minimal phone widget is below.

// close stream A, it optional to close stream B as it will be automatically closed by TringMe
nsA.close();

If the call is terminated by called party, TringMe will close the connection. Notification will be posted to onStatus handler of class NetConnection

function ConnectStatus(pInfo:Object) {
if (pInfo.code == "NetConnection.Connect.Success") {
// do something to indicate successful connection with TringMe
} else if (pInfo.code == "NetConnection.Connect.Closed" || pInfo.code == "NetConnection.Connect.Rejected") {
// close streams and clean up
}
}

Call Status Notifications in Flash

To receive call status notification in Flash itself , register a status handler as shown below. Currently only following status notifications are supported:

TringMe.Status.00200 - Call Connected Status

//Create NetConnection and connect

nc.onStatus = ConnectStatus;
nc = new NetConnection();
//handle async notification and failures

nc.onStatus = ConnectStatus;
nc.connect(TringMeURI);
//Create NetStream A and attach it with Microphone

nsA = new NetStream(nc);
mic = new Microphone.get();
mic.setRate(8);
mic.setSilenceLevel(0);
nsA.attachAudio(mic);
nsA.publish(randomstreamname, "record");
//Create NetStream B and play

nsB = new NetStream(nc);
nsB.onStatus = NSOnStatusHandler;
nsB.play("tring", -1);
...
//Declare the OnStatus handler for receiving status updates.
//It should be registered as shown below

NSOnStatusHandler = function(info:Object) {
trace(info.code);
if (info.code == "TringMe.Status.00200") {
//Call is connected ...
}
}

Using TringMe's Premade Flash Widgets

While you can build your own Flash phone widgets as described above, you can also use TringMe's premade widgets easily. Integrating these readymade widgets is as simple as adding few lines of HTML code.
Embedding TringPhone widget
TringPhone is a Flash widget and can be embedded into your website like any other flash file (.swf) file.TringPhone takes cookie or channel as a parameter. Use 'login' or 'setchannel' API to obtain the cookie or the channel respectively. Following are the details of flash object:

Sample Request URL
http://login.tringme.com/swf/ tringphone.swf?channel =2b4567a90123f567890c 2345d789011

Embedding Push-n-talk widget

TringMe Push-n-talk is a Flash widget can be used for fixed dialing and can be embedded into your website like any other flash file (.swf) file. Any user visiting your website can just push and start talking to you without dialing any number.

Push-n-talk takes following parameters.(All the parameters except 'channel' & 'name' are OPTIONAL:)

Parameters
channel channel
name Name to be displayed on Widget
dtmf DTMF
callerid Caller ID
tag Call tag
duration Max duration of the call
greeting URL of mp3 file to be played before placing the call
postgreeting URL of mp3 file to be played after the call
ctxt Call Text - Replaces default call text on the widget.Default 'Click to Call'.
For Localization & customization.
htxt Hangup Text - Replaces default hangup text on the widget.
ttxt Call Termination Text - Replaces default call termination text on the widget
background URL of Background image
Sample Request URL
http://login.tringme.com/swf/ tringmewidget.swf?channel= 2b4567a90123f567890c23 45d789011&name=My+Name &greeting= http://mywebsite.com/ greeting.mp3

If you are an enterprise and would like to know better how TringMe can help you reduce cost and at the same time benefit you,
please send a mail to bizdev@tringme.com