braid-text 0.2.88 → 0.2.90

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 +19 -5
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -99,11 +99,14 @@ function create_braid_text() {
99
99
  var local_first_put
100
100
  var local_first_put_promise = new Promise(done => local_first_put = done)
101
101
 
102
+ var waitTime = 1
102
103
  function handle_error(_e) {
103
104
  if (closed) return
104
105
  disconnect()
105
- console.log(`disconnected, retrying in 1 second`)
106
- setTimeout(connect, 1000)
106
+ var delay = waitTime * 1000
107
+ console.log(`disconnected, retrying in ${waitTime} second${waitTime > 1 ? 's' : ''}`)
108
+ setTimeout(connect, delay)
109
+ waitTime = Math.min(waitTime + 1, 3)
107
110
  }
108
111
 
109
112
  connect()
@@ -173,6 +176,7 @@ function create_braid_text() {
173
176
  async function send_out(update) {
174
177
  update.signal = ac.signal
175
178
  update.dont_retry = true
179
+ if (options.peer) update.peer = options.peer
176
180
  var x = await braid_text.put(b, update)
177
181
  if (x.ok) {
178
182
  local_first_put()
@@ -200,6 +204,7 @@ function create_braid_text() {
200
204
  signal: temp_ac.signal,
201
205
  parents: frontier,
202
206
  merge_type: 'dt',
207
+ peer: options.peer,
203
208
  subscribe: u => u.version?.length && q.push(u)
204
209
  }
205
210
  await braid_text.get(a, temp_ops)
@@ -234,6 +239,7 @@ function create_braid_text() {
234
239
  var a_ops = {
235
240
  signal: ac.signal,
236
241
  merge_type: 'dt',
242
+ peer: options.peer,
237
243
  subscribe: update => {
238
244
  if (closed) return
239
245
  if (update.version?.length) {
@@ -255,12 +261,15 @@ function create_braid_text() {
255
261
  signal: ac.signal,
256
262
  dont_retry: true,
257
263
  headers: { 'Merge-Type': 'dt', 'accept-encoding': 'updates(dt)' },
264
+ parents: resource.meta.fork_point,
265
+ peer: options.peer,
266
+ heartbeats: 120,
258
267
  subscribe: async update => {
259
268
  // Wait for remote_res to be available
260
269
  await remote_res_promise
261
270
 
262
- // Check if this is a dt-encoded update (initial body without status)
263
- if (!update.status) {
271
+ // Check if this is a dt-encoded update
272
+ if (update.extra_headers?.encoding === 'dt') {
264
273
  var cv = remote_res.headers.get('current-version')
265
274
  await braid_text.put(a, {
266
275
  body: update.body,
@@ -820,7 +829,7 @@ function create_braid_text() {
820
829
 
821
830
  if (options.transfer_encoding === 'dt') {
822
831
  var start_i = 1 + resource.doc.getLocalVersion().reduce((a, b) => Math.max(a, b), -1)
823
-
832
+
824
833
  resource.doc.mergeBytes(body)
825
834
 
826
835
  var end_i = resource.doc.getLocalVersion().reduce((a, b) => Math.max(a, b), -1)
@@ -833,6 +842,11 @@ function create_braid_text() {
833
842
  resource.version = resource.doc.getRemoteVersion().map(x => x.join("-")).sort()
834
843
 
835
844
  await resource.db_delta(body)
845
+
846
+ // Notify non-simpleton clients with the dt-encoded update
847
+ var dt_update = { body, encoding: 'dt' }
848
+ await Promise.all([...resource.clients].map(client => client.my_subscribe(dt_update)))
849
+
836
850
  return { change_count: end_i - start_i + 1 }
837
851
  }
838
852
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-text",
3
- "version": "0.2.88",
3
+ "version": "0.2.90",
4
4
  "description": "Library for collaborative text over http using braid.",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braid-text",