Caster: Mobile Media Cast Control

更新时间:
2024-06-05
下载文档

Caster: Mobile Media Cast Control

The caster module provides many interfaces for applications to implement screen casting functions. Through these interfaces, you can mirror the content on your smartphone screen to a compatible device such as a smart TV, computer or projector. The Screen Casting Assistant's features aim to enhance both entertainment and work experiences, allowing users to flexibly utilize their smartphones and other larger display devices.

Developers can determine whether these interfaces work in the EdgerOS mobile App environment through the following code:

edger.env().then(data => {
  if (data.env === 'edgerapp') {
    // We work in EdgerOS mobile App environment.
  }
}).catch(error => {
  console.error(error)
})

Functions

edger.caster.getStatus()

Get screen casting status.

  • Returns: {Promise} Fulfill upon success with an object.

Get an object of result, the object includes:

  • result {Object} Contain information about the execution result, it can contain the following members:
    • status {String} The status of the operation, with possible values: running and stop.

Example

edger.caster.getStatus().then((res) => {
  console.log('get caster status successful.', res)
})

async / await

async function casterStatus() {
  try {
    const res = await edger.caster.getStatus();
    console.log('get caster status successful.', res)
  } catch (error) {
    console.error(error)
  }
}

edger.caster.start(options)

Initialize screen casting configuration, and starting screen casting refers to initiating the screen casting service to project the content of the device's screen onto another display device.

  • options {CasterConfig} The initialization parameters of the screen casting, it can contain the following members:
    • udn {Boolean} The unique device identifier (UDN) of the device to be casted.
    • multicastLoop {String} Whether to enable broadcast loopback.
    • mode {String} Screen casting service enabled mode. Optional values: both | msresponse | notify.
    • proxy {Boolean} Whether to enable the proxy. If set to true, the proxy function will be enabled. Default: true.
    • target {Object} Configuration for the screen casting target, it can contain the following members:
      • url {String} Screen casting target address.
      • headers {Object} Custom request headers.
  • Returns: {Promise}.

Get an object of result, the object includes:

  • result {Object} Contain information about the execution result, it can contain the following members:
    • message {String} Detailed information about the operation, with possible values: SuccessFailSocket failedServer is starting and Server is running.
    • status {String} The status of the operation, with possible values: ok and error.

Example

const params = {
  udn: 'xxxxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx',
  multicastLoop: true,
  mode: 'both',
  proxy: true
  target: {
    url: 'https://qrd3xo-ajcrjir.qgbist-eulemt.edgeros.vip:7258/proxy/xml/description.xml',
    headers: {}
  }
}
edger.caster.getStatus().then(res => {
  if (res.status === 'stop') {
    edger.caster.start(params).then((res1) => {
      console.log('caster start successful.', res1)
    })
  }
})

async / await

async function casterStart() {
  try {
    const res = await edger.caster.getStatus();
    if (res.status === 'stop') {
      const res1 = await edger.caster.start(params);
      console.log('caster start successful.', res1)
    }
  } catch (error) {
    console.error(error)
  }
}

edger.caster.stop()

Exit screen casting.

  • Returns: {Promise} Fulfill upon success with an object.

Get an object of result, the object includes:

  • result {Object} Contain information about the execution result, it can contain the following members:
    • message {String} Detailed information about the operation, with possible values: SuccessFail and You should start first.
    • status {String} The status of the operation, with possible values: ok and error.

Example

edger.caster.getStatus().then(res => {
  if (res.status === 'running') {
    edger.caster.stop().then((res1) => {
      console.log('caster stop successful.', res1)
    })
  }
})

async / await

async function casterStop() {
  try {
    const res = await edger.caster.getStatus();
    if (res.status === 'running') {
      const res1 = await edger.caster.stop();
      console.log('caster stop successful.', res1)
    }
  } catch (error) {
    console.error(error)
  }
}

Events

The unified event listener provided by Web-SDK:

const listener = (payload) => {
  // Event handling...
}

// add listener
edger.caster.addEventListener('some-event', listener)

// or 
// onAction() is an alias of addEventListener().
edger.caster.onAction('some-event', listener)

// remove listener
edger.caster.removeEventListener('some-event', listener)

// remove all listeners
edger.caster.removeAllListeners()

status

Monitor the status of screen casting service.

  • Returns: {Object}.

Get an object of result, the object includes:

  • status {String} Current status of the screen casting service. Optional values: running | stop.

Example

edger.caster.addEventListener('status', (payload) => {
  console.log("screen casting status:", payload.status)
})
文档内容是否对您有所帮助?
有帮助
没帮助