-
Notifications
You must be signed in to change notification settings - Fork 8
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
configurable ping interval #49
Conversation
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.
Like the ping interval option, but not sure about the other one
src/hyperdeck/hyperdeck-core.js
Outdated
client.on('error', function(e) { | ||
|
||
// https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback | ||
client.setTimeout(cfg.timeout); |
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 don't think this makes sense? The documentation says this does nothing except trigger the 'timeout' event which we are not handling
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, will remove this.
src/hyperdeck/hyperdeck-core.js
Outdated
**/ | ||
function HyperdeckCore(ip) { | ||
function HyperdeckCore(config) { | ||
if (config === null) { |
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 think this should be
typeof config !== 'string' && typeof config !== 'object'
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.
see below
src/hyperdeck/hyperdeck-core.js
Outdated
function HyperdeckCore(ip) { | ||
function HyperdeckCore(config) { | ||
if (config === null) { | ||
throw 'Invalid Configuration, please refer to documentations.'; |
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.
It's better to throw an Error object so there's a stack trace.
throw new Error('...');
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.
if (config == null || ((typeof config) !== 'string' && config.hasOwnProperty('ip') === false)) {
throw new Error('Invalid Configuration, please refer to documentations.');
}
Thinking like 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.
== null is OK because it will also catch 'undefined'
But I think it would be clearer though to be more explicit like
function isConfigValid(config) {
return (
typeof config === 'string' ||
(typeof config === 'object' && !!config.ip)
);
}
...
if (!isConfigValid(config))
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.
On phone and it's removed all the indentation
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.
if config = null
then typeof config === 'object'
will be true and config.ip
will throw exception
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.
Ah l see in which case
(typeof config === 'object' && && config !== null && !!config.ip)
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.
if use config != null
then npm test
fails so did like below:
/**
* validate configuration
*
* @param {*} config
*/
function isConfigValid(config) {
return (
config !== undefined &&
config !== null &&
(typeof config === 'string' || !!config.ip)
);
}
// check for valid configuration
if (!isConfigValid(config)) {
throw new Error('Invalid Configuration, please refer to documentations.');
}
src/hyperdeck/hyperdeck-core.js
Outdated
var self = this; | ||
var cfg = {}; |
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.
This can be a bit neater using Object.assign
var cfg = Object.assign({ pingInterval: 10000 }, config)
Where you would check if the provided config is a string and set it to { ip: config } above if it is
This also means we never mutate the input :)
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.
var cfg = {};
if (typeof config === 'string') {
cfg.ip = config;
}
cfg = Object.assign({ pingInterval: 10000, timeout: 3000 }, cfg);
Do you mean like 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.
Almost
if (typeof config === 'string') {
config = { ip: config };
}
config = Object.assign({ pingInterval: 10000, timeout: 3000 }, config);
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.
you mean:
if (typeof config === 'string') {
config = { ip: config };
}
config = Object.assign({ pingInterval: 10000, timeout: 3000 }, config);
yes its better
src/hyperdeck/hyperdeck-core.js
Outdated
**/ | ||
function HyperdeckCore(ip) { | ||
function HyperdeckCore(config) { | ||
if (config === undefined || |
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.
See other comment :)
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.
Looks great thanks! Will merge and publish a new version when I'm at a computer
No description provided.