@zean-chat/react-native 0.1.16 → 0.1.17
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/index.js +48 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -234,6 +234,22 @@ var QUIET_CALLS = /* @__PURE__ */ new Set(["start", "reportInstall", "setTyping"
|
|
|
234
234
|
function emailKey(offer) {
|
|
235
235
|
return `${offer.kind}:${offer.email}`;
|
|
236
236
|
}
|
|
237
|
+
function placeShowsApp(place) {
|
|
238
|
+
return place.app !== void 0;
|
|
239
|
+
}
|
|
240
|
+
function joinedSession(place, own) {
|
|
241
|
+
if (!placeShowsApp(place)) return place;
|
|
242
|
+
if (own.state === "not_found") return own;
|
|
243
|
+
const blocked = own.state === "blocked";
|
|
244
|
+
return {
|
|
245
|
+
state: place.state === "unavailable" ? "unavailable" : blocked ? "blocked" : "ready",
|
|
246
|
+
app: place.app,
|
|
247
|
+
contact: own.contact,
|
|
248
|
+
emailCode: place.state === "ready" && !blocked ? own.emailCode : null,
|
|
249
|
+
identity: own.identity,
|
|
250
|
+
report: place.report
|
|
251
|
+
};
|
|
252
|
+
}
|
|
237
253
|
function createChatStore(backend, options) {
|
|
238
254
|
const secretKey = `zean:${options.appKey}:device`;
|
|
239
255
|
const outboxKey = `zean:${options.appKey}:outbox`;
|
|
@@ -348,30 +364,50 @@ function createChatStore(backend, options) {
|
|
|
348
364
|
sessionWatch?.stop();
|
|
349
365
|
const live = sessionLive();
|
|
350
366
|
let stopped = false;
|
|
351
|
-
|
|
367
|
+
const watches = [];
|
|
352
368
|
const entry = {
|
|
353
369
|
live,
|
|
354
370
|
// Once: the Convex client throws on a second unsubscribe.
|
|
355
371
|
stop: () => {
|
|
356
372
|
if (stopped) return;
|
|
357
373
|
stopped = true;
|
|
358
|
-
stop
|
|
374
|
+
for (const stop of watches.splice(0)) stop();
|
|
359
375
|
}
|
|
360
376
|
};
|
|
361
377
|
sessionWatch = entry;
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
378
|
+
let place = null;
|
|
379
|
+
let own = null;
|
|
380
|
+
const handle = () => {
|
|
381
|
+
if (!place || !own) return;
|
|
382
|
+
handleSession(joinedSession(place, own));
|
|
383
|
+
if (!live && sessionWatch === entry) entry.stop();
|
|
384
|
+
};
|
|
385
|
+
const handleError = () => {
|
|
386
|
+
failedToLoad = true;
|
|
387
|
+
emit2();
|
|
388
|
+
};
|
|
389
|
+
const { deviceSecret: secret, ...where } = args();
|
|
390
|
+
const placeStop = backend.watch(
|
|
391
|
+
"place",
|
|
392
|
+
where,
|
|
365
393
|
(result) => {
|
|
366
|
-
|
|
367
|
-
|
|
394
|
+
place = result;
|
|
395
|
+
handle();
|
|
368
396
|
},
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
397
|
+
handleError
|
|
398
|
+
);
|
|
399
|
+
watches.push(placeStop);
|
|
400
|
+
const deviceStop = backend.watch(
|
|
401
|
+
"device",
|
|
402
|
+
{ appKey: options.appKey, deviceSecret: secret },
|
|
403
|
+
(result) => {
|
|
404
|
+
own = result;
|
|
405
|
+
handle();
|
|
406
|
+
},
|
|
407
|
+
handleError
|
|
373
408
|
);
|
|
374
|
-
if (stopped)
|
|
409
|
+
if (stopped) deviceStop();
|
|
410
|
+
else watches.push(deviceStop);
|
|
375
411
|
}
|
|
376
412
|
function updateSessionLive() {
|
|
377
413
|
if (!sessionWatch || sessionWatch.live === sessionLive()) return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zean-chat/react-native",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"description": "In-app support chat for React Native and Expo, iOS and Android. Pure JS, no native module. A free Intercom, Crisp and Zendesk mobile SDK alternative.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|