socketio / socket.io-redis-emitter

The Socket.IO Redis emitter, allowing to communicate with a group of Socket.IO servers from another Node.js process.
https://socket.io/docs/v4/redis-adapter/
MIT License
722 stars 121 forks source link

Socket emit with ack function #72

Closed ghost closed 3 years ago

ghost commented 6 years ago

Hello. I can't make an emit with ack function. I would like to send information from client to server, and then, a server will need to reply. Can you help me how to make that, please? Is that appropriate way, if so, how to make it work? Because now it doesn't! Server

const electron = require('electron');
const {app, BrowserWindow} = electron;

app.on('ready', () => {
  let win = new BrowserWindow({width:800, height: 600})
  win.loadURL(`file://${__dirname}/index.html`)
  win.webContents.openDevTools()
})

var server = require('http').createServer();
var io = require('socket.io')(server);

io.on('connection', function(client){
  console.log('Socket connection established');

  io.on("signIn", (bid, text) => {
      domain('Root!');

  });
});

server.listen(3000);

Client


var socket = io.connect('http://localhost:3000');
socket.on('connect', function() {
  console.log('Client connected');

  socket.emit('signIn', 'coffee', (data) => {
    console.log(data); // data will be 'Pizza'
  });

});

Thank you!

darrachequesne commented 3 years ago

For future readers:

io.on('connection', (socket) => {
  console.log('Socket connection established');

  socket.on('signIn', (bid, callback) => {
     console.log(bid); // prints "coffee"
     callback('Pizza');
  });
});

Please see https://socket.io/docs/v3/emitting-events/#Acknowledgements

arpankumarlahiri commented 1 year ago

For future readers:

io.on('connection', (socket) => {
  console.log('Socket connection established');

  socket.on('signIn', (bid, callback) => {
     console.log(bid); // prints "coffee"
     callback('Pizza');
  });
});

Please see https://socket.io/docs/v3/emitting-events/#Acknowledgements

https://github.com/socketio/socket.io-redis-emitter/blob/bfefbdefd963b59279b7f55673a88296a660f7d8/lib/index.ts#L226

this error is coming, is the socket acknowledgement not available for server side yet now?

In socket documentation I think its available https://socket.io/docs/v4/broadcasting-events/#with-acknowledgements

RamAddict commented 7 months ago

This was marked as closed, but as @arpankumarlahiri mentioned it hasn't been implemented. Will this be implemented or should this marked as won't implement?

darrachequesne commented 7 months ago

@RamAddict getting acknowledgements from a Socket.IO cluster with the emitter is indeed currently not implemented. Could you please share your use case?

RamAddict commented 7 months ago

Our use case is trying to get a confirmation of a notification back from the user. Our current workaround is to create a @SubscribeMessage (nestjs) and have the user send a message of that kind back with the notification ID if everything went smoothly.