mirror of
https://gitee.com/270580156/weiyu.git
synced 2026-05-16 04:07:51 +00:00
1 line
23 KiB
JavaScript
1 line
23 KiB
JavaScript
"use strict"; function _defineProperty(e, t, a) { return t in e ? Object.defineProperty(e, t, { value: a, enumerable: !0, configurable: !0, writable: !0 }) : e[t] = a, e } var bd_kfe_stompapi = { subscribeTopic: function (e) { bd_kfe_utils.printLog("subscribeTopic:" + e), -1 === bd_kfe_data.subscribedTopics.indexOf(e) && (bd_kfe_data.subscribedTopics.push(e), bd_kfe_data.stompClient.subscribe("/topic/" + e, function (e) { var t = JSON.parse(e.body); if ("text" === t.type || "robot" === t.type || "robot_result" === t.type || "image" === t.type || "file" === t.type || "voice" === t.type || "video" === t.type || "commodity" === t.type || "card" === t.type || "choice" === t.type) { t.createdAt = t.timestamp, "text" === t.type ? t.content = t.text.content : "robot" === t.type ? t.content = t.text.content : "robot_result" === t.type ? t.content = t.text.content : "image" === t.type ? t.imageUrl = t.image.imageUrl : "file" === t.type ? t.fileUrl = t.file.fileUrl : "voice" === t.type ? (t.voiceUrl = t.voice.voiceUrl, t.length = t.voice.length) : "video" === t.type ? t.videoOrShortUrl = t.video.videoOrShortUrl : "commodity" === t.type ? t.content = t.text.content : "card" === t.type ? t.content = t.text.content : "choice" === t.type && (t.content = t.text.content); var a = t.mid; if (bd_kfe_stompapi.sendReceiptMessage(a, "read"), bd_kfe_data.browserTabHidden) { var d = "收到新客服消息"; "en" === bd_kfe_data.lang && (d = "Received New Message"), document.title = d } t.user.uid !== bd_kfe_data.uid && (bd_kfe_utils.playAudio(), $("#bytedesk_agent_avatar").attr("src", t.user.avatar), $("#bytedesk_agent_nickname").text(t.user.nickname), $("#bytedesk_agent_description").text(t.user.description), window.parent.postMessage({ msg: "bytedesk-message", type: t.type, content: t.content }, "*")) } else if ("notification_browse_invite" === t.type) bd_kfe_data.browseInviteBIid = t.browseInvite.bIid; else if ("notification_queue" === t.type) bd_kfe_data.isThreadClosed = !1; else if ("notification_queue_accept" === t.type) { t.createdAt = t.timestamp; var d = "接入会话"; "en" === bd_kfe_data.lang && (d = "Accept By Agent"), t.content = d, bd_kfe_data.isThreadClosed = !1, bd_kfe_data.isRobot = !1 } else if ("notification_invite_rate" === t.type) t.createdAt = t.timestamp, t.content = t.extra.content, bd_kfe_data.isInviteRate = !0, $("#bytedesk_main").hide(), $("#bytedesk_leave").hide(), $("#bytedesk_rate").show(); else if ("notification_rate_result" === t.type) t.createdAt = t.timestamp, t.content = t.extra.content; else if ("notification_agent_close" === t.type || "notification_auto_close" === t.type) t.createdAt = t.timestamp, t.content = t.text.content, bd_kfe_data.isThreadClosed = !0; else if ("notification_preview" === t.type) t.user.uid !== bd_kfe_data.uid && (bd_kfe_data.inputTipVisible = !0, bd_kfe_utils.toggleInputTip(!0), setTimeout(function () { bd_kfe_data.inputTipVisible = !1, bd_kfe_utils.toggleInputTip(!1) }, 5e3)); else if ("notification_receipt" === t.type) { if (t.user.uid !== bd_kfe_data.uid) { var d = "已读"; if ("en" === bd_kfe_data.lang && (d = "read"), $("#status-" + t.receipt.mid).text() == d) return; if ("received" == t.receipt.status) { var d = "送达"; "en" === bd_kfe_data.lang && (d = "received"), $("#status-" + t.receipt.mid).text(d) } else if ("read" == t.receipt.status) { var d = "已读"; "en" === bd_kfe_data.lang && (d = "read"), $("#status-" + t.receipt.mid).text(d) } } } else if ("notification_recall" === t.type) { var d = "消息已撤回"; "en" === bd_kfe_data.lang && (d = "message recalled"), $("#content-" + t.recall.mid).text(d) } else if ("notification_form_request" === t.type) { var _ = t.extra.content; bd_kfe_utils.printLog("form:" + _), -1 !== _.indexOf("姓名") && $("#bytedesk_form-name-div").show(), -1 !== _.indexOf("手机") && $("#bytedesk_form-mobile-div").show(), -1 !== _.indexOf("邮箱") && $("#bytedesk_form-email-div").show(), -1 !== _.indexOf("年龄") && $("#bytedesk_form-age-div").show(), -1 !== _.indexOf("职业") && $("#bytedesk_form-job-div").show(), bd_kfe_utils.switchForm() } else "notification_form_result" === t.type && (t.createdAt = t.timestamp, t.content = t.form.content); if ("notification_preview" !== t.type && "notification_receipt" !== t.type && "notification_recall" !== t.type && "notification_connect" !== t.type && "notification_disconnect" !== t.type && (bd_kfe_data.isRobot = !1, bd_kfe_utils.pushToMessageArray(t), bd_kfe_utils.scrollToBottom(), bd_kfe_data.hidden && !bd_kfe_utils.is_type_close(t))) { var d = "新客服消息"; "en" === bd_kfe_data.lang && (d = "New Message"), bd_kfe_utils.showNotification(d), bd_kfe_utils.browserTitleNotification() } })) }, onInputChange: function () { if (bd_kfe_data.isRobot) { var e = $.trim($("#bytedesk_input_textarea").val()); return void bd_kfe_httpapi.previewAnswer(e) } bd_kfe_data.isThreadClosed || bd_kfe_stompapi.delaySendPreviewMessage() }, sendPreviewMessage: function () { var e = bd_kfe_utils.guid(), t = $.trim($("#bytedesk_input_textarea").val()), a = { mid: e, timestamp: bd_kfe_utils.currentTimestamp(), client: bd_kfe_data.client, version: "1", type: "notification_preview", user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), extra: { agent: !1 } }, preview: { content: void 0 === t ? " " : t }, thread: { tid: bd_kfe_data.thread.tid, type: bd_kfe_data.thread.type, content: t, nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), topic: bd_kfe_data.threadTopic(), timestamp: bd_kfe_utils.currentTimestamp(), unreadCount: 0 } }; bd_kfe_stompapi.doSendMessage(a) }, sendTextMessage: function () { var e = $.trim($("#bytedesk_input_textarea").val()); if (e = bd_kfe_utils.escapeHTML(e), 0 === e.length) { var t = "消息不能为空"; return "en" === bd_kfe_data.lang && (t = "Message Should Not be Null"), void alert(t) } if (e.length >= 500) { var t = "消息长度太长,请分多次发送"; return "en" === bd_kfe_data.lang && (t = "Message Too Long"), void alert(t) } bd_kfe_data.isRobot ? bd_kfe_httpapi.messageAnswer(e) : bd_kfe_stompapi.sendTextMessageSync(e), $("#bytedesk_input_textarea").val("") }, sendTextMessageSync: function (e) { var t = bd_kfe_utils.guid(), a = { mid: t, type: bd_kfe_data.MESSAGE_TYPE_TEXT, content: e, imageUrl: e, createdAt: bd_kfe_utils.currentTimestamp(), localId: t, status: bd_kfe_data.MESSAGE_STATUS_SENDING, user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar() } }; bd_kfe_utils.pushToMessageArray(a); var d = { mid: t, timestamp: bd_kfe_utils.currentTimestamp(), client: bd_kfe_data.client, version: "1", type: bd_kfe_data.MESSAGE_TYPE_TEXT, user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), extra: { agent: !1 } }, text: { content: e }, thread: { tid: bd_kfe_data.thread.tid, type: bd_kfe_data.thread.type, content: e, nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), topic: bd_kfe_data.threadTopic(), client: bd_kfe_data.client, timestamp: bd_kfe_utils.currentTimestamp(), unreadCount: 0 } }; bd_kfe_stompapi.doSendMessage(d) }, sendImageMessage: function (e) { if (bd_kfe_data.isRobot) { var t = "自助服务暂不支持图片"; return "en" === bd_kfe_data.lang && (t = "Robot Not Allow Image"), void alert(t) } var a = bd_kfe_utils.guid(), d = { mid: a, type: "image", content: e, imageUrl: e, createdAt: bd_kfe_utils.currentTimestamp(), localId: a, status: "sending", user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar() } }; bd_kfe_utils.pushToMessageArray(d); var _ = { mid: a, timestamp: bd_kfe_utils.currentTimestamp(), client: bd_kfe_data.client, version: "1", type: "image", user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), extra: { agent: !1 } }, image: { imageUrl: e }, thread: { tid: bd_kfe_data.thread.tid, type: bd_kfe_data.thread.type, content: "[图片]", nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), topic: bd_kfe_data.threadTopic(), client: bd_kfe_data.client, timestamp: bd_kfe_utils.currentTimestamp(), unreadCount: 0 } }; bd_kfe_stompapi.doSendMessage(_) }, sendVoiceMessage: function (e) { if (bd_kfe_data.isRobot) { var t = "自助服务暂不支持语音"; return "en" === bd_kfe_data.lang && (t = "Robot Not Allow Voice"), void alert(t) } var a = bd_kfe_utils.guid(), d = { mid: a, type: "voice", content: e, voiceUrl: e, createdAt: bd_kfe_utils.currentTimestamp(), localId: a, status: "sending", user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar() } }; bd_kfe_utils.pushToMessageArray(d); var _ = { mid: a, timestamp: bd_kfe_utils.currentTimestamp(), client: bd_kfe_data.client, version: "1", type: "voice", user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), extra: { agent: !1 } }, voice: { voiceUrl: e }, thread: { tid: bd_kfe_data.thread.tid, type: bd_kfe_data.thread.type, content: "[语音]", nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), topic: bd_kfe_data.threadTopic(), client: bd_kfe_data.client, timestamp: bd_kfe_utils.currentTimestamp(), unreadCount: 0 } }; bd_kfe_stompapi.doSendMessage(_) }, sendVideoMessage: function (e) { if (bd_kfe_data.isRobot) { var t = "自助服务暂不支持视频"; return "en" === bd_kfe_data.lang && (t = "Robot Not Allow Video"), void alert(t) } var a = bd_kfe_utils.guid(), d = { mid: a, type: "video", content: e, videoUrl: e, createdAt: bd_kfe_utils.currentTimestamp(), localId: a, status: "sending", user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar() } }; bd_kfe_utils.pushToMessageArray(d); var _ = { mid: a, timestamp: bd_kfe_utils.currentTimestamp(), client: bd_kfe_data.client, version: "1", type: "video", user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), extra: { agent: !1 } }, video: { videoOrShortUrl: e }, thread: { tid: bd_kfe_data.thread.tid, type: bd_kfe_data.thread.type, content: "[视频]", nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), topic: bd_kfe_data.threadTopic(), client: bd_kfe_data.client, timestamp: bd_kfe_utils.currentTimestamp(), unreadCount: 0 } }; bd_kfe_stompapi.doSendMessage(_) }, sendFileMessage: function (e) { if (bd_kfe_data.isRobot) { var t = "自助服务暂不支持文件"; return "en" === bd_kfe_data.lang && (t = "Robot Not Allow File"), void alert(t) } var a = bd_kfe_utils.guid(), d = { mid: a, type: "file", content: e, fileUrl: e, createdAt: bd_kfe_utils.currentTimestamp(), localId: a, status: "sending", user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar() } }; bd_kfe_utils.pushToMessageArray(d); var _ = { mid: a, timestamp: bd_kfe_utils.currentTimestamp(), client: bd_kfe_data.client, version: "1", type: "file", user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), extra: { agent: !1 } }, file: { fileUrl: e }, thread: { tid: bd_kfe_data.thread.tid, type: bd_kfe_data.thread.type, content: "[文件]", nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), topic: bd_kfe_data.threadTopic(), client: bd_kfe_data.client, timestamp: bd_kfe_utils.currentTimestamp(), unreadCount: 0 } }; bd_kfe_stompapi.doSendMessage(_) }, sendReceiptMessage: function (e, t) { var a = bd_kfe_utils.guid(), d = { mid: a, timestamp: bd_kfe_utils.currentTimestamp(), client: bd_kfe_data.client, version: "1", type: "notification_receipt", user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), extra: { agent: !1 } }, receipt: { mid: e, status: t }, thread: { tid: bd_kfe_data.thread.tid, type: bd_kfe_data.thread.type, nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), topic: bd_kfe_data.threadTopic(), client: bd_kfe_data.client, timestamp: bd_kfe_utils.currentTimestamp(), unreadCount: 0 } }; bd_kfe_stompapi.doSendMessage(d) }, sendRecallMessage: function (e) { var t = bd_kfe_utils.guid(), a = { mid: t, timestamp: bd_kfe_utils.currentTimestamp(), client: bd_kfe_data.client, version: "1", type: "notification_recall", user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), extra: { agent: !1 } }, recall: { mid: e }, thread: { tid: bd_kfe_data.thread.tid, type: bd_kfe_data.thread.type, nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), topic: bd_kfe_data.threadTopic(), client: bd_kfe_data.client, timestamp: bd_kfe_utils.currentTimestamp(), unreadCount: 0 } }; bd_kfe_stompapi.doSendMessage(a) }, sendFormMessage: function () { var e = $.trim($("#bytedesk_form-name").val()), t = $.trim($("#bytedesk_form-mobile").val()), a = $.trim($("#bytedesk_form-email").val()), d = $.trim($("#bytedesk_form-age").val()), _ = $.trim($("#bytedesk_form-job").val()); if (d.length > 0 && isNaN(d)) { var i = "年龄必须为数字"; return "en" === bd_kfe_data.lang && (i = "Age should be Number"), void alert(i) } var n = JSON.stringify({ form: { realname: e, mobile: t, email: a, age: d, job: _ } }), r = bd_kfe_utils.guid(), s = { mid: r, timestamp: bd_kfe_utils.currentTimestamp(), client: bd_kfe_data.client, version: "1", type: "notification_form_result", user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), extra: { agent: !1 } }, form: { content: n }, thread: { tid: bd_kfe_data.thread.tid, type: bd_kfe_data.thread.type, content: "[表单]", nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), topic: bd_kfe_data.threadTopic(), client: bd_kfe_data.client, timestamp: bd_kfe_utils.currentTimestamp(), unreadCount: 0 } }; bd_kfe_stompapi.doSendMessage(s), bd_kfe_utils.showMessage(), $("#bytedesk_form-name-div").hide(), $("#bytedesk_form-mobile-div").hide(), $("#bytedesk_form-email-div").hide(), $("#bytedesk_form-age-div").hide(), $("#bytedesk_form-job-div").hide() }, sendBrowseMessage: function () { if (bd_kfe_data.isThreadClosed) { var e = { referrer: encodeURI(document.referrer), url: encodeURI(window.location.href), title: encodeURI(document.title) }, t = { mid: bd_kfe_utils.guid(), timestamp: bd_kfe_utils.currentTimestamp(), client: bd_kfe_data.client, version: "1", type: "notification_notice", user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), extra: { agent: !1 } }, notice: { topic: window.adminUid, type: "notification_browse", content: JSON.stringify(e) } }; bd_kfe_data.stompClient.send("/app/" + window.adminUid, {}, JSON.stringify(t)), setTimeout(function () { bd_kfe_stompapi.sendBrowseMessage() }, 1e4) } }, sendCommodityMessageSync: function () { if ("1" === bd_kfe_utils.getUrlParam("goods")) { var e = bd_kfe_stompapi.commodityInfo(), t = { mid: bd_kfe_utils.guid(), timestamp: bd_kfe_utils.currentTimestamp(), client: bd_kfe_data.client, version: "1", type: "commodity", status: "sending", user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), extra: { agent: !1 } }, text: { content: e }, thread: { tid: bd_kfe_data.thread.tid, type: bd_kfe_data.thread.type, content: "[商品]", nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), topic: bd_kfe_data.threadTopic(), client: bd_kfe_data.client, timestamp: bd_kfe_utils.currentTimestamp(), unreadCount: 0 } }; bd_kfe_stompapi.doSendMessage(t) } }, appendCommodityInfo: function () { var e; if ("1" === bd_kfe_utils.getUrlParam("goods")) { var t = bd_kfe_stompapi.commodityInfo(), a = { mid: bd_kfe_utils.guid(), createdAt: bd_kfe_utils.currentTimestamp(), client: bd_kfe_data.client, version: "1", type: "commodity", status: "sending", user: (e = { uid: bd_kfe_data.my_uid(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar() }, _defineProperty(e, "avatar", bd_kfe_data.my_avatar()), _defineProperty(e, "extra", { agent: !1 }), e), content: t, thread: { tid: bd_kfe_data.thread.tid, type: bd_kfe_data.thread.type, content: "[商品]", nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), topic: bd_kfe_data.threadTopic(), client: bd_kfe_data.client, timestamp: bd_kfe_utils.currentTimestamp(), unreadCount: 0 } }; bd_kfe_utils.pushToMessageArray(a) } }, commodityInfo: function () { var e = { id: bd_kfe_utils.getUrlParam("goods_id"), title: bd_kfe_utils.getUrlParam("goods_title"), content: bd_kfe_utils.getUrlParam("goods_content"), price: bd_kfe_utils.getUrlParam("goods_price"), url: bd_kfe_utils.getUrlParam("goods_url"), imageUrl: bd_kfe_utils.getUrlParam("goods_imageUrl"), categoryCode: bd_kfe_utils.getUrlParam("goods_categoryCode"), type: "commodity" }; return JSON.stringify(e) }, sendMessageJsonRest: function (e, t, a) { var d; "text" === t ? d = { mid: e, timestamp: bd_kfe_utils.currentTimestamp(), client: bd_kfe_data.client, version: "1", type: t, status: "sending", user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), extra: { agent: !1 } }, text: { content: a }, thread: { tid: bd_kfe_data.thread.tid, type: bd_kfe_data.thread.type, content: a, nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), topic: bd_kfe_data.threadTopic(), client: bd_kfe_data.client, timestamp: bd_kfe_utils.currentTimestamp(), unreadCount: 0 } } : "image" === t ? d = { mid: e, timestamp: bd_kfe_utils.currentTimestamp(), client: bd_kfe_data.client, version: "1", type: t, status: "sending", user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), extra: { agent: !1 } }, image: { imageUrl: a }, thread: { tid: bd_kfe_data.thread.tid, type: bd_kfe_data.thread.type, content: "图片", nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), topic: bd_kfe_data.threadTopic(), client: bd_kfe_data.client, timestamp: bd_kfe_utils.currentTimestamp(), unreadCount: 0 } } : "file" === t ? d = { mid: e, timestamp: bd_kfe_utils.currentTimestamp(), client: bd_kfe_data.client, version: "1", type: t, status: "sending", user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), extra: { agent: !1 } }, file: { fileUrl: a }, thread: { tid: bd_kfe_data.thread.tid, type: bd_kfe_data.thread.type, content: "[文件]", nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), topic: bd_kfe_data.threadTopic(), client: bd_kfe_data.client, timestamp: bd_kfe_utils.currentTimestamp(), unreadCount: 0 } } : "voice" === t ? d = { mid: e, timestamp: bd_kfe_utils.currentTimestamp(), client: bd_kfe_data.client, version: "1", type: t, status: "sending", user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), extra: { agent: !1 } }, voice: { voiceUrl: a, length: "0", format: "wav" }, thread: { tid: bd_kfe_data.thread.tid, type: bd_kfe_data.thread.type, content: "[语音]", nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), topic: bd_kfe_data.threadTopic(), client: bd_kfe_data.client, timestamp: bd_kfe_utils.currentTimestamp(), unreadCount: 0 } } : "video" === t && (d = { mid: e, timestamp: bd_kfe_utils.currentTimestamp(), client: bd_kfe_data.client, version: "1", type: t, status: "sending", user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), extra: { agent: !1 } }, video: { videoOrShortUrl: a }, thread: { tid: bd_kfe_data.thread.tid, type: bd_kfe_data.thread.type, content: "[视频]", nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar(), topic: bd_kfe_data.threadTopic(), client: bd_kfe_data.client, timestamp: bd_kfe_utils.currentTimestamp(), unreadCount: 0 } }), bd_kfe_stompapi.sendMessageRest2(e, JSON.stringify(d)) }, doSendMessage: function (e) { bd_kfe_utils.printLog("doSendMessage: " + JSON.stringify(e)), bd_kfe_data.isConnected ? bd_kfe_data.stompClient.send("/app/" + bd_kfe_data.threadTopic(), {}, JSON.stringify(e)) : bd_kfe_stompapi.sendMessageRest(JSON.stringify(e)) }, sendMessageRest: function (e) { $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/messages/send", contentType: "application/json; charset=utf-8", dataType: "json", type: "post", data: JSON.stringify({ json: e }), beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + localStorage.bd_kfe_access_token) }, success: function (e) { bd_kfe_utils.printLog(e) }, error: function (e) { bd_kfe_utils.printLog(e), app.login() } }) }, sendMessageRest2: function (e, t) { $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/messages/send", contentType: "application/json; charset=utf-8", dataType: "json", type: "post", data: JSON.stringify({ json: t }), beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + localStorage.bd_kfe_access_token) }, success: function (t) { bd_kfe_utils.printLog(e + ":" + t) }, error: function (e) { bd_kfe_utils.printLog(e), bd_kfe_httpapi.login() } }) }, byteDeskConnect: function () { var e = new SockJS(bd_kfe_data.STOMP_HOST + "/stomp/?access_token=" + bd_kfe_data.passport.token.access_token); bd_kfe_data.stompClient = Stomp.over(e), bd_kfe_data.stompClient.reconnect_delay = 1e3, bd_kfe_data.stompClient.heartbeat.outgoing = 2e4, bd_kfe_data.stompClient.heartbeat.incoming = 2e4, bd_kfe_data.IS_PRODUCTION && (bd_kfe_data.stompClient.debug = function (e) { }), bd_kfe_data.stompClient.connect({}, function (t) { bd_kfe_utils.printLog("stompConnected: " + t + " username:" + t.headers["user-name"]), bd_kfe_data.isConnected = !0; var a = /\/([^\/]+)\/websocket/.exec(e._transport.url); if (null != a && a.length > 1 && (bd_kfe_data.sessionId = a[1]), bd_kfe_stompapi.subscribeTopic(bd_kfe_data.uid), "" !== bd_kfe_data.thread.topic && null !== bd_kfe_data.thread.topic && void 0 !== bd_kfe_data.thread.topic && bd_kfe_stompapi.subscribeTopic(bd_kfe_data.threadTopic()), "1" !== bd_kfe_data.preload && null !== bd_kfe_data.postscript && void 0 !== bd_kfe_data.postscript && "" !== bd_kfe_data.postscript) { var d = bd_kfe_data.postScriptPrefix + bd_kfe_data.postscript; bd_kfe_stompapi.sendTextMessageSync(d) } }, function (e) { bd_kfe_utils.printLog("连接断开【" + e + "】"), bd_kfe_data.isConnected = !1, bd_kfe_data.subscribedTopics = [], setTimeout(function () { bd_kfe_utils.printLog("reconnecting..."), bd_kfe_stompapi.byteDeskConnect() }, 5e3) }) } }; |