Skip to main content

Twilio Video Adobe Native Extension - Getting Started with Interface - Part 1

We know Adobe AIR apps doesn't support to add native platform external SDK's directly nor we can call native API's. So we need to create an extension that will help out to do our native stuffs

For couple of months, I have been working on Adobe AIR app and now I need to integrate Twilio's video. So here I will show you how to build an adobe native extension for Android that will make Twilio video call.

First of all, we need to define extension public API wrapper or interface. This API will be accessible from AIR app. Wrapper will be build using actionscript. For wrapper, we need a package name. Here I will be using as my package name.

Create wrapper directory

Create a directory named 'wrapper'. Here we will create our extension wrapper.

Create API class to start video

Next create a file under ijasnahamed/twilio/video directory. Copy below code to that file

package {
    import flash.external.ExtensionContext;
    public class TwilioVideo extends EventDispatcher {
        private static var instance:TwilioVideo = null;
        private var context:ExtensionContext = null;
        public function TwilioVideo() {
        public static function getInstance():TwilioVideo {
            if(instance == null) {
                instance = new TwilioVideo();
            return instance;
        private function init():void {
            if(context != null) {
            context = ExtensionContext.createExtensionContext("", "");
            if(context == null) {
                throw new Error("No implementation of the twilio video extension found for this platform");
            context.addEventListener(StatusEvent.STATUS, function (event:StatusEvent):void {
                dispatchEvent(new TwilioVideoEvent(event.code, event.level));
        public function start(callDetailsAsJsonString:String):void {
  "start", callDetailsAsJsonString);


This class will inherit EventDispatcher class because this class will catch all events from native code and dispatch that to our AIR app. Here I have used two methods

#1. Init

This is a private method and will create ExtensionContext that will create a bridge between AIR app and native code. If we doesn't have code for that phone platform, context will be null. Later this method will create an event listener that will listen for events from native side and dispatch events to our app.

#2. Start

This is a public method and we will use this method to start our video call. For now, this file will give you error because we haven't implemented TwilioVideoEvent class yet.

Create class to get library video events

Now create another file named in ijasnahamed/twilio/video/events directory from base directory. Event we send from wrapper to adobe AIR app will be of this type. Copy below code to

package {

 public class TwilioVideoEvent extends Event {

  public static const CALL_CONNECTED:String = "callConnected";
  public static const CALL_DISCONNECTED:String = "callDisconnected";
  public static const CALL_FAILED:String = "callFailed";
  public static const PARTICIPANT_CONNECTED:String = "participantConencted";
  public static const PARTICIPANT_DISCONNECTED:String = "participantDisconnected";
  public static const PARTICIPANT_AUDIO_TRACK_ADDED:String = "participantAudioTrackAdded";
  public static const PARTICIPANT_AUDIO_TRACK_REMOVED:String = "participantAudioTrackRemoved";
  public static const PARTICIPANT_VIDEO_TRACK_ADDED:String = "participantVideoTrackAdded";
  public static const PARTICIPANT_VIDEO_TRACK_REMOVED:String = "participantVIdeoTrackRemoved";

  private var message:String = "";

  public function TwilioVideoEvent(type:String, message:String) {
   super(type, false, false);

   this.message = message;

  public function getMessage():String {
   return message;

Create wrapper build configuration file

Now our wrapper API's are ready. Next we need to create a binary type file that will combine all this classes. For this, we use compc tool that will be available with Flex SDK. To build our binary, we need a config file of type xml where we can say our extension configuration.

Create a file named config.xml in base directory and copy below code.

    <!-- Specifies the minimum player version that will run the compiled SWF. -->

    <!-- Specifies the version of the compiled SWF -->

      <!-- Turn on generation of accessible SWFs. -->
      <!-- Specifies the locales for internationalization. -->

      <!-- Specifies that the target runtime is a mobile device. -->
        <!-- <path-element>../..</path-element> -->

      <!-- Allow the source-path to have path-elements which contain other path-elements -->
      <!-- Run the AS3 compiler in a mode that detects legal but potentially incorrect -->
      <!-- code.                                                                       -->
      <!-- Turn on generation of debuggable SWFs. False by default for mxmlc, -->
      <!-- but true by default for compc. -->

      <!-- List of SWC files or directories to compile against but to omit from -->
      <!-- linking.                                                             -->
         <path-element>[FLEX SDK PATH]\frameworks\libs\air\airglobal.swc</path-element>
      <!-- Turn on writing of generated/*.as files to disk. These files are generated by -->
      <!-- the compiler during mxml translation and are helpful with understanding and   -->
      <!-- debugging Flex applications.                                                  -->

      <!-- not set -->
      <!-- List of SWC files or directories that contain SWC files. -->
         <path-element>[FLEX SDK PATH]\frameworks\libs</path-element>
         <path-element>[FLEX SDK PATH]\frameworks\libs\mobile</path-element>
         <path-element>[FLEX SDK PATH]\frameworks\libs\air\servicemonitor.swc</path-element>
         <path-element>[FLEX SDK PATH]\frameworks\locale\{locale}</path-element>
      <!-- Enable post-link SWF optimization. -->

      <!-- Keep the following AS3 metadata in the bytecodes.                                             -->
      <!-- Warning: For the data binding feature in the Flex framework to work properly,                 -->
      <!--          the following metadata must be kept:                                                 -->
      <!--          1. Bindable                                                                          -->
      <!--          2. Managed                                                                           -->
      <!--          3. ChangeEvent                                                                       -->
      <!--          4. NonCommittingChangeEvent                                                          -->
      <!--          5. Transient                                                                         -->
      <!-- Default preloader. -->

      <!-- Turn on reporting of data binding warnings. For example: Warning: Data binding -->
      <!-- will not be able to detect assignments to "foo".                               -->
      <!-- toggle whether warnings generated from unused type selectors are displayed -->

      <!-- Run the AS3 compiler in strict error checking mode. -->
      <!-- Use the ActionScript 3 class based object model for greater performance and better error reporting. -->
      <!-- In the class based object model most built-in functions are implemented as fixed methods of classes -->
      <!-- (-strict is recommended, but not required, for earlier errors) -->
      <!-- Use the ECMAScript edition 3 prototype based object model to allow dynamic overriding of prototype -->
      <!-- properties. In the prototype based object model built-in functions are implemented as dynamic      -->
      <!-- properties of prototype objects (-strict is allowed, but may result in compiler errors for         -->
      <!-- references to dynamic properties) -->
      <!-- List of CSS or SWC files to apply as a theme. -->
         <!-- default theme is mobile -->
         <filename>[FLEX SDK PATH]\frameworks\themes\Mobile\mobile.swc</filename>
      <!-- Turns on the display of stack traces for uncaught runtime errors. -->
      <!-- Defines the AS3 file encoding. -->
      <!-- not set -->

          <!-- Enables advanced anti-aliasing for embedded fonts, which provides greater clarity for small -->
          <!-- fonts. This setting can be overriden in CSS for specific fonts. -->
          <!-- NOTE: flash-type has been deprecated. Please use advanced-anti-aliasing <flash-type>true</flash-type> -->
          <!-- The number of embedded font faces that are cached. -->
          <!-- The number of character glyph outlines to cache for each font face. -->
          <!-- Defines ranges that can be used across multiple font-face declarations. -->
          <!-- See flash-unicode-table.xml for more examples. -->
          <!-- not set -->
          <!-- Compiler font manager classes, in policy resolution order-->

          <!-- File containing cached system font licensing information produced via 
               java -cp mxmlc.jar (fontpath)
               Will default to winFonts.ser on Windows XP and
               macFonts.ser on Mac OS X, so is commented out by default.
      <!-- Array.toString() format has changed. -->
      <!-- Assignment within conditional. -->
      <!-- Possibly invalid Array cast operation. -->
      <!-- Non-Boolean value used where a Boolean value was expected. -->

      <!-- Invalid Date cast operation. -->
      <!-- Unknown method. -->

      <!-- Unknown property. -->

      <!-- Illogical comparison with NaN. Any comparison operation involving NaN will evaluate to false because NaN != NaN. -->

      <!-- Impossible assignment to null. -->

      <!-- Illogical comparison with null. -->

      <!-- Illogical comparison with undefined. Only untyped variables (or variables of type *) can be undefined. -->

      <!-- Boolean() with no arguments returns false in ActionScript 3.0. Boolean() returned undefined in ActionScript 2.0. -->

      <!-- __resolve is no longer supported. -->

      <!-- Class is sealed. It cannot have members added to it dynamically. -->
      <!-- Constant not initialized. -->

      <!-- Function used in new expression returns a value. Result will be what the -->
      <!-- function returns, rather than a new instance of that function.           -->

      <!-- EventHandler was not added as a listener. -->

      <!-- Unsupported ActionScript 2.0 function. -->

      <!-- Unsupported ActionScript 2.0 property. -->

      <!-- More than one argument by the same name. -->

      <!-- Duplicate variable definition -->

      <!-- ActionScript 3.0 iterates over an object's properties within a "for x in target" statement in random order. -->

      <!-- Importing a package by the same name as the current class will hide that class identifier in this scope. -->

      <!-- Use of the instanceof operator. -->

      <!-- Internal error in compiler. -->

      <!-- _level is no longer supported. For more information, see the flash.display package. -->

      <!-- Missing namespace declaration (e.g. variable is not defined to be public, private, etc.). -->

      <!-- Negative value will become a large positive value when assigned to a uint data type. -->

      <!-- Missing constructor. -->

      <!-- The super() statement was not called within the constructor. -->

      <!-- Missing type declaration. -->
      <!-- In ActionScript 3.0, white space is ignored and '' returns 0. Number() returns -->
      <!-- NaN in ActionScript 2.0 when the parameter is '' or contains white space.      -->
      <!-- Change in scoping for the this keyword. Class methods extracted from an  -->
      <!-- instance of a class will always resolve this back to that instance. In   -->
      <!-- ActionScript 2.0 this is looked up dynamically based on where the method -->
      <!-- is invoked from.                                                         -->
      <!-- Inefficient use of += on a TextField.-->
      <!-- Possible missing parentheses. -->
      <!-- Possible usage of the ActionScript 2.0 XML class. -->

   <!-- compute-digest: writes a digest to the catalog.xml of a library. Use this when the library will be used as a
                        cross-domain rsl.-->
   <!-- compute-digest usage:

   <!-- A list of runtime shared library URLs to be loaded before applications start. -->
   <!-- not set -->
  <!-- static-link-runtime-shared-libraries: statically link the libraries specified by the -runtime-shared-libraries-path option.-->
   <!-- target-player: specifies the version of the player the application is targeting. 
                 Features requiring a later version will not be compiled into the application. 
                       The minimum value supported is "9.0.0".-->
   <!-- target-player usage:

   <!-- Enables SWFs to access the network. -->
   <!-- Metadata added to SWFs via the SWF Metadata tag. -->
      <title>Twilio Video ANE</title>
      <description>Adobe AIR ANE Wrapper for Twilio Video</description>
      <publisher>Ijas N Ahamed</publisher>
      <creator>Ijas Ahamed N</creator>


Please replace [FLEX SDK PATH] with your Flex SDK path.

Build your wrapper

Now run below code to generate binary

compc -load-config config.xml -output TwilioVideo.swc -include-classes

If you get any error with compc, please create an environmental variable in your PC that will points to compc.bat available in Flex_DIR/bin directory. This will create TwilioVideo.swc file which will be used to create our extension.

Get your platform library

This TwilioVideo.swc will a zip type file. Please unzip this file and you will find a library.swf file with this. We will be using this library.swf for extension packing.

Now lets build our android library from Build android library

You can get sample code for wrapper from ijasnahamed > Twilio Video ANE > wrapper

Popular posts from this blog

Setup Asterisk 13 with FreePBX 13 in CentOS 7

Launch CentOS 7 AWS Ec2 InstanceLog in to your aws consoleGo to ec2 management page and click Launch Instance on Instance pageIn Choose AMI step, go to AWS MarketPlace tab and search CentOS 7 on search field. List of centos 7 ami's will be available.Select CentOS 7 (x86_64) ami which is free tier eligible. Select your instance type and click configure instance. Keep default values from Configure Instance to Add Tags stepsIn configure security group, create a security group which allow minimum ports openSSH : port 22HTTP : port 80Custom UDP Rule : 10000-20000 (if you are giving RTP ports 10000-20000)Custom UDP Rule : 5060 (ChanSIP port)Custom TCP Rule : 5060 (ChanSIP Port)Click Launch Instance. Select your key file and accept terms to launch instance.
Setup CentOS Server SSH into newly created CentOS server with username centos and your key file.Update all existing packagessudo yum update -yNow start http service(you can access your server via browser by going to your server ip addres…

Implementing Client Side WebRTC using Sipml5 javascript

Step 1:

Download and require Sipml5 library function.

Step 2:

Initialize sipml5 Engine in your web page :

var readyCallback = function(e) {
// function called when sipml is successfully initialised.
createSipStack(); // calling this function to create sip stack(see below)

var errorCallback = function(e) {
// function called when error occured during sipml initialisation.

SIPml.init(readyCallback, errorCallback);

Step 3:

Create Sip Stack :-
Sip Stack is an object that must be created before making/receiving call and sms. Creating Sip stack is an asynchronous process, so you need to create an event listener function to get state change notification.

var sipStack;

function EventListener(e) {

* e.type ;type of event listener
* e.session ; current event session
* e.getSipResponseCode() ; event response code
* e.description ; event description

if(e.type == 'started'){
// successfully started the stack.
} else if(e.type == 'i_new_call'){
// when new incoming call comes.

Multiple file upload using ajax with progress bar

Uploading multiple files using ajax makes a pleasant feeling to the user. It makes even more happier if upload progress status is printed with percentage.

            In this blog, you will make a file upload form using ajax with file upload progress bar.

Prerequisites :

1) Javascript supported browser
2) LAMP Server / XAMPP Server

Code :


<!DOCTYPE html>



    <title>Multiple File Upload using Ajax</title>

    <link rel="stylesheet" type="text/css" href="style.css">

    <script src="//"></script>




        <form action="action.php" method="post" enctype="multipart/form-data" id="multiple-upload-form">

            <input type="button" id="select-file-btn" value="Select Files" onclick="document.getElementById(…