-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DeviceData and eventHandlers.js #14
base: master
Are you sure you want to change the base?
Conversation
eventHandlers.sample.js
Outdated
*/ | ||
|
||
/** | ||
* Fired when a REGISTER message is received, before creating a corresponding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description is misleading. The PoolAgent
was already created at this time (because it is created before the first register arrives). There is also no reason why the PoolAgent
instance is not a param on this function.
My suggestions would be
a) add PoolAgent
param to beforeRegister
b) rename beforeRegister
to onRegisterMessage
c) fix the description to state that it is fired before the message is processed by the PoolAgent
d) also rename onRegister
to onRegistrationCompleted
to make clear that it is fired after the registration.
src/PoolAgent.js
Outdated
@@ -37,6 +37,30 @@ class PoolAgent extends Nimiq.Observable { | |||
/** @type {Nimiq.Timers} */ | |||
this._timers = new Nimiq.Timers(); | |||
this._timers.resetTimeout('connection-timeout', () => this._onError(), this._pool.config.connectionTimeout); | |||
|
|||
// Public interface | |||
Object.defineProperties(this, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use ES6 getters in our codebase instead.
@mar-v-in Addressed your concerns. |
eventHandlers.sample.js
Outdated
* if registration should not continue. | ||
* @returns {void} | ||
*/ | ||
module.exports.onRegisterMessage = function onRegisterMessage(agent, msg, connectionPool) { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this one be async as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I'd leave it synchronous since I was catching with try/catch
but I suppose this will still work as async.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, exceptions do work across async/await
src/PoolAgent.js
Outdated
this._pool.requestCurrentHead(this); | ||
} | ||
await this.sendBalance(); | ||
this._timers.resetInterval('send-balance', () => this.sendBalance(), 1000 * 60 * 5); | ||
this._timers.resetInterval('send-keep-alive-ping', () => this._ws.ping(), 1000 * 10); | ||
|
||
this._pool.eventHandlers.onRegistrationCompleted(this, this._pool.connectionPool); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing await?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch
Thanks @mar-v-in, addressed second round of comments. |
* Fired when a REGISTER message is received, before being processed by the | ||
* PoolAgent. Good time to perform validation or mutation of message data. | ||
* @param {PoolAgent} agent - The Agent for the newly registered device. | ||
* @param {Object} msg - The full register message. This is not a copy; any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
msg
should definitely be a copy
This feels like it should be |
@mar-v-in Based on our conversation around nimiq-network/developer-reference#24
This PR does a few things:
deviceData
toPoolAgent
PoolAgent
, since we will now be exposing it to pool owners. Properties are:deviceId
,deviceLabel
,mode
,isRegistered
eventHandlers.sample.js
and support foreventHandlers.js
which allows pool owners to easily add handlers for events. I started withonRegister
andbeforeRegister
but this can be expanded on.