Issue with Emitting Messages from Frappe to External Socket.io Clients

Hello Frappe Community,

I’m currently developing a custom app that requires real-time communication capabilities. I’ve set up a Node.js server using Express and Socket.io, integrated with Redis for handling real-time events. I’m facing an issue with messages being emitted from Frappe to external Socket.io clients. While internal communication within Frappe works as expected, the external emits are not functioning properly.

What I Intend To Achieve

I want to enable real-time messaging between Frappe and an external Node.js server using Socket.io. The goal is to send updates from Frappe to the external server, which then broadcasts these messages to connected clients.

What Works

  1. Message Sending from Client to Frappe: Clients connected to the Socket.io server can send messages to Frappe through Redis, and these are received properly.
  2. Internal Frappe Communication: Frappe successfully emits messages to other Frappe instances or services listening on the same Redis channels.

What Does Not Work

Emitting messages from Frappe to the external Node.js/Socket.io server does not work. The messages are intended to be broadcast to all connected external clients, but currently, only internal communication within Frappe is successful.

My Setup

Here is a brief overview of my Node.js setup:

// Node.js with Socket.io and Redis configuration
const express = require('express');
const http = require('http');
const socketIo = require('socket.io');
const redis = require('redis');

const app = express();
const server = http.createServer(app);
const io = socketIo(server, {
    cors: {
        origin: "*", 
        methods: ["GET", "POST"],
        credentials: true
    }
});

const subscriber = redis.createClient();
subscriber.subscribe("custom_connector", (message) => {
    console.log(message);
    io.emit('response_event', JSON.parse(message));
});

io.on('connection', (socket) => {
    console.log('A client connected');
    socket.on('disconnect', () => {
        console.log('A client disconnected');
    });
});

server.listen(9002, () => {
    console.log("Server is running on port 9002");
});

Has anyone faced a similar issue or can offer insights into what might be going wrong with the external emits from Frappe? Any suggestions on how to debug this problem or adjust the configurations would be greatly appreciated.

Frappe version-15

Thank you in advance for your help and suggestions!

Having the exact same problem, making chat apps with guests useless. Have you found the solution?