Summary
The documentation of the events emitted by the VrpcRemote seems to:
- deviate from the actual behaviour of the VrpcRemote
- be a bit unclear as to how it behaves in some usecases/flows.
The events are mentioned below are connected, connect, reconnect, close, offline, end, instanceNew, instanceGone and error.
The connected, connect, reconnect, close, offline and end events
const remote = new VrpcRemote({
broker: `wss:${window.location.host}/mqtt`,
domain: 'internal.cybus',
bestEffort: true,
username,
password
})
console.group('Setting up listeners')
remote.on('connected', () => console.log('Event fired: connected'))
remote.on('connect', () => console.log('Event fired: connect'))
remote.on('reconnect', () => console.log('Event fired: reconnect'))
remote.on('close', () => console.log('Event fired: close'))
remote.on('offline', () => console.log('Event fired: offline'))
remote.on('end', () => console.log('Event fired: end'))
console.groupEnd()
console.group('Connecting...')
await remote.connect()
console.groupEnd()
console.group('Ending...')
await remote.end()
console.groupEnd()
console.group('Connecting again...')
await remote.connect()
console.groupEnd()
Expected Behavior
Setting up listeners
Connecting...
Event fired: connect
Event fired: connected
Ending...
Event fired: end
Event fired: close
Connecting again...
Event fired: reconnect
Event fired: connect
Event fired: connected
Actual
Setting up listeners
Connecting...
Event fired: connect
Ending...
Connecting again...
Event fired: connect
Furthermore, it's not clear to me when the offline
event should be fired, is it along with the close event? Or is it when there is a external reason for the disconnection? Which then would be brought along side an error event?
Documentation used to base these assumptions:
Connected event
Connect event
Close event
End event
Offline event
Reconnect event
Instance New and Instance Gone events
Instance New and Instance Gone are fired once per instance type, but only for the first connection.
Before the code block below was executed, the instances called docker
, core
, testserviceb
and servicesCatalog
were created, but I think they are not relevant to the behaviour.
const remote = new VrpcRemote({
broker: `wss:${window.location.host}/mqtt`,
domain: 'internal.cybus',
bestEffort: true,
username,
password
})
console.group('Setting up listeners')
remote.on('instanceNew', (added) => console.log('Event fired: instanceNew', added))
remote.on('instanceGone', (gone) => console.log('Event fired: instanceGone', gone))
console.groupEnd()
console.group('Connecting...')
await remote.connect()
console.groupEnd()
console.group('Ending...')
await remote.end()
console.groupEnd()
console.group('Connecting again...')
await remote.connect()
console.groupEnd()
Expected Behavior
Setting up listeners
Connecting...
Event fired: instanceNew ["docker", "core"]
Event fired: instanceNew ["testserviceb"]
Event fired: instanceNew ["servicesCatalog"]
Ending...
Connecting again...
Event fired: instanceNew ["docker", "core"]
Event fired: instanceNew ["testserviceb"]
Event fired: instanceNew ["servicesCatalog"]
Actual
Setting up listeners
Connecting...
Event fired: instanceNew ["docker", "core"]
Event fired: instanceNew ["testserviceb"]
Event fired: instanceNew ["servicesCatalog"]
Ending...
Connecting again...
Documentation:
InstanceGone Event
InstanceNew Event
Error events
Error events seems to only fire on connection issues, due to bad authentication arguments/wrong domain configuration
If I turn off the broker and agents during an active connection, no error event is fired.
Documentation:
Error event
Desktop
- OS: Ubuntu 20.04
- Browser: Chrome
- Version 2.3.2
If you need further context/I missed something, please let me know.