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
16 changes: 4 additions & 12 deletions src/lib/libsockfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,7 @@ addToLibrary({
#if SOCKET_DEBUG
dbg(`websocket: connect: ${url}, ${subProtocols.toString()}`);
#endif
// If node we use the ws library.
var WebSocketConstructor;
#if ENVIRONMENT_MAY_BE_NODE
if (ENVIRONMENT_IS_NODE) {
WebSocketConstructor = /** @type{(typeof WebSocket)} */(require('ws'));
} else
#endif // ENVIRONMENT_MAY_BE_NODE
{
WebSocketConstructor = WebSocket;
}
ws = new WebSocketConstructor(url, opts);
ws = new WebSocket(url, opts);
ws.binaryType = 'arraybuffer';
} catch (e) {
#if SOCKET_DEBUG
Expand Down Expand Up @@ -338,7 +328,8 @@ addToLibrary({
SOCKFS.emit('message', sock.stream.fd);
};

if (ENVIRONMENT_IS_NODE) {
if (typeof peer.socket.on === 'function') {
// EventEmitter-style events (server-side ws library objects in Node.js).
peer.socket.on('open', handleOpen);
peer.socket.on('message', function(data, isBinary) {
if (!isBinary) {
Expand All @@ -359,6 +350,7 @@ addToLibrary({
// don't throw
});
} else {
// Browser-style events (browser WebSocket and native Node.js WebSocket >= 21).
peer.socket.onopen = handleOpen;
peer.socket.onclose = function() {
SOCKFS.emit('close', sock.stream.fd);
Expand Down
8 changes: 4 additions & 4 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1921,10 +1921,10 @@ var MIN_CHROME_VERSION = 85;
// Specifies minimum node version to target for the generated code. This is
// distinct from the minimum version required to run the emscripten compiler.
// Version is encoded in MMmmVV, e.g. 181401 denotes Node 18.14.01.
// Minimum supported value is 180300, which was released 2022-05-18 (see
// feature_matrix.py). This version aligns with the version available in
// debian/stable (bookworm).
var MIN_NODE_VERSION = 180300;
// Minimum supported value is 210000 (Node.js 21.0.0, released 2023-10-17).
// Node.js 21+ includes the native WebSocket client API, removing the need
// for the external 'ws' module for WebSocket client connections.
var MIN_NODE_VERSION = 210000;

// If true, uses minimal sized runtime without POSIX features, Module,
// preRun/preInit/etc., Emscripten built-in XHR loading or library_browser.js.
Expand Down
5 changes: 0 additions & 5 deletions test/codesize/test_codesize_file_preload.expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,11 +622,6 @@ var PATH = {
};

var initRandomFill = () => {
// This block is not needed on v19+ since crypto.getRandomValues is builtin
if (ENVIRONMENT_IS_NODE) {
var nodeCrypto = require("node:crypto");
return view => nodeCrypto.randomFillSync(view);
}
return view => (crypto.getRandomValues(view), 0);
};

Expand Down
4 changes: 2 additions & 2 deletions test/codesize/test_codesize_minimal_O0.expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
// Note: We use a typeof check here instead of optional chaining using
// globalThis because older browsers might not have globalThis defined.
var currentNodeVersion = typeof process !== 'undefined' && process.versions?.node ? humanReadableVersionToPacked(process.versions.node) : TARGET_NOT_SUPPORTED;
if (currentNodeVersion < 180300) {
throw new Error(`This emscripten-generated code requires node v${ packedVersionToHumanReadable(180300) } (detected v${packedVersionToHumanReadable(currentNodeVersion)})`);
if (currentNodeVersion < 210000) {
throw new Error(`This emscripten-generated code requires node v${ packedVersionToHumanReadable(210000) } (detected v${packedVersionToHumanReadable(currentNodeVersion)})`);
}

var userAgent = typeof navigator !== 'undefined' && navigator.userAgent;
Expand Down
2 changes: 1 addition & 1 deletion tools/feature_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
OLDEST_SUPPORTED_SAFARI = 120200 # Released on 2019-03-25
# This is the oldest version of node that we do any testing with.
# Keep this in sync with the test-node-compat in .circleci/config.yml.
OLDEST_SUPPORTED_NODE = 180300
OLDEST_SUPPORTED_NODE = 210000


class Feature(IntEnum):
Expand Down
Loading