Skip to content

Commit

Permalink
Merge pull request #1 from aclave1/master
Browse files Browse the repository at this point in the history
hook into http ready and start primus
  • Loading branch information
jaumard authored Jun 28, 2016
2 parents df89d28 + 651fc25 commit 9a1b3f1
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
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
23 changes: 23 additions & 0 deletions .travis.yml
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
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>
```

Empty file added api/index.js
Empty file.
1 change: 1 addition & 0 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.trailpack = require('./trailpack')
5 changes: 5 additions & 0 deletions config/sockets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
authorization: null,
pathname: '/primus',
transformer: 'engine.io'
}
41 changes: 41 additions & 0 deletions config/trailpack.js
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: [ ]
}
}
}
36 changes: 36 additions & 0 deletions index.js
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')
})
}
}
47 changes: 47 additions & 0 deletions package.json
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"
}

0 comments on commit 9a1b3f1

Please sign in to comment.