@banou/social 0.0.4 → 0.0.6
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/build/index.js +29 -27
- package/dist/index.d.mts +7 -1
- package/dist/index.mjs +53 -23
- package/fkn.json +1 -0
- package/package.json +11 -2
package/dist/index.d.mts
CHANGED
|
@@ -184,6 +184,9 @@ type Participant = {
|
|
|
184
184
|
name: string;
|
|
185
185
|
displayName: string;
|
|
186
186
|
avatar: string | null;
|
|
187
|
+
identicon?: string;
|
|
188
|
+
signKey?: string;
|
|
189
|
+
nickname?: string | null;
|
|
187
190
|
} | null;
|
|
188
191
|
self: boolean;
|
|
189
192
|
};
|
|
@@ -245,7 +248,10 @@ type Hub = {
|
|
|
245
248
|
text: string;
|
|
246
249
|
}) => Promise<CommentAnswer>;
|
|
247
250
|
state: () => Promise<Availability>;
|
|
248
|
-
attach: (binding: Omit<RoomBinding, 'send'>
|
|
251
|
+
attach: (binding: Omit<RoomBinding, 'send'> & {
|
|
252
|
+
send?: (frame: string) => Promise<void>;
|
|
253
|
+
onParticipants?: (participants: Participant[]) => void;
|
|
254
|
+
}) => Promise<{
|
|
249
255
|
participants: () => Promise<Participant[]>;
|
|
250
256
|
ingest: (from: string, frame: string, at: number, seq: number) => Promise<boolean>;
|
|
251
257
|
memberJoined: (memberId: string) => Promise<void>;
|
package/dist/index.mjs
CHANGED
|
@@ -109,62 +109,92 @@ const inertPresence = (selfMemberId) => {
|
|
|
109
109
|
const createSocial = (connect) => {
|
|
110
110
|
let hub = null;
|
|
111
111
|
let negotiated = null;
|
|
112
|
-
let
|
|
112
|
+
let outdated = false;
|
|
113
113
|
const ensure = async () => {
|
|
114
|
-
if (
|
|
115
|
-
if (hub !== null && negotiated?.usable === true) return reach ?? "ready";
|
|
114
|
+
if (outdated) return "outdated";
|
|
116
115
|
try {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
if (hub === null || negotiated === null) {
|
|
117
|
+
const connected = await connect();
|
|
118
|
+
const negotiation = negotiate(await connected.hello());
|
|
119
|
+
if (!negotiation.usable) {
|
|
120
|
+
outdated = true;
|
|
121
|
+
return "outdated";
|
|
122
|
+
}
|
|
123
|
+
hub = connected;
|
|
124
|
+
negotiated = negotiation;
|
|
122
125
|
}
|
|
123
|
-
|
|
124
|
-
negotiated = negotiation;
|
|
125
|
-
reach = await connected.state();
|
|
126
|
-
return reach;
|
|
126
|
+
return await hub.state();
|
|
127
127
|
} catch {
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
hub = null;
|
|
129
|
+
negotiated = null;
|
|
130
|
+
return "unavailable";
|
|
130
131
|
}
|
|
131
132
|
};
|
|
132
133
|
const available = async () => ensure();
|
|
133
134
|
const attach = async (binding) => {
|
|
134
|
-
|
|
135
|
+
const state = await ensure();
|
|
136
|
+
if (state === "unavailable" || state === "outdated" || state === "app-not-connected" || hub === null || negotiated === null || !supports(negotiated, SINCE.attach)) return inertPresence(binding.selfMemberId);
|
|
135
137
|
try {
|
|
138
|
+
let cached = [];
|
|
139
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
140
|
+
let detached = false;
|
|
141
|
+
let version = 0;
|
|
142
|
+
let pushVersion = 0;
|
|
143
|
+
const emit = (next) => {
|
|
144
|
+
if (detached) return;
|
|
145
|
+
cached = next;
|
|
146
|
+
for (const listener of listeners) listener(cached);
|
|
147
|
+
};
|
|
136
148
|
const remote = await hub.attach({
|
|
137
149
|
roomId: binding.roomId,
|
|
138
150
|
selfMemberId: binding.selfMemberId,
|
|
139
|
-
observe: binding.observe
|
|
151
|
+
observe: binding.observe,
|
|
152
|
+
send: async (frame) => {
|
|
153
|
+
await binding.send(frame);
|
|
154
|
+
},
|
|
155
|
+
onParticipants: (next) => {
|
|
156
|
+
version += 1;
|
|
157
|
+
pushVersion = version;
|
|
158
|
+
emit(next);
|
|
159
|
+
}
|
|
140
160
|
});
|
|
141
|
-
let cached = [];
|
|
142
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
143
161
|
const refresh = async () => {
|
|
144
|
-
|
|
145
|
-
|
|
162
|
+
const reqVersion = ++version;
|
|
163
|
+
try {
|
|
164
|
+
const next = await remote.participants();
|
|
165
|
+
if (detached || reqVersion < pushVersion || reqVersion < version) return;
|
|
166
|
+
emit(next);
|
|
167
|
+
} catch {}
|
|
146
168
|
};
|
|
147
169
|
refresh();
|
|
148
170
|
return {
|
|
149
171
|
participants: () => cached,
|
|
150
172
|
of: (memberId) => cached.find((p) => p.memberId === memberId) ?? silentParticipant(memberId, binding.selfMemberId),
|
|
151
173
|
on: (listener) => {
|
|
174
|
+
if (detached) return () => {};
|
|
152
175
|
listeners.add(listener);
|
|
153
176
|
return () => listeners.delete(listener);
|
|
154
177
|
},
|
|
155
178
|
ingest: (from, frame, at, seq) => {
|
|
156
|
-
if (!isSocialFrame(frame)) return false;
|
|
179
|
+
if (detached || !isSocialFrame(frame)) return false;
|
|
157
180
|
remote.ingest(from, frame, at, seq).then(refresh, () => {});
|
|
158
181
|
return true;
|
|
159
182
|
},
|
|
160
183
|
memberJoined: (memberId) => {
|
|
184
|
+
if (detached) return;
|
|
161
185
|
remote.memberJoined(memberId).then(refresh, () => {});
|
|
162
186
|
},
|
|
163
187
|
memberLeft: (memberId) => {
|
|
188
|
+
if (detached) return;
|
|
164
189
|
remote.memberLeft(memberId).then(refresh, () => {});
|
|
165
190
|
},
|
|
166
|
-
announce: () => remote.announce(),
|
|
167
|
-
detach: () =>
|
|
191
|
+
announce: () => detached ? Promise.resolve() : remote.announce(),
|
|
192
|
+
detach: async () => {
|
|
193
|
+
if (detached) return;
|
|
194
|
+
detached = true;
|
|
195
|
+
listeners.clear();
|
|
196
|
+
await remote.detach().catch(() => {});
|
|
197
|
+
}
|
|
168
198
|
};
|
|
169
199
|
} catch {
|
|
170
200
|
return inertPresence(binding.selfMemberId);
|
package/fkn.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"v":0,"app":"fkn:app:1ify3klog2ns2qp2vk2xmxep3rjsimrwyxrrq33qxzamx4ctxlxja","name":"Social","version":"0.0.6","key":"7WjOgQ4Oi3PnA2+VrexddFFlAqZGQqtWQsYy8hzhZ4Q=","issuedAt":1795629490,"perSource":["npm:@banou/social"],"url":"https://social.fkn.app/","contentsDigest":"dah5cXPz//zmi+MCTAUslIJKrJXd8oqZpqhGsxphm1Q=","sig":"CCSIqdlZUMvHeEqARg2uLv1kdOri4+CPTE/dbfOOSvym5C3o3fKweFADuuLPMK/IgeszBUz+PLTZlDOIs/IbAA==","contents":{"name":"@banou/social","version":"0.0.6","alg":"sha256","files":{"LICENSE":"WJNqFQbNMx75H+XcF9dJEw5TozbnceF2KidAIbm2kPE=","README.md":"lU5AktI5qC7P+8L7p4wD/Bvaqzk2BurDspCM8vP1v58=","build/index.js":"CPol2AqKVweRrU6lMPr7wjhw5HRJHc3obSZR/MWtL/s=","dist/index.d.mts":"QfveGNQUHT59EkmSYP8uE5V2FOS01g1QdozoHh0F8UY=","dist/index.mjs":"WxU+L4dsuiCDixQZTPUSaYR6A06N895qyw+vdTI6MEs=","dist/names.d.mts":"ooNGOMmaopBmCWs5Y1Wcu/4qF0eVtZ5Wqj+1le20hkM=","dist/names.mjs":"pxVAr3JijQnW5Xc+Rq48j4xiRtUTaX7gkKZfONikm+M=","package.json":"+wGmd13KBwtY88tcIbDUmQ0Jg7SffeSlss5HzG89IZY="},"types":{"LICENSE":"application/octet-stream","README.md":"text/markdown","build/index.js":"text/javascript","dist/index.d.mts":"application/octet-stream","dist/index.mjs":"text/javascript","dist/names.d.mts":"application/octet-stream","dist/names.mjs":"text/javascript","package.json":"application/json"}},"keys":{"app":"fkn:app:1ify3klog2ns2qp2vk2xmxep3rjsimrwyxrrq33qxzamx4ctxlxja","serial":1795628272940,"issuedAt":1795628272,"founder":{"kind":"fkn","seed":"fxn8no70fzaqrzhbbcw28y88u1"},"signer":"fkn-1","name":"Social","members":[{"key":"7WjOgQ4Oi3PnA2+VrexddFFlAqZGQqtWQsYy8hzhZ4Q=","since":1795628272}],"sig":"epRewUVJrk01N/wlEbhXjVDbHtrjipt0HkzcWJ+LINKEy9YrcVgUEBFS7Iz0StjCgrGV/yessx3luUGOfhTsBg=="}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@banou/social",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Identity and friends across FKN apps. One signing key, a proven announcement inside a room, and a friend list that syncs with the account.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -11,6 +11,14 @@
|
|
|
11
11
|
"identity",
|
|
12
12
|
"friends"
|
|
13
13
|
],
|
|
14
|
+
"fkn": {
|
|
15
|
+
"app": "fkn:app:1ify3klog2ns2qp2vk2xmxep3rjsimrwyxrrq33qxzamx4ctxlxja",
|
|
16
|
+
"signed": true,
|
|
17
|
+
"url": "https://social.fkn.app/",
|
|
18
|
+
"embed": [
|
|
19
|
+
"*"
|
|
20
|
+
]
|
|
21
|
+
},
|
|
14
22
|
"sideEffects": [
|
|
15
23
|
"./build/index.js"
|
|
16
24
|
],
|
|
@@ -27,7 +35,8 @@
|
|
|
27
35
|
},
|
|
28
36
|
"files": [
|
|
29
37
|
"build/index.js",
|
|
30
|
-
"dist"
|
|
38
|
+
"dist",
|
|
39
|
+
"fkn.json"
|
|
31
40
|
],
|
|
32
41
|
"scripts": {
|
|
33
42
|
"dev": "vp dev --port 4570",
|