@firebolt-js/discovery-sdk
Version:
The Firebolt Discovery JS SDK
559 lines (433 loc) • 14.8 kB
Markdown
---
title: Content
---
---
Version Content 1.6.0
- [Table of Contents](
- [Usage](
- [Overview](
- [Methods](
- [listen](
- [once](
- [requestUserInterest](
- [Events](
- [userInterest](
- [Private Events](
</details>
- [Types](
- [InterestResult](
- [InterestEvent](
To use the Content module, you can import it into your project from the Firebolt SDK:
```javascript
import { Content } from '@firebolt-js/discovery-sdk'
```
undefined
To listen to a specific event pass the event name as the first parameter:
```typescript
listen(event: string, callback: (data: any) => void): Promise<number>
```
Parameters:
| Param | Type | Required | Summary |
| ---------- | ---------- | -------- | ------------------------------------------------------ |
| `event` | `string` | Yes | The event to listen for, see [Events](
| _callback_ | `function` | Yes | A function that will be invoked when the event occurs. |
Promise resolution:
| Type | Description |
| -------- | ----------------------------------------------------------------------------------------------- |
| `number` | Listener ID to clear the callback method and stop receiving the event, e.g. `Content.clear(id)` |
Callback parameters:
| Param | Type | Required | Summary |
| ------ | ----- | -------- | ------------------------------------------------------------------------------ |
| `data` | `any` | Yes | The event data, which depends on which event is firing, see [Events](
To listen to all events from this module pass only a callback, without specifying an event name:
```typescript
listen(callback: (event: string, data: any) => void): Promise<number>
```
Parameters:
| Param | Type | Required | Summary |
| ---------- | ---------- | -------- | ------------------------------------------------------------------------------------------------------------------------------ |
| _callback_ | `function` | Yes | A function that will be invoked when the event occurs. The event data depends on which event is firing, see [Events](
Callback parameters:
| Param | Type | Required | Summary |
| ------- | -------- | -------- | ------------------------------------------------------------------------------ |
| `event` | `string` | Yes | The event that has occured listen for, see [Events](
| `data` | `any` | Yes | The event data, which depends on which event is firing, see [Events](
Promise resolution:
| Type | Description |
| -------- | ----------------------------------------------------------------------------------------------- |
| `number` | Listener ID to clear the callback method and stop receiving the event, e.g. `Content.clear(id)` |
See [Listening for events](../../docs/listening-for-events/) for more information and examples.
To listen to a single instance of a specific event pass the event name as the first parameter:
```typescript
once(event: string, callback: (data: any) => void): Promise<number>
```
The `once` method will only pass the next instance of this event, and then dicard the listener you provided.
Parameters:
| Param | Type | Required | Summary |
| ---------- | ---------- | -------- | ------------------------------------------------------ |
| `event` | `string` | Yes | The event to listen for, see [Events](
| _callback_ | `function` | Yes | A function that will be invoked when the event occurs. |
Promise resolution:
| Type | Description |
| -------- | ----------------------------------------------------------------------------------------------- |
| `number` | Listener ID to clear the callback method and stop receiving the event, e.g. `Content.clear(id)` |
Callback parameters:
| Param | Type | Required | Summary |
| ------ | ----- | -------- | ------------------------------------------------------------------------------ |
| `data` | `any` | Yes | The event data, which depends on which event is firing, see [Events](
To listen to the next instance only of any events from this module pass only a callback, without specifying an event name:
```typescript
once(callback: (event: string, data: any) => void): Promise<number>
```
Parameters:
| Param | Type | Required | Summary |
| ---------- | ---------- | -------- | ------------------------------------------------------------------------------------------------------------------------------ |
| _callback_ | `function` | Yes | A function that will be invoked when the event occurs. The event data depends on which event is firing, see [Events](
Callback parameters:
| Param | Type | Required | Summary |
| ------- | -------- | -------- | ------------------------------------------------------------------------------ |
| `event` | `string` | Yes | The event that has occured listen for, see [Events](
| `data` | `any` | Yes | The event data, which depends on which event is firing, see [Events](
Promise resolution:
| Type | Description |
| -------- | ----------------------------------------------------------------------------------------------- |
| `number` | Listener ID to clear the callback method and stop receiving the event, e.g. `Content.clear(id)` |
See [Listening for events](../../docs/listening-for-events/) for more information and examples.
Provide information about the entity currently displayed or selected on the screen.
```typescript
function requestUserInterest(
type: InterestType,
reason: InterestReason,
): Promise<InterestResult>
```
Parameters:
| Param | Type | Required | Description |
| -------- | -------------------------------------------------------- | -------- | ------------------------------------------------------ |
| `type` | [`InterestType`](../Discovery/schemas/#InterestType) | true | <br/>values: `'interest' \| 'disinterest'` |
| `reason` | [`InterestReason`](../Discovery/schemas/#InterestReason) | true | <br/>values: `'playlist' \| 'reaction' \| 'recording'` |
Promise resolution:
[InterestResult](#interestresult)
Capabilities:
| Role | Capability |
| ---- | ------------------------------------------ |
| uses | xrn:firebolt:capability:discovery:interest |
#### Examples
Default Example
JavaScript:
```javascript
import { Content } from '@firebolt-js/discovery-sdk'
let interest = await Content.requestUserInterest('interest', 'playlist')
console.log(interest)
```
Value of `interest`:
```javascript
{
"appId": "cool-app",
"entity": {
"identifiers": {
"entityId": "345",
"entityType": "program",
"programType": "movie"
},
"info": {
"title": "Cool Runnings",
"synopsis": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Pulvinar sapien et ligula ullamcorper malesuada proin libero nunc.",
"releaseDate": "1993-01-01T00:00:00.000Z",
"contentRatings": [
{
"scheme": "US-Movie",
"rating": "PG"
},
{
"scheme": "CA-Movie",
"rating": "G"
}
]
}
}
}
```
<details>
<summary>JSON-RPC:</summary>
Request:
```json
{
"jsonrpc": "2.0",
"id": 1,
"method": "Content.requestUserInterest",
"params": {
"type": "interest",
"reason": "playlist"
}
}
```
Response:
```json
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"appId": "cool-app",
"entity": {
"identifiers": {
"entityId": "345",
"entityType": "program",
"programType": "movie"
},
"info": {
"title": "Cool Runnings",
"synopsis": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Pulvinar sapien et ligula ullamcorper malesuada proin libero nunc.",
"releaseDate": "1993-01-01T00:00:00.000Z",
"contentRatings": [
{
"scheme": "US-Movie",
"rating": "PG"
},
{
"scheme": "CA-Movie",
"rating": "G"
}
]
}
}
}
}
```
</details>
---
```typescript
function listen('userInterest', () => void): Promise<number>
```
See also: [listen()](
Event value:
[](
Capabilities:
| Role | Capability |
| ---- | ------------------------------------------ |
| uses | xrn:firebolt:capability:discovery:interest |
Default Example
JavaScript:
```javascript
import { Content } from '@firebolt-js/discovery-sdk'
Content.listen('userInterest', (interest) => {
console.log(interest)
})
```
Value of `interest`:
```javascript
{
"appId": "cool-app",
"type": "interest",
"reason": "playlist",
"entity": {
"identifiers": {
"entityId": "345",
"entityType": "program",
"programType": "movie"
},
"info": {
"title": "Cool Runnings",
"synopsis": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Pulvinar sapien et ligula ullamcorper malesuada proin libero nunc.",
"releaseDate": "1993-01-01T00:00:00.000Z",
"contentRatings": [
{
"scheme": "US-Movie",
"rating": "PG"
},
{
"scheme": "CA-Movie",
"rating": "G"
}
]
}
}
}
```
<details>
<summary>JSON-RPC:</summary>
Request:
```json
{
"jsonrpc": "2.0",
"id": 1,
"method": "Content.onUserInterest",
"params": {
"listen": true
}
}
```
Response:
```json
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"appId": "cool-app",
"type": "interest",
"reason": "playlist",
"entity": {
"identifiers": {
"entityId": "345",
"entityType": "program",
"programType": "movie"
},
"info": {
"title": "Cool Runnings",
"synopsis": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Pulvinar sapien et ligula ullamcorper malesuada proin libero nunc.",
"releaseDate": "1993-01-01T00:00:00.000Z",
"contentRatings": [
{
"scheme": "US-Movie",
"rating": "PG"
},
{
"scheme": "CA-Movie",
"rating": "G"
}
]
}
}
}
}
```
</details>
---
<details id="private-events-details">
<summary>View</summary>
```typescript
function listen('userInterest', () => void): Promise<number>
```
See also: [listen()](
Event value:
[](
Capabilities:
| Role | Capability |
| ---- | ------------------------------------------ |
| uses | xrn:firebolt:capability:discovery:interest |
Default Example
JavaScript:
```javascript
import { Content } from '@firebolt-js/discovery-sdk'
Content.listen('userInterest', (interest) => {
console.log(interest)
})
```
Value of `interest`:
```javascript
{
"appId": "cool-app",
"type": "interest",
"reason": "playlist",
"entity": {
"identifiers": {
"entityId": "345",
"entityType": "program",
"programType": "movie"
},
"info": {
"title": "Cool Runnings",
"synopsis": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Pulvinar sapien et ligula ullamcorper malesuada proin libero nunc.",
"releaseDate": "1993-01-01T00:00:00.000Z",
"contentRatings": [
{
"scheme": "US-Movie",
"rating": "PG"
},
{
"scheme": "CA-Movie",
"rating": "G"
}
]
}
}
}
```
<details>
<summary>JSON-RPC:</summary>
Request:
```json
{
"jsonrpc": "2.0",
"id": 1,
"method": "Content.onUserInterest",
"params": {
"listen": true
}
}
```
Response:
```json
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"appId": "cool-app",
"type": "interest",
"reason": "playlist",
"entity": {
"identifiers": {
"entityId": "345",
"entityType": "program",
"programType": "movie"
},
"info": {
"title": "Cool Runnings",
"synopsis": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Pulvinar sapien et ligula ullamcorper malesuada proin libero nunc.",
"releaseDate": "1993-01-01T00:00:00.000Z",
"contentRatings": [
{
"scheme": "US-Movie",
"rating": "PG"
},
{
"scheme": "CA-Movie",
"rating": "G"
}
]
}
}
}
}
```
</details>
---
</details>
```typescript
type InterestResult = {
appId: string
entity: EntityDetails
}
```
See also:
[](../Entity/schemas/
---
```typescript
type InterestEvent = {
appId: string
type: InterestType
reason: InterestReason
entity: EntityDetails
}
```
See also:
[](../Discovery/schemas/
[](../Discovery/schemas/
[](../Entity/schemas/
---