From ae9a7e04c08ea87189d530fe08a1793894866ca3 Mon Sep 17 00:00:00 2001 From: Alex Clavelle Date: Wed, 22 Jun 2016 22:01:34 -0500 Subject: [PATCH] allow user configuration of primus, document usage --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ index.js | 6 +++--- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index aa785c5..a0210f2 100644 --- a/README.md +++ b/README.md @@ -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: +``` + +``` + diff --git a/index.js b/index.js index e9cb374..01302cc 100644 --- a/index.js +++ b/index.js @@ -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' @@ -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() }) })