send_custom_msg.js
1.81 KB
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
//弹出发自定义消息对话框
function showEditCustomMsgDialog() {
$('#ecm_form')[0].reset();
$('#edit_custom_msg_dialog').modal('show');
}
//发送自定义消息
function sendCustomMsg() {
if (!selToID) {
alert("您还没有好友或群组,暂不能聊天");
return;
}
var data = $("#ecm_data").val();
var desc = $("#ecm_desc").val();
var ext = $("#ecm_ext").val();
var msgLen = webim.Tool.getStrBytes(data);
if (data.length < 1) {
alert("发送的消息不能为空!");
return;
}
var maxLen, errInfo;
if (selType == webim.SESSION_TYPE.C2C) {
maxLen = webim.MSG_MAX_LENGTH.C2C;
errInfo = "消息长度超出限制(最多" + Math.round(maxLen / 3) + "汉字)";
} else {
maxLen = webim.MSG_MAX_LENGTH.GROUP;
errInfo = "消息长度超出限制(最多" + Math.round(maxLen / 3) + "汉字)";
}
if (msgLen > maxLen) {
alert(errInfo);
return;
}
if (!selSess) {
selSess = new webim.Session(selType, selToID, selToID, friendHeadUrl, Math.round(new Date().getTime() / 1000));
}
var msg = new webim.Msg(selSess, true, -1, -1, -1, loginInfo.identifier, 0, loginInfo.identifierNick);
var custom_obj = new webim.Msg.Elem.Custom(data, desc, ext);
msg.addCustom(custom_obj);
//调用发送消息接口
msg.sending = 1;
webim.sendMsg(msg, function(resp) {
addMsg(msg);
$("#id_" + msg.random).find(".spinner").remove();
// if (selType == webim.SESSION_TYPE.C2C) {
// //私聊时,在聊天窗口手动添加一条发的消息,群聊时,长轮询接口会返回自己发的消息
// addMsg(msg);
// }
$('#edit_custom_msg_dialog').modal('hide');
}, function(err) {
alert(err.ErrorInfo);
});
}