-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathindex.js
56 lines (40 loc) · 1.06 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
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var rest = require('rest');
var mime = require('rest/interceptor/mime');
var dial = require('dial');
function connectionUrl(appInfo){
var self = this;
var client = rest.chain(mime, { mime: 'application/json' });
var url = appInfo.service.servicedata.connectionSvcURL;
if(!url){
return this.appInfo().then(function(appInfo){
return self.connectionUrl(appInfo);
});
}
return client({
path: url,
entity: {
channel: 0
}
});
}
function Chromecast(){
if(!(this instanceof Chromecast)) return new Chromecast();
var self = this;
EventEmitter.call(self);
dial.on('device', function(device){
if(device.model !== 'Eureka Dongle'){
// Not a Chromecast
return;
}
// Add connectionUrl method to a device
device.connectionUrl = connectionUrl;
self.emit('device', device);
});
}
util.inherits(Chromecast, EventEmitter);
Chromecast.prototype.discover = function(){
dial.discover();
};
module.exports = Chromecast;