Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Creating Event not possible within index.js of app

While I am able to create events inside index.js of the companion, I am not able to do so within index.js of the app itself. What am I missing?

 

index.js:

console.log('Up and running.');

var event = new Event('test');

console.log('Event added.')

console output:

[1:45:51 PM] App: App Closed
[1:45:51 PM] App: App Started
[1:45:51 PM] App: Up and running. (app/index.js:1,1)
[1:45:51 PM] App: Unhandled exception: ReferenceError: Event is not defined
event at app/index.js:3,1
[1:45:52 PM] Companion: Up and running. (companion/index.js:1,1)
[1:45:52 PM] Companion: Event added. (companion/index.js:5,1)

 

I am using the following versions of the sdk:

"@fitbit/sdk": "~3.1.2",
"@fitbit/sdk-cli": "^1.6.3"
Best Answer
0 Votes
3 REPLIES 3

Two probably-wrong guesses:

  • You may not be importing the right file. (It isn't clear from the documentation what the right file is, if any.)
  • The device runs an older version of javascript, so some things that work on the companion don't work on the watch.
Peter McLennan
Gondwana Software
Best Answer
0 Votes

@Gondwana wrote:

You may not be importing the right file.


There's no need to import anything inside index.js of the companion to make use of the Event class there, so I'd doubt that.

 


@Gondwana wrote:

The device runs an older version of javascript, so some things that work on the companion don't work on the watch.


I guess so, too. On a different thread I recently read about restricted capabilities of the device regarding date methods like "toLocaleString()". JonFitbit stated the following cause there: "The JavaScript on the device only supports ES5.1, ..." Gonna stick to callbacks then, I'm afraid... /:

Best Answer
0 Votes

Try this:

 
document.addEventListener(“EventName”, function(evt){console.log(“Hello World!”)});
document.dispatchEvent({ type: ‘EventName’ });
 
Best Answer
0 Votes