@nuralogix.ai/web-measurement-embedded-app 0.1.0-alpha.15 → 0.1.0-alpha.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,101 +1,102 @@
1
1
  ### Web Measurement Embedded App
2
2
 
3
-
3
+ Need deeper integration details? Check the full docs at [docs.deepaffex.ai/wmea](https://docs.deepaffex.ai/wmea/).
4
4
 
5
5
  ```html
6
6
  <!DOCTYPE html>
7
7
  <html lang="en">
8
- <head>
9
- <meta charset="UTF-8" />
10
- <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
11
- <title>Measurement Embedded App Demo</title>
8
+ <head>
9
+ <meta charset="UTF-8" />
10
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
11
+ <title>Measurement Embedded App Demo</title>
12
12
  <script type="importmap">
13
- {
14
- "imports": {
15
- "@nuralogix.ai/web-measurement-embedded-app": "https://unpkg.com/@nuralogix.ai/web-measurement-embedded-app"
16
- }
13
+ {
14
+ "imports": {
15
+ "@nuralogix.ai/web-measurement-embedded-app": "https://unpkg.com/@nuralogix.ai/web-measurement-embedded-app"
17
16
  }
17
+ }
18
18
  </script>
19
- </head>
20
- <body>
21
- <div id="measurement-embedded-app-container"></div>
22
- <script type="module">
23
- import MeasurementEmbeddedApp, { faceAttributeValue } from '@nuralogix.ai/web-measurement-embedded-app';
24
- const {
25
- SEX_ASSIGNED_MALE_AT_BIRTH,
26
- SMOKER_FALSE,
27
- BLOOD_PRESSURE_MEDICATION_FALSE,
28
- DIABETES_NONE
29
- } = faceAttributeValue;
30
- const measurementApp = new MeasurementEmbeddedApp();
31
- const container = document.getElementById('measurement-embedded-app-container');
32
- if (container) {
33
- const apiUrl = '/api';
34
- const studyId = await fetch(`${apiUrl}/studyId`);
35
- const studyIdResponse = await studyId.json();
36
- const token = await fetch(`${apiUrl}/token`);
37
- const tokenResponse = await token.json();
38
- if (studyIdResponse.status === '200' && tokenResponse.status === '200') {
39
- measurementApp.init({
40
- container,
41
- appPath: 'https://unpkg.com/@nuralogix.ai/web-measurement-embedded-app/dist',
42
- settings: {
43
- token: tokenResponse.token,
44
- refreshToken: tokenResponse.refreshToken,
45
- studyId: studyIdResponse.studyId,
46
- },
47
- profile: {
48
- age: 40,
49
- height: 180,
50
- weight: 60,
51
- sex: SEX_ASSIGNED_MALE_AT_BIRTH,
52
- smoking: SMOKER_FALSE,
53
- bloodPressureMedication: BLOOD_PRESSURE_MEDICATION_FALSE,
54
- diabetes: DIABETES_NONE,
55
- bypassProfile: false,
56
- },
57
- config: { // optional
58
- checkConstraints: true, // optional
59
- cameraFacingMode: 'user', // optional
60
- cameraAutoStart: true, // optional
61
- measurementAutoStart: false, // optional
62
- }
63
- // top: '100px', // (optional)
64
- // language: 'fr', // (optional)
65
- // apiUrl: 'some-custom-api-url-value', // (optional)
66
- loadError: function(error) {
67
- console.error("load rror", error);
68
- }
69
- });
70
- measurementApp.on.results = (results) => {
71
- console.log("Results received", results);
72
- measurementApp.destroy();
73
- };
74
- measurementApp.on.error = (error) => {
75
- console.log("error received", error);
76
- };
77
- measurementApp.on.event = (appEvent) => {
78
- console.log("App Event received", appEvent);
79
- };
80
- } else {
81
- console.error('Failed to get Study ID and Token pair');
82
- }
83
- }
84
- </script>
85
- </body>
19
+ </head>
20
+ <body>
21
+ <div id="measurement-embedded-app-container"></div>
22
+ <script type="module">
23
+ import MeasurementEmbeddedApp, { faceAttributeValue } from '@nuralogix.ai/web-measurement-embedded-app';
24
+ const {
25
+ SEX_ASSIGNED_MALE_AT_BIRTH,
26
+ SMOKER_FALSE,
27
+ BLOOD_PRESSURE_MEDICATION_FALSE,
28
+ DIABETES_NONE
29
+ } = faceAttributeValue;
30
+ const measurementApp = new MeasurementEmbeddedApp();
31
+ const container = document.getElementById('measurement-embedded-app-container');
32
+ if (container) {
33
+ const apiUrl = '/api';
34
+ const studyId = await fetch(`${apiUrl}/studyId`);
35
+ const studyIdResponse = await studyId.json();
36
+ const token = await fetch(`${apiUrl}/token`);
37
+ const tokenResponse = await token.json();
38
+ if (studyIdResponse.status === '200' && tokenResponse.status === '200') {
39
+ measurementApp.init({
40
+ container,
41
+ appPath: 'https://unpkg.com/@nuralogix.ai/web-measurement-embedded-app/dist',
42
+ settings: {
43
+ token: tokenResponse.token,
44
+ refreshToken: tokenResponse.refreshToken,
45
+ studyId: studyIdResponse.studyId,
46
+ },
47
+ profile: {
48
+ age: 40,
49
+ height: 180,
50
+ weight: 60,
51
+ sex: SEX_ASSIGNED_MALE_AT_BIRTH,
52
+ smoking: SMOKER_FALSE,
53
+ bloodPressureMedication: BLOOD_PRESSURE_MEDICATION_FALSE,
54
+ diabetes: DIABETES_NONE,
55
+ bypassProfile: false,
56
+ },
57
+ // Optional configuration overrides (defaults shown)
58
+ config: {
59
+ checkConstraints: true,
60
+ cameraFacingMode: 'user', // or 'environment' for back camera
61
+ cameraAutoStart: false,
62
+ measurementAutoStart: false,
63
+ }
64
+ // Optional top/language/api overrides
65
+ // top: '100px'
66
+ // language: 'fr'
67
+ apiUrl: 'api.na-east.deepaffex.ai', // optional for region specific data processing
68
+ loadError: function(error) {
69
+ console.error("load error", error);
70
+ }
71
+ });
72
+ measurementApp.on.results = (results) => {
73
+ console.log("Results received", results);
74
+ measurementApp.destroy();
75
+ };
76
+ measurementApp.on.error = (error) => {
77
+ console.log("error received", error);
78
+ };
79
+ measurementApp.on.event = (appEvent) => {
80
+ console.log("App Event received", appEvent);
81
+ };
82
+ } else {
83
+ console.error('Failed to get Study ID and Token pair');
84
+ }
85
+ }
86
+ </script>
87
+ </body>
86
88
  </html>
87
89
  ```
88
90
 
89
- **Notes:**
90
-
91
- - If you are bundling `Web Measurement Embedded App` with your app, set `appPath` to `'.'`.
92
-
93
- - `language` prop is optional. You can either set it to `en` or `fr`
94
- - If a supported language is set, the app loads with a supported language.
95
- - If the language prop is not set, the app checks the browser's language and if it is among
96
- the list of supported languages, it loads the language pack for the browser's language.
97
- Otherwise falls back to `en`.
91
+ **Notes:**
98
92
 
93
+ - Set `appPath` to `'.'` when you bundle the assets yourself.
94
+ - Profile handling: when `bypassProfile` remains `true` (default) we skip demographic submission and emit an `ERROR` event with `PROFILE_INFO_NOT_SET`; set it to `false` once you supply real profile data.
95
+ - Optional `top` offset lets you push the UI below your own header (default `'0'`).
96
+ - Optional `apiUrl` enables region-specific processing; omitted values follow the backend token's region automatically. When set explicitly, frontend calls your URL (processing where that endpoint runs) while results continue to store in the token's region—verify the combination suits your deployment.
97
+ - Language support: `en`, `ja`, `cn`, `es`, `pt`, `it`, `fr`, `de`, `br`.
98
+ - Browser locales `zh` and `zh-Hans` automatically fall back to `cn`.
99
+ - `loadError` is called if assets fail to download or the app cannot initialize.
99
100
 
100
101
  **Methods:**
101
102
 
@@ -129,3 +130,40 @@ error: ((error: MeasurementEmbeddedAppError) => void) | null;
129
130
  */
130
131
  event: ((appEvent: AppEvent) => void) | null;
131
132
  ```
133
+
134
+ **App events dispatched through `measurementApp.on.event`:**
135
+
136
+ - `APP_LOADED` – the embedded app finished its startup sequence.
137
+ - `CAMERA_PERMISSION_GRANTED` – the user granted camera access.
138
+ - `CAMERA_STARTED` – a camera stream opened successfully.
139
+ - `MEASUREMENT_STARTED` – a measurement run begins.
140
+ - `MEASUREMENT_COMPLETED` – the measurement finished and results are stable.
141
+ - `INTERMEDIATE_RESULTS` – partial results are available during an active run.
142
+ - `RESULTS_RECEIVED` – the final measurement results are available.
143
+ - `MEASUREMENT_CANCELED` – the active measurement was canceled (user action or constraint).
144
+ - `CONSTRAINT_VIOLATION` – a constraint (e.g., face distance) failed.
145
+ - `PAGE_VISIBILITY_CHANGE` – the page changed visibility (e.g., tab switch or minimize).
146
+ - `PAGE_UNLOADED` – the page is unloading.
147
+
148
+ **Other runtime helpers:**
149
+
150
+ ```typescript
151
+ await measurementApp.cancel(true); // cancel current run
152
+ const logs = await measurementApp.getLogs();
153
+ measurementApp.setTheme('dark');
154
+ measurementApp.setLanguage('es');
155
+ ```
156
+
157
+ **Error codes emitted through `measurementApp.on.error`:**
158
+
159
+ | Code | Meaning |
160
+ | -------------------------- | ----------------------------------------------------------------- |
161
+ | `CAMERA_PERMISSION_DENIED` | Camera access prompt was rejected. |
162
+ | `CAMERA_START_FAILED` | Camera hardware failed to start after permission. |
163
+ | `NO_DEVICES_FOUND` | No video input devices detected during enumeration. |
164
+ | `PAGE_NOT_VISIBLE` | Measurement was running while the tab or window became hidden. |
165
+ | `MEASUREMENT_LOW_SNR` | Signal-to-noise ratio dropped below the acceptable threshold. |
166
+ | `WORKER_ERROR` | SDK worker encountered a fatal processing error. |
167
+ | `PROFILE_INFO_NOT_SET` | Profile bypass stayed enabled, so demographics were not provided. |
168
+ | `COLLECTOR` | Frame collection reported an error |
169
+ | `WEBSOCKET_DISCONNECTED` | Realtime WebSocket connection closed or dropped. |