blob: 86c2b440325a3bd9a794a07ec6c56e5d3d07af2f [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001<html>
2 <head>
3 <script src="https://apprtc.appspot.com/_ah/channel/jsapi"></script>
4 </head>
5 <!--
6 Helper HTML that redirects Google AppEngine's Channel API to a JS object named
7 |androidMessageHandler|, which is expected to be injected into the WebView
8 rendering this page by an Android app's class such as AppRTCClient
9 -->
10 <body onbeforeunload="closeSocket()" onload="openSocket()">
11 <script type="text/javascript">
12 // QueryString is copy/pasta from
13 // chromium's chrome/test/data/media/html/utils.js.
14 var QueryString = function () {
15 // Allows access to query parameters on the URL; e.g., given a URL like:
16 // http://<url>/my.html?test=123&bob=123
17 // parameters can now be accessed via QueryString.test or QueryString.bob.
18 var params = {};
19
20 // RegEx to split out values by &.
21 var r = /([^&=]+)=?([^&]*)/g;
22
23 // Lambda function for decoding extracted match values. Replaces '+' with
24 // space so decodeURIComponent functions properly.
25 function d(s) { return decodeURIComponent(s.replace(/\+/g, ' ')); }
26
27 var match;
28 while (match = r.exec(window.location.search.substring(1)))
29 params[d(match[1])] = d(match[2]);
30
31 return params;
32 } ();
33
34 var channel = null;
35 var socket = null;
36
37 function openSocket() {
38 if (!QueryString.token || !QueryString.token.match(/^[A-z0-9_-]+$/))
39 throw "Missing/malformed token parameter: " + QueryString.token;
40 channel = new goog.appengine.Channel(QueryString.token);
41 socket = channel.open({
42 'onopen': function() { androidMessageHandler.onOpen(); },
43 'onmessage': function(msg) { androidMessageHandler.onMessage(msg.data); },
44 'onclose': function() { androidMessageHandler.onClose(); },
45 'onerror': function(err) { androidMessageHandler.onError(err.code, err.description); }
46 });
47 }
48
49 function closeSocket() {
50 socket.close();
51 }
52 </script>
53 </body>
54</html>