I having a real time feature in my website that open new window on socket.io event fired from the server side (PHP/Laravel 5.1). The problem is if a user logged to my site and opened it in more than one tab/window - the new window.open fire multiple time, anyone know how can I prevent it? my code look like this:
the socket listener:
socket.on('message', function (data) {
data = JSON.parse(data);
if(typeof data.data !== "undefined"){
lead_data = data.data;
}else{
lead_data = data;
}
if(typeof lead_data !== "undefined" && (lead_data.event_name == "new_call" || lead_data.event_name == "new_unsaved_call")){
if(lead_data.user_id == uid){
window.App.openCallWindow(data);
}
}
});
and the openCallWindow
function:
openCallWindow : function(data){
void(0);
var lead_id = '';
if(data && data.lead){
lead_id = data.lead._id;
window.open('/leads/callLead/'+lead_id,'new_lead'+Math.floor((Math.random()*999)+1), "height=800,width=1200" );
}else if(typeof data.phone !== "undefined"){
window.open('/leads/callLead/?phone='+data.phone,'new_lead'+Math.floor((Math.random()*999)+1), "height=800,width=1200" );
}else{
window.open('/leads/callLead/'+lead_id,'new_lead'+Math.floor((Math.random()*999)+1), "height=800,width=1200" );
}
},