Added an android_channel.html reflector page to allow Android apps to use a
WebView to speak the Channel API from Google AppEngine. BUG=webrtc:1169 Review URL: https://webrtc-codereview.appspot.com/1145006 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3644 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
23da8622c0
commit
a33037ea6c
54
samples/js/apprtc/html/android_channel.html
Normal file
54
samples/js/apprtc/html/android_channel.html
Normal file
@ -0,0 +1,54 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="/_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">
|
||||
// QueryString is copy/pasta from
|
||||
// chromium's chrome/test/data/media/html/utils.js.
|
||||
var QueryString = function () {
|
||||
// Allows access to query parameters on the URL; e.g., given a URL like:
|
||||
// http://<url>/my.html?test=123&bob=123
|
||||
// parameters can now be accessed via QueryString.test or QueryString.bob.
|
||||
var params = {};
|
||||
|
||||
// RegEx to split out values by &.
|
||||
var r = /([^&=]+)=?([^&]*)/g;
|
||||
|
||||
// Lambda function for decoding extracted match values. Replaces '+' with
|
||||
// space so decodeURIComponent functions properly.
|
||||
function d(s) { return decodeURIComponent(s.replace(/\+/g, ' ')); }
|
||||
|
||||
var match;
|
||||
while (match = r.exec(window.location.search.substring(1)))
|
||||
params[d(match[1])] = d(match[2]);
|
||||
|
||||
return params;
|
||||
} ();
|
||||
|
||||
var channel = null;
|
||||
var socket = null;
|
||||
|
||||
function openSocket() {
|
||||
if (!QueryString.token || !QueryString.token.match(/^[A-z0-9_-]+$/))
|
||||
throw "Missing/malformed token parameter: " + QueryString.token;
|
||||
channel = new goog.appengine.Channel(QueryString.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>
|
@ -130,6 +130,8 @@
|
||||
miniVideo = document.getElementById("miniVideo");
|
||||
remoteVideo = document.getElementById("remoteVideo");
|
||||
resetStatus();
|
||||
// NOTE: AppRTCClient.java searches & parses this line; update there when
|
||||
// changing here.
|
||||
openChannel('{{ token }}');
|
||||
doGetUserMedia();
|
||||
}
|
||||
@ -250,6 +252,8 @@
|
||||
function sendMessage(message) {
|
||||
var msgString = JSON.stringify(message);
|
||||
console.log('C->S: ' + msgString);
|
||||
// NOTE: AppRTCClient.java searches & parses this line; update there when
|
||||
// changing here.
|
||||
path = '/message?r={{ room_key }}' + '&u={{ me }}';
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', path, true);
|
||||
|
Loading…
Reference in New Issue
Block a user