Videos

Devices can add support for streaming video, which can be viewed from the mobile app & dashboards.

circle-info

Videos are available on Homey Pro (Early 2023) and Homey Pro mini since v12.7.0, and Homey Cloud.

Your app's devices can let Homey know that they support a video stream. Once a front-end (e.g. the Homey app for iOS & Android) requests to start watching, your app will receive a request to share the stream's details, such as URL and authentication. The app, nor Homey, does any transcoding, but acts as a broker between the camera and the front-end.

Supported Video Types

Homey supports video streams with WebRTC, RTSP, RTMP, HLS, DASH. Other types may be supported. Because the Homey Mobile App embeds a VLC media player, you can always try to see if your video type works.

Getting Started with Videos

To register a camera stream, your app needs to ask ManagerVideosarrow-up-right first to create a video. Then, attach the video to your Device by calling Device.setCameraVideo. Note that when a device has both an image and video with the same id then the image will be used as a background image for the video while it is loading.

Example β€” WebRTC

This example shows a basic WebRTC camera stream.

/drivers/my-webrtc-camera/device.mjs
import Homey from 'homey';

export default class MyWebRTCDevice extends Homey.Device {

    /*
     * WebRTC works by creating an offer SDP in the frontend, exchanging it for 
     * an answer SDP through the cameras API, and using that answer SDP in the
     * frontend to set up the connection.
     */
    async onInit() {
        try {
            const video = await this.homey.videos.createVideoWebRTC();

            /*
             * This listener is called when the user opens the camera stream in the
             * mobile app. The argument is an SDP offer generated by the mobile appp.
             */
            video.registerOfferListener(async (offerSdp) => {
                // Normally, you would call an API to exchange an SDP offer for an SDP answer
                const result = await this.oAuth2Client.createStream(offerSdp);
                return {
                    answerSdp: result.answerSdp,
                };
            });

            /*
             * Attach the camera to the device.
             */
            await this.setCameraVideo('main', 'Main Camera', video);
        } catch (err) {
            this.error('Error creating camera:', err);
        }   
    }
    
}

Example β€” WebRTC without Data Channel

This example shows a WebRTC camera without a data channel, and a keepalive listener.

Example β€” RTSP

This example shows an RTSP camera, which is as simple as providing an URL. In this example, we use HTTP Basic Authentication (username:password@...) in the URL.

Example β€” RTMP

This example shows an RTMP camera, which is as simple as providing an URL. It's very similar to RTSP.

Example β€” HLS

This example shows an HLS camera, which is as simple as providing an URL. It's very similar to RTSP.

Example β€” DASH

This example shows an DASH camera, which is as simple as providing an URL. It's very similar to RTSP.

Apps SDK Reference

Please refer to ManagerVideosarrow-up-right in the Apps SDK Reference to learn more about videos in your app.

Last updated

Was this helpful?