-
Notifications
You must be signed in to change notification settings - Fork 1
/
chat.html
71 lines (65 loc) · 1.63 KB
/
chat.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<h1>Disket Chat Messenger</h1>
<div class="config">
<br>
<div class="text">Username:
<div><input id=nickname placeholder="nickname" /></div>
</div>
<div class="text">Send a Message:
<div><input id=input placeholder="message" /></div>
</div>
<br>
</div>
Chat:
<div id=box></div>
<script src=https://cdn.pubnub.com/sdk/javascript/pubnub.4.28.2.min.js></script>
<script> (function() {
var pubnub = new PubNub({
publishKey: 'pub-c-ec96b6b0-7c46-4585-a368-a465e894a785',
subscribeKey: 'sub-c-11399786-25ec-442f-b2cf-37553c458d8b'
});
function $(id) {
return document.getElementById(id);
}
var box = $('box'),
input = $('input'),
nickname = $('nickname'),
channel = '10chat-demo';
pubnub.addListener({
message: function(obj) {
box.innerHTML = ('' + obj.message).replace(/[<>]/g, '') + '<br>' + box.innerHTML
}
});
pubnub.subscribe({
channels: [channel]
});
input.addEventListener('keyup', function(e) {
if ((e.keyCode || e.charCode) === 13) {
pubnub.publish({
channel: channel,
message: nickname.value+": "+input.value,
x: (input.value = '')
});
}
});
})();
</script>
<style>
input{
border-radius:10px;
border:solid;
border-width:1px;
}
.config{
border-radius:20px;
background-color:darkgray;
width:300px;
}
body{
background-color:black;
color:white;
font-family:monospace;
}
.text{
margin-left:20px;
}
</style>