diff --git a/package-lock.json b/package-lock.json
index 82fde88..23eaa79 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "psychojs",
- "version": "2021.2.0",
+ "version": "2021.2.x",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "psychojs",
- "version": "2021.2.0",
+ "version": "2021.2.x",
"license": "MIT",
"dependencies": {
"howler": "^2.2.1",
diff --git a/src/core/PsychoJS.js b/src/core/PsychoJS.js
index b5bf92f..922ff0f 100644
--- a/src/core/PsychoJS.js
+++ b/src/core/PsychoJS.js
@@ -142,9 +142,9 @@ export class PsychoJS
psychoJS: this,
});
- // to be loading `configURL` files in `_configure` calls from
- const hostsEvidently = new Set([...hosts, "https://pavlovia.org/run/", "https://run.pavlovia.org/"]);
- this._hosts = Array.from(hostsEvidently);
+ // add the pavlovia server to the list of hosts:
+ const hostsWithPavlovia = new Set([...hosts, "https://pavlovia.org/run/", "https://run.pavlovia.org/"]);
+ this._hosts = Array.from(hostsWithPavlovia);
// GUI:
this._gui = new GUI(this);
@@ -178,7 +178,7 @@ export class PsychoJS
this.logger.info("[PsychoJS] Initialised.");
this.logger.info("[PsychoJS] @version 2021.2.0");
- // Hide #root::after
+ // hide the initialisation message:
jQuery("#root").addClass("is-ready");
}
@@ -572,17 +572,17 @@ export class PsychoJS
{
this.status = PsychoJS.Status.CONFIGURING;
- // if the experiment is running from the pavlovia.org server, we read the configuration file:
+ // if the experiment is running from an approved hosts, e.e pavlovia.org,
+ // we read the configuration file:
const experimentUrl = window.location.href;
- // go through each url in allow list
- const isHost = this._hosts.some((url) => experimentUrl.indexOf(url) === 0);
+ const isHost = this._hosts.some(url => experimentUrl.indexOf(url) === 0);
if (isHost)
{
const serverResponse = await this._serverManager.getConfiguration(configURL);
this._config = serverResponse.config;
- // legacy experiments had a psychoJsManager block instead of a pavlovia block,
- // and the URL pointed to https://pavlovia.org/server
+ // update the configuration for legacy experiments, which had a psychoJsManager
+ // block instead of a pavlovia block, with URL pointing to https://pavlovia.org/server
if ("psychoJsManager" in this._config)
{
delete this._config.psychoJsManager;
diff --git a/src/core/ServerManager.js b/src/core/ServerManager.js
index c0f51af..a06140a 100644
--- a/src/core/ServerManager.js
+++ b/src/core/ServerManager.js
@@ -429,15 +429,14 @@ export class ServerManager extends PsychObject
}
// whether all resources have been requested:
- const allResources = (resources.length === 1 && resources[0] === ServerManager.ALL_RESOURCES);
+ const allResources = (resources.length === 1 &&
+ resources[0] === ServerManager.ALL_RESOURCES);
// if the experiment is hosted on the pavlovia.org server and
// resources is [ServerManager.ALL_RESOURCES], then we register all the resources
// in the "resources" sub-directory
- if (
- this._psychoJS.config.environment === ExperimentHandler.Environment.SERVER
- && allResources
- )
+ if (this._psychoJS.config.environment === ExperimentHandler.Environment.SERVER &&
+ allResources)
{
// list the resources from the resources directory of the experiment on the server:
const serverResponse = await this._listResources();
@@ -465,10 +464,8 @@ export class ServerManager extends PsychObject
{
// we cannot ask for all resources to be registered locally, since we cannot list
// them:
- if (
- this._psychoJS.config.environment === ExperimentHandler.Environment.LOCAL
- && allResources
- )
+ if (this._psychoJS.config.environment === ExperimentHandler.Environment.LOCAL &&
+ allResources)
{
throw "resources must be manually specified when the experiment is running locally: ALL_RESOURCES cannot be used";
}
@@ -759,14 +756,14 @@ export class ServerManager extends PsychObject
/**
* Asynchronously upload audio data to the pavlovia server.
*
- * @name module:core.ServerManager#uploadAudio
+ * @name module:core.ServerManager#uploadAudioVideo
* @function
* @public
* @param {Blob} audioBlob - the audio blob to be uploaded
* @param {string} tag - additional tag
* @returns {Promise A Trial Handler that implements the Quest algorithm for quick measurement of
- psychophysical thresholds.
resume has no effect if the recording was not previously paused.
* * @name module:visual.Camera#resume + * @function * @param {Object} options * @param {boolean} [options.clear= false] whether or not to empty the video buffer before * resuming the recording @@ -259,13 +270,13 @@ export class Camera extends PsychObject { if (this._status === PsychoJS.Status.PAUSED) { - this._psychoJS.logger.debug('request to resume video recording'); + this._psychoJS.logger.debug("request to resume video recording"); try { if (!this._recorder) { - throw 'the recorder has not been created yet, possibly because the participant has not given the authorisation to record video'; + throw "the recorder has not been created yet, possibly because the participant has not given the authorisation to record video"; } // empty the audio buffer is needed: @@ -287,12 +298,12 @@ export class Camera extends PsychObject } catch (error) { - self._psychoJS.logger.error('unable to resume the video recording: ' + JSON.stringify(error)); + self._psychoJS.logger.error("unable to resume the video recording: " + JSON.stringify(error)); this._status = PsychoJS.Status.ERROR; throw { - origin: 'Camera.resume', - context: 'when resuming the video recording for camera: ' + this._name, + origin: "Camera.resume", + context: "when resuming the video recording for camera: " + this._name, error }; } @@ -305,6 +316,7 @@ export class Camera extends PsychObject * Submit a request to flush the recording. * * @name module:visual.Camera#flush + * @function * @public * @return {Promise} promise fulfilled when the data has actually been made available */ @@ -312,7 +324,7 @@ export class Camera extends PsychObject { if (this._status === PsychoJS.Status.STARTED || this._status === PsychoJS.Status.PAUSED) { - this._psychoJS.logger.debug('request to flush video recording'); + this._psychoJS.logger.debug("request to flush video recording"); // note: calling the requestData method of the MediaRecorder will raise a // dataavailable event @@ -336,13 +348,13 @@ export class Camera extends PsychObject * @name module:visual.Camera#download * @function * @public - * @param {string} filename the filename + * @param {string} filename - the filename of the video file */ - download(filename = 'video.webm') + download(filename = "video.webm") { const videoBlob = new Blob(this._videoBuffer); - const anchor = document.createElement('a'); + const anchor = document.createElement("a"); anchor.href = window.URL.createObjectURL(videoBlob); anchor.download = filename; document.body.appendChild(anchor); @@ -362,7 +374,7 @@ export class Camera extends PsychObject async upload({tag} = {}) { // default tag: the name of this Camera object - if (typeof tag === 'undefined') + if (typeof tag === "undefined") { tag = this._name; } @@ -374,16 +386,15 @@ export class Camera extends PsychObject // if the video recording cannot be uploaded, e.g. the experiment is running locally, or // if it is piloting mode, then we offer the video recording as a file for download: if (this._psychoJS.getEnvironment() !== ExperimentHandler.Environment.SERVER || - this._psychoJS.config.experiment.status !== 'RUNNING' || - this._psychoJS._serverMsg.has('__pilotToken')) + this._psychoJS.config.experiment.status !== "RUNNING" || + this._psychoJS._serverMsg.has("__pilotToken")) { return this.download(tag); } // upload the blob: - // TODO uploadAudio -> uploadAudioVideo const videoBlob = new Blob(this._videoBuffer); - return this._psychoJS.serverManager.uploadAudio(videoBlob, tag); + return this._psychoJS.serverManager.uploadAudioVideo(videoBlob, tag); } @@ -399,22 +410,12 @@ export class Camera extends PsychObject async getRecording({tag, flush = false} = {}) { // default tag: the name of this Microphone object - if (typeof tag === 'undefined') + if (typeof tag === "undefined") { tag = this._name; } // TODO -/* - const videoClip = new VideoClip({ - psychoJS: this._psychoJS, - name: tag, - format: this._format, - data: new Blob(this._videoBuffer) - }); - - return videoClip; -*/ } @@ -455,15 +456,9 @@ export class Camera extends PsychObject this._videos = []; // create a new stream with ideal dimensions: + // TODO use size constraints this._stream = await navigator.mediaDevices.getUserMedia({ - video: { - width: { - ideal: 1920 - }, - height: { - ideal: 1080 - } - } + video: true }); // check the actual width and height: @@ -473,7 +468,7 @@ export class Camera extends PsychObject // check that the specified format is supported, use default if it is not: let options; - if (typeof this._format === 'string' && MediaRecorder.isTypeSupported(this._format)) + if (typeof this._format === "string" && MediaRecorder.isTypeSupported(this._format)) { options = { type: this._format }; } @@ -498,7 +493,7 @@ export class Camera extends PsychObject self._videoBuffer.length = 0; self._clock.reset(); self._status = PsychoJS.Status.STARTED; - self._psychoJS.logger.debug('video recording started'); + self._psychoJS.logger.debug("video recording started"); // resolve the Microphone.start promise: if (self._startCallback) @@ -511,7 +506,7 @@ export class Camera extends PsychObject this._recorder.onpause = () => { self._status = PsychoJS.Status.PAUSED; - self._psychoJS.logger.debug('video recording paused'); + self._psychoJS.logger.debug("video recording paused"); // resolve the Microphone.pause promise: if (self._pauseCallback) @@ -524,7 +519,7 @@ export class Camera extends PsychObject this._recorder.onresume = () => { self._status = PsychoJS.Status.STARTED; - self._psychoJS.logger.debug('video recording resumed'); + self._psychoJS.logger.debug("video recording resumed"); // resolve the Microphone.resume promise: if (self._resumeCallback) @@ -540,7 +535,7 @@ export class Camera extends PsychObject // add data to the buffer: self._videoBuffer.push(data); - self._psychoJS.logger.debug('video data added to the buffer'); + self._psychoJS.logger.debug("video data added to the buffer"); // resolve the data available promise, if needed: if (self._dataAvailableCallback) @@ -552,7 +547,7 @@ export class Camera extends PsychObject // called upon Camera.stop(), after data has been made available: this._recorder.onstop = () => { - self._psychoJS.logger.debug('video recording stopped'); + self._psychoJS.logger.debug("video recording stopped"); self._status = PsychoJS.Status.NOT_STARTED; // resolve the Microphone.stop promise: @@ -564,7 +559,7 @@ export class Camera extends PsychObject // treat stop options if there are any: // download to a file, immediately offered to the participant: - if (typeof self._stopOptions.filename === 'string') + if (typeof self._stopOptions.filename === "string") { self.download(self._stopOptions.filename); } @@ -574,7 +569,7 @@ export class Camera extends PsychObject this._recorder.onerror = (event) => { // TODO - self._psychoJS.logger.error('video recording error: ' + JSON.stringify(event)); + self._psychoJS.logger.error("video recording error: " + JSON.stringify(event)); self._status = PsychoJS.Status.ERROR; }; diff --git a/src/visual/FaceDetector.js b/src/visual/FaceDetector.js index c6143ad..559f244 100644 --- a/src/visual/FaceDetector.js +++ b/src/visual/FaceDetector.js @@ -7,17 +7,19 @@ * @license Distributed under the terms of the MIT License */ -import {PsychoJS} from "../core/PsychoJS"; -import * as util from '../util/Util'; -import {Color} from '../util/Color'; -import {Camera} from "./Camera"; -import {VisualStim} from "./VisualStim"; +import {PsychoJS} from "../core/PsychoJS.js"; +import * as util from "../util/Util.js"; +import { to_pixiPoint } from "../util/Pixi.js"; +import {Color} from "../util/Color.js"; +import {Camera} from "./Camera.js"; +import {VisualStim} from "./VisualStim.js"; import * as PIXI from "pixi.js-legacy"; /** - *This manager handles the detecting of faces in video streams.
- *The detection is performed using the Face-API library: https://github.com/justadudewhohacks/face-api.js
+ *This manager handles the detecting of faces in video streams. FaceDetector relies on the + * [Face-API library]{@link https://github.com/justadudewhohacks/face-api.js} developed by + * [Vincent Muehler]{@link https://github.com/justadudewhohacks}
* * @name module:visual.FaceDetector * @class @@ -39,17 +41,20 @@ import * as PIXI from "pixi.js-legacy"; */ export class FaceDetector extends VisualStim { - + /** + * @constructor + * @public + */ constructor({name, win, input, modelDir, faceApiUrl, units, ori, opacity, pos, size, autoDraw, autoLog} = {}) { super({name, win, units, ori, opacity, pos, size, autoDraw, autoLog}); // TODO deal with onChange (see MovieStim and Camera) - this._addAttribute('input', input, undefined); - this._addAttribute('faceApiUrl', faceApiUrl, 'face-api.js'); - this._addAttribute('modelDir', modelDir, 'models'); - this._addAttribute('autoLog', autoLog, false); - this._addAttribute('status', PsychoJS.Status.NOT_STARTED); + this._addAttribute("input", input, undefined); + this._addAttribute("faceApiUrl", faceApiUrl, "face-api.js"); + this._addAttribute("modelDir", modelDir, "models"); + this._addAttribute("autoLog", autoLog, false); + this._addAttribute("status", PsychoJS.Status.NOT_STARTED); // init face-api: this._initFaceApi(); @@ -65,6 +70,7 @@ export class FaceDetector extends VisualStim * Setter for the video attribute. * * @name module:visual.FaceDetector#setCamera + * @function * @public * @param {string | HTMLVideoElement | module:visual.Camera} input - the name of a * movie resource or a HTMLVideoElement or a Camera component @@ -73,23 +79,23 @@ export class FaceDetector extends VisualStim setInput(input, log = false) { const response = { - origin: 'FaceDetector.setInput', - context: 'when setting the video of FaceDetector: ' + this._name + origin: "FaceDetector.setInput", + context: "when setting the video of FaceDetector: " + this._name }; try { // movie is undefined: that's fine but we raise a warning in case this is // a symptom of an actual problem - if (typeof input === 'undefined') + if (typeof input === "undefined") { - this.psychoJS.logger.warn('setting the movie of MovieStim: ' + this._name + ' with argument: undefined.'); - this.psychoJS.logger.debug('set the movie of MovieStim: ' + this._name + ' as: undefined'); + this.psychoJS.logger.warn("setting the movie of MovieStim: " + this._name + " with argument: undefined."); + this.psychoJS.logger.debug("set the movie of MovieStim: " + this._name + " as: undefined"); } else { // if movie is a string, then it should be the name of a resource, which we get: - if (typeof input === 'string') + if (typeof input === "string") { // TODO create a movie with that resource, and use the movie as input } @@ -106,7 +112,7 @@ export class FaceDetector extends VisualStim // check that video is now an HTMLVideoElement if (!(input instanceof HTMLVideoElement)) { - throw input.toString() + ' is not a video'; + throw input.toString() + " is not a video"; } this.psychoJS.logger.debug(`set the video of FaceDetector: ${this._name} as: src= ${input.src}, size= ${input.videoWidth}x${input.videoHeight}, duration= ${input.duration}s`); @@ -123,7 +129,7 @@ export class FaceDetector extends VisualStim } } - this._setAttribute('input', input, log); + this._setAttribute("input", input, log); this._needUpdate = true; this._needPixiUpdate = true; } @@ -138,6 +144,7 @@ export class FaceDetector extends VisualStim * Start detecting faces. * * @name module:visual.FaceDetector#start + * @function * @public * @param {number} period - the detection period, in ms (e.g. 100 ms for 10Hz) * @param detectionCallback - the callback triggered when detection results are available @@ -147,7 +154,7 @@ export class FaceDetector extends VisualStim { this.status = PsychoJS.Status.STARTED; - if (typeof this._detectionId !== 'undefined') + if (typeof this._detectionId !== "undefined") { clearInterval(this._detectionId); this._detectionId = undefined; @@ -176,6 +183,7 @@ export class FaceDetector extends VisualStim * Stop detecting faces. * * @name module:visual.FaceDetector#stop + * @function * @public * @param {boolean} [log= false] - whether of not to log */ @@ -183,7 +191,7 @@ export class FaceDetector extends VisualStim { this.status = PsychoJS.Status.NOT_STARTED; - if (typeof this._detectionId !== 'undefined') + if (typeof this._detectionId !== "undefined") { clearInterval(this._detectionId); this._detectionId = undefined; @@ -195,16 +203,17 @@ export class FaceDetector extends VisualStim * Init the Face-API library. * * @name module:visual.FaceDetector#_initFaceApi - * @private + * @function + * @protected */ async _initFaceApi() {/* // load the library: await this._psychoJS.serverManager.prepareResources([ { - 'name': 'face-api.js', - 'path': this.faceApiUrl, - 'download': true + "name": "face-api.js", + "path": this.faceApiUrl, + "download": true } ]);*/ @@ -220,7 +229,8 @@ export class FaceDetector extends VisualStim * Update the visual representation of the detected faces, if necessary. * * @name module:visual.FaceDetector#_updateIfNeeded - * @private + * @function + * @protected */ _updateIfNeeded() { @@ -234,7 +244,7 @@ export class FaceDetector extends VisualStim { this._needPixiUpdate = false; - if (typeof this._pixi !== 'undefined') + if (typeof this._pixi !== "undefined") { this._pixi.destroy(true); } @@ -246,7 +256,7 @@ export class FaceDetector extends VisualStim this._pixi.addChild(this._body); const size_px = util.to_px(this.size, this.units, this.win); - if (typeof this._detections !== 'undefined') + if (typeof this._detections !== "undefined") { for (const detection of this._detections) { @@ -256,7 +266,7 @@ export class FaceDetector extends VisualStim for (const position of landmarks.positions) { - this._body.beginFill(new Color('red').int, this._opacity); + this._body.beginFill(new Color("red").int, this._opacity); this._body.drawCircle( position._x / imageWidth * size_px[0] - size_px[0] / 2, position._y / imageHeight * size_px[1] - size_px[1] / 2, @@ -273,7 +283,7 @@ export class FaceDetector extends VisualStim this._pixi.scale.y = -1; this._pixi.rotation = this.ori * Math.PI / 180; - this._pixi.position = util.to_pixiPoint(this.pos, this.units, this.win); + this._pixi.position = to_pixiPoint(this.pos, this.units, this.win); this._pixi.alpha = this._opacity; } @@ -290,15 +300,6 @@ export class FaceDetector extends VisualStim _estimateBoundingBox() { // TODO - - /*this._boundingBox = new PIXI.Rectangle( - this._pos[0] + this._getLengthUnits(limits_px[0]), - this._pos[1] + this._getLengthUnits(limits_px[1]), - this._getLengthUnits(limits_px[2] - limits_px[0]), - this._getLengthUnits(limits_px[3] - limits_px[1]) - );*/ - - // TODO take the orientation into account } }