114 lines
3.9 KiB
JavaScript
114 lines
3.9 KiB
JavaScript
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('<div class="inbox-message-received"><div class="sender-image"><a href="profile.php?user='+data.username+'"><div style="position: relative; margin:auto; display: inline-block;"><img src="./images/nophoto.png" data-src="'+data.photo+'" onerror="this.src=\'https://cdn.bateworld.com/images/nophoto.gif\'" class="photo lozad" style="max-width:90px;" border="0" alt=" " data-loaded="true"></div></a></div><div class="inbox-message-text"><div class="info"><a href="https://bateworld.com/profile.php?user='+data.username+'">'+data.username+'</a><div class="messages_date">'+data.pmtime+'aaa</div> <a data-toggle="modal" data-target="#myModal" href="user_report.php?return_url=https%253A%252F%252Fbateworld.com%252Fhomestorage%252Fmessage_view.php%253Fpmconvo_id%253D'+data.pmconvo_id+'%2526_%253D1765410287184&user='+data.username+'&item=message&objectid='+data.pmid+'">Report a Problem</a></div> <div class="text">'+data.reply+'</div></div></div>'
|
|
|
|
);
|
|
scrollto("#chatContainer-sophie");
|
|
|
|
}
|
|
else if(data.type=="messagereceived")
|
|
{
|
|
alert("AAA");
|
|
jQuery("#chatContainer-sophie").append('<div class="inbox-message-sent"><div class="inbox-message-text"><div class="info"><div class="messages_date">'+data.pmtime+'aaa</div><a href="profile.php?user='+data.username+'">'+data.username+'</a></div><div class="text">'+data.reply+'</div></div><div class="sender-image"><a href="profile.php?user='+data.username+'"><div style="position: relative; margin:auto; display: inline-block;"><img src="./images/nophoto.png" data-src="'+data.photo+'" onerror="this.src=\'https://cdn.bateworld.com/images/nophoto.gif\'" class="photo lozad" style="max-width:90px;" border="0" alt=" "></div></a></div></div>' );
|
|
//jQuery('#submit1').prop( 'disabled', false ); jQuery('#submit1').prop( 'value', 'Send' );
|
|
scrollto("#chatContainer-sophie");
|
|
}
|
|
|
|
|
|
};
|
|
} |