Skip to content

Commit

Permalink
Merge pull request #30 from densellp/wrong-args
Browse files Browse the repository at this point in the history
fix: wrong arguments error resolved
  • Loading branch information
jrcarl624 committed Mar 15, 2024
2 parents b771729 + 8196d72 commit 431eb13
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"build": "tsc",
"test": "node --es-module-specifier-resolution=node --experimental-fetch ./test/index.js",
"test-n-build": "npm run build && npm run test",
"publish": "npm run build && npm publish --access public "
"publish": "npm run build && npm publish --access public",
"start": "node --es-module-specifier-resolution=node --experimental-fetch ./index.js"
},
"author": "minerj101",
"license": "MIT",
Expand Down
15 changes: 10 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const Constants = {
CLIENT_ID: "00000000441cc96b", // Nintendo Switch Title ID
};

function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

const debug = (...args: any[]) => {
if (process.env.FRIEND_CONNECT_DEBUG) {
for (let i of args) {
Expand Down Expand Up @@ -193,7 +197,7 @@ class Session extends EventEmitter {
if (options.autoFriending) this.additionalOptions.autoFriending = true;
this.additionalOptions.constants =
options.constants || ({} as SessionOptionsConstants);
this.getAdvertisement();
this.getAdvertisement(options.ip, options.port);

if (!/.[\/]?[a-zA-Z0-9]+[\/]?/.test(options.tokenPath))
throw new Error("`tokenPath` is invalid, use ./auth/ for example");
Expand Down Expand Up @@ -267,7 +271,7 @@ class Session extends EventEmitter {
);
setInterval(() => {
if (this.additionalOptions.pingServerForInfo)
this.getAdvertisement();
this.getAdvertisement(options.ip, options.port);
}, 15000);
//debug(request);
this.#sessionInstance = new RTAMultiplayerSession(
Expand Down Expand Up @@ -616,11 +620,12 @@ class Session extends EventEmitter {
}, 15000);
}
}
async getAdvertisement(): Promise<void> {
async getAdvertisement(ip, port): Promise<void> {
try {
await delay(2000); // Wait to ping the server
let info = await ping({
host: this.#ip,
port: parseInt(`${this.#port}`),
host: ip,
port: port,
});
if (!this.additionalOptions.constants.gamemode)
this.minecraftLobbyCustomOptions.worldType = info.gamemode;
Expand Down

0 comments on commit 431eb13

Please sign in to comment.