sono.land
broadcast
broadcast
Broadcast a message to all clients in a channel
The broadcast method permits users to send a message to other members within its channel. The user will not see its own message. Upon invoking broadcast the first argument being the message is required however there is an optional second argument a custom event name. This custom event name will be stored in the response the server sends to all applicable clients. This will allow developers to create custom events dependent on the custom event name they are receiving on the client side from the server.
Client Side
1// example below demonstrates 'user is typing...'2document.getElementById('messageInputBox').addEventListener('onChange', () => {3 const user = document.getELementbyId('user').value;4 const message = `${user} is typing`;5 sono.broadcast(message);6});