Trial Recording Extension

Trial recording can be added to most jsPsych trials. This is a jsPsych extension that allows you to add video recording to the trial. The trial will start once the video recording has been set up, and the video recording will finish as soon as the trial has ended.

When to use trial recording

Trial recording should NOT occur simultaneously with session recording, or with any plugins that already use the webcam (e.g. video config, video consent).

To use the CHS trial recording extension, you need to:

  1. Add it to the experiment settings, which is an optional object passed to initjsPsych.
  2. Add it to the extensions parameter for any trial(s) that you want to be recorded.

Don't forget a video config trial!

You MUST have a video config trial in your experiment timeline before doing any trial recording.

Parameters

wait_for_upload_message [null or HTML string | null ]

This parameter determines what content should be displayed while the trial recording is uploading. If null (the default), then the message 'uploading video, please wait...' (or appropriate translation based on locale) will be displayed. Otherwise this parameter can be set to a custom string and can contain HTML markup. If you want to embed images/video/audio in this HTML string, be sure to preload the media files with the preload plugin and manual preloading. Use a blank string ("") for no message/content. If a value is provided then the locale parameter will be ignored.

max_upload_seconds [ Integer | 10 ]

Maximum duration (in seconds) to wait for the trial recording to finish uploading before continuing with the experiment. If the maximum upload duration is reached and the upload has not finished, then the experiment will move on and the trial recording upload will continue in the background.

Examples

Basic usage

To record a single trial, you will have to first load the extension in initJsPsych.

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

Next, create a video configuration trial as described above. Then, add the trial recoding extension parameter to your trial. By adding this extension, you can record any trial you design.

const trialRec = {
  // ... Other trial parameters ...
  extensions: [{ type: chsRecord.TrialRecordExtension }],
};

Finally, insert the trials into the timeline.

jsPsych.run([videoConfig, trialRec]);

Setting parameters

You can set the trial extension parameters when you load the extension with initJsPsych.

In the example below, the default "uploading video, please wait..." message will be displayed in French while a trial recording is uploading at the end of the trial.

const jsPsych = initJsPsych({
  extensions: [
    {
      type: chsRecord.TrialRecordExtension,
      params: { locale: "fr" },
    },
  ],
});

And in this example, the custom message "Please wait!" will be displayed while the trial recording is uploading. You can include any HTML-formatted content in this string, which means you can display images, videos, animations etc.

const jsPsych = initJsPsych({
  extensions: [
    {
      type: chsRecord.TrialRecordExtension,
      params: { wait_for_upload_message: "<div>Please wait!</div>" },
    },
  ],
});

You can also set the parameters within individual trials. This will override any parameters set during the extension initialization (in initJsPsych), which can be useful if you want to change the parameter values during the experiment. In this example, the wait_for_upload_message is set to an empty string, which will prevent the default "uploading video, please wait..." message from appearing after the trial finishes.

const trialRec = {
  // ... Other trial parameters ...
  extensions: [
    {
      type: chsRecord.TrialRecordExtension,
      params: { wait_for_upload_message: "" },
    },
  ],
};

By default, the trial recording extension will wait up to 10 seconds for the recording to finish uploading before moving on to the next trial. If the upload does not finish in that time, it will continue to upload in the background. You can adjust this duration with the max_upload_seconds parameter. You may want to increase or decrease this duration depending on the duration of your recorded trials, or you expect that some participants may have slow/unreliable internet connections. This example decreases the maximum upload duration from 10 to 5 seconds:

const trialRec = {
  // ... Other trial parameters ...
  extensions: [
    {
      type: chsRecord.TrialRecordExtension,
      params: { max_upload_seconds: 5 },
    },
  ],
};