-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathsendMessage.html
More file actions
63 lines (57 loc) · 1.65 KB
/
Copy pathsendMessage.html
File metadata and controls
63 lines (57 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<html>
<head>
<script src='/_ah/channel/jsapi'></script>
</head>
<body>
<script type='text/javascript'>
// this is the app key to send to
var state = {
app_key: '{{ appid }}',
token: '{{ token }}',
msg: '{{message}}'
};
sendMessage = function(path) {
//alert("send called");
var xhr = new XMLHttpRequest();
xhr.open('POST', path, true);
xhr.send();
//console.log("message sent");
};
onOpened = function() {
//alert("on open called");
//console.log("connection opened");
sendMessage('/postmessage');
};
onMessage = function(m) {
alert('Message received ' + m.data);
};
openChannel = function() {
var token = '{{ token }}';
var channel = new goog.appengine.Channel(token);
var handler = {
'onopen': onOpened,
'onmessage': onMessage,
'onerror': function() {},
'onclose': function() {}
};
var socket = channel.open(handler);
socket.onopen = onOpened;
socket.onmessage = onMessage;
};
initialize = function() {
openChannel();
};
setTimeout(initialize, 100);
</script>
<div id='display-area'>
<h2>Send Message Channel Test App</h2>
Using token: {{token}}</br>
Sending to app key: {{appid}}</br>
Sending message: {{message}}</br>
<h3>Links:</h3>
<a href='/createchannel'>Create Channel</a>
<a href='/sendmessage'>Send Message</a>
<a href='/receivemessage'>Get Message</a>
</div>
</body>
</html>