UNPKG

homebridge-shinobi

Version:

A Homebridge plugin integrating Shinobi for motion detector cameras

83 lines 3.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ShinobiMonitorAccessory = void 0; const shinobiStreamingDelegate_1 = require("./shinobiStreamingDelegate"); /** * Shinobi Monitor Accessory */ class ShinobiMonitorAccessory { constructor(platform, accessory, monitor, config) { this.platform = platform; this.accessory = accessory; this.monitor = monitor; this.config = config; this.hap = this.platform.api.hap; this.motionDetected = false; // set accessory information this.accessory.getService(this.platform.Service.AccessoryInformation) .setCharacteristic(this.platform.Characteristic.Manufacturer, 'Default-Manufacturer') .setCharacteristic(this.platform.Characteristic.Model, 'Default-Model') .setCharacteristic(this.platform.Characteristic.SerialNumber, 'Default-Serial'); // get the MotionSensor service if it exists, otherwise create a new MotionSensor service this.motionService = this.accessory.getService(this.platform.Service.MotionSensor) || this.accessory.addService(this.platform.Service.MotionSensor); // set the service name, this is what is displayed as the default name on the Home app this.motionService.setCharacteristic(this.platform.Characteristic.Name, `${this.monitor.monitorConfig.monitor_id} motion`); // register handler for the Motion Characteristic this.motionService.getCharacteristic(this.platform.Characteristic.MotionDetected) .on('get', this.getMotionDetected.bind(this)); this.shinobiStreamingDelegate = new shinobiStreamingDelegate_1.ShinobiStreamingDelegate(this.platform, this.hap, this.monitor, this.config); const options = { cameraStreamCount: 2, delegate: this.shinobiStreamingDelegate, streamingOptions: { srtp: true, proxy: false, supportedCryptoSuites: [0 /* SRTPCryptoSuites.AES_CM_128_HMAC_SHA1_80 */], video: { codec: { profiles: [1 /* H264Profile.MAIN */], levels: [2 /* H264Level.LEVEL4_0 */] }, resolutions: [ [640, 360, 20] ] } } }; const cameraController = new this.hap.CameraController(options); this.shinobiStreamingDelegate.controller = cameraController; accessory.configureController(cameraController); } /** * Handle the "GET" requests from HomeKit * These are sent when HomeKit wants to know the current state of the accessory. */ getMotionDetected(callback) { this.platform.log.debug(`getMotionDetected() -> ${this.motionDetected}`); callback(null, this.motionDetected); } /** * Handle update from shinobi webhook */ setMotionDetected(detected) { this.motionDetected = detected; // push the new value to HomeKit this.motionService.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.motionDetected); this.platform.log.debug(`pushed updated current MotionDetected state to HomeKit: ${this.motionDetected}`); // reset motion state after one second if (detected) { setTimeout(() => { this.setMotionDetected(false); }, 1000); } } /** * Handle homebridge shutdown */ shutdown() { this.shinobiStreamingDelegate.shutdown(); } } exports.ShinobiMonitorAccessory = ShinobiMonitorAccessory; //# sourceMappingURL=shinobiMonitorAccessory.js.map