A music player that connects to your cloud/distributed storage.
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix Fission integration

+163 -106
+4 -3
CHANGELOG.md
··· 2 2 3 3 ## 3.1.0 4 4 5 - - Removes usage of the Web Audio API, just uses `<audio>` elements now so that Diffuse can be played in the background on iOS. Sadly this also means the equalizer has been removed, but a better volume control has been added instead, one that doesn't move away from the tracks view. 6 - - Added a command palette 5 + - **Removes usage of the Web Audio API, just uses `<audio>` elements now so that Diffuse can be played in the background on iOS.** _Sadly this also means the equalizer has been removed, but a better volume control has been added instead, one that doesn't move away from the tracks view._ 6 + - **Added a command palette.** 7 + - Fixes Fission integration 7 8 - Improves launcher design (called Alfred internally) 8 9 - Improves key bindings 9 10 - Small UI improvements ··· 11 12 12 13 ## 3.0.2 13 14 14 - - __Fixes issue with Dropbox user-data storage__ (Dropbox API change) 15 + - **Fixes issue with Dropbox user-data storage** (Dropbox API change) 15 16 - Fixes various issues with the album-cover view (eg. playback issues) 16 17 - Service worker tweaks to improve performance and offline behaviour 17 18
+8 -1
Justfile
··· 136 136 cp {{NPM_DIR}}/subworkers/subworkers.js {{BUILD_DIR}}/subworkers.js 137 137 cp {{NPM_DIR}}/remotestoragejs/release/remotestorage.js {{BUILD_DIR}}/vendor/remotestorage.min.js 138 138 cp {{NPM_DIR}}/webnative/dist/index.umd.min.js {{BUILD_DIR}}/vendor/webnative.min.js 139 + cp ./vendor/ipfs.min.js {{BUILD_DIR}}/vendor/ipfs.min.js 139 140 cp ./vendor/pep.js {{BUILD_DIR}}/vendor/pep.js 140 141 141 142 {{NPM_DIR}}/.bin/esbuild {{NPM_DIR}}/webnative-elm/src/funnel.js --minify --outfile={{BUILD_DIR}}/vendor/webnative-elm.min.js ··· 158 159 ) 159 160 160 161 162 + @download-vendor-dep filename url: 163 + curl --silent --show-error --fail -o ./vendor/{{filename}} {{url}} 164 + 165 + 161 166 @elm-housekeeping: 162 167 echo "> Running elm-review" 163 168 {{NPM_DIR}}/.bin/elm-review {{SRC_DIR}} --config system/Review --fix-all ··· 169 174 pnpm install 170 175 171 176 mkdir -p vendor 172 - curl --silent --show-error --fail -o ./vendor/pep.js https://raw.githubusercontent.com/mpizenberg/elm-pep/071616d75ca61e261fdefc7b55bc46c34e44ea22/elm-pep.js 177 + 178 + just download-vendor-dep pep.js https://raw.githubusercontent.com/mpizenberg/elm-pep/071616d75ca61e261fdefc7b55bc46c34e44ea22/elm-pep.js 179 + just download-vendor-dep ipfs.min.js https://unpkg.com/ipfs@0.62.3/index.min.js 173 180 174 181 cargo install tauri-cli --version "^1.0.0-rc.6" --root ./src-tauri 175 182
+3 -3
package.json
··· 26 26 "delay": "^5.0.0", 27 27 "fast-text-encoding": "^1.0.3", 28 28 "file-saver": "^2.0.2", 29 - "ipfs-message-port-client": "0.10.x", 30 - "ipfs-message-port-protocol": "0.10.x", 29 + "ipfs-message-port-client": "0.11.x", 30 + "ipfs-message-port-protocol": "0.11.x", 31 31 "jszip": "^3.7.1", 32 32 "load-script2": "^2.0.5", 33 33 "lunr": "^2.3.8", ··· 37 37 "subworkers": "^1.0.1", 38 38 "timer.js": "^1.0.4", 39 39 "tocca": "^2.0.9", 40 - "webnative": "0.31.1", 40 + "webnative": "0.32.0", 41 41 "webnative-elm": "7.0.0" 42 42 } 43 43 }
+42 -76
pnpm-lock.yaml
··· 12 12 events: ^3.3.0 13 13 fast-text-encoding: ^1.0.3 14 14 file-saver: ^2.0.2 15 - ipfs-message-port-client: 0.10.x 16 - ipfs-message-port-protocol: 0.10.x 15 + ipfs-message-port-client: 0.11.x 16 + ipfs-message-port-protocol: 0.11.x 17 17 jszip: ^3.7.1 18 18 load-script2: ^2.0.5 19 19 lunr: ^2.3.8 ··· 29 29 tailwindcss-interaction-variants: ^5.0.0 30 30 timer.js: ^1.0.4 31 31 tocca: ^2.0.9 32 - webnative: 0.31.1 32 + webnative: 0.32.0 33 33 webnative-elm: 7.0.0 34 34 35 35 dependencies: ··· 37 37 delay: 5.0.0 38 38 fast-text-encoding: 1.0.3 39 39 file-saver: 2.0.5 40 - ipfs-message-port-client: 0.10.3 41 - ipfs-message-port-protocol: 0.10.5 40 + ipfs-message-port-client: 0.11.3 41 + ipfs-message-port-protocol: 0.11.3 42 42 jszip: 3.7.1 43 43 load-script2: 2.0.6 44 44 lunr: 2.3.9 ··· 48 48 subworkers: 1.0.1 49 49 timer.js: 1.0.4 50 50 tocca: 2.0.9 51 - webnative: 0.31.1 52 - webnative-elm: 7.0.0_webnative@0.31.1 51 + webnative: 0.32.0 52 + webnative-elm: 7.0.0_webnative@0.32.0 53 53 54 54 devDependencies: 55 55 assert: 2.0.0 ··· 159 159 dev: true 160 160 161 161 /@protobufjs/aspromise/1.1.2: 162 - resolution: {integrity: sha1-m4sMxmPWaafY9vXQiToU00jzD78=} 162 + resolution: {integrity: sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==} 163 163 dev: false 164 164 165 165 /@protobufjs/base64/1.1.2: ··· 171 171 dev: false 172 172 173 173 /@protobufjs/eventemitter/1.1.0: 174 - resolution: {integrity: sha1-NVy8mLr61ZePntCV85diHx0Ga3A=} 174 + resolution: {integrity: sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==} 175 175 dev: false 176 176 177 177 /@protobufjs/fetch/1.1.0: 178 - resolution: {integrity: sha1-upn7WYYUr2VwDBYZ/wbUVLDYTEU=} 178 + resolution: {integrity: sha512-lljVXpqXebpsijW71PZaCYeIcE5on1w5DlQy5WH6GLbFryLUrBD4932W/E2BSpfRJWseIL4v/KPgBFxDOIdKpQ==} 179 179 dependencies: 180 180 '@protobufjs/aspromise': 1.1.2 181 181 '@protobufjs/inquire': 1.1.0 182 182 dev: false 183 183 184 184 /@protobufjs/float/1.0.2: 185 - resolution: {integrity: sha1-Xp4avctz/Ap8uLKR33jIy9l7h9E=} 185 + resolution: {integrity: sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==} 186 186 dev: false 187 187 188 188 /@protobufjs/inquire/1.1.0: 189 - resolution: {integrity: sha1-/yAOPnzyQp4tyvwRQIKOjMY48Ik=} 189 + resolution: {integrity: sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q==} 190 190 dev: false 191 191 192 192 /@protobufjs/path/1.1.2: 193 - resolution: {integrity: sha1-bMKyDFya1q0NzP0hynZz2Nf79o0=} 193 + resolution: {integrity: sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==} 194 194 dev: false 195 195 196 196 /@protobufjs/pool/1.1.0: 197 - resolution: {integrity: sha1-Cf0V8tbTq/qbZbw2ZQbWrXhG/1Q=} 197 + resolution: {integrity: sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==} 198 198 dev: false 199 199 200 200 /@protobufjs/utf8/1.1.0: 201 - resolution: {integrity: sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=} 201 + resolution: {integrity: sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==} 202 202 dev: false 203 203 204 204 /@sindresorhus/is/2.1.1: ··· 430 430 dev: true 431 431 432 432 /blakejs/1.1.0: 433 - resolution: {integrity: sha1-ad+S75U6qIylGjLfarHFShVfx6U=} 433 + resolution: {integrity: sha512-1TSf2Cf2KycDPzjJpzamYhr6PFSEgKWyoc4rQ/BarXJzp/jM0FC7yP1rLWtMOWT2EIJtjPv9fwpKquRNbRV7Lg==} 434 434 dev: false 435 435 436 436 /brace-expansion/1.1.11: ··· 576 576 optionalDependencies: 577 577 fsevents: 2.3.2 578 578 dev: true 579 - 580 - /cids/1.1.7: 581 - resolution: {integrity: sha512-dlh+K0hMwFAFFjWQ2ZzxOhgGVNVREPdmk8cqHFui2U4sOodcemLMxdE5Ujga4cDcDQhWfldEPThkfu6KWBt1eA==} 582 - engines: {node: '>=4.0.0', npm: '>=3.0.0'} 583 - deprecated: This module has been superseded by the multiformats module 584 - dependencies: 585 - multibase: 4.0.4 586 - multicodec: 3.1.0 587 - multihashes: 4.0.2 588 - uint8arrays: 2.1.7 589 - dev: false 590 579 591 580 /cids/1.1.9: 592 581 resolution: {integrity: sha512-l11hWRfugIcbGuTZwAM5PwpjPPjyb6UZOGwlHSnOBV5o07XhQ4gNpBN67FbODvpjyHtd+0Xs6KNvUcGBiDRsdg==} ··· 1523 1512 deprecated: This module has been superseded by the multiformats module 1524 1513 dependencies: 1525 1514 cids: 1.1.9 1526 - multicodec: 3.1.0 1527 - multihashes: 4.0.2 1515 + multicodec: 3.2.1 1516 + multihashes: 4.0.3 1528 1517 dev: false 1529 1518 1530 1519 /interface-store/2.0.2: ··· 1536 1525 engines: {node: '>=8'} 1537 1526 dev: false 1538 1527 1539 - /ipfs-core-types/0.9.0: 1540 - resolution: {integrity: sha512-VJ8vJSHvI1Zm7/SxsZo03T+zzpsg8pkgiIi5hfwSJlsrJ1E2v68QPlnLshGHUSYw89Oxq0IbETYl2pGTFHTWfg==} 1528 + /ipfs-core-types/0.10.3: 1529 + resolution: {integrity: sha512-GNid2lRBjR5qgScCglgk7w9Hk3TZAwPHQXxOLQx72wgyc0jF2U5NXRoKW0GRvX8NPbHmsrFszForIqxd23I1Gw==} 1541 1530 dependencies: 1531 + '@ipld/dag-pb': 2.1.15 1542 1532 interface-datastore: 6.1.0 1533 + ipfs-unixfs: 6.0.6 1543 1534 multiaddr: 10.0.1 1544 1535 multiformats: 9.6.3 1545 1536 transitivePeerDependencies: ··· 1547 1538 - supports-color 1548 1539 dev: false 1549 1540 1550 - /ipfs-message-port-client/0.10.3: 1551 - resolution: {integrity: sha512-lAdIdU8fpZBGUg1dG22X55Qnm3N6BxEVf4d3tYu8ITaIxhrZ2nm2HmkNzlc5fYeIZKTICThIDYiqzqMTrx67aw==} 1552 - engines: {node: '>=14.0.0', npm: '>=3.0.0'} 1541 + /ipfs-message-port-client/0.11.3: 1542 + resolution: {integrity: sha512-eMXyW6SVpDJN43R/XmaYbOGFvjH8yPuTafZ4FwZcuSpzOuj3JIRzQIVST3HMqYGse6zyo/6qbgmUixa2yzE2ag==} 1543 + engines: {node: '>=15.0.0', npm: '>=3.0.0'} 1553 1544 dependencies: 1554 1545 browser-readablestream-to-it: 1.0.2 1555 1546 err-code: 3.0.1 1556 - ipfs-core-types: 0.9.0 1557 - ipfs-message-port-protocol: 0.10.5 1547 + ipfs-core-types: 0.10.3 1548 + ipfs-message-port-protocol: 0.11.3 1558 1549 ipfs-unixfs: 6.0.6 1559 1550 it-peekable: 1.0.3 1560 1551 multiformats: 9.6.3 ··· 1563 1554 - supports-color 1564 1555 dev: false 1565 1556 1566 - /ipfs-message-port-protocol/0.10.5: 1567 - resolution: {integrity: sha512-dHq+N0Epur5k7ZnQTSOepp5/Gmvtrg8SCD65t2okthkP8c4xIVxxaMpXZbHgi/2x0ix7HoQt4QiQa0StMkoj7A==} 1568 - engines: {node: '>=14.0.0', npm: '>=3.0.0'} 1557 + /ipfs-message-port-protocol/0.11.3: 1558 + resolution: {integrity: sha512-LRZRlbeTdD2RXPyIjpuLV2ewrMSFwewBgm0s0lzpwtm0RNMXXKE8KBZu/fDZSkx7Cx/tL4nJJCfeyy1nowIDdg==} 1559 + engines: {node: '>=15.0.0', npm: '>=3.0.0'} 1569 1560 dependencies: 1570 - ipfs-core-types: 0.9.0 1561 + ipfs-core-types: 0.10.3 1571 1562 multiformats: 9.6.3 1572 1563 transitivePeerDependencies: 1573 1564 - node-fetch ··· 1587 1578 engines: {node: '>=6.0.0', npm: '>=3.0.0'} 1588 1579 deprecated: This module has been superseded by @ipld/dag-pb and multiformats 1589 1580 dependencies: 1590 - cids: 1.1.7 1581 + cids: 1.1.9 1591 1582 interface-ipld-format: 1.0.1 1592 - multicodec: 3.1.0 1583 + multicodec: 3.2.1 1593 1584 multihashing-async: 2.0.1 1594 1585 protobufjs: 6.11.2 1595 1586 stable: 0.1.8 ··· 1793 1784 set-immediate-shim: 1.0.1 1794 1785 dev: false 1795 1786 1796 - /keystore-idb/0.15.4: 1797 - resolution: {integrity: sha512-3HfkebZQzo7iFA301aXTizupfwlWk350uwCjdUY2p6v9jVP0B1frySTgesInqjHaj66mpridvg8WNF43JErEQg==} 1787 + /keystore-idb/0.15.5: 1788 + resolution: {integrity: sha512-7bcUAnY5iD0+N75odQVTCs8mhXBW+yLt9/HH8+VUrl44FGllpAhu7q3/w9QpNMHxLQv3OXs1fsA042CAviN79Q==} 1798 1789 engines: {node: '>=10.21.0'} 1799 1790 dependencies: 1800 1791 localforage: 1.10.0 ··· 1980 1971 web-encoding: 1.1.5 1981 1972 dev: false 1982 1973 1983 - /multibase/4.0.4: 1984 - resolution: {integrity: sha512-8/JmrdSGzlw6KTgAJCOqUBSGd1V6186i/X8dDCGy/lbCKrQ+1QB6f3HE+wPr7Tpdj4U3gutaj9jG2rNX6UpiJg==} 1985 - engines: {node: '>=12.0.0', npm: '>=6.0.0'} 1986 - deprecated: This module has been superseded by the multiformats module 1987 - dependencies: 1988 - '@multiformats/base-x': 4.0.1 1989 - dev: false 1990 - 1991 1974 /multibase/4.0.6: 1992 1975 resolution: {integrity: sha512-x23pDe5+svdLz/k5JPGCVdfn7Q5mZVMBETiC+ORfO+sor9Sgs0smJzAjfTbM5tckeCqnaUuMYoz+k3RXMmJClQ==} 1993 1976 engines: {node: '>=12.0.0', npm: '>=6.0.0'} ··· 1996 1979 '@multiformats/base-x': 4.0.1 1997 1980 dev: false 1998 1981 1999 - /multicodec/3.1.0: 2000 - resolution: {integrity: sha512-f6d4DhbQ9a8WiJ/wpbKgeJSeR0/juP/1wnjbKdZ0KAWDkC/z7Lb3xOegMUG+uTcfwSYf6j1eTvFf8HDgqPRGmQ==} 2001 - deprecated: This module has been superseded by the multiformats module 2002 - dependencies: 2003 - uint8arrays: 2.1.7 2004 - varint: 6.0.0 2005 - dev: false 2006 - 2007 1982 /multicodec/3.2.1: 2008 1983 resolution: {integrity: sha512-+expTPftro8VAW8kfvcuNNNBgb9gPeNYV9dn+z1kJRWF2vih+/S79f2RVeIwmrJBUJ6NT9IUPWnZDQvegEh5pw==} 2009 1984 deprecated: This module has been superseded by the multiformats module ··· 2023 1998 multibase: 3.1.2 2024 1999 uint8arrays: 1.1.0 2025 2000 varint: 6.0.0 2026 - dev: false 2027 - 2028 - /multihashes/4.0.2: 2029 - resolution: {integrity: sha512-xpx++1iZr4ZQHjN1mcrXS6904R36LWLxX/CBifczjtmrtCXEX623DMWOF1eiNSg+pFpiZDFVBgou/4v6ayCHSQ==} 2030 - engines: {node: '>=12.0.0', npm: '>=6.0.0'} 2031 - dependencies: 2032 - multibase: 4.0.4 2033 - uint8arrays: 2.1.7 2034 - varint: 5.0.2 2035 2001 dev: false 2036 2002 2037 2003 /multihashes/4.0.3: ··· 2962 2928 xhr2: 0.1.4 2963 2929 dev: false 2964 2930 2965 - /webnative-elm/7.0.0_webnative@0.31.1: 2931 + /webnative-elm/7.0.0_webnative@0.32.0: 2966 2932 resolution: {integrity: sha512-i52PkbknlbPAXPrW9ygPMhM8GK5TOHdLsGK0HmzB7qPdPbP2hzL3td574KKiWcF3esf/thuKCc6L+Qx2j2nwFw==} 2967 2933 peerDependencies: 2968 2934 webnative: '> 0.24.0' 2969 2935 dependencies: 2970 - webnative: 0.31.1 2936 + webnative: 0.32.0 2971 2937 dev: false 2972 2938 2973 - /webnative/0.31.1: 2974 - resolution: {integrity: sha512-lkvAyy7MTMp3Yg+WgkjG508iCtwrVPmCSjQxxegLh0C15x4qO//28QYX7sFVPm8uFLST8B7EP8XLbThofKfnAg==} 2939 + /webnative/0.32.0: 2940 + resolution: {integrity: sha512-Oz7+WVakUFuMeIivfsCPGTOSaSHS34MM75EaXTL1G3AHIItHfJq67gwoEhSMgYcia7eM7zEx5HS8hmIhYgbTUg==} 2975 2941 engines: {node: '>=15'} 2976 2942 dependencies: 2977 2943 '@ipld/dag-cbor': 7.0.0 2978 2944 '@ipld/dag-pb': 2.1.15 2979 2945 fission-bloom-filters: 1.7.1 2980 - ipfs-message-port-client: 0.10.3 2981 - ipfs-message-port-protocol: 0.10.5 2946 + ipfs-message-port-client: 0.11.3 2947 + ipfs-message-port-protocol: 0.11.3 2982 2948 ipld-dag-pb: 0.22.3 2983 - keystore-idb: 0.15.4 2949 + keystore-idb: 0.15.5 2984 2950 localforage: 1.10.0 2985 2951 multiformats: 9.6.3 2986 2952 one-webcrypto: 1.0.3
+106 -15
src/Javascript/Brain/user.js
··· 126 126 function constructFission() { 127 127 if (wn) return Promise.resolve() 128 128 129 + importScripts("vendor/ipfs.min.js") 129 130 importScripts("vendor/webnative.min.js") 130 131 importScripts("vendor/webnative-elm.min.js") 131 - importScripts("vendor/ipfs-message-port-client.min.js") 132 132 133 133 // Environment setup 134 134 wn = self.webnative ··· 136 136 if ([ "localhost", "nightly.diffuse.sh" ].includes(location.hostname)) { 137 137 wn.setup.debug({ enabled: true }) 138 138 } 139 + 140 + let endpoints 139 141 140 142 if (WEBNATIVE_STAGING_MODE) { 141 - wn.setup.endpoints(WEBNATIVE_STAGING_ENV) 143 + endpoints = wn.setup.endpoints(WEBNATIVE_STAGING_ENV) 144 + } else { 145 + endpoints = wn.setup.endpoints({}) 142 146 } 143 147 144 148 // Connect IPFS 145 - return ( 146 - new Promise((resolve) => { 147 - const channel = new MessageChannel() 149 + const peersPromise = fetch( `${endpoints.api}/ipfs/peers` ) 150 + .then(r => r.json()) 151 + .then(r => r.filter(p => p.includes("/wss/"))) 152 + .catch(e => { throw new Error("💥 Couldn't start IPFS node, failed to fetch peer list") }) 148 153 149 - channel.port1.onmessage = ({ ports }) => { 150 - resolve(ports[0]) 154 + return peersPromise.then(peers => { 155 + return Ipfs.create({ 156 + config: { 157 + Addresses: { 158 + Delegates: [] 159 + }, 160 + Bootstrap: [], 161 + Discovery: { 162 + webRTCStar: { enabled: false } 163 + } 164 + }, 165 + preload: { 166 + enabled: false 167 + }, 168 + libp2p: { 169 + config: { 170 + peerDiscovery: { autoDial: false } 171 + } 151 172 } 152 - 153 - self.postMessage( 154 - { action: "SETUP_WEBNATIVE_IFRAME" }, 155 - [ channel.port2 ] 156 - ) 173 + }).then(ipfs => { 174 + peers.forEach(peer => tryConnectingToIpfsPeer(ipfs, peer)) 175 + wn.ipfs.set(ipfs) 157 176 }) 158 - ) 159 - .then(port => self.IpfsMessagePortClient.IPFSClient.from(port)) 160 - .then(ipfs => wn.ipfs.set(ipfs)) 177 + }) 161 178 } 162 179 163 180 164 181 ports.deconstructFission = _app => _ => { 165 182 wn.leave({ withoutRedirect: true }) 166 183 wn = null 184 + } 185 + 186 + 187 + // TODO: This stuff is going to be moved into webnative. 188 + // Remove when possible. 189 + 190 + 191 + const KEEP_ALIVE_INTERVAL = 192 + 1 * 60 * 1000 // 1 minute 193 + 194 + const BACKOFF_INIT = { 195 + retryNumber: 0, 196 + lastBackoff: 0, 197 + currentBackoff: 1000 198 + } 199 + 200 + const KEEP_TRYING_INTERVAL = 201 + 5 * 60 * 1000 // 5 minutes 202 + 203 + const latestPeerTimeoutIds = {} 204 + 205 + 206 + function tryConnectingToIpfsPeer(ipfs, peer) { 207 + ipfs.libp2p.ping(peer).then(() => { 208 + return ipfs.swarm.connect(peer, 1 * 1000) 209 + .then(() => { 210 + console.log(`🪐 Connected to ${peer}`) 211 + setTimeout(() => keepAlive(ipfs, peer, BACKOFF_INIT), KEEP_ALIVE_INTERVAL) 212 + }) 213 + .catch(() => { 214 + console.log(`🪓 Could not connect to ${peer}`) 215 + keepAlive(ipfs, peer, BACKOFF_INIT) 216 + }) 217 + }) 218 + } 219 + 220 + 221 + function keepAlive(ipfs, peer, backoff) { 222 + let timeoutId = null 223 + 224 + if (backoff.currentBackoff < KEEP_TRYING_INTERVAL) { 225 + timeoutId = setTimeout(() => reconnect(ipfs, peer, backoff), backoff.currentBackoff) 226 + } else { 227 + timeoutId = setTimeout(() => reconnect(ipfs, peer, backoff), KEEP_TRYING_INTERVAL) 228 + } 229 + 230 + latestPeerTimeoutIds[peer] = timeoutId 231 + 232 + ipfs.libp2p.ping(peer).then(_ => { 233 + clearTimeout(timeoutId) 234 + 235 + if (timeoutId === latestPeerTimeoutIds[peer]) { 236 + setTimeout(() => keepAlive(ipfs, peer, BACKOFF_INIT), KEEP_ALIVE_INTERVAL) 237 + } 238 + }).catch(() => {}) 239 + } 240 + 241 + 242 + function reconnect(ipfs, peer, backoff) { 243 + ipfs.swarm.disconnect(peer) 244 + .then(() => ipfs.swarm.connect(peer)) 245 + .catch(() => {}) 246 + 247 + if (backoff.currentBackoff < KEEP_TRYING_INTERVAL) { 248 + const nextBackoff = { 249 + retryNumber: backoff.retryNumber + 1, 250 + lastBackoff: backoff.currentBackoff, 251 + currentBackoff: backoff.lastBackoff + backoff.currentBackoff 252 + } 253 + 254 + keepAlive(ipfs, peer, nextBackoff) 255 + } else { 256 + keepAlive(ipfs, peer, backoff) 257 + } 167 258 } 168 259 169 260
-8
src/Javascript/index.js
··· 141 141 142 142 function handleAction(action, data, ports) { switch (action) { 143 143 case "DOWNLOAD_TRACKS": return downloadTracks(data) 144 - case "SETUP_WEBNATIVE_IFRAME": return setupWebnativeIframe(ports) 145 144 }} 146 145 147 146 ··· 304 303 wn.setup.endpoints(WEBNATIVE_STAGING_ENV) 305 304 } 306 305 }) 307 - } 308 - 309 - 310 - function setupWebnativeIframe(ports) { 311 - loadWebnative() 312 - .then(_ => wn.ipfs.iframe()) 313 - .then(iframePort => ports[0].postMessage("connect", [ iframePort ])) 314 306 } 315 307 316 308