05-04-2022 15:05
05-04-2022 15:05
Hi all,
I noticed strange behaviour on my clock face: https://gallery.fitbit.com/details/3925af38-b12d-42b0-a611-554c91d73397
After the installation, my Settings are working perfectly, but after for ex. 1 hour, whatever I change in settings it's not reflected on the watch.
I guess this has something to do with the companion, but I really need some kind of event to be fired when settings are opened and the companion to be awakened.
Users are complaining that can change the colours and the stats toggle only the first time.
Here is my code in companion:
import * as messaging from "messaging";
import { settingsStorage } from "settings";
import * as util from "../../common/utils";
import { me as companion } from "companion";
export function initialize() {
settingsStorage.addEventListener("change", evt => {
if (evt.oldValue !== evt.newValue) {
sendValue(evt.key, evt.newValue);
}
});
}
function sendValue(key, val) {
if (val) {
sendSettingData({
key: key,
value: JSON.parse(val)
});
}
}
function sendSettingData(data) {
if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
messaging.peerSocket.send(data);
} else {
console.log("No peerSocket connection");
}
}
Thanks
05-04-2022 15:11
05-04-2022 15:11
Sockets don't always open immediately, I believe. If the connection isn't available when you need it, you're just throwing away the data at the moment. Using file transfer, rather than messaging, may be more robust.
05-04-2022 15:20
05-04-2022 15:20
Totally agree, but is there any way to put a loader screen/gif on the Settings screen for the user, or just display a counter for a few seconds until the socket is opened?
05-04-2022 15:24
05-04-2022 15:24
Yes, but that would be harder.
05-04-2022 15:26
05-04-2022 15:26
Ok, maybe another approach, is there a way to trigger an event for opening the socket immediately when the Settings section is opened?
05-04-2022 15:29
05-04-2022 15:29
No. The availability of the socket depends on the watch. It takes time for the OS to establish the connection. Sometimes it can't be done at all.
05-04-2022 15:31
05-04-2022 15:31
You could try waiting for socket onopen event, but I still think you risk losing data compared to file transfer.
05-04-2022 15:40
05-04-2022 15:40
I would like to implement the file transfer in the following way:
function sendSettingData(data) {
if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
messaging.peerSocket.send(data);
} else if (messaging.peerSocket.readyState === messaging.peerSocket.CLOSED) {
//Disable messaging
//File transfer
}
else {
console.log("No peerSocket connection");
}
}
but there is a risk in the meantime the socket to be opened and rewrite the users' choices, so is there a way to disable messaging once I decide to transfer the settings data via file?