-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush.html
45 lines (39 loc) · 1.49 KB
/
push.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Tui Innovation Push Test Site</title>
<script src="http://54.246.80.107:8080/socket.io/socket.io.js"></script>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
var socket = io.connect('http://54.246.80.107:8080');
if (!window.console) console = {log: function() {}};
function broadcastMessage()
{
console.log('Broadcasting message: ' + $('#textmessage').val());
socket.emit('client',{message: $('#textmessage').val()});
return false;
}
//Log first message for debugging purposes
socket.on('news', function (data) {
console.log(data);
});
// on every message recived we print the new datas inside the #container div
socket.on('notification', function (data) {
console.log ("updating labels...");
$('#container').html('Last Message: ' + data.message);
$('#time').html('Last Update: ' + data.time);
});
</script>
</head>
<body>
<div id="container">Last message shown here</div>
<div id="time">Last update shown here</div>
<h4>Send new message</h4>
<form name="sendMessage" id="messageForm" onSubmit="return broadcastMessage()" action="javascript:broadcastMessage()">
message: <input name="message" id="textmessage" type="text" /> </br>
<input type="submit" />
</form>
</body>
<script>
</script>