Git Product home page Git Product logo

now's Introduction

###NowJS makes realtime web apps really easy.

Go to Github or Download the master tgz

Install From npm

npm install now or npm install now -g to install globally

NowJS is a Node.js module. The client javascript (now.js) is served by the NowJS server.

NowJS uses the excellent socket.io and node-proxy libraries.

2 Step Setup

1. On the server

var httpServer = require('http').createServer(function(req, response){ /* Serve your static files */ })
httpServer.listen(8080);

var nowjs = require("now");
var everyone = nowjs.initialize(httpServer);

everyone.now.logStuff = function(msg){
    console.log(msg);
}

2. On the client


<script type="text/javascript" src="http://localhost:8080/nowjs/now.js"></script>

<script type="text/javascript">
  now.ready(function(){
    // "Hello World!" will print on server
    now.logStuff("Hello World!");
  });
</script>

FAQ

Q: Can I pass in a callback or closure, for example, if the remote function is asynchronous?

A: Yes. This is 100% supported

Q: How do I use NowJS with Express?

A: Very easily.

var app = express.createServer();
var server = app.listen(3000);
var everyone = require("now").initialize(server);

Q: How do I disable WebSockets or only use xhr-polling?

A: You can specifiy exactly which transports to use as an initialization options as follows:

var nowjs = require("now");
var everyone = nowjs.initialize(yourHttpServer, {socketio: {transports: ['xhr-polling', 'jsonp-polling']}});

*Q: Error: " SyntaxError: Unexpected token " / Can I statically host the now.js file?

A: On the client side, make sure you link to now.js like this

 <script src="http://myserver:myport/nowjs/now.js"></script>

You do not need to host the file /nowjs/now.js. It is automatically hosted by the NowJS using the http server you pass into the .initialize(...) in your server code. If you choose to host now.js yourself, you can, but do not use the version in github repo you MUST save the file at http://myserver:myport/nowjs/now.js and host that, because it is automatically configured for your server.

Further Reading

Now that you have NowJS, try the NowJS User Manual and Quick Chat Example

Have more questions? Please contact us: Email: [email protected]

IRC: #nowjs on freenode

Twitter: @NowJSTeam

now's People

Contributors

dcolens avatar ericz avatar jnordberg avatar josiah avatar mrienstra avatar sharadmv avatar sridatta avatar stevewang avatar zachwe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

now's Issues

possible event emitter leak

on Mac, Safari - I run the Express chat demo - create two users, send no messages... and wait a few minutes... to see the following warning message

$ node app
Express server listening on port 8080
8 Apr 00:08:52 - 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.
8 Apr 00:08:52 - socket.io ready - accepting connections
8 Apr 00:08:57 - Initializing client with transport "xhr-polling"
8 Apr 00:08:57 - Client 1566290301270783 connected
Joined: undefined
8 Apr 00:09:36 - Initializing client with transport "websocket"
8 Apr 00:09:36 - Client 3758795636240393 connected
Joined: user1
8 Apr 00:10:25 - Initializing client with transport "websocket"
8 Apr 00:10:25 - Client 6171762924641371 connected
Joined: user2
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace:
at Socket. (events.js:123:17)
at [object Object]. (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/client.js:83:20)
at [object Object]._onConnect (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/xhr-polling.js:23:35)
at [object Object].check (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/listener.js:77:12)
at HTTPServer. (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/listener.js:33:14)
at HTTPServer.emit (events.js:67:17)
at HTTPParser.onIncoming (http.js:1108:12)
at HTTPParser.onHeadersComplete (http.js:108:31)
at Socket.ondata (http.js:1007:22)
at Socket._onReadable (net.js:678:27)
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace:
at Socket. (events.js:123:17)
at [object Object]. (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/client.js:70:19)
at [object Object]._onConnect (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/xhr-polling.js:23:35)
at [object Object].check (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/listener.js:77:12)
at HTTPServer. (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/listener.js:33:14)
at HTTPServer.emit (events.js:67:17)
at HTTPParser.onIncoming (http.js:1108:12)
at HTTPParser.onHeadersComplete (http.js:108:31)
at Socket.ondata (http.js:1007:22)
at Socket._onReadable (net.js:678:27)

Expose socket.io request object

In order to tie now clients to the browsing session, it would be nice to have access to the request object and thus to the client's cookies.

undefined arguments

Hi!

L#181 nowServerLib.js -- bad things happen if theArgs[i] is null/undefined/non-object

--Vladimir

Bug: high latency when sending uploaded chunks back to now.js client

Test case:
https://gist.github.com/918288

Description:
Run this: sudo node uploadNowTest.js -> go to http://localhost:3000 in the browser. Select a semi-large file (eg. 3MB) --> upload. When removing the now.js broadcast, this is instant (as it should be, because this is localhost with 0 latency). When broadcasting the message with now.js, it takes about 5 seconds or so.

Expected behaviour:

  1. since this is run on the local host, the upload and broadcast to now.js client should be almost instant

This behaviour is seen when the now.js broadcast is removed.

However, when not removing the now.js broadcast it takes about 5 seconds. Please run the test case.

Now.js client-side disconnect with Flash open file dialog

This bug may be related to Flash.

When a client is connected to the server, it will disconnect when opening a Flash based file browser / file open dialog for more than about 5 seconds. This does not happen with a HTML5 file browser, only with the flash file browser.

This bug occurs every time to me on Chrome 10.0.648.133 (77742) with Ubuntu 10.10.

no way to set priority of and/or disable socket.io transport types

Some developers will want a different priority of transport types.

Others will want to completely disable certain methods as they would be too laggy for the application to function or ask too much from the server.

Thus, it has to be possible to set this transport order and disable certain transports completely.

Node 2 Node Connections?

Hi, is it intended to support Client-Server connections between multiple Node Instances in the future? this would really be a great feature for Clustering and alike :)

now.ready is not a Function (Firefox 3.6.16 - Firefox for Ubuntu, canonical 1.0)

Hi guys,

first of all congratulations for your work, this is really awesome! =)

We at my workplace are developing with a small chat and a map that can be edited and in Firefox 3.6.16 for Ubuntu I am getting an error that states:

now.ready is not a function.

The strange thing is that this is working in Google Chrome in the same machine and with the same server.

In Firefox 4 in Mac OSx it seems to be working alright.

Any idea of what might be wrong? Cheers!

flashing

Hi!

At initial page load regardless of used socket.io transport an embedded flash object appears and then disappeares, causing unpleasant flashing. Wonder if this is pure socket.io issue?

TIA,
--Vladimir

Add ability for server to address client

Maybe this exists and I couldn't find it, but ...

Also, apologies. This is a feature request without any code to go with it... Lemme know if you'd prefer code...

Whenever I use a Socket.IO-esque framework, I need the server to be able to address the client directly. In NowJS, it looks as though the server can speak directly to the client only in response to a client connection.

Maybe, Google Analytics Async style, the client could pre-declare 'now' with a client_id (I've also added a roomID since it's :

var now = {clientID : 'I-am-a-string-with-the-client-id',
                roomID: 'I-am-a-string-with-the-room-id' };
// NowJS initializes and uses the existing 'now' var.

Now the server can directly communicate with that client:

everyone.client('I-am-a-string-with-the-client-id').directMessage(fromUser, message);
everyone.room('I-am-a-string-with-the-room-id').partyLine(fromUser, message);

Feature request: callback for when all everyone.now.methods have executed

I'm in this situation: I have an incoming stream and receive a chunk. I wish to send this chunk to all now.js clients, but need to pause the stream until all clients have received the chunk.

I can do something like this:

client:

    now.receiveFileChunk = function(id, chunk, cb) {
         //on success
         cb();
    };

and on the server:

 clientsCount = //somehow get ammount of clients here (is this possible?)
 receivedCount = 0;

 stream.pause();
 everyone.now.receiveFileChunk(id, chunk, function() {
      receivedCount++;
      if (receivedCount == clientsCount) stream.resume();
 });

But:

  1. I do not know if it is even possible to get the amount of clients connected
  2. This does not seem like a proper solution

I'm not 100% sure, but it might be a good idea to add a callback to remote function calls for when all clients have received this method. I'm not sure of the implications and overhead involved though...

Feature request: everyone.now.exclude([clientId]).someMethod functionality

A very common scenario is where you'd want to broadcast to all clients in a group except for the client that sent the initial message.

For example, in a chat application, when a user sends a message he does not need to know from the server that he actually sent this message. Thus, the client can add this message locally. However, the server does have to send this message to all clients except for the originating client. This is just an example.

It would make no sense to copy all clients to a new group except for that originating client, thus I propose the following exclude style:

everyone.now.exclude([clientId1, clientId2]).someMethod

which would work exactly the same as:

everyone.now.someMethod

with the exception that clientId1 and clientId2 are excluded.

Thoughts?

Problem initializing "now" on dom ready

Consider the following client code:

<script type="text/javascript" charset="utf-8">
now.listen = function(msg) {
  alert(msg);
}

$(document).ready(function() {
  now.send("Ha");
});
</script>

and the following server code:

everyone.now.send = (msg) ->
  everyone.now.listen msg

Upon page load, I should see an alert box popup and display "Ha". Unfortunately, this does not happen, and I get the following error in the browser console:

Uncaught TypeError: Object #<Object> has no method 'send'

If I change the client side code to:

$(document).ready(function() {
  setTimeout(function(){now.send("Ha");},1000)
});

The alert box successfully shows up and displays "Ha".

This means that nowjs does not (completely) initialize upon dom ready, requiring a few extra moments to work. This is a problem for applications that depend on nowjs behavior upon dom initialization, and setTimeout seems too hacky a work'a'round.

no way to interrupt incoming messages (eg. data of a remote function call)

If a client calls a remote function on the server, there is no way to interrupt this stream of data from the client to the server.

In essence, a function call acts "synchronous" because the server waits for the clients to finish sending all parameters and then executes it on the server.

This means that a client can send huge piles of data within a function to a server, causing the stream to take up way too many resources and be too time intensive.

Thus, it has to be possible to validate incoming streams and be able to kill the connection if too much data is being send.

NowJS is improperly served when it is injected after the document has loaded.

If you include the /nowjs/now.js script in the HTML, everything works fine. The problem arises if you want to inject the script after the page has loaded for some reason.

Suggested fix in lib/nowServerLib.js at line 289

-      if(request.url === "/nowjs/now.js") {
+      if(request.url.split('?')[0] === "/nowjs/now.js") {

express chat example occasional missing/double messages

this may be a duplicate of pbcomm's issue #36.

the following behaviour happens infrequently - i've not been able to establish what triggers it. i'm using 0.5.0 w Safari

  1. after starting the express example, create user1 and send a message "hi"
  2. create user2 and send a message from it: "ho"

if the bug is happening -
3) the "ho" message doesn't appear in user1's window
4) subsequent messages from both user1 and user2 appear twice in user1's window

now.ready

Hi!

Opera/9.80 (X11; Linux i686; U; ru) Presto/2.7.62 Version/11.01

Resulting now.js, L671 -- here can be ready == null -- this causes exception.
If I try/catch this line, now.ready handler is called twice.

TIA,
--Vladimir

Client disconnect?

Hey, I unfortunately don't have a great deal of replication information around this but I did grab the stack trace from Node. I was running the chat demo (which is awesome) and I noticed every once in a while one of the clients would disconnect. It would continue to publish updates, but not receive them (which I found odd). It did occur at the same time as this stack trace:

{ stack: [Getter/Setter],
arguments: [ 'hasOwnProperty', undefined ],
type: 'non_object_property_call',
message: [Getter/Setter] }
TypeError: Cannot call method 'hasOwnProperty' of undefined
at Object.getVarFromFqn (/usr/local/lib/node/.npm/now/0.3.1/package/lib/nowUtil.js:86:18)
at Object.remoteCall (/usr/local/lib/node/.npm/now/0.3.1/package/lib/nowServerLib.js:55:31)
at [object Object]. (/usr/local/lib/node/.npm/now/0.3.1/package/lib/nowServerLib.js:273:48)
at [object Object].emit (events.js:64:17)
at [object Object]._onMessage (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/client.js:58:10)
at Parser. (native)
at Parser.emit (events.js:64:17)
at Parser.parse (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/websocket.js:195:12)
at Parser.add (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/websocket.js:182:8)
at Socket. (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/websocket.js:116:17)
{ stack: [Getter/Setter],
arguments: [ 'hasOwnProperty', undefined ],
type: 'non_object_property_call',
message: [Getter/Setter] }
TypeError: Cannot call method 'hasOwnProperty' of undefined
at Object.getVarFromFqn (/usr/local/lib/node/.npm/now/0.3.1/package/lib/nowUtil.js:86:18)
at Object.remoteCall (/usr/local/lib/node/.npm/now/0.3.1/package/lib/nowServerLib.js:55:31)
at [object Object]. (/usr/local/lib/node/.npm/now/0.3.1/package/lib/nowServerLib.js:273:48)
at [object Object].emit (events.js:64:17)
at [object Object]._onMessage (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/client.js:58:10)
at Parser. (native)
at Parser.emit (events.js:64:17)
at Parser.parse (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/websocket.js:195:12)
at Parser.add (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/websocket.js:182:8)
at Socket. (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/websocket.js:116:17)
{ stack: [Getter/Setter],
arguments: [ 'hasOwnProperty', undefined ],
type: 'non_object_property_call',
message: [Getter/Setter] }
TypeError: Cannot call method 'hasOwnProperty' of undefined
at Object.getVarFromFqn (/usr/local/lib/node/.npm/now/0.3.1/package/lib/nowUtil.js:86:18)
at Object.remoteCall (/usr/local/lib/node/.npm/now/0.3.1/package/lib/nowServerLib.js:55:31)
at [object Object]. (/usr/local/lib/node/.npm/now/0.3.1/package/lib/nowServerLib.js:273:48)
at [object Object].emit (events.js:64:17)
at [object Object]._onMessage (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/client.js:58:10)
at Parser. (native)
at Parser.emit (events.js:64:17)
at Parser.parse (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/websocket.js:195:12)
at Parser.add (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/websocket.js:182:8)
at Socket. (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/websocket.js:116:17)

remote callback not being called

SERVER

everyone.now.getData = function(callback) {
callback(getData())
}

CLIENT

now.ready(function() {
    now.getData(function(data) {
        fillTree(treePanel.getRootNode(), data);
    })
})

I took a wireshark trace and I see the instructions to call the callback (I think) but the callback never gets called. The documentation does not cover this well.

revoke vars/functions

Hi!

Sorry if I missed this in the docu, but how do I unset variables/functions in client context?
delete this.now.foo causes segfault, this.now.foo = undefined/null causes bump at L208 of nowServerLib.js

update: this.now.foo = false works, but still...

TIA,
--Vladimir

Doesn't seem to work with Android's web browser (tested in the emulator)

I just published a blog article where I built a simple chat application using NowJS and JQuery Mobile. I noticed it worked fine in Chrome and Firefox but doesn't work in the Android Web Browser (emulator). I then tried the example code from the nowjs repository and that didn't work either in the Android emulator (the initial prompt never shows up). I think this is tied into how the now.js file is sent (based upon warnings from Chrome) but I'm not sure.

You can see the code I used for the chat demo here: http://www.giantflyingsaucer.com/blog/?p=2535

Chad Lung

Firefox won't work again until restarted on server restart

Firefox mac 3.5.3.

steps to reproduce

  • use the example
  • works perfect
  • restart the server
  • refresh chrome, all good, app restarts
  • refresh firefox, nothing works anymore, dead.

the server still receives the messages and broadcasts them but it doesn't get passed to firefox. Firefox needs to be entirely quit and started again.

I realize this is probably a problem with firefox and sockets. it's pretty flimsy though.

use node event system

Instead of everyone.connected(function() { }); use the node event system so that people can do everyone.on('connected') etc.

This has several advantages:

- consistent with node style

- allows unregistering event listeners

- allows multiple listeners

opera or xhr-polling quirks

Hi!

The following chunk of code:

// ...
now.ready(function() {
  console.log('NOW READY');
  var operaSucksOrXHRPollingSucksOrWhat = false;
  now.getContext(id, function(response) {
    if (operaSucksOrXHRPollingSucksOrWhat) return;
      operaSucksOrXHRPollingSucksOrWhat = true;
      console.log('GOT CONTEXT', response);
      // ...

illustrates the problem I previously described in #39

now.ready indeed is called once, but without the fuser I get two GOT CONTEXT lines in the console, which means the callback for my custom now.getContext is called twice. This quirk I noticed only when testing in Opera which fallbacks to xhr-polling socket.io method.

Can anyone confirm this behavior?

TIA,
--Vladimir

clients should not be able to change data on the server without validation; force server-side "setters"

Any data that is to be used on the server (and all these variables are, because otherwise they should not be in a synced magic pool) should be verified.

For example, the current implementation allows clients to set huge amounts of data to a single variable, causing memory issues on the server side.

Thus, clients should only be able to change a synced variable by calling a setter on the server side. Eg.:

now.setUserName("new name");
rather than
now.userName = "new name";

This also makes sure that the new variable can be used immediately.

The server's setUserName method will be called, in which the server can validate the data and then set the actual variable on the server side:

this.now.userName = userName;

clients should not have the right to create new variables on the server

For a RIA to work, the server has to be aware of the variables of each client. Thus, the server should be the one instantiating the clients' variables of the magic synced pool.

Clients thus do not need the right to create new variables on the server. Also, the current implementation allows clients to create infinite amounts of variables causing memory problems on the server's side.

Channels/selective reception? Constants?

Hi All,

I can see how nowjs could easily be used to create a chat room. Talk about simple!

Context: I'm a complete node.js newbie. This is my first exposure to it, and perhaps that's where my confusion arises.

I don't see how to limit the recipients of a message. If you're building a web app, you usually don't want all your messages to go to every person. In fact, I'd go so far as to say that would be the norm: you want most messages to go to a single client, or at times a selection of clients.

I don't understand enough about the internals to see how to iterate over the clients and only send a message to client 'x', or send a message to clients that have some property (like belonging to a particular account).

Further, is there a way to make constants in the now pocket? I'd like to be able to set a value on the server, and for the client to be able to read it, but not to modify it.

Thanks,

-Ken

now.js transferred as 'text/plain'?

I'm using firefox 4.0rc2. A warning "Resource interpreted as Script but transferred with MIME type text/plain." triggered when loading now.js.

Security Hole via functions in the now pocket?

I had a security question.

I just read the nowjs docs. And it seems that it would be easy to sabatoge the server by passing up code that sets the server variables to null.

I guess it would be possible to avoid this if you never put anything in now that had a function attached to it. But it doesn't say this anywhere and it seem like a pretty big issue.

For example. Say I have now.name = {firstname: 'skile', lastname: 'sare', fullname= function(){return this.firstname + ' ' + this.lastname}};

And then maliciously change this.fullname = function(){app = 1'}; (via the chrome script window or some other method)

If the server calls this.now.fullname(), am I going to kill my node.js sever's app object?

If variables are nicely sandboxed and/or given a new context when passed across, I'd love an explanation on how this is done and why it is safe.

It seems like you are just begging folks to inject node.js code into the server that does malicious things.

Error with latest version of Express

Hello,
I'm having this error every time I load a page, regardless of if I have included now.js script on client-side. My guess would be, it's because of latest version of Connect Middleware; since they have updated their APIs.
I'm on Mac OS, Google Chrome(though, the same error appears with Firefox as well).
I would really appreciate your help.

Thank You.

 { stack: [Getter/Setter],
 arguments: 
 [ 'indexOf',
 { stack: [Object],
   connections: 6,
   allowHalfOpen: true,
   watcher: [Object],
   _events: [Object],
   httpAllowHalfOpen: false,
   match: [Object],
   lookup: [Object],
   settings: [Object],
   redirects: {},
   isCallbacks: {},
   viewHelpers: [Object],
   dynamicViewHelpers: [Object],
   errorHandlers: [],
   route: '/',
   routes: [Object],
   router: [Getter],
   __usedRouter: true,
   type: 'tcp4',
   fd: 9 } ],
 type: 'undefined_method',
 message: [Getter/Setter] }
 TypeError: Object #<HTTPServer> has no method 'indexOf'
 at HTTPServer.<anonymous> (/Users/Me/Work/testing/app.coffee:11:19)
 at HTTPServer.<anonymous>              (/usr/local/lib/node/.npm/now/0.3.2/package/lib/nowServerLib.js:293:31)
at HTTPServer.<anonymous> (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/listener.js:35:20)
at HTTPServer.emit (events.js:67:17)
at HTTPParser.onIncoming (http.js:1108:12)
at HTTPParser.onHeadersComplete (http.js:108:31)
at Socket.ondata (http.js:1007:22)
at Socket._onReadable (net.js:677:27)
at IOWatcher.onReadable [as callback] (net.js:177:10)

Pass Socket.IO control?

Hey guys, I was wondering if there's any way you can make a way to allow us to pass options to Socket.IO via Now? Basically, I just want to suppress Socket's logging and use my own, but currently, I can't do that without modifying NowJS or Socket.

Thanks!

Extend sample with available users

Hi,
is it possible to extend the sample with a list of people that are online? I am not very successful at creating my own sample with a shared list of available people. Would be nice to have this as an addition to the current sample. I guess you can create it in 20 minutes :-).

thanks

async calls

Hi!

How do I manage a client to call a server-side async function (the one that doesn't return the result but instead calls a given callback)?

TIA,
--Vladimir

Software needs an explicit license

Can you please add a license file, or mention on your website how the software is licensed?

I'd love to integrate Now.js into my project (which will be on a public website), but I don't dare until the licensing is explicit. I don't want to steal anything that I am not welcome to.

hasOwnProperty quirk

Hi!

https://github.com/Flotype/now/blob/master/lib/nowUtil.js#L86:

Sometimes causes the falsy negatives -- i.e. I pass a hash which surely is created from scratch (by literal notation) and the function returns false. When I change it to be Object.hasOwnProperty.call(currVar, prop) the result is positive.

Notice, that in CoffeeScript (which compiles to a "least common denominator" JS code, which runs on every JS engine), they use namely the said signature -- Object.hasOwnProperty.call(obj, prop) to determine whether a property is own.

I'd recommend to introduce a helper function __isOwnProp(obj, propName){return Object.hasOwnProperty.call(obj, propName)} and rewrite all invocations of obj.hasOwnProperty(prop).

Sorry for being didactic, and TIA,
--Vladimir

regarding now variables "auto-synced"

Hey, this is probably a stupid question, but it seems like this would work wonderfully for what I am trying to do. My only question is, if I store a json object in now, and I only update some of the values in it, is there some mechanism in place to only "send" (if that's even what happens) the changed values, or does it send everything again?

To provide context: I am writing a web interface for a command-line program, communicating through xml-rpc. I would like to have it auto-update data on the pages, and so the closest I could get to this due to the nature of the program is polling. I don't want to do this on the client-side as this would bombard the program (if each client polls at different times). I was thinking of writing a node back-end that would itself poll the command line program on an interval, and then if there were changes to the data, it would push them out.

The 'auto-syncing' feature of the now namespace seemed really interesting for this application.

Basically the command-line app has a list of items each with its own properties, so the retrieved data by the node back-end would look roughly like this:

data = {
    item-1: {
        name: "first",
        progress: "53%"
    },
    item-2: {
        name: "second",
        progress: "67%"
    }
}

Something that might change from one poll interval to the next is item-2's progress, for example.

To repeat my question: If I were to simply re-assign the now.data variable each time with the new hash, is there a mechanism in place so that the client only has to download the changed part (item-2's progress)?

If not, can anyone provide any opinions/suggestions for what I'm trying to do?

I would really appreciate it.

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace:
at Socket. (events.js:123:17)
at [object Object]. (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/client.js:83:20)
at [object Object]._onConnect (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/xhr-polling.js:23:35)
at [object Object].check (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/listener.js:77:12)
at HTTPServer. (/usr/local/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/listener.js:33:14)
at HTTPServer.emit (events.js:67:17)
at HTTPParser.onIncoming (http.js:1108:12)
at HTTPParser.onHeadersComplete (http.js:108:31)
at Socket.ondata (http.js:1007:22)
at Socket._onReadable (net.js:677:27)
-- Modules --
[email protected]
nowjs 0.5.1
express
jade

----- app.js ------
var util = require('util');

var express = require('express');

var app = module.exports = express.createServer();

var users = {};

// Configuration

app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});

app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('production', function(){
app.use(express.errorHandler());
});

// Routes

app.get('/', function(req, res){
res.render('index', {
pageTitle: 'Nadir'
});
});

// Only listen on $ node app.js

if (!module.parent) {
app.listen(80);
console.log("Express server listening on port %d", app.address().port);

var nowjs = require('now');
var everyone = nowjs.initialize(app);

everyone.now.distributeMessage = function(message){
    everyone.now.receiveMessage(this.now.name, message);
};

everyone.now.userConnect = function(userName){
    userConnected(this, userName);
};
everyone.now.Hello = function() {

}
everyone.connected(function(){
    //userConnected(this);

});
everyone.disconnected(function(){
    userDisconnected(this);

});

}
function userConnected(user, userName)
{
user.now.name = userName;
users[user.user.clientId] = user;
everyone.now.receiveStatusMessage( userName + " has connected.");
sendUserList();
}

function userDisconnected(user)
{
everyone.now.receiveStatusMessage( user.now.name + " has disconnected.");
delete users[user.user.clientId];
sendUserList();
}

function sendUserList()
{
var userDetailList = {};

for(var i in users)
{
    userDetailList[users[i].user.clientId] = 
    { 
        clientId: users[i].user.clientId, 
        Name: users[i].now.name 
    };
}

for(var i in users)
{
    users[i].now.updateUserList(userDetailList);
}

}

working together with expressjs lib

Hi,
Do you have an example of nowjs working with express js library. I see you the nowjs API takes a httpserver, but when i replaced it with the server object from express, it throws an exception....

Is it possible to get this working together with express js ?

I did a very basic test, but i will dig deep into this to see what can be done as well.

Example not working

I'm using node 0.4.3 (without https) and nowjs 0.3 on a virtualbox ubuntu. I get this error message when I try to send a message on the example chat:

22 Mar 01:27:02 - xhr-multipart message handler error - TypeError: Object #<Object> has no method 'receiveMessage'
at Object.<anonymous> (/home/john/local/node/lib/node/.npm/now/0.3.0/package/examples/helloworld_server.js:22:65)
at Object.remoteCall (/home/john/local/node/lib/node/.npm/now/0.3.0/package/lib/nowServerLib.js:187:15)
at [object Object].<anonymous> (/home/john/local/node/lib/node/.npm/now/0.3.0/package/lib/nowServerLib.js:127:48)
at [object Object].emit (events.js:64:17)
at [object Object]._onMessage (/home/john/local/node/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/client.js:58:10)
at IncomingMessage.<anonymous> (/home/john/local/node/lib/node/.npm/socket.io/0.6.16/package/lib/socket.io/transports/xhr-multipart.js:48:16)
at IncomingMessage.emit (events.js:61:17)
at HTTPParser.onMessageComplete (http.js:132:23)
at Socket.ondata (http.js:1001:22)
at Socket._onReadable (net.js:675:27)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.