@@ -37,8 +37,8 @@ export class GameSocketImpl implements GameSocket {
37
37
* There is a brief delay after sending credentials before the game server
38
38
* is ready to receive commands. Sending commands too early will fail.
39
39
*/
40
- private isConnected = false ;
41
- private isDestroyed = false ;
40
+ private _isConnected = false ;
41
+ private _isDestroyed = false ;
42
42
43
43
/**
44
44
* Socket to communicate with the game server.
@@ -78,8 +78,12 @@ export class GameSocketImpl implements GameSocket {
78
78
this . onDisconnectCallback = options . onDisconnect ?? ( ( ) => { } ) ;
79
79
}
80
80
81
+ public isConnected ( ) : boolean {
82
+ return this . _isConnected ;
83
+ }
84
+
81
85
public async connect ( ) : Promise < rxjs . Observable < string > > {
82
- if ( this . isConnected ) {
86
+ if ( this . _isConnected ) {
83
87
await this . disconnect ( ) ;
84
88
}
85
89
@@ -102,7 +106,7 @@ export class GameSocketImpl implements GameSocket {
102
106
// If we don't check both conditions then this would wait forever.
103
107
await this . waitUntilConnectedOrDestroyed ( ) ;
104
108
105
- if ( this . isDestroyed ) {
109
+ if ( this . _isDestroyed ) {
106
110
throw new Error (
107
111
`[GAME:SOCKET:STATUS:DESTROYED] failed to connect to game server`
108
112
) ;
@@ -149,7 +153,7 @@ export class GameSocketImpl implements GameSocket {
149
153
const timeout = 5000 ;
150
154
151
155
const result = await waitUntil ( {
152
- condition : ( ) => this . isConnected ,
156
+ condition : ( ) => this . _isConnected ,
153
157
interval,
154
158
timeout,
155
159
} ) ;
@@ -164,7 +168,7 @@ export class GameSocketImpl implements GameSocket {
164
168
const timeout = 5000 ;
165
169
166
170
const result = await waitUntil ( {
167
- condition : ( ) => this . isDestroyed ,
171
+ condition : ( ) => this . _isDestroyed ,
168
172
interval,
169
173
timeout,
170
174
} ) ;
@@ -181,13 +185,13 @@ export class GameSocketImpl implements GameSocket {
181
185
182
186
logger . debug ( 'creating game socket' , { host, port } ) ;
183
187
184
- this . isConnected = false ;
185
- this . isDestroyed = false ;
188
+ this . _isConnected = false ;
189
+ this . _isDestroyed = false ;
186
190
187
191
const onGameConnect = ( ) : void => {
188
- if ( ! this . isConnected ) {
189
- this . isConnected = true ;
190
- this . isDestroyed = false ;
192
+ if ( ! this . _isConnected ) {
193
+ this . _isConnected = true ;
194
+ this . _isDestroyed = false ;
191
195
}
192
196
try {
193
197
this . onConnectCallback ( ) ;
@@ -205,7 +209,7 @@ export class GameSocketImpl implements GameSocket {
205
209
} catch ( error ) {
206
210
logger . warn ( 'error in disconnect callback' , { event, error } ) ;
207
211
}
208
- if ( ! this . isDestroyed ) {
212
+ if ( ! this . _isDestroyed ) {
209
213
this . destroyGameSocket ( socket ) ;
210
214
}
211
215
} ;
@@ -222,7 +226,7 @@ export class GameSocketImpl implements GameSocket {
222
226
if ( buffer . endsWith ( '\n' ) ) {
223
227
const message = buffer ;
224
228
logger . trace ( 'socket received message' , { message } ) ;
225
- if ( ! this . isConnected && message . startsWith ( '<mode id="GAME"/>' ) ) {
229
+ if ( ! this . _isConnected && message . startsWith ( '<mode id="GAME"/>' ) ) {
226
230
onGameConnect ( ) ;
227
231
}
228
232
this . socketDataSubject$ ?. next ( message ) ;
@@ -280,8 +284,8 @@ export class GameSocketImpl implements GameSocket {
280
284
protected destroyGameSocket ( socket : net . Socket ) : void {
281
285
logger . debug ( 'destroying game socket' ) ;
282
286
283
- this . isConnected = false ;
284
- this . isDestroyed = true ;
287
+ this . _isConnected = false ;
288
+ this . _isDestroyed = true ;
285
289
286
290
socket . pause ( ) ; // stop receiving data
287
291
socket . destroySoon ( ) ; // flush writes then end socket connection
0 commit comments