# Nonstop Javascript SDK

## Choice Cards

Choice Cards control the logic around:

* Whether the user should be offered the choice of purchasing the content at all
* Whether the user has previously purchased the content and is still within their grace period
* Whether the user has enough points to purchase the content
* The user interface for presenting the choices to the user
* Whether the choice card includes a timer, and if so for how long
* Recording the user selection, including recording purchases
* Calling back the integrating application with instruction on path to take

Note: In some situations the actual Choice Card UI will not show at all, the calling client will simply be instructed to continue.

### When to call it

`presentChoiceCard` should be called prior to watching a long form on-demand stream when the user is logged in. The client should wait for the SDK to emit an `onWatchNonstop` event or an `onWatchStandard` event before continuing.

`presentChoiceCard` is not required for Live, VPPO clips or ShowMS clips. When called for non-valid content or when no user logged in it will simply trigger the `onWatchStandard` event.

### How to call it 

```javascript
    Nonstop.default.presentChoiceCard('VDKA4220171', document.querySelectorAll('.choice-card-content')[0], true);
```

* **contentId** - the PartnerAPIId of the content the user has selected to watch
* **inElement** - the element into which the Choice Card should be inserted
* **isContinueWatching** - this should be set to `true` when the user is in continuous play mode i.e. has just finished watching a previous episode and has arrived on this page as a result of selecting to watch the next episode or the end card time out expiring. When this is set to `true` the choice card will be displayed for at most 30 seconds before selecting to watch standard on behalf of the user. If it is `false` or omitted, no timer is present.

### Events

### Watch Nonstop

```javascript
    document.addEventListener(Nonstop.default.Events.OnWatchStandard, () => {
        // Client should play the stream with Nonstop ad load
    });
```

When the client application receives this event it means that the user should watch the selected content Nonstop. This could be for a number of reasons:

* because they purchased via the choice card
* because they are within their grace period for this piece of content
* because this piece of content has been given to all users by a particular sponsor

The client application should instruct the player to commence with a reduced ad load by passing the `cbp` parameter with a value of `1` into the framework player. See [Playing Content Nonstop](PlayingContentNonstop.md) for more details.

### Watch Standard

```javascript
    document.addEventListener(Nonstop.default.Events.OnWatchNonstop, function() {
        // Client should play the stream with normal ad load
    });
```

When the client application receives this event it means that the user should watch the selected content with the standard ad load. This could be for a number of reasons:

* this piece of content is not eligible to watch Nonstop
* the user could not afford to watch the content Nonstop
* the choice card timer elapsed and the user did not make a selection
* an error has occurred that is best to be handled by just playing the stream with standard ad load

The client application should instruct the player to commence with a normal ad load by not passing a value for `cbp` to the player framework.