Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

detect if the companion is started

ANSWERED

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

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

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.

View best answer in original post

Best Answer
3 REPLIES 3

I found out, that the companion gets disloaded while it is running.

I´m confused...

Best Answer
0 Votes

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.

Best Answer

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.

Best Answer
0 Votes