SecondScreen

    SecondScreen


    Article summary


    title: SecondScreen

    version: 0.5.3
    layout: default
    sdk: core

    # SecondScreen Module

    Version 0.5.3

    OpenRPC

    This document was generated from an OpenRPC JSON-Schema, and is intended to provide a human readable overview and examples of the methods contained in the module.

    For the full schema, see the link below.

    Schema
    secondscreen.json

    Table of Contents

    Usage

    To use the SecondScreen module, you can import it into your project from the Firebolt SDK:

    import { SecondScreen } from '@firebolt-js/sdk'
    

    Overview

    Methods for communicating with second screen devices

    Events

    launchRequest

    Listen to the launchRequest event

    // listen to launchRequest
    SecondScreen.listen('launchRequest', (data: SecondScreenEvent) => void): Promise<bigint>
    
    // listen to launchRequest once
    SecondScreen.once('launchRequest', (data: SecondScreenEvent) => void): Promise<bigint>
    
    // clear a listener
    SecondScreen.clear(listenerId?: bigint): void
    
    

    Event value

    TypeDescription
    SecondScreenEventAn a message notification from a second screen device

    Promise Resolution

    TypeDescription
    bigintListener ID to clear() the callback method and stop receiving the event, e.g. SecondScreen.clear(id)

    Examples

    ##### Default Example

    JavaScript
    import { SecondScreen } from '@firebolt-js/sdk'
    
    SecondScreen.listen('launchRequest', launchRequestEvent => {
      console.log(launchRequestEvent)
    })
    

    Value of launchRequestEvent

    {
      "type": "dial",
      "version": "1.7",
      "data": "{\"code\":\"AQDPQZiQcb3KQ7gY7yy5tHTMbbkGHR9Zjp-KL53H3eKBZIeAt7O9UKYPu6B21l2UZVmIqkFXDXBmXvK4g2e3EgZtjMNmKPsTltgnRl95DImtOXjSpWtTjSaOkW4w1kZKUTwLKdwVWTzBVH8ERHorvLU6vCGOVHxXt65LNwdl5HKRweShVC1V9QsyvRnQS61ov0UclmrH_xZML2Bt-Q-rZFjey5MjwupIb4x4f53XUJMhjHpDHoIUKrjpdPDQvK2a\",\"friendlyName\":\"Operator_TX061AEI\",\"UDN\":\"608fef11-2800-482a-962b-23a6690c93c1\"}"
    }
    
    JSON-RPC

    Request

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "secondscreen.onLaunchRequest",
      "params": {
        "listen": true
      }
    }
    

    Response

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": {
        "type": "dial",
        "version": "1.7",
        "data": "{\"code\":\"AQDPQZiQcb3KQ7gY7yy5tHTMbbkGHR9Zjp-KL53H3eKBZIeAt7O9UKYPu6B21l2UZVmIqkFXDXBmXvK4g2e3EgZtjMNmKPsTltgnRl95DImtOXjSpWtTjSaOkW4w1kZKUTwLKdwVWTzBVH8ERHorvLU6vCGOVHxXt65LNwdl5HKRweShVC1V9QsyvRnQS61ov0UclmrH_xZML2Bt-Q-rZFjey5MjwupIb4x4f53XUJMhjHpDHoIUKrjpdPDQvK2a\",\"friendlyName\":\"Operator_TX061AEI\",\"UDN\":\"608fef11-2800-482a-962b-23a6690c93c1\"}"
      }
    }
    

    ##### Listen to an event only once

    JavaScript
    SecondScreen.listen('launchRequest', (value) => {
      console.log(value)
    }).then( (listenerId) => {
      SecondScreen.clear(listenerId)
    })
    

    Alternately, simply call once():

    SecondScreen.once('launchRequest', (value) => {
      console.log(value)
    })
    

    ##### Clear all listeners for an event

    JavaScript
    SecondScreen.clear('launchRequest')
    

    closeRequest

    Listen to the closeRequest event

    // listen to closeRequest
    SecondScreen.listen('closeRequest', (data: SecondScreenEvent) => void): Promise<bigint>
    
    // listen to closeRequest once
    SecondScreen.once('closeRequest', (data: SecondScreenEvent) => void): Promise<bigint>
    
    // clear a listener
    SecondScreen.clear(listenerId?: bigint): void
    
    

    Event value

    TypeDescription
    SecondScreenEventAn a message notification from a second screen device

    Promise Resolution

    TypeDescription
    bigintListener ID to clear() the callback method and stop receiving the event, e.g. SecondScreen.clear(id)

    Examples

    ##### Default Example

    JavaScript
    import { SecondScreen } from '@firebolt-js/sdk'
    
    SecondScreen.listen('closeRequest', closeRequestEvent => {
      console.log(closeRequestEvent)
    })
    

    Value of closeRequestEvent

    {
      "type": "dial",
      "version": "1.7"
    }
    
    JSON-RPC

    Request

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "secondscreen.onCloseRequest",
      "params": {
        "listen": true
      }
    }
    

    Response

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": {
        "type": "dial",
        "version": "1.7"
      }
    }
    

    ##### Listen to an event only once

    JavaScript
    SecondScreen.listen('closeRequest', (value) => {
      console.log(value)
    }).then( (listenerId) => {
      SecondScreen.clear(listenerId)
    })
    

    Alternately, simply call once():

    SecondScreen.once('closeRequest', (value) => {
      console.log(value)
    })
    

    ##### Clear all listeners for an event

    JavaScript
    SecondScreen.clear('closeRequest')
    

    Methods

    protocols

    Get the supported second screen discovery protocols

    function protocols(): Promise<BooleanMap>
    

    Promise Resolution

    TypeDescription
    BooleanMapthe supported protocols

    Examples

    ##### Default Example

    JavaScript
    import { SecondScreen } from '@firebolt-js/sdk'
    
    SecondScreen.protocols()
        .then(protocols => {
            console.log(protocols)
        })
    

    Value of protocols

    {
      "dial1.7": true
    }
    
    JSON-RPC

    ###### Request

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "secondscreen.protocols",
      "params": {}
    }
    

    ###### Response

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": {
        "dial1.7": true
      }
    }
    

    device

    Get the broadcasted id for the device

    function device(type?: string): Promise<string>
    

    Parameters

    ParamTypeRequiredSummary
    typestringfalseThe type of second screen protocol, e.g. "dial"

    Promise Resolution

    TypeDescription
    stringthe device id

    Examples

    ##### Default Example

    JavaScript
    import { SecondScreen } from '@firebolt-js/sdk'
    
    SecondScreen.device(null)
        .then(deviceId => {
            console.log(deviceId)
        })
    

    Value of deviceId

    "device-id"
    
    JSON-RPC

    ###### Request

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "secondscreen.device",
      "params": {}
    }
    

    ###### Response

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": "device-id"
    }
    

    friendlyName

    Get the broadcasted friendly name for the device

    function friendlyName(type?: string): Promise<string>
    

    Parameters

    ParamTypeRequiredSummary
    typestringfalseThe type of second screen protocol, e.g. "dial"

    Promise Resolution

    TypeDescription
    stringthe device friendly-name

    Examples

    ##### Default Example

    JavaScript
    import { SecondScreen } from '@firebolt-js/sdk'
    
    SecondScreen.friendlyName(null)
        .then(friendlyName => {
            console.log(friendlyName)
        })
    

    Value of friendlyName

    "Living Room"
    
    JSON-RPC

    ###### Request

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "secondscreen.friendlyName",
      "params": {}
    }
    

    ###### Response

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": "Living Room"
    }
    


    Was this article helpful?