Browse Source

log last broadcast message

Kieran Gibb 2 years ago
parent
commit
24483aaeaa
No known key found for this signature in database
1 changed files with 4 additions and 1 deletions
  1. 4
    1
      index.js

+ 4
- 1
index.js View File

@@ -11,6 +11,7 @@ const hyperswarm = require('hyperswarm')
11 11
 const collect = require('collect-stream')
12 12
 const { EventEmitter } = require('events')
13 13
 const createBroadcastStream = require('broadcast-stream')
14
+const debug = require('debug')('cobox-hub')
14 15
 
15 16
 class Application extends EventEmitter {
16 17
   constructor (config, opts = {}) {
@@ -63,7 +64,9 @@ class Application extends EventEmitter {
63 64
           collect(self.admin.logs.read({ query: broadcastStop }), (err, stops) => {
64 65
             if (err) return reject(err)
65 66
             var sorted = [...starts, ...stops].sort((a, b) => a.timestamp > b.timestamp ? +1 : -1)
66
-            if (sorted.length) self.emit(sorted[sorted.length - 1].type)
67
+            var last = sorted[sorted.length - 1]
68
+            debug(`Last broadcast message published: `, JSON.stringify(last, null, 2))
69
+            if (sorted.length) self.emit(last.type)
67 70
             return resolve()
68 71
           })
69 72
         })