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…

facebooktwittergoogle_plusredditpinterestlinkedinmailby feather

8 Comments

  1. BroquE

    Thank you, i was looking for where i was mistaken and finally found in your post.

    I forgot to add this line to my codes:
    NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;

    Reply
    1. James

      Good that this helped you, I too was struggling with this till the time I came across a post where I found this.

      Reply
  2. Anubad

    Hi,

    I have been trying to figure this out for sometime.
    Could you please e-mail me the project (.fla file?).

    I am pretty new to actionscript and could not figure out how exactly to use the code above.

    Thanks!

    Anubad Sharma

    Reply
    1. James

      Anubad, I use flash develop for my personal development works so I do not have a .fla file. If you let me know of your requirement, I can help you with it.

      Reply
  3. sava

    James,
    could you please tell me where you put the dest. number in your code?
    I am also trying to figure out how to write a simple phone widget.

    Thanks

    Reply
  4. James

    Sava
    I am bit occupied with my office work as of now, I surely would be glad to help you with this. Let me know if you need this urgently. E-mail me at james UNDERSCORE shaji AT rediffmail.com

    Reply
  5. Stefka

    Can u please send me your fla file?
    Regards

    Reply
    1. James

      Stefka, I use flashdevelop for my development at home, so there is no .fla file, only .as files. The same code can be used in flash without much modification, just place two buttons on stage and name them “call_btn” and “close_btn”. Hopefully if time permits I would have the AS3 project available for download.

      Reply

Leave a Comment

Your email address will not be published. Required fields are marked *

Disclaimer: All published content views of author.