henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | <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 |
fischman@webrtc.org | 147d44a | 2013-07-29 19:07:33 +0000 | [diff] [blame] | 8 | rendering this page by an Android app's class such as AppRTCClient. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | --> |
| 10 | <body onbeforeunload="closeSocket()" onload="openSocket()"> |
| 11 | <script type="text/javascript"> |
fischman@webrtc.org | 147d44a | 2013-07-29 19:07:33 +0000 | [diff] [blame] | 12 | var token = androidMessageHandler.getToken(); |
| 13 | if (!token) |
| 14 | throw "Missing/malformed token parameter: [" + token + "]"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 15 | |
| 16 | var channel = null; |
| 17 | var socket = null; |
| 18 | |
| 19 | function openSocket() { |
fischman@webrtc.org | 147d44a | 2013-07-29 19:07:33 +0000 | [diff] [blame] | 20 | channel = new goog.appengine.Channel(token); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 21 | socket = channel.open({ |
| 22 | 'onopen': function() { androidMessageHandler.onOpen(); }, |
| 23 | 'onmessage': function(msg) { androidMessageHandler.onMessage(msg.data); }, |
| 24 | 'onclose': function() { androidMessageHandler.onClose(); }, |
| 25 | 'onerror': function(err) { androidMessageHandler.onError(err.code, err.description); } |
| 26 | }); |
| 27 | } |
| 28 | |
| 29 | function closeSocket() { |
| 30 | socket.close(); |
| 31 | } |
| 32 | </script> |
| 33 | </body> |
| 34 | </html> |