android-js / androidjs

Platform to build android app using node js
MIT License
466 stars 109 forks source link

IPC communication delay. #156

Open toek79 opened 3 years ago

toek79 commented 3 years ago

There is visible random delay in IPC communication after first running the Android app.

It is very easy to replicate.

After running the application I need to send data from backed to fronted to present it. For now with mentioned bug is really annoying to use my application.

Is it a problem with socket.io library?

I am using Huawei P30 device.

toek79 commented 3 years ago

I changed 3 files:

front.js var socket = io('http://localhost:3000', { transports: [ 'polling']});

back.js var io = require("socket.io", { transports: [ 'polling']});

and assets/androidjs.js

var socket = io('http://localhost:3000', { transports: [ 'polling']});

It looks like now I don't have any delays. Please confirm if my solution is the right one.

skangmy commented 3 years ago

@toek79 I'm facing the same issue right now. There is no delay when testing on my laptop but random delay when running on my phone (Oppo A92).

I have tried the solution you suggested:

  1. Change back.js and front.js in node_modules\androidjs\lib\
  2. Change assets/androidjs.js

But the delay still there. Is there anything else that I missed?

toek79 commented 3 years ago

Hi,

I only changed mentioned files. Nothing else was touched by me.

Please ensure that your code is using proper android.js file

view/index.html

skangmy commented 3 years ago

I was using the wrong androidjs.js file in index.html. 😅

After fixing it, there are still delay but much shorter and bearable. I think it's good enough for me.

Thanks for your help!

Chhekur commented 3 years ago

@skangmy @toek79 Hey Guys, let me tell you the actual reason for the delay, actually Node isn't part of Native Android, so in order to run Node on android we have embedded Node binary in Android App so when the app actually starts it loads the app itself first and then loads the binary into memory and then finally starts the Node thread.

So this whole process takes a variable amount of time-based on your device's hardware and software such as CPU So you can reduce the socket delay but you can't reduce the node thread starting delay that's why you are facing that small amount of delay.

@toek79 if your solution reduces the delay a but then can you please submit a PR so that everyone can enjoy the fix