WebCams library is a part of exalushome-webcams that allows you to manage web cameras added to TR7 controller.
If you want to use this library in any JavaScript or TypeScript project you can use npm to install it as package from npm repository. For that you will have to use command:
npm install lavva.exalushome.webcams
or
yarn add lavva.exalushome.webcams
If you have installed this package then you have to initialize this library first before usage. To do this, you have to call:
import { IWebCamsService, WebCamConfiguration } from 'lavva.exalushome.webcams/build/js/IWebCamsService';
import { WebCamsService } from 'lavva.exalushome.webcams';
WebCamsService.Init();
The library is based on the DI of exalushome-library, so you need to load the base service from the API, then you can load WebCams Services.
let cams = Api.Get<IWebCamsService>(WebCamsService.ServiceName);
<video id="webCam" autoPlay playsInline muted controls style="width: 100%"></video>
To display video stream from this device you have to get media stream and set it as video tag's srcObject.
You can do this like that:
// Get web cam object
let cam = await cams.GetWebCamAsync(camDev);
// get miedia stream for given camera
let mediaStream = await cam.GetRTCMediaStreamAsync();
//set media stream to <video> tak by setting srcObject for example in this way:
(document.getElementById("webCam") as HTMLMediaElement).srcObject = mediaStream;