Camera

The Camera class represents a camera stream that can be used to provide video streaming functionality to Homey. It supports multiple streaming protocols including WebRTC for real-time communication and various URL-based streams.

Camera instances are created through ManagerCameras#createCamera and should be associated with a device using Device#setCamera to enable camera streaming in the Homey interface.

Constructor

Camera

new Camera(manager, id, client, type)

Parameters

Name Type Description
manager
ManagerCamera
id
string
client
any
type
string

Examples

Creating and configuring a WebRTC camera

// In your device.js file
async onInit() {
  const camera = await this.homey.cameras.createCamera({
    type: 'webrtc',
    options: {}
  });

  camera.registerOfferListener(async (offerSdp) => {
    // Handle WebRTC negotiation
    return await this.handleWebRTCOffer(offerSdp);
  });

  camera.registerKeepAliveListener(async (streamId) => {
    // Maintain active stream
    await this.refreshStream(streamId);
  });

  await this.setCamera(camera);
}

Creating an RTSP camera stream

// In your device.js file
async onInit() {
  const camera = await this.homey.cameras.createCamera({
    type: 'rtsp',
    options: {}
  });

  camera.registerVideoUrlListener(async () => {
    return `rtsp://${this.getSetting('ip')}:554/stream`;
  });

  await this.setCamera(camera);
}

Instance Methods

registerKeepAliveListener

registerKeepAliveListener(listener): Camera

Register a listener for WebRTC keep alive events. This is invoked when Homey sends keep alive signals for active WebRTC streams.

Parameters

Name Type Description
listener
function

Function that receives the stream ID

Returns

Example

camera.registerKeepAliveListener(async (streamId) => {
  // Handle keep alive for the stream
  await refreshStream(streamId);
});

registerOfferListener

registerOfferListener(listener): Camera

Register a listener for WebRTC offer events. This is invoked when Homey requests an SDP answer for a WebRTC offer.

Parameters

Name Type Description
listener
function

Function that receives the offer SDP and returns the answer SDP

Returns

Example

camera.registerOfferListener(async (offerSdp) => {
  // Process the WebRTC offer and return answer SDP
  return await generateAnswerSdp(offerSdp);
});

registerVideoUrlListener

registerVideoUrlListener(listener): Camera

Register a listener for video URL requests. This is invoked when Homey requests the video stream URL.

Parameters

Name Type Description
listener
function

Function that returns the video stream URL

Returns

Example

camera.registerVideoUrlListener(async () => {
  return 'rtsp://camera.local:554/stream';
});