Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenkeep committed Mar 23, 2016
0 parents commit c02ca02
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
node_modules/
node_modules/*
Empty file added README.md
Empty file.
66 changes: 66 additions & 0 deletions chromecast-play.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

<script type="text/x-red" data-template-name="chromecast-play">

<div class="form-row">
<label for="node-input-creds"> Credentials</label>
<input type="text" id="node-input-creds">
</div>

<!-- By convention, most nodes have a 'name' property. The following div -->
<!-- provides the necessary field. Should always be the last option -->
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name of this Event">
</div>

<div class="form-row">
<label for="node-input-url">Media Url</label>
<input type="text" id="node-input-url" placeholder="Media Url">
</div>

<div class="form-row">
<label for="node-input-contentType">Media Type</label>
<input type="text" id="node-input-contentType" placeholder="audio/mp3">
</div>

<div class="form-row">
<label for="node-input-ip">IP</label>
<input type="text" id="node-input-ip" placeholder="0.0.0.0">
</div>

</script>


<!-- Next, some simple help text is provided for the node. -->
<script type="text/x-red" data-help-name="chromecast-play">

<h3>About</h3>
<p>Plays a Media file on a chromecast</p>

<h3>Use</h3>
<p>To use pass in the IP address of the chromecast <code>payload.ip_address</code> and a url to a media file <code>payload.url</code>.
</p>
</script>

<!-- Finally, the node type is registered along with all of its properties -->
<!-- The example below shows a small subset of the properties that can be set-->
<script type="text/javascript">
RED.nodes.registerType('chromecast-play', {
category: 'chromecast',
defaults: {
name: {value:""},
url: {value:""},
contentType: {value:""},
ip: {value:""},
},
inputs:1, // set the number of inputs - only 0 or 1
outputs:1, // set the number of outputs - 0 to n
icon: "bridge.png", // saved in icons/myicon.png
color: "#FFFF00",
label: function() {
return this.name || "Play";
},
paletteLabel: "Play"

});
</script>
60 changes: 60 additions & 0 deletions chromecast-play.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
};
35 changes: 35 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "node-red-contrib-chromecast",
"version": "0.0.0",
"description": "NodeRED nodes to for Chromecast",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"predev": "npm i -g",
"dev": "node-red -v"
},
"author": "Stephen Keep",
"contributors": [
{
"name": "Stephen Keep",
"email": "[email protected]"
}
],
"keywords": [
"contrib-chromecast",
"chromecast"
],
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/stephenkeep/node-red-contrib-chromecast"
},
"dependencies": {
"castv2-client": "^1.1.1"
},
"node-red": {
"nodes": {
"chromecast-play": "chromecast-play.js"
}
}
}

0 comments on commit c02ca02

Please sign in to comment.