braid-blob 0.0.76 → 0.0.77

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 (3) hide show
  1. package/client.js +1 -1
  2. package/img-live.js +27 -17
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -22,7 +22,7 @@
22
22
  //
23
23
  function braid_blob_client(url, params = {}) {
24
24
  var peer = params.peer || Math.random().toString(36).slice(2)
25
- var current_version = null
25
+ var current_version = params.parents || null
26
26
 
27
27
  braid_fetch(url, {
28
28
  headers: { "Merge-Type": "aww" },
package/img-live.js CHANGED
@@ -13,25 +13,35 @@ function sync(img) {
13
13
  unsync(img)
14
14
 
15
15
  var ac = new AbortController()
16
- var client = braid_blob_client(url, {
17
- signal: ac.signal,
18
- on_update: (body, content_type, version, from_local_update) => {
19
- if (from_local_update) {
20
- var blob = new Blob([body], { type: content_type || 'image/png' })
21
- img.src = URL.createObjectURL(blob)
22
- } else {
16
+ var client_p = (async () => {
17
+ var res = await braid_fetch(url, {
18
+ method: 'HEAD',
19
+ headers: { "Merge-Type": "aww" },
20
+ subscribe: true,
21
+ retry: () => true,
22
+ signal: ac.signal
23
+ })
24
+ return braid_blob_client(url, {
25
+ signal: ac.signal,
26
+ parents: res.version,
27
+ on_update: (body, content_type, version, from_local_update) => {
28
+ if (from_local_update) {
29
+ var blob = new Blob([body], { type: content_type || 'image/png' })
30
+ img.src = URL.createObjectURL(blob)
31
+ } else {
32
+ img.src = ''
33
+ img.src = url
34
+ }
35
+ },
36
+ on_delete: () => {
23
37
  img.src = ''
24
38
  img.src = url
39
+ },
40
+ on_error: (error) => {
41
+ console.error('Live image error for', url, error)
25
42
  }
26
- },
27
- on_delete: () => {
28
- img.src = ''
29
- img.src = url
30
- },
31
- on_error: (error) => {
32
- console.error('Live image error for', url, error)
33
- }
34
- })
43
+ })
44
+ })()
35
45
  live_images.set(img, ac)
36
46
 
37
47
  if (img.hasAttribute('droppable')) {
@@ -60,7 +70,7 @@ function sync(img) {
60
70
 
61
71
  var reader = new FileReader()
62
72
  reader.onload = async function() {
63
- await client.update(reader.result, file.type)
73
+ await (await client_p).update(reader.result, file.type)
64
74
  img.src = url
65
75
  }
66
76
  reader.readAsArrayBuffer(file)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-blob",
3
- "version": "0.0.76",
3
+ "version": "0.0.77",
4
4
  "description": "Library for collaborative blobs over http using braid.",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braid-blob",