@devvit/realtime 0.12.1-next-2025-09-22-19-00-17-eb5ffb2a8.0 → 0.12.1-next-2025-09-22-20-12-49-9b3f04aa9.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/client.d.ts +1 -1
- package/client.d.ts.map +1 -1
- package/client.js +1 -1
- package/package.json +9 -9
- package/realtime.d.ts +7 -1
- package/realtime.d.ts.map +1 -1
- package/realtime.js +25 -25
package/client.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { type Connection, connectRealtime, type ConnectRealtimeOptions, disconnectRealtime, } from './realtime.js';
|
|
1
|
+
export { type Connection, connectRealtime, type ConnectRealtimeOptions, disconnectRealtime, isRealtimeConnected, } from './realtime.js';
|
|
2
2
|
//# sourceMappingURL=client.d.ts.map
|
package/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,eAAe,EACf,KAAK,sBAAsB,EAC3B,kBAAkB,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,eAAe,EACf,KAAK,sBAAsB,EAC3B,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,eAAe,CAAC"}
|
package/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { connectRealtime, disconnectRealtime, } from './realtime.js';
|
|
1
|
+
export { connectRealtime, disconnectRealtime, isRealtimeConnected, } from './realtime.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devvit/realtime",
|
|
3
|
-
"version": "0.12.1-next-2025-09-22-
|
|
3
|
+
"version": "0.12.1-next-2025-09-22-20-12-49-9b3f04aa9.0",
|
|
4
4
|
"license": "BSD-3-Clause",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -35,22 +35,22 @@
|
|
|
35
35
|
"test:unit-with-coverage": "vitest run --coverage"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@devvit/protos": "0.12.1-next-2025-09-22-
|
|
39
|
-
"@devvit/shared": "0.12.1-next-2025-09-22-
|
|
40
|
-
"@devvit/shared-types": "0.12.1-next-2025-09-22-
|
|
38
|
+
"@devvit/protos": "0.12.1-next-2025-09-22-20-12-49-9b3f04aa9.0",
|
|
39
|
+
"@devvit/shared": "0.12.1-next-2025-09-22-20-12-49-9b3f04aa9.0",
|
|
40
|
+
"@devvit/shared-types": "0.12.1-next-2025-09-22-20-12-49-9b3f04aa9.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@devvit/client": "*",
|
|
44
44
|
"@devvit/server": "*"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@devvit/client": "0.12.1-next-2025-09-22-
|
|
48
|
-
"@devvit/repo-tools": "0.12.1-next-2025-09-22-
|
|
49
|
-
"@devvit/server": "0.12.1-next-2025-09-22-
|
|
50
|
-
"@devvit/tsconfig": "0.12.1-next-2025-09-22-
|
|
47
|
+
"@devvit/client": "0.12.1-next-2025-09-22-20-12-49-9b3f04aa9.0",
|
|
48
|
+
"@devvit/repo-tools": "0.12.1-next-2025-09-22-20-12-49-9b3f04aa9.0",
|
|
49
|
+
"@devvit/server": "0.12.1-next-2025-09-22-20-12-49-9b3f04aa9.0",
|
|
50
|
+
"@devvit/tsconfig": "0.12.1-next-2025-09-22-20-12-49-9b3f04aa9.0",
|
|
51
51
|
"eslint": "9.11.1",
|
|
52
52
|
"typescript": "5.8.3",
|
|
53
53
|
"vitest": "1.6.1"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "5a216cfbb873d9d818cb009701fb203f6c026258"
|
|
56
56
|
}
|
package/realtime.d.ts
CHANGED
|
@@ -39,13 +39,18 @@ export type ConnectRealtimeOptions<Msg extends JsonValue> = {
|
|
|
39
39
|
*/
|
|
40
40
|
export declare const connectRealtime: <Msg extends JsonValue>(opts: Readonly<ConnectRealtimeOptions<Msg>>) => Promise<Connection>;
|
|
41
41
|
export declare function disconnectRealtime(channel: string): Promise<void>;
|
|
42
|
+
/** True if the channel socket is connected. */
|
|
43
|
+
export declare function isRealtimeConnected(channel: string): boolean;
|
|
42
44
|
/**
|
|
43
45
|
* Clears all connections. Used for testing purposes.
|
|
44
46
|
* @internal
|
|
45
47
|
*/
|
|
46
48
|
export declare const __clearConnections: () => void;
|
|
47
49
|
export declare class Connection {
|
|
48
|
-
|
|
50
|
+
/** @internal */
|
|
51
|
+
connected: boolean;
|
|
52
|
+
/** @internal */
|
|
53
|
+
readonly opts: Readonly<ConnectRealtimeOptions<JsonValue>>;
|
|
49
54
|
constructor(opts: Readonly<ConnectRealtimeOptions<JsonValue>>);
|
|
50
55
|
/**
|
|
51
56
|
* Disconnects from the realtime channel.
|
|
@@ -53,6 +58,7 @@ export declare class Connection {
|
|
|
53
58
|
* @deprecated Use `disconnectRealtime()`.
|
|
54
59
|
*/
|
|
55
60
|
disconnect(): Promise<void>;
|
|
61
|
+
/** @internal */
|
|
56
62
|
onMessage: (ev: MessageEvent<WebViewMessageEvent_MessageData>) => void;
|
|
57
63
|
}
|
|
58
64
|
//# sourceMappingURL=realtime.d.ts.map
|
package/realtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"realtime.d.ts","sourceRoot":"","sources":["../src/realtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"realtime.d.ts","sourceRoot":"","sources":["../src/realtime.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,0DAA0D,CAAC;AAChH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD,MAAM,MAAM,sBAAsB,CAAC,GAAG,SAAS,SAAS,IAAI;IAC1D,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,SAAS,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;CAChC,CAAC;AAQF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,eAAe,GAAU,GAAG,SAAS,SAAS,EACzD,MAAM,QAAQ,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC,KAC1C,OAAO,CAAC,UAAU,CAYpB,CAAC;AAEF,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAUvE;AAED,+CAA+C;AAC/C,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE5D;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,QAAO,IAErC,CAAC;AAUF,qBAAa,UAAU;IACrB,gBAAgB;IAChB,SAAS,EAAE,OAAO,CAAS;IAE3B,gBAAgB;IAChB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC,CAAC;gBAE/C,IAAI,EAAE,QAAQ,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAI7D;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC,gBAAgB;IAChB,SAAS,GAAI,IAAI,YAAY,CAAC,+BAA+B,CAAC,KAAG,IAAI,CAkCnE;CACH"}
|
package/realtime.js
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _Connection_opts;
|
|
1
|
+
import { EffectType } from '@devvit/protos/json/devvit/ui/effects/v1alpha/effect.js';
|
|
2
|
+
import { RealtimeSubscriptionStatus } from '@devvit/protos/json/devvit/ui/effects/v1alpha/realtime_subscriptions.js';
|
|
13
3
|
import { emitEffect } from '@devvit/shared-types/client/emit-effect.js';
|
|
14
4
|
const connectionsByChannel = new Map();
|
|
15
5
|
/* TODO: Clean up this API. Now that realtime has been removed from the
|
|
@@ -62,8 +52,15 @@ export async function disconnectRealtime(channel) {
|
|
|
62
52
|
return;
|
|
63
53
|
connectionsByChannel.delete(channel);
|
|
64
54
|
removeEventListener('message', connection.onMessage);
|
|
55
|
+
if (connection.connected)
|
|
56
|
+
connection.opts.onDisconnect?.(channel);
|
|
57
|
+
connection.connected = false;
|
|
65
58
|
await emitConnectionsEffect();
|
|
66
59
|
}
|
|
60
|
+
/** True if the channel socket is connected. */
|
|
61
|
+
export function isRealtimeConnected(channel) {
|
|
62
|
+
return !!connectionsByChannel.get(channel)?.connected;
|
|
63
|
+
}
|
|
67
64
|
/**
|
|
68
65
|
* Clears all connections. Used for testing purposes.
|
|
69
66
|
* @internal
|
|
@@ -75,12 +72,14 @@ export const __clearConnections = () => {
|
|
|
75
72
|
async function emitConnectionsEffect() {
|
|
76
73
|
await emitEffect({
|
|
77
74
|
realtimeSubscriptions: { subscriptionIds: [...connectionsByChannel.keys()] },
|
|
78
|
-
type:
|
|
75
|
+
type: EffectType.EFFECT_REALTIME_SUB,
|
|
79
76
|
});
|
|
80
77
|
}
|
|
81
78
|
export class Connection {
|
|
82
79
|
constructor(opts) {
|
|
83
|
-
|
|
80
|
+
/** @internal */
|
|
81
|
+
this.connected = false;
|
|
82
|
+
/** @internal */
|
|
84
83
|
this.onMessage = (ev) => {
|
|
85
84
|
const { type, data } = ev.data;
|
|
86
85
|
if (type !== 'devvit-message') {
|
|
@@ -90,28 +89,30 @@ export class Connection {
|
|
|
90
89
|
return;
|
|
91
90
|
}
|
|
92
91
|
const { status, event } = data.realtimeEvent;
|
|
93
|
-
if (!event?.channel.endsWith(
|
|
92
|
+
if (!event?.channel.endsWith(this.opts.channel)) {
|
|
94
93
|
return;
|
|
95
94
|
}
|
|
96
95
|
// Normalize the channel name (remove namespacing)
|
|
97
|
-
event.channel =
|
|
98
|
-
if (status ===
|
|
99
|
-
|
|
96
|
+
event.channel = this.opts.channel;
|
|
97
|
+
if (status === RealtimeSubscriptionStatus.REALTIME_SUBSCRIBED) {
|
|
98
|
+
this.connected = true;
|
|
99
|
+
this.opts.onConnect?.(this.opts.channel);
|
|
100
100
|
}
|
|
101
|
-
else if (status ===
|
|
102
|
-
|
|
101
|
+
else if (status === RealtimeSubscriptionStatus.REALTIME_UNSUBSCRIBED) {
|
|
102
|
+
this.connected = false;
|
|
103
|
+
this.opts.onDisconnect?.(this.opts.channel);
|
|
103
104
|
}
|
|
104
105
|
else if (event.data) {
|
|
105
|
-
|
|
106
|
+
this.opts.onMessage(event.data.msg);
|
|
106
107
|
}
|
|
107
108
|
else {
|
|
108
109
|
console.error('[realtime] Received event without data:', {
|
|
109
|
-
channel:
|
|
110
|
+
channel: this.opts.channel,
|
|
110
111
|
event,
|
|
111
112
|
});
|
|
112
113
|
}
|
|
113
114
|
};
|
|
114
|
-
|
|
115
|
+
this.opts = opts;
|
|
115
116
|
}
|
|
116
117
|
/**
|
|
117
118
|
* Disconnects from the realtime channel.
|
|
@@ -119,7 +120,6 @@ export class Connection {
|
|
|
119
120
|
* @deprecated Use `disconnectRealtime()`.
|
|
120
121
|
*/
|
|
121
122
|
async disconnect() {
|
|
122
|
-
await disconnectRealtime(
|
|
123
|
+
await disconnectRealtime(this.opts.channel);
|
|
123
124
|
}
|
|
124
125
|
}
|
|
125
|
-
_Connection_opts = new WeakMap();
|