socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

Ionic + Cpacitor Electron, NAME_NOT_RESOLVED for socket.io requests

Open ZweiEuro opened this issue 3 years ago • 0 comments

Describe the bug

Situation: I made a repository for testing: https://github.com/ZweiEuro/electron_socket_test

It has: server.js - minimal socket io server that just console.logs conections. CORS * so that is not an issue. Listening 3002

A minimal ionic blank project with socket-client installed. The web version just prompts for an ip address and tries to connect to it. Mainly defined in /src/pages/Home.tsx. Always connecting to <IP>:3002

A lot of tasks defined for easier debugging.

The ionic project has https://github.com/capacitor-community/electron installed as a platform, it's data is located in /electron. It should behave the same way as the ionic web page

The Problem:

Using the app Web version:

  1. Running node server.js
  2. Running ionic serve
  3. Navigating browser to http://localhost:8100/home
  4. Entering your machines ip address in the prompt will connect to it
  5. Console says "connect" both for the server and the web client => works as intended

Using the app electron version: (Since electron does not support 'prompt' in their window, you need to hard code the address of the server into Home.tsx, if you do this you need to rebuild (run the tasks again)

  1. Using the tasks "run electron" or "pack electron" (and starting it manually)
  2. open electron dev tools
  3. See error
GET http://capacitor-electron/socket.io/?EIO=4&transport=polling&t=OGz8z5U net::ERR_NAME_NOT_RESOLVED

To me it looks like something is getting rewritten incorrectly?

To Reproduce

  1. clone https://github.com/ZweiEuro/electron_socket_test
  2. npm i in both electron and the root directory
  3. Run the commands listed above, it is easier to start vscode in the directory and using the tasks
  4. Web version works, electron version throws the above error

ZweiEuro avatar Nov 03 '22 11:11 ZweiEuro