Skip to content

Commit 75f921f

Browse files
author
anastasiabouzdine
committed
minor fixes + correct Health --> HF stream in connection.js
1 parent 43e9b80 commit 75f921f

File tree

2 files changed

+31
-72
lines changed

2 files changed

+31
-72
lines changed

hf-data/js/connection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async function performAuthRequest() {
6565
{
6666
streamId: 'hf',
6767
defaultName: 'HF',
68-
level: 'manage' // permission for the app to manage data in the stream 'Health'
68+
level: 'manage' // permission for the app to manage data in the stream 'HF'
6969
}
7070
],
7171
requestingAppId: 'app-web-hfdemo'

hf-data/tutorial.md

Lines changed: 30 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
You can try the live version of the app [here](link-to-gh-pages).
55

6-
All you need to run this app is to download [index.html](index.html), [script.js](script.js) files, [js/](js) and [assets](assets) folders and open **index.html** with your browser.
6+
All you need to run this app is to download [index.html](index.html), [script.js](script.js) files, [js/](js) and [assets](assets) folders and open [index.html](index.html) with your browser.
77

88
This is a data collection and sharing web app that first displays a welcome message and a button to initiate the authentication process.
99
<p align="center">
@@ -44,7 +44,7 @@ The sharing link enables the recipient to consult the list of trackings, along w
4444

4545
## Authenticate your app
4646

47-
For this application, we have used the [Pryv JavaScript library](https://github.com/pryv/lib-js), loading it for [the browser](https://github.com/pryv/lib-js#browser) as following:
47+
For this application, we have used the [Pryv JavaScript library](https://github.com/pryv/lib-js), loading it for [the browser](https://github.com/pryv/lib-js#browser) as following in [index.html](index.html):
4848

4949
```html
5050
<script src="https://api.pryv.com/lib-js/pryv.js"></script>
@@ -56,86 +56,43 @@ For authentication, we will use the [Pryv.io consent process](https://github.com
5656
<span id="pryv-button"></span>
5757
```
5858

59-
The [auth request parameters](https://api.pryv.com/reference/#auth-request) and callback are defined in the separate [script.js](script.js) file:
59+
The [auth request parameters](https://api.pryv.com/reference/#auth-request) and callback are defined in the separate [connection.js](js/connection.js) file:
6060

6161
```javascript
62-
async function authRequest() {
63-
Pryv.Browser.setupAuth(authSettings, serviceInfoInput.value);
64-
}
65-
66-
const authSettings = {
62+
async function performAuthRequest() {
63+
const authSettings = {
6764
spanButtonID: 'pryv-button',
68-
onStateChange: pryvAuthStateChange,
65+
onStateChange: pryvAuthStateChange,
6966
authRequest: {
70-
requestingAppId: 'app-web-hfdemo',
71-
requestedPermissions: [{
72-
streamId: 'hf',
73-
defaultName: 'HF',
74-
level: 'manage'
75-
}],
76-
requestingAppId: 'app-web-hfdemo',
77-
}
78-
};
79-
80-
async function pryvAuthStateChange(state) {
81-
console.log('##pryvAuthStateChange', state);
82-
if (state.id === Pryv.Browser.AuthStates.AUTHORIZED) {
83-
console.log(state);
84-
var connection = new Pryv.Connection(state.apiEndpoint);
85-
await setupStreamStructure(connection);
86-
updateSharings();
87-
showCollectAndVisualize(true);
88-
}
89-
if (state.id === Pryv.Browser.AuthStates.INITIALIZED) {
90-
pryvHF.pryvConn = null;
91-
connection = null;
92-
showCollectAndVisualize(false);
67+
requestingAppId: 'app-web-hfdemo',
68+
requestedPermissions: [
69+
{
70+
streamId: 'hf',
71+
defaultName: 'HF',
72+
level: 'manage'
73+
}
74+
],
75+
requestingAppId: 'app-web-hfdemo'
9376
}
77+
};
78+
79+
Pryv.Browser.setupAuth(authSettings, serviceInfoInput.value);
9480
}
9581
```
9682

97-
The root stream of the `requestedPermissions` array is created if it doesn't exist yet. It will then be populated with events data from the tracking test.
83+
The root stream "**HF**" of the `requestedPermissions` array is created if it doesn't exist yet. It will then be populated with events data from the tracking test.
9884

9985
The auth request is done on page load, except when the shared data is loaded by a third-party.
10086

10187
## Collect HF data
10288

10389
Data collected from the mouse movement (desktop version) or device orientation (accelerometer version) will be stored in the form of [HF series](https://api.pryv.com/reference/#data-structure-high-frequency-series) which are collections of homogenous data points in Pryv.io.
10490

105-
```javascript
106-
var pryvHF = {
107-
pryvConn: null,
108-
measures: {
109-
mouseX: {
110-
event: null,
111-
buffer: []
112-
},
113-
mouseY: {
114-
event: null,
115-
buffer: []
116-
},
117-
orientationGamma: {
118-
event: null,
119-
buffer: []
120-
},
121-
orientationBeta: {
122-
event: null,
123-
buffer: []
124-
},
125-
orientationAlpha: {
126-
event: null,
127-
buffer: []
128-
}
129-
}
130-
131-
};
132-
```
133-
13491
### Collect HF data using the Desktop version
13592

13693
Once the user is signed in (Desktop version), he can perform the test using the mouse tracker. The code for the mouse tracker is contained in the file [desktop.js](./js/desktop.js).
137-
13894
Data collected from the mouse movement (X and Y positions) will be stored in the form of [HF series](https://api.pryv.com/reference/#data-structure-high-frequency-series) in a dedicated stream.
95+
13996
Connection with Pryv is established to store collected measures in the stream "**HF demo**" (see file [connection.js](js/connection.js)):
14097
```javascript
14198
async function setupStreamStructure(connection) {
@@ -157,7 +114,7 @@ async function setupStreamStructure(connection) {
157114
resultHandlers.push(null);
158115
}
159116
```
160-
As both X and Y positions will be captured during the recording, two substreams are created - "**Mouse-X**" and "**Mouse-Y**" - to hold events related to measured positions:
117+
As both X and Y positions will be captured during the recording, two substreams "**Mouse-X**" and "**Mouse-Y**" are created to hold events related to measured positions:
161118
```javascript
162119
if (!hasDesktopStream) {
163120
apiCalls.push(
@@ -248,8 +205,9 @@ function sendHfPoints(connection, measures) {
248205
249206
The tracking task is also available in a mobile version that allows to collect the device orientation in three dimensions. The code for the mobile accelerometer is contained in the file [mobile.js](js/mobile.js).
250207
251-
Similarly as for the [Desktop version](#collect-hf-data-using-the-desktop-version), connection with Pryv is established to store collected measures in the stream "**HF demo**" (see [connection.js](js/connection.js)).
252-
In the mobile version, as three different angles will be captured during the recording, three substreams are created - "**Orientation-Alpha**", "**Orientation-Beta**" and "**Orientation-Gamma**" - to hold events related to measured angles:
208+
Similarly as for the [Desktop version](#collect-hf-data-using-the-desktop-version), connection with Pryv is established to store collected measures in the stream "**HF demo**" (see [connection.js](js/connection.js)).
209+
210+
In the mobile version, as three different angles will be captured during the recording, three substreams "**Orientation-Alpha**", "**Orientation-Beta**" and "**Orientation-Gamma**" are created to hold events related to measured angles:
253211
254212
```javascript
255213
if (!hasMobileStream) {
@@ -360,7 +318,7 @@ function sendHfPoints(connection, measures) {
360318
361319
Once data from the tracking task has been collected, the app is designed to allow the user to share his data with a third-party.
362320
363-
The functions from the file [sharing.js](hf-data/js/sharing.js) enable the user to create a sharing that consists of a URL link with a Pryv apiEndpoint that displays the visualization from the tracking test.
321+
The functions from the file [sharing.js](hf-data/js/sharing.js) enable the user to create a sharing that consists of a URL link (with a Pryv API endpoint) that displays the visualization from the tracking test.
364322
365323
In order to create a sharing, we add a listener to the *Create* button:
366324
@@ -371,7 +329,7 @@ function buildSharing() {
371329
}
372330
```
373331
374-
The *sharing* is translated into the creation of a [shared access](https://api.pryv.com/concepts/#accesses) in Pryv.io. Values for the scope of the sharing ('streamId' and 'level' for permissions) are fetched, in our case "read" level on the stream "**HF Demo**":
332+
The sharing is translated into the creation of a [shared access](https://api.pryv.com/concepts/#accesses) in Pryv.io. Values for the scope of the sharing ('streamId' and 'level' for permissions) are fetched, in our case "read" level on the stream "**HF Demo**":
375333
376334
```javascript
377335
async function createSharing() {
@@ -444,16 +402,17 @@ async function deleteSharing(accessId) {
444402
445403
## Display the sharing (view-only mode)
446404
447-
Once the sharing has been created, it should enable third parties to consult data from the user in a "view-only" mode. In this mode, a table containing all performed tests is displayed, along with the date of the test and the tracking method.
448-
Example: [https://api.pryv.com/app-web-examples/hf-data/?apiEndpoint=https://cke8hrluz00o31kqod5lcdudm@hf-test.pryv.me/](https://api.pryv.com/app-web-examples/hf-data/?apiEndpoint=https://cke8hrluz00o31kqod5lcdudm@hf-test.pryv.me/)
405+
Once the sharing has been created, it should enable third parties to consult data from the user in a "view-only" mode. In this mode, a table containing all performed tests is displayed, along with the date of the test and the tracking method.
406+
407+
*Example: [https://api.pryv.com/app-web-examples/hf-data/?apiEndpoint=https://cke8hrluz00o31kqod5lcdudm@hf-test.pryv.me/](https://api.pryv.com/app-web-examples/hf-data/?apiEndpoint=https://cke8hrluz00o31kqod5lcdudm@hf-test.pryv.me/)*
449408
450409
The recipient of the link can open the data visualization by clicking on the chosen test:
451410
- the **Desktop version** contains the drawing performed with the mouse tracker
452411
- the **Mobile version** displays the recording of the phone orientation
453412
454413
The code for the visualization mode is contained in the [js/view_only.js](js/view_only.js).
455414
456-
This will load the app already authenticated, by passing the `pryvApiEndpoint` parameter in the function *buildVisualizationOnly(apiEndpoint, urlParams)*.
415+
This will load the app already authenticated, by passing the `apiEndpoint` parameter in the function buildVisualizationOnly(apiEndpoint, urlParams).
457416
458417
```javascript
459418
async function buildVisualizationOnly(apiEndpoint, urlParams) {

0 commit comments

Comments
 (0)