I am using adonis js in my back-end and I want to get a callback acknowledgement, in the ChatController the on message function looks like this:
class ChatController {
//{ socket, request, auth }
constructor(ctx) {
this.socket = ctx.socket
this.request = ctx.request
this.auth = ctx.auth
// Add/Update socket id for current logged in user
all_sockets[this.auth.user.username] = this.socket.id
this.socket.emitTo('connect', {username: this.auth.user.username, socketId: this.socket.id}, [this.socket.id])
}
**onMessage(message) {
//this.socket.broadcastToAll('message', message)
console.log('msg sent', message)
}**
}
so I don't know how can I get a callback to make sure that the message was sent or not, in node js I would write it this way
socket.on('message', (msg, callback) => {
console.log(msg);
socket.broadcast.emit('message-broadcast', msg);
callback({serverReceived: true})
socket.emit("message-sent", (data) => {
if(data.messageSent){
console.log("message sent")
}else{
console.log("retry sending the message")
}
})
});
the problem in adonis web sockets that on message is built in so I can't add another parameter for the callback, any idea how can I do it ?