2
2
import { Server , Socket } from 'socket.io' ;
3
3
import * as http from 'http' ;
4
4
import chalk from 'chalk' ;
5
- import { WS_EVENTS } from './utils' ;
5
+ import { WS_EVENTS , isElectron } from './utils' ;
6
6
7
7
export let io : Server ;
8
8
export let clients = new Map < string , Socket > ( ) ;
@@ -19,23 +19,31 @@ export function initWebSocket(server: http.Server) {
19
19
// register client
20
20
socket . on ( WS_EVENTS . REGISTER , ( clientId : string ) => {
21
21
clients . set ( clientId , socket ) ;
22
- console . info ( chalk . green ( `ws client connected ${ clientId } ` ) ) ;
22
+ if ( ! isElectron ( ) ) {
23
+ console . info ( chalk . green ( `ws client connected ${ clientId } ` ) ) ;
24
+ }
23
25
24
26
socket . on ( 'disconnect' , ( ) => {
25
- console . info ( chalk . green ( `ws client disconnected ${ clientId } ` ) ) ;
27
+ if ( ! isElectron ( ) ) {
28
+ console . info ( chalk . green ( `ws client disconnected ${ clientId } ` ) ) ;
29
+ }
26
30
clients . delete ( clientId ) ;
27
31
} ) ;
28
32
29
33
socket . on ( 'error' , ( error : Error ) => {
30
- console . error (
31
- chalk . red ( `ws client error ${ clientId } : ${ error . message } ` )
32
- ) ;
34
+ if ( ! isElectron ( ) ) {
35
+ console . error (
36
+ chalk . red ( `ws client error ${ clientId } : ${ error . message } ` )
37
+ ) ;
38
+ }
33
39
} ) ;
34
40
} ) ;
35
41
} ) ;
36
42
37
43
// Handle server-level errors
38
44
io . on ( 'error' , ( error : Error ) => {
39
- console . error ( chalk . red ( `ws server error: ${ error . message } ` ) ) ;
45
+ if ( ! isElectron ( ) ) {
46
+ console . error ( chalk . red ( `ws server error: ${ error . message } ` ) ) ;
47
+ }
40
48
} ) ;
41
49
}
0 commit comments