Permalink
Browse files

expose frozen Buffer

  • Loading branch information...
1 parent 6c5c20c commit 17a59099f8d743b93c0e149017c90c9956bb6b3c @substack committed Sep 4, 2012
Showing with 31 additions and 4 deletions.
  1. +4 −2 package.json
  2. +27 −2 server.js
View
@@ -1,6 +1,6 @@
{
"name" : "baudio-party",
- "version" : "0.0.0",
+ "version" : "0.0.1",
"description" : "javascript music party http server",
"bin" : {
"baudio-party" : "server.js"
@@ -10,7 +10,9 @@
},
"dependencies" : {
"optimist" : "~0.3.4",
- "baudio" : "~0.1.3"
+ "baudio" : "~0.1.3",
+ "clone" : "~0.1.1",
+ "deep-freeze" : "~0.0.1"
},
"repository" : {
"type" : "git",
View
@@ -5,7 +5,7 @@ var argv = require('optimist')
.alias('channels', 'c')
.default('channels', 8)
.alias('rate', 'r')
- .default('rate', 22050)
+ .default('rate', 8000)
.argv
;
var fs = require('fs');
@@ -16,10 +16,34 @@ if (argv.h || argv.help) {
}
var vm = require('vm');
+var deepFreeze = require('deep-freeze');
+var clone = require('clone');
+
+var context = deepFreeze(clone({
+ Buffer : Buffer
+}));
+
var baudio = require('baudio');
var b = baudio({ rate : argv.rate });
+
var channels = [];
+var sources = [];
+function save (src) {
+ try {
+ var fn = vm.runInNewContext(
+ '(function () {' + src + '})()',
+ context
+ );
+ }
+ catch (err) {
+ res.statusCode = 400;
+ res.end(String(err));
+ }
+ channels.push();
+ channels[ch] = fn;
+}
+
for (var i = 0; i < argv.channels; i++) (function (i) {
b.push(function () {
return channels[i].apply(this, arguments);
@@ -51,7 +75,8 @@ var server = http.createServer(function (req, res) {
req.on('end', function () {
try {
var fn = vm.runInNewContext(
- '(function () {' + src + '})()'
+ '(function () {' + src + '})()',
+ context
);
}
catch (err) {

0 comments on commit 17a5909

Please sign in to comment.