From 528c9e43683313298ddd7e2b7ec884da9ed73313 Mon Sep 17 00:00:00 2001 From: slice Date: Wed, 18 Jul 2018 14:59:07 -0700 Subject: [PATCH] add incident support to ws --- priv/frontend/src/ws/client.js | 14 +++++++++----- priv/frontend/src/ws/op.js | 3 +++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/priv/frontend/src/ws/client.js b/priv/frontend/src/ws/client.js index 7c46abe..65330d1 100644 --- a/priv/frontend/src/ws/client.js +++ b/priv/frontend/src/ws/client.js @@ -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 () { diff --git a/priv/frontend/src/ws/op.js b/priv/frontend/src/ws/op.js index 17934e7..3ae9223 100644 --- a/priv/frontend/src/ws/op.js +++ b/priv/frontend/src/ws/op.js @@ -4,4 +4,7 @@ export default { SUBSCRIBED: 1, UNSUBSCRIBED: 2, DATA: 3, + INCIDENT_NEW: 4, + INCIDENT_UPDATE: 5, + INCIDENT_CLOSE: 6, }