├── screenshots └── .gitkeep ├── test ├── memleaks │ └── config.json ├── fixtures │ ├── pingPongModule.js │ ├── browserComments.js │ └── HelloWorld.js ├── spawn │ ├── basic-spawn-optional.js │ └── bad-spawn-test.js ├── messaging │ ├── local │ │ ├── emit-test.js │ │ └── callback-test.js │ └── remote │ │ ├── emit-child-test.js │ │ ├── emit-parent-test.js │ │ ├── callback-child-test.js │ │ ├── callback-parent-test.js │ │ ├── callback-parent-hookname-test.js │ │ └── callback-child-hookname-test.js ├── siblings │ ├── ping-pong-test.js │ ├── message-test.js │ └── multiple-messages-test.js ├── registry │ ├── simple-test.js │ ├── complex-test.js │ └── disconnection-test.js ├── discovery │ └── basic-init-test.js └── logging │ ├── transports-test.js │ └── exception-handlers-test.js ├── lib ├── hookio │ ├── scaffold │ │ ├── config.json │ │ ├── ReadMe.md │ │ ├── bin │ │ │ ├── generate │ │ │ └── scaffold │ │ ├── lib │ │ │ └── scaffold.js │ │ ├── package.json │ │ └── LICENSE │ ├── discovery.js │ ├── commands │ │ ├── list.js │ │ ├── search.js │ │ └── init.js │ ├── transports │ │ └── couchdb.js │ ├── cli.js │ ├── eventMap.js │ ├── npm-api.js │ ├── scaffold.js │ ├── config.js │ └── query.js └── hookio.js ├── vendor ├── dnode-protocol │ ├── .npmignore │ ├── node_modules │ │ ├── traverse │ │ │ ├── .npmignore │ │ │ ├── examples │ │ │ │ ├── negative.js │ │ │ │ ├── scrub.js │ │ │ │ ├── leaves.js │ │ │ │ ├── json.js │ │ │ │ └── stringify.js │ │ │ ├── main.js │ │ │ ├── test │ │ │ │ ├── obj.js │ │ │ │ ├── instance.js │ │ │ │ ├── leaves.js │ │ │ │ ├── negative.js │ │ │ │ ├── keys.js │ │ │ │ ├── date.js │ │ │ │ ├── subexpr.js │ │ │ │ ├── stop.js │ │ │ │ ├── super_deep.js │ │ │ │ ├── stringify.js │ │ │ │ ├── interface.js │ │ │ │ ├── siblings.js │ │ │ │ ├── json.js │ │ │ │ ├── lib │ │ │ │ │ └── deep_equal.js │ │ │ │ └── circular.js │ │ │ ├── package.json │ │ │ └── LICENSE │ │ └── jsonify │ │ │ ├── index.js │ │ │ ├── test │ │ │ ├── stringify.js │ │ │ └── parse.js │ │ │ ├── package.json │ │ │ └── README.markdown │ ├── package.json │ └── test │ │ ├── store.js │ │ ├── args.js │ │ ├── proto.js │ │ ├── fn.js │ │ └── scrub.js ├── dnode │ ├── .npmignore │ ├── examples │ │ ├── chat │ │ │ ├── INSTALL.txt │ │ │ ├── package.json │ │ │ ├── index.html │ │ │ ├── chat.css │ │ │ ├── server.js │ │ │ └── entry.js │ │ ├── simple │ │ │ ├── server.js │ │ │ └── client.js │ │ ├── web-connect │ │ │ ├── server.js │ │ │ └── index.html │ │ ├── web-express │ │ │ ├── server.js │ │ │ └── index.html │ │ ├── perf │ │ │ ├── client.js │ │ │ └── emitter.js │ │ ├── bidirectional │ │ │ ├── server.js │ │ │ └── client.js │ │ ├── web-http │ │ │ ├── index.html │ │ │ └── server.js │ │ ├── web-browserify │ │ │ ├── server.js │ │ │ └── index.html │ │ ├── https │ │ │ ├── index.html │ │ │ └── server.js │ │ ├── auth │ │ │ ├── quotes.json │ │ │ ├── client.js │ │ │ └── server.js │ │ ├── saturate │ │ │ ├── saturate.js │ │ │ └── index.html │ │ └── nested.js │ ├── LICENSE │ ├── test │ │ ├── _id.js │ │ ├── keys │ │ │ ├── agent2-key.pem │ │ │ ├── agent1-key.pem │ │ │ ├── agent1-csr.pem │ │ │ ├── agent2-csr.pem │ │ │ ├── agent2-cert.pem │ │ │ └── agent1-cert.pem │ │ ├── refs.js │ │ ├── unix.js │ │ ├── unicode.js │ │ ├── stream.js │ │ ├── single.js │ │ ├── circular.js │ │ ├── self-referential.js │ │ ├── obj.js │ │ ├── double.js │ │ ├── recon.js │ │ ├── simple.js │ │ ├── bidirectional.js │ │ ├── null.js │ │ ├── middleware.js │ │ ├── gc.js │ │ ├── nested.js │ │ ├── emit.js │ │ ├── broadcast.js │ │ ├── bundle.js │ │ └── error.js │ ├── bin │ │ └── bundle.js │ ├── package.json │ ├── browser │ │ └── index.js │ └── lib │ │ └── stream_socketio.js └── EventEmitter2 │ ├── index.js │ ├── package.json │ └── test │ ├── perf │ └── benchmark.js │ ├── wildcardEvents │ ├── k1.js │ └── options.js │ └── simple │ └── ttl.js ├── .gitignore ├── .travis.yml ├── bin ├── hookio └── forever-shim ├── config.json ├── examples ├── constructors │ ├── bad-options-conflict.js │ ├── child-hooks │ │ ├── hook-single-child.js │ │ ├── hook-many-child-spawn.js │ │ └── hook-custom-child-spawn.js │ ├── hook-redis-config.js │ └── eventMap │ │ └── event-map-hook.js ├── pummel │ ├── listener.js │ ├── master.js │ └── emitter.js ├── spawn │ ├── missing-hook-spawn.js │ ├── single-hook-spawn.js │ ├── many-hook-spawn.js │ ├── simple-hook-spawn.js │ ├── type-hook-spawn.js │ └── custom-hook-spawn.js ├── authentication │ ├── auth-server-noauth-client.js │ └── basic-connection-auth.js ├── discovery │ ├── local-auto-discover.js │ └── find-free-ports.js ├── npm │ ├── local-npm-install.js │ └── remote-npm-install.js ├── messaging │ ├── local │ │ ├── hook-emit.js │ │ └── hook-callback.js │ ├── remote │ │ ├── hook-emit-child-onany.js │ │ ├── hook-emit-parent-onany.js │ │ ├── hook-emit-sender-info.js │ │ ├── hook-emit-child.js │ │ ├── hook-callback-parent.js │ │ ├── hook-emit-parent.js │ │ ├── hook-callback-child.js │ │ ├── hook-callback-parent-hookname.js │ │ └── hook-callback-child-hookname.js │ └── siblings │ │ ├── hook-multiple-messages.js │ │ └── hook-emit-sibling-onany.js ├── disconnect │ ├── hook-server.js │ └── hook-client.js ├── kill │ ├── simple-hook-kill.js │ └── spawn-hook-kill.js ├── stop │ ├── simple-start-stop-start.js │ └── simple-spawn-stop-start.js ├── transports │ └── couchdb-event-transport.js └── query │ └── hook-query.js └── package.json /screenshots/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/memleaks/config.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /lib/hookio/scaffold/config.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /vendor/dnode-protocol/.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /lib/hookio/scaffold/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Unreleased, please come back later. -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /vendor/dnode/.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .git/* 3 | *.swp 4 | *.swo 5 | -------------------------------------------------------------------------------- /vendor/EventEmitter2/index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./lib/eventemitter2'); 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | *.swp 3 | tags 4 | node_modules/ 5 | node_modules/* 6 | npm-debug.log 7 | test/config.json -------------------------------------------------------------------------------- /vendor/dnode/examples/chat/INSTALL.txt: -------------------------------------------------------------------------------- 1 | Do this first: 2 | 3 | mkdir node_modules 4 | npm install jquery-browserify 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 0.6 4 | - 0.7 5 | 6 | notifications: 7 | email: 8 | - travis@nodejitsu.com 9 | -------------------------------------------------------------------------------- /test/fixtures/pingPongModule.js: -------------------------------------------------------------------------------- 1 | var pingPong = exports; 2 | 3 | pingPong.ping = function (msg) { 4 | console.log(msg); 5 | return msg; 6 | }; -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/jsonify/index.js: -------------------------------------------------------------------------------- 1 | exports.parse = require('./lib/parse'); 2 | exports.stringify = require('./lib/stringify'); 3 | -------------------------------------------------------------------------------- /bin/hookio: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var Hook = require('../lib/hookio').Hook; 4 | 5 | var hook = new Hook( { 6 | name: 'the-hook' 7 | }); 8 | 9 | hook.start(); -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "test": { 3 | "foo": "hello config" 4 | }, 5 | 6 | "logger" : { 7 | "transports" : { 8 | "console" : {} 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /vendor/dnode/examples/simple/server.js: -------------------------------------------------------------------------------- 1 | var dnode = require('dnode'); 2 | 3 | var server = dnode({ 4 | zing : function (n, cb) { cb(n * 100) } 5 | }); 6 | server.listen(7070); 7 | -------------------------------------------------------------------------------- /vendor/dnode/examples/chat/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies" : { 3 | "jquery-browserify" : "*", 4 | "browserify" : "1.0.x", 5 | "express" : "0.7.x" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /vendor/dnode/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2010 James Halliday (mail@substack.net) 2 | 3 | This project is free software released under the MIT license: 4 | http://www.opensource.org/licenses/mit-license.php 5 | -------------------------------------------------------------------------------- /lib/hookio/scaffold/bin/generate: -------------------------------------------------------------------------------- 1 | var introspect = require('../lib/introspect'); 2 | 3 | // 4 | // Remark: This will generate a new hook called "testh" in the /generate/ folder 5 | // 6 | introspect.generate('testh'); -------------------------------------------------------------------------------- /lib/hookio/scaffold/bin/scaffold: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var Scaffold = require('../lib/scaffold').Scaffold; 4 | 5 | var scaffold = new Scaffold({ 6 | name: 'the-scaffold' 7 | }); 8 | 9 | scaffold.start(); -------------------------------------------------------------------------------- /vendor/dnode/examples/simple/client.js: -------------------------------------------------------------------------------- 1 | var dnode = require('dnode'); 2 | 3 | dnode.connect(7070, function (remote, conn) { 4 | remote.zing(33, function (n) { 5 | console.log('n = ' + n); 6 | conn.end(); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /examples/constructors/bad-options-conflict.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var Hook = require('../../lib/hookio').Hook; 4 | 5 | var hook = new Hook( { 6 | name: 'the-hook', 7 | debug: true, 8 | emit: false 9 | }); 10 | 11 | 12 | hook.start(); 13 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/examples/negative.js: -------------------------------------------------------------------------------- 1 | var traverse = require('traverse'); 2 | var obj = [ 5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ]; 3 | 4 | traverse(obj).forEach(function (x) { 5 | if (x < 0) this.update(x + 128); 6 | }); 7 | 8 | console.dir(obj); 9 | -------------------------------------------------------------------------------- /examples/constructors/child-hooks/hook-single-child.js: -------------------------------------------------------------------------------- 1 | 2 | var Hook = require('../../../lib/hookio').Hook; 3 | 4 | var hook = new Hook({ 5 | name: "hook", 6 | hooks: ["helloworld"] 7 | }); 8 | 9 | hook.on('hook::ready', function () { 10 | console.log('hook ready'); 11 | }); 12 | 13 | hook.start(); 14 | -------------------------------------------------------------------------------- /lib/hookio/discovery.js: -------------------------------------------------------------------------------- 1 | var hookio = require('./hook'), 2 | async = require('async'), 3 | path = require('path'), 4 | portfinder = require('portfinder'), 5 | discovery = exports; 6 | 7 | discovery.ports = {}; 8 | 9 | discovery.ports.find = portfinder.getPort; 10 | 11 | 12 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/main.js: -------------------------------------------------------------------------------- 1 | // scrub out circular references 2 | var traverse = require('./index.js'); 3 | 4 | var obj = { a : 1, b : 2, c : [ 3, 4 ] }; 5 | obj.c.push(obj); 6 | 7 | var scrubbed = traverse(obj).map(function (x) { 8 | if (this.circular) this.remove() 9 | }); 10 | console.dir(scrubbed); 11 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/examples/scrub.js: -------------------------------------------------------------------------------- 1 | // scrub out circular references 2 | var traverse = require('traverse'); 3 | 4 | var obj = { a : 1, b : 2, c : [ 3, 4 ] }; 5 | obj.c.push(obj); 6 | 7 | var scrubbed = traverse(obj).map(function (x) { 8 | if (this.circular) this.remove() 9 | }); 10 | console.dir(scrubbed); 11 | -------------------------------------------------------------------------------- /examples/constructors/child-hooks/hook-many-child-spawn.js: -------------------------------------------------------------------------------- 1 | 2 | var Hook = require('../../../lib/hookio').Hook; 3 | 4 | var hook = new Hook({ 5 | name: "hook", 6 | hooks: ["helloworld", "helloworld", "helloworld", "helloworld"] 7 | }); 8 | 9 | hook.on('hook::ready', function () { 10 | console.log('hook ready'); 11 | }); 12 | 13 | hook.start(); 14 | -------------------------------------------------------------------------------- /examples/pummel/listener.js: -------------------------------------------------------------------------------- 1 | var Hook = require('../../lib/hookio').Hook; 2 | var util = require('util'); 3 | 4 | var Slave = exports.Slave = function (options) { 5 | self = this; 6 | Hook.call(this, options); 7 | this.on('hook::ready', function () { 8 | this.on('*::someEvent', function (msg) { 9 | }) 10 | }); 11 | } 12 | 13 | util.inherits(Slave, Hook); -------------------------------------------------------------------------------- /examples/spawn/missing-hook-spawn.js: -------------------------------------------------------------------------------- 1 | var hookio = require('../../lib/hookio'); 2 | 3 | var master = hookio.createHook({ 4 | "name": "master-hook", 5 | "hooks": [ 6 | { "type" : "request" }, 7 | { "type" : "none-exist" }, 8 | 9 | ] 10 | }); 11 | 12 | master.on('spawn::error', function(err){ 13 | console.log(err) 14 | }); 15 | 16 | master.listen(); 17 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/examples/leaves.js: -------------------------------------------------------------------------------- 1 | var traverse = require('traverse'); 2 | 3 | var obj = { 4 | a : [1,2,3], 5 | b : 4, 6 | c : [5,6], 7 | d : { e : [7,8], f : 9 }, 8 | }; 9 | 10 | var leaves = traverse(obj).reduce(function (acc, x) { 11 | if (this.isLeaf) acc.push(x); 12 | return acc; 13 | }, []); 14 | 15 | console.dir(leaves); 16 | -------------------------------------------------------------------------------- /vendor/dnode/examples/web-connect/server.js: -------------------------------------------------------------------------------- 1 | var connect = require('connect'); 2 | var dnode = require('dnode'); 3 | 4 | var server = connect.createServer(); 5 | server.use(connect.static(__dirname)); 6 | 7 | dnode(function (client) { 8 | this.cat = function (cb) { 9 | cb('meow '); 10 | }; 11 | }).listen(server); 12 | 13 | server.listen(6857); 14 | console.log('http://localhost:6857/'); 15 | -------------------------------------------------------------------------------- /vendor/dnode/examples/web-express/server.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var server = express.createServer(); 3 | var dnode = require('dnode'); 4 | 5 | server.use(express.static(__dirname)); 6 | 7 | dnode(function (client) { 8 | this.cat = function (cb) { 9 | cb('meow'); 10 | }; 11 | }).listen(server); 12 | 13 | server.listen(6857); 14 | console.log('http://localhost:6857/'); 15 | -------------------------------------------------------------------------------- /vendor/dnode/examples/perf/client.js: -------------------------------------------------------------------------------- 1 | var frames = 0, last = 0; 2 | setInterval(function () { 3 | if (last) { 4 | var fps = frames / (Date.now() - last) * 1000; 5 | console.log('fps: ' + fps); 6 | } 7 | 8 | last = Date.now(); 9 | frames = 0; 10 | }, 1000); 11 | 12 | var dnode = require('dnode'); 13 | dnode({ 14 | emit : function (i) { frames ++ } 15 | }).connect(7575); 16 | -------------------------------------------------------------------------------- /test/fixtures/browserComments.js: -------------------------------------------------------------------------------- 1 | /* 2 | hook.io - http://hook.io 3 | (C) 2011 Nodejitsu Inc. 4 | MIT LICENCE 5 | THIS FILE WAS AUTOGENERATED ON {{newDate}} 6 | BUILD ID: {{newDateUnix}} 7 | 8 | WARNING: THIS FILE WAS AUTOGENERATED BY THE HOOKIO BROWSERIFY SCRIPT 9 | MODIFYING THIS FILE IS FINE, BUT YOU REALLY SHOULD BE MODIFYING 10 | THE LIBRARY DIRECTLY AND REGENERATING IT USING "bin/browserify" 11 | 12 | */ -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/jsonify/test/stringify.js: -------------------------------------------------------------------------------- 1 | var test = require('tap').test; 2 | var json = require('../'); 3 | var garbage = require('garbage'); 4 | 5 | test('stringify', function (t) { 6 | for (var i = 0; i < 50; i++) { 7 | var obj = garbage(50); 8 | t.equal( 9 | json.stringify(obj), 10 | JSON.stringify(obj) 11 | ); 12 | } 13 | 14 | t.end(); 15 | }); 16 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/jsonify/test/parse.js: -------------------------------------------------------------------------------- 1 | var test = require('tap').test; 2 | var json = require('../'); 3 | var garbage = require('garbage'); 4 | 5 | test('parse', function (t) { 6 | for (var i = 0; i < 50; i++) { 7 | var s = JSON.stringify(garbage(50)); 8 | 9 | t.deepEqual( 10 | json.parse(s), 11 | JSON.parse(s) 12 | ); 13 | } 14 | 15 | t.end(); 16 | }); 17 | -------------------------------------------------------------------------------- /lib/hookio.js: -------------------------------------------------------------------------------- 1 | /* 2 | * hookio.js: Top-level include for the hookio module. 3 | * 4 | * (C) 2011 Nodejitsu Inc. 5 | * MIT LICENCE 6 | * 7 | */ 8 | 9 | var hookio = exports; 10 | 11 | // 12 | // Export the core `hookio` components. 13 | // 14 | hookio.cli = require('./hookio/cli'); 15 | hookio.Hook = require('./hookio/hook').Hook; 16 | 17 | hookio.createHook = function (options) { 18 | var hook = new hookio.Hook(options); 19 | return hook; 20 | }; -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/test/obj.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var Traverse = require('../'); 3 | 4 | exports['traverse an object with nested functions'] = function () { 5 | var to = setTimeout(function () { 6 | assert.fail('never ran'); 7 | }, 1000); 8 | 9 | function Cons (x) { 10 | clearTimeout(to); 11 | assert.equal(x, 10); 12 | }; 13 | Traverse(new Cons(10)); 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /vendor/dnode/examples/bidirectional/server.js: -------------------------------------------------------------------------------- 1 | var dnode = require('dnode'); 2 | 3 | dnode(function (client) { 4 | // Poll the client's own temperature() in celsius and convert that value to 5 | // fahrenheit in the supplied callback 6 | this.clientTempF = function (cb) { 7 | client.temperature(function (degC) { 8 | var degF = Math.round(degC * 9 / 5 + 32); 9 | cb(degF); 10 | }); 11 | }; 12 | }).listen(6060); 13 | -------------------------------------------------------------------------------- /examples/authentication/auth-server-noauth-client.js: -------------------------------------------------------------------------------- 1 | var hookio = require('../../lib/hookio'); 2 | 3 | hookio.createHook({ 4 | authorize: customAuth 5 | }).listen(); 6 | 7 | 8 | hookio.createHook().connect(); 9 | 10 | 11 | function customAuth(user, password, cb) { 12 | console.log('running custom auth') 13 | if (user == 'marak' && pass == 'test') { 14 | console.log(user, ' succeeded!'); 15 | } 16 | else { 17 | console.log(user, ' failed!'); 18 | cb(null); 19 | } 20 | } -------------------------------------------------------------------------------- /vendor/dnode/examples/web-http/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | The cat says ?. 16 | 17 | 18 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/examples/json.js: -------------------------------------------------------------------------------- 1 | var traverse = require('traverse'); 2 | 3 | var id = 54; 4 | var callbacks = {}; 5 | var obj = { moo : function () {}, foo : [2,3,4, function () {}] }; 6 | 7 | var scrubbed = traverse(obj).map(function (x) { 8 | if (typeof x === 'function') { 9 | callbacks[id] = { id : id, f : x, path : this.path }; 10 | this.update('[Function]'); 11 | id++; 12 | } 13 | }); 14 | 15 | console.dir(scrubbed); 16 | console.dir(callbacks); 17 | -------------------------------------------------------------------------------- /vendor/dnode/examples/web-connect/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | The cat says ?. 16 | 17 | 18 | -------------------------------------------------------------------------------- /vendor/dnode/examples/web-express/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | The cat says ?. 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/discovery/local-auto-discover.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | 5 | var Hook = require('../../lib/hookio').Hook; 6 | 7 | 8 | var hook1 = new Hook({ 9 | name: "server-hook", 10 | debug: true 11 | }); 12 | 13 | var hook2 = new Hook({ 14 | name: "callback-hook", 15 | debug: true 16 | }); 17 | 18 | 19 | hook1.on('hook::ready', function () { 20 | console.log('hook1 is ready'); 21 | hook2.on('hook::ready', function () { 22 | console.log('hook2 is ready'); 23 | }); 24 | hook2.start(); 25 | }); 26 | 27 | hook1.start(); -------------------------------------------------------------------------------- /examples/discovery/find-free-ports.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | 5 | var Hook = require('../../lib/hookio').Hook; 6 | 7 | 8 | var hook = new Hook({ 9 | name: "server-hook", 10 | debug: true 11 | }); 12 | 13 | 14 | // Default options 15 | hook.findPort(function(err, result){ 16 | console.log(err, result); 17 | }) 18 | 19 | // Specific port start 20 | hook.findPort({ port: 9000 },function(err, result){ 21 | console.log(err, result); 22 | }) 23 | 24 | // Specific range 25 | // TODO: Patcy node-portfinder to support max ranges of ports 26 | -------------------------------------------------------------------------------- /examples/npm/local-npm-install.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Creates a hook, then installs the `helloworld` hook from npm 3 | */ 4 | 5 | var Hook = require('../../lib/hookio').Hook; 6 | 7 | var myHello = new Hook({ name: "the-hook", debug: true }); 8 | 9 | myHello.on('hook::ready', function () { 10 | myHello.npm.install('hook.io-helloworld', function (err, result) { 11 | if (err) { 12 | return myHello.emit('npm::install::error', err); 13 | } 14 | myHello.emit('npm::installed', result); 15 | }); 16 | }); 17 | 18 | myHello.start(); 19 | -------------------------------------------------------------------------------- /vendor/dnode/test/_id.js: -------------------------------------------------------------------------------- 1 | var dnode = require('../'); 2 | var test = require('tap').test; 3 | 4 | test('_id', function (t) { 5 | t.plan(1); 6 | var port = Math.floor(Math.random() * 40000 + 10000); 7 | 8 | var server = dnode({ _id : 1337 }).listen(port); 9 | 10 | server.on('ready', function () { 11 | dnode.connect(port, function (remote, conn) { 12 | t.equal(remote._id, 1337); 13 | conn.end(); 14 | server.close(); 15 | t.end(); 16 | }); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /examples/spawn/single-hook-spawn.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Creates a helloworld hook, then spawns up a single helloworld child 3 | */ 4 | 5 | var Helloworld = require('hook.io-helloworld').Helloworld; 6 | 7 | var myHello = new Helloworld({ name: "helloworld" }); 8 | 9 | myHello.on('hook::ready', function () { 10 | 11 | // 12 | // This will spawn up one "helloworld" hook with auto-configuration 13 | // see: custom-hook-spawn.js for customized spawn settings 14 | // 15 | // 16 | myHello.spawn('helloworld'); 17 | 18 | }); 19 | 20 | myHello.start(); -------------------------------------------------------------------------------- /vendor/dnode/test/keys/agent2-key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIBOgIBAAJBAMl2/Ba0XSm4ayi4C0rJ+tYtQu8O31VVXezkLJlf+6fVgdpVhYg5 3 | QlihlPUoiM/wOsDWQ1ALnNhPlcLaQk+etQECAwEAAQJBAMT6Bf34+UHKY1ObpsbH 4 | 9u2jsVblFq1rWvs8GPMY6oertzvwm3DpuSUp7PTgOB1nLTLYtCERbQ4ovtN8tn3p 5 | OHUCIQDzIEGsoCr5vlxXvy2zJwu+fxYuhTZWMVuo1397L0VyhwIhANQh+yzqUgaf 6 | WRtSB4T2W7ADtJI35ET61jKBty3CqJY3AiAIwju7dVW3A5WeD6Qc1SZGKZvp9yCb 7 | AFI2BfVwwaY11wIgXF3PeGcvACMyMWsuSv7aPXHfliswAbkWuzcwA4TW01ECIGWa 8 | cgsDvVFxmfM5NPSuT/UDTa6R5BFISB5ea0N0AR3I 9 | -----END RSA PRIVATE KEY----- 10 | -------------------------------------------------------------------------------- /vendor/dnode/examples/web-browserify/server.js: -------------------------------------------------------------------------------- 1 | var connect = require('connect'); 2 | var browserify = require('browserify'); 3 | var dnode = require('dnode'); 4 | 5 | var server = connect.createServer(); 6 | 7 | server.use(connect.static(__dirname)); 8 | 9 | server.use(browserify({ 10 | require : 'dnode', 11 | mount : '/browserify.js' 12 | })); 13 | 14 | dnode(function (client) { 15 | this.cat = function (cb) { 16 | cb('meow'); 17 | }; 18 | }).listen(server); 19 | 20 | server.listen(6857); 21 | console.log('http://localhost:6857/'); 22 | -------------------------------------------------------------------------------- /vendor/dnode/test/keys/agent1-key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIBOwIBAAJBAJ86QKnKF2cVic/1hSuwV8A9t45URMhtdce4JMnbXh75+j61QWwe 3 | cn7unG5PMN/wK+tPAHMjEPbx45C0Ch+3IxECAwEAAQJBAI2cU1IuR+4IO87WPyAB 4 | 76kruoo87AeNQkjjvuQ/00+b/6IS45mcEP5Kw0NukbqBhIw2di9uQ9J51DJ/ZfQr 5 | +YECIQDUHaN3ZjIdJ7/w8Yq9Zzz+3kY2F/xEz6e4ftOFW8bY2QIhAMAref+WYckC 6 | oECgOLAvAxB1lI4j7oCbAaawfxKdnPj5AiEAi95rXx09aGpAsBGmSdScrPdG1v6j 7 | 83/2ebrvoZ1uFqkCIB0AssnrRVjUB6GZTNTyU3ERfdkx/RX1zvr8WkFR/lXpAiB7 8 | cUZ1i8ZkZrPrdVgw2cb28UJM7qZHQnXcMHTXFFvxeQ== 9 | -----END RSA PRIVATE KEY----- 10 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/test/instance.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var Traverse = require('../'); 3 | var EventEmitter = require('events').EventEmitter; 4 | 5 | exports['check instanceof on node elems'] = function () { 6 | 7 | var counts = { emitter : 0 }; 8 | 9 | Traverse([ new EventEmitter, 3, 4, { ev : new EventEmitter }]) 10 | .forEach(function (node) { 11 | if (node instanceof EventEmitter) counts.emitter ++; 12 | }) 13 | ; 14 | 15 | assert.equal(counts.emitter, 2); 16 | }; 17 | 18 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/test/leaves.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var Traverse = require('../'); 3 | 4 | exports['leaves test'] = function () { 5 | var acc = []; 6 | Traverse({ 7 | a : [1,2,3], 8 | b : 4, 9 | c : [5,6], 10 | d : { e : [7,8], f : 9 } 11 | }).forEach(function (x) { 12 | if (this.isLeaf) acc.push(x); 13 | }); 14 | 15 | assert.equal( 16 | acc.join(' '), 17 | '1 2 3 4 5 6 7 8 9', 18 | 'Traversal in the right(?) order' 19 | ); 20 | }; 21 | 22 | -------------------------------------------------------------------------------- /vendor/dnode/examples/web-browserify/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | 17 | The cat says ?. 18 | 19 | 20 | -------------------------------------------------------------------------------- /examples/constructors/child-hooks/hook-custom-child-spawn.js: -------------------------------------------------------------------------------- 1 | var Hook = require('../../../lib/hookio').Hook; 2 | 3 | var hook = new Hook({ 4 | name: "hook", 5 | hooks: [ 6 | { 7 | type: 'helloworld', 8 | name: 'b', 9 | foo: "bar" 10 | }, 11 | { 12 | type: 'helloworld', 13 | name: 'c', 14 | beep: "boop" 15 | }, 16 | { 17 | type: 'helloworld', 18 | name: 'd' 19 | } 20 | ] 21 | }); 22 | 23 | hook.on('hook::ready', function () { 24 | console.log('hook ready'); 25 | }); 26 | 27 | hook.start(); 28 | -------------------------------------------------------------------------------- /examples/spawn/many-hook-spawn.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Creates a helloworld hook, then spawns three helloworld children 3 | */ 4 | 5 | var Helloworld = require('hook.io-helloworld').Helloworld; 6 | 7 | var myHello = new Helloworld({ name: "helloworld" }); 8 | 9 | myHello.on('hook::ready', function () { 10 | 11 | // 12 | // This will spawn up three more "helloworld" hooks with auto-configuration 13 | // see: custom-hook-spawn.js for customized spawn settings 14 | // 15 | // 16 | myHello.spawn(['helloworld', 'helloworld', 'helloworld']); 17 | 18 | }); 19 | 20 | myHello.start(); -------------------------------------------------------------------------------- /examples/spawn/simple-hook-spawn.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Creates a helloworld hook, then spawns three helloworld children 3 | */ 4 | 5 | var Helloworld = require('hook.io-helloworld').Helloworld; 6 | 7 | var myHello = new Helloworld({ name: "helloworld" }); 8 | 9 | myHello.on('hook::ready', function () { 10 | 11 | // 12 | // This will spawn up three more "helloworld" hooks with auto-configuration 13 | // see: custom-hook-spawn.js for customized spawn settings 14 | // 15 | // 16 | myHello.spawn(['helloworld', 'helloworld', 'helloworld']); 17 | 18 | }); 19 | 20 | myHello.start(); -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "traverse", 3 | "version" : "0.5.2", 4 | "description" : "Traverse and transform objects by visiting every node on a recursive walk", 5 | "author" : "James Halliday", 6 | "license" : "MIT/X11", 7 | "main" : "./index", 8 | "repository" : { 9 | "type" : "git", 10 | "url" : "http://github.com/substack/js-traverse.git" 11 | }, 12 | "devDependencies" : { 13 | "expresso" : "0.7.x" 14 | }, 15 | "scripts" : { 16 | "test" : "expresso" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /examples/messaging/local/hook-emit.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple example for basic Hook.emit syntax 3 | */ 4 | 5 | var Hook = require('../../../lib/hookio').Hook; 6 | 7 | 8 | var hook1 = new Hook({ 9 | name: "server-hook", 10 | debug: true 11 | }); 12 | 13 | hook1.on('hello', function (data, callback) { 14 | console.log('calling result back ', data); 15 | callback(null, data); 16 | }) 17 | 18 | hook1.on('hook::ready', function () { 19 | hook1.on('hello::result', function (data) { 20 | console.log('got back ', data); 21 | }); 22 | hook1.emit('hello', 'world'); 23 | }); 24 | 25 | hook1.start(); -------------------------------------------------------------------------------- /examples/npm/remote-npm-install.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Creates `hook1` and `hook2`. `hook1` then remotely installs a NPM package on `hook2` 3 | */ 4 | 5 | var Hook = require('../../lib/hookio').Hook; 6 | 7 | var hook1 = new Hook({ 8 | name: "hook1", 9 | debug: true 10 | }); 11 | 12 | hook1.on('hook::ready', function () { 13 | 14 | var hook2 = new Hook({ 15 | name: "hook2", 16 | debug: true 17 | }); 18 | 19 | hook2.start(); 20 | 21 | hook2.on('hook::ready', function () { 22 | hook1.emit('install', 'hook.io-helloworld'); 23 | }); 24 | 25 | }); 26 | 27 | hook1.start(); 28 | -------------------------------------------------------------------------------- /vendor/dnode/examples/web-http/server.js: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | var fs = require('fs'); 3 | var dnode = require('dnode'); 4 | 5 | var index = fs.readFileSync(__dirname + '/index.html'); 6 | 7 | var server = http.createServer(function (req, res) { 8 | if (req.url === '/') { 9 | res.writeHead(200, { 'Content-Type' : 'text/html' }); 10 | res.end(index); 11 | } 12 | }); 13 | 14 | dnode(function (client) { 15 | this.cat = function (cb) { 16 | cb('meow'); 17 | }; 18 | }).listen(server); 19 | 20 | server.listen(6857); 21 | console.log('http://localhost:6857/'); 22 | -------------------------------------------------------------------------------- /vendor/dnode/test/keys/agent1-csr.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIBXTCCAQcCAQAwfTELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMQswCQYDVQQH 3 | EwJTRjEPMA0GA1UEChMGSm95ZW50MRAwDgYDVQQLEwdOb2RlLmpzMQ8wDQYDVQQD 4 | EwZhZ2VudDExIDAeBgkqhkiG9w0BCQEWEXJ5QHRpbnljbG91ZHMub3JnMFwwDQYJ 5 | KoZIhvcNAQEBBQADSwAwSAJBAJ86QKnKF2cVic/1hSuwV8A9t45URMhtdce4JMnb 6 | Xh75+j61QWwecn7unG5PMN/wK+tPAHMjEPbx45C0Ch+3IxECAwEAAaAlMCMGCSqG 7 | SIb3DQEJBzEWExRBIGNoYWxsZW5nZSBwYXNzd29yZDANBgkqhkiG9w0BAQUFAANB 8 | AF+AfG64hNyYHum46m6i7RgnUBrJSOynGjs23TekV4he3QdMSAAPPqbll8W14+y3 9 | vOo7/yQ2v2uTqxCjakUNPPs= 10 | -----END CERTIFICATE REQUEST----- 11 | -------------------------------------------------------------------------------- /vendor/dnode/test/keys/agent2-csr.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIBXTCCAQcCAQAwfTELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMQswCQYDVQQH 3 | EwJTRjEPMA0GA1UEChMGSm95ZW50MRAwDgYDVQQLEwdOb2RlLmpzMQ8wDQYDVQQD 4 | EwZhZ2VudDIxIDAeBgkqhkiG9w0BCQEWEXJ5QHRpbnljbG91ZHMub3JnMFwwDQYJ 5 | KoZIhvcNAQEBBQADSwAwSAJBAMl2/Ba0XSm4ayi4C0rJ+tYtQu8O31VVXezkLJlf 6 | +6fVgdpVhYg5QlihlPUoiM/wOsDWQ1ALnNhPlcLaQk+etQECAwEAAaAlMCMGCSqG 7 | SIb3DQEJBzEWExRBIGNoYWxsZW5nZSBwYXNzd29yZDANBgkqhkiG9w0BAQUFAANB 8 | AJnll2pt5l0pzskQSpjjLVTlFDFmJr/AZ3UK8v0WxBjYjCe5Jx4YehkChpxIyDUm 9 | U3J9q9MDUf0+Y2+EGkssFfk= 10 | -----END CERTIFICATE REQUEST----- 11 | -------------------------------------------------------------------------------- /vendor/dnode/examples/perf/emitter.js: -------------------------------------------------------------------------------- 1 | var dnode = require('dnode'); 2 | var EventEmitter = require('events').EventEmitter; 3 | 4 | var clients = {}; 5 | setInterval(function () { 6 | Object.keys(clients).forEach(function (id) { 7 | var i = Math.floor(Math.random() * Math.pow(2,32)); 8 | clients[id].emit(i); 9 | }); 10 | }, 1000 / 50); // 50 fps 11 | 12 | dnode(function (client, conn) { 13 | conn.on('ready', function () { 14 | clients[conn.id] = client; 15 | }); 16 | 17 | conn.on('end', function () { 18 | delete clients[conn.id]; 19 | }); 20 | }).listen(7575); 21 | -------------------------------------------------------------------------------- /vendor/dnode/test/refs.js: -------------------------------------------------------------------------------- 1 | var dnode = require('../'); 2 | var test = require('tap').test; 3 | 4 | test('refs', function (t) { 5 | t.plan(2); 6 | var port = Math.floor(Math.random() * 40000 + 10000); 7 | 8 | var server = dnode({ 9 | a : 1, 10 | b : 2, 11 | }).listen(port); 12 | 13 | server.on('ready', function () { 14 | dnode.connect(port, function (remote, conn) { 15 | conn.end(); 16 | server.close(); 17 | t.equal(remote.a, 1); 18 | t.equal(remote.b, 2); 19 | t.end(); 20 | }); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /examples/constructors/hook-redis-config.js: -------------------------------------------------------------------------------- 1 | 2 | var Hook = require('../../lib/hookio').Hook; 3 | 4 | var hook = new Hook({ 5 | redis: { 6 | host: 'localhost', 7 | port: 6379, 8 | db: 0, 9 | namespace: 'hookio' 10 | } 11 | }); 12 | 13 | /* 14 | We have the following redis keys in our redis db 15 | * hookio:name -> 'myhook' 16 | * hookio:type -> 'hook' 17 | 18 | It is equivalent to 19 | 20 | var hook = new Hook({ 21 | name: 'myhook', 22 | type: 'hook' 23 | }); 24 | */ 25 | 26 | hook.on('hook::ready', function () { 27 | console.log('hook ready'); 28 | }); 29 | 30 | hook.start(); 31 | -------------------------------------------------------------------------------- /lib/hookio/scaffold/lib/scaffold.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | hook.io hook for creating hook.io hooks 4 | 5 | ( the scaffold generates new hooks by inspecting itself ) 6 | 7 | */ 8 | 9 | 10 | var Hook = require('hook.io').Hook, 11 | util = require('util'); 12 | 13 | var Scaffold = exports.Scaffold = function(options){ 14 | Hook.call(this, options); 15 | var self = this; 16 | }; 17 | 18 | // Scaffold inherits from Hook 19 | util.inherits(Scaffold, Hook); 20 | 21 | Scaffold.prototype.doSomething = function(options, callback){ 22 | 23 | }; 24 | 25 | Scaffold.prototype.doSomethingElse = function(options, callback){ 26 | 27 | }; -------------------------------------------------------------------------------- /examples/spawn/type-hook-spawn.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Hook type spawning 3 | */ 4 | 5 | var Helloworld = require('hook.io-helloworld').Helloworld; 6 | 7 | 8 | var myHello = new Helloworld({ 9 | name: "a", 10 | debug: true 11 | }); 12 | 13 | myHello.on('hook::ready', function () { 14 | 15 | myHello.spawn([ 16 | { 17 | type: 'helloworld', 18 | name: 'b', 19 | foo: "bar" 20 | }, 21 | { 22 | type: 'helloworld', 23 | name: 'c', 24 | beep: "boop" 25 | }, 26 | { 27 | type: 'helloworld', 28 | name: 'd' 29 | } 30 | ]); 31 | 32 | }); 33 | 34 | myHello.start(); -------------------------------------------------------------------------------- /examples/pummel/master.js: -------------------------------------------------------------------------------- 1 | var Hook = require('../../lib/hookio').Hook; 2 | //var profiler = require('v8-profiler'); 3 | 4 | var hook = new Hook( { 5 | name: 'MemLeakMaster', 6 | silent: true, 7 | local:true, 8 | oneway:true 9 | }); 10 | 11 | hook.on('hook::ready', function () { 12 | hook.spawn([ 13 | { 14 | src: '../emitter.js', 15 | name:'emitter', 16 | silent: true, 17 | oneway: true 18 | }, 19 | { src: '../listener.js',name:'listener', silent:true, oneway:true}, 20 | { src: '../listener.js',name:'listener', silent:true, oneway:true} 21 | ]); 22 | }); 23 | 24 | hook.start(); 25 | -------------------------------------------------------------------------------- /lib/hookio/scaffold/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "Marak Squires ", 3 | "name": "hook.io-scaffold", 4 | "description": "a simple hook.io hook for creating hook.io hooks", 5 | "version": "0.1.0", 6 | "repository": { 7 | "type": "git", 8 | "url": "git://github.com/hookio/scaffold.git" 9 | }, 10 | "bin": { 11 | "hookio-scaffold": "./bin/scaffold" 12 | }, 13 | "main" : "lib/introspect", 14 | "engines": { 15 | "node": ">= v0.4.7" 16 | }, 17 | "dependencies": { 18 | "hook.io": "0.8.x", 19 | "colors": "0.5.x", 20 | "async": "0.1.x" 21 | }, 22 | "devDependencies": {} 23 | } -------------------------------------------------------------------------------- /vendor/dnode-protocol/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dnode-protocol", 3 | "description": "Implements the dnode protocol abstractly", 4 | "version": "0.1.1", 5 | "repository": "https://github.com/substack/dnode-protocol.git", 6 | "author": { 7 | "name" : "James Halliday", 8 | "email" : "mail@substack.net", 9 | "url" : "http://substack.net" 10 | }, 11 | "main": "./index.js", 12 | "dependencies" : { 13 | "traverse" : "0.5.x", 14 | "jsonify" : "0.0.x" 15 | }, 16 | "scripts": { 17 | "test": "expresso" 18 | }, 19 | "engines": { "node" : ">=0.2.0" } 20 | } 21 | -------------------------------------------------------------------------------- /vendor/dnode/examples/https/index.html: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 |

timesTen(10) == ?

16 |

My name is ?.

17 | -------------------------------------------------------------------------------- /vendor/dnode/examples/chat/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | dnode chat example 4 | 5 | 6 | 7 | 8 |
9 |
10 |
11 | Name: 12 | 13 |
14 |
15 | 16 |
17 | 18 |
19 | 20 |
21 |
22 | 23 | 24 | -------------------------------------------------------------------------------- /vendor/dnode/bin/bundle.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var path = require('path'); 3 | var browserify = require('browserify'); 4 | 5 | var src = browserify({ filter : require('uglify-js') }) 6 | .require(__dirname + '/../browser/index.js') 7 | .bundle() 8 | ; 9 | 10 | var buf = new Buffer('var DNode = (function () {' 11 | + src + '; return require("/index.js")' 12 | + '})()'); 13 | 14 | var file = __dirname + '/../browser/bundle.js'; 15 | fs.writeFile(file, buf, function (err) { 16 | if (err) console.error('Error: ' + err) 17 | else { 18 | var bytes = buf.length; 19 | console.log(bytes + ' bytes written'); 20 | } 21 | }); 22 | -------------------------------------------------------------------------------- /examples/authentication/basic-connection-auth.js: -------------------------------------------------------------------------------- 1 | var hookio = require('../../lib/hookio'); 2 | 3 | // 4 | // Create server hook 5 | // 6 | hookio.createHook({ 7 | authorize: customAuth 8 | }).listen(); 9 | 10 | // 11 | // Create client hook 12 | // 13 | hookio.createHook({ 14 | user : "marak", 15 | password : "test123" 16 | }).connect(); 17 | 18 | 19 | function customAuth(user, password, cb) { 20 | if (user == 'marak' && password == 'test123') { 21 | // 22 | // true indicates that login worked 23 | // 24 | cb(null, true); 25 | } 26 | else { 27 | // 28 | // false indicates that login failed 29 | // 30 | cb(null, false); 31 | } 32 | } -------------------------------------------------------------------------------- /examples/messaging/remote/hook-emit-child-onany.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple example for basic Hook.emit syntax 3 | */ 4 | 5 | var Hook = require('../../../lib/hookio').Hook; 6 | 7 | 8 | var hook1 = new Hook({ 9 | name: "server-hook", 10 | debug: true 11 | }); 12 | 13 | var hook2 = new Hook({ 14 | name: "callback-hook", 15 | debug: true 16 | }); 17 | 18 | hook2.onAny(function (data, callback) { 19 | console.log(this.event, data); 20 | }) 21 | 22 | console.log(hook1.getEvents()); 23 | 24 | hook1.on('hook::ready', function () { 25 | hook2.start(); 26 | hook2.on('hook::ready', function () { 27 | hook1.emit('hello', 'world'); 28 | }); 29 | }); 30 | 31 | hook1.start(); -------------------------------------------------------------------------------- /examples/messaging/remote/hook-emit-parent-onany.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple example for basic Hook.emit syntax 3 | */ 4 | 5 | var Hook = require('../../../lib/hookio').Hook; 6 | 7 | 8 | var hook1 = new Hook({ 9 | name: "server-hook", 10 | debug: true 11 | }); 12 | 13 | var hook2 = new Hook({ 14 | name: "callback-hook", 15 | debug: true 16 | }); 17 | 18 | hook1.onAny(function (data, callback) { 19 | console.log(this.event, data); 20 | }) 21 | 22 | console.log(hook1.getEvents()); 23 | 24 | hook1.on('hook::ready', function () { 25 | hook2.start(); 26 | hook2.on('hook::ready', function () { 27 | hook2.emit('hello', 'world'); 28 | }); 29 | }); 30 | 31 | hook1.start(); -------------------------------------------------------------------------------- /examples/constructors/eventMap/event-map-hook.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Creates a helloworld hook, then spawns three helloworld children 3 | */ 4 | 5 | var Hook = require('../../../lib/hookio').Hook; 6 | 7 | var pingPongModule = require('../../../test/fixtures/pingPongModule.js'); 8 | 9 | var myHook = new Hook({ 10 | name: "event-map-hook", 11 | events: { 12 | "*::ping" : pingPongModule.ping, 13 | "*::customPing" : function (msg) { 14 | console.log('custom ping'); 15 | msg = 'foo ' + msg; 16 | pingPongModule.ping(msg); 17 | } 18 | } 19 | }); 20 | 21 | myHook.on('hook::ready', function () { 22 | console.log('ready'); 23 | }); 24 | 25 | myHook.start(); 26 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/test/negative.js: -------------------------------------------------------------------------------- 1 | var Traverse = require('../'); 2 | var assert = require('assert'); 3 | 4 | exports['negative update test'] = function () { 5 | var obj = [ 5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ]; 6 | var fixed = Traverse.map(obj, function (x) { 7 | if (x < 0) this.update(x + 128); 8 | }); 9 | 10 | assert.deepEqual(fixed, 11 | [ 5, 6, 125, [ 7, 8, 126, 1 ], { f: 10, g: 115 } ], 12 | 'Negative values += 128' 13 | ); 14 | 15 | assert.deepEqual(obj, 16 | [ 5, 6, -3, [ 7, 8, -2, 1 ], { f: 10, g: -13 } ], 17 | 'Original references not modified' 18 | ); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /examples/spawn/custom-hook-spawn.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Hook type spawning 3 | */ 4 | 5 | var Helloworld = require('hook.io-helloworld').Helloworld; 6 | 7 | 8 | var myHello = new Helloworld({ 9 | name: "a", 10 | debug: true 11 | }); 12 | 13 | myHello.on('hook::ready', function () { 14 | 15 | myHello.spawn([ 16 | { 17 | src: '../../test/fixtures/HelloWorld', 18 | name: 'b', 19 | foo: "bar" 20 | }, 21 | { 22 | src: '../../test/fixtures/HelloWorld', 23 | name: 'c', 24 | beep: "boop" 25 | }, 26 | { 27 | src: '../../test/fixtures/HelloWorld', 28 | name: 'd' 29 | } 30 | ]); 31 | 32 | }); 33 | 34 | myHello.start(); -------------------------------------------------------------------------------- /examples/disconnect/hook-server.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Creates a server hook, spawns 2 client hooks, stops listening as server 3 | */ 4 | 5 | var Hook = require('../../lib/hookio').Hook; 6 | 7 | var hook = new Hook({ 8 | name: "server-hook", 9 | debug: "true", 10 | hooks: [ 11 | { 12 | type: "helloworld", 13 | name: "client-hook-0" 14 | }, 15 | { 16 | type: "helloworld", 17 | name: "client-hook-1" 18 | } 19 | ] 20 | }); 21 | 22 | hook.on('hook::ready', function() { 23 | setInterval(function() { 24 | hook.emit('hello', hook.name); 25 | }, 1000); 26 | 27 | setTimeout(function() { 28 | hook.stop(); 29 | }, 9999); 30 | }); 31 | 32 | hook.start(); 33 | -------------------------------------------------------------------------------- /vendor/dnode/examples/auth/quotes.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "quote" : "Beauty is a consequential thing, a product of solving problems correctly.", 4 | "who" : "Joseph Eshrick" 5 | }, 6 | { 7 | "quote" : "If you wish to make an apple pie from scratch, you must first invent the universe.", 8 | "who" : "Carl Sagan" 9 | }, 10 | { 11 | "quote" : "If you're not allowed to implement new ideas, you stop having them.", 12 | "who" : "Paul Graham" 13 | }, 14 | { 15 | "quote" : "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled.", 16 | "who" : "Richard Feynman" 17 | } 18 | ] 19 | -------------------------------------------------------------------------------- /vendor/dnode/test/unix.js: -------------------------------------------------------------------------------- 1 | var dnode = require('../'); 2 | var test = require('tap').test; 3 | 4 | test('unix', function (t) { 5 | t.plan(1); 6 | 7 | var sfile = '/tmp/unix_socket_' + Math.floor( 8 | Math.random() * Math.pow(2, 32) 9 | ).toString(16); 10 | 11 | var server = dnode({ f : function (cb) { cb(1337) } }).listen(sfile); 12 | 13 | server.on('ready', function () { 14 | dnode.connect(sfile, function (remote, conn) { 15 | remote.f(function (x) { 16 | t.equal(x, 1337); 17 | server.close(); 18 | conn.end(); 19 | t.end(); 20 | }); 21 | }); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /bin/forever-shim: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var argv = require('optimist').argv; 4 | 5 | var hookPath; 6 | 7 | var path = require('path'); 8 | 9 | if (argv['src']) { 10 | hookPath = path.resolve(argv['src']); 11 | } 12 | 13 | if (argv['hook-type']) { 14 | hookPath = 'hook.io-' + argv['hook-type']; 15 | } 16 | 17 | var Hook = require(hookPath); 18 | 19 | var keys = Object.keys(Hook); 20 | 21 | // 22 | // Remark: Assume the first class exported extends from Hook 23 | // 24 | 25 | // 26 | // TODO: Refactor this convention, it's a bit brittle 27 | // 28 | var hookClass = keys[0]; 29 | if (keys.length > 1) { 30 | hookClass = 'Hook'; 31 | } 32 | var hook = new Hook[hookClass](argv); 33 | 34 | hook.start(); 35 | -------------------------------------------------------------------------------- /examples/messaging/remote/hook-emit-sender-info.js: -------------------------------------------------------------------------------- 1 | 2 | var Hook = require('../../../lib/hookio').Hook; 3 | 4 | 5 | var hook1 = new Hook({ 6 | name: "server-hook", 7 | debug: true 8 | }); 9 | 10 | var hook2 = new Hook({ 11 | name: "client-hook", 12 | debug: true 13 | }); 14 | 15 | hook1.on('*::hello', function (data, callback, sender) { 16 | console.log('== hook received event from %s', sender.name); 17 | }) 18 | 19 | hook1.on('hook::ready', function () { 20 | hook2.start(); 21 | hook2.on('hook::ready', function () { 22 | hook2.on('hello::result', function (data) { 23 | console.log('result is back ', data); 24 | }); 25 | hook2.emit('hello', 'world'); 26 | }); 27 | }); 28 | 29 | hook1.start(); -------------------------------------------------------------------------------- /vendor/dnode/examples/bidirectional/client.js: -------------------------------------------------------------------------------- 1 | var dnode = require('dnode'); 2 | 3 | var client = dnode({ 4 | // Compute the client's temperature and stuff that value into the callback 5 | 6 | temperature : function (cb) { 7 | var degC = Math.round(20 + Math.random() * 10 - 5); 8 | console.log(degC + '° C'); 9 | cb(degC); 10 | } 11 | }); 12 | 13 | client.connect(6060, function (remote, conn) { 14 | // Call the server's conversion routine, which polls the client's 15 | // temperature in celsius degrees and converts to fahrenheit 16 | 17 | remote.clientTempF(function (degF) { 18 | console.log(degF + '° F'); 19 | conn.end(); // all done! 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /examples/kill/simple-hook-kill.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Creates a server hook, a client hook, kills the client hook 3 | */ 4 | 5 | var Hook = require('../../lib/hookio').Hook; 6 | 7 | var hook1 = new Hook({ 8 | name: "server-hook", 9 | debug: "true" 10 | }); 11 | 12 | hook1.on('hook::ready', function() { 13 | setInterval(function() { 14 | hook1.emit('hello', hook1.name); 15 | }, 1000); 16 | }); 17 | 18 | hook1.start(); 19 | 20 | var hook2 = new Hook({ 21 | name: "client-hook", 22 | debug: "true" 23 | }); 24 | 25 | hook2.on('hook::ready', function() { 26 | var counter = 0; 27 | hook2.on('*::hello', function(){ 28 | console.log('got hello'); 29 | counter++; 30 | if (counter >= 3) { 31 | hook2.kill(); 32 | } 33 | }); 34 | }); 35 | 36 | hook2.start(); 37 | -------------------------------------------------------------------------------- /test/fixtures/HelloWorld.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple Hook-io plugin 3 | */ 4 | 5 | var Hook = require('hook.io').Hook, 6 | util = require('util'); 7 | 8 | 9 | var Helloworld = exports.Helloworld = function (options) { 10 | 11 | var self = this; 12 | Hook.call(this, options); 13 | 14 | //console.log(options); 15 | 16 | this.on('hook::ready', function () { 17 | self.on('*::hello', function(data){ 18 | 19 | console.log(data); 20 | 21 | }); 22 | 23 | // 24 | // This is just to simulate I/O, don't use timers... 25 | // 26 | setInterval(function () { 27 | self.emit('hello', 'Hello, I am ' + self.name); 28 | }, 1000); 29 | 30 | }); 31 | }; 32 | 33 | // 34 | // Inherit from `hookio.Hook` 35 | // 36 | util.inherits(Helloworld, Hook); 37 | -------------------------------------------------------------------------------- /examples/messaging/remote/hook-emit-child.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple example for basic Hook.emit syntax 3 | */ 4 | 5 | var Hook = require('../../../lib/hookio').Hook; 6 | 7 | 8 | var hook1 = new Hook({ 9 | name: "server-hook", 10 | debug: true 11 | }); 12 | 13 | var hook2 = new Hook({ 14 | name: "callback-hook", 15 | debug: true 16 | }); 17 | 18 | hook1.on('*::hello', function (data, callback) { 19 | console.log('calling result back ', data); 20 | callback(null, data); 21 | }) 22 | 23 | hook1.on('hook::ready', function () { 24 | hook2.start(); 25 | hook2.on('hook::ready', function () { 26 | hook2.on('hello::result', function (data) { 27 | console.log('result is back ', data); 28 | }); 29 | hook2.emit('hello', 'world'); 30 | }); 31 | }); 32 | 33 | hook1.start(); -------------------------------------------------------------------------------- /examples/kill/spawn-hook-kill.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Creates a server hook, spawn a client hook, kill the spawned client 3 | */ 4 | 5 | var Hook = require('../../lib/hookio').Hook; 6 | 7 | var hook1 = new Hook({ 8 | name: "server-hook", 9 | debug: "true", 10 | hooks: [ 11 | { 12 | name: "client-hook", 13 | type: "helloworld", 14 | debug: "true" 15 | } 16 | ] 17 | }); 18 | 19 | hook1.on('hook::ready', function() { 20 | 21 | var counter = 0; 22 | hook1.on('*::hello', function(){ 23 | console.log('got hello'); 24 | counter++; 25 | if (counter >= 3) { 26 | hook1.kill('client-hook', function(err){ 27 | if (err) { 28 | console.log(err); 29 | } 30 | }); 31 | } 32 | }); 33 | 34 | 35 | 36 | }); 37 | 38 | hook1.start(); 39 | 40 | -------------------------------------------------------------------------------- /vendor/dnode/test/keys/agent2-cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIB7DCCAZYCCQC7gs0MDNn6MTANBgkqhkiG9w0BAQUFADB9MQswCQYDVQQGEwJV 3 | UzELMAkGA1UECBMCQ0ExCzAJBgNVBAcTAlNGMQ8wDQYDVQQKEwZKb3llbnQxEDAO 4 | BgNVBAsTB05vZGUuanMxDzANBgNVBAMTBmFnZW50MjEgMB4GCSqGSIb3DQEJARYR 5 | cnlAdGlueWNsb3Vkcy5vcmcwHhcNMTEwMzE0MTgyOTEyWhcNMzgwNzI5MTgyOTEy 6 | WjB9MQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExCzAJBgNVBAcTAlNGMQ8wDQYD 7 | VQQKEwZKb3llbnQxEDAOBgNVBAsTB05vZGUuanMxDzANBgNVBAMTBmFnZW50MjEg 8 | MB4GCSqGSIb3DQEJARYRcnlAdGlueWNsb3Vkcy5vcmcwXDANBgkqhkiG9w0BAQEF 9 | AANLADBIAkEAyXb8FrRdKbhrKLgLSsn61i1C7w7fVVVd7OQsmV/7p9WB2lWFiDlC 10 | WKGU9SiIz/A6wNZDUAuc2E+VwtpCT561AQIDAQABMA0GCSqGSIb3DQEBBQUAA0EA 11 | C8HzpuNhFLCI3A5KkBS5zHAQax6TFUOhbpBCR0aTDbJ6F1liDTK1lmU/BjvPoj+9 12 | 1LHwrmh29rK8kBPEjmymCQ== 13 | -----END CERTIFICATE----- 14 | -------------------------------------------------------------------------------- /test/spawn/basic-spawn-optional.js: -------------------------------------------------------------------------------- 1 | /* 2 | * test-basic-test.js: Basic tests for the hook.io module 3 | * 4 | * (C) 2011 Marak Squires, Charlie Robbins 5 | * MIT LICENCE 6 | * 7 | */ 8 | 9 | var vows = require('vows'), 10 | assert = require('assert'), 11 | Hook = require('../../lib/hookio').Hook, 12 | macros = require('../helpers/macros'); 13 | 14 | vows.describe('hook.io/spawn/basic-spawn').addBatch({ 15 | "When a hook is listening on a 5020": macros.assertListen('simple-host', 5020, { 16 | "and we ask it to be local and begin spawning": macros.assertHelloWorld(true) 17 | }), 18 | "When a hook is listening on a 5021": macros.assertListen('simple-host', 5021, { 19 | "and we ask it to spawn some children (out of process)" : macros.assertHelloWorld() 20 | }) 21 | }).export(module); 22 | -------------------------------------------------------------------------------- /test/spawn/bad-spawn-test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * test-basic-test.js: Basic tests for the hook.io module 3 | * 4 | * (C) 2011 Marak Squires, Charlie Robbins 5 | * MIT LICENCE 6 | * 7 | */ 8 | 9 | var vows = require('vows'), 10 | assert = require('assert'), 11 | Hook = require('../../lib/hookio').Hook, 12 | macros = require('../helpers/macros'); 13 | 14 | vows.describe('hook.io/spawn/bad-spawn').addBatch({ 15 | "When a hook is listening on 5023": macros.assertListen('simple-host', 5023, { 16 | "and we ask it to spawn a bad hook (out of process)": macros.assertSpawnError('hellbadspawn') 17 | // 18 | // TODO: Check edge case for bad spawn in process. 19 | // 20 | }), 21 | "When we attempt to spawn a child on a hook that is not listening": macros.assertSpawnError('helloworld') 22 | }).export(module); 23 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/jsonify/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "jsonify", 3 | "version" : "0.0.0", 4 | "description" : "JSON without touching any globals", 5 | "main" : "index.js", 6 | "directories" : { 7 | "lib" : ".", 8 | "test" : "test" 9 | }, 10 | "devDependencies" : { 11 | "tap" : "0.0.x", 12 | "garbage" : "0.0.x" 13 | }, 14 | "scripts" : { 15 | "test" : "tap test" 16 | }, 17 | "repository" : { 18 | "type" : "git", 19 | "url" : "http://github.com/substack/jsonify.git" 20 | }, 21 | "keywords" : [ 22 | "json", 23 | "browser" 24 | ], 25 | "author" : { 26 | "name" : "Douglas Crockford", 27 | "url" : "http://crockford.com/" 28 | }, 29 | "license" : "Public Domain" 30 | } 31 | -------------------------------------------------------------------------------- /examples/disconnect/hook-client.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Creates a server hook, 2 client hooks, one client stops listening to the server 3 | */ 4 | 5 | var Hook = require('../../lib/hookio').Hook, 6 | Helloworld = require('hook.io-helloworld').Helloworld; 7 | 8 | var hook = new Hook({ 9 | name: "server-hook", 10 | debug: "true" 11 | }); 12 | 13 | hook.on('hook::ready', function() { 14 | setInterval(function() { 15 | hook.emit('hello', hook.name); 16 | }, 1000); 17 | }); 18 | 19 | hook.start(); 20 | 21 | var client0 = new Helloworld({ 22 | name: "client-hook-0" 23 | }); 24 | 25 | var client1 = new Helloworld({ 26 | name: "client-hook-1" 27 | }); 28 | 29 | client0.on('hook::ready', function() { 30 | setTimeout(function() { 31 | client0.stop(); 32 | }, 9999); 33 | }); 34 | 35 | client0.start(); 36 | client1.start(); 37 | -------------------------------------------------------------------------------- /examples/pummel/emitter.js: -------------------------------------------------------------------------------- 1 | var Hook = require('../../lib/hookio').Hook; 2 | var util = require('util'); 3 | 4 | var fixture = '', i; 5 | for (i = 0; i < 5000; i++) { 6 | fixture += '#'; 7 | } 8 | 9 | var RealMessage = function () { 10 | this.bigData = fixture; 11 | } 12 | 13 | var Slave = exports.Slave = function (options) { 14 | self = this; 15 | var count = 0; 16 | Hook.call(this, options); 17 | 18 | function emitEvent () { 19 | count++; 20 | self.emit("someEvent",new RealMessage()); 21 | if (count==100) { 22 | count = 0; 23 | console.log(process.memoryUsage().rss); 24 | setTimeout(emitEvent, 20); 25 | } else 26 | setTimeout(emitEvent, 5); 27 | } 28 | 29 | this.on('hook::ready', function () { 30 | emitEvent(); 31 | }); 32 | } 33 | 34 | util.inherits(Slave, Hook); 35 | -------------------------------------------------------------------------------- /vendor/dnode/test/unicode.js: -------------------------------------------------------------------------------- 1 | var dnode = require('../'); 2 | var test = require('tap').test; 3 | 4 | test('unicode', function (t) { 5 | t.plan(2); 6 | var port = Math.floor(Math.random() * 40000 + 10000); 7 | 8 | var server = dnode({ 9 | unicodes : function (reply) { 10 | reply('☔☔☔☁☼☁❄'); 11 | } 12 | }).listen(port); 13 | 14 | server.on('ready', function () { 15 | dnode.connect(port, function (remote, conn) { 16 | t.equal(conn.stream.remoteAddress, '127.0.0.1'); 17 | remote.unicodes(function (str) { 18 | t.equal(str, '☔☔☔☁☼☁❄', 'remote unicodes == ☔☔☔☁☼☁❄'); 19 | 20 | conn.end(); 21 | server.close(); 22 | t.end(); 23 | }); 24 | }); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /vendor/dnode/test/keys/agent1-cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICKjCCAZMCCQDQ8o4kHKdCPDANBgkqhkiG9w0BAQUFADB6MQswCQYDVQQGEwJV 3 | UzELMAkGA1UECBMCQ0ExCzAJBgNVBAcTAlNGMQ8wDQYDVQQKEwZKb3llbnQxEDAO 4 | BgNVBAsTB05vZGUuanMxDDAKBgNVBAMTA2NhMTEgMB4GCSqGSIb3DQEJARYRcnlA 5 | dGlueWNsb3Vkcy5vcmcwHhcNMTEwMzE0MTgyOTEyWhcNMzgwNzI5MTgyOTEyWjB9 6 | MQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExCzAJBgNVBAcTAlNGMQ8wDQYDVQQK 7 | EwZKb3llbnQxEDAOBgNVBAsTB05vZGUuanMxDzANBgNVBAMTBmFnZW50MTEgMB4G 8 | CSqGSIb3DQEJARYRcnlAdGlueWNsb3Vkcy5vcmcwXDANBgkqhkiG9w0BAQEFAANL 9 | ADBIAkEAnzpAqcoXZxWJz/WFK7BXwD23jlREyG11x7gkydteHvn6PrVBbB5yfu6c 10 | bk8w3/Ar608AcyMQ9vHjkLQKH7cjEQIDAQABMA0GCSqGSIb3DQEBBQUAA4GBAKha 11 | HqjCfTIut+m/idKy3AoFh48tBHo3p9Nl5uBjQJmahKdZAaiksL24Pl+NzPQ8LIU+ 12 | FyDHFp6OeJKN6HzZ72Bh9wpBVu6Uj1hwhZhincyTXT80wtSI/BoUAW8Ls2kwPdus 13 | 64LsJhhxqj2m4vPKNRbHB2QxnNrGi30CUf3kt3Ia 14 | -----END CERTIFICATE----- 15 | -------------------------------------------------------------------------------- /vendor/dnode/test/stream.js: -------------------------------------------------------------------------------- 1 | var dnode = require('../'); 2 | var net = require('net'); 3 | var test = require('tap').test; 4 | 5 | test('stream', function (t) { 6 | t.plan(1); 7 | var port = Math.floor(Math.random() * 40000 + 10000); 8 | 9 | var server = dnode({ 10 | meow : function f (g) { g('cats') } 11 | }); 12 | 13 | var netServer = net.createServer(); 14 | server.listen(netServer); 15 | 16 | var times = 0; 17 | netServer.listen(port, function () { 18 | var netClient = net.createConnection(port); 19 | dnode.connect(netClient, function (remote) { 20 | remote.meow(function (cats) { 21 | t.equal(cats, 'cats'); 22 | 23 | netClient.end(); 24 | netServer.close(); 25 | t.end(); 26 | }); 27 | }); 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /examples/messaging/remote/hook-callback-parent.js: -------------------------------------------------------------------------------- 1 | var Hook = require('../../../lib/hookio').Hook; 2 | 3 | var hook1 = new Hook({ 4 | name: "a", 5 | debug: true 6 | }); 7 | 8 | var hook2 = new Hook({ 9 | name: "b", 10 | debug: true 11 | }); 12 | 13 | 14 | hook2.on('*::hello', function (data, callback) { 15 | // 16 | // callback is the callback for this event, 17 | // should it exist 18 | // 19 | var result = { 20 | "text": "Why hello there!" 21 | }; 22 | callback(null, result); 23 | 24 | }) 25 | 26 | hook1.on('hook::ready', function () { 27 | 28 | hook2.start(); 29 | 30 | hook2.on('hook::ready', function () { 31 | 32 | // 33 | // Event with data 34 | // event, data, callback 35 | // 36 | hook1.emit('hello', 'data1', function (err, data) { 37 | console.log('callback1 ', err, data); 38 | }); 39 | 40 | }); 41 | 42 | }); 43 | 44 | hook1.start(); -------------------------------------------------------------------------------- /examples/stop/simple-start-stop-start.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Creates a server hook, a client hook, stops the client hook, starts it up again 3 | */ 4 | 5 | var Hook = require('../../lib/hookio').Hook; 6 | 7 | var hook1 = new Hook({ 8 | name: "server-hook", 9 | debug: "true" 10 | }); 11 | 12 | hook1.on('hook::ready', function() { 13 | setInterval(function() { 14 | hook1.emit('hello', hook1.name); 15 | }, 1000); 16 | }); 17 | 18 | hook1.start(); 19 | 20 | var hook2 = new Hook({ 21 | name: "client-hook", 22 | debug: "true" 23 | }); 24 | 25 | hook2.on('hook::ready', function() { 26 | var counter = 0; 27 | hook2.on('*::hello', function(){ 28 | counter++; 29 | if (counter >= 3) { 30 | hook2.stop(); 31 | console.log('stopping hook...') 32 | setTimeout(function(){ 33 | console.log('resuming hook...'); 34 | hook2.start(); 35 | }, 5000) 36 | } 37 | }); 38 | }); 39 | 40 | hook2.start(); 41 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/test/keys.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var Traverse = require('../'); 3 | 4 | exports['sort test'] = function () { 5 | var acc = []; 6 | Traverse({ 7 | a: 30, 8 | b: 22, 9 | id: 9 10 | }).forEach(function (node) { 11 | if ((! Array.isArray(node)) && typeof node === 'object') { 12 | this.before(function(node) { 13 | this.keys = Object.keys(node); 14 | this.keys.sort(function(a, b) { 15 | a = [a === "id" ? 0 : 1, a]; 16 | b = [b === "id" ? 0 : 1, b]; 17 | return a < b ? -1 : a > b ? 1 : 0; 18 | }); 19 | }); 20 | } 21 | if (this.isLeaf) acc.push(node); 22 | }); 23 | 24 | assert.equal( 25 | acc.join(' '), 26 | '9 30 22', 27 | 'Traversal in a custom order' 28 | ); 29 | }; 30 | -------------------------------------------------------------------------------- /lib/hookio/commands/list.js: -------------------------------------------------------------------------------- 1 | // 2 | // list - Shows all currently installed and running hooks 3 | // 4 | 5 | // 6 | // TODO: command system should be refactored to use Flatiron 7 | // 8 | 9 | 10 | var path = require('path'), 11 | prompt = require('prompt'); 12 | 13 | 14 | var list = module.exports = function init () { 15 | 16 | // 17 | // Deletgate based on incoming argv 18 | // 19 | var self = this, 20 | args = self._, 21 | newHookName, 22 | newHookPath = process.cwd() + '/'; 23 | 24 | // 25 | // $ list 26 | // 27 | if(args.length === 1) { 28 | 29 | } 30 | 31 | self.emit('query', { type: 'hook' }, function(err, result){ 32 | console.log('Attempting to query for all locally running hooks...'); 33 | if (err) { 34 | console.log('error running query'); 35 | } 36 | console.log(result); 37 | process.nextTick(function(){ 38 | process.exit(); 39 | }); 40 | }); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /vendor/dnode/examples/saturate/saturate.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var connect = require('connect'); 4 | var server = connect.createServer( 5 | connect.static(__dirname) 6 | ); 7 | 8 | var clients = {}; 9 | 10 | var Hash = require('traverse/hash'); 11 | function publish () { 12 | var args = [].slice.call(arguments); 13 | Hash(clients).forEach( 14 | function (emit) { emit.apply({}, args) } 15 | ); 16 | } 17 | 18 | var DNode = require('dnode'); 19 | DNode(function (client, conn) { 20 | conn.on('ready', function () { 21 | clients[conn.id] = client.emit; 22 | }); 23 | 24 | conn.on('end', function () { 25 | delete clients[conn.id]; 26 | }); 27 | }).listen(server); 28 | 29 | console.log('http://localhost:6061/'); 30 | server.listen(6061); 31 | 32 | setInterval(function () { 33 | var n = Math.floor(Math.random() * 3e4); 34 | var buf = new Buffer(n); 35 | publish('data', buf.toString()); 36 | }, 50); 37 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/test/date.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var Traverse = require('../'); 3 | 4 | exports.dateEach = function () { 5 | var obj = { x : new Date, y : 10, z : 5 }; 6 | 7 | var counts = {}; 8 | 9 | Traverse(obj).forEach(function (node) { 10 | var t = (node instanceof Date && 'Date') || typeof node; 11 | counts[t] = (counts[t] || 0) + 1; 12 | }); 13 | 14 | assert.deepEqual(counts, { 15 | object : 1, 16 | Date : 1, 17 | number : 2, 18 | }); 19 | }; 20 | 21 | exports.dateMap = function () { 22 | var obj = { x : new Date, y : 10, z : 5 }; 23 | 24 | var res = Traverse(obj).map(function (node) { 25 | if (typeof node === 'number') this.update(node + 100); 26 | }); 27 | 28 | assert.ok(obj.x !== res.x); 29 | assert.deepEqual(res, { 30 | x : obj.x, 31 | y : 110, 32 | z : 105, 33 | }); 34 | }; 35 | 36 | -------------------------------------------------------------------------------- /examples/messaging/remote/hook-emit-parent.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple example for basic Hook.emit syntax 3 | */ 4 | 5 | var Hook = require('../../../lib/hookio').Hook; 6 | 7 | 8 | var hook1 = new Hook({ 9 | name: "server-hook", 10 | debug: true 11 | }); 12 | 13 | var hook2 = new Hook({ 14 | name: "callback-hook", 15 | debug: true 16 | }); 17 | 18 | hook2.on('*::hello', function (data, callback) { 19 | console.log('calling result back ', data); 20 | callback(null, data); 21 | }) 22 | 23 | hook1.on('hook::ready', function () { 24 | hook2.start(); 25 | hook2.on('hook::ready', function () { 26 | 27 | // 28 | // This works 29 | // 30 | hook1.on('hello::result', function (data) { 31 | console.log('1 result is back ', data); 32 | }); 33 | 34 | // 35 | // This does not 36 | // 37 | hook1.on('**::hello::result', function (data) { 38 | console.log('2 result is back ', data); 39 | }); 40 | 41 | hook1.emit('hello', 'world'); 42 | }); 43 | }); 44 | 45 | hook1.start(); -------------------------------------------------------------------------------- /vendor/dnode-protocol/test/store.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var Store = require('dnode-protocol').Store; 3 | 4 | exports.store = function () { 5 | var s = new Store; 6 | 7 | assert.eql(s.items.length, 0); 8 | 9 | var i = 0; 10 | var cb = function() { 11 | i++; 12 | }; 13 | 14 | var fn1 = function () { 15 | cb(); 16 | }; 17 | s.add(fn1); 18 | assert.eql(s.items.length, 1); 19 | s.get(0)(); 20 | fn1(); 21 | assert.eql(i, 2); 22 | assert.eql(s.items[0].times, undefined); 23 | 24 | var fn2 = function() { 25 | cb(); 26 | }; 27 | fn2.times = 2; 28 | s.add(fn2); 29 | assert.eql(s.items.length, 2); 30 | s.get(1)(); 31 | fn2(); 32 | assert.eql(i, 4); 33 | assert.eql(s.items[1].times, 1); 34 | s.get(1)(); 35 | assert.eql(s.items[1], undefined); 36 | 37 | var fn3 = function() { 38 | cb2(); 39 | }; 40 | s.add(fn3); 41 | assert.eql(s.items.length, 3); 42 | }; 43 | 44 | 45 | -------------------------------------------------------------------------------- /lib/hookio/transports/couchdb.js: -------------------------------------------------------------------------------- 1 | // 2 | // couchdb.js - the couchdb message transport for hook.io 3 | // 4 | 5 | var couch = exports, 6 | http = require('http'); 7 | 8 | couch.message = function (options, event, data, callback) { 9 | 10 | var req, 11 | options; 12 | 13 | options = { 14 | host: options.host || '127.0.0.1', 15 | port: options.port || 5984, 16 | path: "/" + options.db || 'database', 17 | method: "POST", 18 | headers: {"content-type": "application/json"} 19 | }; 20 | 21 | if (options.user && options.pass) { 22 | options.headers["Authorization"] = "Basic " + new Buffer(options.user + ":" + options.pass).toString('base64'); 23 | } 24 | 25 | req = http.request(options, function (res) { 26 | // 27 | // TODO: 28 | // 29 | }); 30 | 31 | req.on('error', function (err) { 32 | // 33 | // TODO: 34 | // 35 | }); 36 | 37 | req.write(JSON.stringify({ 38 | method: event, 39 | params: data 40 | })); 41 | 42 | req.end(); 43 | 44 | }; -------------------------------------------------------------------------------- /lib/hookio/commands/search.js: -------------------------------------------------------------------------------- 1 | // 2 | // search - Performs a search of hooks to install ( using npm.search in the background ) 3 | // 4 | 5 | // 6 | // TODO: command system should be refactored to use Flatiron 7 | // 8 | 9 | 10 | var path = require('path'), 11 | prompt = require('prompt'); 12 | 13 | 14 | var search = module.exports = function init () { 15 | 16 | // 17 | // Deletgate based on incoming argv 18 | // 19 | var self = this, 20 | args = self._, 21 | keywords = ["hook.io"]; 22 | 23 | 24 | 25 | // 26 | // $ search 27 | // 28 | if(args.length === 1) { 29 | } 30 | 31 | // 32 | // $ search foobar 33 | // 34 | if(args.length === 2) { 35 | keywords.push(args[1]); 36 | } 37 | 38 | console.log('Searching npm for ' + keywords + ', this may take a moment...'); 39 | self.npm.search(keywords, function(err, result){ 40 | 41 | if(err){ 42 | console.log(err); 43 | } 44 | 45 | process.nextTick(function(){ 46 | process.exit(); 47 | }); 48 | 49 | }); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /vendor/dnode/examples/auth/client.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // Connect to the auth server and display a quote from it. 3 | 4 | var DNode = require('dnode'); 5 | var sys = require('sys'); 6 | 7 | if (process.argv.length < 4) { 8 | sys.puts('Usage: ./client.js user pass'); 9 | process.exit(); 10 | } 11 | 12 | var user = process.argv[2]; 13 | var pass = process.argv[3]; 14 | 15 | DNode.connect(7007, function (remote,conn) { 16 | remote.authenticate(user, pass, function (session) { 17 | if (session) { 18 | sys.puts('Authentication success'); 19 | function showNext() { 20 | session.quote(function (q) { 21 | sys.puts('\nAnd now for a quote by ' + q.who + ':\n\n'); 22 | sys.puts(q.quote + '\n\n'); 23 | }); 24 | setTimeout(showNext, 5000); 25 | } 26 | showNext(); 27 | } 28 | else { 29 | sys.puts('Authentication failure'); 30 | conn.end(); 31 | } 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/test/subexpr.js: -------------------------------------------------------------------------------- 1 | var traverse = require('../'); 2 | var assert = require('assert'); 3 | 4 | exports.subexpr = function () { 5 | var obj = [ 'a', 4, 'b', 5, 'c', 6 ]; 6 | var r = traverse(obj).map(function (x) { 7 | if (typeof x === 'number') { 8 | this.update([ x - 0.1, x, x + 0.1 ], true); 9 | } 10 | }); 11 | 12 | assert.deepEqual(obj, [ 'a', 4, 'b', 5, 'c', 6 ]); 13 | assert.deepEqual(r, [ 14 | 'a', [ 3.9, 4, 4.1 ], 15 | 'b', [ 4.9, 5, 5.1 ], 16 | 'c', [ 5.9, 6, 6.1 ], 17 | ]); 18 | }; 19 | 20 | exports.block = function () { 21 | var obj = [ [ 1 ], [ 2 ], [ 3 ] ]; 22 | var r = traverse(obj).map(function (x) { 23 | if (Array.isArray(x) && !this.isRoot) { 24 | if (x[0] === 5) this.block() 25 | else this.update([ [ x[0] + 1 ] ]) 26 | } 27 | }); 28 | 29 | assert.deepEqual(r, [ 30 | [ [ [ [ [ 5 ] ] ] ] ], 31 | [ [ [ [ 5 ] ] ] ], 32 | [ [ [ 5 ] ] ], 33 | ]); 34 | }; 35 | -------------------------------------------------------------------------------- /examples/stop/simple-spawn-stop-start.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Creates a server hook, spawn a client hook, kill the spawned client 3 | */ 4 | 5 | // 6 | // WARN: Currently experiencing a race condition when using this example, 7 | // this means that there is a flaw somewhere in the start / stop / kill logic 8 | // 9 | 10 | var Hook = require('../../lib/hookio').Hook; 11 | 12 | var hook1 = new Hook({ 13 | name: "server-hook", 14 | debug: "true", 15 | hooks: [ 16 | { 17 | name: "client-hook", 18 | type: "helloworld", 19 | debug: "true" 20 | } 21 | ] 22 | }); 23 | 24 | hook1.on('hook::ready', function() { 25 | 26 | var counter = 0; 27 | hook1.on('*::hello', function(){ 28 | console.log('got hello'); 29 | counter++; 30 | if (counter >= 3) { 31 | hook1.kill('client-hook', function(err){ 32 | 33 | if (err) { 34 | console.log(err); 35 | } 36 | setTimeout(function(){ 37 | hook1.start(); 38 | }, 5000); 39 | }); 40 | } 41 | }); 42 | 43 | }); 44 | 45 | hook1.start(); 46 | 47 | -------------------------------------------------------------------------------- /vendor/dnode/test/single.js: -------------------------------------------------------------------------------- 1 | var dnode = require('../') 2 | var test = require('tap').test; 3 | 4 | test('simple', function (t) { 5 | t.plan(3); 6 | var port = Math.floor(Math.random() * 40000 + 10000); 7 | 8 | var server = dnode({ 9 | timesTen : function (n,reply) { 10 | t.equal(n.number, 5); 11 | reply(n.number * 10); 12 | }, 13 | print : function (n,reply) { 14 | reply(sys.inspect(n)); 15 | }, 16 | }).listen(port); 17 | 18 | server.on('ready', function () { 19 | dnode.connect(port, function (remote, conn) { 20 | t.equal(conn.stream.remoteAddress, '127.0.0.1'); 21 | var args = { 22 | number : 5, 23 | func : function () {}, 24 | }; 25 | 26 | remote.timesTen(args, function (m) { 27 | t.equal(m, 50, '5 * 10 == 50'); 28 | conn.end(); 29 | server.close(); 30 | t.end(); 31 | }); 32 | }); 33 | }); 34 | }); 35 | -------------------------------------------------------------------------------- /vendor/dnode/test/circular.js: -------------------------------------------------------------------------------- 1 | var dnode = require('../'); 2 | var test = require('tap').test; 3 | 4 | test('circular refs', function (t) { 5 | t.plan(7); 6 | var port = Math.floor(Math.random() * 40000 + 10000); 7 | 8 | var server = dnode({ 9 | sendObj : function (ref, f) { 10 | t.equal(ref.a, 1); 11 | t.equal(ref.b, 2); 12 | t.deepEqual(ref.c, ref); 13 | 14 | ref.d = ref.c; 15 | 16 | f(ref); 17 | }, 18 | }).listen(port); 19 | 20 | server.on('ready', function () { 21 | dnode.connect(port, function (remote, conn) { 22 | var obj = { a : 1, b : 2 }; 23 | obj.c = obj; 24 | 25 | remote.sendObj(obj, function (ref) { 26 | t.equal(ref.a, 1); 27 | t.equal(ref.b, 2); 28 | t.deepEqual(ref.c, ref); 29 | t.deepEqual(ref.d, ref); 30 | conn.end(); 31 | server.close(); 32 | t.end(); 33 | }); 34 | }); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /examples/messaging/siblings/hook-multiple-messages.js: -------------------------------------------------------------------------------- 1 | var Hook = require('../../../lib/hookio').Hook; 2 | 3 | var parent = new Hook({ 4 | name: 'parent', 5 | }); 6 | 7 | var sender = new Hook({ 8 | name: 'sender', 9 | }); 10 | 11 | var receiver = new Hook({ 12 | name: 'receiver', 13 | }); 14 | 15 | parent.on("hook::ready", function () { 16 | console.log("parent hook ready."); 17 | sender.start(); 18 | 19 | sender.on("hook::ready", function () { 20 | console.log("sending hook ready."); 21 | receiver.start(); 22 | 23 | receiver.on("hook::ready", function () { 24 | console.log("receiver hook ready."); 25 | 26 | // This example breaks unless this section is un-commented. 27 | //receiver.on("*::ping", function (data) { 28 | // console.log("*::ping", this.event); 29 | //}); 30 | 31 | receiver.on("sender::*", function (data) { 32 | console.log("sender::*", this.event); 33 | }); 34 | 35 | //emit from sender 36 | setInterval(function () { 37 | sender.emit('ping'); 38 | }, 500); 39 | }); 40 | }); 41 | }); 42 | 43 | parent.start(); 44 | -------------------------------------------------------------------------------- /examples/messaging/siblings/hook-emit-sibling-onany.js: -------------------------------------------------------------------------------- 1 | var Hook = require('../../../lib/hookio').Hook; 2 | 3 | var parent = new Hook({ 4 | name: 'parent', 5 | }); 6 | 7 | var sender = new Hook({ 8 | name: 'sender', 9 | }); 10 | 11 | var receiver = new Hook({ 12 | name: 'receiver', 13 | }); 14 | 15 | parent.on("hook::ready", function () { 16 | console.log("parent hook ready."); 17 | sender.start(); 18 | 19 | sender.on("hook::ready", function () { 20 | console.log("sending hook ready."); 21 | receiver.start(); 22 | 23 | receiver.on("hook::ready", function () { 24 | console.log("receiver hook ready."); 25 | 26 | // This example breaks unless this section is un-commented. 27 | //receiver.on("*::ping", function (data) { 28 | // console.log("*::ping", this.event); 29 | //}); 30 | 31 | receiver.onAny(function (data) { 32 | console.log(this.event, data); 33 | }); 34 | 35 | //emit from sender 36 | setInterval(function () { 37 | sender.emit('ping', { "foo": "bar" }); 38 | }, 500); 39 | }); 40 | }); 41 | }); 42 | 43 | parent.start(); 44 | -------------------------------------------------------------------------------- /lib/hookio/scaffold/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Marak Squires 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /lib/hookio/cli.js: -------------------------------------------------------------------------------- 1 | /* 2 | * cli.js: Wrapper tools for `optimist` in hookio so children do not need this dependency. 3 | * 4 | * (C) 2011 Nodejitsu Inc. 5 | * MIT LICENCE 6 | * 7 | */ 8 | 9 | var optimist = require('optimist'); 10 | 11 | var defaultOptions = { 12 | debug: { 13 | description: 'Indicates if this hook process will be debugged', 14 | boolean: true, 15 | default: false 16 | }, 17 | 'hook-port': { 18 | description: 'Port that the hook process should listen on', 19 | number: true, 20 | default: 5000 21 | }, 22 | 'hook-host': { 23 | description: 'Host that the hook process should listen on', 24 | string: true, 25 | default: '127.0.0.1' 26 | }, 27 | 'hook-socket': { 28 | description: 'Socket path that the hook process should listen on', 29 | default: null 30 | } 31 | }; 32 | 33 | exports.options = function (options, argv) { 34 | var parsed = argv ? optimist(argv) : optimist; 35 | return parsed.options(defaultOptions).options(options); 36 | }; 37 | 38 | Object.defineProperty(exports, 'argv', { 39 | get: function () { 40 | return optimist.options(defaultOptions).argv; 41 | } 42 | }); -------------------------------------------------------------------------------- /test/messaging/local/emit-test.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'), 2 | vows = require('vows'), 3 | Hook = require('../../../lib/hookio').Hook, 4 | macros = require('../../helpers/macros'); 5 | 6 | var testData = macros.testData; 7 | 8 | vows.describe('hook.io/messaging/local/emit-test').addBatch({ 9 | 'When a hook is started on port 5100': macros.assertReady('test-hook', 5100, { 10 | 'and it emits a test event': { 11 | 'with data': { 12 | topic: function (hook) { 13 | hook.once('testEvent', this.callback.bind(hook, null)); 14 | hook.emit('testEvent', testData); 15 | }, 16 | 'event hook should ba called with correct data': function (data) { 17 | assert.deepEqual(data, testData); 18 | } 19 | }, 20 | 'without data': { 21 | topic: function (hook) { 22 | hook.once('testEvent', this.callback.bind(hook, null)); 23 | hook.emit('testEvent'); 24 | }, 25 | 'event hook should be called without any data': function (data) { 26 | assert.isUndefined(data); 27 | } 28 | } 29 | } 30 | }) 31 | }).export(module); 32 | 33 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/jsonify/README.markdown: -------------------------------------------------------------------------------- 1 | jsonify 2 | ======= 3 | 4 | This module provides Douglas Crockford's JSON implementation without modifying 5 | any globals. 6 | 7 | `stringify` and `parse` are merely exported without respect to whether or not a 8 | global `JSON` object exists. 9 | 10 | methods 11 | ======= 12 | 13 | var json = require('jsonify'); 14 | 15 | json.parse(source, reviver) 16 | --------------------------- 17 | 18 | Return a new javascript object from a parse of the `source` string. 19 | 20 | If a `reviver` function is specified, walk the structure passing each name/value 21 | pair to `reviver.call(parent, key, value)` to transform the `value` before 22 | parsing it. 23 | 24 | json.stringify(value, replacer, space) 25 | -------------------------------------- 26 | 27 | Return a string representation for `value`. 28 | 29 | If `replacer` is specified, walk the structure passing each name/value pair to 30 | `replacer.call(parent, key, value)` to transform the `value` before stringifying 31 | it. 32 | 33 | If `space` is a number, indent the result by that many spaces. 34 | If `space` is a string, use `space` as the indentation. 35 | -------------------------------------------------------------------------------- /vendor/dnode/test/self-referential.js: -------------------------------------------------------------------------------- 1 | var dnode = require('../') 2 | var test = require('tap').test; 3 | 4 | test('simple', function (t) { 5 | t.plan(6); 6 | var port = Math.floor(Math.random() * 40000 + 10000); 7 | 8 | var server = dnode({ 9 | timesTen : function (n,reply) { 10 | t.equal(n.number, 5); 11 | reply(n.number * 10); 12 | }, 13 | print : function (n,reply) { 14 | t.strictEqual(n[0],1); 15 | t.strictEqual(n[1],2); 16 | t.strictEqual(n[2],3); 17 | t.strictEqual(n[3],n); 18 | reply(n); 19 | }, 20 | }).listen(port); 21 | 22 | server.on('ready', function () { 23 | dnode.connect(port, function (remote, conn) { 24 | t.equal(conn.stream.remoteAddress, '127.0.0.1'); 25 | var args = [1,2,3] 26 | args.push(args) 27 | 28 | remote.print(args, function (m) { 29 | t.deepEqual(m, args); 30 | 31 | conn.end(); 32 | server.close(); 33 | t.end(); 34 | }); 35 | }); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /lib/hookio/eventMap.js: -------------------------------------------------------------------------------- 1 | module['exports'] = { 2 | "*::getEvents": function(cb) { 3 | cb(null, this.getEvents()); 4 | }, 5 | "*::query": function (hook, cb) { 6 | this.query(hook, cb); 7 | }, 8 | "*::spawn": function (options, cb) { 9 | this.spawn(options, cb); 10 | }, 11 | "*::install": function (hook, callback) { 12 | var self = this; 13 | self.emit('npm::installing', hook); 14 | self.npm.install(hook, function (err, result) { 15 | if (err) { 16 | return self.emit('npm::install::error', err); 17 | } 18 | self.emit('npm::installed', result); 19 | }); 20 | }, 21 | "connection::end": function (data) { 22 | var self = this; 23 | if(data.proposedRank >= self.proposedRank) { 24 | self.proposedRank = self.proposedRank - 1; 25 | self.emit('hook::rank::accepting', self.proposedRank); 26 | } 27 | }, 28 | "hook::disconnected": function (data) { 29 | var self = this; 30 | self.clientCount = self.clientCount - 1; 31 | if(data.proposedRank >= self.proposedRank) { 32 | //self.proposedRank = self.proposedRank - 1; 33 | //console.log('my new proposedRank is ', self.proposedRank); 34 | } 35 | }, 36 | }; -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/test/stop.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var traverse = require('../'); 3 | 4 | exports.stop = function () { 5 | var visits = 0; 6 | traverse('abcdefghij'.split('')).forEach(function (node) { 7 | if (typeof node === 'string') { 8 | visits ++; 9 | if (node === 'e') this.stop() 10 | } 11 | }); 12 | 13 | assert.equal(visits, 5); 14 | }; 15 | 16 | exports.stopMap = function () { 17 | var s = traverse('abcdefghij'.split('')).map(function (node) { 18 | if (typeof node === 'string') { 19 | if (node === 'e') this.stop() 20 | return node.toUpperCase(); 21 | } 22 | }).join(''); 23 | 24 | assert.equal(s, 'ABCDEfghij'); 25 | }; 26 | 27 | exports.stopReduce = function () { 28 | var obj = { 29 | a : [ 4, 5 ], 30 | b : [ 6, [ 7, 8, 9 ] ] 31 | }; 32 | var xs = traverse(obj).reduce(function (acc, node) { 33 | if (this.isLeaf) { 34 | if (node === 7) this.stop(); 35 | else acc.push(node) 36 | } 37 | return acc; 38 | }, []); 39 | 40 | assert.deepEqual(xs, [ 4, 5, 6 ]); 41 | }; 42 | -------------------------------------------------------------------------------- /vendor/dnode/test/obj.js: -------------------------------------------------------------------------------- 1 | var dnode = require('../'); 2 | var test = require('tap').test; 3 | 4 | test('object ref tests', function (t) { 5 | t.plan(8); 6 | var port = Math.floor(Math.random() * 40000 + 10000); 7 | 8 | var obj = { a : 1, b : 2, f : function (n,g) { g(n * 20) } }; 9 | 10 | var server = dnode({ 11 | getObject : function (f) { f(obj) }, 12 | }).listen(port); 13 | 14 | server.on('ready', function () { 15 | dnode.connect(port, function (remote, conn) { 16 | remote.getObject(function (rObj) { 17 | t.equal(rObj.a, 1); 18 | t.equal(rObj.b, 2); 19 | t.equal(typeof rObj.f, 'function'); 20 | rObj.a += 100; rObj.b += 100; 21 | t.equal(obj.a, 1); 22 | t.equal(obj.b, 2); 23 | t.notEqual(obj.f, rObj.g); 24 | t.equal(typeof obj.f, 'function'); 25 | rObj.f(13, function (res) { 26 | t.equal(res, 260); 27 | conn.end(); 28 | server.close(); 29 | t.end(); 30 | }); 31 | }); 32 | }); 33 | }); 34 | }); 35 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/test/super_deep.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var traverse = require('../'); 3 | var deepEqual = require('./lib/deep_equal'); 4 | 5 | exports.super_deep = function () { 6 | var util = require('util'); 7 | var a0 = make(); 8 | var a1 = make(); 9 | assert.ok(deepEqual(a0, a1)); 10 | 11 | a0.c.d.moo = true; 12 | assert.ok(!deepEqual(a0, a1)); 13 | 14 | a1.c.d.moo = true; 15 | assert.ok(deepEqual(a0, a1)); 16 | 17 | // TODO: this one 18 | //a0.c.a = a1; 19 | //assert.ok(!deepEqual(a0, a1)); 20 | }; 21 | 22 | function make () { 23 | var a = { self : 'a' }; 24 | var b = { self : 'b' }; 25 | var c = { self : 'c' }; 26 | var d = { self : 'd' }; 27 | var e = { self : 'e' }; 28 | 29 | a.a = a; 30 | a.b = b; 31 | a.c = c; 32 | 33 | b.a = a; 34 | b.b = b; 35 | b.c = c; 36 | 37 | c.a = a; 38 | c.b = b; 39 | c.c = c; 40 | c.d = d; 41 | 42 | d.a = a; 43 | d.b = b; 44 | d.c = c; 45 | d.d = d; 46 | d.e = e; 47 | 48 | e.a = a; 49 | e.b = b; 50 | e.c = c; 51 | e.d = d; 52 | e.e = e; 53 | 54 | return a; 55 | } 56 | -------------------------------------------------------------------------------- /test/siblings/ping-pong-test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * test-sibling-callresponse.js: Tests the ability to do a call and response to a sibling 3 | * this input will wait for a sibling to send it a message 4 | * and then respond back. 5 | * 6 | * (C) 2011 Marak Squires, Charlie Robbins 7 | * MIT LICENCE 8 | * 9 | */ 10 | 11 | var vows = require('vows'), 12 | assert = require('assert'), 13 | Hook = require('../../lib/hookio').Hook, 14 | macros = require('../helpers/macros'); 15 | 16 | vows.describe('hook.io/siblings/call-response').addBatch({ 17 | "A single-level event ping/pong": macros.assertPingPong(5001, 18 | { 19 | name: 'ping', 20 | event: 'ping', 21 | value: 'ping', 22 | }, 23 | { 24 | name: 'pong', 25 | event: 'pong', 26 | value: 'pong', 27 | } 28 | ), 29 | "A mulit-level event ping/pong": macros.assertPingPong(5004, 30 | { 31 | name: 'ping-multilevel', 32 | event: 'ping::multilevel', 33 | value: 'ping::multilevel', 34 | }, 35 | { 36 | name: 'pong-multilevel', 37 | event: 'pong::multilevel', 38 | value: 'pong::multilevel', 39 | } 40 | ) 41 | }).export(module); -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/test/stringify.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var Traverse = require('../'); 3 | 4 | exports.stringify = function () { 5 | var obj = [ 5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ]; 6 | 7 | var s = ''; 8 | Traverse(obj).forEach(function (node) { 9 | if (Array.isArray(node)) { 10 | this.before(function () { s += '[' }); 11 | this.post(function (child) { 12 | if (!child.isLast) s += ','; 13 | }); 14 | this.after(function () { s += ']' }); 15 | } 16 | else if (typeof node == 'object') { 17 | this.before(function () { s += '{' }); 18 | this.pre(function (x, key) { 19 | s += '"' + key + '"' + ':'; 20 | }); 21 | this.post(function (child) { 22 | if (!child.isLast) s += ','; 23 | }); 24 | this.after(function () { s += '}' }); 25 | } 26 | else if (typeof node == 'function') { 27 | s += 'null'; 28 | } 29 | else { 30 | s += node.toString(); 31 | } 32 | }); 33 | 34 | assert.equal(s, JSON.stringify(obj)); 35 | } 36 | 37 | -------------------------------------------------------------------------------- /examples/transports/couchdb-event-transport.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Creates a hook and spawns a helloworld child both with an additional CouchDB transport 3 | */ 4 | 5 | var Hook = require('../../lib/hookio').Hook; 6 | 7 | 8 | var myHook = new Hook({ 9 | name: "event-transport-hook", 10 | debug: true, 11 | transports: [ 12 | { 13 | "type" : "couchdb", 14 | "options": { 15 | "host": "localhost", 16 | "port": 5984, 17 | "db": "mydatabase" 18 | } 19 | } 20 | ] 21 | }); 22 | 23 | myHook.on('hook::ready', function () { 24 | 25 | myHook.spawn([{ 26 | name: "event-transport-hook-child", 27 | type: "helloworld", 28 | debug: true, 29 | transports: [ 30 | { 31 | "type" : "couchdb", 32 | "options": { 33 | "host": "localhost", 34 | "port": 5984, 35 | "db": "mydatabase" 36 | } 37 | } 38 | ] 39 | }]); 40 | 41 | myHook.on('children::ready', function () { 42 | 43 | // 44 | // Remark: Since we have set couch as an transport, 45 | // the event will be copied and also sent to CouchDB 46 | // 47 | myHook.emit('someevent', { "foo": "bar" }); 48 | 49 | }); 50 | 51 | }); 52 | 53 | myHook.start(); 54 | -------------------------------------------------------------------------------- /examples/messaging/local/hook-callback.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Creates a helloworld hook, then spawns three helloworld children 3 | */ 4 | 5 | var Hook = require('../../../lib/hookio').Hook; 6 | 7 | var hook1 = new Hook({ 8 | name: "server-hook", 9 | debug: true 10 | }); 11 | 12 | hook1.on('hello', function (data, callback) { 13 | // 14 | // callback is the callback for this event, 15 | // should it exist 16 | // 17 | var result = { 18 | "text": "Why hello there!" 19 | }; 20 | 21 | callback(null, result); 22 | 23 | }) 24 | 25 | hook1.on('hook::ready', function () { 26 | 27 | 28 | // 29 | // Event with data 30 | // event, data, callback 31 | // 32 | hook1.emit('hello', 'data1', function (err, data) { 33 | console.log('callback1 ', err, data); 34 | }); 35 | 36 | // 37 | // Event with data 38 | // event, data, callback 39 | // 40 | hook1.emit('hello', {"foo":"bar"}, function (err, data) { 41 | console.log('callback2 ', err, data); 42 | }); 43 | 44 | // 45 | // Event with no data 46 | // event, callback 47 | // 48 | hook1.emit('hello', function (err, data) { 49 | console.log('callback3 ', err, data); 50 | }); 51 | 52 | 53 | }); 54 | 55 | hook1.start(); -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/test/interface.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var Traverse = require('../'); 3 | 4 | exports['interface map'] = function () { 5 | var obj = { a : [ 5,6,7 ], b : { c : [8] } }; 6 | 7 | assert.deepEqual( 8 | Traverse.paths(obj) 9 | .sort() 10 | .map(function (path) { return path.join('/') }) 11 | .slice(1) 12 | .join(' ') 13 | , 14 | 'a a/0 a/1 a/2 b b/c b/c/0' 15 | ); 16 | 17 | assert.deepEqual( 18 | Traverse.nodes(obj), 19 | [ 20 | { a: [ 5, 6, 7 ], b: { c: [ 8 ] } }, 21 | [ 5, 6, 7 ], 5, 6, 7, 22 | { c: [ 8 ] }, [ 8 ], 8 23 | ] 24 | ); 25 | 26 | assert.deepEqual( 27 | Traverse.map(obj, function (node) { 28 | if (typeof node == 'number') { 29 | return node + 1000; 30 | } 31 | else if (Array.isArray(node)) { 32 | return node.join(' '); 33 | } 34 | }), 35 | { a: '5 6 7', b: { c: '8' } } 36 | ); 37 | 38 | var nodes = 0; 39 | Traverse.forEach(obj, function (node) { nodes ++ }); 40 | assert.deepEqual(nodes, 8); 41 | }; 42 | 43 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/examples/stringify.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | var traverse = require('traverse'); 3 | 4 | var obj = [ 'five', 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ]; 5 | 6 | var s = ''; 7 | traverse(obj).forEach(function to_s (node) { 8 | if (Array.isArray(node)) { 9 | this.before(function () { s += '[' }); 10 | this.post(function (child) { 11 | if (!child.isLast) s += ','; 12 | }); 13 | this.after(function () { s += ']' }); 14 | } 15 | else if (typeof node == 'object') { 16 | this.before(function () { s += '{' }); 17 | this.pre(function (x, key) { 18 | to_s(key); 19 | s += ':'; 20 | }); 21 | this.post(function (child) { 22 | if (!child.isLast) s += ','; 23 | }); 24 | this.after(function () { s += '}' }); 25 | } 26 | else if (typeof node == 'string') { 27 | s += '"' + node.toString().replace(/"/g, '\\"') + '"'; 28 | } 29 | else if (typeof node == 'function') { 30 | s += 'null'; 31 | } 32 | else { 33 | s += node.toString(); 34 | } 35 | }); 36 | 37 | console.log('JSON.stringify: ' + JSON.stringify(obj)); 38 | console.log('this stringify: ' + s); 39 | -------------------------------------------------------------------------------- /vendor/dnode/test/double.js: -------------------------------------------------------------------------------- 1 | var dnode = require('../'); 2 | var test = require('tap').test; 3 | 4 | test('double', function (t) { 5 | t.plan(4); 6 | var port = Math.floor(Math.random() * 40000 + 10000); 7 | 8 | var server = dnode({ 9 | z : function (f, g, h) { 10 | f(10, function (x) { 11 | g(10, function (y) { 12 | h(x,y) 13 | }) 14 | }) 15 | } 16 | }).listen(port); 17 | 18 | server.on('ready', function () { 19 | dnode.connect(port, function (remote, conn) { 20 | remote.z( 21 | function (x,f) { f(x * 2) }, 22 | function (x,f) { f(x / 2) }, 23 | function (x,y) { 24 | t.equal(x, 20, 'double, not equal'); 25 | t.equal(y, 5, 'double, not equal'); 26 | } 27 | ); 28 | 29 | function plusTen(n,f) { f(n + 10) } 30 | 31 | remote.z(plusTen, plusTen, function (x,y) { 32 | t.equal(x, 20, 'double, equal'); 33 | t.equal(y, 20, 'double, equal'); 34 | conn.end(); 35 | server.close(); 36 | t.end(); 37 | }); 38 | }); 39 | }); 40 | }); 41 | -------------------------------------------------------------------------------- /examples/messaging/remote/hook-callback-child.js: -------------------------------------------------------------------------------- 1 | var Hook = require('../../../lib/hookio').Hook; 2 | 3 | 4 | var hook1 = new Hook({ 5 | name: "a", 6 | debug: true 7 | }); 8 | 9 | var hook2 = new Hook({ 10 | name: "b", 11 | debug: true 12 | }); 13 | 14 | 15 | hook1.on('*::hello', function (data, callback) { 16 | 17 | // 18 | // callback is the callback for this event, 19 | // should it exist 20 | // 21 | var result = { 22 | "text": "Why hello there!" 23 | }; 24 | 25 | callback(null, result); 26 | 27 | }) 28 | 29 | hook1.on('hook::ready', function () { 30 | 31 | hook2.start(); 32 | 33 | hook2.on('hook::ready', function () { 34 | 35 | // 36 | // Event with data 37 | // event, data, callback 38 | // 39 | hook2.emit('hello', 'data1', function (err, data) { 40 | console.log('callback1 ', err, data); 41 | }); 42 | 43 | // 44 | // Event with data 45 | // event, data, callback 46 | // 47 | hook2.emit('hello', {"foo":"bar"}, function (err, data) { 48 | console.log('callback2 ', err, data); 49 | }); 50 | 51 | // 52 | // Event with no data 53 | // event, callback 54 | // 55 | hook2.emit('hello', function (err, data) { 56 | console.log('callback3 ', err, data); 57 | }); 58 | 59 | }); 60 | 61 | }); 62 | 63 | hook1.start(); -------------------------------------------------------------------------------- /examples/messaging/remote/hook-callback-parent-hookname.js: -------------------------------------------------------------------------------- 1 | var Hook = require('../../../lib/hookio').Hook; 2 | 3 | 4 | var hook1 = new Hook({ 5 | name: "a", 6 | debug: true 7 | }); 8 | 9 | var hook2 = new Hook({ 10 | name: "b", 11 | debug: true 12 | }); 13 | 14 | 15 | hook2.on('a::*', function (data, callback) { 16 | 17 | // 18 | // callback is the callback for this event, 19 | // should it exist 20 | // 21 | var result = { 22 | "text": "Why hello there!" 23 | }; 24 | 25 | callback(null, result); 26 | 27 | }); 28 | 29 | hook1.on('hook::ready', function () { 30 | 31 | hook2.start(); 32 | 33 | hook2.on('hook::ready', function () { 34 | 35 | // 36 | // Event with data 37 | // event, data, callback 38 | // 39 | hook1.emit('hello', 'data1', function (err, data) { 40 | console.log('callback1 ', err, data); 41 | }); 42 | 43 | // 44 | // Event with data 45 | // event, data, callback 46 | // 47 | hook1.emit('hello', {"foo":"bar"}, function (err, data) { 48 | console.log('callback2 ', err, data); 49 | }); 50 | 51 | // 52 | // Event with no data 53 | // event, callback 54 | // 55 | hook1.emit('hello', function (err, data) { 56 | console.log('callback3 ', err, data); 57 | }); 58 | 59 | }); 60 | 61 | }); 62 | 63 | hook1.start(); 64 | -------------------------------------------------------------------------------- /examples/messaging/remote/hook-callback-child-hookname.js: -------------------------------------------------------------------------------- 1 | 2 | var Hook = require('../../../lib/hookio').Hook; 3 | 4 | 5 | var hook1 = new Hook({ 6 | name: "a", 7 | debug: true 8 | }); 9 | 10 | var hook2 = new Hook({ 11 | name: "b", 12 | debug: true 13 | }); 14 | 15 | 16 | hook1.on('b::*', function (data, callback) { 17 | 18 | // 19 | // callback is the callback for this event, 20 | // should it exist 21 | // 22 | var result = { 23 | "text": "Why hello there!" 24 | }; 25 | 26 | callback(null, result); 27 | 28 | }); 29 | 30 | hook1.on('hook::ready', function () { 31 | 32 | hook2.start(); 33 | 34 | hook2.on('hook::ready', function () { 35 | 36 | // 37 | // Event with data 38 | // event, data, callback 39 | // 40 | hook2.emit('hello', 'data1', function (err, data) { 41 | console.log('callback1 ', err, data); 42 | }); 43 | 44 | // 45 | // Event with data 46 | // event, data, callback 47 | // 48 | hook2.emit('hello', {"foo":"bar"}, function (err, data) { 49 | console.log('callback2 ', err, data); 50 | }); 51 | 52 | // 53 | // Event with no data 54 | // event, callback 55 | // 56 | hook2.emit('hello', function (err, data) { 57 | console.log('callback3 ', err, data); 58 | }); 59 | 60 | }); 61 | 62 | }); 63 | 64 | hook1.start(); 65 | -------------------------------------------------------------------------------- /test/messaging/local/callback-test.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'), 2 | vows = require('vows'), 3 | Hook = require('../../../lib/hookio').Hook; 4 | 5 | var testData = require('../../helpers/macros').testData; 6 | 7 | vows.describe('hook.io/messaging/local/callback-test').addBatch({ 8 | 'When a hook is listening on 5060': { 9 | topic: function () { 10 | var hook = new Hook({ name: 'hook', debug: true }); 11 | hook.on('hook::ready', this.callback.bind(hook, null, hook)); 12 | 13 | hook.on('callbackTestEvent', function (data, callback) { 14 | callback(null, data); 15 | }); 16 | 17 | hook.start({ 'hook-port': 5060 }); 18 | }, 19 | 'and it emits a test event': { 20 | 'with data': { 21 | topic: function (hook) { 22 | hook.emit('callbackTestEvent', testData, this.callback); 23 | }, 24 | 'he should receive a callback with correct data': function (data) { 25 | assert.deepEqual(data, testData); 26 | } 27 | }, 28 | 'without any data': { 29 | topic: function (hook) { 30 | hook.emit('callbackTestEvent', this.callback); 31 | }, 32 | 'he should receive a callback without any data': function (data) { 33 | assert.isNull(data); 34 | } 35 | } 36 | } 37 | } 38 | }).export(module); 39 | 40 | -------------------------------------------------------------------------------- /vendor/EventEmitter2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eventemitter2", 3 | "version": "0.4.2", 4 | "description": "A Node.js event emitter implementation with namespaces, wildcards, TTL and browser support.", 5 | "keywords": ["event", "events", "emitter", "eventemitter"], 6 | "author": "hij1nx http://twitter.com/hij1nx", 7 | "maintainers": [ 8 | "hij1nx ", 9 | "jameson " 10 | ], 11 | "contributors": [ 12 | "Charlie Robbins http://twitter.com/indexzero", 13 | "Jameson Lee http://twitter.com/Jamesonjlee", 14 | "Jeroen van Duffelen http://www.twitter.com/jvduf", 15 | "Fedor Indutny http://www.twitter.com/indutny" 16 | ], 17 | "licenses": [{"type": "MIT"}], 18 | "homepage": "https://github.com/hij1nx/EventEmitter2", 19 | "repositories": [{ 20 | "type": "git", 21 | "url": "git://github.com/hij1nx/EventEmitter2.git" 22 | }], 23 | "devDependencies": { 24 | "nodeunit": "*", 25 | "benchmark" : ">= 0.2.2" 26 | }, 27 | "engines": ["node"], 28 | "main": "./lib/eventemitter2.js", 29 | "scripts" : { 30 | "test" : "nodeunit test/simple/* && nodeunit test/wildcardEvents/*", 31 | "benchmark" : "node test/perf/benchmark.js" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /vendor/dnode/examples/chat/chat.css: -------------------------------------------------------------------------------- 1 | div#prompt { 2 | width: 600px; 3 | height: 400px; 4 | margin: auto; 5 | display: table-cell; 6 | vertical-align: middle; 7 | text-align: center; 8 | background-color: rgb(30,30,30); 9 | color: white; 10 | } 11 | 12 | div#chat { 13 | width: 600px; 14 | margin: auto; 15 | } 16 | 17 | div#messages { 18 | display: none; 19 | overflow-x: hidden; 20 | overflow-y: scroll; 21 | padding: 0.5em; 22 | width: 600px; 23 | height: 400px; 24 | border-color: black; 25 | border-style: solid; 26 | border-width: 2px; 27 | background-color: rgb(30,30,30); 28 | } 29 | 30 | form#post input { 31 | width: 600px; 32 | padding: 0.5em; 33 | background-color: black; 34 | color: white; 35 | border-width: 0px; 36 | } 37 | 38 | span.who { 39 | font-weight: bold; 40 | margin-right: 1em; 41 | color: rgb(200,200,200); 42 | } 43 | 44 | span.me { 45 | font-weight: bold; 46 | margin-right: 1em; 47 | color: white; 48 | } 49 | 50 | span.msg { 51 | color: white; 52 | } 53 | 54 | div.join { 55 | color: rgb(200,250,150); 56 | font-weight: bold; 57 | } 58 | 59 | div.part { 60 | color: rgb(250,200,150); 61 | font-weight: bold; 62 | } 63 | 64 | div.users { 65 | color: rgb(150,200,250); 66 | font-weight: bold; 67 | } 68 | -------------------------------------------------------------------------------- /vendor/dnode/test/recon.js: -------------------------------------------------------------------------------- 1 | var dnode = require('../'); 2 | var test = require('tap').test; 3 | 4 | test('recon', function (t) { 5 | t.plan(4); 6 | var port = Math.floor(Math.random() * 40000 + 10000); 7 | 8 | var scounts = { connect : 0, ready : 0 }; 9 | var ccounts = { connect : 0, ready : 0 }; 10 | 11 | var server = dnode(function (remote, conn) { 12 | scounts.connect ++; 13 | conn.on('ready', function () { 14 | scounts.ready ++; 15 | }); 16 | }).listen(port); 17 | 18 | dnode(function (remote, conn) { 19 | ccounts.connect ++; 20 | conn.on('ready', function () { 21 | ccounts.ready ++; 22 | setTimeout(function () { 23 | if (ccounts.ready >= 4) { 24 | conn.end(); 25 | } 26 | else { 27 | conn.stream.end(); 28 | } 29 | }, 25); 30 | }); 31 | 32 | }).connect(port, { reconnect : 100 }); 33 | 34 | setTimeout(function () { 35 | t.ok(scounts.connect >= 2); 36 | t.ok(scounts.ready >= 2); 37 | 38 | t.equal(ccounts.connect, scounts.connect); 39 | t.equal(ccounts.ready, scounts.ready); 40 | 41 | server.close(); 42 | t.end(); 43 | }, 1000); 44 | }); 45 | -------------------------------------------------------------------------------- /test/messaging/remote/emit-child-test.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'), 2 | vows = require('vows'), 3 | Hook = require('../../../lib/hookio').Hook, 4 | macros = require('../../helpers/macros'); 5 | 6 | var testData = macros.testData; 7 | 8 | vows.describe('hook.io/messaging/remote/emit-child').addBatch({ 9 | 'When a hook is listening on 5110': macros.assertListen('server-hook', 5110, { 10 | 'and another hook connects': macros.assertConnect('client-hook', 5110, { 11 | 'and emits a test event': { 12 | 'with data': { 13 | topic: function (client, _, _, server) { 14 | server.once('*::testEventWithData', this.callback.bind(server, null)); 15 | client.emit('testEventWithData', testData); 16 | }, 17 | 'test event should be fired correctly': function (data) { 18 | assert.deepEqual(data, testData); 19 | } 20 | }, 21 | 'without data': { 22 | topic: function (client, _, _, server) { 23 | server.once('*::testEventWithoutData', this.callback.bind(server, null)); 24 | client.emit('testEventWithoutData'); 25 | }, 26 | 'test event should be fired correctly': function (data) { 27 | assert.isNull(data); 28 | } 29 | } 30 | } 31 | }) 32 | }) 33 | }).export(module); 34 | 35 | -------------------------------------------------------------------------------- /vendor/dnode/test/simple.js: -------------------------------------------------------------------------------- 1 | var dnode = require('../'); 2 | var test = require('tap').test; 3 | 4 | test('simple', function (t) { 5 | t.plan(7); 6 | var port = Math.floor(Math.random() * 40000 + 10000); 7 | 8 | var server = dnode({ 9 | timesTen : function (n,reply) { 10 | t.equal(n, 50); 11 | reply(n * 10); 12 | }, 13 | moo : function (reply) { reply(100) }, 14 | sTimesTen : function (n, cb) { 15 | t.equal(n, 5); 16 | cb(n * 10); 17 | }, 18 | }).listen(port.toString()); // test for stringified ports too why not 19 | 20 | server.on('ready', function () { 21 | dnode.connect(port, function (remote, conn) { 22 | t.ok(conn.id); 23 | t.equal(conn.stream.remoteAddress, '127.0.0.1'); 24 | 25 | remote.moo(function (x) { 26 | t.equal(x, 100, 'remote moo == 100'); 27 | }); 28 | remote.sTimesTen(5, function (m) { 29 | t.equal(m, 50, '5 * 10 == 50'); 30 | remote.timesTen(m, function (n) { 31 | t.equal(n, 500, '50 * 10 == 500'); 32 | conn.end(); 33 | server.close(); 34 | t.end(); 35 | }); 36 | }); 37 | }); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /test/messaging/remote/emit-parent-test.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'), 2 | vows = require('vows'), 3 | Hook = require('../../../lib/hookio').Hook, 4 | macros = require('../../helpers/macros'); 5 | 6 | var testData = macros.testData; 7 | 8 | vows.describe('hook.io/messaging/remote/emit-parent').addBatch({ 9 | 'When a hook is listening on 5120': macros.assertListen('server-hook', 5120, { 10 | 'and another hook connects': macros.assertConnect('client-hook', 5120, { 11 | 'and server emits a test event': { 12 | 'with data': { 13 | topic: function (client, _, _, server) { 14 | client.once('*::testEventWithData', this.callback.bind(server, null)); 15 | server.emit('testEventWithData', testData); 16 | }, 17 | 'test event should be fired correctly': function (data) { 18 | assert.deepEqual(data, testData); 19 | } 20 | }, 21 | 'without data': { 22 | topic: function (client, _, _, server) { 23 | client.once('*::testEventWithoutData', this.callback.bind(server, null)); 24 | server.emit('testEventWithoutData'); 25 | }, 26 | 'test event should be fired correctly': function (data) { 27 | assert.isNull(data); 28 | } 29 | } 30 | } 31 | }) 32 | }) 33 | }).export(module); 34 | 35 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2010 James Halliday (mail@substack.net) 2 | 3 | This project is free software released under the MIT/X11 license: 4 | http://www.opensource.org/licenses/mit-license.php 5 | 6 | Copyright 2010 James Halliday (mail@substack.net) 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/test/siblings.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var traverse = require('../'); 3 | 4 | exports.siblings = function () { 5 | var obj = { a : 1, b : 2, c : [ 4, 5, 6 ] }; 6 | 7 | var res = traverse(obj).reduce(function (acc, x) { 8 | var p = '/' + this.path.join('/'); 9 | if (this.parent) { 10 | acc[p] = { 11 | siblings : this.parent.keys, 12 | key : this.key, 13 | index : this.parent.keys.indexOf(this.key) 14 | }; 15 | } 16 | else { 17 | acc[p] = { 18 | siblings : [], 19 | key : this.key, 20 | index : -1 21 | } 22 | } 23 | return acc; 24 | }, {}); 25 | 26 | assert.deepEqual(res, { 27 | '/' : { siblings : [], key : undefined, index : -1 }, 28 | '/a' : { siblings : [ 'a', 'b', 'c' ], key : 'a', index : 0 }, 29 | '/b' : { siblings : [ 'a', 'b', 'c' ], key : 'b', index : 1 }, 30 | '/c' : { siblings : [ 'a', 'b', 'c' ], key : 'c', index : 2 }, 31 | '/c/0' : { siblings : [ '0', '1', '2' ], key : '0', index : 0 }, 32 | '/c/1' : { siblings : [ '0', '1', '2' ], key : '1', index : 1 }, 33 | '/c/2' : { siblings : [ '0', '1', '2' ], key : '2', index : 2 } 34 | }); 35 | }; 36 | -------------------------------------------------------------------------------- /vendor/dnode/test/bidirectional.js: -------------------------------------------------------------------------------- 1 | var dnode = require('../'); 2 | var test = require('tap').test; 3 | 4 | test('bidirectional', function (t) { 5 | t.plan(5); 6 | var port = Math.floor(Math.random() * 40000 + 10000); 7 | var counts = { timesX : 0, clientX : 0, x : 0 }; 8 | 9 | var server = dnode(function (client) { 10 | this.timesX = function (n,f) { 11 | t.equal(n, 3, "timesX's n == 3"); 12 | counts.timesX ++; 13 | client.x(function (x) { 14 | t.equal(x, 20, 'client.x == 20'); 15 | counts.clientX ++; 16 | f(n * x); 17 | }); 18 | }; 19 | }).listen(port); 20 | 21 | server.on('ready', function () { 22 | dnode({ 23 | x : function (f) { 24 | counts.x ++; 25 | f(20); 26 | } 27 | }).connect(port, function (remote, conn) { 28 | remote.timesX(3, function (res) { 29 | t.equal(res, 60, 'result of 20 * 3 == 60'); 30 | conn.end(); 31 | server.close(); 32 | }); 33 | }); 34 | }); 35 | 36 | server.once('close', function () { 37 | t.equal(counts.timesX, 1, 'timesX called once'); 38 | t.equal(counts.clientX, 1, 'clientX called once'); 39 | t.end(); 40 | }); 41 | }); 42 | -------------------------------------------------------------------------------- /vendor/dnode/test/null.js: -------------------------------------------------------------------------------- 1 | var dnode = require('../'); 2 | var test = require('tap').test; 3 | 4 | test('null', function (t) { 5 | t.plan(7); 6 | var port = Math.floor(Math.random() * 40000 + 10000); 7 | 8 | var server = dnode({ 9 | empty : null, 10 | timesTen : function (n, reply) { 11 | t.equal(n, 50); 12 | reply(n * 10); 13 | }, 14 | moo : function (reply) { reply(100) }, 15 | sTimesTen : function (n, cb) { 16 | t.equal(n, 5); 17 | cb(n * 10, null); 18 | }, 19 | }).listen(port.toString()); // test for stringified ports too why not 20 | 21 | server.on('ready', function () { 22 | dnode.connect(port, function (remote, conn) { 23 | t.ok(conn.id); 24 | t.equal(conn.stream.remoteAddress, '127.0.0.1'); 25 | 26 | remote.moo(function (x) { 27 | t.equal(x, 100, 'remote moo == 100'); 28 | }); 29 | remote.sTimesTen(5, function (m) { 30 | t.equal(m, 50, '5 * 10 == 50'); 31 | remote.timesTen(m, function (n) { 32 | t.equal(n, 500, '50 * 10 == 500'); 33 | conn.end(); 34 | server.close(); 35 | t.end(); 36 | }); 37 | }); 38 | }); 39 | }); 40 | }); 41 | -------------------------------------------------------------------------------- /vendor/dnode/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "dnode", 3 | "version" : "0.9.2", 4 | "description" : "freestyle RPC", 5 | "main" : "./index.js", 6 | "keywords" : [ 7 | "message passing", 8 | "rpc", 9 | "rmi", 10 | "drb", 11 | "remote", 12 | "communication", 13 | "websockets", 14 | "socket.io" 15 | ], 16 | "repository" : { 17 | "type" : "git", 18 | "url" : "http://github.com/substack/dnode.git" 19 | }, 20 | "directories" : { 21 | "lib" : ".", 22 | "examples" : "./examples" 23 | }, 24 | "dependencies" : { 25 | "socket.io" : "0.8.6", 26 | "socket.io-client" : "https://github.com/substack/socket.io-client/tarball/master", 27 | "lazy" : ">=1.0.5 <1.1", 28 | "weak": "*", 29 | "traverse" : "0.4.x", 30 | "dnode-protocol" : "0.1.x", 31 | "jsonify" : "0.0.x" 32 | }, 33 | "devDependencies" : { 34 | "tap" : "0.0.x", 35 | "browserify" : "1.4.x", 36 | "uglify-js" : "1.0.6" 37 | }, 38 | "scripts" : { 39 | "test" : "tap test/*.js" 40 | }, 41 | "browserify" : "browser/index.js", 42 | "engine" : { 43 | "node" : ">=0.4.0" 44 | }, 45 | "author" : { 46 | "name" : "James Halliday", 47 | "email" : "mail@substack.net", 48 | "url" : "http://substack.net" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /examples/query/hook-query.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Creates a hook, spawns up three custom hooks, then queries the hook cloud for information 3 | */ 4 | 5 | var Hook = require('../../lib/hookio').Hook; 6 | 7 | 8 | var hook1 = new Hook({ 9 | name: "server-hook" 10 | }); 11 | 12 | hook1.on('hook::ready', function () { 13 | 14 | hook1.on('children::ready', function () { 15 | 16 | // 17 | // Remark: Get all hooks of generic type "hook" with a callback 18 | // 19 | hook1.emit('query', { "type": "hook" }, function (err, result) { 20 | console.log('hook query result:'.green.bold.underline + ' ' + JSON.stringify(result, true, 2).grey); 21 | }); 22 | 23 | // 24 | // Remark: Get all hooks of generic type "hook" with an emitter 25 | // 26 | hook1.on('query::result', function (result) { 27 | console.log('hook query result:'.green.bold.underline + ' ' + JSON.stringify(result, true, 2).grey); 28 | }); 29 | 30 | hook1.emit('query', { "type":"hook" }); 31 | 32 | }); 33 | 34 | // 35 | // Remark: Spawn up three child hooks with custom options 36 | // 37 | 38 | hook1.spawn([ 39 | { 40 | type: 'hook', 41 | name: 'b', 42 | foo: "bar" 43 | }, 44 | { 45 | type: 'hook', 46 | name: 'c', 47 | beep: "boop" 48 | }, 49 | { 50 | type: 'hook', 51 | name: 'd' 52 | } 53 | ]); 54 | 55 | }); 56 | 57 | hook1.start(); 58 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/test/args.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var protocol = require('../'); 3 | 4 | function argv () { return arguments } 5 | 6 | exports.args = function () { 7 | assert.eql( 8 | protocol.parseArgs(argv('moo.com', 555)), 9 | { host : 'moo.com', port : 555 } 10 | ); 11 | 12 | assert.eql( 13 | protocol.parseArgs(argv('7777')), 14 | { port : 7777 } 15 | ); 16 | 17 | assert.eql( 18 | protocol.parseArgs(argv({ 19 | host : 'moosy.moo.com', 20 | port : 5050, 21 | })), 22 | { host : 'moosy.moo.com', port : 5050 } 23 | ); 24 | 25 | assert.eql( 26 | protocol.parseArgs(argv('meow.cats.com', { port : '1234', })), 27 | { host : 'meow.cats.com', port : 1234 } 28 | ); 29 | 30 | assert.eql( 31 | typeof protocol.parseArgs(argv('789')).port, 32 | 'number' 33 | ); 34 | 35 | assert.eql( 36 | protocol.parseArgs(argv( 37 | { host : 'woof.dogs.com' }, { port : 4050 } 38 | )), 39 | { host : 'woof.dogs.com', port : 4050 } 40 | ); 41 | 42 | assert.eql( 43 | protocol.parseArgs(argv( 44 | undefined, 45 | { host : 'woof.dogs.com' }, 46 | undefined, 47 | { port : 4050 }, 48 | undefined 49 | )), 50 | { host : 'woof.dogs.com', port : 4050 } 51 | ); 52 | }; 53 | -------------------------------------------------------------------------------- /test/siblings/message-test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * test-sibling-callresponse.js: Test the ability to start up an output hook that other hooks can connect to 3 | * this output will receive and rebroadcast messages to all its children 4 | * (which are siblings to each other). 5 | * 6 | * (C) 2011 Marak Squires, Charlie Robbins 7 | * MIT LICENCE 8 | * 9 | */ 10 | 11 | var vows = require('vows'), 12 | assert = require('assert'), 13 | Hook = require('../../lib/hookio').Hook, 14 | macros = require('../helpers/macros'); 15 | 16 | vows.describe('hook.io/siblings/message').addBatch({ 17 | "When a hook is listening on 5002": macros.assertListen('simple-server', 5002, { 18 | "and another hook connects": macros.assertConnect('simple-subscriber', 5002, { 19 | "and emits *::test": { 20 | topic: function (subscriber) { 21 | subscriber.once('*::test', this.callback.bind(subscriber, null)); 22 | 23 | var messager = new Hook({ name: 'simple-client-messager' }); 24 | messager.connect({ "hook-port": 5002 }); 25 | messager.once('hook::connected', function () { 26 | messager.emit('test', 'hello there!'); 27 | }); 28 | }, 29 | "the *::test event should be fired correctly": function (_, data) { 30 | assert.equal(data, 'hello there!'); 31 | } 32 | } 33 | }) 34 | }) 35 | }).export(module); 36 | 37 | -------------------------------------------------------------------------------- /vendor/dnode/examples/auth/server.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // Serve an object with authentication 3 | 4 | var DNode = require('dnode'); 5 | var sys = require('sys'); 6 | var fs = require('fs'); 7 | 8 | var quotes = JSON.parse( 9 | fs.readFileSync(__dirname + '/quotes.json').toString() 10 | ); 11 | 12 | // Serve up a Session object only after the client supplies the valid user/pass 13 | DNode(function (client, connection) { 14 | this.authenticate = function (user, pass, cb) { 15 | if (user == 'moo' && pass == 'hax') { 16 | sys.puts('Sign in as ' + sys.inspect(user) + ' succeeded!'); 17 | cb(new Session({ 18 | user : user, 19 | client : client, 20 | connection : connection, 21 | })); 22 | } 23 | else { 24 | sys.puts('Sign in as ' + sys.inspect(user) + ' failed!'); 25 | cb(null); 26 | } 27 | }; 28 | }).listen(7007); 29 | 30 | // Clients who connect get an instance of this session object: 31 | function Session (params) { 32 | var conn = params.connection; 33 | var user = params.user; 34 | var client = params.client; 35 | 36 | conn.addListener('end', function () { 37 | sys.puts('User ' + sys.inspect(user) + ' disconnected'); 38 | }); 39 | 40 | this.quote = function (f) { 41 | var i = Math.floor(Math.random() * quotes.length); 42 | f(quotes[i]); 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /vendor/EventEmitter2/test/perf/benchmark.js: -------------------------------------------------------------------------------- 1 | 2 | var Benchmark = require('benchmark'); 3 | var suite = new Benchmark.Suite(); 4 | 5 | var EventEmitter = require('events').EventEmitter; 6 | var emitter = new EventEmitter; 7 | 8 | var EventEmitter2 = require('../../lib/eventemitter2').EventEmitter2; 9 | var emitter2 = new EventEmitter2; 10 | 11 | var EventEmitter3 = require('events').EventEmitter; 12 | var emitter3 = new EventEmitter3; 13 | 14 | suite 15 | 16 | .add('EventEmitterHeatUp', function() { 17 | 18 | emitter3.on('test3', function () { 1==1; }); 19 | emitter3.emit('test3'); 20 | emitter3.removeAllListeners('test3'); 21 | 22 | }) 23 | .add('EventEmitter', function() { 24 | 25 | emitter.on('test1', function () { 1==1; }); 26 | emitter.emit('test1'); 27 | emitter.removeAllListeners('test1'); 28 | 29 | }) 30 | .add('EventEmitter2', function() { 31 | 32 | emitter2.on('test2', function () { 1==1; }); 33 | emitter2.emit('test2'); 34 | emitter2.removeAllListeners('test2'); 35 | 36 | }) 37 | 38 | .add('EventEmitter2 (wild)', function() { 39 | 40 | emitter2.on('test2.foo', function () { 1==1; }); 41 | emitter2.emit('test2.foo'); 42 | emitter2.removeAllListeners('test2.foo'); 43 | 44 | }) 45 | 46 | .on('cycle', function(event, bench) { 47 | console.log(String(bench)); 48 | }) 49 | .on('complete', function() { 50 | console.log('Fastest is ' + this.filter('fastest').pluck('name')); 51 | }) 52 | 53 | .run(true); 54 | -------------------------------------------------------------------------------- /lib/hookio/npm-api.js: -------------------------------------------------------------------------------- 1 | /* 2 | * npm-api.js: Wrapper for NPM ( Node Package Manager ) 3 | * 4 | * (C) 2011 Nodejitsu Inc. 5 | * MIT LICENCE 6 | * 7 | */ 8 | 9 | 10 | var npm = exports, 11 | npmModule = require('npm'); 12 | 13 | // 14 | // ### function getHooks (searchKey, callback) 15 | // #### @searchKey {string} Key to search npm with 16 | // #### @callback {function} The callback 17 | // 18 | npm.get = function (searchKey, callback) { 19 | 20 | 21 | // 22 | // Search NPM based on searchKey 23 | // 24 | 25 | 26 | // 27 | // Send the results to the callback 28 | // 29 | 30 | } 31 | 32 | // 33 | // ### function npm.install (hook, callback) 34 | // #### @hook {string} name of Hook to install 35 | // #### @callback {function} The callback 36 | // 37 | npm.install = function (hook, callback) { 38 | // 39 | // Run the npm install command based on the incoming hook name 40 | // 41 | npmModule.load({exit:false}, function (err) { 42 | npmModule.install(hook, function (err, result) { 43 | callback(err, result); 44 | }); 45 | }); 46 | } 47 | 48 | 49 | // 50 | // ### function npm.search (hook, callback) 51 | // #### @hook {string} name of Hook to search for 52 | // #### @callback {function} The callback 53 | // 54 | npm.search = function (keywords, callback) { 55 | npmModule.load({exit:false}, function (err) { 56 | npmModule.commands.search(keywords, function (err, result) { 57 | callback(err, result); 58 | }); 59 | }); 60 | } 61 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/test/json.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var Traverse = require('../'); 3 | 4 | exports['json test'] = function () { 5 | var id = 54; 6 | var callbacks = {}; 7 | var obj = { moo : function () {}, foo : [2,3,4, function () {}] }; 8 | 9 | var scrubbed = Traverse(obj).map(function (x) { 10 | if (typeof x === 'function') { 11 | callbacks[id] = { id : id, f : x, path : this.path }; 12 | this.update('[Function]'); 13 | id++; 14 | } 15 | }); 16 | 17 | assert.equal( 18 | scrubbed.moo, '[Function]', 19 | 'obj.moo replaced with "[Function]"' 20 | ); 21 | 22 | assert.equal( 23 | scrubbed.foo[3], '[Function]', 24 | 'obj.foo[3] replaced with "[Function]"' 25 | ); 26 | 27 | assert.deepEqual(scrubbed, { 28 | moo : '[Function]', 29 | foo : [ 2, 3, 4, "[Function]" ] 30 | }, 'Full JSON string matches'); 31 | 32 | assert.deepEqual( 33 | typeof obj.moo, 'function', 34 | 'Original obj.moo still a function' 35 | ); 36 | 37 | assert.deepEqual( 38 | typeof obj.foo[3], 'function', 39 | 'Original obj.foo[3] still a function' 40 | ); 41 | 42 | assert.deepEqual(callbacks, { 43 | 54: { id: 54, f : obj.moo, path: [ 'moo' ] }, 44 | 55: { id: 55, f : obj.foo[3], path: [ 'foo', '3' ] }, 45 | }, 'Check the generated callbacks list'); 46 | }; 47 | 48 | -------------------------------------------------------------------------------- /vendor/dnode/test/middleware.js: -------------------------------------------------------------------------------- 1 | var dnode = require('../'); 2 | var test = require('tap').test; 3 | 4 | test('middleware', function (t) { 5 | t.plan(5); 6 | 7 | var port = Math.floor(Math.random() * 40000 + 10000); 8 | var tf = setTimeout(function () { 9 | t.fail('never finished'); 10 | }, 1000); 11 | 12 | var tr = setTimeout(function () { 13 | t.fail('never ready'); 14 | }, 1000); 15 | 16 | var tc = setTimeout(function () { 17 | t.fail('connection not ready'); 18 | }, 1000); 19 | 20 | var server = dnode(function (client, conn) { 21 | t.ok(!conn.zing); 22 | t.ok(!client.moo); 23 | 24 | conn.on('ready', (function () { 25 | clearTimeout(tr); 26 | t.ok(conn.zing); 27 | t.ok(this.moo); 28 | }).bind(this)); 29 | 30 | this.baz = 42; 31 | }).listen(port); 32 | 33 | server.use(function (client, conn) { 34 | conn.zing = true; 35 | }); 36 | 37 | server.use(function (client, conn) { 38 | this.moo = true; 39 | conn.on('ready', function () { 40 | clearTimeout(tc); 41 | }); 42 | }); 43 | 44 | server.on('ready', function () { 45 | dnode.connect(port, function (remote, conn) { 46 | clearTimeout(tf); 47 | t.ok(remote.baz); 48 | conn.end(); 49 | server.close(); 50 | t.end(); 51 | }); 52 | }); 53 | }); 54 | -------------------------------------------------------------------------------- /test/messaging/remote/callback-child-test.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'), 2 | vows = require('vows'), 3 | Hook = require('../../../lib/hookio').Hook, 4 | macros = require('../../helpers/macros'); 5 | 6 | var testData = macros.testData; 7 | 8 | vows.describe('hook.io/messaging/remote/callback-child-test').addBatch({ 9 | 'When a hook is listening on 5070': { 10 | topic: function () { 11 | var hook = new Hook({ name: 'hook', debug: true }); 12 | hook.on('hook::ready', this.callback.bind(hook, null, hook)); 13 | 14 | hook.on('*::callbackTestEvent', function (data, callback) { 15 | callback(null, data); 16 | }); 17 | 18 | hook.listen({ 'hook-port': 5070 }); 19 | }, 20 | 'and another hook connects': macros.assertConnect('client-hook', 5070, { 21 | 'and it emits a test event': { 22 | 'with data': { 23 | topic: function (hook) { 24 | hook.emit('callbackTestEvent', testData, this.callback); 25 | }, 26 | 'he should receive a callback with correct data': function (data) { 27 | assert.deepEqual(data, testData); 28 | } 29 | }, 30 | 'without any data': { 31 | topic: function (hook) { 32 | hook.emit('callbackTestEvent', this.callback); 33 | }, 34 | 'he should receive a callback without any data': function (data) { 35 | assert.isNull(data); 36 | } 37 | } 38 | } 39 | }) 40 | } 41 | }).export(module); 42 | 43 | -------------------------------------------------------------------------------- /vendor/dnode/examples/chat/server.js: -------------------------------------------------------------------------------- 1 | // simple dnode chat server with browserify 2 | 3 | var express = require('express'); 4 | var app = express.createServer(); 5 | app.use(express.static(__dirname)); 6 | 7 | var browserify = require('browserify'); 8 | app.use(browserify(__dirname + '/entry.js', { watch : true })); 9 | 10 | app.listen(6061); 11 | console.log('http://localhost:6061/'); 12 | 13 | var EventEmitter = require('events').EventEmitter; 14 | var emitter = new EventEmitter; 15 | 16 | var clients = {}; 17 | 18 | var dnode = require('../../'); 19 | dnode(ChatServer).listen(app); 20 | 21 | function ChatServer (client, con) { 22 | var evNames = [ 'joined', 'said', 'parted' ]; 23 | 24 | con.on('ready', function () { 25 | evNames.forEach(function (name) { 26 | emitter.on(name, client[name]); 27 | }); 28 | emitter.emit('joined', client.name); 29 | 30 | clients[client.name] = client; 31 | }); 32 | 33 | con.on('end', function () { 34 | evNames.forEach(function (name) { 35 | if (typeof client[name] === 'function') { 36 | emitter.removeListener(name, client[name]); 37 | } 38 | }); 39 | emitter.emit('parted', client.name); 40 | delete clients[client.name]; 41 | }); 42 | 43 | this.say = function (msg) { 44 | emitter.emit('said', client.name, msg); 45 | }; 46 | 47 | this.names = function (cb) { 48 | cb(Object.keys(clients)) 49 | }; 50 | } 51 | -------------------------------------------------------------------------------- /test/messaging/remote/callback-parent-test.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'), 2 | vows = require('vows'), 3 | Hook = require('../../../lib/hookio').Hook, 4 | macros = require('../../helpers/macros'); 5 | 6 | var testData = macros.testData; 7 | 8 | vows.describe('hook.io/messaging/remote/callback-parent-test').addBatch({ 9 | 'When a hook is listening on 5080': macros.assertListen('server-hook', 5080, { 10 | 'and another hook connects': { 11 | topic: function (server) { 12 | var client = new Hook({ name: 'client-hook', debug: true }); 13 | client.on('hook::connected', this.callback.bind(client, null, client, server)); 14 | 15 | client.on('*::callbackTestEvent', function (data, callback) { 16 | callback(null, data); 17 | }); 18 | 19 | client.connect({ 'hook-port': 5080 }); 20 | }, 21 | 'and server emits a test event': { 22 | 'with data': { 23 | topic: function (client, server) { 24 | server.emit('callbackTestEvent', testData, this.callback); 25 | }, 26 | 'he should receive a callback with correct data': function (data) { 27 | assert.deepEqual(data, testData); 28 | } 29 | }, 30 | 'without data': { 31 | topic: function (client, server) { 32 | server.emit('callbackTestEvent', this.callback); 33 | }, 34 | 'he should receive a callback without any data': function (data) { 35 | assert.isNull(data); 36 | } 37 | } 38 | } 39 | } 40 | }) 41 | }).export(module); 42 | 43 | -------------------------------------------------------------------------------- /test/messaging/remote/callback-parent-hookname-test.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'), 2 | vows = require('vows'), 3 | Hook = require('../../../lib/hookio').Hook, 4 | macros = require('../../helpers/macros'); 5 | 6 | var testData = macros.testData; 7 | 8 | vows.describe('hook.io/messaging/remote/callback-parent-test').addBatch({ 9 | 'When a hook is listening on 5081': macros.assertListen('server-hook', 5081, { 10 | 'and another hook connects': { 11 | topic: function (server) { 12 | var client = new Hook({ name: 'client-hook', debug: true }); 13 | client.on('hook::connected', this.callback.bind(client, null, client, server)); 14 | 15 | client.on('server-hook::*', function (data, callback) { 16 | callback(null, data); 17 | }); 18 | 19 | client.connect({ 'hook-port': 5081 }); 20 | }, 21 | 'and server emits a test event': { 22 | 'with data': { 23 | topic: function (client, server) { 24 | server.emit('callbackTestEvent', testData, this.callback); 25 | }, 26 | 'he should receive a callback with correct data': function (data) { 27 | assert.deepEqual(data, testData); 28 | } 29 | }, 30 | 'without data': { 31 | topic: function (client, server) { 32 | server.emit('callbackTestEvent', this.callback); 33 | }, 34 | 'he should receive a callback without any data': function (data) { 35 | assert.isNull(data); 36 | } 37 | } 38 | } 39 | } 40 | }) 41 | }).export(module); 42 | 43 | -------------------------------------------------------------------------------- /lib/hookio/commands/init.js: -------------------------------------------------------------------------------- 1 | // 2 | // init - Creates new hook.io hook scaffolds 3 | // 4 | var path = require('path'), 5 | prompt = require('prompt'); 6 | 7 | 8 | // 9 | // TODO: command system should be refactored to use Flatiron 10 | // 11 | 12 | 13 | var init = module.exports = function init () { 14 | 15 | // 16 | // Deletgate based on incoming argv 17 | // 18 | var self = this, 19 | args = self._, 20 | newHookName, 21 | newHookPath = process.cwd() + '/'; 22 | 23 | // 24 | // $ init 25 | // 26 | if(args.length === 1) { 27 | 28 | } 29 | 30 | // 31 | // $ init ./path/to/new/hook 32 | // 33 | if(args.length >= 2 && args[1].search(/\.|\//) !== -1) { 34 | newHookPath = path.normalize(newHookPath + '/' + args[1] + '/'); 35 | } 36 | 37 | // 38 | // $ init newhookname 39 | // 40 | if(args.length >= 2 && args[1].search(/\.|\//) === -1) { 41 | newHookName = args[1]; 42 | } 43 | 44 | prompt.start(); 45 | console.log('Welcome to the ' + 'hook.io'.magenta + ' scaffold tool!'); 46 | console.log('This will attempt to generate a new hook at: ' + newHookPath.grey); 47 | if (!newHookName) { 48 | prompt.get([{ 49 | name: 'hookname', 50 | message: 'Name your hook' 51 | }], function (err, result) { 52 | if (err) { 53 | throw err; 54 | } 55 | newHookName = result['hookname']; 56 | self.scaffold(newHookName, newHookPath, process.exit); 57 | }); 58 | 59 | } else { 60 | self.scaffold(newHookName, newHookPath, process.exit); 61 | } 62 | 63 | } 64 | 65 | init.usage = 'Print out a '; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "Marak Squires ", 3 | "name": "hook.io", 4 | "version": "0.8.9", 5 | "repository": { 6 | "type": "git", 7 | "url": "git://github.com/hookio/hook.io.git" 8 | }, 9 | "contributors": [ 10 | { 11 | "name": "Charlie Robbins", 12 | "email": "charlie@nodejitsu.com" 13 | }, 14 | { 15 | "name": "Jameson Lee", 16 | "email": "jameson@nodejitsu.com" 17 | } 18 | ], 19 | "main": "./lib/hookio", 20 | "bin": { 21 | "hookio": "./bin/hookio" 22 | }, 23 | "engines": { 24 | "node": ">= v0.4.7" 25 | }, 26 | "dependencies": { 27 | "async": "0.1.x", 28 | "colors": "0.x.x", 29 | "eventemitter2": "0.4.x", 30 | "optimist": "0.2.x", 31 | "nconf": "0.3.x", 32 | "npm": "~1.1.x", 33 | "pkginfo": "0.2.x", 34 | "mkdirp": "0.2.x", 35 | "semver": "1.0.x", 36 | "prompt": "0.1.x", 37 | "portfinder": "0.2.x", 38 | "weak": "0.2.x", 39 | "socket.io" : "0.8.6", 40 | "socket.io-client" : "https://github.com/substack/socket.io-client/tarball/master", 41 | "lazy" : ">=1.0.5 <1.1", 42 | "dnode-protocol" : "0.1.x", 43 | "traverse" : "0.6.x", 44 | "jsonify" : "0.0.x", 45 | "winston": "0.5.10" 46 | }, 47 | "scripts": { 48 | "test": "vows test/**/*-test.js --spec" 49 | }, 50 | "browserify" : { 51 | "base" : "./lib", 52 | "main" : "./lib/hookio.js" 53 | }, 54 | "devDependencies": { 55 | "eyes": "0.1.x", 56 | "findit": "0.x.x", 57 | "forever": "0.6.x", 58 | "hook.io-helloworld" : "0.3.x", 59 | "vows": "0.5.x >=0.5.10" 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /test/registry/simple-test.js: -------------------------------------------------------------------------------- 1 | var vows = require('vows'), 2 | assert = require('assert'), 3 | Hook = require('../../lib/hookio').Hook, 4 | macros = require('../helpers/macros'); 5 | 6 | var emptyFn = function() {}; 7 | 8 | vows.describe('hook.io/registry/simple-test').addBatch({ 9 | "When a hook is listening on 5014": { 10 | topic: function() { 11 | var server = new Hook({ name: 'server', debug:true }); 12 | server.on('hook::ready', this.callback.bind(server, null, server)); 13 | server.on('serverTestEvent', emptyFn); 14 | server.listen({ "hook-port": 5014 }); 15 | }, 16 | "and another hook connects": { 17 | topic: function(server) { 18 | var client = new Hook({ name: 'client', debug:true }); 19 | client.connect({ "hook-port": 5014 }, this.callback.bind(client, null, server, client)); 20 | }, 21 | "when my hook registers an event": { 22 | topic: function(server, client) { 23 | // Register a new "testEvent" 24 | client.on('testEvent', emptyFn); 25 | 26 | // Wait a bit for the event to propagate. 27 | // I'm not completely satisfied with this solution... 28 | setTimeout(this.callback.bind(this, null, server), 50); 29 | }, 30 | "then I have that new listener registered": function(server) { 31 | assert.ok(server._names.client.events.testEvent); 32 | }, 33 | "and I also have server events registered": function(server) { 34 | assert.ok(server._names.server.events.serverTestEvent); 35 | } 36 | } 37 | } 38 | } 39 | }).export(module); 40 | -------------------------------------------------------------------------------- /test/messaging/remote/callback-child-hookname-test.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'), 2 | vows = require('vows'), 3 | Hook = require('../../../lib/hookio').Hook, 4 | macros = require('../../helpers/macros'); 5 | 6 | var testData = macros.testData; 7 | 8 | vows.describe('hook.io/messaging/remote/callback-child-hookname-test').addBatch({ 9 | 'When a hook is listening on 5071': { 10 | topic: function () { 11 | var hook = new Hook({ name: 'hook', debug: true }); 12 | hook.on('hook::ready', this.callback.bind(hook, null, hook)); 13 | 14 | // This is different from callback-child-test because it listens for 15 | // "client-hook::*" instead of "*::callbackTestEvent". 16 | hook.on('client-hook::*', function (data, callback) { 17 | callback(null, data); 18 | }); 19 | 20 | hook.listen({ 'hook-port': 5071 }); 21 | }, 22 | 'and another hook connects': macros.assertConnect('client-hook', 5071, { 23 | 'and it emits a test event': { 24 | 'with data': { 25 | topic: function (hook) { 26 | hook.emit('callbackTestEvent', testData, this.callback); 27 | }, 28 | 'he should receive a callback with correct data': function (data) { 29 | assert.deepEqual(data, testData); 30 | } 31 | }, 32 | 'without any data': { 33 | topic: function (hook) { 34 | hook.emit('callbackTestEvent', this.callback); 35 | }, 36 | 'he should receive a callback without any data': function (data) { 37 | assert.isNull(data); 38 | } 39 | } 40 | } 41 | }) 42 | } 43 | }).export(module); 44 | 45 | -------------------------------------------------------------------------------- /vendor/dnode/test/gc.js: -------------------------------------------------------------------------------- 1 | #! node --expose-gc 2 | var dnode = require('../'); 3 | var test = require('tap').test; 4 | var weak = require('weak'); 5 | 6 | test('gc', function (t) { 7 | t.plan(2); 8 | var port = Math.floor(Math.random() * 40000 + 10000); 9 | 10 | var gcLoopIterations = 0; 11 | var server_ok = false, client_ok = false; 12 | 13 | function forced_gc_loop() { 14 | gc(); 15 | if (++gcLoopIterations < 50) { 16 | setTimeout(forced_gc_loop, 100); 17 | } else { 18 | if (!server_ok || !client_ok) t.end(); 19 | setTimeout(function() { 20 | process.exit(); 21 | }, 1000); 22 | } 23 | } 24 | forced_gc_loop(); 25 | 26 | function onSuccess() { 27 | t.end(); 28 | setTimeout(process.exit, 500); 29 | } 30 | 31 | var server = dnode({ 32 | callMeBack : function (fn) { 33 | fn('calling back!'); 34 | weak(fn, function() { 35 | t.ok(true); 36 | server_ok = true; 37 | if (client_ok) onSuccess(); 38 | }); 39 | } 40 | }).listen(port); 41 | 42 | server.on('ready', function () { 43 | dnode.connect(port, function (remote, conn) { 44 | function weakCb() { 45 | t.ok(true); 46 | client_ok = true; 47 | if (server_ok) onSuccess(); 48 | } 49 | (function() { 50 | var cb = function(){}; 51 | remote.callMeBack(cb); 52 | weak(cb, weakCb); 53 | })(); 54 | }); 55 | }); 56 | }); 57 | -------------------------------------------------------------------------------- /vendor/dnode/examples/https/server.js: -------------------------------------------------------------------------------- 1 | var https = require('https'); 2 | var fs = require('fs'); 3 | var dnode = require('dnode'); 4 | 5 | try { 6 | var opts = { 7 | key : fs.readFileSync(__dirname + '/privatekey.pem'), 8 | cert : fs.readFileSync(__dirname + '/certificate.pem'), 9 | }; 10 | } 11 | catch (e) { 12 | console.log('# {privatekey,certificate}.pem missing, do this first:'); 13 | console.log('openssl genrsa -out privatekey.pem 1024'); 14 | console.log('openssl req -new -key privatekey.pem -out certrequest.csr'); 15 | console.log('openssl x509 -req -in certrequest.csr ' 16 | + '-signkey privatekey.pem -out certificate.pem'); 17 | process.exit(); 18 | } 19 | 20 | var index = fs.readFileSync(__dirname + '/index.html'); 21 | var server = https.createServer(opts, function (req, res) { 22 | if (req.url === '/') { 23 | res.writeHead(200, { 'Content-Type' : 'text/html' }); 24 | res.end(index); 25 | } 26 | else if (!res.finished) { 27 | process.nextTick(function () { 28 | if (!res.finished) { 29 | res.writeHead(404, { 'Content-Type' : 'text/html' }); 30 | res.end('Not found!'); 31 | } 32 | }); 33 | } 34 | }); 35 | 36 | dnode(function (client) { 37 | this.timesTen = function (n,f) { f(n * 10) }; 38 | this.whoAmI = function (reply) { 39 | client.name(function (name) { 40 | reply(name 41 | .replace(/Mr\.?/,'Mister') 42 | .replace(/Ms\.?/,'Miss') 43 | .replace(/Mrs\.?/,'Misses') 44 | ); 45 | }) 46 | }; 47 | }).listen(server); 48 | server.listen(8020); 49 | 50 | console.log('https://localhost:8020/'); 51 | -------------------------------------------------------------------------------- /vendor/dnode/examples/nested.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | var DNode = require('dnode'); 3 | var sys = require('sys'); 4 | var EventEmitter = require('events').EventEmitter; 5 | 6 | // server-side: 7 | var server1 = DNode({ 8 | timesTen : function (n,reply) { reply(n * 10) } 9 | }).listen(6060); 10 | 11 | var server2 = DNode({ 12 | timesTwenty : function (n,reply) { reply(n * 20) } 13 | }).listen(6061); 14 | 15 | var moo = new EventEmitter; 16 | 17 | // client-side: 18 | // Good thing this example is so contrived. Real code doesn't turn out this 19 | // ugly very often on purpose. 20 | server1.on('ready', function () { 21 | server2.on('ready', function () { 22 | DNode.connect(6060, function (remote1) { 23 | DNode.connect(6061, function (remote2) { 24 | moo.addListener('hi', function (x) { 25 | remote1.timesTen(x, function (res) { 26 | sys.puts(res); 27 | remote2.timesTwenty(res, function (res2) { 28 | sys.puts(res2); 29 | }); 30 | }); 31 | }); 32 | remote2.timesTwenty(5, function (n) { 33 | sys.puts(n); // 100 34 | remote1.timesTen(0.1, function (n) { 35 | sys.puts(n); // 1 36 | }); 37 | }); 38 | }); 39 | }); 40 | }); 41 | }); 42 | 43 | setTimeout(function() { 44 | moo.emit('hi', 100); 45 | }, 500); 46 | 47 | setTimeout(function () { 48 | // kill the service after a while 49 | server1.end(); 50 | server2.end(); 51 | }, 1000); 52 | 53 | /* 54 | Output: 55 | 100 56 | 1 57 | ... after half a second ... 58 | 1000 59 | 20000 60 | */ 61 | 62 | -------------------------------------------------------------------------------- /test/discovery/basic-init-test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * test-basic-test.js: Basic tests for the hook.io module 3 | * 4 | * (C) 2011 Marak Squires, Charlie Robbins 5 | * MIT LICENCE 6 | * 7 | */ 8 | 9 | var vows = require('vows'), 10 | assert = require('assert'), 11 | Hook = require('../../lib/hookio').Hook, 12 | macros = require('../helpers/macros'); 13 | 14 | vows.describe('hook.io/discovery/basic-init').addBatch({ 15 | "When a Hook is listening on 5010": macros.assertListen('simple-listen', 5010, { 16 | "and another hook attempts to `.connect()`": macros.assertConnect('simple-connect', 5010), 17 | "and another hook attempts to `.start()`": macros.assertReady('simple-start', 5010) 18 | }) 19 | }).addBatch({ 20 | "When a Hook is listening on 5010": { 21 | "and another hook attempts to `.listen()` on 5010": { 22 | topic: function () { 23 | var instance = new Hook({ name: 'simple-error' }); 24 | instance.once('error::*', this.callback.bind(instance, null)); 25 | instance.listen({ "hook-port": 5010, debug:true }); 26 | }, 27 | "it should fire the `error` event": function (_, data) { 28 | assert.equal(this.event, 'error::bind'); 29 | assert.equal(data, '5010'); 30 | } 31 | } 32 | } 33 | }).addBatch({ 34 | "When a Hook is listening on 5010": { 35 | "and another hook attempts to `.listen()` on 5010": { 36 | topic: function () { 37 | var instance = new Hook({ name: 'simple-error-callback', debug:true }); 38 | instance.listen({ "hook-port": 5010 }, this.callback.bind(instance, null)); 39 | }, 40 | "it should return an error ": function (_, err) { 41 | assert.isObject(err); 42 | }, 43 | "error should be EADDRINUSE": function (_, err) { 44 | assert.equal(err.code, 'EADDRINUSE'); 45 | } 46 | } 47 | } 48 | }).export(module); 49 | -------------------------------------------------------------------------------- /vendor/dnode/test/nested.js: -------------------------------------------------------------------------------- 1 | var dnode = require('../'); 2 | var test = require('tap').test; 3 | 4 | test('nested', function (t) { 5 | t.plan(4); 6 | var port = Math.floor(Math.random() * 40000 + 10000); 7 | 8 | var EventEmitter = require('events').EventEmitter; 9 | 10 | var server1 = dnode({ 11 | timesTen : function (n,reply) { reply(n * 10) } 12 | }).listen(port); 13 | 14 | var server2 = dnode({ 15 | timesTwenty : function (n,reply) { reply(n * 20) } 16 | }).listen(port + 1); 17 | 18 | var moo = new EventEmitter; 19 | 20 | // Don't worry, real code does't look like this: 21 | server1.on('ready', function () { 22 | server2.on('ready', function () { 23 | dnode.connect(port, function (remote1, conn1) { 24 | dnode.connect(port + 1, function (remote2, conn2) { 25 | moo.on('hi', function (x) { 26 | remote1.timesTen(x, function (res) { 27 | t.equal(res, 5000, 'emitted value times ten'); 28 | remote2.timesTwenty(res, function (res2) { 29 | t.equal(res2, 100000, 'result times twenty'); 30 | conn1.end(); conn2.end(); 31 | server1.close(); server2.close(); 32 | t.end(); 33 | }); 34 | }); 35 | }); 36 | remote2.timesTwenty(5, function (n) { 37 | t.equal(n, 100); 38 | remote1.timesTen(0.1, function (n) { 39 | t.equal(n, 1); 40 | }); 41 | }); 42 | }); 43 | }); 44 | }); 45 | }); 46 | 47 | setTimeout(function() { 48 | moo.emit('hi', 500); 49 | }, 200); 50 | }); 51 | -------------------------------------------------------------------------------- /vendor/dnode/browser/index.js: -------------------------------------------------------------------------------- 1 | var protocol = require('dnode-protocol'); 2 | var EventEmitter = require('events').EventEmitter; 3 | var io = require('socket.io-client'); 4 | var json = typeof JSON === 'object' ? JSON : require('jsonify'); 5 | 6 | var exports = module.exports = dnode; 7 | 8 | function dnode (wrapper) { 9 | if (!(this instanceof dnode)) return new dnode(wrapper); 10 | this.proto = protocol(wrapper); 11 | this.stack = []; 12 | return this; 13 | } 14 | 15 | dnode.prototype = new EventEmitter; 16 | 17 | dnode.prototype.use = function (middleware) { 18 | this.stack.push(middleware); 19 | return this; 20 | }; 21 | 22 | dnode.prototype.connect = function () { 23 | var self = this; 24 | var params = protocol.parseArgs(arguments); 25 | var client = self.proto.create(); 26 | 27 | var proto = (params.proto || window.location.protocol) 28 | .replace(/:.*/, '') + '://'; 29 | 30 | var sock = client.socketio = io.connect( 31 | proto + (params.host || window.location.host), 32 | params 33 | ); 34 | 35 | client.end = function () { 36 | sock.disconnect(); 37 | }; 38 | 39 | sock.on('connect', function () { 40 | client.start(); 41 | self.emit('connect'); 42 | }); 43 | 44 | sock.on('disconnect', function () { 45 | client.emit('end'); 46 | self.emit('end'); 47 | }); 48 | 49 | sock.on('message', client.parse); 50 | 51 | client.on('request', function (req) { 52 | sock.send(json.stringify(req) + '\n'); 53 | }); 54 | 55 | if (params.block) { 56 | client.on('remote', function () { 57 | params.block.call(client.instance, client.remote, client); 58 | }); 59 | } 60 | 61 | this.stack.forEach(function (middleware) { 62 | middleware.call(client.instance, client.remote, client); 63 | }); 64 | }; 65 | 66 | exports.connect = function () { 67 | var d = exports(); 68 | return d.connect.apply(d, arguments); 69 | }; 70 | -------------------------------------------------------------------------------- /vendor/EventEmitter2/test/wildcardEvents/k1.js: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Joyent, Inc. and other Node contributors. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a 5 | // copy of this software and associated documentation files (the 6 | // "Software"), to deal in the Software without restriction, including 7 | // without limitation the rights to use, copy, modify, merge, publish, 8 | // distribute, sublicense, and/or sell copies of the Software, and to permit 9 | // persons to whom the Software is furnished to do so, subject to the 10 | // following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included 13 | // in all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 18 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 19 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | var common = require('../common'); 24 | var assert = require('assert'); 25 | var EventEmitter = require('../../lib/eventemitter2').EventEmitter2; 26 | 27 | var e = new EventEmitter({wildcard: true}); 28 | var countWildcard = 0; 29 | var counMultiLevelWildcard = 0; 30 | var countAny = 0; 31 | 32 | e.on('foo', function() { 33 | e.emit('bar', 'bar'); 34 | }); 35 | e.on('*', function(name) { 36 | ++countWildcard; 37 | console.log(this.event, name); 38 | assert.equal(this.event, name); 39 | }); 40 | e.on('**', function(name) { 41 | ++counMultiLevelWildcard; 42 | console.log(this.event, name); 43 | assert.equal(this.event, name); 44 | }); 45 | e.onAny(function(name) { 46 | ++countAny; 47 | assert.equal(this.event, name); 48 | }); 49 | 50 | e.emit('foo', 'foo'); 51 | 52 | process.on('exit', function() { 53 | assert.equal(countWildcard, 2); 54 | assert.equal(counMultiLevelWildcard, 2); 55 | assert.equal(countAny, 2); 56 | }); 57 | -------------------------------------------------------------------------------- /vendor/EventEmitter2/test/wildcardEvents/options.js: -------------------------------------------------------------------------------- 1 | var basicEvents = require('nodeunit').testCase; 2 | var lib = '../../lib/eventemitter2'; 3 | 4 | /////helper/////// 5 | function setHelper (emitter, test, testName){ 6 | var eventNames = [ 7 | testName, 8 | testName + '.*', 9 | testName + '.ns1', 10 | testName + '.ns1.ns2', 11 | testName + '.ns2.*', 12 | testName + '.**', 13 | testName = '.ns2.**' 14 | ]; 15 | 16 | for (var i = 0; i < eventNames.length; i++) { 17 | emitter.on(eventNames[i], function () { 18 | test.ok(true, eventNames[i] + 'has fired'); 19 | }); 20 | } 21 | 22 | return eventNames; 23 | } 24 | 25 | module.exports = basicEvents({ 26 | 27 | setUp: function (callback) { 28 | var EventEmitter2; 29 | 30 | if(typeof require !== 'undefined') { 31 | EventEmitter2 = require(lib).EventEmitter2; 32 | } 33 | else { 34 | EventEmitter2 = window.EventEmitter2; 35 | } 36 | 37 | this.emitter = new EventEmitter2({ 38 | wildcard: true, 39 | verbose: true 40 | }); 41 | this.emitterDefault = new EventEmitter2({ 42 | }); 43 | 44 | callback(); 45 | }, 46 | 47 | tearDown: function (callback) { 48 | //clean up? 49 | callback(); 50 | }, 51 | 52 | 'intialize 1. Configuration Flags Test.': function (test) { 53 | // lazy 54 | var emitter = this.emitter, 55 | emitterDefault = this.emitterDefault; 56 | 57 | test.ok(!emitterDefault.wildcard, 'default .wildcard should be false'); 58 | test.ok(emitter.wildcard, '.wildcard should be true when set'); 59 | 60 | test.expect(2); 61 | test.done(); 62 | 63 | }, 64 | 'initialize 2. creating a wildcard EE should have listenerTree.': function (test) { 65 | 66 | var emitter = this.emitter, 67 | emitterDefault = this.emitterDefault; 68 | 69 | test.ok(emitter.listenerTree, 'listenerTree should exist'); 70 | test.equal(typeof emitter.listenerTree, 'object', 'listenerTree should be an Object'); 71 | 72 | test.ok(!emitterDefault.listenerTree, 'listenerTree should not exist'); 73 | // check the tree to be empty? 74 | 75 | test.expect(3); 76 | test.done(); 77 | 78 | }, 79 | }); 80 | -------------------------------------------------------------------------------- /vendor/dnode/test/emit.js: -------------------------------------------------------------------------------- 1 | var test = require('tap').test; 2 | var EventEmitter = require('events').EventEmitter; 3 | var dnode = require('../'); 4 | 5 | test('emit events', function (t) { 6 | t.plan(2); 7 | var port = Math.floor(Math.random() * ((1<<16)-1e4)) + 1e4; 8 | 9 | var subs = []; 10 | function publish (name) { 11 | var args = [].slice.call(arguments, 1); 12 | subs.forEach(function (sub) { 13 | sub.emit(name, args); 14 | }); 15 | } 16 | 17 | var server = dnode(function (remote, conn) { 18 | this.subscribe = function (emit) { 19 | subs.push({ emit : emit, id : conn.id }); 20 | 21 | conn.on('end', function () { 22 | for (var i = 0; i < subs.length; i++) { 23 | if (subs.id === conn.id) { 24 | subs.splice(i, 1); 25 | break; 26 | } 27 | } 28 | }); 29 | }; 30 | }).listen(port); 31 | 32 | server.on('ready', function () { 33 | setTimeout(function () { 34 | var iv = setInterval(function () { 35 | publish('data', Math.floor(Math.random() * 100)); 36 | }, 20); 37 | 38 | server.on('close', function () { 39 | clearInterval(iv); 40 | }); 41 | }, 20); 42 | 43 | var xs = []; 44 | var x = dnode.connect(port, function (remote) { 45 | var em = new EventEmitter; 46 | em.on('data', function (n) { xs.push(n) }); 47 | remote.subscribe(em.emit.bind(em)); 48 | }); 49 | 50 | var ys = []; 51 | var y = dnode.connect(port, function (remote) { 52 | var em = new EventEmitter; 53 | em.on('data', function (n) { ys.push(n) }); 54 | remote.subscribe(em.emit.bind(em)) 55 | }); 56 | 57 | setTimeout(function () { 58 | t.ok(xs.length > 5); 59 | t.deepEqual(xs, ys); 60 | 61 | x.end(); 62 | y.end(); 63 | 64 | server.close(); 65 | t.end(); 66 | }, 200); 67 | }); 68 | }); 69 | -------------------------------------------------------------------------------- /vendor/dnode/test/broadcast.js: -------------------------------------------------------------------------------- 1 | var dnode = require('../'); 2 | var EventEmitter = require('events').EventEmitter; 3 | var test = require('tap').test; 4 | 5 | test('broadcast', function (t) { 6 | t.plan(3); 7 | var port = Math.floor(Math.random() * 40000 + 10000); 8 | 9 | var em = new EventEmitter; 10 | var server = dnode(function (client,conn) { 11 | conn.on('ready', function () { 12 | em.on('message', client.message); 13 | }); 14 | 15 | conn.on('end', function () { 16 | em.removeListener('message', client.message); 17 | }); 18 | 19 | this.message = function (msg) { 20 | em.emit('message', client.name + ' says: ' + msg); 21 | }; 22 | }).listen(port); 23 | 24 | var recv = { 0 : [], 1 : [], 2 : [] }; 25 | 26 | server.on('ready', function () { 27 | dnode({ 28 | name : '#0', 29 | message : function (msg) { recv[0].push(msg) }, 30 | }).connect(port, function (remote) { 31 | setTimeout(function () { 32 | remote.message('hello!'); 33 | }, 25); 34 | }); 35 | 36 | dnode({ 37 | name : '#1', 38 | message : function (msg) { recv[1].push(msg) }, 39 | }).connect(port, function (remote) { 40 | setTimeout(function () { 41 | remote.message('hey'); 42 | }, 50); 43 | }); 44 | 45 | dnode({ 46 | name : '#2', 47 | message : function (msg) { recv[2].push(msg) }, 48 | }).connect(port, function (remote) { 49 | setTimeout(function () { 50 | remote.message('wowsy'); 51 | }, 75); 52 | }); 53 | }); 54 | 55 | setTimeout(function () { 56 | server.end(); 57 | server.close(); 58 | t.deepEqual( 59 | recv[0], 60 | [ '#0 says: hello!', '#1 says: hey', '#2 says: wowsy' ], 61 | "#0 didn't get the right messages" 62 | ); 63 | t.deepEqual(recv[0], recv[1], "#1 didn't get the messages"); 64 | t.deepEqual(recv[0], recv[2], "#2 didn't get the messages"); 65 | t.end(); 66 | }, 150); 67 | }); 68 | -------------------------------------------------------------------------------- /test/logging/transports-test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * transports-test.js: Transport logging tests for the hook.io module 3 | * 4 | * MIT LICENCE 5 | * 6 | */ 7 | 'use strict'; 8 | 9 | var vows, fs, assert, winston, Hook, hook, options; 10 | 11 | fs = require('fs'); 12 | vows = require('vows'); 13 | assert = require('assert'); 14 | winston = require('winston'); 15 | Hook = require('../../lib/hookio').Hook; 16 | 17 | options = { 18 | port : 5002, 19 | logger : { 20 | transports : { 21 | file : { filename : __dirname + "/file.log" } 22 | } 23 | } 24 | }; 25 | 26 | vows.describe('hook.io/logging/transports').addBatch({ 27 | "Given a hook with logging configuration" : { 28 | topic : function() { 29 | return new Hook(options); 30 | }, 31 | 32 | "When a hook is ready" : { 33 | topic: function(hook) { 34 | var self; 35 | 36 | self = this; 37 | 38 | hook.on('hook::ready', function() { 39 | self.callback(null, this._winston); 40 | }); 41 | 42 | hook.start(); 43 | }, 44 | 45 | "It should convert the object into Winston transports" : function(err, hookWinston) { 46 | var types, transports, name, capitalized; 47 | 48 | types = options.logger.transports; 49 | transports = hookWinston.transports; 50 | 51 | for (name in types) { 52 | // capitalize the name 53 | capitalized = name.charAt(0).toUpperCase() + name.substr(1); 54 | 55 | assert.instanceOf(transports[name], winston.transports[capitalized]); 56 | } 57 | } 58 | }, 59 | 60 | "When the log() method is called" : { 61 | topic: function(hook) { 62 | var self = this; 63 | 64 | hook.log(hook, 'Some event', 'This should be logged'); 65 | 66 | setTimeout(function() { 67 | // wait awhile as the file is written to 68 | fs.readFile(hook.logger.transports.file.filename, 'utf-8', self.callback); 69 | }, 1000); 70 | }, 71 | 72 | "It should write to the specified log file" : function(err, data) { 73 | assert.ifError(err); 74 | assert.ok(/This should be logged/.test(data)); 75 | 76 | fs.unlink(options.logger.transports.file.filename); 77 | } 78 | } 79 | } 80 | }).export(module); 81 | -------------------------------------------------------------------------------- /vendor/dnode/test/bundle.js: -------------------------------------------------------------------------------- 1 | var test = require('tap').test; 2 | var dnode = require('../'); 3 | var http = require('http'); 4 | var express = require('express'); 5 | 6 | test('checkCookieHTTP', function (t) { 7 | t.plan(3); 8 | var port = Math.floor(10000 + (Math.random() * Math.pow(2,16) - 10000)); 9 | 10 | var web = http.createServer(function (req, res) { 11 | res.setHeader('set-cookie', [ 'foo=bar' ]); 12 | 13 | if (req.url === '/') { 14 | res.setStatus(200); 15 | res.setHeader('content-type', 'text/html'); 16 | res.end('pow'); 17 | } 18 | }); 19 | var server = dnode().listen(web); 20 | 21 | web.listen(port, function () { 22 | var req = { 23 | host : 'localhost', 24 | port : port, 25 | path : '/dnode.js', 26 | }; 27 | http.get(req, function (res) { 28 | t.equal(res.statusCode, 200); 29 | t.equal(res.headers['content-type'], 'text/javascript'); 30 | t.deepEqual(res.headers['set-cookie'], [ 'foo=bar' ]); 31 | 32 | web.close(); 33 | server.end(); 34 | }); 35 | }); 36 | }); 37 | 38 | test('checkCookieExpress', function (t) { 39 | t.plan(3); 40 | var port = Math.floor(10000 + (Math.random() * Math.pow(2,16) - 10000)); 41 | 42 | var app = express.createServer(); 43 | app.use(function (req, res, next) { 44 | res.setHeader('set-cookie', [ 'foo=bar' ]); 45 | next(); 46 | }); 47 | 48 | app.get('/', function (req, res) { 49 | res.setStatus(200); 50 | res.setHeader('content-type', 'text/html'); 51 | res.end('pow'); 52 | }); 53 | 54 | var server = dnode().listen(app); 55 | 56 | app.listen(port, function () { 57 | var req = { 58 | host : 'localhost', 59 | port : port, 60 | path : '/dnode.js', 61 | }; 62 | http.get(req, function (res) { 63 | t.equal(res.statusCode, 200); 64 | t.deepEqual(res.headers['set-cookie'], [ 'foo=bar' ]); 65 | t.equal(res.headers['content-type'], 'text/javascript'); 66 | 67 | app.close(); 68 | server.end(); 69 | t.end(); 70 | }); 71 | }); 72 | }); 73 | -------------------------------------------------------------------------------- /lib/hookio/scaffold.js: -------------------------------------------------------------------------------- 1 | var scaffold = {}; 2 | 3 | var fs = require('fs'), 4 | async = require('async'), 5 | mkdirp = require('mkdirp'), 6 | colors = require('colors'), 7 | path = require('path'); 8 | 9 | scaffold.files = ['config.json', 'LICENSE', 'package.json', 'ReadMe.md', 'bin/scaffold', 'lib/scaffold.js']; 10 | 11 | scaffold.generate = function (hookName, hookPath, callback) { 12 | 13 | var self = this; 14 | 15 | function copyFiles (file, callback) { 16 | 17 | var self = this, 18 | src = __dirname + '/scaffold/', 19 | dst = hookPath; 20 | 21 | console.log(hookName, hookPath); 22 | 23 | fs.readFile(src + file, function(err, result){ 24 | if (err) { 25 | return console.log(err); 26 | } 27 | // 28 | // TODO: scan for word scaffold and replace 29 | // 30 | var filePath = path.normalize(dst + file); 31 | // Replace the `scaffold` file name with the new hook name 32 | // 33 | 34 | filePath = filePath.replace('lib/scaffold.js', 'lib/' + hookName + '.js'); 35 | filePath = filePath.replace('bin/scaffold', 'bin/' + hookName); 36 | 37 | // 38 | // Replace any instances of the string 'scaffold' or 'Scaffold', 39 | // with new hook name 40 | // 41 | console.log(filePath); 42 | result = result.toString().replace(/scaffold/g, hookName); 43 | 44 | var className = hookName.substr(0, 1).toUpperCase() + hookName.substr(1, hookName.length); 45 | 46 | result = result.toString().replace(/Scaffold/g, className); 47 | 48 | (function(filePath) { 49 | mkdirp(path.dirname(filePath), 0755, function(err){ 50 | if(err){ 51 | console.log(err); 52 | callback(err); 53 | } 54 | fs.writeFile(filePath, result, function(err, result){ 55 | callback(err, result); 56 | }); 57 | }); 58 | })(filePath); 59 | }); 60 | } 61 | 62 | async.map(scaffold.files, copyFiles, function(err, results){ 63 | if (err) { 64 | return console.log(err); 65 | } 66 | console.log('Hook scaffold for ' + hookName.cyan + ' generated in ' 67 | + hookPath.grey + ''); 68 | if(callback) { 69 | callback(null); 70 | } 71 | }); 72 | }; 73 | 74 | 75 | module['exports'] = scaffold.generate; -------------------------------------------------------------------------------- /vendor/dnode-protocol/test/proto.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var proto = require('../'); 3 | var Traverse = require('traverse'); 4 | 5 | exports.protoHashes = function () { 6 | var server = proto({ 7 | x : function (f, g) { 8 | setTimeout(f.bind({}, 7, 8, 9), 50); 9 | setTimeout(g.bind({}, [ 'q', 'r' ]), 100); 10 | }, 11 | y : 555 12 | }); 13 | 14 | var client = proto({}); 15 | 16 | var s = server.create(); 17 | var c = client.create(); 18 | 19 | var sreqs = []; 20 | s.on('request', function (req) { 21 | sreqs.push(Traverse.clone(req)); 22 | c.handle(req); 23 | }); 24 | 25 | var creqs = []; 26 | c.on('request', function (req) { 27 | creqs.push(Traverse.clone(req)); 28 | s.handle(req); 29 | }); 30 | 31 | var tf = setTimeout(function () { 32 | assert.fail('never called f'); 33 | }, 5000); 34 | 35 | var tg = setTimeout(function () { 36 | assert.fail('never called g'); 37 | }, 5000); 38 | 39 | s.start(); 40 | 41 | assert.eql(sreqs, [ { 42 | method : 'methods', 43 | arguments : [ { x : '[Function]', y : 555 } ], 44 | callbacks : { 0 : [ '0', 'x' ] }, 45 | links : [], 46 | } ]); 47 | 48 | c.start(); 49 | 50 | assert.eql(creqs, [ { 51 | method : 'methods', 52 | arguments : [ {} ], 53 | callbacks : {}, 54 | links : [], 55 | } ]); 56 | 57 | c.request('x', [ 58 | function (x, y , z) { 59 | clearTimeout(tf); 60 | assert.eql([ x, y, z ], [ 7, 8, 9 ]); 61 | }, 62 | function (qr) { 63 | clearTimeout(tg); 64 | assert.eql(qr, [ 'q', 'r' ]); 65 | } 66 | ]); 67 | 68 | assert.eql(creqs.slice(1), [ { 69 | method : 'x', 70 | arguments : [ '[Function]', '[Function]' ], 71 | callbacks : { 0 : [ '0' ], 1 : [ '1' ] }, 72 | links : [], 73 | } ]); 74 | 75 | var tt = setTimeout(function () { 76 | assert.fail('broken json never emitted an error'); 77 | }, 5000); 78 | c.on('error', function (err) { 79 | clearTimeout(tt); 80 | assert.ok(err.stack); 81 | assert.ok(err.message.match(/^Error parsing JSON/)); 82 | assert.ok(err instanceof SyntaxError); 83 | }); 84 | c.parse('{'); 85 | }; 86 | -------------------------------------------------------------------------------- /vendor/dnode/examples/chat/entry.js: -------------------------------------------------------------------------------- 1 | var $ = require('jquery-browserify'); 2 | var dnode = require('dnode'); 3 | 4 | $(document).ready(function () { 5 | // Fetch the user's name before the main chat code fires 6 | $('form#name').submit(function (ev) { 7 | ev.preventDefault(); 8 | var name = $('input[name="name"]').val(); 9 | $('#messages').show(); 10 | $('#prompt').hide(); 11 | chat(name); 12 | }); 13 | }); 14 | 15 | function chat (name) { 16 | // Connect to the chat server now that we've got a name 17 | dnode(function () { 18 | this.name = name; 19 | 20 | this.joined = function (who) { 21 | addLine($('
') 22 | .addClass('join') 23 | .text(who + ' has joined') 24 | ); 25 | }; 26 | 27 | this.parted = function (who) { 28 | addLine($('
') 29 | .addClass('part') 30 | .text(who + ' has left') 31 | ); 32 | }; 33 | 34 | this.said = function (who,msg) { 35 | addLine($('
').append( 36 | $('') 37 | .addClass(who == name ? 'me' : 'who') 38 | .text('<' + who + '>') 39 | , 40 | $('').addClass('msg').text(msg) 41 | )); 42 | }; 43 | }).connect(function (remote) { 44 | $('form#post').submit(function (ev) { 45 | ev.preventDefault(); 46 | remote.say(this.elements.msg.value); 47 | this.elements.msg.value = ''; 48 | }); 49 | 50 | // fetch a list of all the connected users 51 | remote.names(function (names) { 52 | addLine($('
') 53 | .addClass('users') 54 | .text('Users: ' + ( 55 | names.map(function (name) { 56 | return '[ ' + name 57 | .replace(/\\/g,'\\\\') 58 | .replace(/\[/g,'\\[') 59 | .replace(/\]/g,'\\]') 60 | + ' ]' 61 | }).join(' ') 62 | || '(no users)' 63 | )) 64 | ); 65 | }); 66 | }); 67 | } 68 | 69 | function addLine(elem) { 70 | var div = $('#messages'); 71 | div.append(elem); 72 | div.animate({ scrollTop: div.attr('scrollHeight') }, 200); 73 | } 74 | -------------------------------------------------------------------------------- /test/logging/exception-handlers-test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * exception-handlers-test.js: Exception handlers logging tests for the hook.io module 3 | * 4 | * MIT LICENCE 5 | * 6 | */ 7 | 'use strict'; 8 | 9 | var vows, fs, assert, winston, Hook, hook, options; 10 | 11 | fs = require('fs'); 12 | vows = require('vows'); 13 | assert = require('assert'); 14 | winston = require('winston'); 15 | Hook = require('../../lib/hookio').Hook; 16 | 17 | options = { 18 | port : 5002, 19 | logger : { 20 | exceptionHandlers : { 21 | file : { filename : __dirname + "/err.log" } 22 | }, 23 | 24 | handleExceptions : true, 25 | exitOnError : false 26 | } 27 | }; 28 | 29 | vows.describe('hook.io/logging/exception-handlers').addBatch({ 30 | "Given a hook with logging configuration" : { 31 | topic : function() { 32 | return new Hook(options); 33 | }, 34 | 35 | "When a hook is ready" : { 36 | topic: function(hook) { 37 | var self; 38 | 39 | self = this; 40 | 41 | hook.on('hook::ready', function() { 42 | self.callback(null, this._winston); 43 | }); 44 | 45 | hook.start(); 46 | }, 47 | 48 | "It should convert the object into Winston exception handlers" : function(err, hookWinston) { 49 | var types, exceptionHandlers, name, capitalized; 50 | 51 | types = options.logger.exceptionHandlers; 52 | exceptionHandlers = hookWinston.exceptionHandlers; 53 | 54 | for (name in types) { 55 | // capitalize the name 56 | capitalized = name.charAt(0).toUpperCase() + name.substr(1); 57 | 58 | assert.instanceOf(exceptionHandlers[name], winston.transports[capitalized]); 59 | } 60 | } 61 | }, 62 | 63 | "When an uncaught exception is thrown" : { 64 | topic: function(hook) { 65 | var self = this; 66 | 67 | // can't really throw an error as vows will catch it, 68 | // so we simulate an uncaught exception 69 | hook._winston._uncaughtException(new Error('This error should be logged')); 70 | 71 | setTimeout(function() { 72 | // we first need to wait for the handler to timeout 73 | fs.readFile(hook.logger.exceptionHandlers.file.filename, 'utf-8', self.callback); 74 | }, 4000); 75 | }, 76 | 77 | "It should write to the specified log file" : function(err, data) { 78 | assert.ifError(err); 79 | assert.ok(/This error should be logged/.test(data)); 80 | 81 | fs.unlink(options.logger.exceptionHandlers.file.filename); 82 | } 83 | } 84 | } 85 | }).export(module); 86 | -------------------------------------------------------------------------------- /vendor/dnode/test/error.js: -------------------------------------------------------------------------------- 1 | var dnode = require('../'); 2 | var sys = require('sys'); 3 | var test = require('tap').test; 4 | 5 | test('errors', function (t) { 6 | t.plan(4); 7 | var port = Math.floor(Math.random() * 40000 + 10000); 8 | var errors = { server : [], client : [] }; 9 | 10 | var server = dnode(function (remote, conn) { 11 | conn.on('error', function (err) { 12 | errors.server.push(err); 13 | }); 14 | 15 | this.one = function () { 16 | throw 'string throw' 17 | }; 18 | 19 | this.two = function () { 20 | undefined.name 21 | }; 22 | 23 | this.three = function () { 24 | remote.pow(); 25 | }; 26 | }).listen(port); 27 | 28 | var ts = setTimeout(function () { 29 | t.fail('server never ended'); 30 | }, 5000); 31 | 32 | server.on('end', function () { 33 | clearTimeout(ts); 34 | t.deepEqual(errors.server[0], 'string throw'); 35 | 36 | try { undefined.name } 37 | catch (refErr) { 38 | process.nextTick(function () { 39 | t.equal(refErr.message, errors.server[1].message); 40 | t.equal(refErr.type, errors.server[1].type); 41 | t.equal(errors.server.length, 2); 42 | t.end(); 43 | }); 44 | } 45 | }); 46 | 47 | server.on('ready', function () { 48 | var client = dnode(function (client, conn) { 49 | conn.on('error', function (err) { 50 | errors.client.push(err); 51 | }); 52 | 53 | conn.on('end', function () { 54 | t.deepEqual(errors.client, [ 'Local error' ]); 55 | }); 56 | 57 | this.pow = function () { 58 | throw 'Local error'; 59 | }; 60 | }).connect(port, function (remote, conn) { 61 | remote.one(); 62 | remote.two(); 63 | remote.three(); 64 | 65 | setTimeout(function () { 66 | conn.end(); 67 | server.end(); 68 | server.close(); 69 | }, 500); 70 | }); 71 | }); 72 | }); 73 | 74 | test('refused', function (t) { 75 | t.plan(2); 76 | 77 | var port = Math.floor(Math.random() * 40000 + 10000); 78 | var client = dnode.connect(port, function (remote, conn) { 79 | assert.fail('should have been refused, very unlikely'); 80 | }); 81 | 82 | client.on('error', function (err) { 83 | t.equal(err.code, 'ECONNREFUSED'); 84 | t.equal(err.syscall, 'connect'); 85 | t.end(); 86 | }); 87 | }); 88 | -------------------------------------------------------------------------------- /vendor/dnode/examples/saturate/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 67 | 68 | 69 |
70 | 0 71 | bytes 72 | transferred 73 |
74 | 75 |
76 | ping X milliseconds 77 |
78 | 79 |
80 | 0 connections 81 |
82 | 83 | 84 | -------------------------------------------------------------------------------- /test/registry/complex-test.js: -------------------------------------------------------------------------------- 1 | var vows = require('vows'), 2 | assert = require('assert'), 3 | Hook = require('../../lib/hookio').Hook, 4 | macros = require('../helpers/macros'); 5 | 6 | // Dummy function for event subscription 7 | var emptyFn = function() {}; 8 | 9 | vows.describe('hook.io/registry/complex-test').addBatch({ 10 | "When a hook is listening on 5012": { 11 | topic: function() { 12 | var self = this, server = new Hook({ name: 'server', debug:true }); 13 | 14 | server.once('hook::ready', self.callback.bind(server, null, server)); 15 | server.on('eventBeforeStart', emptyFn); 16 | 17 | server.listen({ "hook-port": 5012 }); 18 | }, 19 | "and another hook connects": { 20 | topic: function(server) { 21 | server.on('eventAfterStart', emptyFn); 22 | server.on('eventAfterStart', emptyFn); 23 | server.on('eventToBeDestroyed', emptyFn); 24 | 25 | var client = new Hook({ name: 'client', debug:true }), self = this; 26 | client.once('hook::ready', function() { 27 | self.callback(null, server, client); 28 | }); 29 | client.on('eventBeforeStart', emptyFn); 30 | client.on('eventToBeDestroyed', emptyFn); 31 | 32 | client.connect({ "hook-port": 5012 }); 33 | }, 34 | "when my hook registers an event": { 35 | topic: function(server, client) { 36 | client.on('eventAfterStart', emptyFn); 37 | server.off('eventToBeDestroyed', emptyFn); 38 | client.off('eventToBeDestroyed', emptyFn); 39 | 40 | // Register a new "testEvent" 41 | client.on('testEvent', emptyFn); 42 | 43 | // Wait a bit for the event to propagate. 44 | // I'm not completely satisfied with this solution... 45 | setTimeout(this.callback.bind(this, null, server), 50); 46 | }, 47 | "then I have a the good events on the server": function(server) { 48 | // Server checks 49 | assert.ok(!server._names.server.events['hook::ready']); 50 | assert.strictEqual(server._names.server.events.eventBeforeStart, 1); 51 | assert.strictEqual(server._names.server.events.eventAfterStart, 2); 52 | assert.ok(!server._names.server.events.eventToBeDestroyed); 53 | }, 54 | "and I have the good events on the client": function(server) { 55 | // Client checks 56 | assert.ok(!server._names.client.events['hook::ready']); 57 | assert.strictEqual(server._names.client.events.testEvent, 1); 58 | assert.strictEqual(server._names.client.events.eventBeforeStart, 1); 59 | assert.strictEqual(server._names.client.events.eventAfterStart, 1); 60 | assert.ok(!server._names.client.events.eventToBeDestroyed); 61 | } 62 | } 63 | } 64 | } 65 | }).export(module); 66 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/test/fn.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var proto = require('../'); 3 | var Traverse = require('traverse'); 4 | var EventEmitter = require('events').EventEmitter; 5 | 6 | exports.protoFn = function () { 7 | var server = proto(function (remote, conn) { 8 | assert.ok(conn); 9 | assert.ok(conn instanceof EventEmitter); 10 | 11 | var tr = setTimeout(function () { 12 | assert.fail('never got ready event'); 13 | }, 5000); 14 | 15 | conn.on('ready', function () { 16 | clearTimeout(tr); 17 | assert.eql(remote, { a : 1, b : 2 }); 18 | }); 19 | 20 | this.x = function (f, g) { 21 | setTimeout(f.bind({}, 7, 8, 9), 50); 22 | setTimeout(g.bind({}, [ 'q', 'r' ]), 100); 23 | }; 24 | this.y = 555; 25 | }); 26 | 27 | var client = proto({ a : 1, b : 2 }); 28 | 29 | var s = server.create(); 30 | var c = client.create(); 31 | 32 | var sreqs = []; 33 | s.on('request', function (req) { 34 | sreqs.push(Traverse.clone(req)); 35 | c.handle(req); 36 | }); 37 | 38 | var creqs = []; 39 | c.on('request', function (req) { 40 | creqs.push(Traverse.clone(req)); 41 | s.handle(req); 42 | }); 43 | 44 | var tf = setTimeout(function () { 45 | assert.fail('never called f'); 46 | }, 5000); 47 | 48 | var tg = setTimeout(function () { 49 | assert.fail('never called g'); 50 | }, 5000); 51 | 52 | s.start(); 53 | 54 | assert.eql(sreqs, [ { 55 | method : 'methods', 56 | arguments : [ { x : '[Function]', y : 555 } ], 57 | callbacks : { 0 : [ '0', 'x' ] }, 58 | links : [], 59 | } ]); 60 | 61 | c.start(); 62 | 63 | assert.eql(creqs, [ { 64 | method : 'methods', 65 | arguments : [ { a : 1, b : 2 } ], 66 | callbacks : {}, 67 | links : [], 68 | } ]); 69 | 70 | c.request('x', [ 71 | function (x, y , z) { 72 | clearTimeout(tf); 73 | assert.eql([ x, y, z ], [ 7, 8, 9 ]); 74 | }, 75 | function (qr) { 76 | clearTimeout(tg); 77 | assert.eql(qr, [ 'q', 'r' ]); 78 | } 79 | ]); 80 | 81 | assert.eql(creqs.slice(1), [ { 82 | method : 'x', 83 | arguments : [ '[Function]', '[Function]' ], 84 | callbacks : { 0 : [ '0' ], 1 : [ '1' ] }, 85 | links : [], 86 | } ]); 87 | 88 | var tt = setTimeout(function () { 89 | assert.fail('broken json never emitted an error'); 90 | }, 5000); 91 | c.on('error', function (err) { 92 | clearTimeout(tt); 93 | assert.ok(err.stack); 94 | assert.ok(err.message.match(/^Error parsing JSON/)); 95 | assert.ok(err instanceof SyntaxError); 96 | }); 97 | c.parse('{'); 98 | }; 99 | -------------------------------------------------------------------------------- /test/siblings/multiple-messages-test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * multiple-messages-test.js: Test the ability to work with multiple hook and rather important message passing 3 | * to demonstrate some heavier network usage. 4 | * 5 | * This test suite init and start a server hook with a predefined number 6 | * of clients, emiting back and fourth the content of browser/hook.js (150kb). 7 | * 8 | * (C) 2011 Marak Squires, Charlie Robbins 9 | * MIT LICENCE 10 | * 11 | */ 12 | 13 | var vows = require('vows'), 14 | assert = require('assert'), 15 | fs = require('fs'), 16 | path = require('path'), 17 | Hook = require('../../lib/hookio').Hook, 18 | macros = require('../helpers/macros'), 19 | EventEmitter = require('events').EventEmitter; 20 | 21 | 22 | // 23 | // TODO: Update fixture with a large binary file, or something 24 | // 25 | var fixture = '', i; 26 | for (i = 0; i < 5000; i++) { 27 | fixture += '#'; 28 | } 29 | 30 | // create a local macro 31 | // TODO: see if it's better to put this in helpers/macros 32 | var macro = function (event, port) { 33 | 34 | var context = { 35 | topic: function (server, data) { 36 | var messager = new Hook({ name: 'simple-client-messager' }); 37 | 38 | server.once('*::' + event, function (data) { 39 | server.emit('foo::response.' + event, data); 40 | }); 41 | 42 | messager.once('*::response.' + event, this.callback.bind(server, null)); 43 | 44 | messager.once('hook::connected', function () { 45 | messager.emit(event, {content: fixture}); 46 | }); 47 | messager.connect({ 'hook-port': port }); 48 | 49 | } 50 | }; 51 | 52 | context["the *::" + event + " should be fired correctly"] = function (data) { 53 | assert.equal(data.content, fixture); 54 | }; 55 | 56 | return context; 57 | }; 58 | 59 | // creates a context with a preder 60 | macro.multipleSubscriber = function (prefix, count) { 61 | var context = {}, 62 | test = count; 63 | 64 | context["to listen with wildcard mapping"] = { 65 | topic: function () { 66 | var listener = new Hook({ name: 'simple-listener' }), 67 | self = this, 68 | length = count - 1; 69 | 70 | listener.on('*::test::*::*', function log () { 71 | if (--length === 0) self.callback(); 72 | }); 73 | listener.connect({ 'hook-port': 5052 }); 74 | 75 | }, 76 | 77 | "should be able to listen each of the emitted event": function () { 78 | assert.ok(true); 79 | } 80 | }; 81 | 82 | while(--test) { 83 | context["to emit *::" + prefix + test] = macro(prefix + test, 5052); 84 | } 85 | 86 | return context; 87 | }; 88 | 89 | 90 | // Start the batch with a with a predefined number of cycles 91 | vows.describe('hook.io/siblings/multiple-message').addBatch({ 92 | "When a hook is listening on 5050": macros.assertListen('simple-server', 5052, { 93 | "and another hooks connects": macro.multipleSubscriber('test::foo::', 10) 94 | }) 95 | }).export(module); 96 | 97 | -------------------------------------------------------------------------------- /lib/hookio/config.js: -------------------------------------------------------------------------------- 1 | /* 2 | * config.js: Module responsible for config actions. 3 | * 4 | * (C) 2011 Nodejitsu Inc. 5 | * MIT LICENCE 6 | * 7 | */ 8 | 9 | var nconf = require('nconf'), 10 | hookio = require('../hookio'), 11 | path = require('path'), 12 | argv = hookio.cli.argv; 13 | 14 | var config = exports.config = function (options) { 15 | var self = this; 16 | 17 | // 18 | // Each hook get's their own config.json file managed 19 | // by an instance of the `nconf.Provider`. 20 | // 21 | // Remark: This configuration path needs to load from a 22 | // default configuration file and then write to a custom 23 | // configuration file based on the hook `type/name` combo. 24 | // 25 | 26 | this.config = new nconf.Provider(); 27 | function useFileStore () { 28 | if (argv.config) { 29 | self.configFilePath = path.resolve(argv.config); 30 | } 31 | self.config.use('file', { file: self.configFilePath || './config.json' }); 32 | } 33 | 34 | if (options.redis) { 35 | // 36 | // Remark: try / catch is a hack for doing optional npm deps 37 | // 38 | // 39 | try { 40 | require('nconf-redis'); 41 | this.config.use('redis', options.redis); 42 | } catch(ex) { 43 | console.error("(node) warning: Missing nconf-redis module"); 44 | useFileStore(); 45 | } 46 | } else { 47 | useFileStore(); 48 | } 49 | 50 | this.config.load(); 51 | 52 | // 53 | // Load the nconf store into memory 54 | // 55 | var config = this.config.store.store; 56 | 57 | function checkProperty (key, value) { 58 | if(typeof value === "function") { 59 | throw new Error('You are attempting to override prototype method: "' + key + '". This is probably a bad idea.'); 60 | } 61 | } 62 | 63 | // 64 | // Iterate over nconf store and copy key values, 65 | // to Hook 66 | // 67 | Object.keys(config).forEach(function (o) { 68 | checkProperty(o, self[o]); 69 | self[o] = config[o]; 70 | }); 71 | 72 | // 73 | // Iterate over argv and copy key values, 74 | // to Hook ( overwriting duplicate keys from config ) 75 | // 76 | Object.keys(argv).forEach(function (o) { 77 | var reserved = ["hook-port", "hook-host"]; 78 | if (reserved.indexOf(o) === -1) { 79 | checkProperty(o, self[o]); 80 | self[o] = argv[o]; 81 | } 82 | }); 83 | 84 | // 85 | // Iterate over options and copy key values, 86 | // to Hook ( overwriting duplicate keys from argv and config ) 87 | // 88 | Object.keys(options).forEach(function (o) { 89 | checkProperty(o, self[o]); 90 | self[o] = options[o]; 91 | }); 92 | 93 | // 94 | // Remark: This is a hack for passing arrays of objects as strings, 95 | // through argv...fix this in optimist 96 | // 97 | if (typeof this.transports === 'string') { 98 | try { 99 | this.transports = JSON.parse(this.transports); 100 | } catch (err) { 101 | console.log('warn: bad transport parse', err.message); 102 | } 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/test/lib/deep_equal.js: -------------------------------------------------------------------------------- 1 | var traverse = require('../../'); 2 | 3 | module.exports = function (a, b) { 4 | if (arguments.length !== 2) { 5 | throw new Error( 6 | 'deepEqual requires exactly two objects to compare against' 7 | ); 8 | } 9 | 10 | var equal = true; 11 | var node = b; 12 | 13 | traverse(a).forEach(function (y) { 14 | var notEqual = (function () { 15 | equal = false; 16 | //this.stop(); 17 | return undefined; 18 | }).bind(this); 19 | 20 | //if (node === undefined || node === null) return notEqual(); 21 | 22 | if (!this.isRoot) { 23 | /* 24 | if (!Object.hasOwnProperty.call(node, this.key)) { 25 | return notEqual(); 26 | } 27 | */ 28 | if (typeof node !== 'object') return notEqual(); 29 | node = node[this.key]; 30 | } 31 | 32 | var x = node; 33 | 34 | this.post(function () { 35 | node = x; 36 | }); 37 | 38 | var toS = function (o) { 39 | return Object.prototype.toString.call(o); 40 | }; 41 | 42 | if (this.circular) { 43 | if (traverse(b).get(this.circular.path) !== x) notEqual(); 44 | } 45 | else if (typeof x !== typeof y) { 46 | notEqual(); 47 | } 48 | else if (x === null || y === null || x === undefined || y === undefined) { 49 | if (x !== y) notEqual(); 50 | } 51 | else if (x.__proto__ !== y.__proto__) { 52 | notEqual(); 53 | } 54 | else if (x === y) { 55 | // nop 56 | } 57 | else if (typeof x === 'function') { 58 | if (x instanceof RegExp) { 59 | // both regexps on account of the __proto__ check 60 | if (x.toString() != y.toString()) notEqual(); 61 | } 62 | else if (x !== y) notEqual(); 63 | } 64 | else if (typeof x === 'object') { 65 | if (toS(y) === '[object Arguments]' 66 | || toS(x) === '[object Arguments]') { 67 | if (toS(x) !== toS(y)) { 68 | notEqual(); 69 | } 70 | } 71 | else if (x instanceof Date || y instanceof Date) { 72 | if (!(x instanceof Date) || !(y instanceof Date) 73 | || x.getTime() !== y.getTime()) { 74 | notEqual(); 75 | } 76 | } 77 | else { 78 | var kx = Object.keys(x); 79 | var ky = Object.keys(y); 80 | if (kx.length !== ky.length) return notEqual(); 81 | for (var i = 0; i < kx.length; i++) { 82 | var k = kx[i]; 83 | if (!Object.hasOwnProperty.call(y, k)) { 84 | notEqual(); 85 | } 86 | } 87 | } 88 | } 89 | }); 90 | 91 | return equal; 92 | }; 93 | -------------------------------------------------------------------------------- /lib/hookio/query.js: -------------------------------------------------------------------------------- 1 | var hookio = require('./hook'), 2 | async = require('async'), 3 | path = require('path'); 4 | 5 | exports.query = function (params, callback) { 6 | 7 | // 8 | // Performs a query on the hook to get details about other hooks. 9 | // takes an object as first parameter, which should look like: 10 | // {name:'name-of-the-targetted-hook'} 11 | // or 12 | // {type:'type-of-the-targetted-hook'} 13 | // or 14 | // {host:'hostname-hosting-some-hook-or-its-IP'} 15 | // 16 | // the result can be received either as: 17 | // - a callback(error, details) if callback is provided as a standard callback 18 | // 19 | // * error parameter will be returned if result is empty 20 | // * details will be a String (or undefined) if we have queried by name 21 | // 22 | // - a query::out({query: originalQuery, details: arrayOfDetails}) event 23 | // if callback is not defined. 24 | // 25 | // * details is then always an Array of details, and if nothing is available 26 | // for the passed query, Array is just empty. 27 | // * query contains the original query, in order for your hook to check 28 | // it's one similar to what it was looking for, or not. 29 | // 30 | // Each details provided is of the form : 31 | // { 32 | // name: 'hook-name', 33 | // type:'hook-type', 34 | // remote:{ host:'ip address', port:99999/*port number*/} 35 | // } 36 | // 37 | 38 | var self = this; 39 | 40 | params = params || {}; 41 | var name = params.name, 42 | type = params.type, 43 | host = params.host; 44 | 45 | if (!self.server) { 46 | return; 47 | } 48 | 49 | if (typeof callback !== "function") { 50 | callback = function (err, details) { 51 | if (!Array.isArray(details)) { 52 | details = [details]; 53 | } 54 | return self.emit("query::out", {query: params, details: details})}; 55 | } 56 | if (name) { 57 | if (self._names[name]) { 58 | //console.log(callback); 59 | callback(null, self._names[name]); 60 | } 61 | else { 62 | callback(new Error("No hook named "+name+" is connected (anymore?)")); 63 | } 64 | } else if (type) { 65 | var details = Object.keys(self._names) 66 | .map(function (key) { if (self._names[key].type === type) return self._names[key]; }) 67 | .filter(function (detail) {return detail}); 68 | 69 | if (details.length>0) { 70 | callback(null, details); 71 | } else { 72 | callback(new Error("No hook of type "+type+" is connected (anymore?)"),[]); 73 | } 74 | 75 | } else if (host) { 76 | self.toIPs(host, function onIP(err, hosts) { 77 | var details = Object.keys(self._names).map(function getHooks(key) { 78 | if ( hosts.some( function hasHost (host) {return host === self._names[key].remote.host} ) ) 79 | return self._names[key]; 80 | }).filter(function (detail) {return detail}); 81 | 82 | if (details.length>0) 83 | callback(null, details); 84 | else 85 | callback(new Error("No hook for host "+host+" is connected (anymore?)"),[]); 86 | }); 87 | } 88 | 89 | }; -------------------------------------------------------------------------------- /test/registry/disconnection-test.js: -------------------------------------------------------------------------------- 1 | var vows = require('vows'), 2 | assert = require('assert'), 3 | Hook = require('../../lib/hookio').Hook, 4 | macros = require('../helpers/macros'); 5 | 6 | // Dummy function for event subscription 7 | var emptyFn = function() {}; 8 | 9 | vows.describe('hook.io/registry/complex-test').addBatch({ 10 | "When a hook is listening on 5013": { 11 | topic: function() { 12 | var self = this, server = new Hook({ name: 'server', debug:true }); 13 | 14 | server.once('hook::ready', self.callback.bind(server, null, server)); 15 | server.on('eventBeforeStart', emptyFn); 16 | 17 | server.listen({ "hook-port": 5013 }); 18 | }, 19 | "and another hook connects": { 20 | topic: function(server) { 21 | server.on('eventAfterStart', emptyFn); 22 | server.on('eventAfterStart', emptyFn); 23 | server.on('eventToBeDestroyed', emptyFn); 24 | 25 | var client = new Hook({ name: 'client', debug:true }), self = this; 26 | client.once('hook::ready', function() { 27 | self.callback(null, server, client); 28 | }); 29 | client.on('eventBeforeStart', emptyFn); 30 | client.on('eventToBeDestroyed', emptyFn); 31 | 32 | client.connect({ "hook-port": 5013 }); 33 | }, 34 | "when my hook registers an event": { 35 | topic: function(server, client) { 36 | client.on('eventAfterStart', emptyFn); 37 | server.off('eventToBeDestroyed', emptyFn); 38 | client.off('eventToBeDestroyed', emptyFn); 39 | 40 | // Register a new "testEvent" 41 | client.on('testEvent', emptyFn); 42 | 43 | // Wait a bit for the event to propagate. 44 | // I'm not completely satisfied with this solution... 45 | setTimeout(this.callback.bind(this, null, server, client), 50); 46 | }, 47 | "then I disconnect and reconnect the client": { 48 | topic: function(server, client) { 49 | var self = this; 50 | client.stop(function(err) { 51 | assert.ifError(err); 52 | client.connect({ "hook-port": 5013 }, self.callback.bind(self, null, server)); 53 | }); 54 | }, 55 | "then I have a the good events on the server": function(server) { 56 | // Server checks 57 | assert.ok(!server._names.server.events['hook::ready']); 58 | assert.strictEqual(server._names.server.events.eventBeforeStart, 1); 59 | assert.strictEqual(server._names.server.events.eventAfterStart, 2); 60 | assert.ok(!server._names.server.events.eventToBeDestroyed); 61 | }, 62 | "and I have the good events on the client": function(server) { 63 | // Client checks 64 | assert.ok(!server._names.client.events['hook::ready']); 65 | assert.strictEqual(server._names.client.events.testEvent, 1); 66 | assert.strictEqual(server._names.client.events.eventBeforeStart, 1); 67 | assert.strictEqual(server._names.client.events.eventAfterStart, 1); 68 | assert.ok(!server._names.client.events.eventToBeDestroyed); 69 | } 70 | } 71 | } 72 | } 73 | } 74 | }).export(module); 75 | -------------------------------------------------------------------------------- /vendor/EventEmitter2/test/simple/ttl.js: -------------------------------------------------------------------------------- 1 | var simpleEvents = require('nodeunit').testCase; 2 | 3 | var file = '../../lib/eventemitter2'; 4 | 5 | module.exports = simpleEvents({ 6 | 7 | setUp: function (callback) { 8 | var EventEmitter2; 9 | 10 | if(typeof require !== 'undefined') { 11 | EventEmitter2 = require(file).EventEmitter2; 12 | } 13 | else { 14 | EventEmitter2 = window.EventEmitter2; 15 | } 16 | 17 | this.emitter = new EventEmitter2(); 18 | callback(); 19 | }, 20 | 21 | tearDown: function (callback) { 22 | //clean up? 23 | callback(); 24 | }, 25 | 26 | '1. A listener added with `once` should only listen once and then be removed.': function (test) { 27 | 28 | var emitter = this.emitter; 29 | 30 | emitter.once('test1', function () { 31 | test.ok(true, 'The event was raised once'); 32 | }); 33 | 34 | emitter.emit('test1'); 35 | emitter.emit('test1'); 36 | 37 | test.expect(1); 38 | test.done(); 39 | 40 | }, 41 | '2. A listener with a TTL of 4 should only listen 4 times.': function (test) { 42 | 43 | var emitter = this.emitter; 44 | 45 | emitter.many('test1', 4, function (value1) { 46 | test.ok(true, 'The event was raised 4 times.'); 47 | }); 48 | 49 | emitter.emit('test1', 1); 50 | emitter.emit('test1', 2); 51 | emitter.emit('test1', 3); 52 | emitter.emit('test1', 4); 53 | emitter.emit('test1', 5); 54 | 55 | test.expect(4); 56 | test.done(); 57 | 58 | }, 59 | '3. A listener with a TTL of 4 should only listen 4 times and pass parameters.': function (test) { 60 | 61 | var emitter = this.emitter; 62 | 63 | emitter.many('test1', 4, function (value1, value2, value3) { 64 | test.ok(typeof value1 !== 'undefined', 'got value 1'); 65 | test.ok(typeof value2 !== 'undefined', 'got value 2'); 66 | test.ok(typeof value3 !== 'undefined', 'got value 3'); 67 | }); 68 | 69 | emitter.emit('test1', 1, 'A', false); 70 | emitter.emit('test1', 2, 'A', false); 71 | emitter.emit('test1', 3, 'A', false); 72 | emitter.emit('test1', 4, 'A', false); 73 | emitter.emit('test1', 5, 'A', false); 74 | 75 | test.done(); 76 | 77 | }, 78 | '4. Remove an event listener by signature.': function (test) { 79 | 80 | var emitter = this.emitter; 81 | var count = 0; 82 | 83 | function f1(event) { 84 | "event A"; 85 | test.ok(true, 'The event was raised less than 3 times.'); 86 | } 87 | 88 | emitter.on('test1', f1); 89 | 90 | function f2(event) { 91 | "event B"; 92 | test.ok(true, 'The event was raised less than 3 times.'); 93 | } 94 | 95 | emitter.on('test1', f2); 96 | 97 | function f3(event) { 98 | "event C"; 99 | test.ok(true, 'The event was raised less than 3 times.'); 100 | } 101 | 102 | emitter.on('test1', f3); 103 | 104 | emitter.removeListener('test1', f2); 105 | 106 | emitter.emit('test1'); 107 | 108 | test.expect(2); 109 | test.done(); 110 | 111 | }, 112 | '5. `removeListener` and `once`': function(test) { 113 | 114 | var emitter = this.emitter; 115 | var functionA = function() { test.ok(true, 'Event was fired'); }; 116 | 117 | emitter.once('testA', functionA); 118 | emitter.removeListener('testA', functionA); 119 | 120 | emitter.emit('testA'); 121 | 122 | test.expect(0); 123 | test.done(); 124 | } 125 | 126 | }); 127 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/node_modules/traverse/test/circular.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var Traverse = require('../'); 3 | var deepEqual = require('./lib/deep_equal'); 4 | var util = require('util'); 5 | 6 | exports.circular = function () { 7 | var obj = { x : 3 }; 8 | obj.y = obj; 9 | var foundY = false; 10 | Traverse(obj).forEach(function (x) { 11 | if (this.path.join('') == 'y') { 12 | assert.equal( 13 | util.inspect(this.circular.node), 14 | util.inspect(obj) 15 | ); 16 | foundY = true; 17 | } 18 | }); 19 | assert.ok(foundY); 20 | }; 21 | 22 | exports.deepCirc = function () { 23 | var obj = { x : [ 1, 2, 3 ], y : [ 4, 5 ] }; 24 | obj.y[2] = obj; 25 | 26 | var times = 0; 27 | Traverse(obj).forEach(function (x) { 28 | if (this.circular) { 29 | assert.deepEqual(this.circular.path, []); 30 | assert.deepEqual(this.path, [ 'y', 2 ]); 31 | times ++; 32 | } 33 | }); 34 | 35 | assert.deepEqual(times, 1); 36 | }; 37 | 38 | exports.doubleCirc = function () { 39 | var obj = { x : [ 1, 2, 3 ], y : [ 4, 5 ] }; 40 | obj.y[2] = obj; 41 | obj.x.push(obj.y); 42 | 43 | var circs = []; 44 | Traverse(obj).forEach(function (x) { 45 | if (this.circular) { 46 | circs.push({ circ : this.circular, self : this, node : x }); 47 | } 48 | }); 49 | 50 | assert.deepEqual(circs[0].self.path, [ 'x', 3, 2 ]); 51 | assert.deepEqual(circs[0].circ.path, []); 52 | 53 | assert.deepEqual(circs[1].self.path, [ 'y', 2 ]); 54 | assert.deepEqual(circs[1].circ.path, []); 55 | 56 | assert.deepEqual(circs.length, 2); 57 | }; 58 | 59 | exports.circDubForEach = function () { 60 | var obj = { x : [ 1, 2, 3 ], y : [ 4, 5 ] }; 61 | obj.y[2] = obj; 62 | obj.x.push(obj.y); 63 | 64 | Traverse(obj).forEach(function (x) { 65 | if (this.circular) this.update('...'); 66 | }); 67 | 68 | assert.deepEqual(obj, { x : [ 1, 2, 3, [ 4, 5, '...' ] ], y : [ 4, 5, '...' ] }); 69 | }; 70 | 71 | exports.circDubMap = function () { 72 | var obj = { x : [ 1, 2, 3 ], y : [ 4, 5 ] }; 73 | obj.y[2] = obj; 74 | obj.x.push(obj.y); 75 | 76 | var c = Traverse(obj).map(function (x) { 77 | if (this.circular) { 78 | this.update('...'); 79 | } 80 | }); 81 | 82 | assert.deepEqual(c, { x : [ 1, 2, 3, [ 4, 5, '...' ] ], y : [ 4, 5, '...' ] }); 83 | }; 84 | 85 | exports.circClone = function () { 86 | var obj = { x : [ 1, 2, 3 ], y : [ 4, 5 ] }; 87 | obj.y[2] = obj; 88 | obj.x.push(obj.y); 89 | 90 | var clone = Traverse.clone(obj); 91 | assert.ok(obj !== clone); 92 | 93 | assert.ok(clone.y[2] === clone); 94 | assert.ok(clone.y[2] !== obj); 95 | assert.ok(clone.x[3][2] === clone); 96 | assert.ok(clone.x[3][2] !== obj); 97 | assert.deepEqual(clone.x.slice(0,3), [1,2,3]); 98 | assert.deepEqual(clone.y.slice(0,2), [4,5]); 99 | }; 100 | 101 | exports.circMapScrub = function () { 102 | var obj = { a : 1, b : 2 }; 103 | obj.c = obj; 104 | 105 | var scrubbed = Traverse(obj).map(function (node) { 106 | if (this.circular) this.remove(); 107 | }); 108 | assert.deepEqual( 109 | Object.keys(scrubbed).sort(), 110 | [ 'a', 'b' ] 111 | ); 112 | assert.ok(deepEqual(scrubbed, { a : 1, b : 2 })); 113 | 114 | assert.equal(obj.c, obj); 115 | }; 116 | -------------------------------------------------------------------------------- /vendor/dnode/lib/stream_socketio.js: -------------------------------------------------------------------------------- 1 | var EventEmitter = require('events').EventEmitter; 2 | var Stream = require('stream').Stream; 3 | var io = require('socket.io'); 4 | var fs = require('fs'); 5 | 6 | var bundle = (function () { 7 | var cache = null; 8 | var file = __dirname + '/../browser/bundle.js'; 9 | 10 | return function (req, res) { 11 | if (cache) { 12 | res.setHeader('content-type', 'text/javascript'); 13 | res.setHeader('last-modified', cache.modified.toGMTString()); 14 | res.setHeader('date', new Date().toGMTString()); 15 | 16 | var ims = req.headers['if-modified-since']; 17 | if (ims) { 18 | var m = new Date(ims); 19 | if (m >= cache.modified) { 20 | res.statusCode = 304; 21 | res.end(); 22 | return; 23 | } 24 | } 25 | 26 | res.statusCode = 200; 27 | res.end(cache.source); 28 | } 29 | else fs.stat(file, function (err0, stat) { 30 | fs.readFile(file, function (err1, src) { 31 | if (err0 || err1) { 32 | var e = err0 || err1; 33 | console.error(e.message || e); 34 | res.statusCode = 500; 35 | res.setHeader('content-type', 'text/plain'); 36 | res.end('an error occured loading the bundle'); 37 | } 38 | else { 39 | cache = { 40 | source : src, 41 | modified : stat.mtime, 42 | }; 43 | bundle(req, res); 44 | } 45 | }); 46 | }); 47 | }; 48 | })(); 49 | 50 | module.exports = function (webserver, mount, ioOptions) { 51 | if (ioOptions['log level'] === undefined) { 52 | ioOptions['log level'] = -1; 53 | } 54 | 55 | var sock = io.listen(webserver, ioOptions); 56 | var server = new EventEmitter; 57 | 58 | if (mount && webserver.use) { 59 | webserver.use(function (req, res, next) { 60 | if (req.url.split('?')[0] === mount) { 61 | bundle(req, res); 62 | } 63 | else next() 64 | }); 65 | } 66 | else if (mount) { 67 | if (!webserver._events) webserver._events = {}; 68 | var ev = webserver._events; 69 | 70 | if (!ev.request) ev.request = []; 71 | if (!Array.isArray(ev.request)) ev.request = [ ev.request ]; 72 | 73 | ev.request.push(function (req, res) { 74 | if (!res.finished && req.url.split('?')[0] === mount) { 75 | bundle(req, res); 76 | } 77 | }); 78 | } 79 | 80 | sock.sockets.on('connection', function (client) { 81 | var stream = new Stream; 82 | 83 | stream.socketio = client; 84 | stream.readable = true; 85 | stream.writable = true; 86 | 87 | stream.write = client.send.bind(client); 88 | stream.end = stream.destroy 89 | = client.disconnect.bind(client.disconnect); 90 | 91 | client.on('message', stream.emit.bind(stream, 'data')); 92 | client.on('error', stream.emit.bind(stream, 'error')); 93 | 94 | client.on('disconnect', function () { 95 | stream.writable = false; 96 | stream.readable = false; 97 | stream.emit('end'); 98 | }); 99 | 100 | server.emit('connection', stream); 101 | }); 102 | 103 | return server; 104 | }; 105 | -------------------------------------------------------------------------------- /vendor/dnode-protocol/test/scrub.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var Scrubber = require('../').Scrubber; 3 | 4 | exports.noFuncs = function () { 5 | var s = new Scrubber; 6 | assert.eql( 7 | s.scrub([ 1, 2, 3 ]), 8 | { 9 | arguments : [ 1, 2, 3 ], 10 | callbacks : [], 11 | links : [], 12 | } 13 | ); 14 | 15 | assert.eql( 16 | s.scrub([ 4, { a : 5, b : 6 } ]), 17 | { 18 | arguments : [ 4, { a : 5, b : 6 } ], 19 | callbacks : [], 20 | links : [], 21 | } 22 | ); 23 | }; 24 | 25 | exports.funcs = function () { 26 | var s = new Scrubber; 27 | 28 | var calls = { f : 0, g : 0 }; 29 | var f = function () { calls.f ++ }; 30 | var g = function () { calls.g ++ }; 31 | 32 | var sc = s.scrub([ 1, 2, f, g ]); 33 | assert.eql(sc, { 34 | arguments : [ 1, 2, '[Function]', '[Function]' ], 35 | callbacks : { 0 : [ '2' ], 1 : [ '3' ] }, 36 | links : [], 37 | }); 38 | 39 | s.callbacks[0](); 40 | assert.eql(calls, { f : 1, g : 0 }); 41 | 42 | s.callbacks[1](); 43 | assert.eql(calls, { f : 1, g : 1 }); 44 | }; 45 | 46 | exports.link = function () { 47 | var s = new Scrubber; 48 | var x = [ [ 0, { a : 1, b : 2, c : 3 }, 4 ], 5, 6 ]; 49 | x[0][1].d = x[0][1]; 50 | var sc = s.scrub(x); 51 | 52 | assert.eql(sc, { 53 | arguments : [ 54 | [ 0, { a : 1, b : 2, c : 3, d : '[Circular]' }, 4 ], 5, 6 55 | ], 56 | callbacks : {}, 57 | links : [ { from : [ '0', '1' ], to : [ '0', '1', 'd' ] } ], 58 | }); 59 | }; 60 | 61 | exports.multilink = function () { 62 | var s = new Scrubber; 63 | var x = [ [ 0, { a : 1, b : 2, c : 3 }, 4 ], 5, 6 ]; 64 | x[0][1].d = x[0][1]; 65 | x.push(x); 66 | var sc = s.scrub(x); 67 | 68 | assert.eql(sc, { 69 | arguments : [ 70 | [ 0, { a : 1, b : 2, c : 3, d : '[Circular]' }, 4 ], 71 | 5, 6, '[Circular]' 72 | ], 73 | callbacks : {}, 74 | links : [ 75 | { from : [ '0', '1' ], to : [ '0', '1', 'd' ] }, 76 | { from : [], to : [ '3' ] }, 77 | ], 78 | }); 79 | }; 80 | 81 | exports.enumSetLink = function () { 82 | var s = new Scrubber; 83 | var req = { 84 | method : 0, 85 | arguments : [ 33, '[Function]' ], 86 | callbacks : { 0 : [ '1' ] }, 87 | links : [ { 88 | from : [ '0' ], 89 | to : [ '1', 'constructor', 'prototype', 'beep' ] 90 | } ] 91 | }; 92 | 93 | var args = s.unscrub(req, function (id) { 94 | return function () {}; 95 | }); 96 | assert.ok(!(function () {}).beep, 'created non-enumerable property'); 97 | }; 98 | 99 | exports.enumGetLink = function () { 100 | var s = new Scrubber; 101 | var req = { 102 | method : 0, 103 | arguments : [ 'doom', '[Function]' ], 104 | callbacks : { 0 : [ '1' ] }, 105 | links : [ { 106 | from : [ '1', 'constructor', 'prototype', 'toString' ], 107 | to : [ '0' ] 108 | } ] 109 | }; 110 | 111 | var args = s.unscrub(req, function (id) { 112 | return function () {}; 113 | }); 114 | 115 | assert.ok(args[0] === undefined); 116 | }; 117 | 118 | exports.skipSet = function () { 119 | var s = new Scrubber; 120 | var req = { 121 | method : 0, 122 | arguments : [ { x : 33 }, '[Function]' ], 123 | callbacks : { 0 : [ '1' ] }, 124 | links : [ { from : [ '0', 'x' ], to : [ '2' ] } ] 125 | }; 126 | 127 | var args = s.unscrub(req, function (id) { 128 | return function () {}; 129 | }); 130 | assert.equal(args[2], 33); 131 | }; 132 | --------------------------------------------------------------------------------