sidorares / dbus-native

D-bus protocol client and server for node.js written in native javascript
Other
259 stars 93 forks source link

New high-level client and service interfaces #251

Open acrisci opened 5 years ago

acrisci commented 5 years ago

Changes from my fork, dbus-next.

I use some ES6 stuff like destructuring and classes which might require bumping the required node version up to 6.0.

But other than that, no breaking changes! All the new interfaces are built on top of the existing low level interfaces and should not interfere with any of the existing code. Only 8 lines have been removed with minimal logic changes.

The README includes examples of the new interfaces.

Check out the new mpris controller script for a complete example of the client in action and doing something useful.

There's also a working example of the service interface.

All the new interfaces have very good integration tests which use a real dbus connection to test both the client and the service at the same time.

Run integration tests:

npm run integration

Coverage of the new interfaces is about 87 percent:

npm run coverage
Sun1ive commented 5 years ago

any news on this?

acrisci commented 5 years ago

@Sun1ive I've released dbus-next on npm so people can start using it now if they want.

https://www.npmjs.com/package/dbus-next

Sun1ive commented 5 years ago

@Sun1ive I've released dbus-next on npm so people can start using it now if they want.

https://www.npmjs.com/package/dbus-next

thank you! ill give it a try

CyDragon80 commented 5 years ago

Just a random thought, if this new interface is entirely optional, is it possible to simply hide it in versions less than node 7 and expose it in newer versions using the dynamic nature of javascript. By hiding 7+ language features in modules that are only brought in if node is 7+, one might be able to avoid throwing errors in older node in theory. Whether it's worth the extra transitional code or best to wait for the next major package rev is certainly debatable, but thought I'd mention it in case it's of any use to anyone.

function getNodeMajor()
{
    var reg = /^[^\d]*(\d+)/;
    var temp = reg.exec(process.version);
    return (temp==null||temp[1]==null?0:parseInt(temp[1]));
}
module.exports.NodeMajor = getNodeMajor(); // only need to compute once
. . .
if (module.exports.NodeMajor >= 7)
{
    // new feature just for 7+
    const OptionalBit = require('optional-bit'); // module containing newer language features
    module.exports.newThing = OptionalBit.newThing; // new package feature export
    // etc etc
}
else
{
    // fallback if any? or leave new stuff undefined?
    module.exports.newThing = null; // ?
    module.exports.newThing = function() { throw new Error('Feature needs Node 7+')}; // ?
}