Skip to content

Commit b464b9f

Browse files
committed
feat(window.ipfs): opt-in ipfsx experiment
This adds an opt-in ipfsx experiment. In short, if `experiments:{ipfsx:true}` is passed `window.ipfs.enable` will return IPFS API instance wrapped in ipfsx prototype from https://github.com/ipfs-shipyard/ipfsx ``` let ipfs = await window.ipfs.enable({ commands: ['add','files.addPullStream'], experiments: { ipfsx: true } }) ```
1 parent 19a9577 commit b464b9f

File tree

3 files changed

+153
-97
lines changed

3 files changed

+153
-97
lines changed

add-on/src/contentScripts/ipfs-proxy/page.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ const _Buffer = Buffer
55
// TODO: (wip) this should not be injected by default into every page,
66
// instead should be lazy-loaded when .enable() method is called for the first time
77
const { createProxyClient } = require('ipfs-postmsg-proxy')
8-
const { call } = require('postmsg-rpc')
98

109
function createEnableCommand (proxyClient) {
1110
return {
1211
enable: async (opts) => {
12+
// (This should be a lazy-load)
1313
// Send message to proxy server for additional validation
1414
// eg. trigger user prompt if a list of requested capabilities is not empty
1515
// or fail fast and throw if IPFS Proxy is disabled globally
16-
await call('proxy.enable', opts)
16+
await require('postmsg-rpc').call('proxy.enable', opts)
1717
// Additional client-side features
18-
if (opts) {
19-
if (opts.ipfsx === true) {
20-
// TODO: wrap API in https://github.com/alanshaw/ipfsx
21-
// return ipfsx(proxyClient)
18+
if (opts && opts.experiments) {
19+
if (opts.experiments.ipfsx) {
20+
// Experiment: wrap API with https://github.com/alanshaw/ipfsx
21+
return require('ipfsx')(proxyClient)
2222
}
2323
}
2424
return Object.freeze(proxyClient)

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
"ipfs-http-client": "27.1.0",
117117
"ipfs-http-response": "0.2.1",
118118
"ipfs-postmsg-proxy": "3.1.1",
119+
"ipfsx": "0.17.0",
119120
"is-ipfs": "0.4.8",
120121
"is-svg": "3.0.0",
121122
"lru-cache": "5.1.1",

0 commit comments

Comments
 (0)