Skip to content

Commit

Permalink
Merge pull request #24 from jphastings/patch-1
Browse files Browse the repository at this point in the history
Use browser IPFS if available
  • Loading branch information
codedread committed Jan 14, 2019
2 parents 937bcaa + 87309d1 commit c002a97
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions code/kthoom-ipfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ kthoom.ipfs = {
// Load in the IPFS script API.
const ipfsScriptEl = document.createElement('script');
ipfsScriptEl.addEventListener('load', () => {
kthoom.getApp().setProgressMeter({loadPct: 0.2, label: 'Creating IPFS node...'});
const node = window.Ipfs.createNode();
node.on('start', () => {
kthoom.ipfs.node_ = node;
resolve(node);
});
if (window.ipfs) {
kthoom.ipfs.node_ = window.ipfs;
resolve(window.ipfs);
} else {
kthoom.getApp().setProgressMeter({loadPct: 0.2, label: 'Creating IPFS node...'});
const node = window.Ipfs.createNode();
node.on('start', () => {
kthoom.ipfs.node_ = node;
resolve(node);
});
}
});
ipfsScriptEl.setAttribute('src', 'https://unpkg.com/ipfs@0.27.7/dist/index.js');
document.body.appendChild(ipfsScriptEl);
Expand All @@ -56,4 +61,4 @@ kthoom.ipfs = {
kthoom.ipfs.loadHash(ipfshash);
}
},
};
};

0 comments on commit c002a97

Please sign in to comment.