Skip to content

Commit 168d893

Browse files
refactor: rename properties
1 parent 68e2f06 commit 168d893

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.close(connection);
499+
this.webSocketServer.close(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,11 +749,11 @@ class Server {
748749
}
749750

750751
close(cb) {
751-
this.sockets.forEach((socket) => {
752-
this.socketServer.close(socket);
752+
this.webSocketConnections.forEach((socket) => {
753+
this.webSocketServer.close(socket);
753754
});
754755

755-
this.sockets = [];
756+
this.webSocketConnections = [];
756757

757758
const prom = Promise.all(
758759
this.staticWatchers.map((watcher) => watcher.close())
@@ -929,9 +930,12 @@ class Server {
929930
return false;
930931
}
931932

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

@@ -959,7 +963,7 @@ class Server {
959963
}
960964

961965
// Send stats to a socket or multiple sockets
962-
sendStats(sockets, stats, force) {
966+
sendStats(webSocketConnections, stats, force) {
963967
const shouldEmit =
964968
!force &&
965969
stats &&
@@ -969,19 +973,19 @@ class Server {
969973
stats.assets.every((asset) => !asset.emitted);
970974

971975
if (shouldEmit) {
972-
this.sendMessage(sockets, 'still-ok');
976+
this.sendMessage(webSocketConnections, 'still-ok');
973977

974978
return;
975979
}
976980

977-
this.sendMessage(sockets, 'hash', stats.hash);
981+
this.sendMessage(webSocketConnections, 'hash', stats.hash);
978982

979983
if (stats.errors.length > 0) {
980-
this.sendMessage(sockets, 'errors', stats.errors);
984+
this.sendMessage(webSocketConnections, 'errors', stats.errors);
981985
} else if (stats.warnings.length > 0) {
982-
this.sendMessage(sockets, 'warnings', stats.warnings);
986+
this.sendMessage(webSocketConnections, 'warnings', stats.warnings);
983987
} else {
984-
this.sendMessage(sockets, 'ok');
988+
this.sendMessage(webSocketConnections, 'ok');
985989
}
986990
}
987991

@@ -1022,7 +1026,11 @@ class Server {
10221026
// disabling refreshing on changing the content
10231027
if (this.options.liveReload) {
10241028
watcher.on('change', () => {
1025-
this.sendMessage(this.sockets, 'static-changed', watchPath);
1029+
this.sendMessage(
1030+
this.webSocketConnections,
1031+
'static-changed',
1032+
watchPath
1033+
);
10261034
});
10271035
}
10281036

0 commit comments

Comments
 (0)