-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_helloworld.js
60 lines (60 loc) · 1.86 KB
/
demo_helloworld.js
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
/// <reference path = "kfssdk.d.ts" />
function $(key) {
return document.querySelector(key);
}
var CHANNEL_NAME = "demo_helloworld";
function publish() {
var msg = $('#msg');
kfssdk.publish_channel_msg({
_channel: CHANNEL_NAME,
_sub_type: "say",
_msg: { data: msg.value }
});
msg.value = "";
msg.focus();
}
kfssdk.init({
appid: 100001,
appkey: "gjseabmtoljxeknc",
onready: function () {
kfssdk.create_channel({
_channel: CHANNEL_NAME,
_channel_option: {
_max_keep_msg_list_len: 20
},
_last_msg_len: 20
});
},
oncreate_channel: function (msg_body) {
var msg = $('#msg');
msg.readOnly = false;
msg.select();
msg.focus();
},
onpublish_channel_msg: function (msg_body) {
var data = JSON.stringify(msg_body);
$('#msg_list').value += data + "\r\n";
},
onmodify_channel: function (msg_body) {
if (msg_body._user_join) {
if (msg_body._channel === CHANNEL_NAME) {
$('#msg_list').value += "用户【" + msg_body._user_join + "】加入\r\n";
}
}
if (msg_body._user_leave) {
if (msg_body._channel === CHANNEL_NAME) {
$('#msg_list').value += "用户【" + msg_body._user_leave + "】离开\r\n";
}
}
if (msg_body._user_online) {
if (msg_body._channel === CHANNEL_NAME) {
$('#msg_list').value += "用户【" + msg_body._user_online + "】上线\r\n";
}
}
if (msg_body._user_offline) {
if (msg_body._channel === CHANNEL_NAME) {
$('#msg_list').value += "用户【" + msg_body._user_offline + "】离线\r\n";
}
}
}
});