Can reopen calls on page reload

This commit is contained in:
Pierre HUBERT 2019-01-25 10:08:55 +01:00
parent 9eab6c7e2e
commit 0a52bd5fe3
3 changed files with 92 additions and 23 deletions

View File

@ -29,32 +29,14 @@ ComunicWeb.components.calls.controller = {
ComunicWeb.debug.logMessage("Initialize calls component"); ComunicWeb.debug.logMessage("Initialize calls component");
//We wait the user to be connected before trying to get //Initialize call container
// call configuration var initializeCallContainer = function(){
document.addEventListener("got_user_id", function(){
//Check if we have already the call configuration
if(ComunicWeb.components.calls.__config !== undefined)
return;
ComunicWeb.components.calls.interface.getConfig(function(config){
//Check if we could not get calls configuration
if(config.error)
return;
//Save calls configuration
ComunicWeb.components.calls.__config = config;
});
});
// Each time a page is opened, wec check if we have to create calls target
document.addEventListener("openPage", function(){
//Signed out users can not make calls //Signed out users can not make calls
if(!signed_in()) if(!signed_in()){
ComunicWeb.components.calls.controller.userSignedOut();
return; return;
}
//Need a wrapper to continue //Need a wrapper to continue
if(!byId("wrapper")) if(!byId("wrapper"))
@ -74,6 +56,36 @@ ComunicWeb.components.calls.controller = {
type: "div", type: "div",
id: "callsTarget" id: "callsTarget"
}); });
//Now we have to reopen current calls
ComunicWeb.components.calls.controller.reopenCurrentCalls();
}
//We wait the user to be connected before trying to get
// call configuration
document.addEventListener("got_user_id", function(){
//Check if we have already the call configuration
if(ComunicWeb.components.calls.__config !== undefined)
return;
ComunicWeb.components.calls.interface.getConfig(function(config){
//Check if we could not get calls configuration
if(config.error)
return;
//Save calls configuration
ComunicWeb.components.calls.__config = config;
initializeCallContainer();
});
});
// Each time a page is opened, wec check if we have to create calls target
document.addEventListener("openPage", function(){
initializeCallContainer();
}); });
}, },
@ -207,5 +219,39 @@ ComunicWeb.components.calls.controller = {
}); });
},
/**
* Reopen all current calls
*/
reopenCurrentCalls: function(){
//Process each call to open it
ComunicWeb.components.calls.currentList.getCurrentCallsList().forEach(function(entry){
ComunicWeb.components.calls.interface.getInfo(entry, function(call){
if(call.error){
ComunicWeb.components.calls.currentList.removeCallFromList(entry);
return notify("Could not get information about a call!", "danger");
}
ComunicWeb.components.calls.controller.open(call);
});
});
},
/**
* Call this method only if the system is sure that
* nobody is signed in the current tab
*/
userSignedOut: function(){
//Remove all the current calls from the list
ComunicWeb.components.calls.currentList.removeAllCalls();
} }
} }

View File

@ -66,4 +66,10 @@ ComunicWeb.components.calls.currentList = {
}, },
/**
* Remove all the calls from the list
*/
removeAllCalls: function(){
this.saveNewCallsList([]);
}
} }

View File

@ -33,6 +33,23 @@ ComunicWeb.components.calls.interface = {
); );
}, },
/**
* Get information about a single call
*
* @param {Number} callID The ID of the target call
* @param {function} callback Function called on request result
*/
getInfo: function (callID, callback){
ComunicWeb.common.api.makeAPIrequest(
"calls/getInfo",
{
call_id: callID
},
true,
callback
);
},
/** /**
* Get and return the next pending call for the * Get and return the next pending call for the
* user * user