10-16-2019 11:48
10-16-2019 11:48
So I'm trying to use the Ably Realtime npm package but it doesn't seem to work and fails as a very weird place. I have already tried the answers to similar to questions and it doesn't seem to work.
Approaches I have tried as follows and errors for each of them -
1. Importing the package directly using this import statement "import * as Ably from 'ably'; "
var realtime = new Ably.Realtime('API-key');
Error while building is this -
[00:01:20][error][app] Error: Could not load path (imported by /sample-apps/fitbit/samplenewapp/node_modules/ably/nodejs/realtime.js): ENOENT: no such file or directory, open 'path'
Details:
errno: -2
code: PLUGIN_ERROR
syscall: open
path: path
pluginCode: ENOENT
hook: load
2. Importing from a file "import * as Ably from './ably';"
var realtime = new Ably.Realtime('API-key');
Error while building is this -
app/index.js (4:24) 'Realtime' is not exported by 'ably.js'
The same Realtime initialising statement works in React, Javascript etc.
3. I even tried what is mentioned here https://community.fitbit.com/t5/SDK-Development/Using-non-ES6-modules/m-p/2972514#M6292
After following that the build was successful but error while running -
App: Unhandled exception: Error: failed to pre-parse snapshot
I have been trying to make it work but no success. Would really appreciate help in this please.
10-21-2019 01:44
10-21-2019 01:44
I don't know how large that JS is, but the device is very limited in terms of memory. Are you doing this in the companion?
10-21-2019 02:37 - edited 10-21-2019 02:40
10-21-2019 02:37 - edited 10-21-2019 02:40
@JonFitbit No I'm trying this in main file only. Shouldn't I get a memory error in case of memory issue
10-21-2019 06:23
10-21-2019 06:23
You should try to get it working in the companion, the device is probably too constrained. You can then send messages from the device to the companion instructing it to perform actions, or fetch data.
10-21-2019 07:14
10-21-2019 07:14
@JonFitbit I'm still facing the same issue , tried with companion as well.
Got a similar error while building -
[19:13:17][error][companion] Error: Could not load fs (imported by /Users/av/Batman/side-projects/sample-apps/fitbit/samplenewapp/node_modules/ably/nodejs/rest.js): ENOENT: no such file or directory, open 'fs'
Details:
errno: -2
code: PLUGIN_ERROR
syscall: open
path: fs
pluginCode: ENOENT
hook: load
10-21-2019 11:57
10-21-2019 11:57
Can you post the project somewhere?
10-21-2019 12:19
10-21-2019 12:19
@JonFitbit I have created a repo. You can take a look here https://github.com/vardhanapoorv/fitbit-sample-app . Thanks!
10-22-2019 03:57
10-22-2019 03:57
I've submitted a PR. It's slightly weird in that the companion isn't a browser, and it's also not nodejs. I didn't test the comms, but the module imported and isn't complaining.
10-22-2019 04:46
10-22-2019 04:46
@JonFitbit thanks a lot for this. So I basically want to use that library to send message on click of the "Click me" button, so I'm not clear how I can do that since that code I cannot add in click event handler in the app "index.js" file. How can I direct the companion to trigger some code on click of that button?
10-22-2019 06:47
10-22-2019 06:47
You need to use the Messaging API to send messages from the device to the companion, and vice-versa.
https://dev.fitbit.com/build/guides/communications/messaging/
Don't forget to add the `access_internet` permission to your app, since you're using it in the companion.
10-22-2019 06:56
10-22-2019 06:56
@JonFitbit thanks for that. But I wanted to know the feasibility if I can use Ably library. And one more thing I wanted to know, so I can't use this app alone with the device if I'm using companion right?
10-22-2019 09:43
10-22-2019 09:43
The only way for the device to access the internet is via the companion. So you can use the device to drive the behavior and UI of your application, and relay messages via the companion.
10-22-2019 13:37
10-22-2019 13:37
@JonFitbit thanks a lot! Will try this approach and let you know if I face further issues. I think I won't be able to run this in the simulator since I need to enable 'access_internet' and I'm getting this in terminal on running -
Companion: The 'permission' API is not yet supported in the Fitbit OS Simulator. Behavior may not match the documentation or real devices.
So, I think I will have to try this a fitbit device.
10-22-2019 13:44
10-22-2019 13:44
I think you can ignore that simulator warning. All permissions are granted automatically; the sim can definitely access the internet.
10-22-2019 14:21
10-22-2019 14:21
@Gondwana thanks!
@JonFitbit thanks a lot, finally got it working!!!
Had a question so every npm package kind of will have a import statement like this "ably/browser/static/ably-commonjs.js" for it to work in companion and is there any documentation specifying this way of using a lib.
01-02-2020 05:42
01-02-2020 05:42
@JonFitbit so I completed the clockface and its working perfectly on the simulator. Now I want to test on a really Fitbit watch so for that I uploaded the project in the studio but it isn't working there.
First I got an error parsing tsconfig.json so I deleted the file just to check the issue. Then I got an error in the import statement which you helped me with in the PR "ably/browser/static/ably-commonjs.js is imported by companion/index.js, but could not be resolved" .
So if it doesn't work in the studio how can I make it work on the watch. Is there someway I can directly put it on the watch?
Hope to hear from you really soon.
@Gondwana if you can help please let me know.
01-03-2020 13:35
01-03-2020 13:35
Studio doesn't support npm packages, but you don't need Studio if you're already using the CLI.
Just quit the simulator, enable developer bridge on your Fitbit device, and phone, then the CLI will use those devices when you install.
01-04-2020 00:36
01-04-2020 00:36
Thanks @JonFitbit for the help.
01-17-2020 10:05
01-17-2020 10:05
@JonFitbit so I tried that and I'm facing few issues. Like I'm getting this error (refer attachment) the first time I ran it but not after that. Plus I have 3 settings, but only one setting is showing (remaining settings should show up after first setting is filled since they're dependent on that) .
.
01-23-2020 13:42
01-23-2020 13:42
We definitely don't have a navigator object since it's not a browser environment. I wonder if you could declare your own at the global scope. I'm not sure what Ably does with that variable though, or if it's required.