UNPKG

@tanislav000/bluez

Version:

Bluez5 D-Bus bindings for easy to use bluetooth access in Node.js

88 lines 3.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OrgBluezNetwork1 = void 0; const events_1 = require("events"); const utilts_1 = require("../utilts"); /* * Generated by dbus-next interface generator * Template: typescript-class.ts.hbs */ /** * Service: org.bluez * ObjectPath: /org/bluez/hci0/* * Interface: org.bluez.Network1 */ class OrgBluezNetwork1 extends events_1.EventEmitter { static Connect(bus, objectPath, xml) { return bus.getProxyObject("org.bluez", objectPath, xml).then((obj) => new OrgBluezNetwork1(obj)); } constructor(dbusObject) { super(); this.dbusInterfaceName = "org.bluez.Network1"; this.dbusObject = dbusObject; this.thisDBusInterface = this.dbusObject.getInterface("org.bluez.Network1"); this.propertiesDBusInterface = this.dbusObject.getInterface("org.freedesktop.DBus.Properties"); // forward property change events const forwardPropertyChange = (iface, changed, invalidated) => { if (iface === this.dbusInterfaceName) { this.emit("PropertiesChanged", iface, (0, utilts_1.unwrapDbusVariantObject)(changed), invalidated); } }; // forward all signals this.on("newListener", (event, listener) => { if (event === "PropertiesChanged" && this.listenerCount("PropertiesChanged") === 0) { this.propertiesDBusInterface.on("PropertiesChanged", forwardPropertyChange); } else { this.thisDBusInterface.on(event, listener); } }); this.on("removeListener", (event, listener) => { if (event === "PropertiesChanged" && this.listenerCount("PropertiesChanged") === 0) { this.propertiesDBusInterface.removeListener("PropertiesChanged", forwardPropertyChange); } else { this.thisDBusInterface.removeListener(event, listener); } }); } /***** Properties *****/ getProperties() { return this.propertiesDBusInterface.GetAll(this.dbusInterfaceName).then(utilts_1.unwrapDbusVariantObject); } getProperty(name) { return this.propertiesDBusInterface.Get(this.dbusInterfaceName, name).then(utilts_1.unwrapDbusVariant); } setProperty(name, value) { return this.propertiesDBusInterface.Set(this.dbusInterfaceName, name, (0, utilts_1.wrapDbusVariant)(value)); } //@property({ name: 'Connected', signature: 'b', access: ACCESS_READ }) Connected() { return this.propertiesDBusInterface .Get(this.dbusInterfaceName, "Connected") .then((variant) => variant.value); } //@property({ name: 'Interface', signature: 's', access: ACCESS_READ }) Interface() { return this.propertiesDBusInterface .Get(this.dbusInterfaceName, "Interface") .then((variant) => variant.value); } //@property({ name: 'UUID', signature: 's', access: ACCESS_READ }) UUID() { return this.propertiesDBusInterface .Get(this.dbusInterfaceName, "UUID") .then((variant) => variant.value); } /***** Methods *****/ //@method({ name: 'Connect', inSignature: 's', outSignature: 's' }) Connect(uuid) { return this.thisDBusInterface.Connect(uuid).then(utilts_1.unwrapDbusVariantAll); } //@method({ name: 'Disconnect', inSignature: '', outSignature: '' }) Disconnect() { return this.thisDBusInterface.Disconnect().then(utilts_1.unwrapDbusVariantAll); } } exports.OrgBluezNetwork1 = OrgBluezNetwork1; //# sourceMappingURL=Network1.js.map