discorddocs

Server Side Room Service

Room Service comes with a powerful server client for Node.js that lets you update objects within the room from the server without overwriting what the user is doing on the browser. If you want a client for another language, send us a note.

Installing

You can get the Node client with:

yarn add @roomservice/node

# Or...

npm install --save @roomservice/node

Setting up

First, create a new RS client. It's best to just have one of these in your application.

const RoomService = require("@roomservice/node").default;

const rs = new RoomService("YOUR_API_KEY");

Checkpoints

In order to remove the operational burden on you, the Node client does not open a WebSocket. That means it's safe to use in Serverless environments or in hosting platforms that struggle to handle many open connections.

So instead of providing a "room", the Node client provides "checkpoints". Checkpoints are just a point-in-time for a room and implement a subset of the functions that the browser-side room client would.

Create a new checkpoint with the most recent state of the room:

const checkpoint = await rs.checkpoint("myroom");

With the checkpoint, you can read data from maps and lists.

let map = checkpoint.map("coolmap");
map.toObject(); // { someKey: "someValue"  }

But unlike the browser client, if you make a change, it's not immediately sent to everyone. Instead, you can batch up changes and send them all in one go.

map = map.set("lunch", "ramen");
map = map.set("dog", "golden");

await checkpoint.save(map);

You can also save changes to multiple objects at once:

await checkpoint.save(map, anotherMap, someList, anotherList);

Made with 🌁 in San Francisco

hello@roomservice.dev

About Us

Copyright @ 2021

Room Service