File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33const Path = require ( 'path' )
44const debug = require ( 'debug' ) ( 'dataparty.topics.host-topic' )
5+ const EventEmitter = require ( 'eventemitter3' )
56
6- class HostTopic {
7+
8+ class HostTopic extends EventEmitter {
79 constructor ( path , type ) {
10+ super ( )
811 this . path = Path . normalize ( path )
912 this . type = type
1013 this . created = Date . now ( )
@@ -95,6 +98,12 @@ class HostTopic {
9598 sends . push ( node [ 1 ] . send ( this , this . lastMessage , sender ) )
9699 }
97100
101+ this . emit ( 'publish' , {
102+ topic : this ,
103+ data : this . lastMessage ,
104+ sender : sender
105+ } )
106+
98107 if ( sends . length > 0 ) {
99108 debug ( 'publishing' , this . path )
100109 this . sending = true
Original file line number Diff line number Diff line change @@ -18,8 +18,8 @@ class LocalTopicHost {
1818 */
1919 constructor ( ) {
2020 debug ( 'constructor' )
21- this . nodesByUuid = new Map ( )
22- this . topicsByPath = new Map ( )
21+ this . nodesByUuid = new Map ( ) // <string, PeerNode>
22+ this . topicsByPath = new Map ( ) // <string, HostTopic>
2323 this . party = null
2424 }
2525
@@ -146,6 +146,18 @@ class LocalTopicHost {
146146
147147 }
148148
149+ async subscribeInternal ( path , cb , create = false ) {
150+ const topic = this . getTopic ( path , create )
151+
152+ debug ( 'subscribeInternal' , path )
153+
154+ if ( topic ) {
155+
156+ topic . on ( 'publish' , cb )
157+ }
158+
159+ }
160+
149161 async destroyNode ( peer ) {
150162 const node = this . getNodeByPeer ( peer )
151163
You can’t perform that action at this time.
0 commit comments