Pulse is a tool built by Metrik to allow for incredibly efficient realtime WebSocket communication between the web and Roblox. Pulse is built on top of Cloudflare Durable Objects and the Open Cloud MessagingService API.
Pulse makes use of a number of techniques to make the server as efficient as possible, including:
- Virtual MessagingService topics to avoid consuming too much usage
- Hibernation of Durable Objects between messages to reduce cost
Note
A Cloudflare Workers 'Paid plan' account is required to use Pulse.
- Clone the repository (or download the zip file) and navigate to the
server
directory. - Install the dependencies by running
pnpm install
.
Note
If you don't have pnpm installed, read their docs at https://pnpm.io/installation
- Create a new Cloudflare account if you do not already have one.
- Subscribe to the Workers Paid plan (this is required to deploy the server).
- Create a new KV namespace in Cloudflare using the command
pnpx wrangler kv:namespace create UNIVERSE_REGISTRY
. You may need to sign in on Cloudflare. - Replace the original
id
with your newly created KV namespace ID in thewrangler.toml
file under[[kv_namespaces]]
. - Run
pnpm run deploy
to deploy the server to Cloudflare Workers. - Open the Worker's settings on Cloudflare (this link will take you right there)
- Press '+ Add' beside 'Variables and Secrets'
- Enter
API_KEY
as the variable name and a randomly generated string as the variable. You can use https://generate-secret.vercel.app/64 to generate a sufficiently long string.
Caution
Do not forget this value! This is required to interact with the server, either through the UI or through the API/clients.
- Press 'Encrypt' and then 'Deploy'.
- Repeat steps 5 through 7 for the
ENCRYPTION_KEY
variable. You do not need to note down this variable. - You are now done! Press the 'Visit' button at the top of the page to open the UI, and this will be the hostname you use with the Roblox & Server clients.
Pulse comes out of the box with a UI that you can use to inspect the throughput of the server, and manage the Universe Registry. The Universe Registry manages the Open Cloud API keys (which are required to communicate with Roblox games) for each universe you want to use with Pulse.
- Go to the Creator Hub and if using with a group, select the group you want to use in the top left corner dropdown.
- Select 'Open Cloud' and then 'API Keys' from the left sidebar.
- Click 'Create API Key' and then give the key a name.
- Under 'Access Permissions', select
messaging-service
, then 'Add API System'. - In the new search box that appears, search for the game you want to use with Pulse, and select it.
- Under 'Security' put
0.0.0.0/0
in the 'Accepted IP Addresses' field. - Do not let the key expire, and then click 'Save & Generate Key'.
- Save for the next step.
take it away, brandon! should look something like this:
local PulseClient = require(location.of.pulse.client)
local pulse = PulseClient.new({
serverUrl = "https://your-pulse-server",
apiKey = "your-api-key",
})
pulse.Subscribe("test", function(message)
pritn(message)
end)
pulse.Send(topic, message, {
destination = "server" -- default, can be "roblox" for server-server comms.
serverId = "optional-server-id" -- only needed if destination is "roblox". more useful when you are the server.
})
pnpm install @metrik/pulse
import { Pulse } from "@metrik/pulse";
const pulse = new Pulse({
serverUrl: "https://your-pulse-server",
apiKey: "your-api-key",
});
const universe = pulse.Universe(2745313133);
const { subscribe } = await universe.connect();
subscribe("test", (message) => {
console.log(message);
});
await universe.send({
topic: "test",
message: "hello world",
serverId: "optional-server-id",
destination: "roblox" // default, can be "server" for server-server comms (why you would want this is beyond me)
})
Pulse comes with a UI that you can use to interact with the Game Registry, as well as inspect stats about the operation of the server. It is available on the root path of your deployed Worker.