# pie-api-player

Provides the custom element:

`<pie-api-player></pie-api-player>`


Example:

```html
<pie-api-player id="player" token="my_token" item-id="12345"></pie-api-player>
```

## Notes


### `env` property / attribute.

### `preview` property / attribute

`preview = false` -
  <pie-player hosted={!preview} /> is hosted by api components. This means that items models and sessions are controlled by our endpoints in api-components.
  Item  is returned by /load endpoint.
  Bundle url is returned by /load endpoint, bundle type being player.
  Config changed, /model endpoint is called and config of the item is updated based on that and sent further.
  Score calls /score endpoint and saveSession calls /session endpoint
  In case of stimulus items, two bundles will be created, one for passage and one for other pie elements.

`preview = true` -
  <pie-player hosted={!preview} /> is not hosted by api components. No server calls are made in api-components.
  Item is retrieved from pie api (graphql).
  Bundle url is created in pie-player based on pie elements config, bundle type being client-player.
  Elements controllers are initialised when using this bundle type.
  Config changed, env field is changed here and controllers  of pie-elements are used in pie-player
  Score and saveSession do nothing
  In case of stimulus items, two bundles will be created, one for passage and one for other pie elements.


 For assessment item content, defines the current enviroment context for the player by providing the view mode and the user role.<p/>
 
`{ mode:'gather' | 'view' | 'evaluate' , role: 'student' | 'instructor}`

`env.mode === 'gather'` - The item should be presented in a way that allows a response to be entered.
`env.mode === 'view'` - The item should present the item and current response in an immutable state.
`env.mode === 'evaluate'` - The item should present the item showing an evaluation of the entered response.
`env.role === 'student'` - The current viewer is a student.
`env.role === 'instructor'` -  The current viewer is an instructor.


# API

<!-- Auto Generated Below -->


## Properties

| Property               | Attribute                | Description                                                                                                                                                                                                                          | Type                                   | Default        |
|------------------------|--------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -------------------------------------- | -------------- |
| `customConfig`         | `custom-config`          | Customize any of the api endpoint fields.                                                                                                                                                                                            | `ApiEndpoints`                         | `undefined`         |
| `customModels`         | `custom-models`          | Customize model.                                                                                                                                                                                                                     | `any[]`                                | `undefined`         |
| `env`                  | --                       | The current environment context in which to render the player. See notes.                                                                                                                                                            | `{ mode: Mode; role: Role; }`          | `undefined`    |
| `exceptions`           | `exceptions`             | Enable exception tracking.                                                                                                                                                                                                           | `boolean`                              | `true`         |
| `host`                 | `host`                   | Choose 'dev' , 'stage' or 'prod' environments for back end.                                                                                                                                                                          | `"dev" \| "prod" \| "qa" \| "stage"`   | `"prod"`       |
| `initialMode`          | `initial-mode`           | The mode to be used when player is initialized                                                                                                                                                                                       | `string`                               | `Mode.gather`  |
| `initialRole`          | `initial-role`           | The role to be used when player is initialized                                                                                                                                                                                       | `string`                               | `Role.student` |
| `itemId`               | `item-id`                | The identifier for the  content to load. The player will immediately load the content when this property is set.                                                                                                                     | `string`                               | `undefined`    |
| `optimize`             | `optimize`               | Use the beta controllers for pie-elements                                                                                                                                                                                            | `boolean`                              | `false`        |
| `overrides`            | `overrides`              | Override element versions. Requires the 'overrides' scope in the token in pie-api matches the key against the element names and if matching uses the overridden version if a string it's parsed as a json string                     | `string \| { [key: string]: string; }` | `undefined`    |
| `preview`              | `preview`                | If this property is set the item will be rendered in a `preview` state by the player. This means no server-side calls will be made and no reponse-session will be created/stored in pie-api.                                         | `boolean`                              | `false`        |
| `recordScreen`         | `record-screen`          | Enable screen recording with logrocket. Note: not to be used in production unless for temporary use to track down a specific user problem. Defaults to true in beta period                                                           | `boolean`                              | `false`        |
| `recordScreenIdentity` | `record-screen-identity` | If screen recording enabled for debug purposes, use this property to provide a unique identifer for the user whose session is being recorded.                                                                                        | `string`                               | `undefined`    |
| `renderStimulus`       | `render-stimulus`        | If the item contains a stimulus, the player will render it by default. Set this property to false to not render stimulus.                                                                                                            | `boolean`                              | `true`         |
| `sessionId`            | `session-id`             | If provided, will load the assessment session identified by the id. An assessment session is the record of a student's interaction with the item. The player will immediately load the assessment session when this property is set. | `string`                               | `undefined`    |
| `token`                | `token`                  | A JWT token to authorize requests on behalf of the player. This token for accessing pie-api can be generated with a valid Api Client Id and Secret.                                                                                  | `string`                               | `undefined`    |


## Events

| Event              | Description                                                                                                                                                                                             | Type               |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ |
| `recordingStarted` | If `recordScreen` property is set to true this event will be emitted with the url for recorded screen session in `detail` property.                                                                     | `CustomEvent<any>` |
| `session-created`  | Emitted when an item has loaded with a sessionId that was not specified on load. The event detail contains the generated session id and data.  `event.detail === {id: session_id, data:[session_data]}` | `CustomEvent<any>` |
| `api-player-error`  | Emitted when the `pie-api-player` encounters an error. The event detail contains `message` (a high-level error description) and `details` (detailed error info or stack trace). | `CustomEvent<{ message: string; details: any }>` |


## Methods

### `score(disablePartialScoring?: boolean) => Promise<any>`

Return the evaluated score for the current response.
The api token must provide permission to authorize the use of this method.

Note: Score does not (yet) work when in preview mode - will resolve to null if `preview` is `true`

#### Returns

Type: `Promise<any>`




## Dependencies

### Depends on

- pie-player
- [error-message](../error-message)

### Graph
```mermaid
graph TD;
  pie-api-player --> pie-player
  pie-api-player --> error-message
  pie-player --> pie-stimulus-layout
  pie-player --> pie-player
  pie-player --> pie-spinner
  style pie-api-player fill:#f9f,stroke:#333,stroke-width:4px
```

----------------------------------------------

*Built with [StencilJS](https://stenciljs.com/)*
