-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathshout.html
53 lines (43 loc) · 1.21 KB
/
shout.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
<!DOCTYPE HTML>
<html>
<head>
<link href="/style.css" rel="stylesheet" type="text/css">
<title>Shout</title>
</head>
<body>
<div id="container">
<div>Tell others to connect to <a href="">here</a> and shout at each other via ShareJS.</div>
<p>
<input type="text" id="input" placeholder="Shout something…"/>
<input type="button" id="shout" value="shout"/>
<p>
<ul id='shouts' class='content'></div>
</div>
<script src="/channel/bcsocket.js"></script>
<script src="/share/share.uncompressed.js"></script>
<script>
sharejs.open('hello', 'text', function(error, doc) {
var input = document.getElementById('input'),
shout = document.getElementById('shout'),
shouts = document.getElementById('shouts');
function addShout(txt) {
li = document.createElement('li');
li.textContent = txt;
shouts.appendChild(li);
}
function shoutOut() {
var s = input.value;
input.value = '';
doc.shout(s);
addShout('You shouted "' + s + '"');
}
input.focus();
shout.onclick = input.onchange = shoutOut;
doc.on('shout', function (msg) {
addShout('You hear "' + msg + '"');
});
addShout('Connected');
});
</script>
</body>
</html>