.watchers.add
Registers one or more areas to watch with Lampix.

Arguments

  1. 1.
    ...watchers (Watcher[]) Comma separated watcher objects or one level deep arrays of watcher objects.

Returns

(Promise<RegisteredWatcher[]>): A promise that fulfills with a list of RegisteredWatcher objects, equal in length to the number of watcher objects provided to the function

Example

1
import lampix from '@lampix/core';
2
3
const draw = (recognizedObject) => {
4
// Drawing amazing effects
5
};
6
7
const watcher = {
8
name: 'DepthClassifier',
9
shape: lampix.helpers.rectangle(0, 0, window.innerWidth, window.innerHeight),
10
onClassification: (recognizedObjects) => {
11
recognizedObjects.forEach(draw);
12
}
13
};
14
15
lampix.watchers.add(watcher)
16
.then((registeredWatchers) => {
17
console.log(registeredWatchers.length); // 1
18
});
Copied!

Notes

If the method receives arrays, it will concatenate them into a single array that will be sent to Lampix. The promise will be resolved with a single array of watchers, in the same order that they were added. For instance:
1
import lampix from '@lampix/core';
2
3
const draw = (recognizedObject) => {
4
// Drawing amazing effects
5
};
6
7
const watcher = {
8
name: 'DepthClassifier',
9
shape: lampix.helpers.rectangle(0, 0, window.innerWidth, window.innerHeight),
10
onClassification: (recognizedObjects) => {
11
recognizedObjects.forEach(draw);
12
}
13
};
14
15
const otherWatchers = {
16
{
17
// ...
18
},
19
{
20
// ...
21
}
22
}
23
24
lampix.watchers.add(watcher, otherWatchers)
25
.then((registeredWatchers) => {
26
console.log(registeredWatchers.length); // 3
27
console.log(registeredWatchers); // registered watchers corresponding to watcher, otherWatchers[0] and otherWatchers[1], in this order
28
});
Copied!