braid-text 0.2.95 → 0.2.97

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.
Files changed (2) hide show
  1. package/index.js +48 -1
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -52,6 +52,9 @@ function create_braid_text() {
52
52
  // make a=local and b=remote (swap if not)
53
53
  if (a instanceof URL) { let swap = a; a = b; b = swap }
54
54
 
55
+ // DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
56
+ options.do_investigating_disconnects_log_L04LPFHQ1M?.(a, 'braid-text sync start')
57
+
55
58
  // Extract content type for proper Accept (GET) vs Content-Type (PUT) usage
56
59
  var content_type
57
60
  var get_headers = {}
@@ -117,6 +120,10 @@ function create_braid_text() {
117
120
  var closed
118
121
  var disconnect = () => {}
119
122
  options.signal?.addEventListener('abort', () => {
123
+
124
+ // DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
125
+ options.do_investigating_disconnects_log_L04LPFHQ1M?.(a, 'braid-text sync abort')
126
+
120
127
  closed = true
121
128
  disconnect()
122
129
  })
@@ -126,6 +133,10 @@ function create_braid_text() {
126
133
 
127
134
  var waitTime = 1
128
135
  function handle_error(_e) {
136
+
137
+ // DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
138
+ options.do_investigating_disconnects_log_L04LPFHQ1M?.(a, 'braid-text handle_error: ' + _e)
139
+
129
140
  if (closed) return
130
141
  disconnect()
131
142
  var delay = waitTime * 1000
@@ -136,6 +147,9 @@ function create_braid_text() {
136
147
 
137
148
  connect()
138
149
  async function connect() {
150
+ // DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
151
+ options.do_investigating_disconnects_log_L04LPFHQ1M?.(a, 'braid-text connect before on_pre_connect')
152
+
139
153
  if (options.on_pre_connect) await options.on_pre_connect()
140
154
 
141
155
  if (closed) return
@@ -143,6 +157,9 @@ function create_braid_text() {
143
157
  var ac = new AbortController()
144
158
  disconnect = () => ac.abort()
145
159
 
160
+ // DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
161
+ options.do_investigating_disconnects_log_L04LPFHQ1M?.(a, 'braid-text connect before fork-point stuff')
162
+
146
163
  try {
147
164
  // fork-point
148
165
  async function check_version(version) {
@@ -173,6 +190,10 @@ function create_braid_text() {
173
190
 
174
191
  // otherwise let's binary search for new fork point..
175
192
  if (!resource.meta.fork_point) {
193
+
194
+ // DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
195
+ options.do_investigating_disconnects_log_L04LPFHQ1M?.(a, 'braid-text fork-point binary search')
196
+
176
197
  var bytes = resource.doc.toBytes()
177
198
  var [_, events, __] = braid_text.dt_parse([...bytes])
178
199
  events = events.map(x => x.join('-'))
@@ -200,11 +221,19 @@ function create_braid_text() {
200
221
  })
201
222
 
202
223
  async function send_out(update) {
224
+
225
+ // DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
226
+ options.do_investigating_disconnects_log_L04LPFHQ1M?.(a, 'braid-text send_out')
227
+
203
228
  update.signal = ac.signal
204
229
  update.dont_retry = true
205
230
  if (options.peer) update.peer = options.peer
206
231
  update.headers = put_headers
207
232
  var x = await braid_text.put(b, update)
233
+
234
+ // DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
235
+ options.do_investigating_disconnects_log_L04LPFHQ1M?.(a, 'braid-text send_out result: ' + x.ok)
236
+
208
237
  if (x.ok) {
209
238
  local_first_put()
210
239
  extend_fork_point(update)
@@ -284,6 +313,9 @@ function create_braid_text() {
284
313
  var remote_res_promise = new Promise(done => remote_res_done = done)
285
314
  var remote_res = null
286
315
 
316
+ // DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
317
+ options.do_investigating_disconnects_log_L04LPFHQ1M?.(a, 'braid-text before GET/sub')
318
+
287
319
  var b_ops = {
288
320
  signal: ac.signal,
289
321
  dont_retry: true,
@@ -291,7 +323,17 @@ function create_braid_text() {
291
323
  parents: resource.meta.fork_point,
292
324
  peer: options.peer,
293
325
  heartbeats: 120,
326
+
327
+ // DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
328
+ heartbeat_cb: () => {
329
+ options.do_investigating_disconnects_log_L04LPFHQ1M?.(a, 'got heartbeat')
330
+ },
331
+
294
332
  subscribe: async update => {
333
+
334
+ // DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
335
+ options.do_investigating_disconnects_log_L04LPFHQ1M?.(a, 'braid-text got update')
336
+
295
337
  // Wait for remote_res to be available
296
338
  await remote_res_promise
297
339
 
@@ -315,6 +357,10 @@ function create_braid_text() {
315
357
  }
316
358
  // Handle case where remote doesn't exist yet - wait for local to create it
317
359
  remote_res = await braid_text.get(b, b_ops)
360
+
361
+ // DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
362
+ options.do_investigating_disconnects_log_L04LPFHQ1M?.(a, 'braid-text after GET/sub: ' + remote_res?.status)
363
+
318
364
  remote_res_done()
319
365
  if (remote_res === null) {
320
366
  // Remote doesn't exist yet, wait for local to put something
@@ -651,7 +697,8 @@ function create_braid_text() {
651
697
  var params = {
652
698
  signal: options.signal,
653
699
  subscribe: !!options.subscribe,
654
- heartbeats: 120,
700
+ heartbeats: options.heartbeats ?? 120,
701
+ heartbeat_cb: options.heartbeat_cb
655
702
  }
656
703
  if (!options.dont_retry) {
657
704
  params.retry = (res) => res.status !== 404
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "braid-text",
3
- "version": "0.2.95",
3
+ "version": "0.2.97",
4
4
  "description": "Library for collaborative text over http using braid.",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braid-text",
7
7
  "homepage": "https://braid.org",
8
8
  "dependencies": {
9
9
  "@braid.org/diamond-types-node": "^2.0.0",
10
- "braid-http": "~1.3.84",
10
+ "braid-http": "~1.3.85",
11
11
  "url-file-db": "^0.0.25"
12
12
  }
13
13
  }