Permalink
Browse files

Initial commit, v 0.0.1

  • Loading branch information...
0 parents commit 1369a721c62650b6da55f2cf9984db436cbcfec4 @kesla committed Mar 6, 2012
Showing with 95 additions and 0 deletions.
  1. +40 −0 README
  2. +38 −0 index.js
  3. +17 −0 package.json
@@ -0,0 +1,40 @@
+node-xvfb
+=========
+
+node-xvfb makes it easy to start and use Xvfb in node.
+
+example
+=======
+
+.startXvfb
+----------
+
+.startXvfb is inspired by xvfb-run - it searches for a free X display number and starts Xvfb on that.
+
+````javascript
+var xvfb = require('xvfb');
+
+xvfb.startXvfb(function(err, childProcess, servernum) {
+ // childProcess is a ChildProcess, as returned from child_process.spawn()
+ console.log('Xvfb running on server number', servernum);
+ console.log('Xvfb pid', childProcess.pid);
+ console.log('err should be null', err);
+});````
+
+.startXvfb also support an optional number to start searching from.
+
+````javascript
+var xvfb = require('xvfb');
+
+xvfb.startXvfb(200, function(err, childProcess, servernum) {
+ // servernum will be at least 200
+ console.log('Xvfb running on server number', servernum);
+ console.log('Xvfb pid', childProcess.pid);
+});````
+
+install
+=======
+
+With [npm](http://npmjs.org), do:
+
+ npm install xvfb
@@ -0,0 +1,38 @@
+var path = require('path');
+var spawn = require('child_process').spawn;
+var headless = exports;
+
+function findFreeServernum(servernum, callback) {
+ path.exists('/tmp/.X' + servernum + '-lock', function(exists) {
+ if(exists) {
+ servernum++;
+ findFreeServernum(servernum, callback);
+ return;
+ }
+ callback(servernum);
+ });
+}
+
+headless.startXvfb = function (startnum, callback) {
+ if (!callback) {
+ callback = startnum;
+ startnum = 99;
+ }
+
+ findFreeServernum(startnum, function(servernum) {
+ var childProcess = spawn('Xvfb', [':' + servernum]);
+ // assume starting Xvfb takes less than 500 ms and continue if it hasn't
+ // exited during that time
+ var timeout = setTimeout(function() {
+ callback(null, childProcess, servernum);
+ }, 500);
+
+ // if Xvfb exits prematurely the servernum wasn't valid.
+ // Happens if there's already an X-server running on @servernum but no file was created in /tmp
+ childProcess.on('exit', function() {
+ clearTimeout(timeout);
+ servernum++;
+ headless.startXvfb(servernum, callback);
+ });
+ });
+}
@@ -0,0 +1,17 @@
+{
+ "author": "David Björklund <david@admaze.ly>",
+ "name": "headless",
+ "description": "Headless is a Node.js wrapper for Xvfb, the virtual framebuffer",
+ "version": "0.0.1",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/kesla/node-headless.git"
+ },
+ "main": "index.js",
+ "engines": {
+ "node": "~0.6.11"
@substack
substack Jun 26, 2012 Contributor

This is overly restrictive. Node versions are a different category of dependency from dependencies since multiple node versions can't be used in the same program to resolve version conflicts in the same way that dependencies can. Consider >=0.6 or even >=0.4 since I don't see anything in the code that wouldn't work with older versions of node here.

+ },
+ "dependencies": {},
+ "devDependencies": {},
+ "optionalDependencies": {}
+}

0 comments on commit 1369a72

Please sign in to comment.