Actionscript 3.0

Creating Tringme Widget

I have to trying to create a flash widget to enable call/voicemail using TringMe api, success was eluding me for quite some time. Finally I was able to make the widget working, I have the code for people who would like to develop similar widgets using TringMe.

var randomstreamname = "63e457425defb24e8a5ca80de80d";
var tringMeURL:String = "rtmp://sip.tringme.com/call/"; ///uid obtained from TringMe

NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
var nc:NetConnection;

//Call and close buttons
call_btn.addEventListener(MouseEvent.CLICK, callHandler, false, 0, true);
close_btn.addEventListener(MouseEvent.CLICK, closeCallHandler, false, 0, true);

function callHandler(evt:MouseEvent):void{
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, connectionStatushandler, false, 0, true);
nc.connect(tringMeURL);
}

function closeCallHandler(evt:MouseEvent):void{
nc.close();
}

function connectionStatushandler(evt:NetStatusEvent):void{
var info:Object = evt.info;
trace(info.code);

status_txt.text = String(info.code);

if (info.code == "NetConnection.Connect.Success") {

var nsc:NetStream = new NetStream(nc);
var mic:Microphone = Microphone.getMicrophone();
mic.rate = 8;
mic.setSilenceLevel(0);

nsc.attachAudio(mic);
nsc.publish(randomstreamname, "record");

var nsc1:NetStream = new NetStream(nc);
nsc1.play("tring", -1);
}
}

Hope this helps some one…

Disclaimer: All published content views of author.