File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -111,15 +111,20 @@ class RosNode extends EventEmitter {
111111 subscribe ( options , callback ) {
112112 let topic = options . topic ;
113113 let subImpl = this . _subscribers [ topic ] ;
114+ let firstSubscriber = false ;
114115 if ( ! subImpl ) {
115116 subImpl = new SubscriberImpl ( options , this ) ;
116117 this . _subscribers [ topic ] = subImpl ;
118+ this . first = true ;
117119 }
118120
119121 const sub = new Subscriber ( subImpl ) ;
120122 if ( callback && typeof callback === 'function' ) {
121123 sub . on ( 'message' , callback ) ;
122124 }
125+ if ( ! firstSubscriber && subImpl . _latching && subImpl . _lastMessage ) {
126+ sub . emit ( 'message' , subImpl . _lastMessage )
127+ }
123128
124129 return sub ;
125130 }
Original file line number Diff line number Diff line change @@ -85,6 +85,11 @@ class SubscriberImpl extends EventEmitter {
8585 this . _pendingPubClients = { } ;
8686
8787 this . _state = REGISTERING ;
88+
89+ this . _latching = undefined ;
90+
91+ this . _lastMessage = undefined ;
92+
8893 this . _register ( ) ;
8994 }
9095
@@ -389,6 +394,10 @@ class SubscriberImpl extends EventEmitter {
389394 // remove client from pending map now that it's validated
390395 delete this . _pendingPubClients [ client . nodeUri ] ;
391396
397+ if ( header . latching ) {
398+ this . _latching = true ;
399+ }
400+
392401 // pipe all future messages to _handleMessage
393402 client . $deserializer . on ( 'message' , this . _handleMessage . bind ( this ) ) ;
394403
@@ -416,6 +425,9 @@ class SubscriberImpl extends EventEmitter {
416425 _handleMsgQueue ( msgQueue ) {
417426 try {
418427 msgQueue . forEach ( ( msg ) => {
428+ if ( this . _latching ) {
429+ this . _lastMessage = this . _messageHandler . deserialize ( msg ) ;
430+ }
419431 this . emit ( 'message' , this . _messageHandler . deserialize ( msg ) ) ;
420432 } ) ;
421433 }
You can’t perform that action at this time.
0 commit comments