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

View File

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