canvu-react 0.4.55 → 0.4.57
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/chatbot.d.cts +3 -3
- package/dist/chatbot.d.ts +3 -3
- package/dist/index.cjs +30 -252
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +30 -252
- package/dist/index.js.map +1 -1
- package/dist/native.cjs +30 -252
- package/dist/native.cjs.map +1 -1
- package/dist/native.d.cts +3 -3
- package/dist/native.d.ts +3 -3
- package/dist/native.js +30 -252
- package/dist/native.js.map +1 -1
- package/dist/react.cjs +31 -253
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +4 -4
- package/dist/react.d.ts +4 -4
- package/dist/react.js +31 -253
- package/dist/react.js.map +1 -1
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.d.cts +4 -4
- package/dist/realtime.d.ts +4 -4
- package/dist/realtime.js.map +1 -1
- package/dist/realtimeNative.cjs +46 -2
- package/dist/realtimeNative.cjs.map +1 -1
- package/dist/realtimeNative.d.cts +2 -2
- package/dist/realtimeNative.d.ts +2 -2
- package/dist/realtimeNative.js +46 -2
- package/dist/realtimeNative.js.map +1 -1
- package/dist/{shape-builders-BmLS8CNh.d.cts → shape-builders-DzhCOuzo.d.cts} +1 -1
- package/dist/{shape-builders-BCOAG0pS.d.ts → shape-builders-xG3A66sv.d.ts} +1 -1
- package/dist/tldraw.cjs +30 -252
- package/dist/tldraw.cjs.map +1 -1
- package/dist/tldraw.js +30 -252
- package/dist/tldraw.js.map +1 -1
- package/dist/{types-uzeExFkd.d.cts → types-BFZpRGyr.d.cts} +2 -2
- package/dist/{types-BMMPUak7.d.ts → types-BXa2CIrc.d.ts} +1 -1
- package/dist/{types-BAEHaIYO.d.ts → types-D2zesNI8.d.ts} +2 -2
- package/dist/{types-BOQLWyCw.d.cts → types-DqsqQQVf.d.cts} +1 -1
- package/package.json +1 -1
package/dist/realtimeNative.cjs
CHANGED
|
@@ -845,6 +845,7 @@ var DRAFT_STORAGE_PREFIX = "canvu-realtime-draft:";
|
|
|
845
845
|
var DOCUMENT_FLUSH_DEBOUNCE_MS = 120;
|
|
846
846
|
var DRAFT_PERSIST_DEBOUNCE_MS = 420;
|
|
847
847
|
var CONNECTION_MESSAGE_STATE_UPDATE_INTERVAL_MS = 1e3;
|
|
848
|
+
var PRESENCE_UPDATE_THROTTLE_MS = 80;
|
|
848
849
|
function requestRuntimeIdleCallback(callback, timeout) {
|
|
849
850
|
const runtime = globalThis;
|
|
850
851
|
if (typeof runtime.requestIdleCallback === "function") {
|
|
@@ -980,6 +981,10 @@ function nowMs() {
|
|
|
980
981
|
function shouldUpdateRealtimeConnectionMessageState(input) {
|
|
981
982
|
return input.lastStateUpdateAt == null || input.receivedAt - input.lastStateUpdateAt >= CONNECTION_MESSAGE_STATE_UPDATE_INTERVAL_MS;
|
|
982
983
|
}
|
|
984
|
+
function shouldSendRealtimePresenceUpdate(input) {
|
|
985
|
+
const minIntervalMs = input.minIntervalMs ?? PRESENCE_UPDATE_THROTTLE_MS;
|
|
986
|
+
return input.lastPresenceSentAt == null || input.requestedAt - input.lastPresenceSentAt >= minIntervalMs;
|
|
987
|
+
}
|
|
983
988
|
function hasDurableDocumentPersistence(snapshot) {
|
|
984
989
|
return snapshot.persistedRevision == null || snapshot.persistedRevision >= snapshot.revision;
|
|
985
990
|
}
|
|
@@ -1120,6 +1125,7 @@ function useRealtimeSession(options) {
|
|
|
1120
1125
|
const documentFlushIdleRef = react.useRef(null);
|
|
1121
1126
|
const draftPersistTimerRef = react.useRef(null);
|
|
1122
1127
|
const draftPersistIdleRef = react.useRef(null);
|
|
1128
|
+
const presenceUpdateTimerRef = react.useRef(null);
|
|
1123
1129
|
const draftStorageRef = react.useRef(draftStorage);
|
|
1124
1130
|
draftStorageRef.current = draftStorage;
|
|
1125
1131
|
const manualDisconnectRef = react.useRef(false);
|
|
@@ -1144,6 +1150,7 @@ function useRealtimeSession(options) {
|
|
|
1144
1150
|
enabled ? "connecting" : "offline"
|
|
1145
1151
|
);
|
|
1146
1152
|
const lastConnectionMessageStateUpdateAtRef = react.useRef(null);
|
|
1153
|
+
const lastPresenceSentAtRef = react.useRef(null);
|
|
1147
1154
|
const localDraftRef = react.useRef(null);
|
|
1148
1155
|
const conflictRef = react.useRef(null);
|
|
1149
1156
|
const onErrorRef = react.useRef(onError);
|
|
@@ -1208,6 +1215,12 @@ function useRealtimeSession(options) {
|
|
|
1208
1215
|
cancelRuntimeIdleCallback(draftPersistIdleRef.current);
|
|
1209
1216
|
draftPersistIdleRef.current = null;
|
|
1210
1217
|
}, []);
|
|
1218
|
+
const clearPresenceUpdateSchedule = react.useCallback(() => {
|
|
1219
|
+
if (presenceUpdateTimerRef.current != null) {
|
|
1220
|
+
globalThis.clearTimeout(presenceUpdateTimerRef.current);
|
|
1221
|
+
presenceUpdateTimerRef.current = null;
|
|
1222
|
+
}
|
|
1223
|
+
}, []);
|
|
1211
1224
|
const updateConnection = react.useCallback(
|
|
1212
1225
|
(patch) => {
|
|
1213
1226
|
setConnection((prev) => {
|
|
@@ -1566,7 +1579,8 @@ function useRealtimeSession(options) {
|
|
|
1566
1579
|
},
|
|
1567
1580
|
[applyDocument, roomId, scheduleDocumentFlush, setLocalDraft]
|
|
1568
1581
|
);
|
|
1569
|
-
const
|
|
1582
|
+
const sendPresenceUpdateNow = react.useCallback(() => {
|
|
1583
|
+
lastPresenceSentAtRef.current = nowMs();
|
|
1570
1584
|
sendRaw({
|
|
1571
1585
|
type: "presence:update",
|
|
1572
1586
|
roomId,
|
|
@@ -1579,6 +1593,24 @@ function useRealtimeSession(options) {
|
|
|
1579
1593
|
}
|
|
1580
1594
|
});
|
|
1581
1595
|
}, [roomId, sendRaw]);
|
|
1596
|
+
const sendPresenceUpdate = react.useCallback(() => {
|
|
1597
|
+
const requestedAt = nowMs();
|
|
1598
|
+
if (shouldSendRealtimePresenceUpdate({
|
|
1599
|
+
lastPresenceSentAt: lastPresenceSentAtRef.current,
|
|
1600
|
+
requestedAt
|
|
1601
|
+
})) {
|
|
1602
|
+
clearPresenceUpdateSchedule();
|
|
1603
|
+
sendPresenceUpdateNow();
|
|
1604
|
+
return;
|
|
1605
|
+
}
|
|
1606
|
+
if (presenceUpdateTimerRef.current != null) return;
|
|
1607
|
+
const elapsedMs = requestedAt - (lastPresenceSentAtRef.current ?? requestedAt);
|
|
1608
|
+
const delayMs = Math.max(0, PRESENCE_UPDATE_THROTTLE_MS - elapsedMs);
|
|
1609
|
+
presenceUpdateTimerRef.current = globalThis.setTimeout(() => {
|
|
1610
|
+
presenceUpdateTimerRef.current = null;
|
|
1611
|
+
sendPresenceUpdateNow();
|
|
1612
|
+
}, delayMs);
|
|
1613
|
+
}, [clearPresenceUpdateSchedule, sendPresenceUpdateNow]);
|
|
1582
1614
|
const scheduleReconnect = react.useCallback(() => {
|
|
1583
1615
|
if (!reconnect || manualDisconnectRef.current) return;
|
|
1584
1616
|
clearReconnectTimer();
|
|
@@ -1660,6 +1692,7 @@ function useRealtimeSession(options) {
|
|
|
1660
1692
|
if (!roomId) {
|
|
1661
1693
|
clearDocumentFlushSchedule();
|
|
1662
1694
|
clearDraftPersistSchedule();
|
|
1695
|
+
clearPresenceUpdateSchedule();
|
|
1663
1696
|
localDraftRef.current = null;
|
|
1664
1697
|
setHasLocalOfflineDraft(false);
|
|
1665
1698
|
setHasPendingDocumentSync(false);
|
|
@@ -1702,6 +1735,7 @@ function useRealtimeSession(options) {
|
|
|
1702
1735
|
applyDraftSnapshot,
|
|
1703
1736
|
clearDocumentFlushSchedule,
|
|
1704
1737
|
clearDraftPersistSchedule,
|
|
1738
|
+
clearPresenceUpdateSchedule,
|
|
1705
1739
|
roomId,
|
|
1706
1740
|
setConflictState,
|
|
1707
1741
|
setLocalDraft
|
|
@@ -1714,6 +1748,7 @@ function useRealtimeSession(options) {
|
|
|
1714
1748
|
clearHeartbeatTimer();
|
|
1715
1749
|
clearConnectTimeout();
|
|
1716
1750
|
clearDocumentFlushSchedule();
|
|
1751
|
+
clearPresenceUpdateSchedule();
|
|
1717
1752
|
wsRef.current?.close();
|
|
1718
1753
|
wsRef.current = null;
|
|
1719
1754
|
queuedDirtyRef.current = localDraftRef.current != null;
|
|
@@ -1997,12 +2032,14 @@ function useRealtimeSession(options) {
|
|
|
1997
2032
|
clearHeartbeatTimer();
|
|
1998
2033
|
clearConnectTimeout();
|
|
1999
2034
|
clearDocumentFlushSchedule();
|
|
2035
|
+
clearPresenceUpdateSchedule();
|
|
2000
2036
|
socket.close();
|
|
2001
2037
|
};
|
|
2002
2038
|
}, [
|
|
2003
2039
|
clearConnectTimeout,
|
|
2004
2040
|
clearDocumentFlushSchedule,
|
|
2005
2041
|
clearHeartbeatTimer,
|
|
2042
|
+
clearPresenceUpdateSchedule,
|
|
2006
2043
|
clearReconnectTimer,
|
|
2007
2044
|
connectSequence,
|
|
2008
2045
|
connectTimeoutMs,
|
|
@@ -2030,12 +2067,17 @@ function useRealtimeSession(options) {
|
|
|
2030
2067
|
() => () => {
|
|
2031
2068
|
clearDocumentFlushSchedule();
|
|
2032
2069
|
clearDraftPersistSchedule();
|
|
2070
|
+
clearPresenceUpdateSchedule();
|
|
2033
2071
|
if (boardRef.current) {
|
|
2034
2072
|
boardRef.current.doc.destroy();
|
|
2035
2073
|
boardRef.current = null;
|
|
2036
2074
|
}
|
|
2037
2075
|
},
|
|
2038
|
-
[
|
|
2076
|
+
[
|
|
2077
|
+
clearDocumentFlushSchedule,
|
|
2078
|
+
clearDraftPersistSchedule,
|
|
2079
|
+
clearPresenceUpdateSchedule
|
|
2080
|
+
]
|
|
2039
2081
|
);
|
|
2040
2082
|
const flushDocumentSync = react.useCallback(async () => {
|
|
2041
2083
|
const board = boardRef.current;
|
|
@@ -2087,6 +2129,7 @@ function useRealtimeSession(options) {
|
|
|
2087
2129
|
clearReconnectTimer();
|
|
2088
2130
|
clearHeartbeatTimer();
|
|
2089
2131
|
clearConnectTimeout();
|
|
2132
|
+
clearPresenceUpdateSchedule();
|
|
2090
2133
|
sendRaw({
|
|
2091
2134
|
type: "session:leave",
|
|
2092
2135
|
roomId,
|
|
@@ -2103,6 +2146,7 @@ function useRealtimeSession(options) {
|
|
|
2103
2146
|
}, [
|
|
2104
2147
|
clearConnectTimeout,
|
|
2105
2148
|
clearHeartbeatTimer,
|
|
2149
|
+
clearPresenceUpdateSchedule,
|
|
2106
2150
|
clearReconnectTimer,
|
|
2107
2151
|
collapsePeersToSelf,
|
|
2108
2152
|
roomId,
|