Skip to content

Commit

Permalink
Changed jsPsych and extensions to read version and name from class
Browse files Browse the repository at this point in the history
  • Loading branch information
Bankminer78 committed Jul 18, 2024
1 parent b94d961 commit 81ed9ad
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
2 changes: 0 additions & 2 deletions packages/extension-mouse-tracking/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ class MouseTrackingExtension implements JsPsychExtension {
}

return {
extension_type: "mouse-tracking",
extension_version: version,
mouse_tracking_data: this.currentTrialData,
mouse_tracking_targets: Object.fromEntries(this.currentTrialTargets.entries()),
};
Expand Down
12 changes: 2 additions & 10 deletions packages/extension-record-video/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,10 @@ class RecordVideoExtension implements JsPsychExtension {

if (!this.currentTrialData.record_video_data) {
this.onUpdateCallback = () => {
resolve({
extension_type: "record-video",
extension_version: version,
...this.currentTrialData,
});
resolve(this.currentTrialData);
};
} else {
resolve({
extension_type: "record-video",
extension_version: version,
...this.currentTrialData,
});
resolve(this.currentTrialData);
}
});
};
Expand Down
2 changes: 0 additions & 2 deletions packages/extension-webgazer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ class WebGazerExtension implements JsPsychExtension {

// send back the gazeData
return {
extension_type: "webgazer",
extension_version: version,
webgazer_data: this.currentTrialData,
webgazer_targets: this.currentTrialTargets,
};
Expand Down
33 changes: 26 additions & 7 deletions packages/jspsych/src/ExtensionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,28 @@ export class ExtensionManager {

public async initializeExtensions() {
await Promise.all(
this.extensionsConfiguration.map(({ type, params = {} }) =>
this.getExtensionInstanceByClass(type).initialize(params)
)
this.extensionsConfiguration.map(({ type, params = {} }) => {
this.getExtensionInstanceByClass(type).initialize(params);

const extensionInfo = type["info"] as JsPsychExtensionInfo;

if (!("version" in extensionInfo) && !("data" in extensionInfo)) {
console.warn(
extensionInfo["name"],
"is missing the 'version' and 'data' fields. Please update extension as 'version' and 'data' will be required in v9. See https://www.jspsych.org/latest/developers/extension-development/ for more details."
);
} else if (!("version" in extensionInfo)) {
console.warn(
extensionInfo["name"],
"is missing the 'version' field. Please update extension as 'version' will be required in v9. See https://www.jspsych.org/latest/developers/extension-development/ for more details."
);
} else if (!("data" in extensionInfo)) {
console.warn(
extensionInfo["name"],
"is missing the 'data' field. Please update extension as 'data' will be required in v9. See https://www.jspsych.org/latest/developers/extension-development/ for more details."
);
}
})
);
}

Expand All @@ -67,14 +86,14 @@ export class ExtensionManager {
)
);

const extensionInfo = trialExtensionsConfiguration.length
const extensionInfos = trialExtensionsConfiguration.length
? {
extension_type: results.map((result) => result.extension_type),
extension_version: results.map((result) => result.extension_version),
extension_type: trialExtensionsConfiguration.map(({ type }) => type["info"].name),
extension_version: trialExtensionsConfiguration.map(({ type }) => type["info"].version),
}
: {};

results.push(extensionInfo);
results.push(extensionInfos);

return Object.assign({}, ...results);
}
Expand Down

0 comments on commit 81ed9ad

Please sign in to comment.