File size: 926 Bytes
d9d886e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
 * Shared Socket.IO Instance
 * This module provides a centralized Socket.IO instance that can be shared
 * across different parts of the application (app.js, handlers, etc.)
 */

let io = null

/**
 * Set the Socket.IO instance
 * @param {SocketIO.Server} socketIOInstance - The Socket.IO server instance
 */
function setSocketIOInstance (socketIOInstance) {
  io = socketIOInstance
}

/**
 * Get the Socket.IO instance
 * @returns {SocketIO.Server|null} - The Socket.IO server instance or null if not set
 */
function getSocketIOInstance () {
  if (!io) {
    console.warn('⚠️ Socket.IO instance has not been initialized yet')
  }
  return io
}

/**
 * Check if Socket.IO instance is available
 * @returns {boolean} - True if instance is available, false otherwise
 */
function isSocketIOAvailable () {
  return io !== null
}

module.exports = {
  setSocketIOInstance,
  getSocketIOInstance,
  isSocketIOAvailable
}