@blogmcp/sdk 0.10.1 → 0.12.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/dist/community/channels.d.ts +3 -2
- package/dist/community/client.d.ts +130 -3
- package/dist/community/client.js +232 -161
- package/dist/community/forum.d.ts +82 -0
- package/dist/community/forum.js +96 -0
- package/dist/community/index.d.ts +14 -7
- package/dist/community/index.js +185 -121
- package/dist/community/links.d.ts +38 -0
- package/dist/community/links.js +98 -71
- package/dist/community/messages.cs.d.ts +164 -3
- package/dist/community/messages.cs.js +184 -3
- package/dist/community/messages.d.ts +19 -1
- package/dist/community/messages.en.d.ts +154 -3
- package/dist/community/messages.en.js +167 -3
- package/dist/community/messages.js +37 -28
- package/dist/community/outcome.d.ts +8 -3
- package/dist/community/outcome.js +61 -20
- package/dist/community/poll.d.ts +28 -4
- package/dist/community/poll.js +70 -47
- package/dist/community/realtime/index.d.ts +19 -3
- package/dist/community/realtime/index.js +175 -145
- package/dist/community/routes.d.ts +36 -1
- package/dist/community/routes.js +51 -21
- package/dist/community/server/bff.d.ts +25 -2
- package/dist/community/server/bff.js +135 -118
- package/dist/community/server/host-routes.d.ts +3 -0
- package/dist/community/server/host-routes.js +17 -0
- package/dist/community/server/index.d.ts +5 -1
- package/dist/community/shapes.d.ts +649 -7
- package/dist/community/shapes.js +92 -61
- package/dist/community/store.d.ts +27 -0
- package/dist/community/store.js +84 -80
- package/dist/community/topic.d.ts +173 -0
- package/dist/community/topic.js +225 -0
- package/dist/nuxt/composables/useAsyncKb.d.ts +10 -4
- package/dist/packages/mdx-render-vue/dist/render/gallery/GalleryLightbox.vue.js +2 -2
- package/dist/packages/mdx-render-vue/dist/render/tripmap/TripMapDefault.vue.js +36 -36
- package/package.json +3 -3
- package/src/community/channels.ts +3 -2
- package/src/community/client.ts +212 -7
- package/src/community/forum.ts +209 -0
- package/src/community/index.ts +146 -2
- package/src/community/links.ts +64 -4
- package/src/community/messages.cs.ts +185 -3
- package/src/community/messages.en.ts +168 -3
- package/src/community/messages.ts +25 -2
- package/src/community/outcome.ts +47 -1
- package/src/community/poll.ts +79 -17
- package/src/community/realtime/index.ts +124 -48
- package/src/community/routes.ts +42 -1
- package/src/community/server/bff.ts +89 -30
- package/src/community/server/host-routes.ts +20 -0
- package/src/community/server/index.ts +5 -1
- package/src/community/shapes.ts +677 -6
- package/src/community/store.ts +25 -7
- package/src/community/topic.ts +521 -0
- package/src/core/markdown.ts +1 -1
- package/src/nuxt/composables/useAsyncKb.ts +11 -4
- package/src/nuxt/nuxt-imports.d.ts +2 -2
package/dist/community/poll.js
CHANGED
|
@@ -1,70 +1,93 @@
|
|
|
1
|
-
import { COMMUNITY_HEAD_ARTICLES_MAX as
|
|
2
|
-
const
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { COMMUNITY_HEAD_ARTICLES_MAX as C, COMMUNITY_HEAD_TOPICS_MAX as S } from "./routes.js";
|
|
2
|
+
const E = 2e4, k = 5 * 6e4, w = 6e4, x = (t, o) => t.lastSeq === o.lastSeq && t.count === o.count && t.lastChangeAt === o.lastChangeAt;
|
|
3
|
+
function D(t, o, n) {
|
|
4
|
+
return b(
|
|
5
|
+
{
|
|
6
|
+
ask: (e, a) => t.discussions.head({ articleIds: e }, a),
|
|
7
|
+
keyOf: (e) => typeof e?.articleId == "string" ? e.articleId.toLowerCase() : null,
|
|
8
|
+
max: C,
|
|
9
|
+
stopsOn: ["surfaceOff"]
|
|
10
|
+
},
|
|
11
|
+
o,
|
|
12
|
+
n
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
function F(t, o, n) {
|
|
16
|
+
return b(
|
|
17
|
+
{
|
|
18
|
+
ask: (e, a) => t.forum.topics.head({ conversationIds: e }, a),
|
|
19
|
+
keyOf: (e) => typeof e?.conversationId == "string" ? e.conversationId.toLowerCase() : null,
|
|
20
|
+
max: S,
|
|
21
|
+
stopsOn: ["surfaceOff", "membersOnly"]
|
|
22
|
+
},
|
|
23
|
+
o,
|
|
24
|
+
n
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
function b(t, o, n) {
|
|
28
|
+
const e = Math.max(1e3, n.intervalMs ?? E), a = [...new Set((Array.isArray(o) ? o : []).filter((i) => typeof i == "string" && i !== ""))].slice(0, t.max), A = n.visible ?? (() => typeof document > "u" || document.visibilityState !== "hidden"), g = /* @__PURE__ */ new Map();
|
|
29
|
+
let s = null, c = null, f = 0, y = !1, l = !1;
|
|
30
|
+
const u = (i) => {
|
|
31
|
+
l || (s && clearTimeout(s), s = setTimeout(() => {
|
|
32
|
+
L();
|
|
33
|
+
}, i));
|
|
34
|
+
}, p = (i) => {
|
|
35
|
+
u(i), y = !0;
|
|
15
36
|
}, M = () => {
|
|
16
|
-
!
|
|
37
|
+
!l && !c && !y && u(0);
|
|
17
38
|
};
|
|
18
|
-
async function
|
|
19
|
-
if (
|
|
20
|
-
if (!
|
|
21
|
-
|
|
39
|
+
async function L() {
|
|
40
|
+
if (s = null, y = !1, l || c) return;
|
|
41
|
+
if (!A()) {
|
|
42
|
+
u(e);
|
|
22
43
|
return;
|
|
23
44
|
}
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
const T = { signal:
|
|
27
|
-
if (
|
|
28
|
-
if (
|
|
45
|
+
const i = new AbortController();
|
|
46
|
+
c = i;
|
|
47
|
+
const T = { signal: i.signal }, r = await t.ask(a, T);
|
|
48
|
+
if (c = null, !l) {
|
|
49
|
+
if (r.ok) {
|
|
29
50
|
f = 0;
|
|
30
|
-
const
|
|
31
|
-
for (const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
51
|
+
const h = [];
|
|
52
|
+
for (const d of Array.isArray(r.value.heads) ? r.value.heads : []) {
|
|
53
|
+
const v = t.keyOf(d);
|
|
54
|
+
if (v === null) continue;
|
|
55
|
+
const _ = g.get(v);
|
|
56
|
+
g.set(v, d), (!_ || !x(_, d)) && h.push(d);
|
|
35
57
|
}
|
|
36
|
-
if (
|
|
58
|
+
if (h.length > 0)
|
|
37
59
|
try {
|
|
38
|
-
n.onChange(
|
|
60
|
+
n.onChange(h);
|
|
39
61
|
} catch {
|
|
40
62
|
}
|
|
41
|
-
|
|
63
|
+
u(e);
|
|
42
64
|
return;
|
|
43
65
|
}
|
|
44
66
|
try {
|
|
45
|
-
n.onFailure?.(
|
|
67
|
+
n.onFailure?.(r);
|
|
46
68
|
} catch {
|
|
47
69
|
}
|
|
48
|
-
if (t.code
|
|
49
|
-
if (
|
|
50
|
-
|
|
70
|
+
if (t.stopsOn.includes(r.code)) return m();
|
|
71
|
+
if (r.code === "fast" || r.code === "quota") {
|
|
72
|
+
p(Math.max(e, r.retryAfterS !== void 0 ? r.retryAfterS * 1e3 : w));
|
|
51
73
|
return;
|
|
52
74
|
}
|
|
53
|
-
f = Math.min(
|
|
75
|
+
f = Math.min(k, (f || e) * 2), p(f);
|
|
54
76
|
}
|
|
55
77
|
}
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
},
|
|
59
|
-
function
|
|
60
|
-
|
|
78
|
+
const O = () => {
|
|
79
|
+
A() && M();
|
|
80
|
+
}, I = () => m();
|
|
81
|
+
function m() {
|
|
82
|
+
l || (l = !0, s && clearTimeout(s), s = null, c?.abort(), c = null, typeof document < "u" && document.removeEventListener("visibilitychange", O), n.signal?.removeEventListener("abort", I));
|
|
61
83
|
}
|
|
62
|
-
return
|
|
84
|
+
return a.length === 0 || n.signal?.aborted ? (l = !0, { stop: () => {
|
|
63
85
|
}, now: () => {
|
|
64
|
-
} }) : (typeof document < "u" && document.addEventListener("visibilitychange",
|
|
86
|
+
} }) : (typeof document < "u" && document.addEventListener("visibilitychange", O), n.signal?.addEventListener("abort", I, { once: !0 }), u(e), { stop: m, now: M });
|
|
65
87
|
}
|
|
66
88
|
export {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
89
|
+
E as POLL_INTERVAL_MS,
|
|
90
|
+
k as POLL_MAX_BACKOFF_MS,
|
|
91
|
+
D as pollDiscussionHead,
|
|
92
|
+
F as pollTopicHead
|
|
70
93
|
};
|
|
@@ -9,6 +9,11 @@
|
|
|
9
9
|
* const session = createRealtimeSession({ client, store }) // after the first discussions/list
|
|
10
10
|
* // on unmount: session.stop()
|
|
11
11
|
*
|
|
12
|
+
* M3 (m3-contracts.md §3.5, §5.2): a forum topic's store (createTopicStore) works the same way — the session re-reads
|
|
13
|
+
* the topic (refreshTopic) where it re-reads a discussion, and falls back to pollTopicHead. The channel is the topic's
|
|
14
|
+
* conversation's; kb-api mints its token only for an onboarded member or an interactive team session (a visitor's
|
|
15
|
+
* host session is refused `notFound`, so it polls — and `forum/topics/head` stops that poller with `membersOnly`).
|
|
16
|
+
*
|
|
12
17
|
* What it does:
|
|
13
18
|
* - asks `me/realtime/token` for a connection token AND the URL to connect to — the only source of that URL (this
|
|
14
19
|
* entry builds none from configuration: the endpoints are `${url}/connection/websocket`, `${url}/connection/
|
|
@@ -37,6 +42,7 @@
|
|
|
37
42
|
*/
|
|
38
43
|
import type { CommunityClient } from '../client.js';
|
|
39
44
|
import { type DiscussionStore } from '../store.js';
|
|
45
|
+
import { type TopicStore } from '../topic.js';
|
|
40
46
|
/** A Centrifuge subscription, as far as this entry uses it. */
|
|
41
47
|
export interface RealtimeSubscriptionLike {
|
|
42
48
|
on(event: 'publication' | 'subscribed' | 'unsubscribed' | 'error', listener: (ctx: any) => void): unknown;
|
|
@@ -72,9 +78,8 @@ export interface CentrifugeModuleLike {
|
|
|
72
78
|
UnauthorizedError?: new (message?: string) => Error;
|
|
73
79
|
}
|
|
74
80
|
export type RealtimeMode = 'connecting' | 'live' | 'polling' | 'stopped';
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
store: DiscussionStore;
|
|
81
|
+
/** What every session takes besides its client and store. */
|
|
82
|
+
export interface RealtimeSessionCommonOptions {
|
|
78
83
|
/**
|
|
79
84
|
* `disc:<conversationId>`; default the store's conversation (a discussion without one polls until it has one). The id
|
|
80
85
|
* is used in lower case (kb-api publishes to, and mints tokens for, the lower-case channel).
|
|
@@ -93,6 +98,17 @@ export interface RealtimeSessionOptions {
|
|
|
93
98
|
/** Aborting it stops the session. */
|
|
94
99
|
signal?: AbortSignal;
|
|
95
100
|
}
|
|
101
|
+
/** An article's discussion: its store (createDiscussionStore) and a client that reads discussions. */
|
|
102
|
+
export interface DiscussionRealtimeSessionOptions extends RealtimeSessionCommonOptions {
|
|
103
|
+
client: Pick<CommunityClient, 'discussions' | 'me' | 'realtime'>;
|
|
104
|
+
store: DiscussionStore;
|
|
105
|
+
}
|
|
106
|
+
/** M3: a forum topic: its store (createTopicStore) and a client that reads the forum. */
|
|
107
|
+
export interface TopicRealtimeSessionOptions extends RealtimeSessionCommonOptions {
|
|
108
|
+
client: Pick<CommunityClient, 'forum' | 'me' | 'realtime'>;
|
|
109
|
+
store: TopicStore;
|
|
110
|
+
}
|
|
111
|
+
export type RealtimeSessionOptions = DiscussionRealtimeSessionOptions | TopicRealtimeSessionOptions;
|
|
96
112
|
export interface RealtimeSession {
|
|
97
113
|
readonly mode: RealtimeMode;
|
|
98
114
|
/** Re-reads the discussion now (coalesced with one already on its way). */
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { COMMUNITY_CHANNELS as
|
|
2
|
-
import { pollDiscussionHead as
|
|
1
|
+
import { COMMUNITY_CHANNELS as ie } from "../channels.js";
|
|
2
|
+
import { pollTopicHead as oe, pollDiscussionHead as le } from "../poll.js";
|
|
3
3
|
import { refreshDiscussion as ce } from "../store.js";
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { isTopicStore as se, refreshTopic as ae } from "../topic.js";
|
|
5
|
+
const ue = 15e3, fe = 4501, de = (e) => typeof e == "number" && (e >= 3500 && e < 4e3 || e >= 4500 && e < 5e3), me = 3, ve = 1e3, L = (e) => typeof e == "object" && e !== null && !Array.isArray(e);
|
|
6
|
+
function pe(e) {
|
|
6
7
|
if (typeof e != "string" || e.length > 2048) return null;
|
|
7
|
-
let
|
|
8
|
+
let i;
|
|
8
9
|
try {
|
|
9
|
-
|
|
10
|
+
i = new URL(e);
|
|
10
11
|
} catch {
|
|
11
12
|
return null;
|
|
12
13
|
}
|
|
13
|
-
return
|
|
14
|
+
return i.protocol !== "https:" && i.protocol !== "http:" || i.username || i.password || i.search || i.hash ? null : i.href.replace(/\/+$/, "");
|
|
14
15
|
}
|
|
15
|
-
function
|
|
16
|
+
function be(e) {
|
|
16
17
|
return {
|
|
17
18
|
endpoints: [
|
|
18
19
|
{ transport: "websocket", endpoint: `${e.replace(/^http/, "ws")}/connection/websocket` },
|
|
@@ -21,195 +22,224 @@ function pe(e) {
|
|
|
21
22
|
emulationEndpoint: `${e}/emulation`
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
+
let J = !1;
|
|
26
|
+
async function ge(e) {
|
|
27
|
+
let i = null;
|
|
25
28
|
try {
|
|
26
|
-
|
|
27
|
-
if (e) return e;
|
|
28
|
-
const t = await import("centrifuge");
|
|
29
|
-
return t && typeof t.Centrifuge == "function" ? t : null;
|
|
29
|
+
typeof e == "function" ? i = await e() : e ? i = e : i = await import("centrifuge");
|
|
30
30
|
} catch {
|
|
31
|
-
|
|
31
|
+
i = null;
|
|
32
|
+
}
|
|
33
|
+
return i && typeof i.Centrifuge == "function" ? i : (J || (J = !0, console.warn('[community] live updates are off on this page: the "centrifuge" module could not be loaded (not installed, or not resolvable from the SDK at build time); the discussion polls instead.')), null);
|
|
34
|
+
}
|
|
35
|
+
function we(e) {
|
|
36
|
+
const i = e.languageCode ?? null;
|
|
37
|
+
if (se(e.store)) {
|
|
38
|
+
const { store: r, client: n } = e;
|
|
39
|
+
return {
|
|
40
|
+
key: () => r.getState().conversationId,
|
|
41
|
+
conversationId: () => r.getState().conversationId,
|
|
42
|
+
viewerMember: () => r.getState().viewer.memberId,
|
|
43
|
+
subscribe: (o) => r.subscribe(() => o()),
|
|
44
|
+
applyEvent: (o) => r.applyEvent(o),
|
|
45
|
+
read: (o, s) => ae(r, n, { conversationId: o, languageCode: i }, s),
|
|
46
|
+
poll(o, s) {
|
|
47
|
+
const c = {
|
|
48
|
+
visible: s.visible,
|
|
49
|
+
signal: s.signal,
|
|
50
|
+
onChange: (m) => {
|
|
51
|
+
m.some((g) => r.applyHead(g)) && s.onNewer();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
return s.intervalMs !== void 0 && (c.intervalMs = s.intervalMs), oe(n, [o], c);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
32
57
|
}
|
|
58
|
+
const { store: l, client: h } = e;
|
|
59
|
+
return {
|
|
60
|
+
key: () => l.getState().articleId,
|
|
61
|
+
conversationId: () => l.getState().conversationId,
|
|
62
|
+
viewerMember: () => l.getState().viewer.memberId,
|
|
63
|
+
subscribe: (r) => l.subscribe(() => r()),
|
|
64
|
+
applyEvent: (r) => l.applyEvent(r),
|
|
65
|
+
read: (r, n) => ce(l, h, { articleId: r, languageCode: i }, n),
|
|
66
|
+
poll(r, n) {
|
|
67
|
+
const o = {
|
|
68
|
+
visible: n.visible,
|
|
69
|
+
signal: n.signal,
|
|
70
|
+
onChange: (s) => {
|
|
71
|
+
s.some((c) => l.applyHead(c)) && n.onNewer();
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
return n.intervalMs !== void 0 && (o.intervalMs = n.intervalMs), le(h, [r], o);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
33
77
|
}
|
|
34
|
-
function
|
|
35
|
-
const { client:
|
|
36
|
-
let
|
|
37
|
-
const
|
|
38
|
-
if (
|
|
39
|
-
|
|
78
|
+
function Me(e) {
|
|
79
|
+
const { client: i } = e, l = we(e), h = e.visible ?? (() => typeof document > "u" || document.visibilityState !== "hidden");
|
|
80
|
+
let r = "connecting", n = !1, o = null, s = null, c = null, m = null, g = 0, k = null, E = null, M = !1, V = !1, I = null, A = !1, T = 0, W = l.viewerMember(), R = null;
|
|
81
|
+
const _ = new AbortController(), S = { signal: _.signal }, b = (t) => {
|
|
82
|
+
if (r !== t) {
|
|
83
|
+
r = t;
|
|
40
84
|
try {
|
|
41
|
-
e.onMode?.(
|
|
85
|
+
e.onMode?.(t);
|
|
42
86
|
} catch {
|
|
43
87
|
}
|
|
44
88
|
}
|
|
45
|
-
}
|
|
89
|
+
};
|
|
46
90
|
async function Q() {
|
|
47
|
-
const
|
|
48
|
-
!
|
|
91
|
+
const t = l.key();
|
|
92
|
+
!t || n || await l.read(t, S);
|
|
49
93
|
}
|
|
50
|
-
function
|
|
51
|
-
return
|
|
94
|
+
function y() {
|
|
95
|
+
return n ? Promise.resolve() : I ? (A = !0, I) : (I = (async () => {
|
|
52
96
|
try {
|
|
53
97
|
do
|
|
54
|
-
|
|
55
|
-
while (
|
|
98
|
+
A = !1, await Q();
|
|
99
|
+
while (A && !n);
|
|
56
100
|
} finally {
|
|
57
101
|
I = null;
|
|
58
102
|
}
|
|
59
103
|
})(), I);
|
|
60
104
|
}
|
|
61
105
|
function N() {
|
|
62
|
-
|
|
106
|
+
E && clearTimeout(E), E = null;
|
|
63
107
|
}
|
|
64
|
-
function
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
108
|
+
function O() {
|
|
109
|
+
k && clearTimeout(k), k = null, N(), M = !1;
|
|
110
|
+
const t = o;
|
|
111
|
+
o = null;
|
|
112
|
+
const w = s;
|
|
113
|
+
s = null;
|
|
70
114
|
try {
|
|
71
|
-
|
|
115
|
+
w?.unsubscribe(), t?.removeSubscription?.(w), t?.disconnect();
|
|
72
116
|
} catch {
|
|
73
117
|
}
|
|
74
118
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
onChange: (L) => {
|
|
82
|
-
L.some((h) => d.applyHead(h)) && w();
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
e.pollIntervalMs !== void 0 && (u.intervalMs = e.pollIntervalMs), l = J(t, [n], u);
|
|
119
|
+
const q = (t) => l.poll(t, { visible: h, signal: _.signal, intervalMs: e.pollIntervalMs, onNewer: () => {
|
|
120
|
+
y();
|
|
121
|
+
} });
|
|
122
|
+
function D() {
|
|
123
|
+
const t = l.key();
|
|
124
|
+
!t || c || n || (c = q(t));
|
|
86
125
|
}
|
|
87
|
-
function
|
|
88
|
-
|
|
126
|
+
function v() {
|
|
127
|
+
n || (O(), b("polling"), !c && (D(), !c && !m && (m = l.subscribe(() => D()))));
|
|
89
128
|
}
|
|
90
|
-
function
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
},
|
|
129
|
+
function H(t) {
|
|
130
|
+
n || M || t !== o || s === null || (N(), E = setTimeout(() => {
|
|
131
|
+
E = null, !(n || t !== o || s === null || r === "live" || r === "polling") && (M = !0, b("polling"), D());
|
|
132
|
+
}, ue));
|
|
94
133
|
}
|
|
95
134
|
function Z() {
|
|
96
|
-
N(), M && (M = !1,
|
|
135
|
+
N(), M && (M = !1, c?.stop(), c = null), b("live");
|
|
97
136
|
}
|
|
98
137
|
async function x() {
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
if (!(
|
|
102
|
-
if (!
|
|
103
|
-
await
|
|
138
|
+
O(), c?.stop(), c = null, m?.(), m = null, b("connecting");
|
|
139
|
+
const t = T, w = await i.me.realtime.token(S);
|
|
140
|
+
if (!(n || t !== T)) {
|
|
141
|
+
if (!w.ok) return v();
|
|
142
|
+
await U(w.value);
|
|
104
143
|
}
|
|
105
144
|
}
|
|
106
|
-
const
|
|
145
|
+
const z = () => {
|
|
107
146
|
if (typeof e.channel == "string" && e.channel !== "") return e.channel.toLowerCase();
|
|
108
|
-
const
|
|
109
|
-
return
|
|
147
|
+
const t = l.conversationId();
|
|
148
|
+
return t ? ie.discussion(t) : null;
|
|
110
149
|
};
|
|
111
|
-
async function
|
|
112
|
-
const
|
|
113
|
-
if (!
|
|
114
|
-
if (!
|
|
115
|
-
const
|
|
116
|
-
if (!
|
|
117
|
-
if (!
|
|
118
|
-
const
|
|
119
|
-
if (!
|
|
120
|
-
const
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
123
|
-
throw
|
|
124
|
-
}, { endpoints: te, emulationEndpoint: re } =
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}),
|
|
128
|
-
|
|
129
|
-
}),
|
|
130
|
-
if (
|
|
131
|
-
const
|
|
132
|
-
if (
|
|
133
|
-
if (
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
},
|
|
150
|
+
async function U(t) {
|
|
151
|
+
const w = ++T, B = () => w === T && !n, C = await ge(e.centrifuge);
|
|
152
|
+
if (!B()) return;
|
|
153
|
+
if (!C) return v();
|
|
154
|
+
const P = t ? { ok: !0, value: t } : await i.me.realtime.token(S);
|
|
155
|
+
if (!B()) return;
|
|
156
|
+
if (!P.ok) return v();
|
|
157
|
+
const F = pe(P.value.url);
|
|
158
|
+
if (!F) return v();
|
|
159
|
+
const G = (a) => C.UnauthorizedError ? new C.UnauthorizedError(a) : new Error(a), ne = async () => {
|
|
160
|
+
const a = await i.me.realtime.token(S);
|
|
161
|
+
if (a.ok) return a.value.token;
|
|
162
|
+
throw a.code === "realtimeOff" || a.code === "signIn" ? (queueMicrotask(v), G(a.code)) : new Error(a.code);
|
|
163
|
+
}, { endpoints: te, emulationEndpoint: re } = be(F), u = new C.Centrifuge(te, { token: P.value.token, getToken: ne, emulationEndpoint: re, name: "blogmcp-community" });
|
|
164
|
+
o = u, u.on("connected", () => {
|
|
165
|
+
u === o && (g = 0);
|
|
166
|
+
}), u.on("connecting", () => {
|
|
167
|
+
u !== o || n || (r === "live" && b("connecting"), H(u));
|
|
168
|
+
}), u.on("disconnected", (a) => {
|
|
169
|
+
if (u !== o || n) return;
|
|
170
|
+
const f = L(a) ? a.code : void 0;
|
|
171
|
+
if (f === 1 || f === 3500) {
|
|
172
|
+
if (g >= me) return v();
|
|
173
|
+
g += 1, r === "live" && b("connecting"), H(u);
|
|
174
|
+
const p = ve * 2 ** (g - 1) * (0.5 + Math.random());
|
|
175
|
+
k = setTimeout(() => {
|
|
176
|
+
k = null, u === o && !n && u.connect();
|
|
177
|
+
}, p);
|
|
139
178
|
return;
|
|
140
179
|
}
|
|
141
|
-
if (
|
|
142
|
-
|
|
180
|
+
if (f === fe && !V) {
|
|
181
|
+
V = !0, x().catch(() => v());
|
|
143
182
|
return;
|
|
144
183
|
}
|
|
145
|
-
|
|
184
|
+
de(f) && v();
|
|
146
185
|
});
|
|
147
|
-
const X = (
|
|
148
|
-
const
|
|
149
|
-
getToken: async (
|
|
150
|
-
const
|
|
151
|
-
if (
|
|
152
|
-
throw
|
|
186
|
+
const X = (a) => {
|
|
187
|
+
const f = u.newSubscription(a, {
|
|
188
|
+
getToken: async (p) => {
|
|
189
|
+
const d = await i.realtime.subscribeToken({ channel: p?.channel ?? a }, S);
|
|
190
|
+
if (d.ok) return d.value.token;
|
|
191
|
+
throw d.code === "notFound" || d.code === "realtimeOff" || d.code === "signIn" || d.code === "surfaceOff" ? (queueMicrotask(v), G(d.code)) : new Error(d.code);
|
|
153
192
|
}
|
|
154
193
|
});
|
|
155
|
-
|
|
156
|
-
if (
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
}),
|
|
160
|
-
|
|
161
|
-
}),
|
|
162
|
-
|
|
163
|
-
}),
|
|
164
|
-
}, Y =
|
|
194
|
+
s = f, H(u), f.on("publication", (p) => {
|
|
195
|
+
if (f !== s || n) return;
|
|
196
|
+
const d = L(p) ? p.data : void 0;
|
|
197
|
+
L(d) && l.applyEvent(d) === "resync" && y();
|
|
198
|
+
}), f.on("subscribed", () => {
|
|
199
|
+
f !== s || n || (Z(), y());
|
|
200
|
+
}), f.on("unsubscribed", (p) => {
|
|
201
|
+
f !== s || n || L(p) && p.code !== 0 && v();
|
|
202
|
+
}), f.subscribe();
|
|
203
|
+
}, Y = z();
|
|
165
204
|
if (Y) X(Y);
|
|
166
205
|
else {
|
|
167
|
-
const
|
|
168
|
-
const
|
|
169
|
-
!
|
|
170
|
-
}),
|
|
171
|
-
|
|
172
|
-
|
|
206
|
+
const a = l.subscribe(() => {
|
|
207
|
+
const d = z();
|
|
208
|
+
!d || u !== o || n || (a(), c?.stop(), c = null, X(d));
|
|
209
|
+
}), f = m;
|
|
210
|
+
m = () => {
|
|
211
|
+
a(), f?.();
|
|
173
212
|
};
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
const o = {
|
|
177
|
-
visible: R,
|
|
178
|
-
signal: T.signal,
|
|
179
|
-
onChange: (ie) => {
|
|
180
|
-
ie.some((oe) => d.applyHead(oe)) && w();
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
e.pollIntervalMs !== void 0 && (o.intervalMs = e.pollIntervalMs), l = J(t, [f], o);
|
|
184
|
-
}
|
|
213
|
+
const p = l.key();
|
|
214
|
+
p && (c = q(p));
|
|
185
215
|
}
|
|
186
|
-
|
|
216
|
+
u.connect();
|
|
187
217
|
}
|
|
188
218
|
function ee() {
|
|
189
|
-
|
|
219
|
+
n || (O(), c?.stop(), c = null, m?.(), m = null, g = 0, b("connecting"), U().catch(() => v()));
|
|
190
220
|
}
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
},
|
|
194
|
-
|
|
221
|
+
const K = () => {
|
|
222
|
+
h() && r === "live" && y();
|
|
223
|
+
}, j = () => {
|
|
224
|
+
r === "live" && y();
|
|
195
225
|
};
|
|
196
|
-
function
|
|
197
|
-
|
|
226
|
+
function $() {
|
|
227
|
+
n || (n = !0, O(), c?.stop(), c = null, m?.(), m = null, R?.(), R = null, _.abort(), typeof document < "u" && document.removeEventListener("visibilitychange", K), typeof window < "u" && window.removeEventListener("online", j), e.signal?.removeEventListener("abort", $), b("stopped"));
|
|
198
228
|
}
|
|
199
|
-
return e.signal?.aborted ? (
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
}),
|
|
229
|
+
return e.signal?.aborted ? (n = !0, r = "stopped") : (typeof document < "u" && document.addEventListener("visibilitychange", K), typeof window < "u" && window.addEventListener("online", j), e.signal?.addEventListener("abort", $, { once: !0 }), R = l.subscribe(() => {
|
|
230
|
+
const t = l.viewerMember();
|
|
231
|
+
t !== W && (W = t, ee());
|
|
232
|
+
}), U().catch(() => v())), {
|
|
203
233
|
get mode() {
|
|
204
|
-
return
|
|
234
|
+
return r;
|
|
205
235
|
},
|
|
206
|
-
resync:
|
|
207
|
-
stop:
|
|
236
|
+
resync: y,
|
|
237
|
+
stop: $
|
|
208
238
|
};
|
|
209
239
|
}
|
|
210
240
|
export {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
241
|
+
ue as REALTIME_WATCHDOG_MS,
|
|
242
|
+
Me as createRealtimeSession,
|
|
243
|
+
be as realtimeEndpointsOf,
|
|
244
|
+
pe as realtimeUrlOf
|
|
215
245
|
};
|