Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' of github.com:Flotype/now
  • Loading branch information
ericz committed Mar 12, 2011
2 parents 19b2b92 + 5eaf462 commit 478921f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
6 changes: 6 additions & 0 deletions best_practices.md
Expand Up @@ -51,3 +51,9 @@ As described above, some amount of traversal is required to syncronize variables

3. The Internet will always be slower than the local machine
We try to make remote functions and variables as natural to use as local ones. But the reality is that the latency for any remote action is 6 orders of magnitude longer than the same action done locally. Try to execute things locally when possible.

Further Reading
----------------------
Now that you've read the Best Practices guide, try the NowJS [User Manual](http://nowjs.com/doc) and [Quick Start](http://nowjs.com/guide)

Have more questions? You can reach us in #nowjs on freenode
8 changes: 7 additions & 1 deletion getting_started.md
@@ -1,6 +1,6 @@
Getting Started with NowJS
==========================
Getting started with NowJS is really simple. Here we will make a simple chat server in just over a dozen lines of code. If you want to follow along on your own computer, download the two source files [here](http://google.com).
Getting started with NowJS is really simple. Here we will make a simple chat server in just over a dozen lines of code. If you want to follow along on your own computer, download the two source files [here](https://github.com/downloads/Flotype/now/chat-example.tgz).

Magic Pockets
-------------
Expand Down Expand Up @@ -66,3 +66,9 @@ Because the client defines the `receiveMessage` function in the `now` pocket, th
Fin
---
That's all there is to building things in NowJS. Armed with this knowledge, you can build all sorts of real-time applications easily and expressively. Happy coding!

Further Reading
----------------------
Now that you've read the Getting Started guide, try the NowJS [User Manual](http://nowjs.com/doc) and [Best Practices](http://nowjs.com/bestpractices)

Have more questions? You can reach us in #nowjs on freenode
33 changes: 28 additions & 5 deletions user_manual.md
Expand Up @@ -8,17 +8,20 @@ At your command line, simply enter `npm install nodejs`.

Setup on the server
-------------------
NowJS needs an instance of a node.js `httpServer` in order to communicate. If your application is already using an `httpServer`, NowJS can use the existing instance. Otherwise, you will need to create one.
NowJS needs an instance of a node.js http server in order to communicate. If your application is already using an http server, NowJS can use the existing instance. Otherwise, you will need to create one. Here's an example server:

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

At the top of your code, place the following:
`var everyone = require("nowjs").initialize(yourHttpServer);`
`var everyone = require("now").initialize(yourHttpServer);`

Setup on the client
-------------------
On pages that you would like to use NowJS on, simply include this script tag in your HTML head:
`<script src="/nowjs/nowClient.js"></script>`
`<script src="/nowjs/now.js"></script>`

NowJS only works on pages that are served through the same `httpServer` instance that was passed into the `initialize` function above.
NowJS only works on pages that are served through the same http server instance that was passed into the `initialize` function above.

Using NowJS
-------------------
Expand All @@ -39,4 +42,24 @@ When a remote machine invokes a function, the `now` namespace that is shared bet
###Special behavior of everyone.now
When you call a function inside the `everyone.now` namespace, NowJS will attempt to call the corresponding function in each connected client's `now` namespace. If the corresponding function exists, a remote function call will be made to that client. If not, a call will not be made.

Setting variables inside the `everyone.now` namespace will set the same value uniformly across all clients' `now` namespaces. It is possible to also get/read values from `everyone.now`, but since clients may change the value of the variable in their own `now` namespace, the returned value is indeterminate/meaningless.
Setting variables inside the `everyone.now` namespace will set the same value uniformly across all clients' `now` namespaces. It is possible to also get/read values from `everyone.now`, but since clients may change the value of the variable in their own `now` namespace, the returned value is indeterminate/meaningless.

###Client connected/disconnected events on the server
NowJS allows you to specify a callback to be fired when a client connects or disconnects on the server. To set a listener for the events, do the following:

everyone.connected(function(){});
everyone.disconnected(function(){});

The callbacks are run in the context of the connecting/disconnecting client's `now` namespace. This makes it easy to access information about that client for setup or setdown procedures.

###Client ready event on the client
NowJS allows you to specify a callback to be fired when the client has successfully connected to the NowJS server. To set a listener for the events, do the following:

now.ready(function(){});


Further Reading
----------------------
Now that you've read the User Manual guide, try the NowJS [Quick Start](http://nowjs.com/guide) and [Best Practices](http://nowjs.com/bestpractices)

Have more questions? You can reach us in #nowjs on freenode

0 comments on commit 478921f

Please sign in to comment.