06-05-2019 00:29
06-05-2019 00:29
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 Answer06-13-2019 03:24
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.
06-13-2019 03:24
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 Answer06-06-2019 15:12
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.
06-06-2019 15:12
Are you getting this error in your /companion code?
Which mobile phone OS/version are you using?
Best Answer06-07-2019 01:03
06-07-2019 01:03
Ipod, IOS
Best Answer06-10-2019 08:30
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.
06-10-2019 08:30
Which version of iOS?
Best Answer06-10-2019 09:07
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.
06-10-2019 09:07
Can you also post the code you're using too? Thanks
Best Answer06-13-2019 01:14
06-13-2019 01:14
I 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 Answer06-13-2019 03:24
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.
06-13-2019 03:24
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 Answer06-13-2019 23:13
06-13-2019 23:13
Thanks, 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 Answer06-14-2019 00:59
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.
06-14-2019 00:59
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 Answer05-17-2020 04:34
05-17-2020 04:34
Just 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