Flotype / now

NowJS makes it easy to build real-time web apps using JavaScript
http://www.nowjs.com
MIT License
1.91k stars 175 forks source link

nowjs and calling client side function with function as parameter #120

Closed czajah closed 13 years ago

czajah commented 13 years ago

hello,

this is my server code


var sys = requi  re("sys");
var fs = require('fs');
var express = require('express');

var app = express.createServer();

app.get('/', function(req, res){
    res.writeHead(200, {"Content-Type":"text/html"});
    res.write(fs.readFileSync('issue_000.html').toString());
    res.end();
});

app.listen(3000);

var everyone = require("now").initialize(app);

everyone.now.runClientFunctionWithStringParameter = function(paramClientFunctionWithStringParameter)
{
    paramClientFunctionWithStringParameter("passed by server");
}

everyone.now.runClientFunctionWithFunctionParameter = function(paramClientFunctionWithFunctionParameter)
{
    sys.puts("runClientFunctionWithFunctionParameter()::1");

    var callbackFunction = function(){sys.puts("jupi!")};

    sys.puts("runClientFunctionWithFunctionParameter()::2");

    paramClientFunctionWithFunctionParameter(callbackFunction);

    sys.puts("runClientFunctionWithFunctionParameter()::3");
}

and client code

<html>
    <head>
        <script type="text/javascript" src="http://localhost:3000/nowjs/now.js"></script>
    </head>
    <body>
        <script type="text/javascript">
            now.ready(function()
            {
                now.runClientFunctionWithStringParameter(function(paramText){alert(paramText);});
                now.runClientFunctionWithFunctionParameter(function(paramCallbackFunction){paramCallbackFunction();});
            });
        </script>
    </body>
</html>

Call of now.runClientFunctionWithStringParameter(function(paramText){alert(paramText);}); works just fine - result is client alert window with text "passed by server".

But invocation of line now.runClientFunctionWithFunctionParameter(function(paramCallbackFunction){paramCallbackFunction();}); results on server with this error message:

9 Jul 18:57:08 - Your node instance does not have root privileges. This means that the flash XML policy file will be served inline instead of on port 843. This will slow down initial connections slightly.
9 Jul 18:57:08 - socket.io ready - accepting connections
9 Jul 18:57:23 - Initializing client with transport "websocket"
9 Jul 18:57:23 - Client 9094739998690784 connected
runClientFunctionWithFunctionParameter()::1
runClientFunctionWithFunctionParameter()::2
{ stack: [Getter/Setter],
  arguments: [ 'closureTimeout' ],
  type: 'not_defined',
  message: [Getter/Setter] }
ReferenceError: closureTimeout is not defined
    at /home/run/node_modules/now/lib/nowServerLib.js:212:11
    at Object.<anonymous> (/home/run/Projekty/poligon/nodejs/issue_000.js:30:5)
    at Object.<anonymous> (native)
    at Object.remoteCall (/home/run/node_modules/now/lib/nowServerLib.js:90:19)
    at [object Object].<anonymous> (/home/run/node_modules/now/lib/nowServerLib.js:288:46)
    at [object Object].emit (events.js:64:17)
    at [object Object]._onMessage (/home/run/node_modules/now/node_modules/socket.io/lib/socket.io/client.js:58:10)
    at Parser.<anonymous> (native)
    at Parser.emit (events.js:64:17)
    at Parser.parse (/home/run/node_modules/now/node_modules/socket.io/lib/socket.io/transports/websocket.js:195:12)
steveWang commented 13 years ago

Hi czajah, I think this issue has been fixed in the version of NowJS currently on npm. See if reinstalling fixes your problem.

czajah commented 13 years ago

you're right