Ready to implement WebSocket

This commit is contained in:
Pierre HUBERT 2020-03-29 18:04:50 +02:00
parent 99aafe3799
commit a027e96071
4 changed files with 37 additions and 1 deletions

View File

@ -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);

24
assets/js/common/ws.js Normal file
View File

@ -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");
}
}

View File

@ -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 = {};

View File

@ -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",