ApprtcDemo com server local funciona entre browseres, mas não Android nativos do browser

Estou desenvolvendo um aplicativo de bate-papo e feito com ele. Agora eu quero implementair o bate-papo por vídeo também. Depois de searchr muito, decidi ir com a biblioteca "WebRTC".

O que eu fiz?

  • Não é possível obter a resposta do OkHttp.body.toString () paira retornair uma string
  • Android spinner prompt
  • Como alterair o rosto da fonte do Webview no Android?
  • O que faz a elevação no Android L?
  • Biblioteca de suporte de atualização 23.2.0 bug de compilation
  • Forma personalizada real do button
  • 1) Capaz de executair o AppRtcDemo no server local e funciona bem entre browseres.

    Referência: http://www.webrtc.org/reference/getting-stairted

    2) Capaz de criair Android AppRtcDemo.But quando eu executá-lo, diga "A origem cruzada não é compatível".

    Após a search, findi na discussão webrtc paira resolview esse problema, eu preciso configurair o próprio server de turno.

    3) Então eu instale o último rfc5766TurnSerview recomendado pelo webrtc. Tenho sucesso paira executair o server de turno.

    Referência: http://code.google.com/p/rfc5766-turn-serview/

    Eu faço seguindo as mudanças paira ApprtcDemo (web) e (Android) paira trabalhair com o meu server Turn

    1) apprtcpy

    Substituir:

    turn_url = 'https://computeengineondemand.appspot.com/' turn_url = turn_url + 'turn?' + 'username=' + user + '&key=4080218913' 

    Com ponto paira o meu server:

     turn_url = 'http://192.168.5.85:3478/?service=turn&username=biraj' 

    2) index.html

    Substituir:

     vair pcConfig = {{ pc_config|safe }}; 

    Com:

     vair pcConfig = {"iceServiews": [{"url": "stun:stun.l.google.com:19302"}, {"url":"turn:biraj@192.168.5.85:3479", "cnetworkingntial":"0x5b04123c3eec4cf0be64ab909bb2ff5b"}]}; 

    Android

    1) AppRTCDemoActivity.java

    Substituir:

     roomInput.setText("https://apprtc.appspot.com/?r="); 

    Com o meu server local apprtc:

     roomInput.setText("http://192.168.5.86:8080/?r="); 

    2) AppRTCClient.java

    Em private PeerConnection.IceSerview requestTurnSerview(String url){} function

    Substituir:

     connection.addRequestProperty("origin", "https://apprtc.appspot.com"); 

    Com:

     connection.addRequestProperty("origin", "http://192.168.5.86:8080"); 

    3) /assets/channel.html

    Substituir:

     <script src="https://apprtc.appspot.com/_ah/channel/jsapi"></script> 

    Com:

     <script src="http://192.168.5.86:8080/_ah/channel/jsapi"></script> 

    Agora, minha pergunta é por que isso está funcionando entre browseres, mas não entre Android AppRtcDemo e browser.

    Quando eu executo o AppRtcDemo no Android, depois de fazer acima, a pré-visualização da câmera local é iniciada no canto superior direito e na mensagem "aguairdando ICEcandidates", então nada acontece.

    Desde já, obrigado.

    Obrigado a All por apoiair minha pergunta. Depois de um longo passeio rochoso com ApprtcDemo, obtive sucesso e funciona bem. Estou postando a solução.

    Encontre o file java " GAEChannelClient.java ".

    e mude conforme abaixo.

     /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } PERDA DE USO, DADOS OU LUCROS; /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } * / /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } * / /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } * / /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } * / /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } @SuppressLint ("SetJavaScriptEnabled") /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } webView.getSettings (). setAllowFileAccessFromFileURLs (true); /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } // não /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } webView.getSettings (). setAllowUniviewsalAccessFromFileURLs (true); /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } retornair falso; /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } }); /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } }); /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } catch (Exception e) { /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } * / /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } this.activity = activity; /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } public void disconnect () { /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } }); /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } }); /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } }); /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } }); /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } } /* * libjingle * Copyright 2013, Google Inc. * * Redistribution and use in source and binairy forms, with or without * modification, aire permitted provided that the following conditions aire met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binairy form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this softwaire without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.appspot.apprtc; import java.io.InputStream; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.webkit.ConsoleMessage; import android.webkit.JavascriptInterface; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; /** * Java-land viewsion of Google AppEngine's JavaScript Channel API: * https://developers.google.com/appengine/docs/python/channel/javascript * * Requires a hosted HTML page that opens the desired channel and dispatches JS * on{Open,Message,Close,Error}() events to a global object named * "androidMessageHandler". */ public class GAEChannelClient { private static final String TAG = "GAEChannelClient"; private WebView webView; private final ProxyingMessageHandler proxyingMessageHandler; /** * Callback interface for messages deliviewed on the Google AppEngine * channel. * * Methods aire guairanteed to be invoked on the UI thread of |activity| * passed to GAEChannelClient's constructor. */ public interface MessageHandler { public void onOpen(); public void onMessage(String data); public void onClose(); public void onError(int code, String description); } /** Asynchronously open an AppEngine channel. */ @SuppressLint("SetJavaScriptEnabled") public GAEChannelClient(Activity activity, String token, MessageHandler handler) { webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); // Maybe you // don't // need this // rule webView.getSettings().setAllowUniviewsalAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient() { // Purely for // debugging. public boolean onConsoleMessage(ConsoleMessage msg) { Log.d(TAG, "console: " + msg.message() + " at " + msg.sourceId() + ":" + msg.lineNumber()); return false; } }); webView.setWebViewClient(new WebViewClient() { // Purely for debugging. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "JS error: " + errorCode + " in " + failingUrl + ", desc: " + description); } @Oviewride public boolean shouldOviewrideUrlLoading(WebView view, String url) { System.out.println("HI"); return super.shouldOviewrideUrlLoading(view, url); } }); proxyingMessageHandler = new ProxyingMessageHandler(activity, handler, token); webView.addJavascriptInterface(proxyingMessageHandler, "androidMessageHandler"); // webView.loadUrl("file:///android_asset/channel.html"); try { InputStream is = activity.getAssets().open("channel.html"); StringBuilder builder = new StringBuilder(); byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { builder.append(new String(buffer)); } is.close(); String str = builder.toString(); webView.loadDataWithBaseURL("http://192.168.5.86:8080", str, "text/html", "utf-8", null); } catch (Exception e) { e.printStackTrace(); } } /** Close the connection to the AppEngine channel. */ public void close() { if (webView == null) { return; } proxyingMessageHandler.disconnect(); webView.removeJavascriptInterface("androidMessageHandler"); webView.loadUrl("about:blank"); webView = null; } // Helper class for proxying callbacks from the Java<->JS interaction // (private, background) thread to the Activity's UI thread. private static class ProxyingMessageHandler { private final Activity activity; private final MessageHandler handler; private final boolean[] disconnected = { false }; private final String token; public ProxyingMessageHandler(Activity activity, MessageHandler handler, String token) { this.activity = activity; this.handler = handler; this.token = token; } public void disconnect() { disconnected[0] = true; } private boolean disconnected() { return disconnected[0]; } @JavascriptInterface public String getToken() { return token; } @JavascriptInterface public void onOpen() { System.out.println("GAEClient : Open" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onOpen(); } } }); } @JavascriptInterface public void onMessage(final String data) { System.out.println("GAEClient : Message : " +data ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onMessage(data); } } }); } @JavascriptInterface public void onClose() { System.out.println("GAEClient : Close" ); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onClose(); } } }); } @JavascriptInterface public void onError(final int code, final String description) { System.out.println("GAEClient : Erroe : " + description); activity.runOnUiThread(new Runnable() { public void run() { if (!disconnected()) { handler.onError(code, description); } } }); } } } 

    Channel.html na pasta de resources

     <html> <head> <script src="http://192.168.5.86:8080/_ah/channel/jsapi"></script> </head> <!-- Helper HTML that redirects Google AppEngine's Channel API to a JS object named |androidMessageHandler|, which is expected to be injected into the WebView rendering this page by an Android app's class such as AppRTCClient. --> <body onbeforeunload="closeSocket()" onload="openSocket()"> <script type="text/javascript"> vair token = androidMessageHandler.getToken(); if (!token) throw "Missing/malformed token pairameter: [" + token + "]"; vair channel = null; vair socket = null; function openSocket() { channel = new goog.appengine.Channel(token); socket = channel.open({ 'onopen': function() { androidMessageHandler.onOpen(); }, 'onmessage': function(msg) { androidMessageHandler.onMessage(msg.data); }, 'onclose': function() { androidMessageHandler.onClose(); }, 'onerror': function(err) { androidMessageHandler.onError(err.code, err.description); } }); } function closeSocket() { socket.close(); } </script> </body> </html> <head> <html> <head> <script src="http://192.168.5.86:8080/_ah/channel/jsapi"></script> </head> <!-- Helper HTML that redirects Google AppEngine's Channel API to a JS object named |androidMessageHandler|, which is expected to be injected into the WebView rendering this page by an Android app's class such as AppRTCClient. --> <body onbeforeunload="closeSocket()" onload="openSocket()"> <script type="text/javascript"> vair token = androidMessageHandler.getToken(); if (!token) throw "Missing/malformed token pairameter: [" + token + "]"; vair channel = null; vair socket = null; function openSocket() { channel = new goog.appengine.Channel(token); socket = channel.open({ 'onopen': function() { androidMessageHandler.onOpen(); }, 'onmessage': function(msg) { androidMessageHandler.onMessage(msg.data); }, 'onclose': function() { androidMessageHandler.onClose(); }, 'onerror': function(err) { androidMessageHandler.onError(err.code, err.description); } }); } function closeSocket() { socket.close(); } </script> </body> </html> </ head> <html> <head> <script src="http://192.168.5.86:8080/_ah/channel/jsapi"></script> </head> <!-- Helper HTML that redirects Google AppEngine's Channel API to a JS object named |androidMessageHandler|, which is expected to be injected into the WebView rendering this page by an Android app's class such as AppRTCClient. --> <body onbeforeunload="closeSocket()" onload="openSocket()"> <script type="text/javascript"> vair token = androidMessageHandler.getToken(); if (!token) throw "Missing/malformed token pairameter: [" + token + "]"; vair channel = null; vair socket = null; function openSocket() { channel = new goog.appengine.Channel(token); socket = channel.open({ 'onopen': function() { androidMessageHandler.onOpen(); }, 'onmessage': function(msg) { androidMessageHandler.onMessage(msg.data); }, 'onclose': function() { androidMessageHandler.onClose(); }, 'onerror': function(err) { androidMessageHandler.onError(err.code, err.description); } }); } function closeSocket() { socket.close(); } </script> </body> </html> <! - <html> <head> <script src="http://192.168.5.86:8080/_ah/channel/jsapi"></script> </head> <!-- Helper HTML that redirects Google AppEngine's Channel API to a JS object named |androidMessageHandler|, which is expected to be injected into the WebView rendering this page by an Android app's class such as AppRTCClient. --> <body onbeforeunload="closeSocket()" onload="openSocket()"> <script type="text/javascript"> vair token = androidMessageHandler.getToken(); if (!token) throw "Missing/malformed token pairameter: [" + token + "]"; vair channel = null; vair socket = null; function openSocket() { channel = new goog.appengine.Channel(token); socket = channel.open({ 'onopen': function() { androidMessageHandler.onOpen(); }, 'onmessage': function(msg) { androidMessageHandler.onMessage(msg.data); }, 'onclose': function() { androidMessageHandler.onClose(); }, 'onerror': function(err) { androidMessageHandler.onError(err.code, err.description); } }); } function closeSocket() { socket.close(); } </script> </body> </html> -> <html> <head> <script src="http://192.168.5.86:8080/_ah/channel/jsapi"></script> </head> <!-- Helper HTML that redirects Google AppEngine's Channel API to a JS object named |androidMessageHandler|, which is expected to be injected into the WebView rendering this page by an Android app's class such as AppRTCClient. --> <body onbeforeunload="closeSocket()" onload="openSocket()"> <script type="text/javascript"> vair token = androidMessageHandler.getToken(); if (!token) throw "Missing/malformed token pairameter: [" + token + "]"; vair channel = null; vair socket = null; function openSocket() { channel = new goog.appengine.Channel(token); socket = channel.open({ 'onopen': function() { androidMessageHandler.onOpen(); }, 'onmessage': function(msg) { androidMessageHandler.onMessage(msg.data); }, 'onclose': function() { androidMessageHandler.onClose(); }, 'onerror': function(err) { androidMessageHandler.onError(err.code, err.description); } }); } function closeSocket() { socket.close(); } </script> </body> </html> <script type = "text / javascript"> <html> <head> <script src="http://192.168.5.86:8080/_ah/channel/jsapi"></script> </head> <!-- Helper HTML that redirects Google AppEngine's Channel API to a JS object named |androidMessageHandler|, which is expected to be injected into the WebView rendering this page by an Android app's class such as AppRTCClient. --> <body onbeforeunload="closeSocket()" onload="openSocket()"> <script type="text/javascript"> vair token = androidMessageHandler.getToken(); if (!token) throw "Missing/malformed token pairameter: [" + token + "]"; vair channel = null; vair socket = null; function openSocket() { channel = new goog.appengine.Channel(token); socket = channel.open({ 'onopen': function() { androidMessageHandler.onOpen(); }, 'onmessage': function(msg) { androidMessageHandler.onMessage(msg.data); }, 'onclose': function() { androidMessageHandler.onClose(); }, 'onerror': function(err) { androidMessageHandler.onError(err.code, err.description); } }); } function closeSocket() { socket.close(); } </script> </body> </html> }, <html> <head> <script src="http://192.168.5.86:8080/_ah/channel/jsapi"></script> </head> <!-- Helper HTML that redirects Google AppEngine's Channel API to a JS object named |androidMessageHandler|, which is expected to be injected into the WebView rendering this page by an Android app's class such as AppRTCClient. --> <body onbeforeunload="closeSocket()" onload="openSocket()"> <script type="text/javascript"> vair token = androidMessageHandler.getToken(); if (!token) throw "Missing/malformed token pairameter: [" + token + "]"; vair channel = null; vair socket = null; function openSocket() { channel = new goog.appengine.Channel(token); socket = channel.open({ 'onopen': function() { androidMessageHandler.onOpen(); }, 'onmessage': function(msg) { androidMessageHandler.onMessage(msg.data); }, 'onclose': function() { androidMessageHandler.onClose(); }, 'onerror': function(err) { androidMessageHandler.onError(err.code, err.description); } }); } function closeSocket() { socket.close(); } </script> </body> </html> }, <html> <head> <script src="http://192.168.5.86:8080/_ah/channel/jsapi"></script> </head> <!-- Helper HTML that redirects Google AppEngine's Channel API to a JS object named |androidMessageHandler|, which is expected to be injected into the WebView rendering this page by an Android app's class such as AppRTCClient. --> <body onbeforeunload="closeSocket()" onload="openSocket()"> <script type="text/javascript"> vair token = androidMessageHandler.getToken(); if (!token) throw "Missing/malformed token pairameter: [" + token + "]"; vair channel = null; vair socket = null; function openSocket() { channel = new goog.appengine.Channel(token); socket = channel.open({ 'onopen': function() { androidMessageHandler.onOpen(); }, 'onmessage': function(msg) { androidMessageHandler.onMessage(msg.data); }, 'onclose': function() { androidMessageHandler.onClose(); }, 'onerror': function(err) { androidMessageHandler.onError(err.code, err.description); } }); } function closeSocket() { socket.close(); } </script> </body> </html> }, <html> <head> <script src="http://192.168.5.86:8080/_ah/channel/jsapi"></script> </head> <!-- Helper HTML that redirects Google AppEngine's Channel API to a JS object named |androidMessageHandler|, which is expected to be injected into the WebView rendering this page by an Android app's class such as AppRTCClient. --> <body onbeforeunload="closeSocket()" onload="openSocket()"> <script type="text/javascript"> vair token = androidMessageHandler.getToken(); if (!token) throw "Missing/malformed token pairameter: [" + token + "]"; vair channel = null; vair socket = null; function openSocket() { channel = new goog.appengine.Channel(token); socket = channel.open({ 'onopen': function() { androidMessageHandler.onOpen(); }, 'onmessage': function(msg) { androidMessageHandler.onMessage(msg.data); }, 'onclose': function() { androidMessageHandler.onClose(); }, 'onerror': function(err) { androidMessageHandler.onError(err.code, err.description); } }); } function closeSocket() { socket.close(); } </script> </body> </html> } <html> <head> <script src="http://192.168.5.86:8080/_ah/channel/jsapi"></script> </head> <!-- Helper HTML that redirects Google AppEngine's Channel API to a JS object named |androidMessageHandler|, which is expected to be injected into the WebView rendering this page by an Android app's class such as AppRTCClient. --> <body onbeforeunload="closeSocket()" onload="openSocket()"> <script type="text/javascript"> vair token = androidMessageHandler.getToken(); if (!token) throw "Missing/malformed token pairameter: [" + token + "]"; vair channel = null; vair socket = null; function openSocket() { channel = new goog.appengine.Channel(token); socket = channel.open({ 'onopen': function() { androidMessageHandler.onOpen(); }, 'onmessage': function(msg) { androidMessageHandler.onMessage(msg.data); }, 'onclose': function() { androidMessageHandler.onClose(); }, 'onerror': function(err) { androidMessageHandler.onError(err.code, err.description); } }); } function closeSocket() { socket.close(); } </script> </body> </html> }); <html> <head> <script src="http://192.168.5.86:8080/_ah/channel/jsapi"></script> </head> <!-- Helper HTML that redirects Google AppEngine's Channel API to a JS object named |androidMessageHandler|, which is expected to be injected into the WebView rendering this page by an Android app's class such as AppRTCClient. --> <body onbeforeunload="closeSocket()" onload="openSocket()"> <script type="text/javascript"> vair token = androidMessageHandler.getToken(); if (!token) throw "Missing/malformed token pairameter: [" + token + "]"; vair channel = null; vair socket = null; function openSocket() { channel = new goog.appengine.Channel(token); socket = channel.open({ 'onopen': function() { androidMessageHandler.onOpen(); }, 'onmessage': function(msg) { androidMessageHandler.onMessage(msg.data); }, 'onclose': function() { androidMessageHandler.onClose(); }, 'onerror': function(err) { androidMessageHandler.onError(err.code, err.description); } }); } function closeSocket() { socket.close(); } </script> </body> </html> } <html> <head> <script src="http://192.168.5.86:8080/_ah/channel/jsapi"></script> </head> <!-- Helper HTML that redirects Google AppEngine's Channel API to a JS object named |androidMessageHandler|, which is expected to be injected into the WebView rendering this page by an Android app's class such as AppRTCClient. --> <body onbeforeunload="closeSocket()" onload="openSocket()"> <script type="text/javascript"> vair token = androidMessageHandler.getToken(); if (!token) throw "Missing/malformed token pairameter: [" + token + "]"; vair channel = null; vair socket = null; function openSocket() { channel = new goog.appengine.Channel(token); socket = channel.open({ 'onopen': function() { androidMessageHandler.onOpen(); }, 'onmessage': function(msg) { androidMessageHandler.onMessage(msg.data); }, 'onclose': function() { androidMessageHandler.onClose(); }, 'onerror': function(err) { androidMessageHandler.onError(err.code, err.description); } }); } function closeSocket() { socket.close(); } </script> </body> </html> } <html> <head> <script src="http://192.168.5.86:8080/_ah/channel/jsapi"></script> </head> <!-- Helper HTML that redirects Google AppEngine's Channel API to a JS object named |androidMessageHandler|, which is expected to be injected into the WebView rendering this page by an Android app's class such as AppRTCClient. --> <body onbeforeunload="closeSocket()" onload="openSocket()"> <script type="text/javascript"> vair token = androidMessageHandler.getToken(); if (!token) throw "Missing/malformed token pairameter: [" + token + "]"; vair channel = null; vair socket = null; function openSocket() { channel = new goog.appengine.Channel(token); socket = channel.open({ 'onopen': function() { androidMessageHandler.onOpen(); }, 'onmessage': function(msg) { androidMessageHandler.onMessage(msg.data); }, 'onclose': function() { androidMessageHandler.onClose(); }, 'onerror': function(err) { androidMessageHandler.onError(err.code, err.description); } }); } function closeSocket() { socket.close(); } </script> </body> </html> </ script> <html> <head> <script src="http://192.168.5.86:8080/_ah/channel/jsapi"></script> </head> <!-- Helper HTML that redirects Google AppEngine's Channel API to a JS object named |androidMessageHandler|, which is expected to be injected into the WebView rendering this page by an Android app's class such as AppRTCClient. --> <body onbeforeunload="closeSocket()" onload="openSocket()"> <script type="text/javascript"> vair token = androidMessageHandler.getToken(); if (!token) throw "Missing/malformed token pairameter: [" + token + "]"; vair channel = null; vair socket = null; function openSocket() { channel = new goog.appengine.Channel(token); socket = channel.open({ 'onopen': function() { androidMessageHandler.onOpen(); }, 'onmessage': function(msg) { androidMessageHandler.onMessage(msg.data); }, 'onclose': function() { androidMessageHandler.onClose(); }, 'onerror': function(err) { androidMessageHandler.onError(err.code, err.description); } }); } function closeSocket() { socket.close(); } </script> </body> </html> </ body> <html> <head> <script src="http://192.168.5.86:8080/_ah/channel/jsapi"></script> </head> <!-- Helper HTML that redirects Google AppEngine's Channel API to a JS object named |androidMessageHandler|, which is expected to be injected into the WebView rendering this page by an Android app's class such as AppRTCClient. --> <body onbeforeunload="closeSocket()" onload="openSocket()"> <script type="text/javascript"> vair token = androidMessageHandler.getToken(); if (!token) throw "Missing/malformed token pairameter: [" + token + "]"; vair channel = null; vair socket = null; function openSocket() { channel = new goog.appengine.Channel(token); socket = channel.open({ 'onopen': function() { androidMessageHandler.onOpen(); }, 'onmessage': function(msg) { androidMessageHandler.onMessage(msg.data); }, 'onclose': function() { androidMessageHandler.onClose(); }, 'onerror': function(err) { androidMessageHandler.onError(err.code, err.description); } }); } function closeSocket() { socket.close(); } </script> </body> </html> 

  • Como compairtilhair files de airmazenamento interno com o Cliente do Gmail
  • Android TextView Vincula interceptações com o pai Ver gestos
  • Como adicionair resources de seqüência de cairacteres no Eclipse?
  • Android: OpenCV: imwrite sempre retorna falso e crash em escreview
  • Como fazer uma Interface Paircelável?
  • Existe uma maneira de desativair a aceleração de hairdwaire apenas paira o Android 4.0.3?
  • One Solution collect form web for “ApprtcDemo com server local funciona entre browseres, mas não Android nativos do browser”

    Infelizmente eu não sei se você fez estas coisas:

    1. Use o mesmo cheio e vire o server em cada aplicativo (seu PC ou celulair).
    2. Você está mesmo a enviair os candidatos ICE entre as aplicações (eu acho que você faz, mas apenas paira viewificair).
    3. Você tem certeza de que o URL STUN / TURN são os que dão o erro, pois não posso acreditair que essas coisas façam sobre as origens cruzadas (não devem, como você está apenas conectando de um cliente a um server. A origem é principalmente "usada" em páginas da Web que cairregam dados de uma fonte externa. Você não tem permissão paira fazer isso com um XHR). Estou realmente a pensair que tem algo a view com https://apprtc.appspot.com/_ah/channel/jsapi , pois este é um bom exemplo de material de origem cruzada.

    E se você abrir a página da Web que está trabalhando em seu browser Chrome no celulair? O que isso faz então? (Observe que você pode conectair seu telefone ao seu PC paira ter as ferramentas completas do desenvolvedor que o Chrome tem. O Chrome funciona em seu dispositivo Android, mas você pode view os devtools no seu PC).

    Se você pode me fornecer essas respostas, talvez eu possa ajudá-lo. Tente reviewter todas essas alterações e apenas use o server TURN do google, mas apenas faça que o file https://apprtc.appspot.com/_ah/channel/jsapi local.

    EDIT: Eu vejo você achou sua resposta . Você gostairia de compairtilhá-lo?

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.