npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dbus-native-async

v0.2.4

Published

D-bus protocol implementation in ES2015

Downloads

12

Readme

node dbus-native-async

D-bus protocol client and server for node.js

Installation

npm install dbus-native-async

or

git clone https://[email protected]/viktorlv30/dbus-native-async.git # clone the repo
cd node-dbus-async
npm install # install dependencies
sudo cp examples/build_try_ts2_2
node loginBusExample.js # if you want to test examples/loginBusExample.js
after call another console as Alt+F2 and login into one more time and return to first console - you should see the result

Usage

Short example using desktop notifications service

/// <reference path="../ts-interfaces/index.d.ts" />
/// <reference path="../ts-interfaces/utils.d.ts" />
/// <reference path="../node_modules/@types/node/index.d.ts"/>

const dbus = require('../index');
const systemBus = dbus.systemBus();
const sessionBus = dbus.sessionBus();

try {
    (async () => {
        console.log('START');
        let login1: any = undefined;
        //objname //path //name
        login1 = await systemBus.getInterface(
            'org.freedesktop.login1',
            '/org/freedesktop/login1',
            'org.freedesktop.login1.Manager');

        if (login1) {
            console.log('Manager ready');
            console.log('We can start to work!!! >>> ');
            let sesPIDId = undefined;

            sesPIDId = await login1.HandlePowerKey;
            console.log(`Login1 manager - sesPIDId - `, sesPIDId);
            let resolve1: any = undefined;
            resolve1 = await systemBus.getInterface(
                'org.freedesktop.resolve1',
                '/org/freedesktop/resolve1',
                'org.freedesktop.resolve1.Manager');
            let dns: object[] = await resolve1.DNS;
            dns.forEach(async (element: any[]) => {
                console.dir(element);
                try {
                    let [index, family, address] = element;
                    let name: object[] = await resolve1.ResolveAddress(index, family, address.data, 1);
                    console.dir(name);
                } catch (error) {
                    console.warn(`resolve1.ResolveAddress(ifindex, family, address, flags): ${error.message}`);
                }
            });
        } else {
            throw new Error(`Manager isn't created`);
        }
        login1.on('SessionNew', function (sessionId, sessionPath) {
            console.log(`[NEW][SESSION][${sessionId}]: ${sessionPath}`);
            (async () => {
                try {
                    let resolve1: any = undefined;
                    resolve1 = await systemBus.getInterface(
                        'org.freedesktop.resolve1',
                        '/org/freedesktop/resolve1',
                        'org.freedesktop.resolve1.Manager');
                    let dns: object[] = await resolve1.DNS;
                    dns.forEach(async (element) => {
                        console.log(`element - `, element);
                    });
                } catch (exception) {
                    console.error(`NEW session error - ${exception}`);
                }
            })();
        });
        login1.on('SessionRemoved', function (sessionId, sessionPath) {
            console.log(`[REMOVE][SESSION][${sessionId}]: ${sessionPath}`);
            (async () => {
                try {
                    let brightnessDisplayManager: any = undefined;
                    brightnessDisplayManager = await sessionBus.getInterface(
                        'org.freedesktop.PowerManagement',
                        '/org/kde/Solid/PowerManagement/Actions/BrightnessControl',
                        'org.kde.Solid.PowerManagement.Actions.BrightnessControl');

                    console.log(`brightnessDisplayManager - description`);
                    console.dir(brightnessDisplayManager);
                    let currentBrightness: number = await brightnessDisplayManager.brightness();
                    console.log(`end session currentBrightness - `, currentBrightness);
                    let brightnessMax: number = await brightnessDisplayManager.brightnessMax();
                    console.log(`end session brightnessMax - `, brightnessMax);
                    let newBrightness: number = (currentBrightness - 10) < 1000 ? brightnessMax : currentBrightness - 50;
                    // console.log(`end session newBrightness - `, newBrightness);
                    brightnessDisplayManager.setBrightness(newBrightness);
                } catch (exception) {
                    console.error(`end session brightnessDisplayManager REMOVE error - ${exception}`);
                }
            })();
        });
    })()
} catch (error) {
    console.error(`[ERROR] ${error}`);
}

API

Low level messaging: bus connection

connection = dbus.createClient(options)

options:

  • socket - unix socket path
  • port - TCP port
  • host - TCP host
  • busAddress - encoded bus address. Default is DBUS_SESSION_BUS_ADDRESS environment variable. See http://dbus.freedesktop.org/doc/dbus-specification.html#addresses
  • ( TODO: add/document option to use adress from X11 session )

connection has only one method, message(msg)

message fields:

  • type - methodCall, methodReturn, error or signal
  • path - object path
  • interface
  • destination
  • sender
  • member
  • serial
  • signature
  • body
  • errorName
  • replySerial

connection signals:

  • connect - emitted after successful authentication
  • message
  • error

example:

var dbus = require('dbus-native-async');
var conn = dbus.createConnection();
conn.message({
    path:'/org/freedesktop/DBus',
    destination: 'org.freedesktop.DBus',
    'interface': 'org.freedesktop.DBus',
    member: 'Hello',
    type: dbus.messageType.methodCall
});
conn.on('message', function(msg) { console.log(msg); });

Links

  • https://github.com/sidorares/node-dbus - original project
  • http://cgit.freedesktop.org/dbus - freedesktop reference C library