-
Notifications
You must be signed in to change notification settings - Fork 463
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
feat(cli): supports ws and wss protocols #1310
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,14 @@ const send = ( | |
} else { | ||
basicLog.published() | ||
} | ||
client.end() | ||
// FIXME: When using the ws and wss protocols to connect, and QoS is 0, the message may not have been successfully sent when the publish callback is triggered. Therefore, delay closing the connection for 2 seconds. | ||
if (['ws', 'wss'].includes(connOpts.protocol ?? '') && pubOpts.opts.qos === 0) { | ||
setTimeout(() => { | ||
client.end() | ||
}, 2000) | ||
} else { | ||
client.end() | ||
} | ||
}) | ||
}) | ||
client.on('error', (err) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the code review:
Overall, the code looks good and follows the best practices. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ declare global { | |
username?: string | ||
password?: string | ||
protocol?: Protocol | ||
path?: string | ||
key?: string | ||
cert?: string | ||
ca?: string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code patch looks correct, but there are a few things to consider. First, the new addition of the "path" variable should be declared with a type, such as string or number, to ensure that it is used correctly. Second, it would be best to add a comment explaining the purpose of the added variable, for future maintainers. Third, the global scope could potentially be too broad for the variable's use case. Consider if there are other scopes, such as a function or class, that the variable should be declared in instead. Finally, a test should be written to ensure that the variable is working as expected. Overall, this code patch looks good but it would be beneficial to add more details and tests before implementing it in production. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,8 @@ const parseNumber = (value: string) => { | |
} | ||
|
||
const parseProtocol = (value: string) => { | ||
if (!['mqtt', 'mqtts'].includes(value)) { | ||
signale.error('Only mqtt and mqtts are supported.') | ||
if (!['mqtt', 'mqtts', 'ws', 'wss'].includes(value)) { | ||
signale.error('Only mqtt, mqtts, ws and wss are supported.') | ||
process.exit(1) | ||
} | ||
return value | ||
|
@@ -156,6 +156,7 @@ const parseConnectOptions = ( | |
username, | ||
password, | ||
protocol, | ||
path, | ||
key, | ||
cert, | ||
ca, | ||
|
@@ -190,6 +191,7 @@ const parseConnectOptions = ( | |
username, | ||
password, | ||
protocol, | ||
path, | ||
reconnectPeriod, | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with the code review. The first part of the patch changes the error message that is displayed when an invalid protocol is entered. This is a good change, as it makes the error message more informative. The second part adds a new parameter, path, to the parseConnectOptions function. This is also a good change, as it allows the user to specify a custom path for their connection. Overall, the patch looks good and should be accepted. |
||
|
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 code review.
Firstly, I recommend you to consider using DRY principle (Don't Repeat Yourself). It looks like you have repeated the same code several times, which is unnecessary and can cause errors if you need to make changes later on.
Secondly, it's important to make sure that all the options are properly documented and the default values are clearly defined. As you have already done this, I suggest a more detailed documentation for the '--path ' option.
Thirdly, it would be beneficial to consider adding some error handling code to your code in order to prevent any unexpected errors.
Finally, I suggest that you should test your code thoroughly in order to ensure that it works properly.
I hope these suggestions help you improve your code patch.