@@ -32,7 +32,7 @@ class Server {
32
32
this . compiler = compiler ;
33
33
this . options = options ;
34
34
this . logger = this . compiler . getInfrastructureLogger ( 'webpack-dev-server' ) ;
35
- this . sockets = [ ] ;
35
+ this . webSocketConnections = [ ] ;
36
36
this . staticWatchers = [ ] ;
37
37
// Keep track of websocket proxies for external websocket upgrade.
38
38
this . webSocketProxies = [ ] ;
@@ -43,7 +43,7 @@ class Server {
43
43
44
44
this . applyDevServerPlugin ( ) ;
45
45
46
- this . SocketServerImplementation = getSocketServerImplementation (
46
+ this . webSocketServerImplementation = getSocketServerImplementation (
47
47
this . options
48
48
) ;
49
49
@@ -99,7 +99,7 @@ class Server {
99
99
msg = `${ msg } (${ addInfo } )` ;
100
100
}
101
101
102
- this . sendMessage ( this . sockets , 'progress-update' , {
102
+ this . sendMessage ( this . webSocketConnections , 'progress-update' , {
103
103
percent,
104
104
msg,
105
105
pluginName,
@@ -120,7 +120,7 @@ class Server {
120
120
setupHooks ( ) {
121
121
// Listening for events
122
122
const invalidPlugin = ( ) => {
123
- this . sendMessage ( this . sockets , 'invalid' ) ;
123
+ this . sendMessage ( this . webSocketConnections , 'invalid' ) ;
124
124
} ;
125
125
126
126
const addHooks = ( compiler ) => {
@@ -129,7 +129,7 @@ class Server {
129
129
compile . tap ( 'webpack-dev-server' , invalidPlugin ) ;
130
130
invalid . tap ( 'webpack-dev-server' , invalidPlugin ) ;
131
131
done . tap ( 'webpack-dev-server' , ( stats ) => {
132
- this . sendStats ( this . sockets , this . getStats ( stats ) ) ;
132
+ this . sendStats ( this . webSocketConnections , this . getStats ( stats ) ) ;
133
133
this . stats = stats ;
134
134
} ) ;
135
135
} ;
@@ -474,9 +474,10 @@ class Server {
474
474
}
475
475
476
476
createWebSocketServer ( ) {
477
- this . socketServer = new this . SocketServerImplementation ( this ) ;
477
+ // eslint-disable-next-line new-cap
478
+ this . webSocketServer = new this . webSocketServerImplementation ( this ) ;
478
479
479
- this . socketServer . onConnection ( ( connection , headers ) => {
480
+ this . webSocketServer . onConnection ( ( connection , headers ) => {
480
481
if ( ! connection ) {
481
482
return ;
482
483
}
@@ -495,18 +496,18 @@ class Server {
495
496
) {
496
497
this . sendMessage ( [ connection ] , 'error' , 'Invalid Host/Origin header' ) ;
497
498
498
- this . socketServer . close ( connection ) ;
499
+ this . webSocketServer . close ( connection ) ;
499
500
500
501
return ;
501
502
}
502
503
503
- this . sockets . push ( connection ) ;
504
+ this . webSocketConnections . push ( connection ) ;
504
505
505
- this . socketServer . onConnectionClose ( connection , ( ) => {
506
- const idx = this . sockets . indexOf ( connection ) ;
506
+ this . webSocketServer . onConnectionClose ( connection , ( ) => {
507
+ const idx = this . webSocketConnections . indexOf ( connection ) ;
507
508
508
509
if ( idx >= 0 ) {
509
- this . sockets . splice ( idx , 1 ) ;
510
+ this . webSocketConnections . splice ( idx , 1 ) ;
510
511
}
511
512
} ) ;
512
513
@@ -748,11 +749,11 @@ class Server {
748
749
}
749
750
750
751
close ( cb ) {
751
- this . sockets . forEach ( ( socket ) => {
752
- this . socketServer . close ( socket ) ;
752
+ this . webSocketConnections . forEach ( ( socket ) => {
753
+ this . webSocketServer . close ( socket ) ;
753
754
} ) ;
754
755
755
- this . sockets = [ ] ;
756
+ this . webSocketConnections = [ ] ;
756
757
757
758
const prom = Promise . all (
758
759
this . staticWatchers . map ( ( watcher ) => watcher . close ( ) )
@@ -929,9 +930,12 @@ class Server {
929
930
return false ;
930
931
}
931
932
932
- sendMessage ( sockets , type , data ) {
933
- sockets . forEach ( ( socket ) => {
934
- this . socketServer . send ( socket , JSON . stringify ( { type, data } ) ) ;
933
+ sendMessage ( webSocketConnections , type , data ) {
934
+ webSocketConnections . forEach ( ( webSocketConnection ) => {
935
+ this . webSocketServer . send (
936
+ webSocketConnection ,
937
+ JSON . stringify ( { type, data } )
938
+ ) ;
935
939
} ) ;
936
940
}
937
941
@@ -959,7 +963,7 @@ class Server {
959
963
}
960
964
961
965
// Send stats to a socket or multiple sockets
962
- sendStats ( sockets , stats , force ) {
966
+ sendStats ( webSocketConnections , stats , force ) {
963
967
const shouldEmit =
964
968
! force &&
965
969
stats &&
@@ -969,19 +973,19 @@ class Server {
969
973
stats . assets . every ( ( asset ) => ! asset . emitted ) ;
970
974
971
975
if ( shouldEmit ) {
972
- this . sendMessage ( sockets , 'still-ok' ) ;
976
+ this . sendMessage ( webSocketConnections , 'still-ok' ) ;
973
977
974
978
return ;
975
979
}
976
980
977
- this . sendMessage ( sockets , 'hash' , stats . hash ) ;
981
+ this . sendMessage ( webSocketConnections , 'hash' , stats . hash ) ;
978
982
979
983
if ( stats . errors . length > 0 ) {
980
- this . sendMessage ( sockets , 'errors' , stats . errors ) ;
984
+ this . sendMessage ( webSocketConnections , 'errors' , stats . errors ) ;
981
985
} else if ( stats . warnings . length > 0 ) {
982
- this . sendMessage ( sockets , 'warnings' , stats . warnings ) ;
986
+ this . sendMessage ( webSocketConnections , 'warnings' , stats . warnings ) ;
983
987
} else {
984
- this . sendMessage ( sockets , 'ok' ) ;
988
+ this . sendMessage ( webSocketConnections , 'ok' ) ;
985
989
}
986
990
}
987
991
@@ -1022,7 +1026,11 @@ class Server {
1022
1026
// disabling refreshing on changing the content
1023
1027
if ( this . options . liveReload ) {
1024
1028
watcher . on ( 'change' , ( ) => {
1025
- this . sendMessage ( this . sockets , 'static-changed' , watchPath ) ;
1029
+ this . sendMessage (
1030
+ this . webSocketConnections ,
1031
+ 'static-changed' ,
1032
+ watchPath
1033
+ ) ;
1026
1034
} ) ;
1027
1035
}
1028
1036
0 commit comments