var Amoeba = require("amoeba.io");
var AmoebaLocalClient = require("amoeba.io-local-client");
var AmoebaSocketServer = require("amoeba.io-socket-server");
function Cube() {}
Cube.prototype.move = function(x, y) {
this.emit("moved", {
x: x,
y: y
});
};
var amoeba = new Amoeba();
amoeba.path("cube").as(new AmoebaLocalClient(new Cube()));
new AmoebaSocketServer(amoeba, {
port: "8092"
});
var amoeba = new Amoeba();
amoeba.path("cube").as(new SocketClient({
url: "http://localhost:8092"
}), function(err, result) {
if (err) return; //eror here
//listen event "moved"
amoeba.path("cube").on("moved", function(data, event, path) {
$('.cube').css({
"top": data.y,
"left": data.x
});
});
// set cube draggable
$(".cube").draggable({
drag: function(event, ui) {
var pos = ui.position;
amoeba.path("cube").invoke('move', pos.left, pos.top);
}
});
});
Open this page in two different browsers and move cube. Or will see if somebody move cube in this time.