feat: connected/disconnected status with wakuV2

This commit is contained in:
Richard Ramos 2021-08-30 16:59:37 -04:00 committed by Iuri Matias
parent 22e8c8a7ff
commit d0514f366d
3 changed files with 92 additions and 0 deletions

View File

@ -18,6 +18,16 @@ proc handleSignals(self: ChatController) =
)
mailserverWorker.start(task)
self.status.events.on(SignalType.PeerStats.event) do(e:Args):
var data = PeerStatsSignal(e)
let
mailserverWorker = self.status.tasks.marathon[MailserverWorker().name]
task = PeerSummaryChangeTaskArg(
`method`: "peerSummaryChange",
peers: data.peers
)
mailserverWorker.start(task)
self.status.events.on(SignalType.EnvelopeSent.event) do(e:Args):
var data = EnvelopeSentSignal(e)
self.status.messages.updateStatus(data.messageIds)

View File

@ -35,6 +35,11 @@ proc init*(self: NodeController) =
self.status.network.peerSummaryChange(data.enodes)
self.view.setPeerSize(data.enodes.len)
self.status.events.on(SignalType.PeerStats.event) do(e:Args):
var data = PeerStatsSignal(e)
self.status.network.peerSummaryChange(data.peers)
self.view.setPeerSize(data.peers.len)
self.status.events.on(SignalType.Stats.event) do (e:Args):
self.view.setStats(StatsSignal(e).stats)
self.view.fetchBitsSet()

View File

@ -0,0 +1,77 @@
import NimQml, tables, json, chronicles, strutils, json_serialization
import ../types as status_types
import types, messages, discovery, whisperFilter, envelopes, expired, wallet, mailserver, communities, stats, peerstats
import ../status
import ../../eventemitter
logScope:
topics = "signals"
QtObject:
type SignalsController* = ref object of QObject
variant*: QVariant
status*: Status
proc newController*(status: Status): SignalsController =
new(result)
result.status = status
result.setup()
result.variant = newQVariant(result)
proc setup(self: SignalsController) =
self.QObject.setup
proc delete*(self: SignalsController) =
self.variant.delete
self.QObject.delete
proc processSignal(self: SignalsController, statusSignal: string) =
var jsonSignal: JsonNode
try:
jsonSignal = statusSignal.parseJson
except:
error "Invalid signal received", data = statusSignal
return
let signalString = jsonSignal["type"].getStr
trace "Raw signal data", data = $jsonSignal
var signalType: SignalType
try:
signalType = parseEnum[SignalType](signalString)
except:
warn "Unknown signal received", type = signalString
signalType = SignalType.Unknown
return
var signal: Signal = case signalType:
of SignalType.Message: messages.fromEvent(jsonSignal)
of SignalType.EnvelopeSent: envelopes.fromEvent(jsonSignal)
of SignalType.EnvelopeExpired: expired.fromEvent(jsonSignal)
of SignalType.WhisperFilterAdded: whisperFilter.fromEvent(jsonSignal)
of SignalType.Wallet: wallet.fromEvent(jsonSignal)
of SignalType.NodeLogin: Json.decode($jsonSignal, NodeSignal)
of SignalType.PeerStats: peerStats.fromEvent(jsonSignal)
of SignalType.DiscoverySummary: discovery.fromEvent(jsonSignal)
of SignalType.MailserverRequestCompleted: mailserver.fromCompletedEvent(jsonSignal)
of SignalType.MailserverRequestExpired: mailserver.fromExpiredEvent(jsonSignal)
of SignalType.CommunityFound: communities.fromEvent(jsonSignal)
of SignalType.Stats: stats.fromEvent(jsonSignal)
else: Signal()
if(signalType == SignalType.NodeLogin):
if(NodeSignal(signal).event.error != ""):
error "node.login", error=NodeSignal(signal).event.error
if(signalType == SignalType.NodeCrashed):
error "node.crashed", error=statusSignal
self.status.events.emit(signalType.event, signal)
proc signalReceived*(self: SignalsController, signal: string) {.signal.}
proc receiveSignal(self: SignalsController, signal: string) {.slot.} =
self.processSignal(signal)
self.signalReceived(signal)