# Nonstop Javascript SDK

## Performing Tasks

Users can complete Tasks with the integrating application calling Nonstop to tell the platform whenever one of the relevant user actions occurs. Each Task has it's own input model, that inherits from a base class, so that the parameters relevant to that task can be passed in. The relevant input model can be created by calling the createTask function and passing in the required type.

This input model can then have properties set and be passed to `userPerformedTask`.

Tasks that should be tracked by the client application are:

### Started Content

This should be called whenever a logged in user starts any content including Live, Episodes, Movies, VPPO Clips and ShowMS Clips.

* **contentId** - For VPPO content it should be passed the Partner API Id, for ShowMS Clips the ShowMS Id and for live either "US/Eastern" or "US/Pacific".
* **isWatchingNonstop** - This defaults to false and should be set to true when the user is starting a stream in Nonstop mode. The client app should know this from the result of the `presentChoiceCard` call. It does not need to be set for Live, VPPO or ShowMS Clips as these cannot be viewed Nonstop.

Create and set properties:

```javascript
    const taskInput = new TaskInput('start-content');
    taskInput.contentId = 'VDKA4220171';
    taskInput.isWatchingNonstop = true;
```

### Watch 1 Minute of Content

Whenever the logged in user is watching any content this task should be called once per every minute of viewing.

* **contentId** - For VPPO content it should be passed the Partner API Id, for ShowMS Clips the ShowMS Id and for live either "US/Eastern" or "US/Pacific".

Create and set properties:

```javascript
    const taskInput = new TaskInput('watch-1-minute-of-content');
    taskInput.contentId = 'VDKA48583';
```

Note: While you cannot watch and earn on VPPO or ShowMS Clips by the minute we still recommend reporting Starts and Watch 1 Minute tasks for these content types.

### Connect MVPD Account

This should be called whenever a logged in user connects their MVPD Provider.

* **mvpdName** - MVPD name of the TV provider the user successfully connected. Note this should be the value obtained from the Adobe SDK for the provider Name, not the provider Id. For example, for Comcast it should be "Comcast Xfinity" not "Comcast_sso". The value should be camel cased.

Create and set properties:

```javascript
    const taskInput = new TaskInput('connect-mvpd-account');
    taskInput.mvpdName = 'Spectrum';
```

### Calling `userPerformedTask`

The correct task input and parameters is then passed to `userPerformedTask` as follows:

```javascript
    Nonstop.default.userPerformedTask(taskInput)
        .then(() => {
            // Task recorded successfully
        })
        .catch(() => {
            // Error when recording task
        })
```

Notes on calling `userPerformedTask`:

* If there is no logged in user an error will be thrown
* Any issues with the validation of the task will be returned as an error - e.g. content doesn't exist
* If the user should be receive points for completing the task then the SDK will assign them automatically
* If the user should see a Reward Card for completing the task the SDK will show it and play it before returning success
* If you wish to suppress the animation which will be played as a result of completing the task, the property `shouldAnimate` can be set to `false` on the `taskInput` object to remove the animation

Success and Error should only be used for logging, if required.

### Internal Tasks

Note: For some tasks the completion of them is tracked internally within the SDK based on either user interactions within SDK components or based on other SDK calls. These are:

#### Enter Code

This will be recorded when a user enters a code within the Nonstop home.

#### Sign Up

This is recorded in the background whenever the Login function is called.

#### Complete Content - Nonstop Promos

This will be recorded automatically when users complete Nonstop promos from Nonstop home.

As such at present the Client applications do not have to call `userPerformedTask` for these tasks.