-
Notifications
You must be signed in to change notification settings - Fork 0
/
socket.io.demo.html
53 lines (41 loc) · 1.45 KB
/
socket.io.demo.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
<!doctype html>
<html>
<head>
<title>Socket.IO demo</title>
</head>
<body>
<h1>Socket.IO demo</h1>
<input type="text" autofocus="autofocus" />
<button type="button">publish</button>
<button type="button">broadcast</button>
<button type="button">whisper</button>
<p>Status: <span id="status">Undefined</span></p>
<ol id="messages"></ol>
<script src="/socket.io/socket.io.js"></script>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js"></script>
<script type="text/coffeescript">
jQuery ($) ->
$status = $ '#status'
socket = io.connect()
socket.on 'connect', ->
$status.text 'Connected'
socket.on 'disconnect', ->
$status.text 'Disconnected'
socket.on 'reconnecting', (seconds) ->
$status.text "Reconnecting in #{seconds} seconds"
socket.on 'reconnect', ->
$status.text 'Reconnected'
socket.on 'reconnect_failed', ->
$status.text 'Failed to reconnect'
socket.on 'message', (message) ->
$('<textarea>').text(message).appendTo $('#messages')
socket.on 'secret', (message) ->
console.log message
$input = $ 'input'
$('button').click ->
socket.emit $(this).text(), $input.val()
$input.val('').focus()
</script>
</body>
</html>