Navigation Menu

Skip to content

Commit

Permalink
Client/Server event binding fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
matbee-eth committed Jun 15, 2012
1 parent 711bd7b commit bced481
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 36 deletions.
7 changes: 6 additions & 1 deletion client/test.js
@@ -1,4 +1,9 @@
var i = 0;
(function() {
console.log(i);
window.server.Execute("Hello", ["one","two","three"], function (fail, one, two, three) {
console.log(one);
console.log(two);
console.log(three);
i++;
});
})();
2 changes: 1 addition & 1 deletion client/test.template.html
@@ -1,5 +1,5 @@
<script type="text/html" id="TestTemplate">
<div>
<span>This is a sss.</span>
<span>This is a test.</span>
</div>
</script>
23 changes: 4 additions & 19 deletions server.js
Expand Up @@ -15,9 +15,9 @@ app.use(express.session({
key: 'express.sid'
}));

io.configure('development', function () {
io.set('log level', 2);
})
// io.configure('development', function () {
// io.set('log level', 2);
// })

app.get('/*', function (req, res) {
req.session.visitCount = req.session.visitCount ? req.session.visitCount + 1 : 1;
Expand Down Expand Up @@ -50,6 +50,7 @@ appServer.Hook('change', '#inputElement', function (event) {
this.get(
// Function executed on the client...
function () {
// alert("wtf");
return $('#inputElement').val();
},
// Server-side callback.
Expand All @@ -58,18 +59,6 @@ appServer.Hook('change', '#inputElement', function (event) {
}
);
});
appServer.WatchFiles(__dirname + '/client/index.html', function() {
// this.get(
// function() {

// },
// function () {

// }
// );
// this(function(){}, parameters, parameters, parameters, parameters...);

});

appServer.WatchFiles(__dirname + '/client/test.css', function() {

Expand All @@ -79,10 +68,6 @@ appServer.WatchFiles(__dirname + '/client/test.js', function() {

});

appServer.WatchFiles(__dirname + '/client/clientserver.js', function() {

});

appServer.WatchFiles(__dirname + '/client/test.template.html', function() {

});
31 changes: 16 additions & 15 deletions server/appserver.js
Expand Up @@ -13,24 +13,25 @@ var Server = function (io) {

self.__io = io;
self.__io.sockets.on('connection', function (socket) {
socket.on('Server.Methods', function (data) {
if (self.serverMethodQueue[data.callbackId]) {
socket.emit(data.callbackId, {duplicate: true});
for (var k in _hooks) {
var serverCallbackId = __randomString();
socket.emit('hook', {event: _hooks[k].event, element: _hooks[k].element, callbackId: serverCallbackId});

socket.on(serverCallbackId, function() {
var hook = new methodClass(socket);
_hooks[k].callback.apply(hook, [].slice.call(arguments));
});
}
else {
self.serverMethodQueue[data.callbackId] = {socket: socket, method: data.method, parameters: data.parameters};
self.Execute(data.method, data.parameters, data.callbackId);
for (var k in _hooks) {
var serverCallbackId = __randomString();
socket.emit('hook', {event: _hooks[k].event, element: _hooks[k].element, callbackId: serverCallbackId});
socket.on('Server.Methods', function (data) {
if (self.serverMethodQueue[data.callbackId]) {
socket.emit(data.callbackId, {duplicate: true});
}
else {
self.serverMethodQueue[data.callbackId] = {socket: socket, method: data.method, parameters: data.parameters};
self.Execute(data.method, data.parameters, data.callbackId);

socket.on(serverCallbackId, function() {
var hook = new methodClass(socket);
_hooks[k].callback.apply(hook, [].slice.call(arguments));
});
}
}
});
});
});

self.serverMethodQueue = [];
Expand Down

0 comments on commit bced481

Please sign in to comment.