-
-
Save maddin77/c437b7a58489c7725a6f 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
// pseudo-code | |
// wenn sich ein client verbindet | |
io.on("connection", function (socket) { | |
// irgendwas womit du den client eindeutig identifizieren kannst. | |
// benutzername, oder ne eindeute ID oder sowas | |
socket.username = eindeutigerBenutzername; | |
}); | |
// irgendwo im code, wo du etwas an einen bestimmten nutzer schicken willst | |
// io.sockets.sockets ist ein array mit allen zur zeit verbundenen clients | |
// mit array.find kannst du dann einfach den client anhand username (oder was auch immer du oben genommen hast) suchen | |
const socket = io.sockets.sockets.find(function (socket) { | |
return socket.username === usernameDesBenutzersDenDuSuchst; | |
}); | |
socket.emit("receiveOffer", blabla); // sendet das event nur an den einen Client |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment