socket.io-redis-emitter icon indicating copy to clipboard operation
socket.io-redis-emitter copied to clipboard

Synchronous processing between 2 libraries

Open hoangphongdhhp opened this issue 3 years ago • 2 comments

"socket.io-redis-emitter": io.to(id).emit(eventName); "socket.io-redis-adapte": await io.of('/').adapter.remoteJoin('', 'room1');

hoangphongdhhp avatar Dec 11 '21 16:12 hoangphongdhhp

I found the solution: redis v4 has a new update: await publisher.publish('channel', 'message'); and here is the code I modified the library "socket.io-redis-emitter" file index.js, hope it helps someone:

    emit(ev, ...args) {
        return new Promise(async (resolve) => {
            if (exports.RESERVED_EVENTS.has(ev)) {
                throw new Error(`"${ev}" is a reserved event name`);
            }
            // set up packet object
            const data = [ev, ...args];
            const packet = {
                type: socket_io_parser_1.PacketType.EVENT,
                data: data,
                nsp: this.broadcastOptions.nsp,
            };
            const opts = {
                rooms: [...this.rooms],
                flags: this.flags,
                except: [...this.exceptRooms],
            };
            const msg = msgpack.encode([UID, packet, opts]);
            let channel = this.broadcastOptions.broadcastChannel;
            if (this.rooms && this.rooms.size === 1) {
                channel += this.rooms.keys().next().value + "#";
            }
            debug("publishing message to channel %s", channel);
            await this.redisClient.publish(channel, msg);
            resolve(true);
        });
    }

hoangphongdhhp avatar Dec 13 '21 03:12 hoangphongdhhp

Hope admin will update this change soon

hoangphongdhhp avatar Dec 13 '21 03:12 hoangphongdhhp

Please reopen if needed.

darrachequesne avatar Jan 12 '23 05:01 darrachequesne