Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #726 from 3box/hotfix/multiple-ipfs-creates
Browse files Browse the repository at this point in the history
fix: getIPFS called same time or from different closures in browser
  • Loading branch information
zachferland authored Feb 13, 2020
2 parents 8c38e7e + 7a348d0 commit f002cf8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
4 changes: 4 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

## v1.16.3 - 2020-02-13
* fix: getIPFS called same time or from different closures in browser
* fix: ghost chat member list, with no auth opens

## v1.16.2 - 2020-02-05
* chore: update ipfs & orbitdb
* fix: Verify legacy muport DID properly
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "3box",
"version": "1.16.2",
"version": "1.16.3",
"description": "Interact with user data",
"main": "lib/3box.js",
"directories": {
Expand Down
18 changes: 15 additions & 3 deletions src/3box.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const PINNING_NODE = config.pinning_node
const ADDRESS_SERVER_URL = config.address_server_url
const IPFS_OPTIONS = config.ipfs_options

let globalIPFS // , ipfsProxy, cacheProxy, iframeLoadedPromise
let globalIPFS, globalIPFSPromise // , ipfsProxy, cacheProxy, iframeLoadedPromise

/*
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
Expand Down Expand Up @@ -509,8 +509,20 @@ class Box extends BoxApi {
* @return {IPFS} the ipfs instance
*/
static async getIPFS (opts = {}) {
const ipfs = globalIPFS || await initIPFS(opts.ipfs, opts.iframeStore, opts.ipfsOptions)
globalIPFS = ipfs
if (typeof window !== 'undefined') {
globalIPFS = window.globalIPFS
globalIPFSPromise = window.globalIPFSPromise
}

if (!globalIPFS && !globalIPFSPromise) {
globalIPFSPromise = initIPFS(opts.ipfs, opts.iframeStore, opts.ipfsOptions)
}
if (typeof window !== 'undefined') window.globalIPFSPromise = globalIPFSPromise

if (!globalIPFS) globalIPFS = await globalIPFSPromise
if (typeof window !== 'undefined') window.globalIPFS = globalIPFS

const ipfs = globalIPFS
const pinningNode = opts.pinningNode || PINNING_NODE
ipfs.swarm.connect(pinningNode, () => {})
return ipfs
Expand Down
6 changes: 3 additions & 3 deletions src/ghost.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class GhostThread extends EventEmitter {
this._3id = threeId
// announce to other peers that we are online
this.listMembers().then(members => {
members.map(({ id }) => {
this._announce(this._threeIdToPeerId(id))
this._room.getPeers().map(id => {
this._announce(id)
})
})
}
Expand Down Expand Up @@ -228,7 +228,7 @@ class GhostThread extends EventEmitter {
*/
async _userJoined (did, peerID) {
const members = await this.listMembers()
if (!members.includes(did) && (this._3id && this._3id.DID !== did)) {
if (!members.includes(did) && (!this._3id || this._3id.DID !== did)) {
this._members[did] = peerID
this._members[peerID] = did
this.emit('user-joined', 'joined', did, peerID)
Expand Down

0 comments on commit f002cf8

Please sign in to comment.