converse js在每次刷新页面时都会重新连接

converse js reconnects on every page refresh

本文关键字:重新连接 刷新 js converse      更新时间:2023-09-26

我在xmpp服务器上使用converse js。我遇到了一个问题,每当刷新页面时,聊天框都会断开连接,然后重新连接。我制作了以下代码来修复它,它在fire fox上运行良好,但在谷歌chrome中它不连接,并一直显示为连接。。

这是一个原始代码,可以在每次重新加载页面时重新连接聊天:

$(window).load(function(){
$("#jidy").val('<?php echo osc_logged_user_id();  ?>@xmpp');
$("#pass").val('<?php echo osc_logged_user_id(); ?>');
$(".login-submit").trigger("click");
$("#controlbox").hide();
});

这是下面修改过的代码,在firefox上效果很好,但在谷歌chrome:上效果不佳

$(document).ready(function(){     
 require(['converse'], function (converse) {
 converse.initialize({
 });
});
$("#jidy").val('<?php echo osc_logged_user_id();  ?>@xmpp');
$("#pass").val('<?php echo osc_logged_user_id(); ?>');
$(".login-submit").trigger("click");
$("#controlbox").remove();
$('.conn-feedback').remove();
$("#toggle-controlbox").remove();

});

尝试

var xmppSubmit = setInterval(function()
 {
     if(jQuery(".login-submit").length > 0)
     {
         if(readCookie("xmpp_username") != null && readCookie("xmpp_password") != null)
         {
             jQuery('input[id="xmpp_username"]').val(readCookie("xmpp_username"));
             jQuery('input[id="xmpp_password"]').val(b64_to_utf8(readCookie("xmpp_password")));
             jQuery('input[class="login-submit"]').trigger('click');
         }
         clearInterval(xmppSubmit);
     }
 }, 700);
function utf8_to_b64( str ) {
  return window.btoa(unescape(encodeURIComponent( str )));
}
function b64_to_utf8( str ) {
  return decodeURIComponent(escape(window.atob( str )));
}

因为CCD_ 1可能未被加载。