From 95fddac66bffa2585fd0d23a13a2de62fbb5b793 Mon Sep 17 00:00:00 2001 From: raymondtri Date: Wed, 26 Feb 2025 08:48:22 -0500 Subject: [PATCH 1/2] added is_testing env variable so that requires work better with auto bundlers like vite --- index.js | 43 ++++++++++++++++++++++++++++++------------- test/auth.js | 2 ++ test/callback.js | 2 ++ test/input.js | 2 ++ test/matchmaking.js | 2 ++ test/networking.js | 3 +++ test/overlay.js | 2 ++ test/user.js | 2 ++ test/workshop.js | 2 ++ 9 files changed, 47 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index bc9e54d..2b93cb6 100644 --- a/index.js +++ b/index.js @@ -3,32 +3,49 @@ const { platform, arch } = process /** @typedef {typeof import('./client.d')} Client */ /** @type {Client} */ let nativeBinding = undefined - -if (platform === 'win32' && arch === 'x64') { - nativeBinding = require('./dist/win64/steamworksjs.win32-x64-msvc.node') -} else if (platform === 'linux' && arch === 'x64') { - nativeBinding = require('./dist/linux64/steamworksjs.linux-x64-gnu.node') -} else if (platform === 'darwin') { - if (arch === 'x64') { - nativeBinding = require('./dist/osx/steamworksjs.darwin-x64.node') - } else if (arch === 'arm64') { - nativeBinding = require('./dist/osx/steamworksjs.darwin-arm64.node') +if(process.env.IS_TESTING){ + if (platform === 'win32' && arch === 'x64') { + nativeBinding = require('./dist/win64/steamworksjs.win32-x64-msvc.node') + } else if (platform === 'linux' && arch === 'x64') { + nativeBinding = require('./dist/linux64/steamworksjs.linux-x64-gnu.node') + } else if (platform === 'darwin') { + if (arch === 'x64') { + nativeBinding = require('./dist/osx/steamworksjs.darwin-x64.node') + } else if (arch === 'arm64') { + nativeBinding = require('./dist/osx/steamworksjs.darwin-arm64.node') + } + } else { + throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`) } } else { - throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`) + if (platform === 'win32' && arch === 'x64') { + nativeBinding = require('steamworks.js/dist/win64/steamworksjs.win32-x64-msvc.node') + } else if (platform === 'linux' && arch === 'x64') { + nativeBinding = require('steamworks.js/dist/linux64/steamworksjs.linux-x64-gnu.node') + } else if (platform === 'darwin') { + if (arch === 'x64') { + nativeBinding = require('steamworks.js/dist/osx/steamworksjs.darwin-x64.node') + } else if (arch === 'arm64') { + nativeBinding = require('steamworks.js/dist/osx/steamworksjs.darwin-arm64.node') + } + } else { + throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`) + } } + let runCallbacksInterval = undefined /** * Initialize the steam client or throw an error if it fails * @param {number} [appId] - App ID of the game to load, if undefined, will search for a steam_appid.txt file + * @param {boolean} [networking] - Enable networking * @returns {Omit} */ -module.exports.init = (appId) => { +module.exports.init = (appId, networking) => { const { init: internalInit, runCallbacks, restartAppIfNecessary, ...api } = nativeBinding - internalInit(appId) + internalInit(appId, networking) clearInterval(runCallbacksInterval) runCallbacksInterval = setInterval(runCallbacks, 1000 / 30) diff --git a/test/auth.js b/test/auth.js index 5375e64..4577067 100644 --- a/test/auth.js +++ b/test/auth.js @@ -1,3 +1,5 @@ +process.env.IS_TESTING = true + const { init } = require('../index.js') const client = init(480) diff --git a/test/callback.js b/test/callback.js index e12acfd..098cbae 100644 --- a/test/callback.js +++ b/test/callback.js @@ -1,3 +1,5 @@ +process.env.IS_TESTING = true + const { init, SteamCallback } = require('../index.js') const client = init(480); diff --git a/test/input.js b/test/input.js index d168666..96d9b84 100644 --- a/test/input.js +++ b/test/input.js @@ -1,3 +1,5 @@ +process.env.IS_TESTING = true + const { init } = require('../index.js') const client = init(1694450) diff --git a/test/matchmaking.js b/test/matchmaking.js index c40b09a..4129222 100644 --- a/test/matchmaking.js +++ b/test/matchmaking.js @@ -1,3 +1,5 @@ +process.env.IS_TESTING = true + const { init, SteamCallback } = require('../index.js') const client = init(480) diff --git a/test/networking.js b/test/networking.js index abee2d3..4004a1b 100644 --- a/test/networking.js +++ b/test/networking.js @@ -1,4 +1,7 @@ const rl = require('readline'); + +process.env.IS_TESTING = true + const { init, SteamCallback } = require('../index.js') const client = init(480) diff --git a/test/overlay.js b/test/overlay.js index 7b30e50..80a5e74 100644 --- a/test/overlay.js +++ b/test/overlay.js @@ -1,3 +1,5 @@ +process.env.IS_TESTING = true + const { init } = require('../index.js') const client = init(480) diff --git a/test/user.js b/test/user.js index 450b49d..7f8d12c 100644 --- a/test/user.js +++ b/test/user.js @@ -1,3 +1,5 @@ +process.env.IS_TESTING = true + const { init } = require('../index.js') const client = init(480) diff --git a/test/workshop.js b/test/workshop.js index c6f76c0..bc18a08 100644 --- a/test/workshop.js +++ b/test/workshop.js @@ -1,3 +1,5 @@ +process.env.IS_TESTING = true + const { init } = require('../index.js'); (async () => { From 9d37f19d50ff4c358998969b18842cb30bb46b12 Mon Sep 17 00:00:00 2001 From: Ray Tri Date: Wed, 5 Mar 2025 14:09:27 -0500 Subject: [PATCH 2/2] Update index.js --- index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 2b93cb6..6fcd442 100644 --- a/index.js +++ b/index.js @@ -39,13 +39,12 @@ let runCallbacksInterval = undefined /** * Initialize the steam client or throw an error if it fails * @param {number} [appId] - App ID of the game to load, if undefined, will search for a steam_appid.txt file - * @param {boolean} [networking] - Enable networking * @returns {Omit} */ -module.exports.init = (appId, networking) => { +module.exports.init = (appId) => { const { init: internalInit, runCallbacks, restartAppIfNecessary, ...api } = nativeBinding - internalInit(appId, networking) + internalInit(appId) clearInterval(runCallbacksInterval) runCallbacksInterval = setInterval(runCallbacks, 1000 / 30) @@ -91,4 +90,4 @@ module.exports.electronEnableSteamOverlay = (disableEachFrameInvalidation) => { } const SteamCallback = nativeBinding.callback.SteamCallback -module.exports.SteamCallback = SteamCallback \ No newline at end of file +module.exports.SteamCallback = SteamCallback