@adriansteffan/reactive 0.2.6 → 0.5.0
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 +796 -229
- package/bin/add.js +56 -0
- package/bin/deploy.js +48 -0
- package/bin/download.js +28 -0
- package/bin/ghsetup.js +21 -0
- package/bin/native.js +81 -0
- package/bin/setup.js +11 -17
- package/bin/study-deploy.js +60 -0
- package/bin/undeploy.js +15 -0
- package/extras/transcription/compose.yaml +32 -0
- package/{template → extras}/transcription/transcribe.py +4 -9
- package/package.json +62 -64
- package/src/bun-env.d.ts +1 -0
- package/src/bun-plugin.ts +22 -0
- package/src/components/canvasblock.tsx +209 -537
- package/src/components/checkdevice.tsx +64 -84
- package/src/components/fullscreenblock.tsx +130 -0
- package/src/components/icons.tsx +50 -0
- package/src/components/index.ts +9 -11
- package/src/components/microphonecheck.tsx +76 -38
- package/src/components/plaininput.tsx +48 -41
- package/src/components/prolificending.tsx +64 -28
- package/src/components/quest.tsx +89 -87
- package/src/components/{randomdotkinetogram.tsx → randomdotkinematogram.tsx} +205 -267
- package/src/components/{voicerecorder.tsx → recorder.tsx} +81 -106
- package/src/components/requestfilepermission.tsx +63 -0
- package/src/components/stimulus.tsx +373 -0
- package/src/components/storeui.tsx +94 -148
- package/src/components/text.tsx +61 -59
- package/src/components/tutorial.tsx +45 -47
- package/src/components/upload.tsx +133 -309
- package/src/components/voicerecording.tsx +90 -94
- package/src/core/backend.ts +20 -0
- package/src/core/bytecode.ts +178 -0
- package/src/core/columns.ts +50 -0
- package/src/core/component.ts +238 -0
- package/src/core/development.ts +32 -0
- package/src/core/experiment.ts +263 -0
- package/src/core/files.ts +291 -0
- package/src/core/params.ts +166 -0
- package/src/core/platform.ts +29 -0
- package/src/core/rows.ts +106 -0
- package/src/core/simulation.ts +158 -0
- package/src/core/slides.ts +178 -0
- package/src/core/store.ts +22 -0
- package/src/core/timeline.ts +399 -0
- package/src/fonts/AtkinsonHyperlegible-Bold.woff2 +0 -0
- package/src/fonts/AtkinsonHyperlegible-BoldItalic.woff2 +0 -0
- package/src/fonts/AtkinsonHyperlegible-Italic.woff2 +0 -0
- package/src/fonts/AtkinsonHyperlegible-Regular.woff2 +0 -0
- package/src/index.css +5 -7
- package/src/mod.tsx +31 -17
- package/src/native.ts +127 -0
- package/src/quest.ts +2 -0
- package/src/runner/contexts.ts +35 -0
- package/src/runner/devpanel.tsx +68 -0
- package/src/runner/experimentrunner.tsx +210 -0
- package/src/runner/fullscreenguard.tsx +93 -0
- package/src/runner/paraminput.tsx +86 -0
- package/src/runner/progressbar.tsx +20 -0
- package/src/runner/settingsscreen.tsx +517 -0
- package/src/{utils → runner}/theme.ts +9 -8
- package/src/server.ts +93 -0
- package/src/tutorial.ts +3 -0
- package/src/utils/array.ts +30 -62
- package/src/utils/canvas.ts +66 -0
- package/src/utils/ddm.ts +47 -70
- package/src/utils/distributions.ts +352 -61
- package/src/utils/fullscreen.ts +38 -0
- package/src/utils/ids.ts +11 -0
- package/src/utils/keys.ts +46 -0
- package/src/utils/llm.ts +15 -15
- package/src/utils/time.ts +12 -0
- package/src/utils/tts.ts +24 -24
- package/template/.dockerignore +3 -1
- package/template/.env.example +5 -0
- package/template/.github/workflows/deploy.yml +25 -0
- package/template/.gitignore +14 -0
- package/template/Dockerfile +9 -14
- package/template/README.md +74 -214
- package/template/biome.json +34 -0
- package/template/build.ts +20 -0
- package/template/bunfig.toml +3 -0
- package/template/docker-compose.yaml +4 -33
- package/template/index.html +2 -2
- package/template/package.json +16 -89
- package/template/public/.gitkeep +0 -0
- package/template/server.ts +32 -0
- package/template/simulate.ts +4 -44
- package/template/src/Experiment.tsx +76 -128
- package/template/src/bun-env.d.ts +1 -0
- package/template/src/index.css +1 -9
- package/template/src/main.tsx +25 -10
- package/template/tsconfig.json +4 -6
- package/.claude/settings.local.json +0 -61
- package/.eslintrc.cjs +0 -18
- package/.playwright-mcp/console-2026-04-07T14-22-59-060Z.log +0 -1
- package/.prettierrc +0 -5
- package/Dockerfile +0 -20
- package/dist/mod-HDegGPrf.js +0 -87434
- package/dist/mod.d.ts +0 -946
- package/dist/reactive.es.js +0 -87
- package/dist/reactive.umd.js +0 -10255
- package/dist/style.css +0 -5
- package/dist/web-7BbR1Ad7.js +0 -435
- package/dist/web-CATfZO1Q.js +0 -12
- package/planned.md +0 -103
- package/postcss.config.js +0 -6
- package/raw-loader-hooks.mjs +0 -25
- package/raw-loader.mjs +0 -5
- package/rdk_doc.md +0 -341
- package/src/components/enterfullscreen.tsx +0 -230
- package/src/components/exitfullscreen.tsx +0 -113
- package/src/components/experimentprovider.tsx +0 -69
- package/src/components/experimentrunner.tsx +0 -497
- package/src/components/mobilefilepermission.tsx +0 -68
- package/src/components/settingsscreen.tsx +0 -770
- package/src/types/array.d.ts +0 -6
- package/src/utils/audiodevice.ts +0 -4
- package/src/utils/bytecode.ts +0 -261
- package/src/utils/common.ts +0 -291
- package/src/utils/ddm.test.ts +0 -233
- package/src/utils/distributions.test.ts +0 -209
- package/src/utils/nodecompat.ts +0 -11
- package/src/utils/overlays.ts +0 -19
- package/src/utils/request.ts +0 -25
- package/src/utils/simulation.ts +0 -299
- package/src/utils/upload.ts +0 -275
- package/src/vite-env.d.ts +0 -1
- package/template/.env.template +0 -2
- package/template/.eslintrc.cjs +0 -18
- package/template/.prettierrc +0 -5
- package/template/backend/package-lock.json +0 -2544
- package/template/backend/package.json +0 -31
- package/template/backend/src/backend.ts +0 -131
- package/template/backend/tsconfig.json +0 -110
- package/template/capacitor.config.ts +0 -15
- package/template/electron/main.js +0 -131
- package/template/electron/preload.js +0 -9
- package/template/electron.vite.config.js +0 -45
- package/template/package-lock.json +0 -12467
- package/template/postcss.config.js +0 -5
- package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-Bold.ttf +0 -0
- package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-BoldItalic.ttf +0 -0
- package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-Italic.ttf +0 -0
- package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-Regular.ttf +0 -0
- package/template/shared.vite.config.js +0 -39
- package/template/src/vite-env.d.ts +0 -2
- package/template/tsconfig.node.json +0 -12
- package/template/vite.config.js +0 -11
- package/tsconfig.json +0 -30
- package/tsconfig.node.json +0 -12
- package/vite.config.ts +0 -39
- /package/{template → extras}/transcription/Dockerfile.cpu +0 -0
- /package/{template → extras}/transcription/Dockerfile.gpu +0 -0
- /package/{template/public/Atkinson_Hyperlegible → src/fonts}/OFL.txt +0 -0
package/src/utils/tts.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
// Runs a shell command without blocking, so that participants simulated at the same time do not wait for each other
|
|
2
|
+
function run(command: string): Promise<string> {
|
|
3
|
+
const { exec } = process.getBuiltinModule('child_process');
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
exec(command, { encoding: 'utf8' }, (error, stdout) => (error ? reject(error) : resolve(stdout)));
|
|
6
|
+
});
|
|
7
|
+
}
|
|
2
8
|
|
|
3
9
|
/**
|
|
4
10
|
* Generates a WebM audio file from text using the platform's native TTS.
|
|
@@ -12,13 +18,10 @@ import { getNodeRequire } from './nodecompat';
|
|
|
12
18
|
*/
|
|
13
19
|
export async function textToWebmBase64(text: string): Promise<string | null> {
|
|
14
20
|
try {
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const fs: typeof import('fs') = req('fs');
|
|
19
|
-
const os: typeof import('os') = req('os');
|
|
21
|
+
const path = process.getBuiltinModule('path');
|
|
22
|
+
const fs = process.getBuiltinModule('fs');
|
|
23
|
+
const os = process.getBuiltinModule('os');
|
|
20
24
|
|
|
21
|
-
const { execSync } = childProcess;
|
|
22
25
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'reactive-tts-'));
|
|
23
26
|
const wavPath = path.join(dir, 'tts.wav');
|
|
24
27
|
const webmPath = path.join(dir, 'tts.webm');
|
|
@@ -29,29 +32,27 @@ export async function textToWebmBase64(text: string): Promise<string | null> {
|
|
|
29
32
|
if (platform === 'darwin') {
|
|
30
33
|
let voice = '';
|
|
31
34
|
try {
|
|
32
|
-
const voices =
|
|
35
|
+
const voices = await run('say -v "?"');
|
|
33
36
|
if (voices.includes('Ava')) voice = '-v "Ava (Premium)"';
|
|
34
37
|
} catch { /* use default */ }
|
|
35
|
-
|
|
38
|
+
await run(`say ${voice} -o "${wavPath}" --data-format=LEI16@22050 "${escaped}"`);
|
|
36
39
|
} else if (platform === 'win32') {
|
|
37
40
|
const ps = `Add-Type -AssemblyName System.Speech; $s = New-Object System.Speech.Synthesis.SpeechSynthesizer; $s.SetOutputToWaveFile('${wavPath.replace(/'/g, "''")}'); $s.Speak('${escaped.replace(/'/g, "''")}'); $s.Dispose()`;
|
|
38
|
-
|
|
41
|
+
await run(`powershell -Command "${ps.replace(/"/g, '\\"')}"`);
|
|
39
42
|
} else {
|
|
40
43
|
try {
|
|
41
|
-
|
|
44
|
+
await run(`espeak-ng -w "${wavPath}" "${escaped}"`);
|
|
42
45
|
} catch {
|
|
43
|
-
|
|
46
|
+
await run(`espeak -w "${wavPath}" "${escaped}"`);
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
49
|
|
|
47
|
-
|
|
50
|
+
await run(`ffmpeg -i "${wavPath}" -c:a libopus -b:a 24k "${webmPath}" -y`);
|
|
48
51
|
|
|
49
52
|
const webmData = fs.readFileSync(webmPath);
|
|
50
53
|
const base64 = webmData.toString('base64');
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
try { fs.unlinkSync(webmPath); } catch { /* ignore */ }
|
|
54
|
-
try { fs.rmdirSync(dir); } catch { /* ignore */ }
|
|
55
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
55
56
|
|
|
56
57
|
return base64;
|
|
57
58
|
} catch {
|
|
@@ -65,16 +66,15 @@ export async function textToWebmBase64(text: string): Promise<string | null> {
|
|
|
65
66
|
*/
|
|
66
67
|
export async function probeAudioDurationMs(base64Audio: string): Promise<number | null> {
|
|
67
68
|
try {
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
const path = req('path') as typeof import('path');
|
|
72
|
-
const os = req('os') as typeof import('os');
|
|
69
|
+
const fs = process.getBuiltinModule('fs');
|
|
70
|
+
const path = process.getBuiltinModule('path');
|
|
71
|
+
const os = process.getBuiltinModule('os');
|
|
73
72
|
|
|
74
|
-
const
|
|
73
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'reactive-probe-'));
|
|
74
|
+
const tmp = path.join(dir, 'audio.webm');
|
|
75
75
|
fs.writeFileSync(tmp, Buffer.from(base64Audio, 'base64'));
|
|
76
|
-
const out =
|
|
77
|
-
fs.
|
|
76
|
+
const out = (await run(`ffprobe -v error -show_entries format=duration -of csv=p=0 "${tmp}"`)).trim();
|
|
77
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
78
78
|
return Math.round(parseFloat(out) * 1000);
|
|
79
79
|
} catch {
|
|
80
80
|
return null;
|
package/template/.dockerignore
CHANGED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Copy this file to .env.production for the deployed study, and to .env.development for running it on your computer.
|
|
2
|
+
# Git ignores both. Variables starting with PUBLIC_ end up in the experiment's code, all others only reach server.ts.
|
|
3
|
+
PUBLIC_PROLIFIC_CODE=""
|
|
4
|
+
PUBLIC_DISABLE_SETTINGS=FALSE
|
|
5
|
+
PUBLIC_DISABLE_DEV=FALSE
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Deploys the study to a study-deploy server on every push to main, if the repository has the secret DEPLOY_TOKEN (see README.md).
|
|
2
|
+
name: Deploy
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
push:
|
|
6
|
+
branches: [main]
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
concurrency: deploy
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
deploy:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v5
|
|
17
|
+
- uses: oven-sh/setup-bun@v2
|
|
18
|
+
- run: bun install
|
|
19
|
+
- run: |
|
|
20
|
+
if [ -z "$DEPLOY_TOKEN" ]; then echo "There is no DEPLOY_TOKEN secret, so nothing is deployed."; exit 0; fi
|
|
21
|
+
if [ -n "$DOTENV" ]; then echo "$DOTENV" > .env.production; fi
|
|
22
|
+
bun run deploy
|
|
23
|
+
env:
|
|
24
|
+
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
|
|
25
|
+
DOTENV: ${{ secrets.DOTENV }}
|
package/template/Dockerfile
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
FROM
|
|
1
|
+
FROM oven/bun:1-alpine AS build
|
|
2
2
|
WORKDIR /app
|
|
3
|
-
COPY package*.json ./
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
COPY package.json bun.lock* ./
|
|
5
|
+
RUN bun install
|
|
6
6
|
|
|
7
7
|
COPY . .
|
|
8
|
-
RUN
|
|
8
|
+
RUN bun run build:production
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
FROM
|
|
11
|
+
FROM oven/bun:1-distroless
|
|
12
12
|
WORKDIR /app
|
|
13
13
|
|
|
14
|
-
COPY
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
COPY backend/ ./
|
|
18
|
-
RUN npm run build
|
|
19
|
-
RUN npm install -g pm2
|
|
20
|
-
|
|
21
|
-
COPY --from=frontend-builder /app/dist ./static
|
|
14
|
+
COPY --from=build /app/dist-server ./
|
|
15
|
+
COPY --from=build /app/public ./public
|
|
22
16
|
|
|
23
17
|
EXPOSE 8001
|
|
24
18
|
|
|
25
|
-
|
|
19
|
+
# The image's entrypoint is bun
|
|
20
|
+
CMD ["server.js"]
|
package/template/README.md
CHANGED
|
@@ -2,87 +2,93 @@
|
|
|
2
2
|
|
|
3
3
|
Built with [reactive](https://github.com/adriansteffan/reactive)
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Setup
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
To install the needed dependencies, run the following in the root directory:
|
|
7
|
+
Install [Bun](https://bun.sh/), then run in the root directory:
|
|
10
8
|
|
|
11
9
|
```
|
|
12
|
-
|
|
10
|
+
bun install
|
|
13
11
|
```
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
### Project layout
|
|
14
|
+
|
|
15
|
+
- `src/Experiment.tsx`: the experiment
|
|
16
|
+
- `public/`: static files, served from the site root (`public/images/cat.png` is available at `/images/cat.png`)
|
|
17
|
+
- `server.ts`: serves the experiment and the route that saves uploaded data, which comes from the library (`uploadRoutes`); add your own routes to `api`, which components reach at `getBackendUrl()` (also in simulations)
|
|
18
|
+
- `.env.production`: the settings for the deployed study, such as the Prolific completion code
|
|
19
|
+
- `.env.development`: the settings for running the study on your computer, read by `bun run dev`, `start`, `build` and `simulate`
|
|
20
|
+
- `.env.example`: the settings to copy into these two files, which git ignores. Variables starting with `PUBLIC_` are compiled into the experiment, where every participant could read them. All others, such as API keys, only reach your routes in `server.ts`. Both are read as `process.env.NAME`, which is `undefined` if it is not set. Avoid `.env` and `.env.local` for them, since Bun reads those on your computer and in deployments alike.
|
|
21
|
+
- `data/`: uploaded data
|
|
22
|
+
- `data_download/`: data downloaded from a study-deploy server
|
|
16
23
|
|
|
17
24
|
## Target: Web (Online Experiment)
|
|
18
25
|
|
|
19
|
-
This is the version of the experiment you should use if your testing devices have internet access and don't need any device-specific functionalities (e.g. sensors). The web version will work on all platforms!
|
|
26
|
+
This is the version of the experiment you should use if your testing devices have internet access and don't need any device-specific functionalities (e.g. sensors). The web version will work on all platforms!
|
|
20
27
|
|
|
21
28
|
### Development
|
|
22
29
|
|
|
23
|
-
The web version of the experiment needs no additional setup for development.
|
|
24
|
-
|
|
25
|
-
Run the app in development mode with
|
|
26
|
-
|
|
27
30
|
```
|
|
28
|
-
|
|
31
|
+
bun run dev
|
|
29
32
|
```
|
|
30
|
-
in the root directory.
|
|
31
|
-
|
|
32
|
-
By default, open [http://localhost:5173](http://localhost:5173) to view it in the browser.
|
|
33
|
-
The page will reload if you make edits.
|
|
34
33
|
|
|
34
|
+
Open [http://localhost:8001](http://localhost:8001). The page updates as you edit.
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
`bun run start` serves the production version locally, and `bun run typecheck` and `bun run lint` check the code. Linting and formatting use [Biome](https://biomejs.dev/), which has an editor extension.
|
|
37
37
|
|
|
38
|
+
### Deployment
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
You will need a server with [Docker](https://docs.docker.com/engine/install/) and Docker Compose 2.24 or newer. In the root directory, start the app with
|
|
40
41
|
|
|
41
42
|
```
|
|
42
|
-
|
|
43
|
+
docker compose up -d --build
|
|
43
44
|
```
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
and stop it with `docker compose down`. To update, run `git pull` and start it again with the same command.
|
|
46
47
|
|
|
48
|
+
The settings page and the `?dev=true` panel are available in the deployed study too. To turn one off, set `PUBLIC_DISABLE_SETTINGS` or `PUBLIC_DISABLE_DEV` to `TRUE` in `.env.production`.
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
The app listens on port 8001 (see `docker-compose.yaml`). Expose it with a reverse proxy (Apache Virtualhosts or Nginx Server Blocks); [this guide](https://gist.github.com/adriansteffan/48c9bda7237a8a7fcc5bb6987c8e1790) explains how for our setup. Since `.env.production` is not committed, copy it into the clone on the server yourself, and start the app with the same command again whenever it changes.
|
|
50
51
|
|
|
51
|
-
|
|
52
|
+
Uploaded data is stored in `data/` in the root directory of the cloned repo.
|
|
52
53
|
|
|
54
|
+
### Deploying to a study-deploy server
|
|
53
55
|
|
|
54
|
-
|
|
56
|
+
If you have access to a [study-deploy](https://github.com/adriansteffan/study-deploy) server, deploy the study with
|
|
55
57
|
|
|
56
58
|
```
|
|
57
|
-
|
|
59
|
+
bun run deploy
|
|
58
60
|
```
|
|
59
61
|
|
|
60
|
-
|
|
62
|
+
This builds the study with the settings in `.env.production` and uploads it. The first time, it asks for
|
|
63
|
+
|
|
64
|
+
- the server's address and the subdomain the study should get (up to 32 lowercase letters, digits and dashes), and saves both in `package.json` under `studyDeploy`. Commit them, so that GitHub can deploy there too.
|
|
65
|
+
- your token for the server, and saves it in `~/.config/study-deploy/tokens.json` on your computer, for all your studies
|
|
61
66
|
|
|
62
|
-
|
|
67
|
+
The study is then served at `https://<subdomain>.<domain>`. Only the user who deployed it first can deploy it again, so collaborators cannot use their own tokens for it. To change the subdomain, edit it in `package.json` and deploy again. The study also stays online under the old one.
|
|
63
68
|
|
|
64
|
-
|
|
69
|
+
Download the data with
|
|
65
70
|
|
|
66
71
|
```
|
|
67
|
-
|
|
72
|
+
bun run download
|
|
68
73
|
```
|
|
69
74
|
|
|
70
|
-
|
|
75
|
+
It is saved in `data_download/`, apart from the sessions you ran on your computer. Running it again adds new data and overwrites the files downloaded before.
|
|
76
|
+
|
|
77
|
+
Take the study offline with
|
|
71
78
|
|
|
72
79
|
```
|
|
73
|
-
|
|
80
|
+
bun run undeploy
|
|
74
81
|
```
|
|
75
82
|
|
|
76
|
-
|
|
77
|
-
Use Virtualhosts (Apache) or Server Blocks (Nginx) with reverse proxy to expose these to the outside. [This guide](https://gist.github.com/adriansteffan/48c9bda7237a8a7fcc5bb6987c8e1790) explains how to do this for our setup.
|
|
78
|
-
|
|
79
|
-
#### Updating
|
|
83
|
+
This also deletes its data on the server, so download it first. It asks for confirmation, and only deletes the study under the subdomain in `package.json`.
|
|
80
84
|
|
|
81
|
-
|
|
85
|
+
GitHub can also deploy on every push to `main`, using `.github/workflows/deploy.yml`. Deploy from your computer once and commit `package.json`. Then, with the [GitHub CLI](https://cli.github.com) installed and logged in, run
|
|
82
86
|
|
|
83
|
-
|
|
87
|
+
```
|
|
88
|
+
bun run ghsetup
|
|
89
|
+
```
|
|
84
90
|
|
|
85
|
-
|
|
91
|
+
This saves your token and the contents of `.env.production` as the repository's secrets `DEPLOY_TOKEN` and `DOTENV`. Run it again whenever you change `.env.production`, since the next push would otherwise deploy the old values. Anyone with write access to the repository can read the secrets, so only do this where you trust every collaborator.
|
|
86
92
|
|
|
87
93
|
|
|
88
94
|
## Simulation
|
|
@@ -91,238 +97,92 @@ You can simulate your experiment headlessly to generate synthetic data, test you
|
|
|
91
97
|
|
|
92
98
|
### Setup
|
|
93
99
|
|
|
94
|
-
Define your participant generator
|
|
100
|
+
Define your participant generator in the `simulation` field of `defineExperiment` in `Experiment.tsx`:
|
|
95
101
|
|
|
96
102
|
```tsx
|
|
97
|
-
export
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
count: 10,
|
|
103
|
+
export default defineExperiment({
|
|
104
|
+
simulation: {
|
|
105
|
+
createParticipants: () => Array.from({ length: 10 }, (_, i) => ({ id: i, nickname: `participant_${i}` })),
|
|
101
106
|
},
|
|
102
|
-
}
|
|
107
|
+
timeline: ({ clicks }) => [ ... ],
|
|
108
|
+
});
|
|
103
109
|
```
|
|
104
110
|
|
|
105
111
|
### Running
|
|
106
112
|
|
|
107
113
|
```
|
|
108
|
-
|
|
114
|
+
bun run simulate
|
|
109
115
|
```
|
|
110
116
|
|
|
111
|
-
This starts the backend, simulates all participants through the experiment, and shuts down. The simulated data ends up in `
|
|
117
|
+
This starts the backend, simulates all participants through the experiment, and shuts down. The simulated data ends up in `data/`.
|
|
112
118
|
|
|
113
119
|
### Customizing participant behavior
|
|
114
120
|
|
|
115
|
-
Each trial component has default decision functions that model participant behavior. Override them per
|
|
121
|
+
Each trial component has default decision functions that model participant behavior. Override them per trial with `.simulators()`:
|
|
116
122
|
|
|
117
123
|
```tsx
|
|
118
|
-
{
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
simulators: {
|
|
122
|
-
respond: (_trialProps, participant) => ({
|
|
123
|
-
value: participant.nickname,
|
|
124
|
-
participantState: participant,
|
|
125
|
-
}),
|
|
126
|
-
},
|
|
127
|
-
}
|
|
124
|
+
PlainInput.trial('name', { content: <p>What is your name?</p> }).simulators({
|
|
125
|
+
respond: ({ participant }) => ({ value: participant.nickname }),
|
|
126
|
+
}),
|
|
128
127
|
```
|
|
129
128
|
|
|
130
129
|
### Custom components
|
|
131
130
|
|
|
132
|
-
|
|
131
|
+
Give your custom components a simulation in their `defineComponent` call. See the `CustomTrial` example in `Experiment.tsx` and the [reactive README](https://github.com/adriansteffan/reactive) for details.
|
|
133
132
|
|
|
134
|
-
### Hybrid mode
|
|
135
133
|
|
|
136
|
-
|
|
134
|
+
## Transcription
|
|
137
135
|
|
|
138
|
-
|
|
136
|
+
Automatically transcribe voice recordings from experiment data using Docker. Requires [Docker](https://docs.docker.com/engine/install/) to be installed. The transcription setup is left out of new projects; add it in the root directory with
|
|
139
137
|
|
|
140
138
|
```
|
|
141
|
-
|
|
139
|
+
bunx @adriansteffan/reactive add transcription
|
|
142
140
|
```
|
|
143
141
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
## Transcription
|
|
148
|
-
|
|
149
|
-
Automatically transcribe voice recordings from experiment data using Docker. Requires [Docker](https://docs.docker.com/engine/install/) to be installed.
|
|
142
|
+
which creates `transcription/` and the scripts below.
|
|
150
143
|
|
|
151
144
|
### CPU (faster-whisper)
|
|
152
145
|
|
|
153
146
|
```
|
|
154
|
-
|
|
147
|
+
bun run transcribe
|
|
155
148
|
```
|
|
156
149
|
|
|
157
150
|
### GPU (qwen-asr, requires NVIDIA GPU)
|
|
158
151
|
|
|
159
152
|
```
|
|
160
|
-
|
|
153
|
+
bun run transcribe:gpu
|
|
161
154
|
```
|
|
162
155
|
|
|
163
156
|
### Options
|
|
164
157
|
|
|
165
158
|
```
|
|
166
|
-
|
|
167
|
-
|
|
159
|
+
bun run transcribe -- --overwrite # re-transcribe even if transcriptions.csv exists
|
|
160
|
+
bun run transcribe -- --model small # use a different model
|
|
168
161
|
```
|
|
169
162
|
|
|
170
|
-
Output: `transcriptions
|
|
171
|
-
|
|
163
|
+
Output: `transcriptions.<sessionId>.csv` in each session's data directory, wherever it is under `data/` or `data_download/`, with `filename,text` columns. The model is cached in a Docker volume, so it only downloads once.
|
|
172
164
|
|
|
173
|
-
## Target: Windows or MacOS
|
|
174
165
|
|
|
175
|
-
|
|
166
|
+
## Extra components
|
|
176
167
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
Run the app in the development mode with
|
|
168
|
+
Quest (SurveyJS questionnaires) and Tutorial (slide decks) need packages of their own, so they are left out until you add them:
|
|
180
169
|
|
|
181
170
|
```
|
|
182
|
-
|
|
171
|
+
bunx @adriansteffan/reactive add quest tutorial
|
|
183
172
|
```
|
|
184
|
-
in the root directory.
|
|
185
173
|
|
|
186
|
-
|
|
174
|
+
Then import them from `@adriansteffan/reactive/quest` and `@adriansteffan/reactive/tutorial`.
|
|
187
175
|
|
|
188
|
-
To build platform specific executables, run either
|
|
189
176
|
|
|
190
|
-
|
|
191
|
-
npm run package:mac
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
or
|
|
195
|
-
|
|
196
|
-
```
|
|
197
|
-
npm run package:win
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
There will be a directory called "release" that will contain your executables.
|
|
201
|
-
|
|
202
|
-
#### Where is my data stored?
|
|
203
|
-
|
|
204
|
-
* Windows:
|
|
205
|
-
* On windows, a folder called "data" is created next the executable as soon as the first participant has completed the study
|
|
206
|
-
|
|
207
|
-
* MacOS:
|
|
208
|
-
* Right click on the application and go to TODO > TODO > TODO, where a folder called "data" is created as soon as the first participant has completed the study
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
## Target: Android
|
|
213
|
-
|
|
214
|
-
For ease of use, it makes sense to run the web version for most of the development and only switch to the specific device emulators for implementing device-specific features and testing compatibility before packaging.
|
|
215
|
-
|
|
216
|
-
### Setup
|
|
217
|
-
|
|
218
|
-
To build and test an Adroid app containing your experiment, you will need an installation of
|
|
219
|
-
[Android Studio](https://developer.android.com/studio) and [Java 21 or later](https://www.oracle.com/de/java/technologies/downloads/)
|
|
220
|
-
|
|
221
|
-
To set up the android project, run this command in the root directory:
|
|
222
|
-
```
|
|
223
|
-
npx cap add android
|
|
224
|
-
````
|
|
225
|
-
|
|
226
|
-
Next, find the [path to your local android sdk](https://stackoverflow.com/questions/25176594/android-sdk-location) and create a `local.properties` file in the `android` folder with the following content:
|
|
227
|
-
|
|
228
|
-
```
|
|
229
|
-
sdk.dir=SDK_PATH_HERE
|
|
230
|
-
```
|
|
177
|
+
## Android and iOS apps
|
|
231
178
|
|
|
232
|
-
|
|
179
|
+
The experiment can also be packaged as an Android or iOS app that stores data on the device, e.g. for studies without a reliable internet connection. To add this, run
|
|
233
180
|
|
|
234
181
|
```
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
|
238
|
-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
|
239
|
-
|
|
240
|
-
<!-- For Android 10+ (API 29+) -->
|
|
241
|
-
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
|
|
242
|
-
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
|
|
243
|
-
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
|
|
244
|
-
|
|
245
|
-
<application
|
|
246
|
-
android:requestLegacyExternalStorage="true" // add this to the application tag
|
|
182
|
+
bunx @adriansteffan/reactive native
|
|
247
183
|
```
|
|
248
184
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
### Running
|
|
253
|
-
|
|
254
|
-
Whenever you have made changes to the code and want to run it on the Android emulator, run:
|
|
255
|
-
```
|
|
256
|
-
npm run build
|
|
257
|
-
npx cap sync
|
|
258
|
-
npx cap run android
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
### Packaging
|
|
262
|
-
|
|
263
|
-
From the root directory, run
|
|
264
|
-
|
|
265
|
-
```
|
|
266
|
-
npx cap open android
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
. Wait for Android Studio to install the project dependencies and then run Build > Generate APKs and Bundles > Generate APKs. Once your build is finished, there will be a popup guiding you to the location of the bundle's app that you can transfer to your Android device.
|
|
270
|
-
|
|
271
|
-
#### Where is my data stored?
|
|
272
|
-
|
|
273
|
-
In the "Internal Storage" section of the file browser, you will find a "Documents" folder that will contain subfolders with your data as soon as the first participant has finished the experiment.
|
|
274
|
-
|
|
275
|
-
## Target: iOS
|
|
276
|
-
|
|
277
|
-
For ease of use, it makes sense to run the web version for most of the development and only switch to the specific device emulators for implementing device-specific features and testing compatibility before packaging.
|
|
278
|
-
|
|
279
|
-
### Setup
|
|
280
|
-
|
|
281
|
-
To build an iOS app containing your experiment, you will need a machine running MacOS and an installation of [XCode](https://apps.apple.com/us/app/xcode/id497799835). Furthermore, you will need to install [CocoaPods](https://cocoapods.org/), which is most easily installed with [Homebrew](https://brew.sh/).
|
|
282
|
-
|
|
283
|
-
To set up the iOS project, run
|
|
284
|
-
|
|
285
|
-
```
|
|
286
|
-
npx cap add ios
|
|
287
|
-
```
|
|
288
|
-
|
|
289
|
-
Then, go to `iso > App > App > Info.plist`
|
|
290
|
-
|
|
291
|
-
And add these lines next to the other keys:
|
|
292
|
-
|
|
293
|
-
```
|
|
294
|
-
<key>UIFileSharingEnabled</key>
|
|
295
|
-
<string>YES</string>
|
|
296
|
-
<key>LSSupportsOpeningDocumentsInPlace</key>
|
|
297
|
-
<string>YES</string>
|
|
298
|
-
```
|
|
299
|
-
|
|
300
|
-
For more information, refer to the [Capacitor documentation on iOS](https://capacitorjs.com/docs/ios)
|
|
301
|
-
|
|
302
|
-
### Running
|
|
303
|
-
|
|
304
|
-
Whenever you have made changes to the code and want to run it on the iOS emulator, run:
|
|
305
|
-
|
|
306
|
-
```
|
|
307
|
-
npm run build
|
|
308
|
-
npx cap sync
|
|
309
|
-
npx cap run ios
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
### Packaging
|
|
313
|
-
|
|
314
|
-
Packaging iOS apps is quite an undertaking, which is why the process is not overly streamlined/documented yet. The best way to get your experiment on an iOS device right now is to run
|
|
315
|
-
|
|
316
|
-
```
|
|
317
|
-
npx cap run ios
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
which will open the finished project in XCode. From there, follow a guide on how to sign, bundle and install your app/experiment.
|
|
321
|
-
|
|
322
|
-
#### Where is my data stored?
|
|
323
|
-
|
|
324
|
-
After the first participant is run, a folder with the name of your app will appear under "My iPhone/iPad" in the files app, which contains your data.
|
|
325
|
-
|
|
185
|
+
in the root directory and follow the [setup instructions](https://github.com/adriansteffan/reactive#android-and-ios-apps).
|
|
326
186
|
|
|
327
187
|
|
|
328
188
|
## Authors
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
|
|
3
|
+
"vcs": {
|
|
4
|
+
"enabled": true,
|
|
5
|
+
"clientKind": "git",
|
|
6
|
+
"useIgnoreFile": true
|
|
7
|
+
},
|
|
8
|
+
"formatter": {
|
|
9
|
+
"indentStyle": "space",
|
|
10
|
+
"lineWidth": 100
|
|
11
|
+
},
|
|
12
|
+
"javascript": {
|
|
13
|
+
"formatter": {
|
|
14
|
+
"quoteStyle": "single",
|
|
15
|
+
"jsxQuoteStyle": "single"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"css": {
|
|
19
|
+
"parser": {
|
|
20
|
+
"tailwindDirectives": true
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"linter": {
|
|
24
|
+
"rules": {
|
|
25
|
+
"preset": "recommended",
|
|
26
|
+
"a11y": "off",
|
|
27
|
+
"complexity": "off",
|
|
28
|
+
"style": "off",
|
|
29
|
+
"suspicious": {
|
|
30
|
+
"noArrayIndexKey": "off"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Bundles the experiment for production: dist/ for Capacitor, dist-server/ for the Docker image
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import tailwind from 'bun-plugin-tailwind';
|
|
4
|
+
import publicDir from '@adriansteffan/reactive/bun-plugin';
|
|
5
|
+
|
|
6
|
+
const options = {
|
|
7
|
+
minify: true,
|
|
8
|
+
env: 'PUBLIC_*' as const,
|
|
9
|
+
define: { 'process.env.NODE_ENV': '"production"' },
|
|
10
|
+
plugins: [tailwind, publicDir],
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
fs.rmSync('dist', { recursive: true, force: true });
|
|
14
|
+
fs.rmSync('dist-server', { recursive: true, force: true });
|
|
15
|
+
|
|
16
|
+
await Bun.build({ ...options, entrypoints: ['./index.html'], outdir: 'dist' });
|
|
17
|
+
fs.cpSync('public', 'dist', { recursive: true });
|
|
18
|
+
|
|
19
|
+
// The server bundle includes the frontend, so the image needs no node_modules
|
|
20
|
+
await Bun.build({ ...options, entrypoints: ['./server.ts'], target: 'bun', outdir: 'dist-server' });
|