Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a new example that seamlessly works across 2 different machines. #84

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
38 changes: 38 additions & 0 deletions test/listen.js
Original file line number Diff line number Diff line change
@@ -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())
34 changes: 34 additions & 0 deletions test/talk.js
Original file line number Diff line number Diff line change
@@ -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 (){})