• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SyTW2526 / Proyecto-E09 / 19927988907

04 Dec 2025 11:50AM UTC coverage: 15.275% (+15.3%) from 0.0%
19927988907

push

github

alu0101539669
Fix: arreglo el package.json añadiendo los test unitarios para que muestre la tabla

153 of 1688 branches covered (9.06%)

Branch coverage included in aggregate %.

403 of 1952 relevant lines covered (20.65%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/client/socket.ts
1
/**
2
 * @file socket.ts
3
 * @description Configuración de conexión a Socket.io para comunicación en tiempo real
4
 * 
5
 * Gestiona:
6
 * - Inicialización de la conexión Socket.io
7
 * - Autenticación con JWT
8
 * - Acceso global a la instancia del socket
9
 * 
10
 * @requires socket.io-client - Cliente de Socket.io
11
 * @module socket
12
 */
13

14
import { io } from "socket.io-client";
15

16
/**
17
 * Instancia global de Socket.io
18
 * @type {Socket|null}
19
 */
20
let socket: any = null;
×
21

22
/**
23
 * Inicializa la conexión Socket.io con autenticación JWT
24
 * Se conecta a http://localhost:3000 usando WebSocket
25
 * 
26
 * @function
27
 * @returns {Socket|null} Instancia del socket o null si no hay token
28
 * @throws {Error} Si hay problemas en la conexión
29
 * 
30
 * @example
31
 * const socket = initSocket();
32
 * if (socket) {
33
 *   socket.on('connect', () => console.log('Conectado'));
34
 * }
35
 */
36
export function initSocket() {
37
  if (socket) return socket;
×
38

39
  const token = localStorage.getItem("token");
×
40
  if (!token) return null;
×
41

42
  /**
43
   * Socket.io se conecta con autenticación por JWT
44
   * El token se envía en el handshake
45
   */
46
  socket = io("http://localhost:3000", {
×
47
    auth: { token },
48
    transports: ["websocket"],
49
  });
50

51
  /**
52
   * Evento de conexión exitosa
53
   * Se dispara cuando se establece la conexión con el servidor
54
   */
55
  socket.on("connect", () => {
×
56
    console.log("Socket conectado:", socket.id);
×
57
  });
58

59
  return socket;
×
60
}
61

62
/**
63
 * Obtiene la instancia global del socket
64
 * Debe usarse después de initSocket()
65
 * 
66
 * @function
67
 * @returns {Socket|null} Instancia del socket o null si no está inicializado
68
 * 
69
 * @example
70
 * const socket = getSocket();
71
 * if (socket) {
72
   socket.emit('event', data);
73
 * }
74
 */
75
export function getSocket() {
76
  return socket;
×
77
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc