Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bin/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ module.exports = {
configs: [
{
type: "enum",
values: ["sockjs", "ws"],
values: ["ws"],
multiple: false,
description:
"Allows to set custom web socket transport to communicate with dev server.",
Expand Down Expand Up @@ -1253,7 +1253,7 @@ module.exports = {
multiple: false,
path: "webSocketServer",
type: "enum",
values: ["sockjs", "ws"],
values: ["ws"],
},
{
description:
Expand All @@ -1276,7 +1276,7 @@ module.exports = {
multiple: false,
path: "webSocketServer.type",
type: "enum",
values: ["sockjs", "ws"],
values: ["ws"],
},
{
description:
Expand Down
46 changes: 0 additions & 46 deletions client-src/clients/SockJSClient.js

This file was deleted.

1 change: 0 additions & 1 deletion client-src/modules/sockjs-client/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion client-src/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import WebSocketClient from "./clients/WebSocketClient.js";
import { log } from "./utils/log.js";

/** @typedef {import("./index.js").EXPECTED_ANY} EXPECTED_ANY */
/** @typedef {import("./clients/SockJSClient")} SockJSClient */
/** @typedef {WebSocketClient} */

// this WebsocketClient is here as a default fallback, in case the client is not injected
/** @type {CommunicationClientConstructor} */
Expand Down
9 changes: 0 additions & 9 deletions client-src/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,4 @@ module.exports = [
),
],
}),
merge(baseForModules, {
entry: path.join(__dirname, "modules/sockjs-client/index.js"),
output: {
filename: "sockjs-client/index.js",
library: "SockJS",
libraryTarget: "umd",
globalObject: "(typeof self !== 'undefined' ? self : this)",
},
}),
];
29 changes: 0 additions & 29 deletions examples/web-socket-server/sockjs/README.md

This file was deleted.

6 changes: 0 additions & 6 deletions examples/web-socket-server/sockjs/app.js

This file was deleted.

13 changes: 0 additions & 13 deletions examples/web-socket-server/sockjs/webpack.config.js

This file was deleted.

4 changes: 0 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,5 @@ module.exports = {
// https://jestjs.io/docs/upgrading-to-jest28#packagejson-exports
// https://github.com/microsoft/accessibility-insights-web/pull/5421#issuecomment-1109168149
//
// FIXME: this uuid moduleNameMapper workaround can be removed after sockjs > uuid@v9 release
// https://github.com/uuidjs/uuid/pull/616#issuecomment-1206283882
// eslint-disable-next-line n/no-extraneous-require
"^uuid$": require.resolve("uuid"),
},
};
108 changes: 15 additions & 93 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,16 @@ const schema = require("./options.json");

/**
* @typedef {object} WebSocketServerConfiguration
* @property {("sockjs" | "ws" | string | (() => WebSocketServerConfiguration))=} type type
* @property {( "ws" | string | (() => WebSocketServerConfiguration))=} type type
* @property {Record<string, EXPECTED_ANY>=} options options
*/

/**
* @typedef {(import("ws").WebSocket | import("sockjs").Connection & { send: import("ws").WebSocket["send"], terminate: import("ws").WebSocket["terminate"], ping: import("ws").WebSocket["ping"] }) & { isAlive?: boolean }} ClientConnection
* @typedef {(import("ws").WebSocket & { send: import("ws").WebSocket["send"], terminate: import("ws").WebSocket["terminate"], ping: import("ws").WebSocket["ping"] }) & { isAlive?: boolean }} ClientConnection
*/

/**
* @typedef {import("ws").WebSocketServer | import("sockjs").Server & { close: import("ws").WebSocketServer["close"] }} WebSocketServer
* @typedef {import("ws").WebSocketServer & { close: import("ws").WebSocketServer["close"] }} WebSocketServer
*/

/**
Expand Down Expand Up @@ -190,7 +190,7 @@ const schema = require("./options.json");
* @property {(boolean | { warnings?: OverlayMessageOptions, errors?: OverlayMessageOptions, runtimeErrors?: OverlayMessageOptions })=} overlay overlay
* @property {boolean=} progress progress
* @property {(boolean | number)=} reconnect reconnect
* @property {("ws" | "sockjs" | string)=} webSocketTransport web socket transport
* @property {("ws" | string)=} webSocketTransport web socket transport
* @property {(string | WebSocketURL)=} webSocketURL web socket URL
*/

Expand Down Expand Up @@ -231,7 +231,7 @@ const schema = require("./options.json");
* @property {(boolean | string | Static | Array<string | Static>)=} static
* @property {(ServerType<A, S> | ServerConfiguration<A, S>)=} server
* @property {(() => Promise<A>)=} app
* @property {(boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration)=} webSocketServer
* @property {(boolean | "ws" | string | WebSocketServerConfiguration)=} webSocketServer
* @property {ProxyConfigArray=} proxy
* @property {(boolean | string | Open | Array<string | Open>)=} open
* @property {boolean=} setupExitSignals
Expand Down Expand Up @@ -674,28 +674,17 @@ class Server {
/** @type {string} */
let hostname;

// SockJS is not supported server mode, so `hostname` and `port` can't specified, let's ignore them
const isSockJSType = webSocketServer.type === "sockjs";
const isWebSocketServerHostDefined =
typeof webSocketServer.options.host !== "undefined";
const isWebSocketServerPortDefined =
typeof webSocketServer.options.port !== "undefined";

if (
isSockJSType &&
(isWebSocketServerHostDefined || isWebSocketServerPortDefined)
) {
this.logger.warn(
"SockJS only supports client mode and does not support custom hostname and port options. Please consider using 'ws' if you need to customize these options.",
);
}

// We are proxying dev server and need to specify custom `hostname`
if (typeof webSocketURL.hostname !== "undefined") {
hostname = webSocketURL.hostname;
}
// Web socket server works on custom `hostname`, only for `ws` because `sock-js` is not support custom `hostname`
else if (isWebSocketServerHostDefined && !isSockJSType) {
else if (isWebSocketServerHostDefined) {
hostname = webSocketServer.options.host;
}
// The `host` option is specified
Expand All @@ -717,7 +706,7 @@ class Server {
port = webSocketURL.port;
}
// Web socket server works on custom `port`, only for `ws` because `sock-js` is not support custom `port`
else if (isWebSocketServerPortDefined && !isSockJSType) {
else if (isWebSocketServerPortDefined) {
port = webSocketServer.options.port;
}
// The `port` option is specified
Expand Down Expand Up @@ -1560,9 +1549,7 @@ class Server {
(this.options.webSocketServer).type
) === "string" &&
// @ts-expect-error
(this.options.webSocketServer.type === "ws" ||
/** @type {WebSocketServerConfiguration} */
(this.options.webSocketServer).type === "sockjs");
this.options.webSocketServer.type === "ws";

let clientTransport;

Expand All @@ -1589,12 +1576,8 @@ class Server {

switch (typeof clientTransport) {
case "string":
// could be 'sockjs', 'ws', or a path that should be required
if (clientTransport === "sockjs") {
clientImplementation = require.resolve(
"../client/clients/SockJSClient",
);
} else if (clientTransport === "ws") {
// could be 'ws', or a path that should be required
if (clientTransport === "ws") {
clientImplementation = require.resolve(
"../client/clients/WebSocketClient",
);
Expand All @@ -1616,7 +1599,7 @@ class Server {
!isKnownWebSocketServerImplementation
? "When you use custom web socket implementation you must explicitly specify client.webSocketTransport. "
: ""
}client.webSocketTransport must be a string denoting a default implementation (e.g. 'sockjs', 'ws') or a full path to a JS file via require.resolve(...) which exports a class `,
}client.webSocketTransport must be a string denoting a default implementation (e.g. 'ws') or a full path to a JS file via require.resolve(...) which exports a class `,
);
}

Expand All @@ -1639,14 +1622,8 @@ class Server {
)
) {
case "string":
// Could be 'sockjs', in the future 'ws', or a path that should be required
// Could be 'ws', or a path that should be required
if (
/** @type {WebSocketServerConfiguration} */ (
this.options.webSocketServer
).type === "sockjs"
) {
implementation = require("./servers/SockJSServer");
} else if (
/** @type {WebSocketServerConfiguration} */ (
this.options.webSocketServer
).type === "ws"
Expand Down Expand Up @@ -1674,7 +1651,7 @@ class Server {

if (!implementationFound) {
throw new Error(
"webSocketServer (webSocketServer.type) must be a string denoting a default implementation (e.g. 'ws', 'sockjs'), a full path to " +
"webSocketServer (webSocketServer.type) must be a string denoting a default implementation (e.g. 'ws'), a full path to " +
"a JS file which exports a class extending BaseServer (webpack-dev-server/lib/servers/BaseServer.js) " +
"via require.resolve(...), or the class itself which extends BaseServer",
);
Expand Down Expand Up @@ -2065,56 +2042,6 @@ class Server {
middleware: /** @type {MiddlewareHandler} */ (this.middleware),
});

// Should be after `webpack-dev-middleware`, otherwise other middlewares might rewrite response
middlewares.push({
name: "webpack-dev-server-sockjs-bundle",
path: "/__webpack_dev_server__/sockjs.bundle.js",
/**
* @param {Request} req request
* @param {Response} res response
* @param {NextFunction} next next function
* @returns {void}
*/
middleware: (req, res, next) => {
if (req.method !== "GET" && req.method !== "HEAD") {
next();
return;
}

const clientPath = path.join(
__dirname,
"..",
"client/modules/sockjs-client/index.js",
);

// Express send Etag and other headers by default, so let's keep them for compatibility reasons
if (typeof res.sendFile === "function") {
res.sendFile(clientPath);
return;
}

let stats;

try {
// TODO implement `inputFileSystem.createReadStream` in webpack
stats = fs.statSync(clientPath);
} catch {
next();
return;
}

res.setHeader("Content-Type", "application/javascript; charset=UTF-8");
res.setHeader("Content-Length", stats.size);

if (req.method === "HEAD") {
res.end();
return;
}

fs.createReadStream(clientPath).pipe(res);
},
});

middlewares.push({
name: "webpack-dev-server-invalidate",
path: "/webpack-dev-server/invalidate",
Expand Down Expand Up @@ -2677,11 +2604,7 @@ class Server {
typeof request !== "undefined"
? /** @type {{ [key: string]: string | undefined }} */
(request.headers)
: typeof (
/** @type {import("sockjs").Connection} */ (client).headers
) !== "undefined"
? /** @type {import("sockjs").Connection} */ (client).headers
: undefined;
: undefined;

if (!headers) {
this.logger.warn(
Expand Down Expand Up @@ -3315,8 +3238,7 @@ class Server {
*/
sendMessage(clients, type, data, params) {
for (const client of clients) {
// `sockjs` uses `1` to indicate client is ready to accept data
// `ws` uses `WebSocket.OPEN`, but it is mean `1` too
// `ws` uses `WebSocket.OPEN`, which is `1`
if (client.readyState === 1) {
client.send(JSON.stringify({ type, data, params }));
}
Expand Down
Loading
Loading