diff --git a/assets/js/common/system.js b/assets/js/common/system.js index 9caa9e30..62b2ad8d 100644 --- a/assets/js/common/system.js +++ b/assets/js/common/system.js @@ -79,6 +79,10 @@ ComunicWeb.common.system = { //Open specified page ComunicWeb.common.page.openPage(openPage); + // Initialize Websocket if user is connect + if(signed_in()) + UserWebSocket.Connect(); + //End of init ComunicWeb.debug.logMessage("Application is ready !"); } @@ -91,6 +95,7 @@ ComunicWeb.common.system = { /** * Automaticaly refresh login state */ + // TODO : remove when websockets are implemented var autoRefresh = setInterval((function(){ ComunicWeb.user.userLogin.refreshLoginState(); }), 25000); diff --git a/assets/js/common/ws.js b/assets/js/common/ws.js new file mode 100644 index 00000000..c0b706ea --- /dev/null +++ b/assets/js/common/ws.js @@ -0,0 +1,24 @@ +/** + * Main client websocket + * + * @author Pierre HUBERT + */ +class UserWebSocket { + + /** + * Connect to server + */ + static async Connect() { + await this.Disconnect(); + + console.log("Connect to websocket"); + } + + /** + * Disconnect from server + */ + static async Disconnect() { + console.log("Disconnect from websockt"); + + } +} \ No newline at end of file diff --git a/assets/js/user/userLogin.js b/assets/js/user/userLogin.js index 0026b5bb..48eab9ae 100644 --- a/assets/js/user/userLogin.js +++ b/assets/js/user/userLogin.js @@ -176,6 +176,9 @@ ComunicWeb.user.userLogin = { //Save email address ComunicWeb.components.mailCaching.set(usermail); + + // Initialize websocket + UserWebSocket.Connect(); } //Perform next action if login failed @@ -213,7 +216,10 @@ ComunicWeb.user.userLogin = { * * @param {Function} afterLogout What to do once user is logged out */ - logoutUser: function(afterLogout){ + logoutUser: async function(afterLogout){ + + await UserWebSocket.Disconnect(); + //Prepare and make an API request var apiURI = "user/disconnectUSER"; var params = {}; diff --git a/system/config/dev.config.php b/system/config/dev.config.php index 5d4965cf..fb8029bf 100644 --- a/system/config/dev.config.php +++ b/system/config/dev.config.php @@ -325,6 +325,7 @@ class Dev { "js/common/date.js", "js/common/system.js", array("path" => "js/common/songPlayer.js", "uglifyjs" => false), + array("path" => "js/common/ws.js", "uglifyjs" => false), //Languages "js/langs/en.inc.js",