lookit / lookit-jspsych

0 stars 0 forks source link

Add AWS S3 upload to Record extension #29

Closed becky-gilbert closed 4 months ago

becky-gilbert commented 5 months ago

This PR adds AWS S3 uploading to the lookit-jspsych record package (currently on the video branch).

Notes:

Trial recording example code:

const timeline = [];

const jsPsych = initJsPsych({
    extensions: [{
        type: chsRecord.TrialRecordExtension
    }]
});

const consent_survey = {
    type: chsSurvey.consent,
    survey_json: {
        elements: {
            type: "boolean",
            name: "consent",
            title: "This is a consent question. Click yes to continue.",
            required: true
        }
    },
    validation_function: function(_, options) {
        if (options.name === "consent") {
            if (!options.value) {
                options.error = "You must select 'Yes' to continue.";
            }
        }
    }
};

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: chsRecord.TrialRecordExtension
    }],
};

const exit_survey = {
    type: chsSurvey.exit,
}

timeline.push(consent_survey, init_camera, trial, exit_survey);

jsPsych.run(timeline);

Session recording example code:

const timeline = [];

const jsPsych = initJsPsych({});

const consent_survey = {
    type: chsSurvey.consent,
    survey_json: {
        elements: {
            type: "boolean",
            name: "consent",
            title: "This is a consent question. Click yes to continue.",
            required: true
        }
    },
    validation_function: function(_, options) {
        if (options.name === "consent") {
            if (!options.value) {
                options.error = "You must select 'Yes' to continue.";
            }
        }
    }
};

const init_camera = {
    type: jsPsychInitializeCamera
};

const start_rec = {
    type: chsRecord.StartRecordPlugin
};

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>"
};

const stop_rec = {
    type: chsRecord.StopRecordPlugin
};

const exit_survey = {
    type: chsSurvey.exit,
}

timeline.push(consent_survey, init_camera, start_rec, trial, stop_rec, exit_survey);

jsPsych.run(timeline);

To do:

changeset-bot[bot] commented 5 months ago

⚠️ No Changeset found

Latest commit: a45edb956eef1407f2f4d07a27e5acb2afd8ab7f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR