forked from pubnub/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple-chat.html
More file actions
31 lines (28 loc) · 884 Bytes
/
Copy pathsimple-chat.html
File metadata and controls
31 lines (28 loc) · 884 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
Enter Chat and press enter
<div><input id=input placeholder=you-chat-here /></div>
<div id=box></div>
<div id=pubnub pub-key=demo sub-key=demo></div>
<script src=../../web/pubnub.min.js></script>
<script>(function(){
var box = PUBNUB.$('box')
, input = PUBNUB.$('input')
, channel = 'chat';
// HANDLE TEXT MESSAGE
function chat_receive(text) {
box.innerHTML = (''+text).replace( /[<>]/g, '' ) +
'<br>' + box.innerHTML;
}
// OPEN SOCKET TO RECEIVE TEXT MESSAGE
PUBNUB.subscribe({
channel : channel,
message : chat_receive
});
// SEND TEXT MESSAGE
PUBNUB.bind( 'keyup', input, function(e) {
(e.keyCode || e.charCode) === 13 && PUBNUB.publish({
channel : channel,
message : input.value,
x : (input.value='')
});
} );
})();</script>