@awesomate/sdk 0.9.0 → 0.10.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 +5 -0
- package/dist/index.js +14 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -146,6 +146,11 @@ and takes a fresh copy when it does. Up to 200 rows a list and 20 lists a connec
|
|
|
146
146
|
`{ onRows, onError }` to hear about a list the server refused (a column that does not exist).
|
|
147
147
|
Outside a browser, give it a WebSocket: `createAppClient({ publishableKey, WebSocket })`.
|
|
148
148
|
|
|
149
|
+
While a list is open in a browser, the connection also tells the hub whether the tab is in front.
|
|
150
|
+
If the account switched on reply emails, someone looking at the app isn't emailed about a reply,
|
|
151
|
+
but a tab left open in the background doesn't count as looking, and closing the last one counts as
|
|
152
|
+
leaving straight away.
|
|
153
|
+
|
|
149
154
|
### Staff find a customer
|
|
150
155
|
|
|
151
156
|
People in an app read no contacts but their own, so by default staff cannot put a job under a
|
package/dist/index.js
CHANGED
|
@@ -553,6 +553,10 @@ function unref(t) {
|
|
|
553
553
|
t.unref?.();
|
|
554
554
|
return t;
|
|
555
555
|
}
|
|
556
|
+
/** The page's document, when there is one: the part live() reads to say whether the tab is in front. */
|
|
557
|
+
function pageDocument() {
|
|
558
|
+
return globalThis.document;
|
|
559
|
+
}
|
|
556
560
|
/** The one WebSocket behind live(). */
|
|
557
561
|
class LiveSocket {
|
|
558
562
|
o;
|
|
@@ -569,6 +573,15 @@ class LiveSocket {
|
|
|
569
573
|
connecting = false;
|
|
570
574
|
constructor(o) {
|
|
571
575
|
this.o = o;
|
|
576
|
+
// Reply emails wait only while one of the person's tabs is in front, so the hub hears when this
|
|
577
|
+
// one goes to the back or comes forward. Outside a browser there is no tab, and nothing is sent.
|
|
578
|
+
pageDocument()?.addEventListener?.('visibilitychange', () => this.sendPresence());
|
|
579
|
+
}
|
|
580
|
+
/** Whether this tab is in front, to the hub (from 0.10.0; an older hub ignores the frame). */
|
|
581
|
+
sendPresence() {
|
|
582
|
+
const d = pageDocument();
|
|
583
|
+
if (this.ready && typeof d?.visibilityState === 'string')
|
|
584
|
+
this.send({ type: 'presence', visible: d.visibilityState === 'visible' });
|
|
572
585
|
}
|
|
573
586
|
add(spec, handlers) {
|
|
574
587
|
const id = `l${++this.seq}`;
|
|
@@ -632,6 +645,7 @@ class LiveSocket {
|
|
|
632
645
|
this.attempt = 0;
|
|
633
646
|
for (const [id, e] of this.entries)
|
|
634
647
|
this.send({ type: 'sub', id, spec: e.spec });
|
|
648
|
+
this.sendPresence();
|
|
635
649
|
this.pinger = unref(setInterval(() => this.send({ type: 'ping' }), 25_000));
|
|
636
650
|
return;
|
|
637
651
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@awesomate/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Your own Awesomate data from Node and the browser: query contacts and app data with generated types, and sign your app's own users in",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|