Skip to content

Callback from user A to user B #3275

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

Closed
IamNotHuman opened this issue Jun 15, 2018 · 9 comments
Closed

Callback from user A to user B #3275

IamNotHuman opened this issue Jun 15, 2018 · 9 comments

Comments

@IamNotHuman
Copy link

Is there a way to do a callback that passes throw the server to another user?

@sudoshreyas
Copy link

can you please be more specific?

@IamNotHuman
Copy link
Author

For example:

// client A
this.socket.emit('call client b', room, (callback)=>{
    if(callback)
        console.log(true);
    else
        console.log(false);
});

// server

socket.on('call client b', function(room, callback1) {
    socket.to(room).emit('call client b', (callback2)=>{
        if(callback2)
           callback1(true);
        else
           callback1(false);
    });
});

// client B

socket.on('call client b', function(callback) {
     callback(true);
});

@Twois
Copy link

Twois commented Jun 21, 2018

You can emit to client B from the server

//server
io.to(socketIdOfClientB).emit('keyOfClientBListener', { "success": true, "msg": "have some fun" });

//Client side
socket.on('keyOfClientBListener', (data) => { //do something });

@bharathnallamothu
Copy link

bharathnallamothu commented Jul 27, 2018

@Twois @IamNotHuman @darrachequesne @subdash @sudoshreyas i have 5 rooms on server let say "A", "B","C","D","E"
server side
i.e `io.on('connection', (socket) => {
console.log('New user connected');
socket.on('disconnect', () => {
console.log('User was disconnected');
});
});
//function that create rooms
function connectSocket(data) {
io.emit(data.device_id, data);
console.log('room',data.device_id, 'created');
}
// room creation call
connectSocket("A")

client side
var socket = io(url);
socket.on('connect', function () {
console.log('Connected to server');
});
socket.on(roomname, function (message) {
console.log(message);
});
`
problem
i want to leave room A and join room B
after joins room B i don't want to to hear data from room A

@LoganDark
Copy link

@bharathnallamothu excuse me, why did you mention me? I have nothing to do with this.

@bharathnallamothu
Copy link

@LoganDark i thought you are good at socket io if not ignore ... :(

@LoganDark
Copy link

Sorry, I'm not very experienced with socket.io. I don't use it very much. Please don't mention me for trivial reasons. Additionally, if you'd like help, please try explaining your issue a little better. What's a "switch", for example? I may not be able to help, but others might if you give them something to work off of.

@darrachequesne
Copy link
Member

@bharathnallamothu please open a new issue (note: you can wrap your code example within ```js <your code> ```, so that it is easier to read)

@IamNotHuman to answer your question, no there is currently no way to use acknowledgements between two clients, it only works between the client and the server.

@darrachequesne
Copy link
Member

Merged into #1811

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

6 participants