Skip to content

Commit 1993769

Browse files
refactor: rename properties
1 parent 17aa345 commit 1993769

File tree

1 file changed

+33
-25
lines changed

1 file changed

+33
-25
lines changed

lib/Server.js

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Server {
3232
this.compiler = compiler;
3333
this.options = options;
3434
this.logger = this.compiler.getInfrastructureLogger('webpack-dev-server');
35-
this.sockets = [];
35+
this.webSocketConnections = [];
3636
this.staticWatchers = [];
3737
// Keep track of websocket proxies for external websocket upgrade.
3838
this.webSocketProxies = [];
@@ -43,7 +43,7 @@ class Server {
4343

4444
this.applyDevServerPlugin();
4545

46-
this.SocketServerImplementation = getSocketServerImplementation(
46+
this.webSocketServerImplementation = getSocketServerImplementation(
4747
this.options
4848
);
4949

@@ -99,7 +99,7 @@ class Server {
9999
msg = `${msg} (${addInfo})`;
100100
}
101101

102-
this.sendMessage(this.sockets, 'progress-update', {
102+
this.sendMessage(this.webSocketConnections, 'progress-update', {
103103
percent,
104104
msg,
105105
pluginName,
@@ -120,7 +120,7 @@ class Server {
120120
setupHooks() {
121121
// Listening for events
122122
const invalidPlugin = () => {
123-
this.sendMessage(this.sockets, 'invalid');
123+
this.sendMessage(this.webSocketConnections, 'invalid');
124124
};
125125

126126
const addHooks = (compiler) => {
@@ -129,7 +129,7 @@ class Server {
129129
compile.tap('webpack-dev-server', invalidPlugin);
130130
invalid.tap('webpack-dev-server', invalidPlugin);
131131
done.tap('webpack-dev-server', (stats) => {
132-
this.sendStats(this.sockets, this.getStats(stats));
132+
this.sendStats(this.webSocketConnections, this.getStats(stats));
133133
this.stats = stats;
134134
});
135135
};
@@ -474,9 +474,10 @@ class Server {
474474
}
475475

476476
createWebSocketServer() {
477-
this.socketServer = new this.SocketServerImplementation(this);
477+
// eslint-disable-next-line new-cap
478+
this.webSocketServer = new this.webSocketServerImplementation(this);
478479

479-
this.socketServer.onConnection((connection, headers) => {
480+
this.webSocketServer.onConnection((connection, headers) => {
480481
if (!connection) {
481482
return;
482483
}
@@ -495,18 +496,18 @@ class Server {
495496
) {
496497
this.sendMessage([connection], 'error', 'Invalid Host/Origin header');
497498

498-
this.socketServer.closeConnection(connection);
499+
this.webSocketServer.closeConnection(connection);
499500

500501
return;
501502
}
502503

503-
this.sockets.push(connection);
504+
this.webSocketConnections.push(connection);
504505

505-
this.socketServer.onConnectionClose(connection, () => {
506-
const idx = this.sockets.indexOf(connection);
506+
this.webSocketServer.onConnectionClose(connection, () => {
507+
const idx = this.webSocketConnections.indexOf(connection);
507508

508509
if (idx >= 0) {
509-
this.sockets.splice(idx, 1);
510+
this.webSocketConnections.splice(idx, 1);
510511
}
511512
});
512513

@@ -748,9 +749,9 @@ class Server {
748749
}
749750

750751
close(callback) {
751-
if (this.socketServer) {
752-
this.socketServer.close();
753-
this.sockets = [];
752+
if (this.webSocketServer) {
753+
this.webSocketServer.close();
754+
this.webSocketConnections = [];
754755
}
755756

756757
const prom = Promise.all(
@@ -928,9 +929,12 @@ class Server {
928929
return false;
929930
}
930931

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+
);
934938
});
935939
}
936940

@@ -960,7 +964,7 @@ class Server {
960964
}
961965

962966
// Send stats to a socket or multiple sockets
963-
sendStats(sockets, stats, force) {
967+
sendStats(webSocketConnections, stats, force) {
964968
const shouldEmit =
965969
!force &&
966970
stats &&
@@ -970,23 +974,23 @@ class Server {
970974
stats.assets.every((asset) => !asset.emitted);
971975

972976
if (shouldEmit) {
973-
this.sendMessage(sockets, 'still-ok');
977+
this.sendMessage(webSocketConnections, 'still-ok');
974978

975979
return;
976980
}
977981

978-
this.sendMessage(sockets, 'hash', stats.hash);
982+
this.sendMessage(webSocketConnections, 'hash', stats.hash);
979983

980984
if (stats.errors.length > 0 || stats.warnings.length > 0) {
981985
if (stats.errors.length > 0) {
982-
this.sendMessage(sockets, 'errors', stats.errors);
986+
this.sendMessage(webSocketConnections, 'errors', stats.errors);
983987
}
984988

985989
if (stats.warnings.length > 0) {
986-
this.sendMessage(sockets, 'warnings', stats.warnings);
990+
this.sendMessage(webSocketConnections, 'warnings', stats.warnings);
987991
}
988992
} else {
989-
this.sendMessage(sockets, 'ok');
993+
this.sendMessage(webSocketConnections, 'ok');
990994
}
991995
}
992996

@@ -1027,7 +1031,11 @@ class Server {
10271031
// disabling refreshing on changing the content
10281032
if (this.options.liveReload) {
10291033
watcher.on('change', (item) => {
1030-
this.sendMessage(this.sockets, 'static-changed', item);
1034+
this.sendMessage(
1035+
this.webSocketConnections,
1036+
'static-changed',
1037+
item
1038+
);
10311039
});
10321040
}
10331041

0 commit comments

Comments
 (0)