Skip to content

Commit

Permalink
hook into http ready and start primus
Browse files Browse the repository at this point in the history
  • Loading branch information
aclave1 committed Jan 30, 2016
1 parent df89d28 commit 99806e9
Show file tree
Hide file tree
Showing 6 changed files with 140 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
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')
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 Promise = require('bluebird');
const Trailpack = require('trailpack')
const Primus = require('primus');

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)=>{
this.app.sockets = new Primus(this.server,primusDefaults)
res()
})
})
}

constructor (app) {
super(app, {
config: require('./config'),
api: require('./api'),
pkg: require('./package')
})
}
}
51 changes: 51 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"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": {
"bluebird": "^3.1.1",
"engine.io": "^1.6.7",
"primus": "^4.0.4",
"trailpack": "latest"
},
"devDependencies": {
"eslint-config-trails": "latest",
"eslint": "^1.10",
"mocha": "^2.3"
},
"bundledDependencies": [
"trailpack"
],
"scripts": {
"test": "eslint . && mocha"
},
"engines": {
"node": ">= 4.0.0"
},
"eslintConfig": {
"extends": "trails"
},
"repository": "[email protected]:trailsjs/trailpack-realtime",
"license": "MIT"
}

0 comments on commit 99806e9

Please sign in to comment.