let pingIntervalvc; let reconnectTimeoutvc; //let host = 'wss://vidchat.bateworld.com/ws/'; let host = 'wss://bateworld.com/ws'; window.socket=null; function connectwss(){ console.log("Function hit "+ new Date()); window.socket = new WebSocket(host); console.log("New Socket "+ new Date()); window.socket.onopen = function(e) { console.log("Socket Open "+ new Date()); if(reconnectTimeoutvc) { clearTimeout(reconnectTimeoutvc); } console.log("[open] Connection established "+ new Date()); window.socket.send( JSON.stringify({ type: "auth", authid: grabCookie('se_auth_token') })); pingIntervalvc=setInterval(function() { window.socket.send(JSON.stringify({ type: "notify_get" })); }, 30000); window.socket.send( JSON.stringify({ type: "notify_get", data:"" })); }; //window.socket.onmessage = function(event) {}; window.socket.onclose = function(event) { clearInterval(pingIntervalvc); console.log("[close] Connection lost, retrying in 10s..." + new Date()); reconnectTimeoutvc = setTimeout(connectwss, 10000); }; window.socket.onerror = function(error) { //alert("[error] "+error.message); }; window.socket.onmessage = function(event) { const data = JSON.parse(event.data); if (data.type == "ping") { socket.send(JSON.stringify({ type: "pong" })); } else if(data.type == "get_notifications"){ SocialEngine.Viewer.userNotifyGenerate(data.text); SocialEngine.Viewer.userNotifyShow(); } else if (data.type === "istyping") { jQuery(".typing").html(data.text); } else if (data.type === "stoptyping") { jQuery(".typing").html(''); } else if (data.type == "ping") { console.log("pingfrom"); } else if(data.type=="messagesend"){ alert("RRRRR"); jQuery("#chatContainer-sophie").append('
'+data.reply+'
' ); scrollto("#chatContainer-sophie"); } else if(data.type=="messagereceived") { alert("AAA"); jQuery("#chatContainer-sophie").append('
'+data.pmtime+'aaa
'+data.username+'
'+data.reply+'
' ); //jQuery('#submit1').prop( 'disabled', false ); jQuery('#submit1').prop( 'value', 'Send' ); scrollto("#chatContainer-sophie"); } }; }