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,SAAU,CACtB,KAAK,IAAI,KAAK,eAAiB,KAAK,OAAO,UAAY,kBAAoB,IACvE,uBAAyB,KAAK,OAAO,SAAW,OACpD,MAAM,EAAS,OAAO,QAAQ,eACxB,EAAW,KAAK,OAAO,UAAY,iBAAc,EACvD,EAAO,OAAO,KAAK,OAAO,SAAU,GACpC,EAAO,GAAG,WAAW,CAAC,EAAS,KAC3B,IAAI,EAAU,CACV,OAAO,EACP,QAAS,kBAEb,GAAI,EAAQ,IAAK,CACb,MAAM,EAAW,EAAQ,IAAI,MAAM,KACnC,GAAuB,GAAnB,EAAS,OAAa,CACtB,MAAM,EAAO,mBAAmB,EAAS,IAAI,MAAM,KAAK,GACxD,EAAU,KAAK,YAAY,EAAS,GAAI,EAC5C,CACJ,CACA,EAAS,UAAU,EAAQ,MAAQ,IAAM,KACzC,EAAS,MAAM,KAAK,UAAU,IAC9B,EAAS,KAAK,GAEtB,CACA,KAAK,kBAAkB,SAAS,IAC5B,MAAM,EAAe,KAAK,cAAc,IAAI,EAAU,MACjD,IAAgB,EAAa,WAC9B,KAAK,IAAI,KAAK,gCAAiC,EAAU,aACzD,KAAK,IAAI,8BAA8B,YAAa,cAAe,CAAC,IACxE,GAER,EAEJ,OAAO,QAAW,IACd,IAAM,EAAI,IACV,UAAY,EAAI,kBAChB,EAAI,iBAAiB,YAAa,cAAe,eAAe","file":"/npm/homebridge-camera-ffmpeg@3.1.4/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/homebridge-camera-ffmpeg@3.1.4/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n    return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nconst http_1 = __importDefault(require(\"http\"));\nconst mqtt_1 = __importDefault(require(\"mqtt\"));\nconst logger_1 = require(\"./logger\");\nconst streamingDelegate_1 = require(\"./streamingDelegate\");\nconst version = require('../package.json').version;\nlet hap;\nlet Accessory;\nconst PLUGIN_NAME = 'homebridge-camera-ffmpeg';\nconst PLATFORM_NAME = 'Camera-ffmpeg';\nclass FfmpegPlatform {\n    constructor(log, config, api) {\n        var _a;\n        this.cameraConfigs = new Map();\n        this.cachedAccessories = [];\n        this.accessories = [];\n        this.motionTimers = new Map();\n        this.doorbellTimers = new Map();\n        this.mqttActions = new Map();\n        this.log = new logger_1.Logger(log);\n        this.api = api;\n        this.config = config;\n        (_a = this.config.cameras) === null || _a === void 0 ? void 0 : _a.forEach((cameraConfig) => {\n            let error = false;\n            if (!cameraConfig.name) {\n                this.log.error('One of your cameras has no name configured. This camera will be skipped.');\n                error = true;\n            }\n            if (!cameraConfig.videoConfig) {\n                this.log.error('The videoConfig section is missing from the config. This camera will be skipped.', cameraConfig.name);\n                error = true;\n            }\n            else {\n                if (!cameraConfig.videoConfig.source) {\n                    this.log.error('There is no source configured for this camera. This camera will be skipped.', cameraConfig.name);\n                    error = true;\n                }\n                else {\n                    const sourceArgs = cameraConfig.videoConfig.source.split(/\\s+/);\n                    if (!sourceArgs.includes('-i')) {\n                        this.log.warn('The source for this camera is missing \"-i\", it is likely misconfigured.', cameraConfig.name);\n                    }\n                }\n                if (cameraConfig.videoConfig.stillImageSource) {\n                    const stillArgs = cameraConfig.videoConfig.stillImageSource.split(/\\s+/);\n                    if (!stillArgs.includes('-i')) {\n                        this.log.warn('The stillImageSource for this camera is missing \"-i\", it is likely misconfigured.', cameraConfig.name);\n                    }\n                }\n                if (cameraConfig.videoConfig.vcodec === 'copy' && cameraConfig.videoConfig.videoFilter) {\n                    this.log.warn('A videoFilter is defined, but the copy vcodec is being used. This will be ignored.', cameraConfig.name);\n                }\n            }\n            if (!error) {\n                const uuid = hap.uuid.generate(cameraConfig.name);\n                if (this.cameraConfigs.has(uuid)) {\n                    this.log.warn('Multiple cameras are configured with this name. Duplicate cameras will be skipped.', cameraConfig.name);\n                }\n                else {\n                    this.cameraConfigs.set(uuid, cameraConfig);\n                }\n            }\n        });\n        api.on(\"didFinishLaunching\", this.didFinishLaunching.bind(this));\n    }\n    addMqttAction(topic, message, details) {\n        const messageMap = this.mqttActions.get(topic) || new Map();\n        const actionArray = messageMap.get(message) || [];\n        actionArray.push(details);\n        messageMap.set(message, actionArray);\n        this.mqttActions.set(topic, messageMap);\n    }\n    setupAccessory(accessory, cameraConfig) {\n        accessory.on(\"identify\", () => {\n            this.log.info('Identify requested.', accessory.displayName);\n        });\n        const accInfo = accessory.getService(hap.Service.AccessoryInformation);\n        if (accInfo) {\n            accInfo.setCharacteristic(hap.Characteristic.Manufacturer, cameraConfig.manufacturer || 'Homebridge');\n            accInfo.setCharacteristic(hap.Characteristic.Model, cameraConfig.model || 'Camera FFmpeg');\n            accInfo.setCharacteristic(hap.Characteristic.SerialNumber, cameraConfig.serialNumber || 'SerialNumber');\n            accInfo.setCharacteristic(hap.Characteristic.FirmwareRevision, cameraConfig.firmwareRevision || version);\n        }\n        const motionSensor = accessory.getService(hap.Service.MotionSensor);\n        const doorbell = accessory.getService(hap.Service.Doorbell);\n        const doorbellTrigger = accessory.getServiceById(hap.Service.Switch, 'DoorbellTrigger');\n        const motionTrigger = accessory.getServiceById(hap.Service.Switch, 'MotionTrigger');\n        const doorbellSwitch = accessory.getServiceById(hap.Service.StatelessProgrammableSwitch, 'DoorbellSwitch');\n        if (motionSensor) {\n            accessory.removeService(motionSensor);\n        }\n        if (doorbell) {\n            accessory.removeService(doorbell);\n        }\n        if (doorbellTrigger) {\n            accessory.removeService(doorbellTrigger);\n        }\n        if (motionTrigger) {\n            accessory.removeService(motionTrigger);\n        }\n        if (doorbellSwitch) {\n            accessory.removeService(doorbellSwitch);\n        }\n        if (cameraConfig.doorbell) {\n            const doorbell = new hap.Service.Doorbell(cameraConfig.name + ' Doorbell');\n            accessory.addService(doorbell);\n            if (cameraConfig.switches) {\n                const doorbellTrigger = new hap.Service.Switch(cameraConfig.name + ' Doorbell Trigger', 'DoorbellTrigger');\n                doorbellTrigger\n                    .getCharacteristic(hap.Characteristic.On)\n                    .on(\"set\", (state, callback) => {\n                    this.doorbellHandler(accessory, state);\n                    callback();\n                });\n                accessory.addService(doorbellTrigger);\n            }\n        }\n        if (cameraConfig.motion) {\n            const motionSensor = new hap.Service.MotionSensor(cameraConfig.name);\n            accessory.addService(motionSensor);\n            if (cameraConfig.switches) {\n                const motionTrigger = new hap.Service.Switch(cameraConfig.name + ' Motion Trigger', 'MotionTrigger');\n                motionTrigger\n                    .getCharacteristic(hap.Characteristic.On)\n                    .on(\"set\", (state, callback) => {\n                    this.motionHandler(accessory, state, 1);\n                    callback();\n                });\n                accessory.addService(motionTrigger);\n            }\n        }\n        const delegate = new streamingDelegate_1.StreamingDelegate(this.log, cameraConfig, this.api, hap, this.config.videoProcessor);\n        accessory.configureController(delegate.controller);\n        if (this.config.mqtt) {\n            if (cameraConfig.mqtt) {\n                if (cameraConfig.mqtt.motionTopic) {\n                    this.addMqttAction(cameraConfig.mqtt.motionTopic, cameraConfig.mqtt.motionMessage || cameraConfig.name, { accessory: accessory, active: true, doorbell: false });\n                }\n                if (cameraConfig.mqtt.motionResetTopic) {\n                    this.addMqttAction(cameraConfig.mqtt.motionResetTopic, cameraConfig.mqtt.motionResetMessage || cameraConfig.name, { accessory: accessory, active: false, doorbell: false });\n                }\n                if (cameraConfig.mqtt.doorbellTopic) {\n                    this.addMqttAction(cameraConfig.mqtt.doorbellTopic, cameraConfig.mqtt.doorbellMessage || cameraConfig.name, { accessory: accessory, active: true, doorbell: true });\n                }\n            }\n        }\n    }\n    configureAccessory(accessory) {\n        this.log.info('Configuring cached bridged accessory...', accessory.displayName);\n        const cameraConfig = this.cameraConfigs.get(accessory.UUID);\n        if (cameraConfig) {\n            this.setupAccessory(accessory, cameraConfig);\n        }\n        this.cachedAccessories.push(accessory);\n    }\n    doorbellHandler(accessory, active = true) {\n        var _a;\n        const doorbell = accessory.getService(hap.Service.Doorbell);\n        if (doorbell) {\n            this.log.debug('Switch doorbell ' + (active ? 'on.' : 'off.'), accessory.displayName);\n            const timeout = this.doorbellTimers.get(accessory.UUID);\n            if (timeout) {\n                clearTimeout(timeout);\n                this.doorbellTimers.delete(accessory.UUID);\n            }\n            const doorbellTrigger = accessory.getServiceById(hap.Service.Switch, 'DoorbellTrigger');\n            if (active) {\n                doorbell.updateCharacteristic(hap.Characteristic.ProgrammableSwitchEvent, hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);\n                if (doorbellTrigger) {\n                    doorbellTrigger.updateCharacteristic(hap.Characteristic.On, true);\n                    let timeoutConfig = (_a = this.cameraConfigs.get(accessory.UUID)) === null || _a === void 0 ? void 0 : _a.motionTimeout;\n                    timeoutConfig = timeoutConfig && timeoutConfig > 0 ? timeoutConfig : 1;\n                    const timer = setTimeout(() => {\n                        this.log.debug('Doorbell handler timeout.', accessory.displayName);\n                        this.doorbellTimers.delete(accessory.UUID);\n                        doorbellTrigger.updateCharacteristic(hap.Characteristic.On, false);\n                    }, timeoutConfig * 1000);\n                    this.doorbellTimers.set(accessory.UUID, timer);\n                }\n                return {\n                    error: false,\n                    message: 'Doorbell switched on.'\n                };\n            }\n            else {\n                if (doorbellTrigger) {\n                    doorbellTrigger.updateCharacteristic(hap.Characteristic.On, false);\n                }\n                return {\n                    error: false,\n                    message: 'Doorbell switched off.'\n                };\n            }\n        }\n        else {\n            return {\n                error: true,\n                message: 'Doorbell is not enabled for this camera.'\n            };\n        }\n    }\n    motionHandler(accessory, active = true, minimumTimeout = 0) {\n        var _a;\n        const motionSensor = accessory.getService(hap.Service.MotionSensor);\n        if (motionSensor) {\n            this.log.debug('Switch motion detect ' + (active ? 'on.' : 'off.'), accessory.displayName);\n            const timeout = this.motionTimers.get(accessory.UUID);\n            if (timeout) {\n                clearTimeout(timeout);\n                this.motionTimers.delete(accessory.UUID);\n            }\n            const motionTrigger = accessory.getServiceById(hap.Service.Switch, 'MotionTrigger');\n            const config = this.cameraConfigs.get(accessory.UUID);\n            if (active) {\n                motionSensor.updateCharacteristic(hap.Characteristic.MotionDetected, true);\n                if (motionTrigger) {\n                    motionTrigger.updateCharacteristic(hap.Characteristic.On, true);\n                }\n                if (!timeout && (config === null || config === void 0 ? void 0 : config.motionDoorbell)) {\n                    this.doorbellHandler(accessory, true);\n                }\n                let timeoutConfig = (_a = config === null || config === void 0 ? void 0 : config.motionTimeout) !== null && _a !== void 0 ? _a : 1;\n                if (timeoutConfig < minimumTimeout) {\n                    timeoutConfig = minimumTimeout;\n                }\n                if (timeoutConfig > 0) {\n                    const timer = setTimeout(() => {\n                        this.log.debug('Motion handler timeout.', accessory.displayName);\n                        this.motionTimers.delete(accessory.UUID);\n                        motionSensor.updateCharacteristic(hap.Characteristic.MotionDetected, false);\n                        if (motionTrigger) {\n                            motionTrigger.updateCharacteristic(hap.Characteristic.On, false);\n                        }\n                    }, timeoutConfig * 1000);\n                    this.motionTimers.set(accessory.UUID, timer);\n                }\n                return {\n                    error: false,\n                    message: 'Motion switched on.',\n                    cooldownActive: !!timeout\n                };\n            }\n            else {\n                motionSensor.updateCharacteristic(hap.Characteristic.MotionDetected, false);\n                if (motionTrigger) {\n                    motionTrigger.updateCharacteristic(hap.Characteristic.On, false);\n                }\n                if (config === null || config === void 0 ? void 0 : config.motionDoorbell) {\n                    this.doorbellHandler(accessory, false);\n                }\n                return {\n                    error: false,\n                    message: 'Motion switched off.'\n                };\n            }\n        }\n        else {\n            return {\n                error: true,\n                message: 'Motion is not enabled for this camera.'\n            };\n        }\n    }\n    httpHandler(fullpath, name) {\n        const accessory = this.accessories.find((curAcc) => {\n            return curAcc.displayName == name;\n        });\n        if (accessory) {\n            const path = fullpath.split('/').filter((value) => value.length > 0);\n            switch (path[0]) {\n                case 'motion':\n                    return this.motionHandler(accessory, path[1] != 'reset');\n                    break;\n                case 'doorbell':\n                    return this.doorbellHandler(accessory);\n                    break;\n                default:\n                    return {\n                        error: true,\n                        message: 'First directory level must be \"motion\" or \"doorbell\", got \"' + path[0] + '\".'\n                    };\n            }\n        }\n        else {\n            return {\n                error: true,\n                message: 'Camera \"' + name + '\" not found.'\n            };\n        }\n    }\n    didFinishLaunching() {\n        for (const [uuid, cameraConfig] of this.cameraConfigs) {\n            if (cameraConfig.unbridge) {\n                const accessory = new Accessory(cameraConfig.name, uuid);\n                this.log.info('Configuring unbridged accessory...', accessory.displayName);\n                this.setupAccessory(accessory, cameraConfig);\n                this.api.publishExternalAccessories(PLUGIN_NAME, [accessory]);\n                this.accessories.push(accessory);\n            }\n            else {\n                const cachedAccessory = this.cachedAccessories.find((curAcc) => curAcc.UUID === uuid);\n                if (!cachedAccessory) {\n                    const accessory = new Accessory(cameraConfig.name, uuid);\n                    this.log.info('Configuring bridged accessory...', accessory.displayName);\n                    this.setupAccessory(accessory, cameraConfig);\n                    this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);\n                    this.accessories.push(accessory);\n                }\n                else {\n                    this.accessories.push(cachedAccessory);\n                }\n            }\n        }\n        if (this.config.mqtt) {\n            const portmqtt = this.config.portmqtt || '1883';\n            this.log.info('Setting up MQTT connection...');\n            const client = mqtt_1.default.connect((this.config.tlsmqtt ? 'mqtts://' : 'mqtt://') + this.config.mqtt + ':' + portmqtt, {\n                'username': this.config.usermqtt,\n                'password': this.config.passmqtt\n            });\n            client.on('connect', () => {\n                this.log.info('MQTT connected.');\n                for (const [topic] of this.mqttActions) {\n                    this.log.debug('Subscribing to MQTT topic: ' + topic);\n                    client.subscribe(topic);\n                }\n            });\n            client.on('message', (topic, message) => {\n                const messageMap = this.mqttActions.get(topic);\n                if (messageMap) {\n                    const actionArray = messageMap.get(message.toString());\n                    if (actionArray) {\n                        for (const action of actionArray) {\n                            if (action.doorbell) {\n                                this.doorbellHandler(action.accessory, action.active);\n                            }\n                            else {\n                                this.motionHandler(action.accessory, action.active);\n                            }\n                        }\n                    }\n                }\n            });\n        }\n        if (this.config.porthttp) {\n            this.log.info('Setting up ' + (this.config.localhttp ? 'localhost-only ' : '') +\n                'HTTP server on port ' + this.config.porthttp + '...');\n            const server = http_1.default.createServer();\n            const hostname = this.config.localhttp ? 'localhost' : undefined;\n            server.listen(this.config.porthttp, hostname);\n            server.on('request', (request, response) => {\n                let results = {\n                    error: true,\n                    message: 'Malformed URL.'\n                };\n                if (request.url) {\n                    const spliturl = request.url.split('?');\n                    if (spliturl.length == 2) {\n                        const name = decodeURIComponent(spliturl[1]).split('=')[0];\n                        results = this.httpHandler(spliturl[0], name);\n                    }\n                }\n                response.writeHead(results.error ? 500 : 200);\n                response.write(JSON.stringify(results));\n                response.end();\n            });\n        }\n        this.cachedAccessories.forEach((accessory) => {\n            const cameraConfig = this.cameraConfigs.get(accessory.UUID);\n            if (!cameraConfig || cameraConfig.unbridge) {\n                this.log.info('Removing bridged accessory...', accessory.displayName);\n                this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);\n            }\n        });\n    }\n}\nmodule.exports = (api) => {\n    hap = api.hap;\n    Accessory = api.platformAccessory;\n    api.registerPlatform(PLUGIN_NAME, PLATFORM_NAME, FfmpegPlatform);\n};\n"]}