1.0.8 • Published 2 years ago

raylink-sdk v1.0.8

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Raylink SDK for JavaScript

Installation

You can install Raylink-SDK using the npm package manager.

npm install raylink-sdk --save

Usage

import { Client } from 'raylink-sdk'

const url = 'wss://xxxxxxxxxxxxxxxxxxxxxxxx'

const config = {
  bitrate: 300,
  fps: 60,
  video_width: 1920,
  video_height: 1080,
}

// Instantiate
const client = new Client()
client.connect()

client.onConnect((connected) => {
  if (connected) {
    // Start streaming
    client
      .start({
        url,
        config,
      })
      .then((res) => {
        console.log(res)
      })
  } else {
    console.log('RayLink client disconnected!')
    setTimeout(() => {
      client.connect()
    }, 3000)
  }
})

// Stop streaming
client.stop()

start()

The start() method takes the following parameters:

  • iceServers: RTCIceServer[], representing a list of ICE servers.
  • config: Config, an optional object parameter used to configure the streaming media.

config parameters:

  • bitrate?: number, representing the bitrate (bps), optional.
  • fps?: number, representing the frame rate, optional.
  • video_width?: number, representing the video width, optional.
  • video_height?: number, representing the video height, optional.
  • color_mode?: '420' | '444', representing the color space, optional.

stop()

client.stop()

After calling stop(), the streaming will be stopped.

executeCommand(command: string) Method

The executeCommand method is used to send any arbitrary message to the client. This can be useful for sending additional data or commands to the client during a streaming session. The method takes a single parameter, command, which should be a JSON string.

const command = JSON.stringify({
  message: 'data',
  data: { key: 'value' },
})
client.executeCommand(command)

onResponse(callback: (response: Response) => void) Method

The onResponse method is used to listen for any arbitrary response from the client. This method takes a callback function as its only parameter. The callback function will be called whenever a response is received from the client that matches the criteria specified in the callback. The response object will contain a message property to identify the message type and a data property that contains the data received from the client.

client.onResponse((res) => {
  if (res.message === 'data') {
    console.log(res.data)
  }
})
1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago