Skip to content
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

Enable TCP connections and export createClient method #23

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ let createClient = function(params) {
return new MessageBus(connection);
};

/**
* Create a new {@link MessageBus} client on a manually defined bus to connect to
* interfaces or request service names. Connects to the socket specified by the
* properties assigned.
*/
module.exports.createClient = createClient;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to expose this. Just use sessionBus(). It's the same thing

https://github.com/acrisci/node-dbus-next/blob/a241269c6e917e22ae6e9f1015713751192469ff/index.js#L40-L42

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but that's a bit of a strange way to access the system bus...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can allow to override the address for systemBus() if you want. Or propose to have only one function to create a bus.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or propose to have only one function to create a bus.

Isn't this actually what I'm doing here, other than leaving two 'convenience' functions for systemBus and sessionBus? Removing those would be quite a major breaking change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quite a major breaking change.

FYI I'm still probably about 2 months from a stable api and have some other major breaking changes planned that are worse than this. It's something I want to get right because I'm copying this pattern in the python version of this library.

I think one or two functions would be a good idea, but three is too many.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about something like this?

dbus.connect({
  bus: "system" | "session" | "unix:path=/tmp/foo" | "tcp:host=localhost,port=1234"
})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the way this looks actually. Open a new issue for it though because there are some subtle points.

/**
* Create a new {@link MessageBus} client on the DBus system bus to connect to
* interfaces or request service names. Connects to the socket specified by the
Expand Down
4 changes: 3 additions & 1 deletion lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ function createStream(opts) {
try {
switch (family.toLowerCase()) {
case 'tcp':
throw new Error('tcp dbus connections are not supported');
host = params.host || 'localhost';
port = params.port;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I like the idea of being able to override address string properties with option parameters because then we have to do it for every parameter. Just specify it in the address like tcp:host=127.0.0.1,port=4242 and we should be able to parse it out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, that's actually what this is doing, my mistake. I mistook params for opts. 👍

return net.createConnection(port, host);
case 'unix':
if (params.socket) {
return net.createConnection(params.socket);
Expand Down