File tree Expand file tree Collapse file tree
packages/tdev/webserial/models Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,8 +35,19 @@ const DEFAULT_CONFIG: Config = {
3535
3636export interface iSubscriber {
3737 id : string ;
38+ /**
39+ * called when a complete line (ending with a newline) is received from the serial device.
40+ */
3841 onNewLines : ( newLines : string [ ] ) => void ;
42+ /**
43+ * called when the reset trigger is received or when the replay is reset/started.
44+ * Subscribers should clear any state that depends on the received lines when this is called.
45+ */
3946 reset : ( ) => void ;
47+ /**
48+ * called when the connection state changes (e.g. from 'connected' to 'disconnected').
49+ */
50+ onConnectionStateChange ?: ( state : ConnectionState ) => void ;
4051}
4152
4253export default class SerialDevice {
@@ -196,6 +207,9 @@ export default class SerialDevice {
196207 @action
197208 setConnectionState ( state : ConnectionState ) {
198209 this . connectionState = state ;
210+ for ( const subscriber of this . subscriptions . values ( ) ) {
211+ subscriber . onConnectionStateChange ?.( state ) ;
212+ }
199213 }
200214
201215 @action
You can’t perform that action at this time.
0 commit comments