

var dual = require('../index');

var serverDomain = dual();
var allenDomain = dual();

serverDomain
    .host('greeting')
    .host('english')
    .endpoint({
        hello: function (to, from, body) {
            this.root.send(from, [], 'Hello.');
        }
        , goodbye: function (to, from, body) {
            this.root.send(from, [], 'Goodbye.');
        }
    });

serverDomain
    .host('greeting')
    .host('francais')
    .endpoint({
        hello: function (to, from, body) {
            this.root.send(from, [], 'Bonjour.');
        }
        , goodbye: function (to, from, body) {
            this.root.send(from, [], 'Au revoir.');
        }
});

serverDomain.connect('clientAllen', allenDomain);
allenDomain.connect('server', serverDomain);

allenDomain
    .get(['server', 'greeting', 'english', 'hello'])
    .response(function (from, body) {
        console.log(body);
    });

allenDomain
    .get(['server', 'greeting', 'francais', 'goodbye'])
    .response(function (from, body) {
        console.log(body)
    });




var dual = require('../index');

var server = dual();
var alice = dual();

server
    .mount(['greeting', 'english'], {
        hello: function (ctxt) {
            ctxt.reply('Hello');
        }
        , goodbye: function (ctxt) {
            ctxt.reply('Goodbye');
        }
    });

server
    .mount(['greeting', 'francais'], {
        hello: function (ctxt) {
            ctxt.reply('Bonjour');
        }
        , goodbye: function (ctxt) {
            ctxt.reply('Au revoir');
        }
    });


server
    .mount(['alice', '**'], function (ctxt) {
        alice.send(ctxt.to.slice(1), ['server'].concat(ctxt.from), ctxt.body);
    });

alice
    .mount(['server', '**'], function (ctxt) {
        server.send(ctxt.to.slice(1), ['alice'].concat(ctxt.from), ctxt.body);
    });


alice
    .get(['server', 'greeting', 'english', 'hello'])
    .then(function (ctxt) {
        console.log(ctxt.body)
    });

alice
    .get(['server', 'greeting', 'francais', 'goodbye'])
    .then(function (ctxt) {
        console.log(ctxt.body);
    });


server
    .mount(['greetcast'], dual.broadcaster(function (ctxt, allow) {
        allow(true);
    }));

alice
    .live(['server', 'greetcast'])
    .then(function (greetcast) {
        greetcast.on('message', function (ctxt) {
            console.log('broadcast: ', ctxt.body);
        });
        server
            .send(['greetcast', 'broadcast'], [], 'HELLOOOO');
    });


Add simple2 example demonstrating communication between separate domains.