# PsychoJS

## core. PsychoJS

PsychoJS initialises the library and its various components (e.g. the `ServerManager`, the `EventManager`), and manages the lifecycle of an experiment.

## Constructor

#### new PsychoJS(options)

Source:
  - core/PsychoJS.js, line 27

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` | Object | ###### Properties
Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`debug` | boolean | <optional> | `true` | whether to log debug information in the browser console
`collectIP` | boolean | <optional> | `false` | whether to collect the IP information of the participant

### Members

#### (static, readonly) Status :Symbol

Source:
  - core/PsychoJS.js, line 768

##### Properties:

Name | Type | Description
--- | --- | ---
`NOT_CONFIGURED` | Symbol |
`CONFIGURING` | Symbol |
`CONFIGURED` | Symbol |
`NOT_STARTED` | Symbol |
`STARTED` | Symbol |
`PAUSED` | Symbol |
`FINISHED` | Symbol |
`STOPPED` | Symbol |
`ERROR` | Symbol |

PsychoJS status.

##### Type:

- Symbol

### Methods

#### (protected) _captureErrors()

Source:
  - core/PsychoJS.js, line 703

Capture all errors and display them in a pop-up error box.

#### (async, protected) _configure(configURL, name)

Source:
  - core/PsychoJS.js, line 555

Configure PsychoJS for the running experiment.

##### Parameters:

Name | Type | Description
--- | --- | ---
`configURL` | string | the URL of the configuration file
`name` | string | the name of the experiment

#### (async, protected) _getParticipantIPInfo()

Source:
  - core/PsychoJS.js, line 657

Get the IP information of the participant, asynchronously.

Note: we use `http://www.geoplugin.net/json.gp`.

#### (protected) _makeStatusTopLevel()

Source:
  - core/PsychoJS.js, line 749

Make the various Status top level, in order to accommodate PsychoPy's Code Components.

#### getEnvironment() → {ExperimentHandler.Environment|undefined}

Source:
  - core/PsychoJS.js, line 185

Get the experiment's environment.

##### Returns:

the environment of the experiment, or undefined

Type
  ExperimentHandler.Environment | undefined

#### importAttributes(obj)

Source:
  - core/PsychoJS.js, line 439

Make the attributes of the given object those of window, such that they become global.

##### Parameters:

Name | Type | Description
--- | --- | ---
`obj` | Object.<string, *> | the object whose attributes are to become global

#### openWindow(options)

Source:
  - core/PsychoJS.js, line 210

Open a PsychoJS Window.

This opens a PIXI canvas.

Note: we can only open one window.

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` | Object | ###### Properties
Name | Type | Attributes | Description
--- | --- | --- | ---
`name` | string | <optional> | the name of the window
`fullscr` | boolean | <optional> | whether or not to go fullscreen
`color` | Color | <optional> | the background color of the window
`units` | string | <optional> | the units of the window
`autoLog` | boolean | <optional> | whether or not to log
`waitBlanking` | boolean | <optional> | whether or not to wait for all rendering operations to be done before flipping

##### Throws:

exception if a window has already been opened

Type
  Object.<string, *>

#### (async) quit(options)

Source:
  - core/PsychoJS.js, line 465

Close everything and exit nicely at the end of the experiment, potentially redirecting to one of the URLs previously specified by setRedirectUrls.

Note: if the resource manager is busy, we inform the participant that he or she needs to wait for a bit.

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` | Object | ###### Properties
Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`message` | string | <optional> |  | optional message to be displayed in a dialog box before quitting
`isCompleted` | boolean | <optional> | `false` | whether the participant has completed the experiment

#### schedule(task, args)

Source:
  - core/PsychoJS.js, line 261

Schedule a task.

##### Parameters:

Name | Type | Description
--- | --- | ---
`task` | module:util.Scheduler~Task | the task to be scheduled
`args` | * | arguments for that task

#### scheduleCondition(condition, thenScheduler, elseScheduler)

Source:
  - core/PsychoJS.js, line 279

Schedule a series of task based on a condition.

##### Parameters:

Name | Type | Description
--- | --- | ---
`condition` | PsychoJS.condition |
`thenScheduler` | Scheduler | scheduler to run if the condition is true
`elseScheduler` | Scheduler | scheduler to run if the condition is false

#### setRedirectUrls(completionUrl, cancellationUrl)

Source:
  - core/PsychoJS.js, line 249

Set the completion and cancellation URL to which the participant will be redirect at the end of the experiment.

##### Parameters:

Name | Type | Description
--- | --- | ---
`completionUrl` | string | the completion URL
`cancellationUrl` | string | the cancellation URL

#### (async) start(options, resourcesopt)

Source:
  - core/PsychoJS.js, line 306

Start the experiment.

The resources are specified in the following fashion:

- For an experiment running locally: the root directory for the specified resources is that of index.html unless they are prepended with a protocol, such as http:// or https://.
- For an experiment running on the server: if no resources are specified, all files in the resources directory of the experiment are downloaded, otherwise we only download the specified resources. All resources are assumed local to index.html unless they are prepended with a protocol.
- If resources is null: we do not download any resources.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`options` | Object |  |  | ###### Properties
Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`configURL` | string | <optional> | `config.json` | the URL of the configuration file
`expName` | string | <optional> | `UNKNOWN` | the name of the experiment
`expInfo` | Object.<string, *> | <optional> |  | additional information about the experiment
`resources` | Array.<{name: string, path: string}> | <optional> | `[]` | the list of resources

#### waitForResources(resourcesopt)

Source:
  - core/PsychoJS.js, line 416

Block the experiment until the specified resources have been downloaded.

Note: only those resources that have not already been downloaded at that point are considered.

- For an experiment running locally: the root directory for the specified resources is that of index.html unless they are prepended with a protocol, such as http:// or https://.
- For an experiment running on the server: if no resources are specified, all files in the resources directory of the experiment are downloaded, otherwise we only download the specified resources. All resources are assumed local to index.html unless they are prepended with a protocol.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`resources` | Array.<{name: string, path: string}> | <optional> | `[]` | the list of resources