@@ -213,6 +213,8 @@ export class Message {
213213 readonly mux : kcd . Mux | undefined ;
214214 readonly signals : Record < string , Signal > = { } ;
215215
216+ public updateListeners : CallableFunction [ ] = [ ] ;
217+
216218 constructor ( msgDef : kcd . Message ) {
217219 /**
218220 * CAN identifier
@@ -282,6 +284,39 @@ export class Message {
282284 }
283285 } ) ;
284286 }
287+
288+ /**
289+ * Keep track of listeners who want to be notified if this message is received/decoded.
290+ * @method onMessageUpdate
291+ * @param listener JS callback to get notification
292+ * @for Message
293+ */
294+ onMessageUpdate ( listener : CallableFunction ) {
295+ this . updateListeners . push ( listener ) ;
296+ return listener ;
297+ }
298+
299+ /**
300+ * Remove the message listener.
301+ * @method removeListener
302+ * @param listener to be removed
303+ * @for Message
304+ */
305+ removeListener ( listener : CallableFunction ) {
306+ let idx = this . updateListeners . indexOf ( listener ) ;
307+ if ( idx >= 0 ) this . updateListeners . splice ( idx , 1 ) ;
308+ }
309+
310+ /**
311+ * Called internally to let the message listener know that the message was received.
312+ * @method update
313+ * @for Message
314+ */
315+ update ( ) {
316+ this . updateListeners . forEach ( ( listener ) => {
317+ listener ( this ) ;
318+ } ) ;
319+ }
285320}
286321
287322// -----------------------------------------------------------------------------
@@ -363,6 +398,9 @@ export class DatabaseService {
363398
364399 s . update ( val ) ;
365400 }
401+
402+ // Let the message listener know that the message was received.
403+ m . update ( ) ;
366404 }
367405
368406 /**
0 commit comments