I am new to this and unable to understand why this happening - how do I resolve this? Please help
Answered! Go to the Best Answer.
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
I just tested this on Android 9.
// companion/index.js
const wsUri = "wss://echo.websocket.org/";
let websocket;
function testWebSocket() {
websocket = new WebSocket(wsUri);
websocket.addEventListener("open", onOpen);
websocket.addEventListener("close", onClose);
websocket.addEventListener("message", onMessage);
websocket.addEventListener("error", onError);
}
function onOpen(evt) {
console.log("CONNECTED");
doSend("WebSocket rocks");
}
function onClose(evt) {
console.log("DISCONNECTED");
}
function onMessage(evt) {
console.log(`MESSAGE: ${evt.data}`);
websocket.close();
}
function onError(evt) {
console.error(`ERROR: ${evt.data}`);
}
function doSend(message) {
console.log(`SEND: ${message}`);
websocket.send(message);
}
testWebSocket();
Which produces:
[11:22:40 AM] Companion: Companion launched by [launchedOnTracker] [11:22:41 AM] Companion: CONNECTED (companion/index.js:9,3) [11:22:41 AM] Companion: SEND: WebSocket rocks (companion/index.js:23,3) [11:22:41 AM] Companion: MESSAGE: WebSocket rocks (companion/index.js:14,3) [11:22:41 AM] Companion: DISCONNECTED (companion/index.js:14,3) [11:22:42 AM] Companion: Companion unloaded
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
Ipod, IOS
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
Which version of iOS?
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
Can you also post the code you're using too? Thanks
Best AnswerI am using below code in my companion app js and ios ver 10.3.3, android 9
const socket = new WebSocket('ws://localhost:8080');
socket.addEventListener('open', function (event) {
socket.send('Hi localserver!');
});
socket.addEventListener('message', function (event) {
console.log('Message from server ', event.data);
});
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
I just tested this on Android 9.
// companion/index.js
const wsUri = "wss://echo.websocket.org/";
let websocket;
function testWebSocket() {
websocket = new WebSocket(wsUri);
websocket.addEventListener("open", onOpen);
websocket.addEventListener("close", onClose);
websocket.addEventListener("message", onMessage);
websocket.addEventListener("error", onError);
}
function onOpen(evt) {
console.log("CONNECTED");
doSend("WebSocket rocks");
}
function onClose(evt) {
console.log("DISCONNECTED");
}
function onMessage(evt) {
console.log(`MESSAGE: ${evt.data}`);
websocket.close();
}
function onError(evt) {
console.error(`ERROR: ${evt.data}`);
}
function doSend(message) {
console.log(`SEND: ${message}`);
websocket.send(message);
}
testWebSocket();
Which produces:
[11:22:40 AM] Companion: Companion launched by [launchedOnTracker] [11:22:41 AM] Companion: CONNECTED (companion/index.js:9,3) [11:22:41 AM] Companion: SEND: WebSocket rocks (companion/index.js:23,3) [11:22:41 AM] Companion: MESSAGE: WebSocket rocks (companion/index.js:14,3) [11:22:41 AM] Companion: DISCONNECTED (companion/index.js:14,3) [11:22:42 AM] Companion: Companion unloaded
Best AnswerThanks, works fine, but when I use my URL "ws://127.0.0.1:9000/" then i am getting this error "WebSocket connection to 'ws://127.0.0.1:9000/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED"
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
Connection refused sounds like your service isn't running on that port. Or, are you running that service on a server? If so, you'll need to change 127.0.0.1 to the IP address of the server.
Best AnswerJust based on the comments, I read that only secure connections are support by device.
Therefore, wss:// protocol has to be declaired and not ws://.
Best Answer