

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)
    });


@@ -38,22 +38,16 @@
 r server
-Domain
  = dual(
@@ -55,25 +55,19 @@
 ;%0Avar al
-lenDomain
+ice
  = dual(
@@ -76,33 +76,29 @@
 %0A%0Aserver
-Domain
 %0A    .
-hos
+moun
 t(
+%5B
 'greetin
@@ -103,45 +103,22 @@
 ing'
-)%0A    .host('english')%0A    .endpoint(
+, 'english'%5D, 
 %7B%0A  
@@ -136,38 +136,28 @@
 : function (
-to, from, body
+ctxt
 ) %7B%0A        
@@ -164,40 +164,25 @@
     
-this.root.send(from, %5B%5D, 
+ctxt.reply(
 'Hello
-.
 ');%0A
@@ -216,38 +216,28 @@
 : function (
-to, from, body
+ctxt
 ) %7B%0A        
@@ -244,41 +244,27 @@
     
-this.root.send(from, %5B%5D, 
+ctxt.reply(
 'Goodbye
 .');
@@ -259,17 +259,16 @@
 'Goodbye
-.
 ');%0A    
@@ -292,25 +292,21 @@
 rver
-Domain
 %0A    .
-hos
+moun
 t(
+%5B
 'gre
@@ -315,46 +315,23 @@
 ing'
-)%0A    .host('francais')%0A    .endpoint(
+, 'francais'%5D, 
 %7B%0A  
@@ -349,38 +349,28 @@
 : function (
-to, from, body
+ctxt
 ) %7B%0A        
@@ -377,41 +377,27 @@
     
-this.root.send(from, %5B%5D, 
+ctxt.reply(
 'Bonjour
 .');
@@ -392,17 +392,16 @@
 'Bonjour
-.
 ');%0A    
@@ -439,22 +439,12 @@
 on (
-to, from, body
+ctxt
 ) %7B%0A
@@ -459,33 +459,19 @@
     
-this.root.send(from, %5B%5D, 
+ctxt.reply(
 'Au 
@@ -476,17 +476,16 @@
 u revoir
-.
 ');%0A    
@@ -494,83 +494,177 @@
   %7D%0A
+    
 %7D);%0A%0A
+%0A
 server
-Domain.connect('clientAllen', allenDomain);%0AallenDomain.connec
+%0A    .mount(%5B'alice', '**'%5D, function (ctxt) %7B%0A        alice.send(ctxt.to.slice(1), %5B'server'%5D.concat(ctxt.from), ctxt.body);%0A    %7D);%0A%0Aalice%0A    .moun
 t(
+%5B
 'ser
@@ -673,35 +673,127 @@
 r', 
-serverDomain);%0A%0AallenDomain
+'**'%5D, function (ctxt) %7B%0A        server.send(ctxt.to.slice(1), %5B'alice'%5D.concat(ctxt.from), ctxt.body);%0A    %7D);%0A%0A%0Aalice
 %0A   
@@ -843,32 +843,28 @@
 llo'%5D)%0A    .
-response
+then
 (function (f
@@ -858,34 +858,28 @@
 n(function (
-from, body
+ctxt
 ) %7B%0A        
@@ -890,22 +890,26 @@
 ole.log(
+ctxt.
 body)
-;
 %0A    %7D);
@@ -916,17 +916,11 @@
 %0A%0Aal
-lenDomain
+ice
 %0A   
@@ -981,37 +981,299 @@
    .
-response(function (from, body
+then(function (ctxt) %7B%0A        console.log(ctxt.body);%0A    %7D);%0A%0A%0Aserver%0A    .mount(%5B'greetcast'%5D, dual.broadcaster(function (ctxt, allow) %7B%0A        allow(true);%0A    %7D));%0A%0Aalice%0A    .live(%5B'server', 'greetcast'%5D)%0A    .then(function (greetcast) %7B%0A        greetcast.on('message', function (ctxt
 ) %7B%0A
@@ -1272,32 +1272,36 @@
 ctxt) %7B%0A        
+   
+ 
 console.log(body
@@ -1296,21 +1296,132 @@
 ole.log(
-body)
+'broadcast: ', ctxt.body);%0A        %7D);%0A        server%0A            .send(%5B'greetcast', 'broadcast'%5D, %5B%5D, 'HELLOOOO');
 %0A    %7D);

Add simple2 example demonstrating communication between separate domains.