Creating Tringme Widget

Posted by: James on Sunday, November 15th, 2009

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var randomstreamname = "63e457425defb24e8a5ca80de80d";
var tringMeURL:String = "rtmp://sip.tringme.com/call/<uid>";  ///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…