Camera controls
Add controls for Pan, Tilt, Zoom (PTZ) cameras and second cameras.
Pan, Tilt, Zoom (PTZ)
The Video SDK can control local and far end cameras that are compatible with the PTZ standard. You can use these functions to build a remote monitoring solution with camera control that allows the user to pan-tilt-zoom the device.
This is currently only supported on Chromium-based browsers on Windows. To determine whether your browser supports PTZ for a camera, go to the internal
about://media-internalspage and see the "Pan-Tilt-Zoom" column in the "Video Capture" tab.
Control local camera
To get the capability of the default camera on the device, call getCameraPTZCapability.
stream.getCameraPTZCapability();
If the device has multiple cameras attached, pass in a device ID as the cameraId to getCameraPTZCapability for the specific camera's capabilities.
let cameras = stream.getCameraList();
let cameraId = cameras[1].deviceId;
stream.getCameraPTZCapability(cameraId);
To control the local camera, call controlCamera, and pass in the cmd and range parameters.
stream.controlCamera({
cmd: CameraControlCmd.Left,
range: 10,
});
Control far end camera
To get control of a specific user's far end camera, the user will need to request control from the specific user and approve the request.
//User A on request control of User B's camera
stream.requestFarEndCameraControl(userBId);
// User B on receiving request for camera control
client.on("far-end-camera-request-control", (payload) => {
const { userId, displayName } = payload;
// popup a confirm window, approve or decline the request
stream.approveFarEndCameraControl(userId);
});
// User A on receiving control's request from User B
let isFarEndCameraApproved = false;
let capability = undefined;
client.on("far-end-camera-response-control", (payload) => {
const { isApproved, userId, displayName } = payload;
isFarEndCameraApproved = isApproved;
});
To get the capability of the far end camera, pass in the userId to getCameraPTZCapability. The function will return the far end camera capabilities if the user has already approved the request for far end camera control.
stream.getFarEndCameraPTZCapabilitiy(userId);
To control the far end camera, call controlFarEndCamera, and pass in the userId, cmd, and range parameters.
stream.controlFarEndCamera({
userId,
cmd: CameraControlCmd.Left,
range: 10,
});
To give up control of the camera, call giveUpFarEndCameraControl, and pass in the userId parameter.
stream.giveUpFarEndCameraControl(userId);
Share second camera content
You can share content from a second camera, such as an external USB camera (for example, a document camera or ultrasound camera) using the stream.startShareScreen() function. Once the user grants camera permission, get the list of cameras and pass in a deviceId share.
let cameras = stream.getCameraList();
if (stream.isStartShareScreenWithVideoElement()) {
// if MediaStreamTrackProcessor is supported
stream.startShareScreen(document.querySelector("#my-second-camera-video"), {
secondaryCameraId: cameras[1].deviceId,
});
} else {
// if MediaStreamTrackProcessor is not supported
stream.startShareScreen(
document.querySelector("#my-second-camera-canvas"),
{
secondaryCameraId: cameras[1].deviceId,
},
);
}