@@ -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 . closeConnection ( connection ) ;
499
+ this . webSocketServer . closeConnection ( 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,9 +749,9 @@ class Server {
748
749
}
749
750
750
751
close ( callback ) {
751
- if ( this . socketServer ) {
752
- this . socketServer . close ( ) ;
753
- this . sockets = [ ] ;
752
+ if ( this . webSocketServer ) {
753
+ this . webSocketServer . close ( ) ;
754
+ this . webSocketConnections = [ ] ;
754
755
}
755
756
756
757
const prom = Promise . all (
@@ -928,9 +929,12 @@ class Server {
928
929
return false ;
929
930
}
930
931
931
- sendMessage ( sockets , type , data ) {
932
- sockets . forEach ( ( socket ) => {
933
- this . socketServer . send ( socket , JSON . stringify ( { type, data } ) ) ;
932
+ sendMessage ( webSocketConnections , type , data ) {
933
+ webSocketConnections . forEach ( ( webSocketConnection ) => {
934
+ this . webSocketServer . send (
935
+ webSocketConnection ,
936
+ JSON . stringify ( { type, data } )
937
+ ) ;
934
938
} ) ;
935
939
}
936
940
@@ -960,7 +964,7 @@ class Server {
960
964
}
961
965
962
966
// Send stats to a socket or multiple sockets
963
- sendStats ( sockets , stats , force ) {
967
+ sendStats ( webSocketConnections , stats , force ) {
964
968
const shouldEmit =
965
969
! force &&
966
970
stats &&
@@ -970,23 +974,23 @@ class Server {
970
974
stats . assets . every ( ( asset ) => ! asset . emitted ) ;
971
975
972
976
if ( shouldEmit ) {
973
- this . sendMessage ( sockets , 'still-ok' ) ;
977
+ this . sendMessage ( webSocketConnections , 'still-ok' ) ;
974
978
975
979
return ;
976
980
}
977
981
978
- this . sendMessage ( sockets , 'hash' , stats . hash ) ;
982
+ this . sendMessage ( webSocketConnections , 'hash' , stats . hash ) ;
979
983
980
984
if ( stats . errors . length > 0 || stats . warnings . length > 0 ) {
981
985
if ( stats . errors . length > 0 ) {
982
- this . sendMessage ( sockets , 'errors' , stats . errors ) ;
986
+ this . sendMessage ( webSocketConnections , 'errors' , stats . errors ) ;
983
987
}
984
988
985
989
if ( stats . warnings . length > 0 ) {
986
- this . sendMessage ( sockets , 'warnings' , stats . warnings ) ;
990
+ this . sendMessage ( webSocketConnections , 'warnings' , stats . warnings ) ;
987
991
}
988
992
} else {
989
- this . sendMessage ( sockets , 'ok' ) ;
993
+ this . sendMessage ( webSocketConnections , 'ok' ) ;
990
994
}
991
995
}
992
996
@@ -1027,7 +1031,11 @@ class Server {
1027
1031
// disabling refreshing on changing the content
1028
1032
if ( this . options . liveReload ) {
1029
1033
watcher . on ( 'change' , ( item ) => {
1030
- this . sendMessage ( this . sockets , 'static-changed' , item ) ;
1034
+ this . sendMessage (
1035
+ this . webSocketConnections ,
1036
+ 'static-changed' ,
1037
+ item
1038
+ ) ;
1031
1039
} ) ;
1032
1040
}
1033
1041
0 commit comments