Shrew

Free Real‑Time Communication Engine

Create Account (no personal data needed)

Edit Account

Usage

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" }));

Optional Back-End Endpoints

(Used by Shrew for Validation & Message Logging)

“HTTP Endpoint for Join Validation (Optional)”

When a WebSocket client connects to Shrew and sends a join request, Shrew only validates the session key. If you want to perform additional authentication on your own back‑end — for example, checking user credentials or validating access rights — you can provide an optional HTTP endpoint. Shrew will call this endpoint during the join process whenever a client attempts to enter a room.

Shrew will make a POST request to your endpoint and include a JSON body containing the username and password that the WebSocket client sent in the join message:
{ “username”: “<username>”, “password”: “<password>” }

Your back‑end should return HTTP 200 when authentication succeeds, and any other HTTP status code when authentication fails.

“HTTP Endpoint for Message Saving (Optional)”

When a WebSocket client sends a message to a room (after joining it), Shrew can optionally forward a copy of that message to your back‑end. To enable this behavior, you must specify an HTTP endpoint for message saving when creating your account (or when updating it later).

Whenever a client sends a chat message, Shrew will make a POST request to your endpoint with the following JSON payload:
{ “source_user_name” : “<source_user_name>”, “target_room_id” : “<target_room_id>” }

Your back‑end should return HTTP 200 if the message was processed successfully. Any other HTTP status code will be treated as a failure.

“HTTP Endpoint for Authorizing a Room ID (Optional)”

During a join operation, Shrew can optionally send your back‑end the room ID that a client is attempting to join or create. Your back‑end can then decide whether that room ID is allowed. To enable this behavior, you must specify an HTTP endpoint for room authorization when creating your account (or when updating it later).

Whenever a client sends a join message, Shrew will make a GET request to your endpoint, passing the room ID as a query parameter:
“<your endpoint>?roomid=<target_room_id>&username=<source_username>”

Your back‑end should return HTTP 200 if the target_room_id name is allowed. Any other HTTP status code will be treated as a failure.