# Camera

#### new Camera(options)

Source:
  - hardware/Camera.js, line 19
To Do:
  - add video constraints as parameter

This manager handles the recording of video signal.

##### Parameters:

Name | Type | Description
--- | --- | ---

`options`

Object

###### Properties

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`win` | module:core.Window |  |  | the associated Window
`format` | string | <optional> | `'video/webm;codecs=vp9'` | the video format
`clock` | Clock | <optional> |  | an optional clock
`autoLog` | boolean | <optional> | `false` | whether or not to log

### Methods

#### (protected) _onChange()

Source:
  - hardware/Camera.js, line 506

Callback for changes to the recording settings.

Changes to the settings require the recording to stop and be re-started.

#### (protected) _prepareRecording()

Source:
  - hardware/Camera.js, line 527

Prepare the recording.

#### (protected) _upload(tag, waitForCompletionopt, showDialogopt, dialogMsgopt)

Source:
  - hardware/Camera.js, line 436

Upload the video recording to the pavlovia server.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`tag` | string |  |  | an optional tag for the video file
`waitForCompletion` | boolean | <optional> | `false` | whether to wait for completion before returning
`showDialog` | boolean | <optional> | `false` | whether to open a dialog box to inform the participant to wait for the data to be uploaded to the server
`dialogMsg` | string | <optional> | `""` | default message informing the participant to wait for the data to be uploaded to the server

#### authorize(showDialogopt, dialogMsgopt) → {boolean}

Source:
  - hardware/Camera.js, line 54

Prompt the user for permission to use the camera on their device.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`showDialog` | boolean | <optional> | `false` | whether to open a dialog box to inform the participant to wait for the camera to be initialised
`dialogMsg` | string | <optional> |  | the dialog message

##### Returns:

whether or not the camera is ready to record

Type
  boolean

#### close() → {Promise.<void>}

Source:
  - hardware/Camera.js, line 489

Close the camera stream.

##### Returns:

promise fulfilled when the stream has stopped and is now closed

Type
  Promise.<void>

#### flush() → {Promise}

Source:
  - hardware/Camera.js, line 387

Submit a request to flush the recording.

##### Returns:

promise fulfilled when the data has actually been made available

Type
  Promise

#### getRecording(tag, flushopt)

Source:
  - hardware/Camera.js, line 416

Get the current video recording as a VideoClip in the given format.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`tag` | string |  |  | an optional tag for the video clip
`flush` | boolean | <optional> | `false` | whether or not to first flush the recording

#### getStream() → {MediaStream}

Source:
  - hardware/Camera.js, line 122

Get the underlying video stream.

##### Returns:

the video stream

Type
  MediaStream

#### getVideo() → {HTMLVideoElement}

Source:
  - hardware/Camera.js, line 135

Get a video element pointing to the Camera stream.

##### Returns:

a video element

Type
  HTMLVideoElement

#### isReady() → {boolean}

Source:
  - hardware/Camera.js, line 109

Query whether the camera is ready to record.

##### Returns:

true if the camera is ready to record, false otherwise

Type
  boolean

#### open()

Source:
  - hardware/Camera.js, line 169

Open the video stream.

#### pause() → {Promise}

Source:
  - hardware/Camera.js, line 283

Submit a request to pause the recording.

##### Returns:

promise fulfilled when the recording actually paused

Type
  Promise

#### record() → {Promise}

Source:
  - hardware/Camera.js, line 191

Submit a request to start the recording.

##### Returns:

promise fulfilled when the recording actually starts

Type
  Promise

#### resume(options) → {Promise}

Source:
  - hardware/Camera.js, line 330

Submit a request to resume the recording.

resume has no effect if the recording was not previously paused.

##### Parameters:

Name | Type | Description
--- | --- | ---

`options`

Object

###### Properties

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`clear` | boolean | <optional> | `false` | whether or not to empty the video buffer before resuming the recording

##### Returns:

promise fulfilled when the recording actually resumed

Type
  Promise

#### stop(options) → {Promise}

Source:
  - hardware/Camera.js, line 246

Submit a request to stop the recording.

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` | Object |

##### Returns:

promise fulfilled when the recording actually stopped, and the recorded data was made available

Type
  Promise