diff --git a/config.json b/config.json index aa66435..e15bea0 100644 --- a/config.json +++ b/config.json @@ -105,5 +105,10 @@ "autoConnexion": true, "notificationSonore": true, "affichageCompact": false + }, + "signalR": { + "serverUrl": "http://10.90.20.201:8002/signalR", + "serviceProvider": "RDVPREM", + "enabled": true } } \ No newline at end of file diff --git a/index.html b/index.html index 7c74d83..e1291d8 100644 --- a/index.html +++ b/index.html @@ -11,6 +11,10 @@

SimpleConnect

+
+ + Connexion au serveur... +

Connexion Agent

diff --git a/main.js b/main.js index 6f32513..d8cf92a 100644 --- a/main.js +++ b/main.js @@ -1,10 +1,13 @@ const { app, BrowserWindow, ipcMain, session } = require('electron'); const path = require('path'); const fs = require('fs'); +const signalR = require('@microsoft/signalr'); let mainWindow; let config; let currentAgent = null; +let signalRConnection = null; +let signalRStatus = 'disconnected'; // disconnected, connecting, connected, error // Charger la configuration function loadConfig() { @@ -42,6 +45,82 @@ function createWindow() { }); } +// === GESTION SIGNALR === +function initializeSignalR() { + if (!config.signalR || !config.signalR.enabled) { + console.log('SignalR désactivé dans la configuration'); + signalRStatus = 'disabled'; + sendSignalRStatus(); + return; + } + + try { + // Créer la connexion SignalR + signalRConnection = new signalR.HubConnectionBuilder() + .withUrl(config.signalR.serverUrl) + .withAutomaticReconnect([0, 2000, 5000, 10000, 30000]) + .configureLogging(signalR.LogLevel.Information) + .build(); + + // Gérer les changements d'état + signalRConnection.onreconnecting(() => { + console.log('SignalR: Reconnexion en cours...'); + signalRStatus = 'connecting'; + sendSignalRStatus(); + }); + + signalRConnection.onreconnected(() => { + console.log('SignalR: Reconnecté'); + signalRStatus = 'connected'; + sendSignalRStatus(); + }); + + signalRConnection.onclose(() => { + console.log('SignalR: Connexion fermée'); + signalRStatus = 'disconnected'; + sendSignalRStatus(); + }); + + // Démarrer la connexion + startSignalRConnection(); + + } catch (error) { + console.error('Erreur initialisation SignalR:', error); + signalRStatus = 'error'; + sendSignalRStatus(); + } +} + +async function startSignalRConnection() { + try { + signalRStatus = 'connecting'; + sendSignalRStatus(); + + await signalRConnection.start(); + console.log('SignalR: Connexion établie'); + signalRStatus = 'connected'; + sendSignalRStatus(); + + } catch (error) { + console.error('Erreur connexion SignalR:', error); + signalRStatus = 'error'; + sendSignalRStatus(); + + // Réessayer dans 5 secondes + setTimeout(() => { + if (signalRConnection && signalRStatus !== 'connected') { + startSignalRConnection(); + } + }, 5000); + } +} + +function sendSignalRStatus() { + if (mainWindow && !mainWindow.isDestroyed()) { + mainWindow.webContents.send('signalr-status', signalRStatus); + } +} + // Initialisation de l'application app.whenReady().then(() => { // Configuration de la session pour éviter les problèmes CORS @@ -61,6 +140,9 @@ app.whenReady().then(() => { loadConfig(); createWindow(); + + // Initialiser SignalR après le chargement de la config + initializeSignalR(); }); // Quitter quand toutes les fenêtres sont fermées @@ -84,6 +166,11 @@ ipcMain.handle('get-config', () => { return config; }); +// Obtenir le statut SignalR +ipcMain.handle('get-signalr-status', () => { + return signalRStatus; +}); + // Connexion agent ipcMain.handle('login-agent', (event, credentials) => { const agent = config.agents.find(a => diff --git a/package.json b/package.json index ee4b4a4..edea48e 100644 --- a/package.json +++ b/package.json @@ -65,5 +65,8 @@ "repository": { "type": "git", "url": "https://github.com/simpleconnect/electron-app.git" + }, + "dependencies": { + "@microsoft/signalr": "^9.0.6" } -} \ No newline at end of file +} diff --git a/renderer.js b/renderer.js index bffb3be..60928d8 100644 --- a/renderer.js +++ b/renderer.js @@ -12,6 +12,18 @@ let callStats = { // === GESTION DE LA CONNEXION === document.addEventListener('DOMContentLoaded', async () => { + // Initialiser l'indicateur SignalR + updateSignalRStatus(); + + // Écouter les changements de statut SignalR + ipcRenderer.on('signalr-status', (event, status) => { + updateSignalRIndicator(status); + }); + + // Obtenir le statut initial SignalR + const initialStatus = await ipcRenderer.invoke('get-signalr-status'); + updateSignalRIndicator(initialStatus); + // Vérifier si un agent est déjà connecté const agentData = await ipcRenderer.invoke('get-current-agent'); if (agentData) { @@ -392,4 +404,44 @@ async function saveNotes() { alert('Notes sauvegardées !'); document.getElementById('quickNotes').value = ''; } +} + +// === GESTION INDICATEUR SIGNALR === +function updateSignalRStatus() { + // Fonction appelée au chargement pour initialiser l'interface +} + +function updateSignalRIndicator(status) { + const indicator = document.getElementById('signalrIndicator'); + const text = document.getElementById('signalrText'); + + if (!indicator || !text) return; + + // Réinitialiser les classes + indicator.className = 'signalr-indicator'; + + switch(status) { + case 'connected': + indicator.classList.add('connected'); + text.textContent = 'Connecté au serveur'; + break; + case 'connecting': + indicator.classList.add('connecting'); + text.textContent = 'Connexion en cours...'; + break; + case 'disconnected': + indicator.classList.add('disconnected'); + text.textContent = 'Serveur déconnecté'; + break; + case 'error': + indicator.classList.add('error'); + text.textContent = 'Erreur de connexion'; + break; + case 'disabled': + indicator.classList.add('disabled'); + text.textContent = 'SignalR désactivé'; + break; + default: + text.textContent = 'État inconnu'; + } } \ No newline at end of file diff --git a/styles.css b/styles.css index 328e958..7737327 100644 --- a/styles.css +++ b/styles.css @@ -47,6 +47,64 @@ body { font-size: 32px; } +/* Indicateur de statut SignalR */ +.signalr-status { + display: flex; + align-items: center; + justify-content: center; + gap: 8px; + margin: 15px 0; + padding: 10px; + background: #f8f9fa; + border-radius: 5px; + font-size: 14px; +} + +.signalr-indicator { + width: 12px; + height: 12px; + border-radius: 50%; + background-color: #999; + animation: pulse 2s infinite; +} + +.signalr-indicator.connected { + background-color: #4CAF50; + animation: none; +} + +.signalr-indicator.connecting { + background-color: #FFC107; + animation: pulse 1s infinite; +} + +.signalr-indicator.disconnected, +.signalr-indicator.error { + background-color: #F44336; + animation: none; +} + +.signalr-indicator.disabled { + background-color: #999; + animation: none; +} + +@keyframes pulse { + 0% { + opacity: 1; + } + 50% { + opacity: 0.5; + } + 100% { + opacity: 1; + } +} + +.signalr-text { + color: #666; +} + .login-container h2 { text-align: center; color: #666;