fix(startup): Subscribing to chat pubsub channel at startup

This commit is contained in:
Chris Troutner
2022-05-26 09:12:15 -07:00
parent da62f1bbe3
commit 324c372119
4 changed files with 23 additions and 1 deletions
+3 -1
View File
@@ -85,5 +85,7 @@ module.exports = {
ipfsHost: process.env.IPFS_HOST ? process.env.IPFS_HOST : 'localhost', ipfsHost: process.env.IPFS_HOST ? process.env.IPFS_HOST : 'localhost',
ipfsApiPort: process.env.IPFS_API_PORT ipfsApiPort: process.env.IPFS_API_PORT
? parseInt(process.env.IPFS_API_PORT) ? parseInt(process.env.IPFS_API_PORT)
: 5001 : 5001,
chatPubSubChan: 'psf-ipfs-chat-001'
} }
+4
View File
@@ -2,6 +2,7 @@
top-level IPFS library that combines the individual IPFS-based libraries. top-level IPFS library that combines the individual IPFS-based libraries.
*/ */
// Local libraries
const IpfsAdapter = require('./ipfs') const IpfsAdapter = require('./ipfs')
const IpfsCoordAdapter = require('./ipfs-coord') const IpfsCoordAdapter = require('./ipfs-coord')
@@ -36,6 +37,9 @@ class IPFS {
await this.ipfsCoordAdapter.start() await this.ipfsCoordAdapter.start()
console.log('ipfs-coord is ready.') console.log('ipfs-coord is ready.')
// Subscribe to the chat pubsub channel
await this.ipfsCoordAdapter.subscribeToChat()
return true return true
} catch (err) { } catch (err) {
console.error('Error in adapters/ipfs/index.js/start()') console.error('Error in adapters/ipfs/index.js/start()')
+14
View File
@@ -97,6 +97,20 @@ class IpfsCoordAdapter {
throw err throw err
} }
} }
// Subscribe to the chat pubsub channel
async subscribeToChat () {
try {
await this.ipfsCoord.adapters.pubsub.subscribeToPubsubChannel(
this.config.chatPubSubChan,
console.log,
this.ipfsCoord.thisNode
)
} catch (err) {
console.error('Error in subscribeToChat')
throw err
}
}
} }
module.exports = IpfsCoordAdapter module.exports = IpfsCoordAdapter
+2
View File
@@ -8,6 +8,8 @@ class IPFSCoord {
} }
async start () {} async start () {}
async subscribeToChat() {}
} }
module.exports = IPFSCoord module.exports = IPFSCoord