Shrew
Free Real‑Time Communication Engine
const ws = new WebSocket('wss://dgtaware.com:3000');
ws.onopen = () =>{
ws.send(JSON.stringify({
type: 'join',
room: 'room1',
username: 'user_1',
password: 'pwd1',
company: 'mycompany',
session_key: '0A2345461111BFE2423FF32423EEE',
}));
});
ws.onmessage = (event) =>{
try { const msg = JSON.parse(data);
if (msg.type === 'notification')
{
if(msg.hasOwnProperty("message_error") && msg.message_error == "Join Error")
{
return;
}
else if(msg.hasOwnProperty("message_username_joined"))
{
//New user joined my room: "+msg.message_username_joined);
}
else if(msg.hasOwnProperty("users"))
{
//Users already in the room: "+msg.users);
//Websocket is now connected");
}
}
else if (msg.type === 'chat')
{
//Chat: ${msg.username}: ${msg.message}
}
}
catch (err)
{
//Received invalid JSON: ${err}
}
});
ws.onclose = () =>{
//Websocket disconnected
});
ws.onerror = (err) =>{
//Websocket error:, err.message
});
...
ws.send(JSON.stringify({ type: 'chat', message:"Hello from client" }));