shuttlepro-shared 1.1.69 → 1.1.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/config/socket.js +17 -7
  2. package/package.json +3 -2
package/config/socket.js CHANGED
@@ -3,15 +3,19 @@ const { client: redisClient, connectRedis } = require("./redis");
3
3
  const { createClient } = require("redis");
4
4
  require("dotenv").config();
5
5
 
6
- const REDIS_CHANNEL = "socket_events"; // Redis Pub/Sub Channel
7
6
  let io;
8
7
 
9
8
  /**
10
9
  * ✅ Initialize WebSocket Server with Redis Pub/Sub
11
10
  * @param {Object} server - HTTP Server instance
12
11
  * @param {string|null} namespace - Optional namespace (passed from `index.js`)
12
+ * @param {string} [redisChannel="socket_events"] - Custom Redis Pub/Sub Channel
13
13
  */
14
- const initializeSocket = async (server, namespace = null) => {
14
+ const initializeSocket = async (
15
+ server,
16
+ namespace = null,
17
+ redisChannel = "socket_events"
18
+ ) => {
15
19
  await connectRedis(); // Ensure Redis is connected
16
20
 
17
21
  io = new Server(server, {
@@ -21,7 +25,7 @@ const initializeSocket = async (server, namespace = null) => {
21
25
  console.log(
22
26
  `✅ WebSocket Server Initialized ${
23
27
  namespace ? `with namespace: ${namespace}` : "globally"
24
- }`
28
+ }, using Redis channel: ${redisChannel}`
25
29
  );
26
30
 
27
31
  // Create Redis Pub/Sub Clients
@@ -29,8 +33,8 @@ const initializeSocket = async (server, namespace = null) => {
29
33
  const subClient = createClient({ url: process.env.REDIS_URL });
30
34
  await subClient.connect();
31
35
 
32
- // ✅ Subscribe to Redis channel
33
- await subClient.subscribe(REDIS_CHANNEL, (message) => {
36
+ // ✅ Subscribe to the dynamic Redis channel
37
+ await subClient.subscribe(redisChannel, (message) => {
34
38
  const { workspaceId, event, data } = JSON.parse(message);
35
39
 
36
40
  if (namespace) {
@@ -92,10 +96,16 @@ const handleConnection = async (socket, namespace = null) => {
92
96
  * @param {string} workspaceId - Target workspace ID
93
97
  * @param {string} event - Event name
94
98
  * @param {Object} data - Event payload
99
+ * @param {string} [redisChannel="socket_events"] - Custom Redis Pub/Sub Channel
95
100
  */
96
- const sendEventToServer = async ({ workspaceId, event, data }) => {
101
+ const sendEventToServer = async ({
102
+ workspaceId,
103
+ event,
104
+ data,
105
+ redisChannel = "socket_events",
106
+ }) => {
97
107
  await redisClient.publish(
98
- REDIS_CHANNEL,
108
+ redisChannel,
99
109
  JSON.stringify({ workspaceId, event, data })
100
110
  );
101
111
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shuttlepro-shared",
3
- "version": "1.1.69",
3
+ "version": "1.1.70",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,6 +22,7 @@
22
22
  "mongoose": "^8.7.1",
23
23
  "cors": "^2.8.5",
24
24
  "helmet": "^8.0.0",
25
- "bull": "^4.10.4"
25
+ "bull": "^4.10.4",
26
+ "socket.io": "^4.8.1"
26
27
  }
27
28
  }