this is on my server side
socket.on('searching', (userID) => {
usersSearching.push(userID);
console.log(usersSearching);
// Jika ada dua pengguna atau lebih yang mencari, pilih dua pengguna secara acak
if (usersSearching.length >= 2) {
const [user1, user2] = getRandomUsers(usersSearching);
const uid = [user1, user2].join('');
const id1 = user1.toString();
const id2 = user2.toString();
socket.emit(id2, uid);
socket.emit(id1, uid);
usersSearching.splice(usersSearching.indexOf(user1), 1);
usersSearching.splice(usersSearching.indexOf(user2), 1);
// Mengurutkan secara descending (berdasarkan urutan leksikografis terbalik)
// Hubungkan kedua pengguna yang terpilih
}
});
and this is on the side of each of my clients,
I took the user ID from the database
socket.on(profile.userData.value.id!, (id) {
chat.idRandom(id);
print(id);
update();
});
and this is the response I got from the server [ 'C7gNAYvqssgqTMVLKF7kCWHsbmh2', 'sz7Er9blxpXjztNJw3Y4ZQRAqEo1' ] User joined room: C7gNAYvqssgqTMVLKF7kCWHsbmh2sz7Er9blxpXjztNJw3Y4ZQRAqEo1
You can see that only the 2nd emit is executed while the first emit is skipped... I've tried it back and forth, the results are the same.
Please help me
I tried emitting to 2 users with their respective IDs. but the result is that only the second emit is sent to the client