forked from pubnub/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat.html
More file actions
34 lines (30 loc) · 994 Bytes
/
Copy pathchat.html
File metadata and controls
34 lines (30 loc) · 994 Bytes
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
<!-- Hey, let's be friends! http://twitter.com/pubnub -->
Enter Chat and press enter
<div><input id=input placeholder=chat-here></div>
<code>Chat Output</code>
<div id=box></div>
<div id=pubnub pub-key=demo sub-key=demo></div>
<script src=../../web/pubnub.min.js></script>
<script src=sound.js></script>
<script>(function(){
var box = PUBNUB.$('box'), input = PUBNUB.$('input'), channel = 'chatlllll';
PUBNUB.subscribe({
channel : channel,
callback : function(text) {
// PLAY SOUND HERE
sounds.play('chat');
// UPDATE TEXT OUTPUT HERE
box.innerHTML =
(''+text).replace( /[<>]/g, '' ) +
'<br>' +
box.innerHTML;
}
});
PUBNUB.bind( 'keyup', input, function(e) {
(e.keyCode || e.charCode) === 13 && PUBNUB.publish({
channel : channel,
message : input.value,
x : (input.value='')
});
});
})();</script>