mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
add extension docs
This commit is contained in:
parent
98a4dcc27d
commit
2e1757192c
62
docs/demos/jspsych-extension-record-video-demo1.html
Normal file
62
docs/demos/jspsych-extension-record-video-demo1.html
Normal file
@ -0,0 +1,62 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<script src="docs-demo-timeline.js"></script>
|
||||
<script src="../../packages/jspsych/dist/index.browser.js"></script>
|
||||
<!--<script src="https://unpkg.com/jspsych@7.2.3"></script>-->
|
||||
<script src="https://unpkg.com/@jspsych/plugin-html-button-response@1.1.1"></script>
|
||||
<script src="../../packages/extension-record-video/dist/index.browser.js"></script>
|
||||
<!--<script src="https://unpkg.com/@jspsych/extension-record-video@1.0.0"></script>-->
|
||||
<script src="../../packages/plugin-initialize-camera/dist/index.browser.js"></script>
|
||||
<!--<script src="https://unpkg.com/@jspsych/plugin-initialize-camera@1.0.0"></script>-->
|
||||
<link rel="stylesheet" href="https://unpkg.com/jspsych@7.2.3/css/jspsych.css" />
|
||||
<link rel="stylesheet" href="docs-demo.css" type="text/css">
|
||||
</head>
|
||||
<body></body>
|
||||
<script>
|
||||
|
||||
const jsPsych = initJsPsych({
|
||||
extensions: [
|
||||
{ type: jsPsychExtensionRecordVideo}
|
||||
]
|
||||
});
|
||||
|
||||
const init_camera = {
|
||||
type: jsPsychInitializeCamera
|
||||
};
|
||||
|
||||
const trial = {
|
||||
type: jsPsychHtmlButtonResponse,
|
||||
stimulus: `<div id="target" style="width:250px; height: 250px; background-color: #333; position: relative; margin: 2em auto;">
|
||||
<div class="orbit" style="width:25px; height:25px; border-radius:25px;background-color: #f00; position: absolute; top:calc(50% - 12px); left:calc(50% - 12px);"></div>
|
||||
</div>
|
||||
<style>
|
||||
.orbit {
|
||||
transform: translateX(100px);
|
||||
animation: orbit 4s infinite;
|
||||
}
|
||||
@keyframes orbit {
|
||||
0% {
|
||||
transform: rotate(0deg) translateX(100px);
|
||||
}
|
||||
100% {
|
||||
transform: rotate(360deg) translateX(100px);
|
||||
}
|
||||
}
|
||||
</style>`,
|
||||
choices: ['Done'],
|
||||
prompt: "<p>Video is recording. Click done after a few seconds.</p>",
|
||||
extensions: [
|
||||
{type: jsPsychExtensionRecordVideo}
|
||||
]
|
||||
};
|
||||
|
||||
const timeline = [init_camera, trial];
|
||||
|
||||
if (typeof jsPsych !== "undefined") {
|
||||
jsPsych.run(generateDocsDemoTimeline(timeline));
|
||||
} else {
|
||||
document.body.innerHTML = '<div style="text-align:center; margin-top:50%; transform:translate(0,-50%);">You must be online to view the plugin demo.</div>';
|
||||
}
|
||||
</script>
|
||||
</html>
|
90
docs/extensions/record-video.md
Normal file
90
docs/extensions/record-video.md
Normal file
@ -0,0 +1,90 @@
|
||||
# record-video
|
||||
|
||||
This extension records video from the participant's webcam during a trial.
|
||||
|
||||
This extension encodes the video data in [base 64 format](https://developer.mozilla.org/en-US/docs/Glossary/Base64).
|
||||
This is a text-based representation of the video which can be coverted to various video formats using a variety of [online tools](https://www.google.com/search?q=base64+video+decoder) as well as in languages like python and R.
|
||||
|
||||
## Parameters
|
||||
|
||||
### Initialization Parameters
|
||||
|
||||
Initialization parameters can be set when calling `initJsPsych()`
|
||||
|
||||
```js
|
||||
initJsPsych({
|
||||
extensions: [
|
||||
{type: jsPsychExtensionRecordVideo, params: {...}}
|
||||
]
|
||||
})
|
||||
```
|
||||
|
||||
Parameter | Type | Default Value | Description
|
||||
----------|------|---------------|------------
|
||||
|
||||
|
||||
### Trial Parameters
|
||||
|
||||
Trial parameters can be set when adding the extension to a trial object.
|
||||
|
||||
```js
|
||||
var trial = {
|
||||
type: jsPsych...,
|
||||
extensions: [
|
||||
{type: jsPsychExtensionRecordVideo, params: {...}}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Parameter | Type | Default Value | Description
|
||||
----------|------|---------------|------------
|
||||
|
||||
|
||||
## Data Generated
|
||||
|
||||
Name | Type | Value
|
||||
-----|------|------
|
||||
record_video_data | base64 string | [Base 64 encoded](https://developer.mozilla.org/en-US/docs/Glossary/Base64) representation of the video data.
|
||||
|
||||
## Examples
|
||||
|
||||
???+ example "Record video data during a trial"
|
||||
=== "Code"
|
||||
```javascript
|
||||
const init_camera = {
|
||||
type: jsPsychInitializeCamera
|
||||
};
|
||||
|
||||
const trial = {
|
||||
type: jsPsychHtmlButtonResponse,
|
||||
stimulus: `<div id="target" style="width:250px; height: 250px; background-color: #333; position: relative; margin: 2em auto;">
|
||||
<div class="orbit" style="width:25px; height:25px; border-radius:25px;background-color: #f00; position: absolute; top:calc(50% - 12px); left:calc(50% - 12px);"></div>
|
||||
</div>
|
||||
<style>
|
||||
.orbit {
|
||||
transform: translateX(100px);
|
||||
animation: orbit 4s infinite;
|
||||
}
|
||||
@keyframes orbit {
|
||||
0% {
|
||||
transform: rotate(0deg) translateX(100px);
|
||||
}
|
||||
100% {
|
||||
transform: rotate(360deg) translateX(100px);
|
||||
}
|
||||
}
|
||||
</style>`,
|
||||
choices: ['Done'],
|
||||
prompt: "<p>Video is recording. Click done after a few seconds.</p>",
|
||||
extensions: [
|
||||
{type: jsPsychExtensionRecordVideo}
|
||||
]
|
||||
};
|
||||
```
|
||||
|
||||
=== "Demo"
|
||||
<div style="text-align:center;">
|
||||
<iframe src="../../demos/jspsych-extension-record-video-demo1.html" width="90%;" height="500px;" frameBorder="0"></iframe>
|
||||
</div>
|
||||
|
||||
<a target="_blank" rel="noopener noreferrer" href="../../demos/jspsych-extension-record-video-demo1.html">Open demo in new tab</a>
|
Loading…
Reference in New Issue
Block a user