@volorio/rtm 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # @volorio/rtm
2
+
3
+ Volorio Real-Time Messaging client for channel messages, presence, and low-latency app events.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @volorio/rtm
9
+ ```
10
+
11
+ `@volorio/rtm` is built on Volorio signaling. Customer applications import Volorio packages only.
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { VolorioRtmClient } from "@volorio/rtm";
17
+ import { VolorioSignalingClient } from "@volorio/signaling";
18
+
19
+ const rtm = new VolorioRtmClient(new VolorioSignalingClient(room));
20
+
21
+ await rtm.publishMessage("lobby", { text: "hello" });
22
+ await rtm.setPresence("lobby", { status: "available" });
23
+
24
+ const unsubscribe = rtm.onMessage("lobby", (message) => {
25
+ console.log(message.payload);
26
+ });
27
+ ```
@@ -0,0 +1,23 @@
1
+ import { VolorioSignalingClient, type VolorioSignalEnvelope, type VolorioSignalHandler } from "@volorio/signaling";
2
+ export interface VolorioRtmMessage<TPayload = unknown> {
3
+ channel: string;
4
+ payload: TPayload;
5
+ clientMessageId?: string;
6
+ }
7
+ export interface VolorioRtmPresence {
8
+ identity?: string;
9
+ status: "online" | "away" | "busy" | "offline" | string;
10
+ metadata?: Record<string, unknown>;
11
+ }
12
+ export type VolorioRtmEvent<TPayload = unknown> = VolorioSignalEnvelope<VolorioRtmMessage<TPayload> | VolorioRtmPresence>;
13
+ export declare class VolorioRtmClient {
14
+ private readonly signaling;
15
+ constructor(signaling: VolorioSignalingClient);
16
+ publishMessage<TPayload>(channel: string, payload: TPayload, clientMessageId?: string): Promise<void>;
17
+ setPresence(channel: string, presence: VolorioRtmPresence): Promise<void>;
18
+ onMessage<TPayload>(channel: string, handler: (event: VolorioSignalEnvelope<VolorioRtmMessage<TPayload>>) => void): () => void;
19
+ onPresence(channel: string, handler: (event: VolorioSignalEnvelope<VolorioRtmPresence>) => void): () => void;
20
+ subscribe<TPayload>(channel: string, type: string, handler: VolorioSignalHandler<TPayload>): () => void;
21
+ }
22
+ export { VolorioSignalingClient, parseVolorioSignal } from "@volorio/signaling";
23
+ export type { VolorioSignalEnvelope, VolorioSignalHandler };
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseVolorioSignal = exports.VolorioSignalingClient = exports.VolorioRtmClient = void 0;
4
+ class VolorioRtmClient {
5
+ signaling;
6
+ constructor(signaling) {
7
+ this.signaling = signaling;
8
+ }
9
+ async publishMessage(channel, payload, clientMessageId) {
10
+ await this.signaling.publish(channel, "volorio.rtm.message", { channel, payload, clientMessageId });
11
+ }
12
+ async setPresence(channel, presence) {
13
+ await this.signaling.publish(channel, "volorio.rtm.presence", presence);
14
+ }
15
+ onMessage(channel, handler) {
16
+ return this.subscribe(channel, "volorio.rtm.message", handler);
17
+ }
18
+ onPresence(channel, handler) {
19
+ return this.subscribe(channel, "volorio.rtm.presence", handler);
20
+ }
21
+ subscribe(channel, type, handler) {
22
+ return this.signaling.subscribe(channel, (event) => {
23
+ if (event.type === type) {
24
+ handler(event);
25
+ }
26
+ });
27
+ }
28
+ }
29
+ exports.VolorioRtmClient = VolorioRtmClient;
30
+ var signaling_1 = require("@volorio/signaling");
31
+ Object.defineProperty(exports, "VolorioSignalingClient", { enumerable: true, get: function () { return signaling_1.VolorioSignalingClient; } });
32
+ Object.defineProperty(exports, "parseVolorioSignal", { enumerable: true, get: function () { return signaling_1.parseVolorioSignal; } });
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAgBA,MAAa,gBAAgB;IACE;IAA7B,YAA6B,SAAiC;QAAjC,cAAS,GAAT,SAAS,CAAwB;IAAG,CAAC;IAElE,KAAK,CAAC,cAAc,CAAW,OAAe,EAAE,OAAiB,EAAE,eAAwB;QACzF,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,qBAAqB,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAwC,CAAC,CAAC;IAC5I,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,OAAe,EAAE,QAA4B;QAC7D,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,sBAAsB,EAAE,QAAQ,CAAC,CAAC;IAC1E,CAAC;IAED,SAAS,CAAW,OAAe,EAAE,OAA4E;QAC/G,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAC;IACjE,CAAC;IAED,UAAU,CAAC,OAAe,EAAE,OAAmE;QAC7F,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,sBAAsB,EAAE,OAAO,CAAC,CAAC;IAClE,CAAC;IAED,SAAS,CAAW,OAAe,EAAE,IAAY,EAAE,OAAuC;QACxF,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,KAAsC,EAAE,EAAE;YAClF,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;gBACxB,OAAO,CAAC,KAAK,CAAC,CAAC;YACjB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA1BD,4CA0BC;AAED,gDAAgF;AAAvE,mHAAA,sBAAsB,OAAA;AAAE,+GAAA,kBAAkB,OAAA"}
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@volorio/rtm",
3
+ "version": "0.2.0",
4
+ "private": false,
5
+ "description": "Volorio Real-Time Messaging client for channel messages, presence, and low-latency app events.",
6
+ "main": "dist/src/index.js",
7
+ "types": "dist/src/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/src/index.d.ts",
11
+ "default": "./dist/src/index.js"
12
+ }
13
+ },
14
+ "files": ["dist/src", "README.md"],
15
+ "publishConfig": {
16
+ "access": "public",
17
+ "registry": "https://registry.npmjs.org/"
18
+ },
19
+ "scripts": {
20
+ "build": "tsc -p tsconfig.build.json",
21
+ "test": "pnpm build",
22
+ "pack:local": "pnpm build && npm pack --pack-destination dist"
23
+ },
24
+ "dependencies": {
25
+ "@volorio/signaling": "^0.2.0"
26
+ }
27
+ }