Skip to content

Commit afc01f7

Browse files
committed
describe the server in more detail
1 parent 0125946 commit afc01f7

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ the Heroku WebSocket Beta announcement at [blog.heroku.com/archives/2013/10/8/we
1212

1313
When the client is first run in the browser, a [UUID](https://github.com/broofa/node-uuid#readme) token is generated and stored in a cookie which is passed to the server in the headers of each WebSocket message. This gives the server a consistent way to identify each user.
1414

15-
The client uses the [browser's geolocation API](https://www.google.com/search?q=browser%20geolocation%20api) and the [geolocation-stream](https://github.com/maxogden/geolocation-stream#readme) node module to determine the user's physical location, continually listening for location updates in realtime. EOnce the WebSocket connection is establised, the client broadcasts its location to the server:
15+
The client uses the [browser's geolocation API](https://www.google.com/search?q=browser%20geolocation%20api) and the [geolocation-stream](https://github.com/maxogden/geolocation-stream#readme) node module to determine the user's physical location, continually listening for location updates in realtime. Once the WebSocket connection is established, the client broadcasts its location to the server:
1616

1717
```js
1818
{
@@ -31,6 +31,15 @@ The client then listens for messages from the server, rendering and removing mar
3131

3232
The server was designed with horizontal scalability in mind. The shared location dataset is stored in a redis datastore and each web dyno connects to this shared resource to pull the complete list of pins to place on the map. Clients viewing the map each establish their own WebSocket connection to any one of the backend web dynos and receive real-time updates as locations are added and removed from the redis datastore.
3333

34+
When the server receives a message from a client, it adds the client's location data to the Redis store (or updates if it's already present), using the combined client's URL/UUID pair as the Redis key:
35+
36+
```coffee
37+
@redis.setex "#{user.url}---#{user.uuid}", @ttl, JSON.stringify(user)
38+
```
39+
40+
The server then fetches all keys from Redis that match that URL and broadcasts the update
41+
to all connected clients at that same URL.
42+
3443
### Embedding the Javscript Client on Your Site
3544

3645
The Geosockets JavasScript client can be used on any website:
@@ -57,7 +66,7 @@ If you're new to Heroku or Node.js development, you'll need to install a few thi
5766

5867
1. [Heroku Toolbelt](https://toolbelt.heroku.com), which gives you git, foreman, and the heroku command-line interface.
5968
1. [Node.js](http://nodejs.org/)
60-
1. [redis](http://redis.io/). If you're using [homebrew](http://brew.sh/), install with `brew install redis`
69+
1. [Redis](http://redis.io/). If you're using [homebrew](http://brew.sh/), install with `brew install redis`
6170

6271
Clone the repo and install npm dependencies:
6372

@@ -83,7 +92,7 @@ behavior in production without exposing your site visitors to debugging data.
8392
8493
### Testing
8594
86-
Crude integration testing is done with [CasperJS](http://casperjs.org/), a navigation scripting & testing utility for [PhantomJS](http://phantomjs.org/). Casper is integrated into the app using the [grunt-casper](https://github.com/iamchrismiller/grunt-casper) plugin, and run with foreman. Each time you make a change to your client, the casper tests are run automatically.
95+
Basic integration testing is done with [CasperJS](http://casperjs.org/), a navigation scripting & testing utility for [PhantomJS](http://phantomjs.org/). Casper is integrated into the app using the [grunt-casper](https://github.com/iamchrismiller/grunt-casper) plugin, and run with foreman. Each time you make a change to your client, the casper tests are run automatically.
8796
8897
### Deploying Geosockets to Heroku
8998

0 commit comments

Comments
 (0)