Sipper - The Simplest SIP client in Flash

Our GTalk2VoIP gateway is now supporting RTMP protocol, which is a core of network interconnection for Adobe Flash applications. We do provide a publicly open RTMP-to-SIP gatewaying service and a Flex 2.0 API, which you can use to build your own Flash applications with SIP calling functionality. Flex is a core language used to create Adobe Flash applications that are to be played (executed) by Adobe Flash Player 9 or 10. You can see an example of such application that uses our Flex API on the right.

Subscription

To test our Flex API you will have to subscribe and obtain a Provider Cookie from us. Provider Cookie is used to destinguish your company as a SIP provider in our GTalk2VoIP system. Each Provider Cookie is tied up to one of your SIP servers, so all calls made with same cookie will be routed to same SIP server.

To get yourself a Provider Cookie, please e-mail us to team@gtalk2voip.com. Don't forget to include your SIP server address and details on how are you going to use our Flex API.

Flex API

Our Flex API is pretty simple yet straightforward. It allows your Flash application to connect to our gateway over RTMP protocol, then to place SIP calls. Here below we provide some code snippets to let you better uderstand how it works.

1) Setup network connection to GTalk2VoIP gateway:


	NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;	
	netConnection = null;
	netConnection = new NetConnection();
	netConnection.objectEncoding = ObjectEncoding.AMF0;
	netConnection.client = this;
	netConnection.addEventListener( NetStatusEvent.NET_STATUS , netStatus );
	netConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);

	netConnection.connect("rtmp://gtalk2voip.com:1935/apps/sipper", "SIP", providerCookie);

Here, the URL is an addrss to our public RTMP service which implements SIP gateway. providerCookie is the cookie you got from us.

2) Access and configure a microphone:


	mic = Microphone.getMicrophone();

	mic.setUseEchoSuppression(true);
	mic.setLoopBack(false);
	mic.setSilenceLevel(10);
	mic.gain = 80;
	mic.rate = 8;


3) Place a call with:


	netConnection.call("call", null, Username, Password, Destination);

Where Username is a SIP username on your SIP server, Password is their password and Destination is a phone number or an extention your SIP server can route to.

4) Once call is accepted, you will have to create inbound and outbound audio streams:


	incomingNetStream = new NetStream(netConnection);
	var client1:Object = new Object(); 
	incomingNetStream.client = client1;		
	incomingNetStream.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
	incomingNetStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);

	outgoingNetStream = new NetStream(netConnection);
	var client2:Object = new Object(); 
	outgoingNetStream.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
	outgoingNetStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
	outgoingNetStream.attachAudio(mic);

	incomingNetStream.play(playName); 
	outgoingNetStream.publish(publishName, "live");

5) Drop the call with:


	netConnection.call("hangup", null);

	incomingNetStream.close();
	outgoingNetStream.close();
	incomingNetStream = null;
	outgoingNetStream = null;

Example

You can download a source code of our Sipper application, which is a simplest implementaion of SIP client in Flash to be used with our Flex API.

Source code: sipper.mxml
Flash SWF: sipper.swf