List of usage examples for org.apache.cordova.api LOG i
public static void i(String tag, String s)
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;//from w w w.j a va 2 s.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; }
From source file:de.dfki.iui.opentok.cordova.plugin.OpenTokPlugin.java
License:Open Source License
@SuppressLint("DefaultLocale") private PluginResult doUpdateView(String sid, int top, int left, int width, int height, int zIndex) { try {//FIXME TEST LOG.i(PLUGIN_NAME, String.format(/*w ww .ja v a2s . c o m*/ "updateView with arguments: sid %s, top %d, left %d, width %d, height %d, zIndex %d", sid, top, left, width, height, zIndex)); if (_publisher != null && sid.equals(ID_PUBLISHER)) { LOG.i(PLUGIN_NAME, String.format("The Width is: %d", width)); // LayoutParams layoutParams = createLayoutParams(left, top, width, height); //// _publisher.getView().setLeft(left); //// _publisher.getView().setTop(top); // _publisher.getView().setX(left); // _publisher.getView().setY(top); // publisherViewContainer.addView(mPublisher.getView(), layoutParams); // this.publisherViewParams = new ViewParams(left, top, width, height, zIndex); // LayoutParams params = this.publisherViewParams.create();//this.createLayoutParams(left, top, width, height); LayoutParams params = this.createLayoutParams(left, top, width, height); // _publisher.getView().setLayoutParams(params);//frame = CGRectMake(left, top, width, height); doUpdateViewLayoutParams(_publisher.getView(), params); // _publisher.view.layer.zPosition = zIndex; if (_publisherAudioIcon != null) { LayoutParams iParams = createIconLayoutParams(top, left, width, height); int micStatus = getIconResourceForPublisherStatus(); int micIconVisiblity = getIconVisibilityForPublisherStatus(); doUpdateViewIcon(_publisherAudioIcon, iParams, micStatus, micIconVisiblity); } } // Subscriber streamInfo = subscriberDictionary.get(sid); // if (streamInfo) { // // Reposition the video feeds! // streamInfo.view.frame = CGRectMake(left, top, width, height); // streamInfo.view.layer.zPosition = zIndex; // } if (streamInfo != null) { // Reposition the video feeds! ViewParams viewParams = new ViewParams(left, top, width, height, zIndex);//subscriberViewParams.get(sid); subscriberViewParams.put(sid, viewParams); LayoutParams newPosition = this.createLayoutParams(left, top, width, height);//viewParams.create();// this.createLayoutParams(left, top, width, height); // streamInfo.getView().setLayoutParams(newPosition); doUpdateViewLayoutParams(streamInfo.getView(), newPosition); ImageView subscriberAudioIcon = subscriberAudioIconDictionary.get(sid); if (subscriberAudioIcon != null) { LayoutParams iParams = createIconLayoutParams(top, left, width, height); int speakerStatus = getIconResourceForSubscriberStatus(streamInfo); int speakerIconVisiblity = getIconVisibilityForSubscriberStatus(streamInfo); doUpdateViewIcon(subscriberAudioIcon, iParams, speakerStatus, speakerIconVisiblity); } } PluginResult result = new PluginResult(PluginResult.Status.OK, String.format("updateView [stream %s, top %d, left %d, width %d, height %d, zIndex %d]", sid, top, left, width, height, zIndex)); result.setKeepCallback(true); return result; } catch (Exception e) { String msg = String.format( "error during updateView with arguments: sid %s, top %d, left %d, width %d, height %d, zIndex %d", sid, top, left, width, height, zIndex); System.err.println(msg); e.printStackTrace(); LOG.e(PLUGIN_NAME, msg, e); throw (new RuntimeException( "This is a 'proxied' Exception (for 'real' Exception, see first entry in stack-trace)", e)); } }
From source file:de.dfki.iui.opentok.cordova.plugin.OpenTokPlugin.java
License:Open Source License
private PluginResult doInitPublisher(int top, int left, int width, int height, String name, boolean publishAudio, boolean publishVideo, int zIndex) { // Publish and set View _publisher = Publisher.newInstance(this.cordova.getActivity(), this.mListener, name); _publisher.setPublishAudio(publishAudio); _publisher.setPublishVideo(publishVideo); LayoutParams params = this.createLayoutParams(left, top, width, height); if (isInfo()) LOG.i(PLUGIN_NAME, String.format("Adding view for publisher '%s' at (%d,%d), width %d, height %d (layer: %d)", name, left, top, width, height, zIndex)); viewAdministrator.addView(this.cordova.getActivity(), _webView, _publisher.getView(), params); _publisherAudioIcon = createPublisherAudioIcon(); LayoutParams iconPosition = createIconLayoutParams(top, left, width, height); viewAdministrator.addView(this.cordova.getActivity(), _webView, _publisherAudioIcon, iconPosition); // Return to Javascript return new PluginResult(PluginResult.Status.OK, String.format("initPublisher [stream '%s' at (%d,%d), width %d, height %d (z-layer: %d)]", name, left, top, width, height, zIndex)); }
From source file:de.dfki.iui.opentok.cordova.plugin.OpenTokPlugin.java
License:Open Source License
private PluginResult doSubscribe(String sid, int top, int left, int width, int height, boolean isSubscribeToVideo, int zIndex) { if (!statusIsDeviceOnPause) { // Acquire Stream, then create a subscriber object and put it into dictionary Stream stream = streamDictionary.get(sid); Subscriber subscriber = Subscriber.newInstance(this.cordova.getActivity(), stream, this.mListener); subscriberDictionary.put(stream.getStreamId(), subscriber); subscriber.setSubscribeToVideo(isSubscribeToVideo); _session.subscribe(subscriber);// ww w . ja v a 2s. co m ViewParams viewParams = new ViewParams(top, left, width, height, zIndex); subscriberViewParams.put(stream.getStreamId(), viewParams); LayoutParams params = this.createLayoutParams(left, top, width, height);//viewParams.create();//this.createLayoutParams(left, top, width, height); // subscriber.getView().setLayoutParams(params); // ((OpenTokExample)this.cordova.getActivity()).addView(subscriber.getView(), params); if (isInfo()) LOG.i(PLUGIN_NAME, String.format( "Adding subscriber (stream %s) for publisher at (%d,%d), width %d, height %d (layer: %d)%s", sid, left, top, width, height, zIndex, isSubscribeToVideo ? "" : " IS NOT SUSCRIBING TO VIDEO!")); viewAdministrator.addView(this.cordova.getActivity(), _webView, subscriber.getView(), params); ImageView subscriberAudioIcon = createSubscriberAudioIcon(subscriber); subscriberAudioIconDictionary.put(sid, subscriberAudioIcon); LayoutParams iParams = this.createIconLayoutParams(top, left, width, height); viewAdministrator.addView(this.cordova.getActivity(), _webView, subscriberAudioIcon, iParams); // Return to JS event handler return new PluginResult(PluginResult.Status.OK, String.format("subscribe [stream %s at (%d,%d), width %d, height %d (z-layer: %d)%s]", sid, left, top, width, height, zIndex, isSubscribeToVideo ? "" : " _disabled video_ ")); } else { // Return to JS event handler return new PluginResult(PluginResult.Status.ERROR, String.format( "could not subscribe to [stream %s at (%d,%d), width %d, height %d (z-layer: %d)%s] -- Reason: device is on pause.", sid, left, top, width, height, zIndex, isSubscribeToVideo ? "" : " _disabled video_ ")); } }
From source file:de.dfki.iui.opentok.cordova.plugin.OpenTokPlugin.java
License:Open Source License
private PluginResult doToggleAudio(String streamId) { PluginResult result = null;//from ww w . j ava 2 s . com if (_publisher != null && streamId.equals(ID_PUBLISHER)) { boolean newAudioSetting = !_publisher.getPublishAudio(); if (isInfo()) LOG.i(PLUGIN_NAME, String.format("Toggle audio for publisher: mute %s", newAudioSetting)); _publisher.setPublishAudio(newAudioSetting); doUpdateViewIconStatus(_publisherAudioIcon, getIconResourceForPublisherStatus(), getIconVisibilityForPublisherStatus()); result = new PluginResult(PluginResult.Status.OK, "toggleAudio [stream " + streamId + ", publisher]"); } Subscriber streamInfo = subscriberDictionary.get(streamId); if (streamInfo != null) { boolean newAudioSetting = !streamInfo.getSubscribeToAudio(); if (isInfo()) LOG.i(PLUGIN_NAME, String.format("Toggle audio for Subscriber (stream-ID: %s): mute %s", streamId, newAudioSetting)); streamInfo.setSubscribeToAudio(newAudioSetting); ImageView subscriberAudioIcon = subscriberAudioIconDictionary.get(streamId); doUpdateViewIconStatus(subscriberAudioIcon, getIconResourceForSubscriberStatus(streamInfo), getIconVisibilityForSubscriberStatus(streamInfo)); result = new PluginResult(PluginResult.Status.OK, "toggleAudio [stream " + streamId + ", subscriber]"); } if (result == null) { result = new PluginResult(PluginResult.Status.ERROR, "No Subscriber / Publisher for streamId " + streamId); } return result; }
From source file:de.dfki.iui.opentok.cordova.plugin.OpenTokPlugin.java
License:Open Source License
private PluginResult doRefresh(String streamId) { PluginResult result = null;/*from ww w.j ava2 s. co m*/ if (_publisher != null && streamId.equals(ID_PUBLISHER)) { boolean isAudio = _publisher.getPublishAudio(); boolean isVideo = _publisher.getPublishVideo(); _publisher.setPublishAudio(false); _publisher.setPublishVideo(false); _publisher.setPublishAudio(isAudio); _publisher.setPublishVideo(isVideo); //BUGFIX there seems to a problem, with the correct positioning ... trigger update through JavaScript: this.webView.sendJavascript( "if(typeof TB !== 'undefined' && TB.updateViews){ TB.updateViews(); } else {console.error('could not enfore view update for subscribers: missing TB.updateViews() function!');}"); if (isInfo()) LOG.i(PLUGIN_NAME, String.format("Refreshing view for publisher...")); result = new PluginResult(PluginResult.Status.OK, "refresh [stream " + streamId + ", publisher]"); } Subscriber streamInfo = subscriberDictionary.get(streamId); if (streamInfo != null) { //REFRESH: remove and re-add the subscriber ViewParams p = subscriberViewParams.get(streamId); doUnsubscribe(streamId); doSubscribe(streamId, p.top, p.left, p.width, p.height, streamInfo.getSubscribeToVideo(), p.zIndex); //BUGFIX there seems to a problem, with the correct positioning ... trigger update through JavaScript: this.webView.sendJavascript( "if(typeof TB !== 'undefined' && TB.updateViews){ TB.updateViews(); } else {console.error('could not enfore view update for subscribers: missing TB.updateViews() function!');}"); if (isInfo()) LOG.i(PLUGIN_NAME, String.format("Refreshing view for Subscriber (stream-ID: %s)...", streamId)); result = new PluginResult(PluginResult.Status.OK, "refresh [stream " + streamId + ", subscriber]"); } if (result == null) { result = new PluginResult(PluginResult.Status.ERROR, "No Subscriber / Publisher for streamId " + streamId); } return result; }