-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
38 lines (33 loc) · 870 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'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) => {
if (Array.isArray(httpServer)) {
httpServer = httpServer[0]
}
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'),
pkg: require('./package')
})
}
}