CameraEnhancer - Auxiliary
Name | Description |
---|---|
on() | Registers an event listener for specific camera-related events. |
off() | Removes an event listener previously registered with the on method. |
Type definition used on this page:
type EventName ="cameraOpen" | "cameraClose" | "cameraChange" | "resolutionChange" | "played" | "singleFrameAcquired" | "frameAddedToBuffer";
Built-in Event Reference Table
Event Name | Description |
---|---|
cameraOpen | Triggered when the camera opens. |
cameraClose | Triggered when the camera closes. |
cameraChange | Triggered when a different camera is used. |
resolutionChange | Triggered when the resolution changes. |
played | Triggered when the video starts playing/streaming. |
singleFrameAcquired | Triggered when an image is acquired under the single-frame mode. |
frameAddedToBuffer | Triggered each time a new frame is added to the buffer. |
NOTE:
When the event “singleFrameAcquired” is triggered, the acquired image data will be returned as a reference, not a copy. Therefore, any changes to it will change the data source, and if another callback returns the same image data, the modifications will be synchronized.
on
Registers an event listener for specific camera-related events.
on(eventName: EventName, listener: Function): void;
Parameters
eventName
: the name of the event to listen for. Possible values include “cameraOpen”, “cameraClose”, “cameraChange”, “resolutionChange”, “played”, “singleFrameAcquired”, and “frameAddedToBuffer”.
listener
: the callback function to be invoked when the event occurs.
Return value
None.
Code Snippet
let cameraEnhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance();
cameraEnhancer.on("cameraOpen", () => {
console.log("Camera opened.");
});
cameraEnhancer.on("cameraClose", () => {
console.log("Camera closed.");
});
cameraEnhancer.on("cameraChange", (deviceId, previousDeviceId) => {
console.log("Camera changed.");
});
cameraEnhancer.on("resolutionChange", (resolution, previousResolution) => {
console.log("Resolution changed.");
});
cameraEnhancer.on("played", () => {
console.log("Video stream started.");
});
cameraEnhancer.on("singleFrameAcquired", dceFrame => {
console.log("An image is acquired under the single-frame mode.");
});
cameraEnhancer.on("frameAddedToBuffer", () => {
console.log("A new frame is added to the buffer.");
});
off
Removes an event listener previously registered with the on
method.
off(eventName: EventName, listener: Function): void;
Parameters
eventName
: the name of the event to listen for. Possible values include “cameraOpen”, “cameraClose”, “cameraChange”, “resolutionChange”, “played”, “singleFrameAcquired”, and “frameAddedToBuffer”.
listener
: the callback function to be invoked when the event occurs.
Return value
None.
Code Snippet
let cameraEnhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance();
let cameraChanged = playCallBackInfo => {
console.log(playCallBackInfo.deviceId);
cameraEnhancer.off("cameraChange", cameraChanged);
}
cameraEnhancer.on("cameraChange", cameraChanged);