Browse Source

assign discoveryKey

Kieran Gibb 2 years ago
parent
commit
aa2def0558
No known key found for this signature in database
3 changed files with 17 additions and 1 deletions
  1. 14
    0
      index.js
  2. 2
    0
      package.json
  3. 1
    1
      test/index.test.js

+ 14
- 0
index.js View File

@@ -1,5 +1,7 @@
1 1
 const Base = require('cobox-group-base')
2 2
 const swarm = require('cobox-swarm')
3
+const maybe = require('call-me-maybe')
4
+const assert = require('assert')
3 5
 
4 6
 module.exports = (storage, address, opts = {}) => (
5 7
   new BlindReplicator(storage, address, opts)
@@ -14,6 +16,18 @@ class BlindReplicator extends Base {
14 16
     this._isSwarming = true
15 17
   }
16 18
 
19
+  ready (callback) {
20
+    var self = this
21
+    return maybe(callback, new Promise((resolve, reject) => {
22
+      self._readyCallback((err) => {
23
+        if (err) return reject(err)
24
+        self.discoveryKey = self.multifeed._root.discoveryKey
25
+        self._isReady = true
26
+        return resolve()
27
+      })
28
+    }))
29
+  }
30
+
17 31
   swarm (opts = {}) {
18 32
     this._connection = swarm(this, Object.assign(opts, {
19 33
       logger: this.config.logger

+ 2
- 0
package.json View File

@@ -16,6 +16,8 @@
16 16
   "author": "magma collective",
17 17
   "license": "AGPL-3.0-or-later",
18 18
   "dependencies": {
19
+    "assert": "^2.0.0",
20
+    "call-me-maybe": "^1.0.1",
19 21
     "cobox-group-base": "git+https://ledger-git.dyne.org/cobox/cobox-group-base",
20 22
     "cobox-swarm": "git+https://ledger-git.dyne.org/cobox/cobox-swarm"
21 23
   },

+ 1
- 1
test/index.test.js View File

@@ -41,7 +41,7 @@ describe('basic', (context) => {
41 41
     replicator.unswarm()
42 42
 
43 43
     assert.notOk(replicator._connection, 'destroys the connection')
44
-    asser.notOk(repicator._isSwarming, 'stops swarming')
44
+    assert.notOk(replicator._isSwarming, 'stops swarming')
45 45
 
46 46
     cleanup(storage, next)
47 47
   })