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

Signals in PulseAudio #296

Open
kd496 opened this issue Jun 28, 2023 · 0 comments
Open

Signals in PulseAudio #296

kd496 opened this issue Jun 28, 2023 · 0 comments

Comments

@kd496
Copy link

kd496 commented Jun 28, 2023

Hi everyone,

I'm using this module with PulseAudio and it works well except for subscribing to a signal.
The code below is annotated with approaches A and B.

A. Throws immediately.

Error: Method "AddMatch" with signature "s" on interface "org.freedesktop.DBus" doesn't exist

    at DBusInterface.<anonymous> (/home/kd/Desktop/bluetooth/samples/node_modules/dbus-native/lib/introspect.js:102:22)

B. It first logs what seems to be the same error that is thrown in A, but apart from that everything is as expected.

{
  serial: 3,
  errorName: 'org.freedesktop.DBus.Error.UnknownMethod',
  replySerial: 3,
  signature: 's',
  type: 3,
  flags: 1,
  body: [
    `Method "AddMatch" with signature "s" on interface "org.freedesktop.DBus" doesn't exist\n`
  ]
}
{
  serial: 4,
  path: '/org/pulseaudio/core1',
  interface: 'org.PulseAudio.Core1',
  member: 'NewSink',
  signature: 'o',
  type: 4,
  flags: 1,
  body: [ '/org/pulseaudio/core1/sink5' ]
}

Could someone explain what is going on here? I wrote a working python equivalent and here's a post it is based on. Might be useful.

My code:

import * as dbus from 'dbus-native';

async function getAddress(): Promise<string | null> {
    const bus = dbus.sessionBus();

    const promise = new Promise<string | null>((resolve, reject) => {
        bus.getService('org.PulseAudio1').getInterface('/org/pulseaudio/server_lookup1', 'org.freedesktop.DBus.Properties', (err, iface) => {
            if (err) {
                reject(err);
            }

            iface.Get('org.PulseAudio.ServerLookup1', 'Address', (err, result) => {
                if (err) {
                    reject(err);
                }

                let address = result[1][0];
                address = address.replace('unix:path=', '')
                resolve(address);
            })
        })
    })

    return promise;
}

async function subscribeSinkEvents(conn: any) {
    conn.getService("org.PulseAudio.Core1").getInterface('/org/pulseaudio/core1',
        'org.PulseAudio.Core1', (err, core) => {
            if (err) {
                throw new Error(err);
            }

            core.ListenForSignal('org.PulseAudio.Core1.NewSink', [], (err, result) => {
                if (err) {
                    console.error(`err: ${err}`);
                }

                // A 
                core.on('NewSink', console.log);
                //


                // B
                conn.connection.on('message', console.log);
                const match = "type='signal',destination='org.PulseAudio.Core1',path='/org/pulseaudio/core1',interface='org.PulseAudio.Core1',member='NewSink'";
                conn.addMatch(match, () => { })
                //
            })

        });
}

const address = await getAddress();

const conn = dbus.createClient({
    socket: address,
    direct: true,
})

subscribeSinkEvents(conn);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant