-
Notifications
You must be signed in to change notification settings - Fork 28
/
chromecast-play.js
60 lines (42 loc) · 1.6 KB
/
chromecast-play.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
var Client = require('castv2-client').Client;
var DefaultMediaReceiver = require('castv2-client').DefaultMediaReceiver;
function play(host, url, type) {
var client = new Client();
client.connect(host, function() {
console.log('connected, launching app on %s with url %s and type %s', host, url, type);
client.launch(DefaultMediaReceiver, function(err, player) {
var media = {
// Here you can plug an URL to any mp4, webm, mp3 or jpg file with the proper contentType.
contentId: url,
contentType: type,
streamType: 'BUFFERED' // or LIVE
};
player.load(media, { autoplay: true }, function(err, status) {
console.log('media loaded playerState=%s', status.playerState);
client.close();
});
});
});
}
module.exports = function(RED) {
'use strict';
function Node(n) {
RED.nodes.createNode(this,n);
var node = this;
this.on('input', function (msg) {
var creds = RED.nodes.getNode(n.creds),
payload = typeof msg.payload === 'object' ? msg.payload : {};
var attrs = ['ip', 'url', 'contentType'];
for (var attr of attrs) {
if (n[attr]) {
payload[attr] = n[attr];
}
}
if (payload.ip && payload.url && payload.contentType) {
play(payload.ip, payload.url, payload.contentType);
}
node.send(msg);
});
}
RED.nodes.registerType('chromecast-play', Node);
};