Java tutorial
package com.google.gwt.tok.client; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.tok.client.event.ExceptionEvent; import com.google.gwt.tok.client.handler.ExceptionHandler; import com.google.gwt.tok.client.util.EventDispatcher; public class TokBox extends EventDispatcher { public static TokBox getInstance() { TokBox tokBox = new TokBox(); tokBox.initEventListeners(); return tokBox; } private TokBox() { } /** * Checks if the system supports the Tok API. * * @return true if the system supports the API, false otherwise */ public static native boolean supportRequirements() /*-{ if ($wnd.TB.checkSystemRequirements() == 1) { return true; } else { return false; } }-*/; /** * Initializes and returns a DeviceManager * * @param apiKey * The API key that TokBox provided you when you registered for * the OpenTok API. * @return A DeviceManager, with which you can manage cameras and * microphones for published streams. */ public DeviceManager initDeviceManager(String apiKey) { return new DeviceManager(this._initDeviceManager(apiKey)); } private native JavaScriptObject _initDeviceManager(String apiKey) /*-{ return $wnd.TB.initDeviceManager(apiKey); }-*/; /** * Initializes and returns a RecorderManager * * @param apiKey * The API key that TokBox provided you when you registered for * the OpenTok API. * @return A RecorderManager object, with which you can record and play back * stand-alone archives. */ public RecorderManager initRecorderManager(String apiKey) { return new RecorderManager(this._initRecorderManager(apiKey)); } private native JavaScriptObject _initRecorderManager(String apiKey) /*-{ return TB.initRecorderManager(apiKey); }-*/; /** * Initializes and returns the local session object for a specified session * ID. * * The TB.initSession() method performs setup local to the browser and * readies the web page for connecting to the session. You connect to the * session using the connect() method of the Session object returned by the * TB.initSession() method. Note that calling TB.initSession() does not * initiate communications with the cloud. It simply initializes the Session * object that you can use to connect (and to perform other operations once * connected). * * @param sessionId * Session ID generated by TokBox that represents the session to * which you are planning to connect. * @return The session object through which all further interactions with * the session will occur. */ public Session initSession(String sessionId) { Session session = new Session(this._initSession(sessionId)); session.initEventListeners(); return session; } private native JavaScriptObject _initSession(String sessionId) /*-{ return $wnd.TB.initSession(sessionId); }-*/; /** * Event listener */ private native void initEventListeners() /*-{ $wnd.TB.addEventListener("exception", exceptionHandler); function exceptionHandler(event) { this.@com.google.gwt.tok.client.TokBox::onException(Lcom/google/gwt/core/client/JavaScriptObject;)(event); } }-*/; private void onException(JavaScriptObject jso) { this.fireEvent(new ExceptionEvent(jso)); } /** * Add an {@link ExceptionHandler} listening to {@link ExceptionEvent} * * @param handler * @return */ public HandlerRegistration addExceptionHandler(ExceptionHandler handler) { return this.addHandler(ExceptionEvent.TYPE, handler); } /** * Remove an {@link ExceptionHandler} * * @param handler */ public void removeExceptionHandler(ExceptionHandler handler) { this.removeHandler(ExceptionEvent.TYPE, handler); } /* * -------------------------- - Logging -------------------------- */ // TODO log // public static String DEBUG; // public static String ERROR; // public static String WARN; // public static String INFO; // public static String NONE; // public native void setLogLevel(String logLevel) /*-{ // TB.setLogLevel(logLevel); // }-*/; // // public native void initLogLevels() /*-{ // this.@com.google.gwt.tok.client.TokBox::DEBUG = TB.DEBUG; // this.@com.google.gwt.tok.client.TokBox::ERROR = TB.ERROR; // this.@com.google.gwt.tok.client.TokBox::WARN = TB.WARN; // this.@com.google.gwt.tok.client.TokBox::INFO = TB.INFO; // this.@com.google.gwt.tok.client.TokBox::NONE = TB.NONE; // }-*/; }