forked from homebridge-plugins/homebridge-camera-ffmpeg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·61 lines (46 loc) · 1.67 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var Accessory, hap, UUIDGen;
var FFMPEG = require('./ffmpeg').FFMPEG;
module.exports = function(homebridge) {
Accessory = homebridge.platformAccessory;
hap = homebridge.hap;
UUIDGen = homebridge.hap.uuid;
homebridge.registerPlatform("homebridge-camera-ffmpeg", "Camera-ffmpeg", ffmpegPlatform, true);
}
function ffmpegPlatform(log, config, api) {
var self = this;
self.log = log;
self.config = config || {};
if (api) {
self.api = api;
if (api.version < 2.1) {
throw new Error("Unexpected API version.");
}
self.api.on('didFinishLaunching', self.didFinishLaunching.bind(this));
}
}
ffmpegPlatform.prototype.configureAccessory = function(accessory) {
// Won't be invoked
}
ffmpegPlatform.prototype.didFinishLaunching = function() {
var self = this;
var videoProcessor = self.config.videoProcessor || 'ffmpeg';
var interfaceName = self.config.interfaceName || '';
if (self.config.cameras) {
var configuredAccessories = [];
var cameras = self.config.cameras;
cameras.forEach(function(cameraConfig) {
var cameraName = cameraConfig.name;
var videoConfig = cameraConfig.videoConfig;
if (!cameraName || !videoConfig) {
self.log("Missing parameters.");
return;
}
var uuid = UUIDGen.generate(cameraName);
var cameraAccessory = new Accessory(cameraName, uuid, hap.Accessory.Categories.CAMERA);
var cameraSource = new FFMPEG(hap, cameraConfig, self.log, videoProcessor, interfaceName);
cameraAccessory.configureCameraSource(cameraSource);
configuredAccessories.push(cameraAccessory);
});
self.api.publishCameraAccessories("Camera-ffmpeg", configuredAccessories);
}
}