Skip to content

Commit

Permalink
allow user configuration of primus, document usage
Browse files Browse the repository at this point in the history
  • Loading branch information
aclave1 committed Jun 23, 2016
1 parent a5c942e commit ae9a7e0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@
# trailpack-realtime
:package: Realtime Trailpack. Synchronize the client and server via WebSockets

## Getting Started

### Install

```js
npm install --save trailpack-realtime
```

Then edit `config/main.js `

```js
packs: [
require('trailpack-core'),
require('trailpack-repl'),
require('trailpack-router'),
require('trailpack-express'),
require('trailpack-realtime')
],
```

### Configure

Create the config file: `config/realtime.js `

```js
module.exports = {
primus:{
options:{
//these options are passed directly to the Primus constructor: https://github.com/primus/primus#getting-started
}
}
};
```

## Client

You can include the primus client library as a script:
```
<script src="/primus/primus.js"></script>
```

6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict'

const Promise = require('bluebird');
const Trailpack = require('trailpack')
const Primus = require('primus');
const _ = require('lodash');

const primusDefaults = {
transformer:'engine.io'
Expand All @@ -20,7 +19,8 @@ module.exports = class Realtime extends Trailpack {
initialize () {
return new Promise((res,rej)=>{
this.app.once('webserver:http:ready',(httpServer)=>{
this.app.sockets = new Primus(httpServer,primusDefaults)
const primusConfig = _.get(this.app.config,'realtime.primus',{options:{}})
this.app.sockets = new Primus(httpServer,Object.assign(primusDefaults,primusConfig.options))
res()
})
})
Expand Down

0 comments on commit ae9a7e0

Please sign in to comment.