jspsych 8.2.1 → 8.2.3
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 +1 -1
- package/dist/index.browser.js +95 -3
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.min.js +7 -7
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.cjs +94 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +94 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/modules/plugin-api/MediaAPI.ts +28 -1
- package/src/modules/plugins.ts +1 -0
- package/src/timeline/Trial.spec.ts +105 -1
- package/src/timeline/Trial.ts +78 -0
package/dist/index.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ type ParameterInfo = ({
|
|
|
50
50
|
array?: boolean;
|
|
51
51
|
pretty_name?: string;
|
|
52
52
|
default?: any;
|
|
53
|
+
options?: any;
|
|
53
54
|
};
|
|
54
55
|
type ParameterInfos = Record<string, ParameterInfo>;
|
|
55
56
|
type InferredParameter<I extends ParameterInfo> = I["array"] extends true ? Array<ParameterTypeMap[I["type"]]> : ParameterTypeMap[I["type"]];
|
|
@@ -666,6 +667,8 @@ declare class MediaAPI {
|
|
|
666
667
|
private camera_stream;
|
|
667
668
|
private camera_recorder;
|
|
668
669
|
initializeCameraRecorder(stream: MediaStream, opts?: MediaRecorderOptions): void;
|
|
670
|
+
/** returns a compatible mimetype string, or null if none from the array are supported. */
|
|
671
|
+
private getCompatibleMimeType;
|
|
669
672
|
getCameraStream(): MediaStream;
|
|
670
673
|
getCameraRecorder(): MediaRecorder;
|
|
671
674
|
}
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import autoBind from 'auto-bind';
|
|
|
2
2
|
import rw from 'random-words';
|
|
3
3
|
import seedrandom from 'seedrandom/lib/alea.js';
|
|
4
4
|
|
|
5
|
-
var version = "8.2.
|
|
5
|
+
var version = "8.2.3";
|
|
6
6
|
|
|
7
7
|
class ExtensionManager {
|
|
8
8
|
constructor(dependencies, extensionsConfiguration) {
|
|
@@ -967,10 +967,35 @@ class MediaAPI {
|
|
|
967
967
|
return this.microphone_recorder;
|
|
968
968
|
}
|
|
969
969
|
initializeCameraRecorder(stream, opts) {
|
|
970
|
+
let mimeType = this.getCompatibleMimeType() || "video/webm";
|
|
971
|
+
const recorderOptions = {
|
|
972
|
+
...opts,
|
|
973
|
+
mimeType
|
|
974
|
+
};
|
|
970
975
|
this.camera_stream = stream;
|
|
971
|
-
const recorder = new MediaRecorder(stream,
|
|
976
|
+
const recorder = new MediaRecorder(stream, recorderOptions);
|
|
972
977
|
this.camera_recorder = recorder;
|
|
973
978
|
}
|
|
979
|
+
// mimetype checking code adapted from https://github.com/lookit/lookit-jspsych/blob/develop/packages/record/src/videoConfig.ts#L673-L699
|
|
980
|
+
/** returns a compatible mimetype string, or null if none from the array are supported. */
|
|
981
|
+
getCompatibleMimeType() {
|
|
982
|
+
const types = [
|
|
983
|
+
// chrome firefox edge
|
|
984
|
+
"video/webm;codecs=vp9,opus",
|
|
985
|
+
"video/webm;codecs=vp8,opus",
|
|
986
|
+
// general
|
|
987
|
+
"video/mp4;codecs=avc1.42E01E,mp4a.40.2",
|
|
988
|
+
// safari
|
|
989
|
+
"video/mp4;codecs=h264,aac",
|
|
990
|
+
"video/mp4;codecs=hevc,aac"
|
|
991
|
+
];
|
|
992
|
+
for (const mimeType of types) {
|
|
993
|
+
if (MediaRecorder.isTypeSupported(mimeType)) {
|
|
994
|
+
return mimeType;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
return null;
|
|
998
|
+
}
|
|
974
999
|
getCameraStream() {
|
|
975
1000
|
return this.camera_stream;
|
|
976
1001
|
}
|
|
@@ -2039,6 +2064,73 @@ class Trial extends TimelineNode {
|
|
|
2039
2064
|
}
|
|
2040
2065
|
}
|
|
2041
2066
|
});
|
|
2067
|
+
if (!parameterConfig.array && parameterValue !== null) {
|
|
2068
|
+
switch (parameterConfig.type) {
|
|
2069
|
+
case ParameterType.BOOL:
|
|
2070
|
+
if (typeof parameterValue !== "boolean") {
|
|
2071
|
+
const parameterPathString = parameterPathArrayToString(parameterPath);
|
|
2072
|
+
console.warn(
|
|
2073
|
+
`A non-boolean value (\`${parameterValue}\`) was provided for the boolean parameter "${parameterPathString}" in the "${this.pluginInfo.name}" plugin.`
|
|
2074
|
+
);
|
|
2075
|
+
}
|
|
2076
|
+
break;
|
|
2077
|
+
// @ts-ignore falls through
|
|
2078
|
+
case ParameterType.KEYS:
|
|
2079
|
+
if (Array.isArray(parameterValue)) break;
|
|
2080
|
+
case ParameterType.STRING:
|
|
2081
|
+
case ParameterType.HTML_STRING:
|
|
2082
|
+
case ParameterType.KEY:
|
|
2083
|
+
case ParameterType.AUDIO:
|
|
2084
|
+
case ParameterType.VIDEO:
|
|
2085
|
+
case ParameterType.IMAGE:
|
|
2086
|
+
if (typeof parameterValue !== "string") {
|
|
2087
|
+
const parameterPathString = parameterPathArrayToString(parameterPath);
|
|
2088
|
+
console.warn(
|
|
2089
|
+
`A non-string value (\`${parameterValue}\`) was provided for the parameter "${parameterPathString}" in the "${this.pluginInfo.name}" plugin.`
|
|
2090
|
+
);
|
|
2091
|
+
}
|
|
2092
|
+
break;
|
|
2093
|
+
case ParameterType.FLOAT:
|
|
2094
|
+
case ParameterType.INT:
|
|
2095
|
+
if (typeof parameterValue !== "number") {
|
|
2096
|
+
const parameterPathString = parameterPathArrayToString(parameterPath);
|
|
2097
|
+
console.warn(
|
|
2098
|
+
`A non-numeric value (\`${parameterValue}\`) was provided for the numeric parameter "${parameterPathString}" in the "${this.pluginInfo.name}" plugin.`
|
|
2099
|
+
);
|
|
2100
|
+
}
|
|
2101
|
+
break;
|
|
2102
|
+
case ParameterType.FUNCTION:
|
|
2103
|
+
if (typeof parameterValue !== "function") {
|
|
2104
|
+
const parameterPathString = parameterPathArrayToString(parameterPath);
|
|
2105
|
+
console.warn(
|
|
2106
|
+
`A non-function value (\`${parameterValue}\`) was provided for the function parameter "${parameterPathString}" in the "${this.pluginInfo.name}" plugin.`
|
|
2107
|
+
);
|
|
2108
|
+
}
|
|
2109
|
+
break;
|
|
2110
|
+
case ParameterType.SELECT:
|
|
2111
|
+
if (!parameterConfig.options) {
|
|
2112
|
+
const parameterPathString = parameterPathArrayToString(parameterPath);
|
|
2113
|
+
console.warn(
|
|
2114
|
+
`The "options" array is required for the "select" parameter "${parameterPathString}" in the "${this.pluginInfo.name}" plugin.`
|
|
2115
|
+
);
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
if (parameterConfig.type === ParameterType.INT && parameterValue % 1 !== 0) {
|
|
2119
|
+
const parameterPathString = parameterPathArrayToString(parameterPath);
|
|
2120
|
+
console.warn(
|
|
2121
|
+
`A float value (\`${parameterValue}\`) was provided for the integer parameter "${parameterPathString}" in the "${this.pluginInfo.name}" plugin. The value will be truncated to an integer.`
|
|
2122
|
+
);
|
|
2123
|
+
parameterValue = Math.trunc(parameterValue);
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
if (parameterConfig.type === ParameterType.SELECT) {
|
|
2127
|
+
if (!parameterConfig.options.includes(parameterValue)) {
|
|
2128
|
+
const parameterPathString = parameterPathArrayToString(parameterPath);
|
|
2129
|
+
console.warn(
|
|
2130
|
+
`The value "${parameterValue}" is not a valid option for the parameter "${parameterPathString}" in the "${this.pluginInfo.name}" plugin. Valid options are: ${parameterConfig.options.join(", ")}.`
|
|
2131
|
+
);
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2042
2134
|
if (parameterConfig.array && !Array.isArray(parameterValue)) {
|
|
2043
2135
|
const parameterPathString = parameterPathArrayToString(parameterPath);
|
|
2044
2136
|
throw new Error(
|