add incident support to ws
This commit is contained in:
parent
d2ec70799d
commit
528c9e4368
2 changed files with 12 additions and 5 deletions
|
@ -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 () {
|
||||
|
|
|
@ -4,4 +4,7 @@ export default {
|
|||
SUBSCRIBED: 1,
|
||||
UNSUBSCRIBED: 2,
|
||||
DATA: 3,
|
||||
INCIDENT_NEW: 4,
|
||||
INCIDENT_UPDATE: 5,
|
||||
INCIDENT_CLOSE: 6,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue