Privacy Module
Version 0.1.0-alpha.4
Overview
A module for managing device settings.
OpenRPC
Firebolt APIs are maintained in the rdkcentral/firebolt-manage-sdk.git GitHub repository.
You can see this API in the privacy.json OpenRPC JSON-Schema document.
Table of Contents
Usage
To use the Privacy module, you can import it into your project from the Firebolt SDK:
import { Privacy } from '@firebolt-js/manage-sdk'
Methods
enableRecommendations
Whether or not to the user has enabled history-based recommendations.
To get the value, call the method with no parameters:
function enableRecommendations(): Promise<boolean>
Promise resolution:
Type | Description |
---|---|
boolean |
Examples
Default Example
JavaScript:
import { Privacy } from '@firebolt-js/manage-sdk'
Privacy.enableRecommendations("some-app")
.then(share => {
console.log(share)
})
Value of share
:
true
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "privacy.enableRecommendations",
"params": {
"appId": "some-app"
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": true
}
To set the value, pass in the new value as the only parameter:
function enableRecommendations(value: boolean): Promise<void>
Parameters:
Param | Type | Required | Summary |
---|---|---|---|
value |
boolean |
true |
Promise resolution:
Type | Summary |
---|---|
void |
Promise resolves with no value when the operation is complete. |
Examples
JavaScript:
import { Privacy } from '@firebolt-js/manage-sdk'
Privacy.enableRecommendations(true)
.then(response => {
// property value has been set
})
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "privacy.setEnableRecommendations",
"params": {
"value": true
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": null
}
To subscribe to notifications when the value changes, pass a function as the only parameter:
function enableRecommendations(subscriber: (share: boolean) => void): Promise<boolean>
Parameters:
Param | Type | Required | Summary |
---|---|---|---|
subscriber |
Function |
Yes | A callback that gets invoked when the value for enableRecommendations changes |
Promise resolution:
Type | Summary |
---|---|
listenerId |
The id of the listener that can be used with Privacy.clear(listenerId) to unsubscribe |
Callback parameters:
Param | Type | Required | Summary |
---|---|---|---|
share |
boolean |
Yes |
Examples
Default Example
JavaScript:
import { Privacy } from '@firebolt-js/manage-sdk'
Privacy.enableRecommendations(share => {
// property value was changed
console.log(share)
}).then(listenerId => {
// you can clear this listener w/ Privacy.clear(listenerId)
})
value of share
:
true
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "privacy.onEnableRecommendationsChanged",
"params": {
"listen": true
}
}
Response:
{
"jsonrpc": "2.0",
"id": "1",
"result": {
"listening": "true"
}
}
{
"jsonrpc": "2.0",
"id": 1,
"result": true
}
listen
Listen for events from this module.
To listen to a specific event pass the event name as the first parameter:
Privacy.listen(event: string, (data: any) => void): Promise<bigint>
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 |
---|---|
bigint |
Listener ID to clear the callback method and stop receiving the event, e.g. Privacy.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:
Privacy.listen((event: string, data: any) => void): Promise<bigint>
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 |
---|---|
bigint |
Listener ID to clear the callback method and stop receiving the event, e.g. Privacy.clear(id) |
See Listening for events for more information and examples.
once
Listen for only one occurance of an event from this module. The callback will be cleared after one event.
To listen to a specific event pass the event name as the first parameter:
Privacy.once(event: string, (data: any) => void): Promise<bigint>
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 |
---|---|
bigint |
Listener ID to clear the callback method and stop receiving the event, e.g. Privacy.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:
Privacy.once((event: string, data: any) => void): Promise<bigint>
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 |
---|---|
bigint |
Listener ID to clear the callback method and stop receiving the event, e.g. Privacy.clear(id) |
See Listening for events for more information and examples.
provide
Register to provide a capability from this module.
See Provider Interfaces, for more info.
function provide(provider: object | class): Promise<void>
Parameters:
Param | Type | Required | Summary |
---|---|---|---|
provider |
`object | class` | true |
Promise resolution:
void
rememberWatchedPrograms
Whether or not to the user has enabled persistence of watch history content.
To get the value, call the method with no parameters:
function rememberWatchedPrograms(): Promise<boolean>
Promise resolution:
Type | Description |
---|---|
boolean |
Examples
Default Example
JavaScript:
import { Privacy } from '@firebolt-js/manage-sdk'
Privacy.rememberWatchedPrograms("some-app")
.then(remember => {
console.log(remember)
})
Value of remember
:
true
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "privacy.rememberWatchedPrograms",
"params": {
"appId": "some-app"
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": true
}
To set the value, pass in the new value as the only parameter:
function rememberWatchedPrograms(value: boolean): Promise<void>
Parameters:
Param | Type | Required | Summary |
---|---|---|---|
value |
boolean |
true |
Promise resolution:
Type | Summary |
---|---|
void |
Promise resolves with no value when the operation is complete. |
Examples
JavaScript:
import { Privacy } from '@firebolt-js/manage-sdk'
Privacy.rememberWatchedPrograms(true)
.then(response => {
// property value has been set
})
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "privacy.setRememberWatchedPrograms",
"params": {
"value": true
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": null
}
To subscribe to notifications when the value changes, pass a function as the only parameter:
function rememberWatchedPrograms(subscriber: (remember: boolean) => void): Promise<boolean>
Parameters:
Param | Type | Required | Summary |
---|---|---|---|
subscriber |
Function |
Yes | A callback that gets invoked when the value for rememberWatchedPrograms changes |
Promise resolution:
Type | Summary |
---|---|
listenerId |
The id of the listener that can be used with Privacy.clear(listenerId) to unsubscribe |
Callback parameters:
Param | Type | Required | Summary |
---|---|---|---|
remember |
boolean |
Yes |
Examples
Default Example
JavaScript:
import { Privacy } from '@firebolt-js/manage-sdk'
Privacy.rememberWatchedPrograms(remember => {
// property value was changed
console.log(remember)
}).then(listenerId => {
// you can clear this listener w/ Privacy.clear(listenerId)
})
value of remember
:
true
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "privacy.onRememberWatchedProgramsChanged",
"params": {
"listen": true
}
}
Response:
{
"jsonrpc": "2.0",
"id": "1",
"result": {
"listening": "true"
}
}
{
"jsonrpc": "2.0",
"id": 1,
"result": true
}
shareWatchHistory
Whether or not the user has enabled app watch history data to be shared with the platform.
To get the value, call the method with no parameters:
function shareWatchHistory(): Promise<boolean>
Promise resolution:
Type | Description |
---|---|
boolean |
Examples
Default Example
JavaScript:
import { Privacy } from '@firebolt-js/manage-sdk'
Privacy.shareWatchHistory("some-app")
.then(share => {
console.log(share)
})
Value of share
:
true
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "privacy.shareWatchHistory",
"params": {
"appId": "some-app"
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": true
}
To set the value, pass in the new value as the only parameter:
function shareWatchHistory(value: boolean): Promise<void>
Parameters:
Param | Type | Required | Summary |
---|---|---|---|
value |
boolean |
true |
Promise resolution:
Type | Summary |
---|---|
void |
Promise resolves with no value when the operation is complete. |
Examples
JavaScript:
import { Privacy } from '@firebolt-js/manage-sdk'
Privacy.shareWatchHistory(true)
.then(response => {
// property value has been set
})
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "privacy.setShareWatchHistory",
"params": {
"value": true
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": null
}
To subscribe to notifications when the value changes, pass a function as the only parameter:
function shareWatchHistory(subscriber: (share: boolean) => void): Promise<boolean>
Parameters:
Param | Type | Required | Summary |
---|---|---|---|
subscriber |
Function |
Yes | A callback that gets invoked when the value for shareWatchHistory changes |
Promise resolution:
Type | Summary |
---|---|
listenerId |
The id of the listener that can be used with Privacy.clear(listenerId) to unsubscribe |
Callback parameters:
Param | Type | Required | Summary |
---|---|---|---|
share |
boolean |
Yes |
Examples
Default Example
JavaScript:
import { Privacy } from '@firebolt-js/manage-sdk'
Privacy.shareWatchHistory(share => {
// property value was changed
console.log(share)
}).then(listenerId => {
// you can clear this listener w/ Privacy.clear(listenerId)
})
value of share
:
true
JSON-RPC:
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "privacy.onShareWatchHistoryChanged",
"params": {
"listen": true
}
}
Response:
{
"jsonrpc": "2.0",
"id": "1",
"result": {
"listening": "true"
}
}
{
"jsonrpc": "2.0",
"id": 1,
"result": true
}
Additional methods
The following methods are documented as part of a related set of method APIs.
For more information, follow the links under the “Documentation” column.
JavaScript | RPC | Parameters | Documentation |
---|---|---|---|
NA | setShareWatchHistory | (appId: string, share: boolean) |
shareWatchHistory |
NA | setEnableRecommendations | (appId: string, share: boolean) |
enableRecommendations |
NA | setRememberWatchedPrograms | (appId: string, remember: boolean) |
rememberWatchedPrograms |
NA | contentPolicyResponse | (response: ProviderResponse) |
ContentPolicyProvider |
Events
Additional events
The following events are documented as part of a related set of method APIs.
For more information, follow the links under the “Documentation” column.
JavaScript | RPC | Payload | Documentation |
---|---|---|---|
NA | onRequestContentPolicy | ProviderRequest | |
shareWatchHistoryChanged | onShareWatchHistoryChanged | boolean | shareWatchHistory |
enableRecommendationsChanged | onEnableRecommendationsChanged | boolean | enableRecommendations |
rememberWatchedProgramsChanged | onRememberWatchedProgramsChanged | boolean | rememberWatchedPrograms |
Provider Interfaces
Providers are interfaces that your app can implement in order to provide certain capabilties back to the platform.
To register a provider, use the provide()
method.
Every provider interface method has the following signature:
(parameters: object | void, session: ProviderSession) => {}
ProviderSession
has the following interface:
interface ProviderSession {
correlationId(): string // Returns the correlation id of the current provider session
}
ContentPolicyProvider
The provider interface for the xrn:firebolt:capability:privacy:content
capability.
interface ContentPolicyProvider {
contentPolicy(parameters?: object, session?: ProviderSession): Promise<ContentPolicy>
}
Usage:
Privacy.provide('xrn:firebolt:capability:privacy:content', provider: ContentPolicyProvider | object)
contentPolicy
Request the content privacy settings for a specific app.
function contentPolicy(parameters?: object, session?: ProviderSession): Promise<ContentPolicy>
Provider methods always have two arguments:
Param | Type | Required | Summary |
---|---|---|---|
parameters |
object |
false | |
session |
ProviderSession |
false |
Promise resolution:
Type | Description |
---|---|
ContentPolicy |
Examples
Register your app to provide the xrn:firebolt:capability:privacy:content
capability.
import { Privacy } from '@firebolt-js/manage-sdk'
class MyContentPolicyProvider {
async contentPolicy(parameters, session) {
return await Promise.resolve({
"enableRecommendations": true,
"shareWatchHistory": false,
"rememberWatchedPrograms": true
})
}
}
Privacy.provide('xrn:firebolt:capability:privacy:content', new MyContentPolicyProvider())
**JSON-RPC**
Register to recieve each provider API
Request:
{
"id": 1,
"method": "onRequestContentPolicy",
"params": {
"listen": true
}
}
Response:
{
"id": 1,
"result": {
"listening": true,
"event": "Privacy.onRequestContentPolicy"
}
}
Asynchronous event to initiate contentPolicy()
Event Response:
{
"id": 1,
"result": {
"correlationId": "xyz",
"parameters": null
}
}
App initiated response to event
Request:
{
"id": 2,
"method": "contentPolicyResponse",
"params": {
"response": {
"correlationId": "xyz",
"result": {
"enableRecommendations": true,
"shareWatchHistory": false,
"rememberWatchedPrograms": true
}
}
}
}
Response:
{
"id": 2,
"result": true
}