1function addChatTextBlock(e, json, isSelf = true) { 2 const div1 = document.createElement("div"); 3 div1.className = 'data-row'; 4 if (isMobileDevice()) { 5 div1.classList.add("data-row-Mobile") 6 } 7 const div2 = document.createElement("div"); 8 div2.className = "sendDateTime"; 9 div2.innerText = getDate(new Date(json.sendDate)); 10 div1.appendChild(div2); 11 const br = document.createElement("br"); 12 div1.appendChild(br); 13 const img = document.createElement("img"); 14 const userConfJson = isSelf ? USER_CONF : USER_CONF_TEMP; 15 img.className = "headSculpture"; 16 const b = userConfJson.headSculpture === undefined; 17 img.src = b ? 'image/logo.svg' : userConfJson.headSculpture[1]; 18 img.alt = my_temp.name; 19 img.style.margin = "1vh;"; 20 if (!b) { 21 img.onclick = () => toPersonHomePage(my_temp) 22 } 23 div1.appendChild(img) 24 const div3 = document.createElement("div"); 25 div3.className = "container left textDataBlock"; 26 div3.style.backgroundColor = isSelf ? '#fff' : '#b2c3ff' 27 div3.id = json.id; 28 editormd.markdownToHTML(div3, { 29 flowChart: true, 30 htmlDecode: "video,style,iframe,sub,sup", 31 markdown: json.data, 32 emoji: true, 33 path: "editor.md/lib/" 34 }) 35 div1.appendChild(div3); 36 e.appendChild(div1); 37 // ç§»å¨å°æåºé¨ 38 e.scrollTop = e.scrollHeight; 39} 40 41class Ly_MblOnline { 42 /** 43 * å½åç»å½çå¨çº¿äººæ° ä»¥å ææäººçå¨çº¿äººæ° 44 * @type {number} 45 */ 46 static nowLoginCount = 0; 47 static nowNoLoginUserCount = 0; 48 49 /** 50 * 设置å½åç»å½çå¨çº¿äººæ°ï¼ä¸æ¬¡å·æ°æ¶ æ°æ®å°è¢«å±ç¤ºï¼ 51 * @param count 52 */ 53 static setNowLoginCount(count) { 54 Ly_MblOnline.nowLoginCount = count; 55 } 56 57 /** 58 * 设置å½åå¨çº¿æªç»å½äººæ°ï¼ä¸æ¬¡å·æ°æ¶ æ°æ®å°è¢«å±ç¤ºï¼ 59 * @param count 60 */ 61 static setNowNoLoginUserCount(count) { 62 Ly_MblOnline.nowNoLoginUserCount = count; 63 } 64} 65 66class LY_MblChat { 67 68 static webSocket; 69 70 static initChat(okFun, closeConnectFun = undefined, reConnectFun = undefined, checkConnect = undefined) { 71 72 function extracted(wsUrl) { 73 if (LY_MblChat.webSocket !== undefined) { 74 // å ³éä¹åçè¿æ¥ 75 LY_MblChat.webSocket.close(3024, 'Manual close, do not reconnect'); 76 // æ¸ é¤æ§ç WebSocket å®ä¾ 77 LY_MblChat.webSocket = undefined; 78 } 79 LY_MblChat.webSocket = new WebSocket(wsUrl); 80 initChatSocket(LY_MblChat.webSocket, wsUrl, closeConnectFun, reConnectFun, checkConnect); 81 okFun(LY_MblChat.webSocket); 82 } 83 84 // è·åå° codeBookWebSocket çè®¤è¯ 85 CodeBookAuthentication( 86 "codeBookWebSocket", 87 (dataTemp) => { 88 const wsUrl = char_host_href() + WEB_CONF['CHAT_HANDLER'] + '?' + 'userId=' + dataTemp.thirdPartyUserID + '&passwd=' + dataTemp.thirdPartyKey; 89 extracted(wsUrl); 90 }, 91 (_) => { 92 // 认为没æç»å½ è¿ä¸ªæ åµä¹å¯ä»¥å»ºç«è¿æ¥ åªæ¯å»ºç«çè¿æ¥ä¸æ²¡æç¨æ·ä¿¡æ¯ 93 const wsUrl = char_host_href() + WEB_CONF['CHAT_HANDLER'] + '?noLogin=true'; 94 extracted(wsUrl); 95 } 96 ) 97 } 98} 99 100let getWebSocketHandler = () => undefined; 101 102// åå¤è®¡æ¶å¨ å·æ°å½åå¨çº¿äººæ° 103setInterval(() => { 104 const webSocketHandler = getWebSocketHandler(); 105 if (!webSocketHandler) { 106 return; 107 } 108 webSocketHandler.send(JSON.stringify( 109 { 110 id: getRandomInt(-40690000, 40690000), 111 sendId: -1, 112 recId: -1, 113 command: "updateOnlineToClient" 114 } 115 )); 116}, 5000); 117 118/** 119 * åå§åè天çwebsocket å¨è¿éä¼è¢«èµäºäºä»¶å½æ° 120 * @param webSocket éè¦è¢«åå§åçwebsocket 121 * @param wsUrl websocket çurl éè¿éè¦ç¨ 122 * @param closeConnectFun å ³éè¿æ¥ç彿° å¨è¿éä¸è¦éæ°è¿æ¥ å 为å é¨æéæ°è¿æ¥çé»è¾
123 * @param reConnectFun éè¿åçä¹åè¦è°ç¨ç彿° è¿éä¼ä¼ éææ°ç webSocket 124 * @param checkConnect æ£æ¥è¿æ¥æ¯å¦å¯ç¨ 125 */ 126function initChatSocket(webSocket, wsUrl, closeConnectFun = undefined, reConnectFun = undefined, checkConnect = undefined) { 127 webSocket.onopen = function () { 128 getWebSocketHandler = () => webSocket; 129 } 130 131 webSocket.onerror = function (error) { 132 if (getNOW_PAGE() === 'chat.html') { 133 addChatTextBlock(data_message, { 134 id: parse.id, 135 sendId: parse.sendId, 136 sendDate: parse.sendDate, 137 data: error.toString() 138 }, false) 139 } else { 140 console.error(error) 141 } 142 }; 143 144 function extractedMassage(parse) { 145 if (confirm("æ¨æ¶å°äº[" + parse.sendName + "]忥çç§ä¿¡ï¼" + parse.data + "; æ¯å¦éè¦ç«å»æ¥ç?")) { 146 getUserByUserIdOrName(parse.sendId, parse.sendName).then((res) => { 147 if (WEB_CONF['RES_RETURN_OK_VALUE'] === res[WEB_CONF.RES_RETURN]) { 148 toChatPage(res[parse.sendName]) 149 } else { 150 alert("è·³è½¬å¤±è´¥ï¼æ æ³è·åå°åéè çä¿¡æ¯!!!") 151 } 152 }) 153 } 154 } 155 156 const command_handler = { 157 "updateOnlineToClient": function (parse) { 158 // æ´æ°å½åç»å½ç¨æ· 159 Ly_MblOnline.setNowLoginCount(parse['onlineUserCount'] ? parse['onlineUserCount'] : 0); 160 // æ´æ°å½åæªç»å½ç¨æ· 161 Ly_MblOnline.setNowNoLoginUserCount(parse['noLoginCount'] ? parse['noLoginCount'] : 0); 162 }, 163 "jokBox": function (parse) { 164 // å¼¹çª 165 jokerBoxPopUp.show(parse.data); 166 }, 167 "logout": function (parse) { 168 // 强å¶éåºç»å½ 169 logout(true, parse.data ? parse.data : "æ¨å·²è¢«å¼ºå¶éåºç»å½ï¼"); 170 } 171 } 172 173 webSocket.onmessage = function (event) { 174 const parse = JSON.parse(event.data); 175 const commandHandlerElement = command_handler[parse.command]; 176 if (commandHandlerElement) { 177 commandHandlerElement(parse); 178 return; 179 } 180 if (!parse.sendId) { 181 parse.sendId = -1; 182 } 183 const isSelf = my && parse.sendId.toString() === my.id; 184 const isChat = getNOW_PAGE() === 'chat.html'; 185 if (isChat) { 186 if (parse.recId === my_temp.id || parse.sendId === my_temp.id) { 187 switch (parse.command) { 188 case "memory": 189 // åå¿æ¶æ¯ ä¸éè¦é声 190 addChatTextBlock(data_message, parse, parse.sendId.toString() === my.id); 191 break; 192 default: 193 // è天 194 Ring.playRing(); 195 addChatTextBlock(data_message, { 196 id: parse.id, 197 sendId: parse.sendId, 198 sendDate: parse.sendDate, 199 data: parse.data 200 }, isSelf); 201 } 202 } else { 203 if (!isSelf) { 204 Ring.playRing('dingDang') 205 extractedMassage(parse); 206 } 207 } 208 } else if (!isSelf) { 209 Ring.playRing('dingDang') 210 extractedMassage(parse); 211 } 212 }; 213 214 function reConnect() { 215 console.info("reConnectFun(webSocket)"); 216 if (webSocket.readyState === WebSocket.OPEN) { 217 return; 218 } 219 const webSocket1 = new WebSocket(wsUrl); 220 initChatSocket(webSocket1, wsUrl, closeConnectFun, reConnectFun, checkConnect); 221 webSocket1.addEventListener("open", () => { 222 reConnectFun(webSocket1); 223 }); 224 } 225 226 webSocket.onclose = function (event) { 227 console.log('龿¥è¢«è¿«å ³éï¼' + event.code); 228 if (closeConnectFun !== undefined) { 229 closeConnectFun(event.code); 230 } 231 // åè®¾ç¶æç 1000 表示æ£å¸¸å ³éï¼ä¸éè¿ 232 if (event.code !== 3024) { 233 setTimeout(() => reConnect(), 2000); 234 } 235 }; 236} 237 238function checkSocketIsNotConnect(socket) { 239 return socket === null || socket === undefined || socket.readyState !== WebSocket.OPEN 240}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.