-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
56 lines (47 loc) · 2.12 KB
/
index.html
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
<html>
<head>
<script type="text/javascript" src="https://talkgadget.google.com/talkgadget/channel.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</head>
<body >
<script>
openChannel = function () {
var emailId = document.getElementById("emailId").value;
var url = 'http://channel-api-1.appspot.com/createchannel';
$.post(url, {userId: emailId},
function (data, status) {
var token = data;
console.log("Recieved Token : " + token);
var channel = new goog.appengine.Channel(token);
var socket = channel.open();
socket.onopen = function () {
alert('open');
};
socket.onmessage = function (responseData) {
alert('Server Messge : ' + responseData.data);
console.log(responseData)
};
socket.onerror = function () {
alert('error');
};
socket.onclose = function () {
alert('close');
};
});
};
sendMessage = function () {
var url = 'http://channel-api-1.appspot.com/sendmessage';
var messageToId = document.getElementById("messageToId").value;
var message = document.getElementById("message").value;
$.post(url, {messageToId: messageToId,message:message},
function (data, status) {
});
};
</script>
Enter Email to create Channel : <input type="text" id="emailId">
<button onclick="openChannel()">Open Connection</button> <br><br><br>
Email of registered user to Send Message: <input type="text" id="messageToId"><br><br>
Message to send : <input type="text" id="message">
<button onclick="sendMessage()">Send Message</button>
</body>
</html>