Skip to content

Commit

Permalink
Wrap docs at 80 chars.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoglan committed Nov 20, 2011
1 parent e8ccb16 commit bcefb0e
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 97 deletions.
25 changes: 12 additions & 13 deletions examples/shared/public/soapbox.js
@@ -1,8 +1,8 @@
Soapbox = {
/**
* Initializes the application, passing in the globally shared Bayeux
* client. Apps on the same page should share a Bayeux client so
* that they may share an open HTTP connection with the server.
* Initializes the application, passing in the globally shared Bayeux client.
* Apps on the same page should share a Bayeux client so that they may share
* an open HTTP connection with the server.
*/
init: function(bayeux) {
var self = this;
Expand All @@ -25,9 +25,9 @@ Soapbox = {
},

/**
* Starts the application after a username has been entered. A
* subscription is made to receive messages that mention this user,
* and forms are set up to accept new followers and send messages.
* Starts the application after a username has been entered. A subscription is
* made to receive messages that mention this user, and forms are set up to
* accept new followers and send messages.
*/
launch: function() {
var self = this;
Expand All @@ -38,8 +38,8 @@ Soapbox = {
self._app.fadeIn('slow');
});

// When we add a follower, subscribe to a channel to which the
// followed user will publish messages
// When we add a follower, subscribe to a channel to which the followed user
// will publish messages
this._follow.submit(function() {
var follow = $('#followee'),
name = follow.val();
Expand Down Expand Up @@ -79,18 +79,17 @@ Soapbox = {
// Message object to transmit over Bayeux channels
message = {user: this._username, message: message};

// Publish to this user's 'from' channel, and to channels for any
// @replies found in the message
// Publish to this user's 'from' channel, and to channels for any @replies
// found in the message
this._bayeux.publish('/chat/' + this._username, message);
$.each(mentions, function(i, name) {
self._bayeux.publish('/members/' + name, message);
});
},

/**
* Handler for messages received over subscribed channels. Takes the
* message object sent by the post() method and displays it in
* the user's message list.
* Handler for messages received over subscribed channels. Takes the message
* object sent by the post() method and displays it in the user's message list.
*/
accept: function(message) {
this._stream.prepend('<li><b>' + message.user + ':</b> ' +
Expand Down
37 changes: 17 additions & 20 deletions site/src/pages/browser.haml
Expand Up @@ -4,47 +4,44 @@
:textile
h4. Setting up

In order to use the browser client, you'll need to start up a Faye
server to handle message delivery between clients. See the
"Node.js":/node.html or "Ruby":/ruby.html documentation for more
information.
In order to use the browser client, you'll need to start up a Faye server to
handle message delivery between clients. See the "Node.js":/node.html or
"Ruby":/ruby.html documentation for more information.

With the server up and running, you just need to include the
client script in your page. Let's assume you've mounted a server
at @http://localhost:8000/faye@.
With the server up and running, you just need to include the client script
in your page. Let's assume you've mounted a server at @http://localhost:8000/faye@.

<pre class="prettyprint"><script type="text/javascript"
src="http://localhost:8000/faye.js">
</script></pre>

You can then create a client. You should make sure you only create
one client per target server, since browsers impose a per-host connection
limit and creating more clients will saturate the available connections
in many browsers.
You can then create a client. You should make sure you only create one
client per target server, since browsers impose a per-host connection limit
and creating more clients will saturate the available connections in many
browsers.

To make a client, all you need is the mount point of the server you
want to connect to:
To make a client, all you need is the mount point of the server you want to
connect to:

<pre class="prettyprint"><script type="text/javascript">
var client = new Faye.Client('http://localhost:8000/faye');
</script></pre>

h4. Timeouts

You can optionally specify a timeout; if the server does not send back
any data for the given period of time, the client will assume the
server has gone away and will attempt to reconnect. Specify the timeout
as follows:
You can optionally specify a timeout; if the server does not send back any
data for the given period of time, the client will assume the server has
gone away and will attempt to reconnect. Specify the timeout as follows:

<pre class="prettyprint"><script type="text/javascript">
var client = new Faye.Client('http://localhost:8000/faye', {
timeout: 120
});
</script></pre>

The timeout is given in seconds and should be larger that the timeout
you set up on the server side, so we give the server ample time to
respond before assuming there's been a network error.
The timeout is given in seconds and should be larger that the timeout you
set up on the server side, so we give the server ample time to respond
before assuming there's been a network error.

h4. Cross-domain operation

Expand Down
15 changes: 7 additions & 8 deletions site/src/pages/browser/extensions.haml
Expand Up @@ -4,17 +4,16 @@
:textile
h4. Extensions

Faye clients support an extension system that lets you intercept
messages as they pass between the client and the server. To add
an extension to a client, just call:
Faye clients support an extension system that lets you intercept messages as
they pass between the client and the server. To add an extension to a client,
just call:

<pre class="prettyprint">client.addExtension(extension);</pre>

@extension@ should be an object with an @incoming()@ or @outgoing()@
method (or both). These methods accept a message and a callback
function, and should call the callback with the message after any
necessary modifications have been made. For example, a simple logging
extension would look like:
@extension@ should be an object with an @incoming()@ or @outgoing()@ method
(or both). These methods accept a message and a callback function, and
should call the callback with the message after any necessary modifications
have been made. For example, a simple logging extension would look like:

<pre class="prettyprint">Logger = {
incoming: function(message, callback) {
Expand Down
30 changes: 14 additions & 16 deletions site/src/pages/browser/publishing.haml
Expand Up @@ -4,25 +4,23 @@
:textile
h4. Sending messages

Clients do not send each other messages directly, instead they send
their messages to channels, and the server figures out which clients
need to receive the message. You can send a message using the @#publish()@
method, passing in the channel name and a message object.
Clients do not send each other messages directly, instead they send their
messages to channels, and the server figures out which clients need to
receive the message. You can send a message using the @#publish()@ method,
passing in the channel name and a message object.

<pre class="prettyprint">client.publish('/foo', {text: 'Hi there'});</pre>

The message object can be any arbitrary JavaScript object that can
be serialized to JSON, so it can contain strings, numbers, booleans,
arrays and other objects. There are no required fields, and the
object will be delivered verbatim to any subscriber functions
listening to that channel.
The message object can be any arbitrary JavaScript object that can be
serialized to JSON, so it can contain strings, numbers, booleans, arrays and
other objects. There are no required fields, and the object will be
delivered verbatim to any subscriber functions listening to that channel.

Just like @subscribe()@, the @publish()@ method lets you add callbacks
to find out whether it was successful. Bear in mind that 'success' here
just means the server received and routed the message successfully, not
that it has been received by all other clients. An error means the server
found a problem processing the message. Network errors are not covered
by this.
Just like @subscribe()@, the @publish()@ method lets you add callbacks to
find out whether it was successful. Bear in mind that 'success' here just
means the server received and routed the message successfully, not that it
has been received by all other clients. An error means the server found a
problem processing the message. Network errors are not covered by this.

<pre class="prettyprint">var publication = client.publish('/foo', {text: 'Hi there'});

Expand All @@ -33,4 +31,4 @@
publication.errback(function(error) {
alert('There was a problem: ' + error.message);
});</pre>


44 changes: 22 additions & 22 deletions site/src/pages/browser/subscribing.haml
Expand Up @@ -4,41 +4,41 @@
:textile
h4. Subscribing to channels

Clients receive data from other clients by subscribing to channels.
Whenever any client sends a message to a channel you're subscribed to,
Faye will notify your client with the new message.

Channel names must be formatted as absolute path names whose segments
may contain only letters, numbers, and the symbols @-@, @_@, @!@, @~@,
@(@, @)@, @$@ and @@@. Channel names may also end with wildcards:

* The @*@ wildcard matches any channel segment. So @/foo/*@ matches
@/foo/bar@ and @/foo/thing@ but not @/foo/bar/thing@.
* The @**@ wildcard matches any channel name recursively. So
@/foo/**@ matches @/foo/bar@, @/foo/thing@ and @/foo/bar/thing@.

So for example if you subscribe to @/foo/*@ and someone sends a
message to @/foo/bar@, you will receive that message.
Clients receive data from other clients by subscribing to channels. Whenever
any client sends a message to a channel you're subscribed to, Faye will
notify your client with the new message.

Channel names must be formatted as absolute path names whose segments may
contain only letters, numbers, and the symbols @-@, @_@, @!@, @~@, @(@, @)@,
@$@ and @@@. Channel names may also end with wildcards:
* The @*@ wildcard matches any channel segment. So @/foo/*@ matches @/foo/bar@
and @/foo/thing@ but not @/foo/bar/thing@.
* The @**@ wildcard matches any channel name recursively. So @/foo/**@
matches @/foo/bar@, @/foo/thing@ and @/foo/bar/thing@.

So for example if you subscribe to @/foo/*@ and someone sends a message to
@/foo/bar@, you will receive that message.

Clients should subscribe to channels using the @#subscribe()@ method:

<pre class="prettyprint">var subscription = client.subscribe('/foo', function(message) {
// handle message
});</pre>

The subscriber function will be invoked when anybody sends a message
to @/foo@, and the @message@ parameter will contain the sent message
object. A client may bind multiple listeners to a channel, and the Faye
client handles all the management of those listeners and makes sure the
server sends it the right messages.
The subscriber function will be invoked when anybody sends a message to
@/foo@, and the @message@ parameter will contain the sent message object. A
client may bind multiple listeners to a channel, and the Faye client handles
all the management of those listeners and makes sure the server sends it the
right messages.

The @subscribe()@ method returns a @Subscription@ object, which you can
cancel if you want to remove that listener from the channel.

<pre class="prettyprint">subscription.cancel();</pre>

It also lets you add callbacks that will run as soon as the subcription
has been set up and acknowledged by the server:
It also lets you add callbacks that will run as soon as the subcription has
been set up and acknowledged by the server:

<pre class="prettyprint">subscription.callback(function() {
alert('Subscription is now active!');
Expand Down
35 changes: 17 additions & 18 deletions site/src/pages/download.haml
Expand Up @@ -3,14 +3,14 @@
h3. Download Faye

The latest version is 0.6.7, released October 20 2011. It is open-source
software, released under the MIT license. You can follow development
on Faye's "GitHub page":http://github.com/jcoglan/faye.
software, released under the MIT license. You can follow development on
Faye's "GitHub page":http://github.com/jcoglan/faye.

h4. Download for Node.js and web browsers

The Node.js version is available through "npm":http://npmjs.org/.
This package contains a copy of the browser client, which is served
up by the Faye server when running.
The Node.js version is available through "npm":http://npmjs.org/. This
package contains a copy of the browser client, which is served up by the
Faye server when running.

<pre class="prettyprint">npm install faye</pre>

Expand All @@ -25,23 +25,22 @@
* @faye-node.js@
* @faye-browser-min.js@

To use Faye for Node.js, just put these two files together in a
directory, and load the server-side component using
@require('./path/to/faye-node')@. The @faye-browser-min.js@ file
contains the web browser client, which your Faye server will serve for
you automatically.
To use Faye for Node.js, just put these two files together in a directory,
and load the server-side component using @require('./path/to/faye-node')@.
The @faye-browser-min.js@ file contains the web browser client, which your
Faye server will serve for you automatically.

The browser client can be used standalone with other Bayeux
servers like "CometD":http://cometd.org - just include
@faye-browser-min.js@ in your web page to use it.
The browser client can be used standalone with other Bayeux servers like
"CometD":http://cometd.org - just include @faye-browser-min.js@ in your web
page to use it.

h4. Download for Ruby

For Ruby platforms, Faye is easily installable through RubyGems. It
requires @eventmachine@, @em-http-request@, @rack@, @thin@ and
@json@, which should all be automatically installed for you.
For Ruby platforms, Faye is easily installable through RubyGems. It requires
@eventmachine@, @em-http-request@, @rack@, @thin@ and @json@, which should
all be automatically installed for you.

<pre class="prettyprint">gem install faye</pre>

This package also includes the browser client which is served up
by the Faye server when running.
This package also includes the browser client which is served up by the Faye
server when running.

0 comments on commit bcefb0e

Please sign in to comment.