11-28-2018 14:58
11-28-2018 14:58
Hello,
what is the right way to detect if the companion is started and the connection is established / stable?
At this moment I have it get done the following way on app/index.js:
import * as messaging from "messaging"; messaging.peerSocket.onopen = () => { console.log("Companion: peerSocket onopen"); }; messaging.peerSocket.onclose = () => { console.log("Companion: peerSocket onclose"); }; messaging.peerSocket.onerror = () => { console.log("Companion: peerSocket onerror"); };
I think I get wrong because the Events don´t get fired when I close the companion (Fitbit-App on smartphone) or disconnect via disabling bluetooth on my smartphone.
thanks,
NoWo
Answered! Go to the Best Answer.
11-29-2018 09:48
11-29-2018 09:48
Mobile phones are aggressive about their battery optimization. Send a message from the device to the companion, and it should be woken for you. Or, you can use the wakeinterval on the companion.
11-29-2018 09:23
11-29-2018 09:23
I found out, that the companion gets disloaded while it is running.
I´m confused...
11-29-2018 09:48
11-29-2018 09:48
Mobile phones are aggressive about their battery optimization. Send a message from the device to the companion, and it should be woken for you. Or, you can use the wakeinterval on the companion.
11-30-2018 11:59
11-30-2018 11:59
I got it 🙂
I thought I have to check myself if the connection to companion and backward is ok 😕
But all I have to know is that onopen and onclose does that by themself 🙂
But I found a bug in the Simulator:
I spent much time because I got multiple Answers of one message.
When I send message via an onclick-Event (for e.g. on an image) to Companion (message.send() ) then the companion fires much onmessage-Events and processes them all (so many returns which themself have also processes...), but outside Simulator the onmessage-event fires only one time (the onmessage-Event fetches an Internet-Site and on the Log of Server I see only one fetch, but console.log shows much fetches).
On the real Device (not Simulator) everythings works fine, only Simulator has this bug..
Perhaps this could be fixed in the Future so other users do not have these problems.