braid-blob 0.0.76 → 0.0.78

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 +38 -19
  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
@@ -9,29 +9,48 @@ function sync(img) {
9
9
  var url = img.src
10
10
  if (!url) return
11
11
 
12
+ // Find an unused query parameter name for cache-busting
13
+ var param = 'img-live'
14
+ var u = new URL(url)
15
+ while (u.searchParams.has(param)) param = '-' + param
16
+ function cache_bust() {
17
+ u.searchParams.set(param, Math.random().toString(36).slice(2))
18
+ return u.toString()
19
+ }
20
+
12
21
  // Unsync first to handle attribute changes (e.g. droppable added/removed)
13
22
  unsync(img)
14
23
 
15
24
  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 {
25
+ var client_p = (async () => {
26
+ var res = await braid_fetch(cache_bust(), {
27
+ method: 'HEAD',
28
+ headers: { "Merge-Type": "aww" },
29
+ subscribe: true,
30
+ retry: () => true,
31
+ signal: ac.signal
32
+ })
33
+ return braid_blob_client(cache_bust(), {
34
+ signal: ac.signal,
35
+ parents: res.version,
36
+ on_update: (body, content_type, version, from_local_update) => {
37
+ if (from_local_update) {
38
+ var blob = new Blob([body], { type: content_type || 'image/png' })
39
+ img.src = URL.createObjectURL(blob)
40
+ } else {
41
+ img.src = ''
42
+ img.src = cache_bust()
43
+ }
44
+ },
45
+ on_delete: () => {
23
46
  img.src = ''
24
- img.src = url
47
+ img.src = cache_bust()
48
+ },
49
+ on_error: (error) => {
50
+ console.error('Live image error for', url, error)
25
51
  }
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
- })
52
+ })
53
+ })()
35
54
  live_images.set(img, ac)
36
55
 
37
56
  if (img.hasAttribute('droppable')) {
@@ -60,8 +79,8 @@ function sync(img) {
60
79
 
61
80
  var reader = new FileReader()
62
81
  reader.onload = async function() {
63
- await client.update(reader.result, file.type)
64
- img.src = url
82
+ await (await client_p).update(reader.result, file.type)
83
+ img.src = cache_bust()
65
84
  }
66
85
  reader.readAsArrayBuffer(file)
67
86
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-blob",
3
- "version": "0.0.76",
3
+ "version": "0.0.78",
4
4
  "description": "Library for collaborative blobs over http using braid.",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braid-blob",