05-24-2019 11:39
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-24-2019 11:39
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I'm trying to wrap my head around messaging in the fitbit ecosystem. With a simple exercise:
1) Display a textblock that says "Loading"
2) Send a message with "Hello World" up to my app from the companion
3) Render that message on the gui.
Right now, that's not working at all it just shows the original message and doesn't seem to be doing anything. Am I missing some steps?
I have: index.gui
<svg class="background"> <text id="test" x="40%" y="60" text-length="20" text-overflow="ellipsis" >Loading</text> </svg>
In app/index.js:
import document from "document"; import * as messaging from "messaging"; let test= document.getElementById("test"); messaging.peerSocket.onmessage = event => { console.log("Data up to the app: " + event); test.text = event.data; // Should display message } messaging.peerSocket.onerror = (err) => { console.log(`Connection error: ${err.code} - ${err.message}`); }
In companion/index.js:
import { peerSocket } from "messaging";
if (peerSocket.readyState === peerSocket.OPEN) { peerSocket.send("Hello World"); // Should send message to app } peerSocket.onerror = (err) => { console.log(`Connection error: ${err.code} - ${err.message}`); }
Answered! Go to the Best Answer.

Accepted Solutions
05-24-2019 12:25
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-24-2019 12:25
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Got it!
In the companion I needed to wrap my send(..) in a onopen() method. Can't send stuff without it being open:
import { peerSocket } from "messaging"; peerSocket.onopen = () =>{ if (peerSocket.readyState === peerSocket.OPEN) { peerSocket.send("Hello World"); } } peerSocket.onerror = (err) => { console.log(`Connection error: ${err.code} - ${err.message}`); }
05-24-2019 12:25
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-24-2019 12:25
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Got it!
In the companion I needed to wrap my send(..) in a onopen() method. Can't send stuff without it being open:
import { peerSocket } from "messaging"; peerSocket.onopen = () =>{ if (peerSocket.readyState === peerSocket.OPEN) { peerSocket.send("Hello World"); } } peerSocket.onerror = (err) => { console.log(`Connection error: ${err.code} - ${err.message}`); }
