High-level WebSocket client with automatic reconnection, cross-tab connection sharing, and built-in RPC/event system.
PxConnect is a TypeScript library that simplifies building real-time applications over WebSocket.
Instead of manually implementing reconnection logic, heartbeat, tab synchronization, request-response handling, and room management, you work with a simple and consistent API.
Passimx Chats Frontend is released under the terms of the MIT license.
See https://opensource.org/license/MIT for more information.
| Area | Technologies Used |
|---|---|
| API | WebSocket |
| Encryption | SHA-512 / Ed25519 |
npm install @passimx/px.connect
# or
yarn add @passimx/px.connectimport { PxConnect } from '@passimx/px.connect';
const px = new PxConnect('url');
px.connect();px.join('channel:1', 'channel:2', 'channel:3');px.leave('channel:1', 'channel:2', 'channel:3');const channel = px.createChannel({
info?: {...},
data?: {...}
});Creates a new cryptographically identifiable channel.
- info — immutable initialization metadata. It becomes part of the channel identity and cannot be changed after creation.
- data — mutable channel state that can be updated during the channel lifetime.
The channel identifier is deterministically derived from the hash of the initialization data (info). This means that any modification to info results in a different channel ID.
const channel = px.createChannel({ exportInit: {...} });Restores an existing channel from a previously exported initialization object.
The imported exportInit contains all immutable initialization data required to reproduce the original channel, including its identifier. As long as exportInit remains unchanged, the restored channel will have the same channel ID.
const result = await px.callAction<T>(
{ connectionId: "..." }, // or { channelId: "..." }
{
action: "get-user",
payload: {...}
}
);Invokes a remote action and waits for its response.
The target may be:
{ connectionId }— send the request directly to a specific connection.{ channelId }— send the request to the owner of the channel.
The returned promise resolves with the value passed to onAction() on the remote side.
Actions can be addressed either to a specific connection or to a channel.
When a channel is the destination, the request is automatically routed to the channel owner—the connection that originally created the channel.
Client A ──── callAction({ connectionId }) ───► Client B
Client B ──── onAction(...) ─────────► Client A
Client A ───────────── callAction({ channelId }) ───► Channel Owner Connection
Channel Owner Connection ──── onAction(...) ─────────────────► Client A
px.onAction((routes) => {
routes.on("get-user", async (ctx: Context<string>) => {
const userId: string = ctx.payload
if(!userId) return;
...
return user
});
});Registers one or more action handlers.
Each handler receives a context object containing:
- from — the sender connection.
- to — the original destination (connectionId or channelId).
- payload — request payload.
- date — request timestamp.
px.offAction((routes) => {
routes.off("get-user", handler);
});Removes previously registered action handlers.