Skip to content

Commit

Permalink
update README, dependencies and lint (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
bwp91 authored Apr 10, 2024
1 parent 9748bde commit dfb6e9f
Show file tree
Hide file tree
Showing 47 changed files with 1,811 additions and 6,489 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ node_modules
npm-debug.log

.nyc_output

.idea
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
node-dbus
===========
<p align="center">
<a href="https://homebridge.io"><img src="https://raw.githubusercontent.com/homebridge/branding/latest/logos/homebridge-color-round-stylized.png" height="140"></a>
</p>

<span align="center">

# D-Bus Native

[![Greenkeeper badge](https://badges.greenkeeper.io/sidorares/dbus-native.svg)](https://greenkeeper.io/)
[![Node Test](https://github.com/homebridge/dbus-native/actions/workflows/run-test.yml/badge.svg)](https://github.com/homebridge/dbus-native/actions/workflows/run-test.yml)

D-bus protocol client and server for node.js
</span>

D-bus protocol client and server for node.js

Fork Status
------------

This fork is maintained with the following two changes:
This fork is maintained with the following changes:
* Removed the optional `abstract-socket` dependency for faster installs
* Moved to our `long.js` fork to work around a crash on `ARMv6` platforms running node 16.1+
* Updated dependencies (including `prettier`, which has made style changes to a lot of files)

Installation
------------
Expand Down
20 changes: 10 additions & 10 deletions bin/dbus-dissect.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ console.log(isSystemBus);
var address = isSystemBus ? '/var/run/dbus/system_bus_socket' : `\0${m[1]}`;

function waitHandshake(stream, prefix, cb) {
readLine(stream, function(line) {
readLine(stream, function (line) {
console.log(prefix, line.toString());
if (
line.toString().slice(0, 5) === 'BEGIN' ||
Expand All @@ -31,14 +31,14 @@ function waitHandshake(stream, prefix, cb) {
}

net
.createServer(function(s) {
.createServer(function (s) {
var buff = '';
var connected = false;

var socket = isSystemBus ? net : abs;
var cli = socket.connect(address);

s.on('data', function(d) {
s.on('data', function (d) {
if (connected) {
cli.write(d);
} else {
Expand All @@ -53,26 +53,26 @@ net
var ss = through2();

// TODO: pipe? streams1 and streams2 here
cli.on('data', function(b) {
cli.on('data', function (b) {
cc.write(b);
});
s.on('data', function(b) {
s.on('data', function (b) {
ss.write(b);
});

waitHandshake(cc, 'dbus>', function() {
message.unmarshalMessages(cc, function(message) {
waitHandshake(cc, 'dbus>', function () {
message.unmarshalMessages(cc, function (message) {
console.log('dbus>\n', JSON.stringify(message, null, 2));
});
});

waitHandshake(ss, ' cli>', function() {
message.unmarshalMessages(ss, function(message) {
waitHandshake(ss, ' cli>', function () {
message.unmarshalMessages(ss, function (message) {
console.log(' cli>\n', JSON.stringify(message, null, 2));
});
});
})
.listen(3334, function() {
.listen(3334, function () {
console.log(
'Server started. connect with DBUS_SESSION_BUS_ADDRESS=tcp:host=127.0.0.1,port=3334'
);
Expand Down
6 changes: 3 additions & 3 deletions bin/dbus2js.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ function getXML(callback) {
}

if (argv.dump) {
getXML(function(err, xml) {
getXML(function (err, xml) {
console.log(xml);
bus.connection.end();
});
}

if (!argv.server) {
getXML(function(err, xml) {
getXML(function (err, xml) {
if (err) die(err);

var output = [];

var parser = new xml2js.Parser(xml2js_opts);
parser.parseString(xml, function(err, result) {
parser.parseString(xml, function (err, result) {
if (err) die(err);

var ifaceName, method, property, iface, arg, signature;
Expand Down
6 changes: 3 additions & 3 deletions examples/active-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ bus.connection.on('message', console.log);
ayatana.getInterface(
'/org/ayatana/bamf/matcher',
'org.ayatana.bamf.matcher',
function(err, bm) {
function (err, bm) {
console.log(err, bm);
bm.on('ActiveWindowChanged', function(oldwin, newwin) {
bm.on('ActiveWindowChanged', function (oldwin, newwin) {
console.log('ActiveWindowChanged', oldwin, newwin);
});
bm.on('ActiveApplicationChanged', function(oldwin, newwin) {
bm.on('ActiveApplicationChanged', function (oldwin, newwin) {
console.log('ActiveApplicationChanged', oldwin, newwin);
});
}
Expand Down
6 changes: 3 additions & 3 deletions examples/bamf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ bus.connection.on('message', console.log);
ayatana.getInterface(
'/org/ayatana/bamf/matcher',
'org.ayatana.bamf.matcher',
function(err, bm) {
function (err, bm) {
console.log(err, bm);
bm.on('ActiveWindowChanged', function(oldwin, newwin) {
bm.on('ActiveWindowChanged', function (oldwin, newwin) {
console.log('ActiveWindowChanged', oldwin, newwin);
});
bm.on('ActiveApplicationChanged', function(oldwin, newwin) {
bm.on('ActiveApplicationChanged', function (oldwin, newwin) {
console.log('ActiveApplicationChanged', oldwin, newwin);
});
}
Expand Down
4 changes: 1 addition & 3 deletions examples/basic-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ service.getInterface(objectPath, interfaceName, (err, iface) => {
if (err) {
console.error(
`Failed to request interface '${interfaceName}' at '${objectPath}' : ${err}`
? err
: '(no error)'
);
process.exit(1);
}
Expand All @@ -54,7 +52,7 @@ service.getInterface(objectPath, interfaceName, (err, iface) => {
});
});

iface.on('Rand', nb => {
iface.on('Rand', (nb) => {
console.log(`Received Rand: ${nb}`);
});
});
8 changes: 4 additions & 4 deletions examples/basic-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ function proceed() {

// Then we need to create the interface implementation (with actual functions)
var iface = {
SayHello: function() {
SayHello: function () {
return 'Hello, world!';
},
GiveTime: function() {
GiveTime: function () {
return new Date().toString();
},
Capitalize: function(str) {
Capitalize: function (str) {
return str.toUpperCase();
},
Flag: true,
StringProp: 'initial string',
emit: function() {
emit: function () {
// no nothing, as usual
}
};
Expand Down
6 changes: 2 additions & 4 deletions examples/client-signals.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ targetService.getInterface(targetObjectPath, targetIfaceName, (err, iface) => {
if (err || !iface) {
console.error(
`Could not query interface '${targetIfaceName}', the error was: ${err}`
? err
: '(no error)'
);
process.exit(1);
}
Expand All @@ -46,14 +44,14 @@ targetService.getInterface(targetObjectPath, targetIfaceName, (err, iface) => {
Here, 'iface' represents the service's interface. It is made an event emitter, so to listen to signals, we
just have to do like any other signals: on('signalName')
*/
iface.on('Tick', date => {
iface.on('Tick', (date) => {
console.log(`Signal 'Tick' received! The date is: '${date}'`);
});

/*
Here we listen for the second signal.
*/
iface.on('Rand', randomNumber => {
iface.on('Rand', (randomNumber) => {
console.log(`We've got our random number: ${randomNumber}`);
});
});
10 changes: 5 additions & 5 deletions examples/dbusproxy/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ var sockjs_opts = {
};

var sockjs_echo = sockjs.createServer(sockjs_opts);
sockjs_echo.on('connection', function(conn) {
sockjs_echo.on('connection', function (conn) {
var dbusConn = dbus.sessionBus().connection;
conn.on('data', function(message) {
conn.on('data', function (message) {
//conn.write(message);
try {
//console.log('about to parse', message)
Expand All @@ -25,7 +25,7 @@ sockjs_echo.on('connection', function(conn) {
//console.log('sent to dbus');
} catch (e) {}
});
dbusConn.on('message', function(msg) {
dbusConn.on('message', function (msg) {
//console.log('GOT MESSAGE', msg);
conn.write(JSON.stringify(msg));
//conn.write(msg);
Expand All @@ -37,10 +37,10 @@ var static_directory = new node_static.Server(__dirname);

// 3. Usual http stuff
var server = http.createServer();
server.addListener('request', function(req, res) {
server.addListener('request', function (req, res) {
static_directory.serve(req, res);
});
server.addListener('upgrade', function(req, res) {
server.addListener('upgrade', function (req, res) {
res.end();
});

Expand Down
2 changes: 1 addition & 1 deletion examples/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ conn.message({
body: ["type='method_return'"]
});

conn.on('message', function(msg) {
conn.on('message', function (msg) {
if (!msg.body) return;
//console.log(JSON.stringify(msg, 0, 4)); //TODO: dbus-monitor pretty-print
});
8 changes: 4 additions & 4 deletions examples/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ var notify = bus.getService('org.freedesktop.Notifications');
notify.getInterface(
'/org/freedesktop/Notifications',
'org.freedesktop.Notifications',
function(err, nm) {
function (err, nm) {
console.log(nm);
nm.on('ActionInvoked', function() {
nm.on('ActionInvoked', function () {
console.log('ActionInvoked', arguments);
});
nm.on('NotificationClosed', function() {
nm.on('NotificationClosed', function () {
console.log('NotificationClosed', arguments);
});
nm.Notify(
Expand All @@ -22,7 +22,7 @@ notify.getInterface(
['xxx yyy', 'test2', 'test3', 'test4'],
[],
5,
function(err /*, id*/) {
function (err /*, id*/) {
console.log(err);
//setTimeout(function() { n.CloseNotification(id, console.log); }, 4000);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/p2p/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const dbus = require('../../index');

var count = 0;
const conn = dbus.createConnection({ port: 3333, handshake: 'none' });
conn.on('message', function(msg) {
conn.on('message', function (msg) {
if (msg.serial) {
msg.serial += 1;
} else {
Expand All @@ -12,7 +12,7 @@ conn.on('message', function(msg) {
count++;
});

setInterval(function() {
setInterval(function () {
console.log(count);
count = 0;
}, 1000);
4 changes: 2 additions & 2 deletions examples/p2p/serv.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const dbus = require('../../index');

dbus
.createServer(function(conn) {
conn.on('message', function(msg) {
.createServer(function (conn) {
conn.on('message', function (msg) {
if (msg.serial) {
msg.serial += 1;
} else {
Expand Down
22 changes: 11 additions & 11 deletions examples/return-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,46 +96,46 @@ function proceed() {

// Then we need to create the interface implementation (with actual functions)
iface = {
SayHello: function() {
SayHello: function () {
return 'Hello, world!'; // This is how to return a single string
},
GetInt16: function() {
GetInt16: function () {
var min = -0x7fff - 1;
var max = 0x7fff;
return Math.round(Math.random() * (max - min) + min);
},
GetUInt16: function() {
GetUInt16: function () {
var min = 0;
var max = 0xffff;
return Math.round(Math.random() * (max - min) + min);
},
GetInt32: function() {
GetInt32: function () {
var min = -0x7fffffff - 1;
var max = 0x7fffffff;
return Math.round(Math.random() * (max - min) + min);
},
GetUInt32: function() {
GetUInt32: function () {
var min = 0;
var max = 0xffffffff;
return Math.round(Math.random() * (max - min) + min);
},
GetBool: function() {
GetBool: function () {
return Math.random() >= 0.5 ? true : false;
},
GetDouble: function() {
GetDouble: function () {
/*
We are only returning a number between 0 and 1 here, but this is just for the test.
Javascript can handle number between Number.MIN_VALUE and Number.MAX_VALUE, which are 5e-234 and 1.7976931348623157e+308 respectively.
There would be no point in returing such big numbers for this demo, but this is perfectly okay with DBus.
*/
return Math.random();
},
GetByte: function() {
GetByte: function () {
var min = 0x00;
var max = 0xff;
return Math.round(Math.random() * (max - min) + min);
},
GetArrayOfStrings: function(n) {
GetArrayOfStrings: function (n) {
// Check that we requested a positive number of elements, and not a too big one
if (n < 0 || n > 255) {
// Return a DBus error to indicate a problem (shows how to send DBus errors)
Expand All @@ -151,7 +151,7 @@ function proceed() {

return ret; // 'ret' is an array, to return an array, we simply return it
},
GetCustomStruct: function() {
GetCustomStruct: function () {
var min = -0x7fffffff - 1;
var max = 0x7fffffff;
var string =
Expand All @@ -165,7 +165,7 @@ function proceed() {
*/
return [string, int32, bool];
},
GetDictEntry: function() {
GetDictEntry: function () {
var min = -0x7fffffff - 1;
var max = 0x7fffffff;
var key1 = 'str1';
Expand Down
2 changes: 1 addition & 1 deletion examples/service-signals.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function proceed() {
Here we use the neat ES6 syntax, the spread operator (...), this basically says "bind the first argument in
the variable 'signalName' and all others in 'signalOutputParams'"
*/
emit: function(signalName, ...signalOutputParams) {
emit: function (signalName, ...signalOutputParams) {
/*
Now we are in the body of the 'emit()' function of the interface.
Just to be clear: you dont NEED to put ANYTHING in this body. When you call 'bus.exportInterface()',
Expand Down
Loading

0 comments on commit dfb6e9f

Please sign in to comment.