Commit 84bd5a23 authored by Karan Goel's avatar Karan Goel
Browse files

new files

parents
var static = require('node-static');
var http = require('http');
var url = require('url');
var port = process.env.PORT || 3000;
var file = new static.Server('.');
var app = http.createServer(function (requestToNode, responseToClient) {
// Parse the request url
var parsed = url.parse(requestToNode.url, true);
if (parsed.pathname == '/proxy') {
// We want proxying. The SoundCloud API url is contained in the ?url
// part of the request URL
var scURL = parsed.query.url;
// Parse the SoundCloud URL and compile options for a get request
var parsedSCURL = url.parse(scURL);
var options = {
host: parsedSCURL.host,
port: 80,
path: parsedSCURL.pathname + '?client_id=apigee'
};
// Ask the SoundCloud API server for the media URL
var requestToSC = http.get(options, function(responseFromSC) {
// If it's a 302, then we have the media URL
if (responseFromSC.statusCode = 302) {
// Media URL is in headers.location
var mediaLocation = responseFromSC.headers.location;
// Parse the media URL and compile the options for a (second)
// get request
var parsedMediaURL = url.parse(mediaLocation);
var options = {
host: parsedMediaURL.host,
port: 80,
path: parsedMediaURL.pathname + parsedMediaURL.search
};
// Request the media
var requestForMedia = http.get(options,
function(responseFromMedia) {
// And stream it back to the client
responseFromMedia.pipe(responseToClient);
});
requestForMedia.on('error', function(error) {
// If we can't get to the SC media server then respond
// with a 404
responseToClient.writeHead(404);
responseToClient.end();
});
}
else {
// If the SoundCloud API server doesn't give a 302 then we
// don't have the media, so we'll respond with a 404
responseToClient.writeHead(404);
responseToClient.end();
}
});
requestToSC.on('error', function(error) {
// If we can't get to the SC API server then respond with a 404
responseToClient.writeHead(404);
responseToClient.end();
});
}
else {
// Not a proxy request, so serve the static files
requestToNode.on('end', function () {
file.serve(requestToNode, responseToClient);
});
}
});
app.listen(port);
/*********************************************
This Audio Module demo sets volume, then plays
an audio file out over Headphones/Line out
*********************************************/
var tessel = require('tessel');
var fs = require('fs');
var http = require('http');
var audio = require('audio-vs1053b').use(tessel.port['A']);
var audioFile = 'sample.mp3';
// Wait for the module to connect
audio.on('ready', function() {
console.log("Audio module connected! Setting volume...");
// Set the volume in decibels. Around .8 is good; 80% max volume or -25db
audio.setVolume(.8, function(err) {
if (err) {
return console.log(err);
}
// Get the song
console.log('Retrieving file...');
var url = 'http://localhost:3000/proxy?url=https://soundcloud.com/monstercat/astronaut-champions-laslzo-remix';
var body = '';
http.get(url, function(res) {
res.on('data', function(chunk) {
console.log('Downloading song');
body += chunk;
});
res.on('end', function() {
// all data has been downloaded
console.log('Song has been downloaded');
audio.play(body, function(err) {
if (err) {
console.log(err);
} else {
console.log('Done playing');
}
});
});
});
});
});
// If there is an error, report it
audio.on('error', function(err) {
console.log(err);
});
\ No newline at end of file
{
"name": "audio",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"audio-vs1053b": "^0.1.91"
}
}
var tessel = require('tessel');
var script = require.resolve('./server/server.js');
var opts = {
// Stop existing script, if any
stop: true,
// Serial number (`undefined` picks the first one)
serial: process.env.TESSEL_SERIAL,
};
var args = [];
// `tessel.findTessel` finds a Tessel attached to this computer and connects.
tessel.findTessel(opts, function(err, device) {
console.log('Connected to: ', device);
if (err) throw err;
// Once we've found a Tessel, we tell it to run our script. This works just
// like `tessel run` and bundles the `device/` directory. It bundles only
// `device/` and not the host code because `device/` has its own
// `package.json`.
device.run(script, args, {}, function () {
// Connect the stdout and stderr of the process running on Tessel to
// the console, so that our `console.log` messages show.
device.stdout.resume();
device.stdout.pipe(process.stdout);
device.stderr.resume();
device.stderr.pipe(process.stderr);
//===================================
var http = require('http');
var audio = require('audio-vs1053b').use(tessel.port['A']);
// Wait for the module to connect
audio.on('ready', function() {
console.log("Audio module connected! Setting volume...");
// Set the volume in decibels. Around .8 is good; 80% max volume or -25db
audio.setVolume(.8, function(err) {
if (err) {
return console.log(err);
}
// Get the song
console.log('Retrieving file...');
var url = 'http://localhost:3000/proxy?url=https://soundcloud.com/monstercat/astronaut-champions-laslzo-remix';
var body = '';
http.get(url, function(res) {
res.on('data', function(chunk) {
console.log('Downloading song');
body += chunk;
});
res.on('end', function() {
// all data has been downloaded
console.log('Song has been downloaded');
audio.play(body, function(err) {
if (err) {
console.log(err);
} else {
console.log('Done playing');
}
});
});
});
});
});
// If there is an error, report it
audio.on('error', function(err) {
console.log(err);
});
//===================================
// Exit cleanly on Ctrl+C.
process.on('SIGINT', function() {
// Try to stop the process on the Tessel
device.stop();
setTimeout(function () {
// But if that fails, just exit
logs.info('Script aborted');
process.exit(131);
}, 200);
});
// When the script on Tessel exits, shut down
// USB communications and exit
device.once('script-stop', function (code) {
device.close(function () {
process.exit(code);
});
});
});
});
\ No newline at end of file
{
"name": "audio",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"node-static": "^0.7.6"
}
}
var static = require('node-static');
var http = require('http');
var url = require('url');
var port = process.env.PORT || 3000;
var file = new static.Server('.');
var app = http.createServer(function (requestToNode, responseToClient) {
// Parse the request url
var parsed = url.parse(requestToNode.url, true);
if (parsed.pathname == '/proxy') {
// We want proxying. The SoundCloud API url is contained in the ?url
// part of the request URL
var scURL = parsed.query.url;
// Parse the SoundCloud URL and compile options for a get request
var parsedSCURL = url.parse(scURL);
var options = {
host: parsedSCURL.host,
port: 80,
path: parsedSCURL.pathname + '?client_id=apigee'
};
// Ask the SoundCloud API server for the media URL
var requestToSC = http.get(options, function(responseFromSC) {
// If it's a 302, then we have the media URL
if (responseFromSC.statusCode = 302) {
// Media URL is in headers.location
var mediaLocation = responseFromSC.headers.location;
// Parse the media URL and compile the options for a (second)
// get request
var parsedMediaURL = url.parse(mediaLocation);
var options = {
host: parsedMediaURL.host,
port: 80,
path: parsedMediaURL.pathname + parsedMediaURL.search
};
// Request the media
var requestForMedia = http.get(options,
function(responseFromMedia) {
// And stream it back to the client
responseFromMedia.pipe(responseToClient);
});
requestForMedia.on('error', function(error) {
// If we can't get to the SC media server then respond
// with a 404
responseToClient.writeHead(404);
responseToClient.end();
});
}
else {
// If the SoundCloud API server doesn't give a 302 then we
// don't have the media, so we'll respond with a 404
responseToClient.writeHead(404);
responseToClient.end();
}
});
requestToSC.on('error', function(error) {
// If we can't get to the SC API server then respond with a 404
responseToClient.writeHead(404);
responseToClient.end();
});
}
else {
// Not a proxy request, so serve the static files
requestToNode.on('end', function () {
file.serve(requestToNode, responseToClient);
});
}
});
app.listen(port);
var static = require('node-static');
var http = require('http');
var url = require('url');
var port = process.env.PORT || 3000;
var file = new static.Server('.');
var app = http.createServer(function (requestToNode, responseToClient) {
// Parse the request url
var parsed = url.parse(requestToNode.url, true);
if (parsed.pathname == '/proxy') {
// We want proxying. The SoundCloud API url is contained in the ?url
// part of the request URL
var scURL = parsed.query.url;
// Parse the SoundCloud URL and compile options for a get request
var parsedSCURL = url.parse(scURL);
var options = {
host: parsedSCURL.host,
port: 80,
path: parsedSCURL.pathname + '?client_id=apigee'
};
// Ask the SoundCloud API server for the media URL
var requestToSC = http.get(options, function(responseFromSC) {
// If it's a 302, then we have the media URL
if (responseFromSC.statusCode = 302) {
// Media URL is in headers.location
var mediaLocation = responseFromSC.headers.location;
// Parse the media URL and compile the options for a (second)
// get request
var parsedMediaURL = url.parse(mediaLocation);
var options = {
host: parsedMediaURL.host,
port: 80,
path: parsedMediaURL.pathname + parsedMediaURL.search
};
// Request the media
var requestForMedia = http.get(options,
function(responseFromMedia) {
// And stream it back to the client
responseFromMedia.pipe(responseToClient);
});
requestForMedia.on('error', function(error) {
// If we can't get to the SC media server then respond
// with a 404
responseToClient.writeHead(404);
responseToClient.end();
});
}
else {
// If the SoundCloud API server doesn't give a 302 then we
// don't have the media, so we'll respond with a 404
responseToClient.writeHead(404);
responseToClient.end();
}
});
requestToSC.on('error', function(error) {
// If we can't get to the SC API server then respond with a 404
responseToClient.writeHead(404);
responseToClient.end();
});
}
else {
// Not a proxy request, so serve the static files
requestToNode.on('end', function () {
file.serve(requestToNode, responseToClient);
});
}
});
app.listen(port);
/*********************************************
This Audio Module demo sets volume, then plays
an audio file out over Headphones/Line out
*********************************************/
var tessel = require('tessel');
var fs = require('fs');
var http = require('http');
var audio = require('audio-vs1053b').use(tessel.port['A']);
var audioFile = 'sample.mp3';
// Wait for the module to connect
audio.on('ready', function() {
console.log("Audio module connected! Setting volume...");
// Set the volume in decibels. Around .8 is good; 80% max volume or -25db
audio.setVolume(.8, function(err) {
if (err) {
return console.log(err);
}
// Get the song
console.log('Retrieving file...');
var url = 'http://localhost:3000/proxy?url=https://soundcloud.com/monstercat/astronaut-champions-laslzo-remix';
var body = '';
http.get(url, function(res) {
res.on('data', function(chunk) {
console.log('Downloading song');
body += chunk;
});
res.on('end', function() {
// all data has been downloaded
console.log('Song has been downloaded');
audio.play(body, function(err) {
if (err) {
console.log(err);
} else {
console.log('Done playing');
}
});
});
});
});
});
// If there is an error, report it
audio.on('error', function(err) {
console.log(err);
});
\ No newline at end of file
#!/bin/sh
basedir=`dirname "$0"`
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../node-static/bin/cli.js" "$@"
ret=$?
else
node "$basedir/../node-static/bin/cli.js" "$@"
ret=$?
fi
exit $ret
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\node-static\bin\cli.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\node-static\bin\cli.js" %*
)
\ No newline at end of file
node_modules
*.elf
*.hex
*.lss
*.lst
*.o
*.map
*.sym
*.eep
.dep
The Audio Module project is copyright 2014
Technical Machine, Inc.
Licensed under the Apache License, Version 2.0
<LICENSE-APACHE or
http://www.apache.org/licenses/LICENSE-2.0> or the MIT
license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
at your option. All files in the project carrying such
notice may not be copied, modified, or distributed except
according to those terms.
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.