From c7f35936112d37850d141defeae361f80e1c610c Mon Sep 17 00:00:00 2001 From: Vitaly Date: Tue, 26 Sep 2023 19:30:07 +0300 Subject: [PATCH] fix(important): fix connect to servers by domain fix: finally display readable errors on proxy connect errors --- cypress/integration/index.spec.ts | 2 +- package.json | 2 +- pnpm-lock.yaml | 32 +++++++++++++-------------- src/index.ts | 33 +++++++++++++++++++--------- src/menus/loading_or_error_screen.js | 2 +- 5 files changed, 42 insertions(+), 29 deletions(-) diff --git a/cypress/integration/index.spec.ts b/cypress/integration/index.spec.ts index d8744a4e..bfc5ff8c 100644 --- a/cypress/integration/index.spec.ts +++ b/cypress/integration/index.spec.ts @@ -55,7 +55,7 @@ it('Loads & renders singleplayer', () => { it('Joins to server', () => { // visit('/?version=1.16.1') - window.localStorage.version = '1.16.1' + window.localStorage.version = '' visit() // todo replace with data-test cy.get('#title-screen').find('[data-test-id="connect-screen-button"]', { includeShadowDom: true, }).click() diff --git a/package.json b/package.json index 69a18859..6a7fdac1 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "lit": "^2.8.0", "lodash": "^4.17.21", "minecraft-data": "^3.0.0", - "net-browserify": "github:PrismarineJS/net-browserify", + "net-browserify": "github:zardoy/prismarinejs-net-browserify", "peerjs": "^1.5.0", "pretty-bytes": "^6.1.1", "qrcode.react": "^3.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 49270a55..9ec9eda3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -79,8 +79,8 @@ importers: specifier: 3.45.0 version: 3.45.0 net-browserify: - specifier: github:PrismarineJS/net-browserify - version: github.com/PrismarineJS/net-browserify/0acebf76d5a14991e6b2586f83f707be5171579c + specifier: github:zardoy/prismarinejs-net-browserify + version: github.com/zardoy/prismarinejs-net-browserify/51262fe139a6a4856ffd4a6dc7b9145c3d6d8039 peerjs: specifier: ^1.5.0 version: 1.5.0 @@ -12157,20 +12157,6 @@ packages: - utf-8-validate dev: true - github.com/PrismarineJS/net-browserify/0acebf76d5a14991e6b2586f83f707be5171579c: - resolution: {tarball: https://codeload.github.com/PrismarineJS/net-browserify/tar.gz/0acebf76d5a14991e6b2586f83f707be5171579c} - name: net-browserify - version: 0.2.4 - dependencies: - body-parser: 1.20.2 - express: 4.18.2 - express-ws: 4.0.0(express@4.18.2) - transitivePeerDependencies: - - bufferutil - - supports-color - - utf-8-validate - dev: false - github.com/PrismarineJS/node-process/380d0b4f4c86f1b65b216c311bf00431f314e88e: resolution: {tarball: https://codeload.github.com/PrismarineJS/node-process/tar.gz/380d0b4f4c86f1b65b216c311bf00431f314e88e} name: process @@ -12288,6 +12274,20 @@ packages: dependencies: vec3: 0.1.8 + github.com/zardoy/prismarinejs-net-browserify/51262fe139a6a4856ffd4a6dc7b9145c3d6d8039: + resolution: {tarball: https://codeload.github.com/zardoy/prismarinejs-net-browserify/tar.gz/51262fe139a6a4856ffd4a6dc7b9145c3d6d8039} + name: net-browserify + version: 0.2.4 + dependencies: + body-parser: 1.20.2 + express: 4.18.2 + express-ws: 4.0.0(express@4.18.2) + transitivePeerDependencies: + - bufferutil + - supports-color + - utf-8-validate + dev: false + github.com/zardoy/space-squid/eec886b7a881eb40dd8efc6d48fa52e638e07693: resolution: {tarball: https://codeload.github.com/zardoy/space-squid/tar.gz/eec886b7a881eb40dd8efc6d48fa52e638e07693} name: flying-squid diff --git a/src/index.ts b/src/index.ts index 2edc84c0..1c1883cd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -450,18 +450,31 @@ async function connect(connectOptions: { bot.emit('inject_allowed') bot._client.emit('connect') } else { - bot._client.socket.on('connect', () => { - console.log('TCP connection established') - //@ts-expect-error - bot._client.socket._ws.addEventListener('close', () => { - console.log('TCP connection closed') - setTimeout(() => { - if (bot) { - bot.emit('end', 'TCP connection closed with unknown reason') - } + const setupConnectHandlers = () => { + bot._client.socket.on('connect', () => { + console.log('TCP connection established') + //@ts-expect-error + bot._client.socket._ws.addEventListener('close', () => { + console.log('TCP connection closed') + setTimeout(() => { + if (bot) { + bot.emit('end', 'TCP connection closed with unknown reason') + } + }) }) }) - }) + } + // socket setup actually can be delayed because of dns lookup + if (bot._client.socket) { + setupConnectHandlers() + } else { + const originalSetSocket = bot._client.setSocket.bind(bot._client) + bot._client.setSocket = (socket) => { + originalSetSocket(socket) + setupConnectHandlers() + } + } + } } catch (err) { handleError(err) diff --git a/src/menus/loading_or_error_screen.js b/src/menus/loading_or_error_screen.js index d2259d42..7a9588d8 100644 --- a/src/menus/loading_or_error_screen.js +++ b/src/menus/loading_or_error_screen.js @@ -79,7 +79,7 @@ class LoadingErrorScreen extends LitElement { return html`
-
${this.status}${this.hasError || this.hideDots ? '' : this._loadingDots} +
${this.status}${this.hasError || this.hideDots ? '' : this._loadingDots}

${this.hasError ? guessProblem(this.status) : ''}

${this.lastStatus ? `Last status: ${this.lastStatus}` : this.lastStatus}