I can't seem to get a message to send when the Companion wakes up.
The following code in my Companion always results in: 'messaging not open'
How can I open the messaging on wokenUp?
if (me.launchReasons.wokenUp) {
console.log("Started due to wake interval!");
sendWakeMessage();
}
function sendWakeMessage() {
if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
var data = {
message: "wake"
}
messaging.peerSocket.send(data);
console.log("Message sent from companion");
} else {
console.log("messaging not open");
}
}
I also tried putting
messaging.peerSocket.onopen = function() {
sendWakeMessage();
}
inside the wokenUp handler, with no luck
Best AnswerApps do not work in background, so if your app is off, then you can't communicate with it.
There is a feature suggestion combining background processing with app-originated notifications:
Feel free to vote on it.
Best Answer