@inkandswitch/patchwork-pkg-base 0.0.11 → 0.0.12
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/package.json
CHANGED
|
@@ -17,10 +17,18 @@ const sessions = new Map()
|
|
|
17
17
|
let currentDocUrl = null
|
|
18
18
|
let unsubscribeView = null
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (!
|
|
23
|
-
|
|
20
|
+
let loadingSelf = null
|
|
21
|
+
function loadSelf() {
|
|
22
|
+
if (!loadingSelf) loadingSelf = loadSelfOnce()
|
|
23
|
+
return loadingSelf
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function loadSelfOnce() {
|
|
27
|
+
let contactUrl
|
|
28
|
+
while (!(contactUrl = window.accountDocHandle?.doc()?.contactUrl)) {
|
|
29
|
+
await new Promise(resolve => setTimeout(resolve, 250))
|
|
30
|
+
}
|
|
31
|
+
myContactUrl = contactUrl
|
|
24
32
|
const contactHandle = await window.repo.find(myContactUrl)
|
|
25
33
|
function refresh() {
|
|
26
34
|
const c = contactHandle.doc()
|
|
@@ -45,7 +53,6 @@ function broadcast(handle) {
|
|
|
45
53
|
color: s.color,
|
|
46
54
|
avatarUrl: s.avatarUrl,
|
|
47
55
|
focused: focused(),
|
|
48
|
-
ts: Date.now(),
|
|
49
56
|
})
|
|
50
57
|
}
|
|
51
58
|
|
|
@@ -54,7 +61,6 @@ function sendGoodbye(handle) {
|
|
|
54
61
|
handle.broadcast({
|
|
55
62
|
type: "doc-presence-goodbye",
|
|
56
63
|
contactUrl: myContactUrl,
|
|
57
|
-
ts: Date.now(),
|
|
58
64
|
})
|
|
59
65
|
}
|
|
60
66
|
|
|
@@ -75,7 +81,7 @@ function joinDoc(handle) {
|
|
|
75
81
|
}
|
|
76
82
|
if (msg.type !== "doc-presence") return
|
|
77
83
|
setPeers(m => {
|
|
78
|
-
m.set(msg.contactUrl, msg)
|
|
84
|
+
m.set(msg.contactUrl, {...msg, ts: Date.now()})
|
|
79
85
|
return m
|
|
80
86
|
})
|
|
81
87
|
}
|
|
@@ -137,7 +143,7 @@ async function onSelectedDocChange(newUrl) {
|
|
|
137
143
|
currentDocUrl = newUrl
|
|
138
144
|
|
|
139
145
|
if (newUrl && window.repo) {
|
|
140
|
-
|
|
146
|
+
loadSelf()
|
|
141
147
|
const handle = await window.repo.find(newUrl)
|
|
142
148
|
joinDoc(handle)
|
|
143
149
|
}
|
|
@@ -222,6 +228,7 @@ function DocPresence(handle, element) {
|
|
|
222
228
|
)
|
|
223
229
|
|
|
224
230
|
return () => {
|
|
231
|
+
leaveDoc(handle)
|
|
225
232
|
style.remove()
|
|
226
233
|
dispose()
|
|
227
234
|
}
|