@interactivefitness/peripherals
v0.4.6
Published
IF Peripherals
Downloads
1
Readme
Interactive Fitness Peripherals
This abstracts the Pulse Audio and Bluez DBus APIs into an easy to use module.
Leveraging these APIs, this code watches for bluetooth peripheral changes and audio interface changes and using an event-driven architecture gives you the ability to make adjustments to these.
Install
It depends on the bluez
and @interactivefitness/paclient
sudo apt-get install -y curl pkg-config libdbus-1-dev libdbus-glib-1-dev
yarn add @interactivefitness/peripherals @interactivefitness/paclient bluez
Usage
import { Headsets } from "./Headsets";
import Express from "express";
const app = Express();
const hs = new Headsets();
const port = 4141;
app.get("/", (req, res) => res.send("Hello World!"));
app.get("/headsets", (req, res) => res.send(hs.devices));
// init headsets
hs.init().then(() => {
app.listen({ port: port }, () =>
console.log(`Example app listening on port ${port}!`)
);
});
/*
process.on("SIGINT", function() {
hs.onDestroy(function() {
console.error("connection closed due to app termination");
return process.exit(0);
});
});
*/
References
Bluez 5.50
https://launchpad.net/~bluetooth/+archive/ubuntu/bluez
The below would normally work, but it is not build for xenial.
sudo add-apt-repository ppa:bluetooth/bluez
sudo apt-get update
sudo apt-get install -y bluez
#
sudo apt-get install -y libglib2.0-dev libdbus-1-dev
So we have to do it as follows:
sudo apt install ./libreadline7_7.0-3_amd64.deb
cat > /etc/apt/sources.list.d/bluetooth-ubuntu-bluez-bionic.list
deb http://ppa.launchpad.net/bluetooth/bluez/ubuntu bionic main
# deb-src http://ppa.launchpad.net/bluetooth/bluez/ubuntu bionic main
sudo apt-get update
sudo apt-get install -y bluez
MacOS
See https://github.com/zbentley/dbus-osx-examples
brew install dbus
brew services start dbus
launchctl getenv DBUS_LAUNCHD_SESSION_BUS_SOCKET
export DISPLAY=':0'
export DBUS_SESSION_BUS_ADDRESS = 'unix:path=/run/dbus/system_bus_socket'
Manual Pulse Audio Configuration
bluetoothctl
pulseaudio --start
pactl load-module module-bluetooth-discover
pactl list short sinks
pacmd list-sinks | grep -e 'name:' -e 'index:'
pactl set-card-profile 3 a2dp_sink
pactl set-default-sink "bluez_sink.04_AA_00_0F_5C_94"