add incident support to ws

This commit is contained in:
slice 2018-07-18 14:59:07 -07:00
parent d2ec70799d
commit 528c9e4368
No known key found for this signature in database
GPG Key ID: 1508C19D7436A26D
2 changed files with 12 additions and 5 deletions

View File

@ -29,7 +29,7 @@ export default class StreamingClient extends NanoEvents {
const { status } = this.metrics const { status } = this.metrics
const channels = Object.keys(status).reduce( const channels = Object.keys(status).reduce(
(channels, name) => [...channels, `latency:${name}`, `status:${name}`], (channels, name) => [...channels, `latency:${name}`, `status:${name}`],
[] ['incidents']
) )
log(`subscribing to ${channels.length} channels: ${channels.join(', ')}`) log(`subscribing to ${channels.length} channels: ${channels.join(', ')}`)
@ -39,13 +39,17 @@ export default class StreamingClient extends NanoEvents {
handle (packet) { handle (packet) {
const { op, c: channel, d: data } = packet const { op, c: channel, d: data } = packet
if (op !== OP.DATA) { if ([OP.SUBSCRIBED, OP.UNSUBSCRIBED].includes(op)) {
return return
} }
const [type, name] = channel.split(':') if (channel === 'incidents') {
const [name] = Object.entries(OP).find(([_name, value]) => value === op)
this.emit(type, name, data) this.emit(name.toLowerCase(), data)
} else {
const [type, name] = channel.split(':')
this.emit(type, name, data)
}
} }
connect () { connect () {

View File

@ -4,4 +4,7 @@ export default {
SUBSCRIBED: 1, SUBSCRIBED: 1,
UNSUBSCRIBED: 2, UNSUBSCRIBED: 2,
DATA: 3, DATA: 3,
INCIDENT_NEW: 4,
INCIDENT_UPDATE: 5,
INCIDENT_CLOSE: 6,
} }