Why is this illegal:
app/index.js
messaging.peerSocket.onmessage = evt => {
myWater.text = `${Math.ceil(evt.data.water/29.574)} oz`;
myCalories.text = `${evt.data.calories}`;
};companion/index.js
if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
messaging.peerSocket.send(myWaterData);
messaging.peerSocket.send(myCalorieData);
}
Calories show up fine but Water shows up as NaN. There has to be a way to batch-send/receive several values from the Web API to the device.
Answered! Go to the Best Answer.
Best AnswerI figured that that specific function had a "data" element so I tried seeing if the message would accept all of the declared data within the function and it worked!
.then(function(data) {
let calorieGoalData = {"goals":data.goals};
let summary = {"summary":data.summary};
if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
messaging.peerSocket.send(data);
}
Best AnswerWhat should the format be to send both values in one message? Using commas? Turning them into an array? And would the format in app.index.js still be valid?
Thanks! this is literally the last step before my watch app is completed!
Best AnswerI'd probably use an object, but an array would also work.
Best AnswerI realized that the food summary included both water and calorie data so that worked nicely! But what if I were to send separate data points like "calories" and "calorie goal" data in one message, how would I do that? Or sending separate databases like sleep and nutrition in one message even.
Best AnswerI figured that that specific function had a "data" element so I tried seeing if the message would accept all of the declared data within the function and it worked!
.then(function(data) {
let calorieGoalData = {"goals":data.goals};
let summary = {"summary":data.summary};
if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
messaging.peerSocket.send(data);
}
Best Answer