diff --git a/assets/js/components/calls/controller.js b/assets/js/components/calls/controller.js index fbc3c3de..cc8561c6 100644 --- a/assets/js/components/calls/controller.js +++ b/assets/js/components/calls/controller.js @@ -29,32 +29,14 @@ ComunicWeb.components.calls.controller = { ComunicWeb.debug.logMessage("Initialize calls component"); - //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; - }); - - }); - - // Each time a page is opened, wec check if we have to create calls target - document.addEventListener("openPage", function(){ + //Initialize call container + var initializeCallContainer = function(){ //Signed out users can not make calls - if(!signed_in()) + if(!signed_in()){ + ComunicWeb.components.calls.controller.userSignedOut(); return; + } //Need a wrapper to continue if(!byId("wrapper")) @@ -74,6 +56,36 @@ ComunicWeb.components.calls.controller = { type: "div", 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(); + } } \ No newline at end of file diff --git a/assets/js/components/calls/currentList.js b/assets/js/components/calls/currentList.js index 50828e32..483cbd5a 100644 --- a/assets/js/components/calls/currentList.js +++ b/assets/js/components/calls/currentList.js @@ -66,4 +66,10 @@ ComunicWeb.components.calls.currentList = { }, + /** + * Remove all the calls from the list + */ + removeAllCalls: function(){ + this.saveNewCallsList([]); + } } \ No newline at end of file diff --git a/assets/js/components/calls/interface.js b/assets/js/components/calls/interface.js index 0aa2ad18..20f6d9a4 100644 --- a/assets/js/components/calls/interface.js +++ b/assets/js/components/calls/interface.js @@ -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 * user