diff --git a/README.md b/README.md index 7c1ec3b..7559aa3 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ var App = SecretStack({ appKey: '1KHLiKZvAvjbY1ziZEHMXawbCEIM6qwjCDm3VYRan/s=' } var app = App(config) ``` +See also: [`talk.js`](./examples/talk.js) and [`listen.js`](./examples/listen.js) For documentation on plugins, see [PLUGINS.md](./PLUGINS.md). diff --git a/test/listen.js b/test/listen.js new file mode 100644 index 0000000..6630a57 --- /dev/null +++ b/test/listen.js @@ -0,0 +1,38 @@ +// On one server use: node listen.js +// On another server use: node talk.js +var crypto = require('crypto') +var SecretStack = require('../lib') +var seeds = require('./seeds') + +// deterministic keys make testing easy. +function hash (s) { + return crypto.createHash('sha256').update(s).digest() +} + +var appkey = hash('test_key') + +var create = SecretStack({ + appKey: appkey +}).use({ + manifest: { + hello: 'sync' + }, + permissions: { + anonymous: { allow: ['hello'], deny: null } + }, + init: function (api) { + return { + hello: function (name) { + return 'Hello, ' + name + '.' + } + } + } +}) + +var bob = create({ seed: seeds.bob }) + bob.on('rpc:connect', function (rpc, isClient) { + console.log(rpc.stream.address.substr(0, 4)) + console.log(rpc.stream.address.length) + }) + +console.log(bob.address()) diff --git a/test/talk.js b/test/talk.js new file mode 100644 index 0000000..7f0be07 --- /dev/null +++ b/test/talk.js @@ -0,0 +1,34 @@ +// First start the server usign node talk.js +// Note the computer's IP address and port and change the alice.connect +// comman accordingly +var Illuminati = require('../') +var crypto = require('crypto') +var seeds = require('./seeds') + +//deterministic keys make testing easy. +function hash (s) { + return crypto.createHash('sha256').update(s).digest() +} + +var appkey = hash('test_key') + +var create = Illuminati({ + appKey: appkey, +}).use({ + manifest: { + hello: 'sync' + }, + permissions: { + anonymous: { allow: ['hello'], deny: null } + }, + init: function (api) { + return { + hello: function (name) { + return 'Hello, ' + name + '.' + } + } + } +}) + +var alice = create({ seed: seeds.alice }) +alice.connect("net:10.0.1.52:57691~shs:bob3PzV+FJy8Xs6TtRBbWPhnOi53Brp7A+AG66XsJCY=", function (){})