7
7
// Include this first to auto-register Crypto, Network and Time Node.js implementations
8
8
import { Environment , Logger , StorageContext , StorageService } from "@matter/general" ;
9
9
import { ControllerStore } from "@matter/node" ;
10
- import { StorageBackendDisk } from "@matter/nodejs" ;
11
10
import { EndpointInterface } from "@matter/protocol" ;
12
11
import { NodeId } from "@matter/types" ;
13
12
import { CommissioningController } from "@project-chip/matter.js" ;
@@ -18,19 +17,18 @@ const logger = Logger.get("Node");
18
17
19
18
export class MatterNode {
20
19
#storageLocation?: string ;
21
- private storage ?: StorageBackendDisk ;
22
- private storageContext ?: StorageContext ;
23
-
24
- #environment?: Environment ;
20
+ #storageContext?: StorageContext ;
21
+ readonly #environment?: Environment ;
25
22
commissioningController ?: CommissioningController ;
26
- private started = false ;
23
+ #started = false ;
24
+ readonly #nodeNum: number ;
25
+ readonly #netInterface?: string ;
27
26
28
- constructor (
29
- private readonly nodeNum : number ,
30
- private readonly netInterface ?: string ,
31
- ) {
27
+ constructor ( nodeNum : number , netInterface ?: string ) {
32
28
this . #environment = Environment . default ;
33
29
this . #environment. runtime . add ( this ) ;
30
+ this . #nodeNum = nodeNum ;
31
+ this . #netInterface = netInterface ;
34
32
}
35
33
36
34
get storageLocation ( ) {
@@ -46,11 +44,11 @@ export class MatterNode {
46
44
*/
47
45
48
46
if ( this . #environment) {
49
- if ( this . netInterface !== undefined ) {
50
- this . #environment. vars . set ( "mdns.networkinterface" , this . netInterface ) ;
47
+ if ( this . # netInterface !== undefined ) {
48
+ this . #environment. vars . set ( "mdns.networkinterface" , this . # netInterface) ;
51
49
}
52
50
// Build up the "Not-so-legacy" Controller
53
- const id = `shell-${ this . nodeNum . toString ( ) } ` ;
51
+ const id = `shell-${ this . # nodeNum. toString ( ) } ` ;
54
52
this . commissioningController = new CommissioningController ( {
55
53
environment : {
56
54
environment : this . #environment,
@@ -65,7 +63,7 @@ export class MatterNode {
65
63
if ( resetStorage ) {
66
64
await controllerStore . erase ( ) ;
67
65
}
68
- this . storageContext = controllerStore . storage . createContext ( "Node" ) ;
66
+ this . # storageContext = controllerStore . storage . createContext ( "Node" ) ;
69
67
70
68
const storageService = this . #environment. get ( StorageService ) ;
71
69
const baseLocation = storageService . location ;
@@ -81,26 +79,21 @@ export class MatterNode {
81
79
}
82
80
83
81
get Store ( ) {
84
- if ( ! this . storageContext ) {
82
+ if ( ! this . # storageContext) {
85
83
throw new Error ( "Storage uninitialized" ) ;
86
84
}
87
- return this . storageContext ;
85
+ return this . # storageContext;
88
86
}
89
87
90
88
async close ( ) {
91
89
await this . commissioningController ?. close ( ) ;
92
- return await this . closeStorage ( ) ;
93
- }
94
-
95
- async closeStorage ( ) {
96
- await this . storage ?. close ( ) ;
97
90
}
98
91
99
92
async start ( ) {
100
- if ( this . started ) {
93
+ if ( this . # started) {
101
94
return ;
102
95
}
103
- logger . info ( `matter.js shell controller started for node ${ this . nodeNum } ` ) ;
96
+ logger . info ( `matter.js shell controller started for node ${ this . # nodeNum} ` ) ;
104
97
105
98
if ( this . commissioningController !== undefined ) {
106
99
await this . commissioningController . start ( ) ;
@@ -113,7 +106,7 @@ export class MatterNode {
113
106
} else {
114
107
throw new Error ( "No controller initialized" ) ;
115
108
}
116
- this . started = true ;
109
+ this . # started = true ;
117
110
}
118
111
119
112
async connectAndGetNodes ( nodeIdStr ?: string , connectOptions ?: CommissioningControllerNodeOptions ) {
0 commit comments