@blackevin/client
v0.1.0
Published
The Blackevin SDK: connect, subscribe to channels, publish, and read presence.
Readme
@blackevin/client
The Blackevin SDK: connect, subscribe to channels, publish, and read presence.
import * as Blackevin from "@blackevin/client";
const realtime = new Blackevin.Realtime({ key: "…", clientId: "bob" });
const channel = realtime.channels.get("chat:lobby");
channel.subscribe((message) => console.log(message.data));
await channel.publish("hello", { text: "hi" });
channel.presence.subscribe(["enter", "leave", "update"], async () => {
console.log("Members:", await channel.presence.get());
});Browser and Node. Authentication is by publishable key or by a short-lived token your server signs, so an API key secret never reaches a browser.
Where it connects
Nothing to configure: new Blackevin.Realtime({ key }) talks to Blackevin.
endpoint is there for when you need something else — a self-hosted node, a
local dev node, a staging environment. It resolves in this order:
- the
endpointoption BLACKEVIN_ENDPOINT, where an environment exists (Node, Bun, Deno)wss://ws.blackevin.com
restEndpoint follows the same order with BLACKEVIN_REST_ENDPOINT, except that an
explicitly-given endpoint implies it — a dev or self-hosted node serves both
from one origin, so ws://127.0.0.1:3000 yields http://127.0.0.1:3000. Only
the default falls through to https://api.blackevin.com, because in production the
socket and the API are separate services and swapping the scheme would send REST
calls to a host that serves none.
Step 2 needs an actual environment, so it covers Node, Bun and Deno. A browser bundle has none at runtime — if a web app wants to point somewhere else per build, it reads its own env and passes the result:
new Blackevin.Realtime({
endpoint: import.meta.env.VITE_BLACKEVIN_WS, // unset in prod → the default
key,
});Everything exported is public API — see CLAUDE.md before changing a signature.
