-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (48 loc) · 1.86 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
62
63
64
65
var Device = require('./lib/device')
, util = require('util')
, stream = require('stream')
, configHandlers = require('./lib/config-handlers');
util.inherits(driver,stream);
var HELLO_WORLD_ANNOUNCEMENT = {
"contents": [
{ "type": "heading", "text": "Autoremote Driver Loaded" },
{ "type": "paragraph", "text": "The Autoremote driver has been loaded. Further configuration is required. ('Drivers', 'Configure')" }
]
};
function driver(opts,app) {
var self = this;
this._app = app;
this._opts = opts;
app.on('client::up',function(){
if (!opts.hasSentAnnouncement) {
self.emit('announcement',HELLO_WORLD_ANNOUNCEMENT);
opts.hasSentAnnouncement = true;
self.save();
}
if (!opts.urls) {opts.urls = [];};
if (!AR_keys) {var AR_keys = [];};
self._opts.urls.forEach(function(url,index) {
self.createCameraByUrl(url,index);
});
});
};
driver.prototype.config = function(rpc,cb) {
var self = this;
if (!rpc) {
return configHandlers.probe.call(this,cb);
}
switch (rpc.method) {
case 'back': return configHandlers.probe.call(this,cb); break;
case 'manual_set_url': return configHandlers.manual_set_url.call(this,rpc.params,cb); break;
case 'manual_get_url': return configHandlers.manual_get_url.call(this,rpc.params,cb); break;
case 'manual_show_remove': return configHandlers.manual_show_remove.call(this,rpc.params,cb); break;
case 'manual_remove_url': return configHandlers.manual_remove_url.call(this,rpc.params,cb); break;
default: return cb(true); break;
}
};
driver.prototype.createCameraByUrl = function(snapshot_url,index) {
var opts = snapshot_url;
var Camera = new Device(opts,this._app.opts,this._app.id,this._app.token,index);
this.emit('register', Camera);
};
module.exports = driver;