Example usage for org.apache.cordova.api CallbackContext isFinished

List of usage examples for org.apache.cordova.api CallbackContext isFinished

Introduction

In this page you can find the example usage for org.apache.cordova.api CallbackContext isFinished.

Prototype

public boolean isFinished() 

Source Link

Usage

From source file:de.dfki.iui.opentok.cordova.plugin.OpenTokPlugin.java

License:Open Source License

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    boolean isHandled = false;

    doDebug(args != null ? args.toString()
            : "NO_ARGS" + (callbackContext.isFinished() ? " CALLBACK_FINISHED!" : ""), "execute-" + action);//FIXME debug

    if (ACTION_UPDATE_VIEW.equals(action)) {
        isHandled = true;/*ww w .  j  av a2s .  co m*/

        PluginResult result;
        try {
            String sid = args.getString(0); //[command.arguments objectAtIndex:0];
            int top = extractDp(args, 1);//args.getInt(1); //[[command.arguments objectAtIndex:1] intValue];
            int left = extractDp(args, 2);//args.getInt(2); //[[command.arguments objectAtIndex:2] intValue];
            int width = extractDp(args, 3);//args.getInt(3); //[[command.arguments objectAtIndex:3] intValue];
            int height = extractDp(args, 4);//args.getInt(4); //[[command.arguments objectAtIndex:4] intValue];
            int zIndex = args.getInt(5); //[[command.arguments objectAtIndex:5] intValue];

            result = doUpdateView(sid, top, left, width, height, zIndex);

        } catch (JSONException e) {
            e.printStackTrace();
            String msg = String.format("Error processing arguments for %s: %s - arguments: %s", action, e,
                    args.toString());
            result = new PluginResult(PluginResult.Status.ERROR, msg);
        }

        callbackContext.sendPluginResult(result);
    } else if (ACTION_EXEPTION_HANDLER.equals(action)) {
        isHandled = true;

        PluginResult result = this.setExceptionHandler(callbackContext);

        callbackContext.sendPluginResult(result);
    } else if (ACTION_STREAM_DISCONNECT_HANDLER.equals(action)) {
        isHandled = true;

        PluginResult result = this.setStreamDisconnectHandler(callbackContext);

        callbackContext.sendPluginResult(result);
    } else if (ACTION_SESSION_DISCONNECT_HANDLER.equals(action)) {
        isHandled = true;

        PluginResult result = this.setSessionDisconnectHandler(callbackContext);

        callbackContext.sendPluginResult(result);
    } else if (ACTION_TB_TESTING.equals(action)) {
        isHandled = true;

        this.doTBTesting(callbackContext);
    } else if (ACTION_INIT_SESSION.equals(action)) {
        isHandled = true;

        PluginResult result;
        try {

            String sessionId = args.getString(0);

            result = doInitSession(sessionId);

        } catch (JSONException e) {
            e.printStackTrace();
            String msg = String.format("Error processing arguments for %s: %s - arguments: %s", action, e,
                    args.toString());
            result = new PluginResult(PluginResult.Status.ERROR, msg);
        }

        callbackContext.sendPluginResult(result);
    } else if (ACTION_INIT_PUBLISHER.equals(action)) {
        isHandled = true;

        PluginResult result;
        try {

            LOG.i(PLUGIN_NAME, "creating Publisher");
            boolean bpubAudio = true;
            boolean bpubVideo = true;

            // Get Parameters

            int top = args.getInt(0); //[[command.arguments objectAtIndex:0] intValue];
            int left = args.getInt(1); //[[command.arguments objectAtIndex:1] intValue];
            int width = args.getInt(2); //[[command.arguments objectAtIndex:2] intValue];
            int height = args.getInt(3); //[[command.arguments objectAtIndex:3] intValue];

            String name = args.getString(4); //[command.arguments objectAtIndex:4];
            if (name.equals("TBNameHolder")) {

                //TODO this usually only works for tab-devices... need to provide a fallback in case this is a phone...
                name = Secure.getString(this.cordova.getActivity().getContentResolver(), Secure.ANDROID_ID);
                //                 name = [[UIDevice currentDevice] name];
            }

            String publishAudio = args.getString(5); //[command.arguments objectAtIndex:5];
            if (publishAudio.equals("false")) {
                bpubAudio = false;
            }
            String publishVideo = args.getString(6); //[command.arguments objectAtIndex:6];
            if (publishVideo.equals("false")) {
                bpubVideo = false;
            }
            int zIndex = args.getInt(7); //[[command.arguments objectAtIndex:7] intValue];

            result = doInitPublisher(top, left, width, height, name, bpubAudio, bpubVideo, zIndex);

        } catch (JSONException e) {
            e.printStackTrace();
            String msg = String.format("Error processing arguments for %s: %s - arguments: %s", action, e,
                    args.toString());
            result = new PluginResult(PluginResult.Status.ERROR, msg);
        }

        callbackContext.sendPluginResult(result);
    } else if (ACTION_PUBLISH.equals(action)) {
        isHandled = true;

        PluginResult result = doPublish();

        callbackContext.sendPluginResult(result);
    } else if (ACTION_UNPUBLISH.equals(action)) {
        isHandled = true;

        PluginResult result = doUnpublish();

        callbackContext.sendPluginResult(result);
    } else if (ACTION_DESTROY_PUBLISHER.equals(action)) {
        isHandled = true;

        PluginResult result = doDestroyPublisher();

        callbackContext.sendPluginResult(result);
    } else if (ACTION_STREAM_CREATED_HANDLER.equals(action)) {
        isHandled = true;

        PluginResult result = this.setStreamCreatedHandler(callbackContext);

        callbackContext.sendPluginResult(result);
    } else if (ACTION_CONNECT.equals(action)) {
        isHandled = true;

        //         PluginResult result;
        try {

            //             NSString* tbKey = [command.arguments objectAtIndex:0];
            //             NSString* tbToken = [command.arguments objectAtIndex:1];
            String tbKey = args.getString(0);
            String tbToken = args.getString(1);

            //            result = 
            doConnect(tbKey, tbToken, callbackContext);

        } catch (JSONException e) {
            e.printStackTrace();
            String msg = String.format("Error processing arguments for %s: %s - arguments: %s", action, e,
                    args.toString());
            //            result =
            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, msg));
        }

        //          callbackContext.sendPluginResult(result);
    } else if (ACTION_SUBSCRIBE.equals(action)) {
        isHandled = true;

        PluginResult result;
        try {

            String sid = args.getString(0);//[command.arguments objectAtIndex:0];

            int top = args.getInt(1);// [[command.arguments objectAtIndex:1] intValue];
            int left = args.getInt(2);// [[command.arguments objectAtIndex:2] intValue];
            int width = args.getInt(3);// [[command.arguments objectAtIndex:3] intValue];
            int height = args.getInt(4);// [[command.arguments objectAtIndex:4] intValue];
            String tmp = args.getString(5);// [command.arguments objectAtIndex:5];
            int zIndex = args.getInt(6);// [[command.arguments objectAtIndex:6] intValue];

            boolean isSubscribeToVideo = true;
            if (tmp != null) {
                tmp = tmp.trim();
                if (tmp.length() > 0)
                    isSubscribeToVideo = Boolean.parseBoolean(tmp);
            }

            result = doSubscribe(sid, top, left, width, height, isSubscribeToVideo, zIndex);

        } catch (JSONException e) {
            e.printStackTrace();
            String msg = String.format("Error processing arguments for %s: %s - arguments: %s", action, e,
                    args.toString());
            result = new PluginResult(PluginResult.Status.ERROR, msg);
        }

        callbackContext.sendPluginResult(result);
    } else if (ACTION_UNSUBSCRIBE.equals(action)) {
        isHandled = true;

        PluginResult result;
        try {

            String sid = args.getString(0);//[command.arguments objectAtIndex:0];

            result = doUnsubscribe(sid);

        } catch (JSONException e) {
            e.printStackTrace();
            String msg = String.format("Error processing arguments for %s: %s - arguments: %s", action, e,
                    args.toString());
            result = new PluginResult(PluginResult.Status.ERROR, msg);
        }

        callbackContext.sendPluginResult(result);
    } else if (ACTION_DISCONNECT.equals(action)) {
        isHandled = true;

        PluginResult result = doDisconnect();

        callbackContext.sendPluginResult(result);
    } else if (ACTION_SESSION_CONNECTION_CREATED_HANDLER.equals(action)) {
        isHandled = true;

        PluginResult result = this.setSessionConnectionCreatedHandler(callbackContext);

        callbackContext.sendPluginResult(result);
    } else if (ACTION_SESSION_CONNECTION_DESTROYED_HANDLER.equals(action)) {
        isHandled = true;

        PluginResult result = this.setSessionConnectionDestroyedHandler(callbackContext);

        callbackContext.sendPluginResult(result);
    } else if (ACTION_GET_SESSION_CONNECTION.equals(action)) {
        isHandled = true;

        doGetSessionConnection(callbackContext);
    } else if (ACTION_TOGGLE_AUDIO.equals(action)) {
        isHandled = true;

        PluginResult result;
        try {

            String sid = args.getString(0);

            result = doToggleAudio(sid);

        } catch (JSONException e) {
            e.printStackTrace();
            String msg = String.format("Error processing arguments for %s: %s - arguments: %s", action, e,
                    args.toString());
            result = new PluginResult(PluginResult.Status.ERROR, msg);
        }

        callbackContext.sendPluginResult(result);
    } else if (ACTION_REFRESH.equals(action)) {
        isHandled = true;

        PluginResult result;
        try {

            String sid = args.getString(0);

            result = doRefresh(sid);

        } catch (JSONException e) {
            e.printStackTrace();
            String msg = String.format("Error processing arguments for %s: %s - arguments: %s", action, e,
                    args.toString());
            result = new PluginResult(PluginResult.Status.ERROR, msg);
        }

        callbackContext.sendPluginResult(result);
    }

    return isHandled;
}