holepunch-hop 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "holepunch-hop",
3
- "version": "0.1.8",
3
+ "version": "0.2.0",
4
4
  "description": "data interface to HOP",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/bees.js CHANGED
@@ -156,15 +156,73 @@ class HyperBee extends EventEmitter {
156
156
  await this.dbHOPresults.put(refContract.hash, refContract.data)
157
157
  }
158
158
 
159
+ /**
160
+ * save chat history
161
+ * @method saveBentochat
162
+ *
163
+ */
164
+ saveBentochat = async function (chatHistory) {
165
+ await this.dbBentospaces.put(chatHistory.chat.chatid, chatHistory)
166
+ let checkSave = await this.getBentochat(chatHistory.chat.chatid)
167
+ return checkSave
168
+ }
169
+
170
+ /**
171
+ * delete chat item
172
+ * @method deleteBentochat
173
+ *
174
+ */
175
+ deleteBentochat = async function (chat) {
176
+ await this.dbBentospaces.del(chat.chatid)
177
+ let deleteInfo = {}
178
+ deleteInfo.chatid = chat.chatid
179
+ return deleteInfo
180
+ }
181
+
182
+ /**
183
+ * lookup peer bentospace layout default
184
+ * @method getBentochat
185
+ *
186
+ */
187
+ getBentochat = async function (key) {
188
+ // let key = 'startbentospaces'
189
+ const nodeData = await this.dbBentospaces.get(key)
190
+ return nodeData
191
+ }
192
+
193
+ /**
194
+ * lookup range save chat history
195
+ * @method getBentochatHistory
196
+ *
197
+ */
198
+ getBentochatHistory = async function (range) {
199
+ const chathistoryData = this.dbBentospaces.createReadStream() // { gt: 'a', lt: 'z' }) // anything >a and <z
200
+ let chatData = []
201
+ for await (const { key, value } of chathistoryData) {
202
+ chatData.push({ key, value })
203
+ }
204
+ return chatData
205
+ }
206
+
207
+ /**
208
+ * save space menu
209
+ * @method saveSpaceHistory
210
+ *
211
+ */
212
+ saveSpaceHistory = async function (spaceContract) {
213
+ await this.dbBentospaces.put(spaceContract.space.spaceid, spaceContract)
214
+ let checkSave = await this.getBentospace(spaceContract.space.spaceid)
215
+ return checkSave
216
+ }
217
+
159
218
  /**
160
219
  * save space layout of bentobox
161
220
  * @method saveBentospace
162
221
  *
163
222
  */
164
223
  saveBentospace = async function (spaceContract) {
165
- let key = 'startbentospaces'
166
- await this.dbBentospaces.put(key, spaceContract)
167
- let checkSave = await this.getBentospace(key)
224
+ await this.dbBentospaces.put(spaceContract.spaceid, spaceContract)
225
+ let checkSave = await this.getBentospace(spaceContract.spaceid)
168
226
  return checkSave
169
227
  }
170
228
 
@@ -173,12 +231,23 @@ class HyperBee extends EventEmitter {
173
231
  * @method getBentospace
174
232
  *
175
233
  */
176
- getBentospace = async function () {
177
- let key = 'startbentospaces'
234
+ getBentospace = async function (key) {
178
235
  const nodeData = await this.dbBentospaces.get(key)
179
236
  return nodeData
180
237
  }
181
238
 
239
+ /**
240
+ * delete nxp ref contract from peer library
241
+ * @method deleteBentospace
242
+ *
243
+ */
244
+ deleteBentospace = async function (space) {
245
+ const deleteStatus = await this.dbBentospaces.del(space.spaceid)
246
+ let deleteInfo = {}
247
+ deleteInfo.spaceid = space.spaceid
248
+ return deleteInfo
249
+ }
250
+
182
251
  /**
183
252
  * save space layout of bentobox
184
253
  * @method saveSolospace
@@ -329,17 +398,6 @@ class HyperBee extends EventEmitter {
329
398
  return deleteInfo
330
399
  }
331
400
 
332
- /**
333
- * delete nxp ref contract from peer library
334
- * @method deleteBentospace
335
- *
336
- */
337
- deleteBentospace = async function (nxpID) {
338
- let key = 'startbentospaces'
339
- const deleteStatus = await this.dbBentospaces.del(key)
340
- return deleteStatus
341
- }
342
-
343
401
  /**
344
402
  * repicate the publiclibrary peer to peer
345
403
  * @method replicatePubliclibrary
package/src/index.js CHANGED
@@ -99,10 +99,11 @@ class HolepunchWorker extends EventEmitter {
99
99
  // new warm incoming peer
100
100
  this.Peers.on('connect-warm', (data) => {
101
101
  let peerId = {}
102
- peerId.name = ''
103
- peerId.publickkey = data
102
+ peerId.name = 'new-peer'
103
+ peerId.publickey = data
104
104
  peerId.datastore = ''
105
105
  this.warmPeers.push(peerId)
106
+ this.emit('peer-incoming', peerId)
106
107
  })
107
108
  }
108
109