You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+34-32Lines changed: 34 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,53 +3,54 @@
3
3
Geosockets is a Node.js webserver and javascript browser client for rendering website
4
4
visitors on a map in realtime using WebSockets and the browser's Geolocation API.
5
5
6
-
See the demo app at [geosockets.herokuapp.com](https://geosockets.herokuapp.com).
6
+
See the demo app at [geosockets.herokuapp.com](https://geosockets.herokuapp.com) and
7
+
the Heroku WebSocket Beta announcement at [blog.heroku.com/archives/2013/10/8/websockets-public-beta](https://blog.heroku.com/archives/2013/10/8/websockets-public-beta).
7
8
8
-
### Using the Client Script on Your Site
9
+
### The Client
9
10
10
-
The Geosockets javascript client can be used on any website:
11
+
[client.coffee](https://github.com/heroku-examples/geosockets/blob/master/client.coffee) is written as a node app that uses [Coffeeify](https://github.com/substack/coffeeify) (the red-headed step-child of [browserify](https://github.com/substack/node-browserify#readme)) and [Grunt](http://gruntjs.com/) to transpile the source into a single browser-ready javascript file.
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.
18
14
19
-
Use CSS to configure the size and position of the map container:
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:
The client then listens for messages from the server, rendering and removing markers from the map as site visitors come and go.
27
+
28
28
### The Server
29
29
30
30
[server.coffee](https://github.com/heroku-examples/geosockets/blob/master/server.coffee) is a node app powered by [express 3](http://expressjs.com/guide.html), node's native [http](http://nodejs.org/api/http.html) module, and the [einaros/ws](https://github.com/einaros/ws/blob/master/doc/ws.md) WebSocket implementation. Express is used to serve the static frontend in `/public`.
31
31
32
32
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.
33
33
34
-
### The Client
34
+
### Embedding the Javscript Client on Your Site
35
35
36
-
[client.coffee](https://github.com/heroku-examples/geosockets/blob/master/client.coffee) is also written as a node app. [Coffeeify](https://github.com/substack/coffeeify), the red-headed step-child of [browserify](https://github.com/substack/node-browserify#readme), is used in concert with [Grunt](http://gruntjs.com/) to transpile the client into a single browser-ready javascript file.
36
+
The Geosockets JavasScript client can be used on any website:
37
37
38
-
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.
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:
45
+
Use CSS to configure the size and position of the map container:
The client then listens for messages from the server, rendering and removing markers from the map as site visitors come and go.
52
-
53
54
### Running Geosockets Locally
54
55
55
56
If you're new to Heroku or Node.js development, you'll need to install a few things first:
@@ -66,22 +67,23 @@ cd geosockets
66
67
npm install
67
68
```
68
69
69
-
Fire up redis, a grunt watcher, and the node webserver at [localhost:5000/?debug](http://localhost:5000/?debug):
70
+
The foreman [Procfile](https://github.com/heroku-examples/geosockets/blob/master/Procfile) defines the processes
71
+
required to run the app. Fire up redis, a grunt watcher, and the node webserver at [localhost:5000/?debug](http://localhost:5000/?debug):
70
72
71
73
````
72
74
foreman start
73
75
```
74
76
75
-
## Debuggging
77
+
### Debugging
76
78
77
-
The client uses a custom logging function, found in `lib/logger.coffee`. This function
78
-
only logs messages to the console if a `debug` query param is present in the URL, e.g.
79
+
The client uses a [custom logging function](https://github.com/heroku-examples/geosockets/blob/master/lib/logger.coffee)
80
+
that only logs messages to the console if a `debug` query param is present in the URL, e.g.
79
81
[localhost:5000/?debug](http://localhost:5000/?debug). This allows you to view client
80
82
behavior in production without exposing your site visitors to debugging data.
81
83
82
-
## Testing
84
+
### Testing
83
85
84
-
Simple 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.
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.
0 commit comments