braid-http 1.3.6 → 1.3.8
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/README.md +19 -7
- package/braid-http-client.js +0 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Braid-HTTP
|
|
2
2
|
|
|
3
|
-
This polyfill library implements the [Braid-HTTP v04 protocol](https://github.com/braid-org/braid-spec/blob/master/draft-toomim-httpbis-braid-http-04.txt)
|
|
3
|
+
This polyfill library implements the [Braid-HTTP v04 protocol](https://github.com/braid-org/braid-spec/blob/master/draft-toomim-httpbis-braid-http-04.txt), modified slightly to follow the HTTP Multiresponse concept discussed at [braid.org/meeting-89](https://braid.org/meeting-89). It provides browsers with a `braid_fetch()` drop-in replacement for the `fetch()` API, and offers nodejs an `http` plugin, enabling simple Braid communication.
|
|
4
4
|
|
|
5
5
|
Developed in [braid.org](https://braid.org).
|
|
6
6
|
|
|
@@ -53,8 +53,14 @@ fetch('https://braid.org/chat', {subscribe: true}).then(
|
|
|
53
53
|
// {
|
|
54
54
|
// version: ["me"],
|
|
55
55
|
// parents: ["mom", "dad"],
|
|
56
|
-
// patches: [{
|
|
57
|
-
|
|
56
|
+
// patches: [{
|
|
57
|
+
//. unit: "json",
|
|
58
|
+
// range: ".foo",
|
|
59
|
+
// content: new Uint8Array([51]),
|
|
60
|
+
// content_text: "3" <-- getter
|
|
61
|
+
//. }],
|
|
62
|
+
// body: new Uint8Array([51]),
|
|
63
|
+
// body_text: "3" <-- getter
|
|
58
64
|
// }
|
|
59
65
|
//
|
|
60
66
|
// Note that `update` will contain either patches *or* body
|
|
@@ -113,7 +119,7 @@ for await (var update of subscription_iterator) {
|
|
|
113
119
|
// Or complete snapshots:
|
|
114
120
|
else
|
|
115
121
|
// Beware the server doesn't send these yet.
|
|
116
|
-
chat = JSON.parse(update.
|
|
122
|
+
chat = JSON.parse(update.body_text)
|
|
117
123
|
|
|
118
124
|
render_stuff()
|
|
119
125
|
}
|
|
@@ -233,10 +239,16 @@ function connect () {
|
|
|
233
239
|
// {
|
|
234
240
|
// version: ["me"],
|
|
235
241
|
// parents: ["mom", "dad"],
|
|
236
|
-
// patches: [{
|
|
237
|
-
|
|
242
|
+
// patches: [{
|
|
243
|
+
//. unit: "json",
|
|
244
|
+
// range: ".foo",
|
|
245
|
+
// content: new Uint8Array([51]),
|
|
246
|
+
// content_text: "3" <-- getter
|
|
247
|
+
//. }],
|
|
248
|
+
// body: new Uint8Array([51]),
|
|
249
|
+
// body_text: "3" <-- getter
|
|
238
250
|
// }
|
|
239
|
-
//
|
|
251
|
+
// Update will contain either patches *or* body, but not both
|
|
240
252
|
console.log('We got a new update!', update)
|
|
241
253
|
})
|
|
242
254
|
|
package/braid-http-client.js
CHANGED
|
@@ -234,7 +234,6 @@ async function braid_fetch (url, params = {}) {
|
|
|
234
234
|
)
|
|
235
235
|
|
|
236
236
|
var waitTime = 10
|
|
237
|
-
var waitedTime = 0
|
|
238
237
|
var res = null
|
|
239
238
|
var subscription_cb = null
|
|
240
239
|
var subscription_error = null
|
|
@@ -252,15 +251,8 @@ async function braid_fetch (url, params = {}) {
|
|
|
252
251
|
|
|
253
252
|
underlying_aborter.abort()
|
|
254
253
|
|
|
255
|
-
if (params.retry.timeout && waitedTime + waitTime > params.retry.timeout) {
|
|
256
|
-
e = new Error('Timeout Error')
|
|
257
|
-
subscription_error?.(e)
|
|
258
|
-
return fail(e)
|
|
259
|
-
}
|
|
260
|
-
|
|
261
254
|
console.log(`retrying in ${waitTime}ms: ${url} after error: ${e}`)
|
|
262
255
|
setTimeout(connect, waitTime)
|
|
263
|
-
waitedTime += waitTime
|
|
264
256
|
waitTime = Math.min(waitTime * 2, 3000)
|
|
265
257
|
}
|
|
266
258
|
|
|
@@ -419,7 +411,6 @@ async function braid_fetch (url, params = {}) {
|
|
|
419
411
|
|
|
420
412
|
params?.retry?.onRes?.(res)
|
|
421
413
|
waitTime = 10
|
|
422
|
-
waitedTime = 0
|
|
423
414
|
} catch (e) { on_error(e) }
|
|
424
415
|
}
|
|
425
416
|
})
|