Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis Adapter emits message twice #477

Open
willjk opened this issue Dec 15, 2022 · 0 comments
Open

Redis Adapter emits message twice #477

willjk opened this issue Dec 15, 2022 · 0 comments

Comments

@willjk
Copy link

willjk commented Dec 15, 2022

When I use callbacks and I follow this pattern client-1 -> server -> client-2 -> callback-to-server -> callback-to-client-1 the adapter appears to send messages twice to client-2. Here is replication code. When I comment out all redis things it will only send once

Server

`const socketIo = require("socket.io");
const redisAdapter = require("@socket.io/redis-adapter");
const redis = require("redis");

const io = new socketIo.Server(
{
cors: {
origin: process.env.ORIGIN,
methods: ["GET", "POST"],
credentials: true,
},
}
);

let ns = io.of('/');

const pubClient = redis.createClient({ url: "redisurl" });
const subClient = pubClient.duplicate();

Promise.all([pubClient.connect(), subClient.connect()]).then(() => {
io.adapter(redisAdapter.createAdapter(pubClient, subClient));
io.listen(PORT);
});

pubClient.on('connect', () => {
console.log('::> Redis Client Connected');
});
pubClient.on('error', (err) => {
console.log('<:: Redis Client Error', err);
});

ns.on("connection", async (socket) => {
socket.on("host:broadcast", async (data, callback) => {
const room = socket.to(data.room);
room.emit("member:message", data, (arg) => {
callback(arg);
});
});
});

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant