-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.html
67 lines (51 loc) · 1.45 KB
/
index.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
<!DOCTYPE HTML>
<html>
<head>
<meta charset=utf-8>
<script language="JavaScript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js" ></script>
<script src="https://comet-server.com/CometServerApi.js" type="text/javascript"></script>
<style>
pre{
border: 1px solid #ccc;
padding: 5px;
background-color: #EEE;
}
</style>
</head>
<body>
<div id="web_chat"></div>
<div>
Name :<input type="text" id="name"><br><br>
Text: <textarea id="text"></textarea><br>
<input type="button" onclick="send();" value="send" ><br>
</div>
<script type="text/javascript">
$(document).ready(function()
{
cometApi.start({node:"app.comet-server.ru", dev_id:15 })
cometApi.subscription("simplechat.newMessage", function(event){
$("#web_chat").append('<b>'+HtmlEncode(event.data.name)+'</b>')
$("#web_chat").append('<pre>'+HtmlEncode(event.data.text)+'</pre>')
$("#web_chat").append('<br>')
})
})
function HtmlEncode(s)
{
var el = document.createElement("div");
el.innerText = el.textContent = s;
s = el.innerHTML;
return s;
}
function send()
{
var name = $('#name').val();
var text = $('#text').val();
$.ajax({
url: "https://comet-server.com/doc/CppComet/chat-example/chat.php",
type: "POST",
data:"text="+encodeURIComponent(text)+"&name="+encodeURIComponent(name)
});
}
</script>
</body>
</html>