-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
39 lines (33 loc) · 974 Bytes
/
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
<!DOCTYPE html>
<html>
<head>
<title>LiveStreaming</title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
</head>
<body>
Hello! Welcome to chatzy
<ul id="messages">
</ul>
<form id="new-message">
<input id="message-name" type="text" placeholder="Name" />
<input id="message-content" type="text"/>
<input type="submit" id="send-message"/>
</form>
</body>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost:3000');
socket.on('message', function (data) {
$("#messages").append($("<li>").text(data.name + ": " + data.content));
});
$('#new-message').submit(function() {
return false;
});
$("#send-message").click(function(e) {
var name = $("#message-name").val(),
content = $("#message-content").val();
$("#messages").append($("<li>").text(name + ": " + content));
socket.emit('messages.create', { name: name, content: content });
});
</script>
</html>