V
V
Vladimir Golub2020-01-14 17:47:46
JavaScript
Vladimir Golub, 2020-01-14 17:47:46

How to send a message only to recipients from the list?

After authorization, I enter socket.id into an array. How to send a message only to them?

socket.emit('block_item', {itemId: data.id});

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Z
zendor, 2019-03-30
@vnesterov2005

Because the script is included in the head and the DOM has not yet been formed at the time the element is searched.

R
ReActor Dmitry Vershansky, 2019-03-30
@HunteR-VRX

Because you need to store the DOM element you received earlier in a variable

var myElement = document.getElementById('message').innerHTML = 'Hello';

P
ProAI, 2020-01-15
@ProAI

You don't need to put users in an array.
socket.io supports rooms (Room) or other channels.
You should simply add an authorized user to a specific room: and then send messages to the selected room(s):
More transmission options here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question