44 CoreOptions ,
55 DDPConnectorOptions ,
66 DDPTLSOptions ,
7+ ICoreHandler ,
78 Observer ,
89 PeripheralDevicePubSub ,
910 PeripheralDevicePubSubCollections ,
@@ -36,7 +37,7 @@ export interface CoreConfig {
3637/**
3738 * Represents a connection between the Gateway and Core
3839 */
39- export class CoreHandler {
40+ export class CoreHandler implements ICoreHandler {
4041 core ! : CoreConnection <
4142 CorelibPubSubTypes & PeripheralDevicePubSubTypes ,
4243 CorelibPubSubCollections & PeripheralDevicePubSubCollections
@@ -45,12 +46,7 @@ export class CoreHandler {
4546 public _observers : Array < any > = [ ]
4647 public deviceSettings : LiveStatusGatewayConfig = { }
4748
48- public errorReporting = false
49- public multithreading = false
50- public reportAllCommands = false
51-
5249 private _deviceOptions : DeviceConfig
53- private _onConnected ?: ( ) => any
5450 private _executedFunctions = new Set < PeripheralDeviceCommandId > ( )
5551 private _coreConfig ?: CoreConfig
5652
@@ -59,6 +55,10 @@ export class CoreHandler {
5955 private _statusInitialized = false
6056 private _statusDestroyed = false
6157
58+ public get connectedToCore ( ) : boolean {
59+ return this . core && this . core . connected
60+ }
61+
6262 constructor ( logger : Logger , deviceOptions : DeviceConfig ) {
6363 this . logger = logger
6464 this . _deviceOptions = deviceOptions
@@ -77,7 +77,6 @@ export class CoreHandler {
7777 this . setupObserversAndSubscriptions ( ) . catch ( ( e ) => {
7878 this . logger . error ( 'Core Error during setupObserversAndSubscriptions:' , e )
7979 } )
80- if ( this . _onConnected ) this . _onConnected ( )
8180 } )
8281 this . core . onDisconnected ( ( ) => {
8382 this . logger . warn ( 'Core Disconnected!' )
@@ -97,7 +96,6 @@ export class CoreHandler {
9796
9897 this . logger . info ( 'Core id: ' + this . core . deviceId )
9998 await this . setupObserversAndSubscriptions ( )
100- if ( this . _onConnected ) this . _onConnected ( )
10199
102100 this . _statusInitialized = true
103101 await this . updateCoreStatus ( )
@@ -180,9 +178,6 @@ export class CoreHandler {
180178
181179 return options
182180 }
183- onConnected ( fcn : ( ) => any ) : void {
184- this . _onConnected = fcn
185- }
186181
187182 onDeviceChanged ( ) : void {
188183 const col = this . core . getCollection ( PeripheralDevicePubSubCollectionsNames . peripheralDeviceForDevice )
@@ -319,7 +314,10 @@ export class CoreHandler {
319314 this . logger . info ( 'getDevicesInfo' )
320315 return [ ]
321316 }
322- async updateCoreStatus ( ) : Promise < any > {
317+ getCoreStatus ( ) : {
318+ statusCode : StatusCode
319+ messages : string [ ]
320+ } {
323321 let statusCode = StatusCode . GOOD
324322 const messages : Array < string > = [ ]
325323
@@ -331,11 +329,13 @@ export class CoreHandler {
331329 statusCode = StatusCode . BAD
332330 messages . push ( 'Shut down' )
333331 }
334-
335- return this . core . setStatus ( {
336- statusCode : statusCode ,
337- messages : messages ,
338- } )
332+ return {
333+ statusCode,
334+ messages,
335+ }
336+ }
337+ async updateCoreStatus ( ) : Promise < any > {
338+ return this . core . setStatus ( this . getCoreStatus ( ) )
339339 }
340340 private _getVersions ( ) {
341341 const versions : { [ packageName : string ] : string } = { }
0 commit comments