<div style="border: 1px solid #ccc;padding:10px;"> <div id="WebChatFormForm" style="overflow: auto;max-height: 100px;"></div> <input type="text" id="WebChatNameID" style="margin-top:10px;" placeholder=" ..."> <div id="answer_div" style="float:right;"></div> <textarea id="WebChatTextID" placeholder=" online ..." style="max-width: 600px;max-height: 100px;width: 600px;margin-top:10px;display: block;"></textarea> <div style="margin-bottom: 0px;margin-top: 10px;"> <input type="button" style="width: 220px;" onclick="web_send_msg();" value=""> <div id="answer_error" style="float:right;"></div> </div> </div>
var timer = new Date(); function web_send_msg() { // . var text = $("#WebChatTextID").val(); var name = $("#WebChatNameID").val(); // $("#WebChatTextID").val(""); // timer = new Date(); // CometServer().web_pipe_send("web_chat_pipe", {"text":text, "name":name}); // comet_server_signal().send_emit("AddToChat", {"text":text, "name":name}) } // $(document).ready(function() { // . CometServer().subscription("web_chat_pipe", function(msg){ console.log(["msg", msg]); // . $("#WebChatFormForm").append("<p><b>"+HtmlEncode(msg.data.name)+": </b>"+HtmlEncode(msg.data.text)+"</p>"); }); // , // comet_server_signal().connect("AddToChat", function(msg){ console.log(["msg", msg]); // . $("#WebChatFormForm").append("<p><b>"+HtmlEncode(msg.name)+": </b>"+HtmlEncode(msg.text)+"</p>"); }); // . CometServer().subscription("#web_chat_pipe", function(p) { // var etime = new Date(); console.log(["answer_to_web_chat_pipe", p]); $("#answer_div").html(" "+p.data.number_messages+" "+ (etime.getTime() - timer.getTime() )+"ms"); $("#answer_error").html(" "+p.data.error); }); }); function HtmlEncode(s) { var el = document.createElement("div"); el.innerText = el.textContent = s; s = el.innerHTML; return s; }
Source: https://habr.com/ru/post/272817/