Created
April 17, 2019 05:51
-
-
Save beardlessman/8b84e2e82c442a06bd5a18c47f340408 to your computer and use it in GitHub Desktop.
Выбираем, кому эмитить событие
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ответить | |
// текущему клиенту | |
socket.emit(EVENT_NAME, data); | |
// клиентам этой сессии | |
const sockets = io.sockets.sockets; | |
const clients = Object.keys(sockets); | |
clients.forEach(client => { | |
if (sockets[client].handshake.sid !== socket.handshake.sid) return; | |
sockets[client].emit(EVENT_NAME, data); | |
}); | |
// всем подключенным клиентам | |
io.emit(EVENT_NAME, data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment