mirror of
https://github.com/koush/scrypted.git
synced 2026-02-07 16:02:13 +00:00
24 lines
1.0 KiB
TypeScript
24 lines
1.0 KiB
TypeScript
import { ScriptDevice } from "@scrypted/common/src/eval/monaco/script-device"; // SCRYPTED_FILTER_EXAMPLE_LINE
|
|
import sdk, { HttpRequest, HttpRequestHandler, HttpResponse, ScryptedDeviceBase, ScryptedInterface } from "@scrypted/sdk"; // SCRYPTED_FILTER_EXAMPLE_LINE
|
|
declare const device: ScriptDevice & ScryptedDeviceBase; // SCRYPTED_FILTER_EXAMPLE_LINE
|
|
const { endpointManager } = sdk; // SCRYPTED_FILTER_EXAMPLE_LINE
|
|
|
|
class WebhookExample implements HttpRequestHandler {
|
|
timeout: any;
|
|
|
|
async onRequest(request: HttpRequest, response: HttpResponse) {
|
|
response.send('OK');
|
|
device.motionDetected = true;
|
|
// reset the motion sensor after 10 seconds.
|
|
clearTimeout(this.timeout);
|
|
this.timeout = setTimeout(() => device.motionDetected = false, 10000);
|
|
}
|
|
}
|
|
|
|
device.handleTypes(ScryptedInterface.MotionSensor);
|
|
|
|
endpointManager.getLocalEndpoint(device.nativeId, { insecure: true, public: true })
|
|
.then(endpoint => console.log('motion webhook:', endpoint));
|
|
|
|
export default WebhookExample;
|