-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from aclave1/master
hook into http ready and start primus
- Loading branch information
Showing
9 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
language: node_js | ||
node_js: | ||
- 4 | ||
- 5 | ||
- 6 | ||
|
||
notifications: | ||
email: false | ||
webhooks: | ||
urls: | ||
- https://webhooks.gitter.im/e/54f8a1e753f859f5ca1a | ||
on_start: never | ||
on_failure: change | ||
|
||
deploy: | ||
provider: npm | ||
email: [email protected] | ||
api_key: | ||
secure: d/VChdWWPr8Mi6UyRUjIhjEfXHoyTCJ0z/pyNzF3yd2vpvC07fK90ka0CPxHhKyPWj7h7+ZG0FO0U8wj4YAZ8QeKIuc5rZbe1wI5yISpbnVxDKk0tYqyDFCRbmXVu7RNeLbBPN6y3fbJYdCLM14ugTfaJaBdewVTeOFGFBA712vHwu8ptWW/zw72YbH9d6C+LnAyz17ZyeAG7BvABISKv+bzuYexFaw4gv/uGNp2o//zC4FlXNcVWR3hb/cS6SWWoiPdsOZvDJTY+2J+WSEMlZ+PIZaJjfki4RbisoIg5Q3KM/WhgXwRfgma4POrGSqXvg8Yy1lqTIoZJT1SEnIj+KIOHuLoI+Rv1hc3n+Aw5Q2iMSPo/QlbolhfOhmGRkx5XIxIlKs/Vf6GJGQBf2lB5W2tgdf3UYwGbXjWOUoj+4NBotWQ4vaHlwfJb9sm66yXG9ayDkgc8Gegj6ooRC+xl8irgu/xgtSMKek6I893r/sLTnAkYcrLMUSqOp9qMBk8Zfdir978yKx4pTPBJvlnilze+cdSNMSXokKMDNF4wbaDVCyaFsoYEYNW/basaKynBiPgi4exjWH1SlXBOKA+LTr8i9ZwdGNIRDx3mxTiUHvwaYbn9tHOt8ymEwTfFe90a2XDp0+sUKEtLT+i6jF41iFQq0b/OwzWnQf3GfcDyYY= | ||
on: | ||
tags: true | ||
repo: trailsjs/trailpack-realtime | ||
node: 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
``` | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exports.trailpack = require('./trailpack') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
authorization: null, | ||
pathname: '/primus', | ||
transformer: 'engine.io' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Trailpack Configuration | ||
* | ||
* @see {@link http://trailsjs.io/doc/trailpack/config | ||
*/ | ||
module.exports = { | ||
|
||
/** | ||
* API and config resources provided by this Trailpack. | ||
*/ | ||
provides: { | ||
api: { | ||
controllers: [ ] | ||
// ... | ||
}, | ||
config: [ ] | ||
}, | ||
|
||
/** | ||
* Configure the lifecycle of this pack; that is, how it boots up, and which | ||
* order it loads relative to other trailpacks. | ||
*/ | ||
lifecycle: { | ||
configure: { | ||
/** | ||
* List of events that must be fired before the configure lifecycle | ||
* method is invoked on this Trailpack | ||
*/ | ||
listen: [ ], | ||
|
||
/** | ||
* List of events emitted by the configure lifecycle method | ||
*/ | ||
emit: [ ] | ||
}, | ||
initialize: { | ||
listen: [ ], | ||
emit: [ ] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict' | ||
const Trailpack = require('trailpack') | ||
const Primus = require('primus') | ||
const _ = require('lodash') | ||
|
||
const primusDefaults = { | ||
transformer: 'engine.io' | ||
} | ||
|
||
module.exports = class Realtime extends Trailpack { | ||
validate () { | ||
return Promise.resolve() | ||
} | ||
|
||
configure () { | ||
return Promise.resolve() | ||
} | ||
|
||
initialize () { | ||
return new Promise((res,rej)=>{ | ||
this.app.once('webserver:http:ready',(httpServer)=>{ | ||
const primusConfig = _.get(this.app.config,'realtime.primus',{options: {}}) | ||
this.app.sockets = new Primus(httpServer,Object.assign(primusDefaults,primusConfig.options)) | ||
res() | ||
}) | ||
}) | ||
} | ||
|
||
constructor (app) { | ||
super(app, { | ||
config: require('./config'), | ||
api: require('./api'), | ||
pkg: require('./package') | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "trailpack-realtime", | ||
"version": "0.0.1", | ||
"description": "Realtime Trailpack. Synchronize the client and server via WebSockets", | ||
"homepage": "http://www.trailsjs.io/", | ||
"author": "Trails.js Team <[email protected]>", | ||
"files": [ | ||
"lib" | ||
], | ||
"contributors": [ | ||
{ | ||
"name": "Travis Webb", | ||
"url": "https://github.com/tjwebb" | ||
}, | ||
{ | ||
"name": "Alex Clavelle", | ||
"url": "https://github.com/aclave1" | ||
} | ||
], | ||
"main": "index.js", | ||
"keywords": [ | ||
"trailpack", | ||
"trails", | ||
"trailjs" | ||
], | ||
"dependencies": { | ||
"engine.io": "^1.6.7", | ||
"primus": "^4.0.4", | ||
"trailpack": "^1.0.4" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^2.13.1", | ||
"eslint-config-trails": "^1.0.7", | ||
"mocha": "^2.3" | ||
}, | ||
"scripts": { | ||
"test": "eslint ." | ||
}, | ||
"engines": { | ||
"node": ">= 4.0.0" | ||
}, | ||
"eslintConfig": { | ||
"extends": "trails" | ||
}, | ||
"repository": "[email protected]:trailsjs/trailpack-realtime", | ||
"license": "MIT" | ||
} |