@tanislav000/bluez
Version:
Bluez5 D-Bus bindings for easy to use bluetooth access in Node.js
258 lines (231 loc) • 9.42 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AgentWrapper = void 0;
const DBus = __importStar(require("dbus-next"));
const debug_1 = __importDefault(require("debug"));
const debug = (0, debug_1.default)("bluez:AgentWrapper");
class AgentWrapper extends DBus.interface.Interface {
constructor(agent, bluez) {
super("org.bluez.Agent1");
this.impl = agent;
this.bluez = bluez;
}
/**
void Release()
This method gets called when the service daemon
unregisters the agent. An agent can use it to do
cleanup tasks. There is no need to unregister the
agent, because when this method gets called it has
already been unregistered.
*/
Release() {
debug("Release");
if (this.impl.Release)
return this.impl.Release();
}
/**
string RequestPinCode(object device)
This method gets called when the service daemon
needs to get the passkey for an authentication.
The return value should be a string of 1-16 characters
length. The string can be alphanumeric.
Possible errors: org.bluez.Error.Rejected
org.bluez.Error.Canceled
*/
async RequestPinCode(device) {
debug("RequestPinCode", device);
if (this.impl.RequestPinCode) {
const dev = await this.bluez.getDeviceFromObject(device);
return this.impl.RequestPinCode(dev);
}
else {
throw new DBus.DBusError("org.bluez.Error.Rejected", "Not Supported", true);
}
}
/**
void DisplayPinCode(object device, string pincode)
This method gets called when the service daemon
needs to display a pincode for an authentication.
An empty reply should be returned. When the pincode
needs no longer to be displayed, the Cancel method
of the agent will be called.
This is used during the pairing process of keyboards
that don't support Bluetooth 2.1 Secure Simple Pairing,
in contrast to DisplayPasskey which is used for those
that do.
This method will only ever be called once since
older keyboards do not support typing notification.
Note that the PIN will always be a 6-digit number,
zero-padded to 6 digits. This is for harmony with
the later specification.
Possible errors: org.bluez.Error.Rejected
org.bluez.Error.Canceled
*/
async DisplayPinCode(device, pincode) {
debug("DisplayPinCode", device, pincode);
if (this.impl.DisplayPinCode) {
const dev = await this.bluez.getDeviceFromObject(device);
return this.impl.DisplayPinCode(dev, pincode);
}
else {
throw new DBus.DBusError("org.bluez.Error.Rejected", "Not Supported", true);
}
}
/**
uint32 RequestPasskey(object device)
This method gets called when the service daemon
needs to get the passkey for an authentication.
The return value should be a numeric value
between 0-999999.
Possible errors: org.bluez.Error.Rejected
org.bluez.Error.Canceled
*/
async RequestPasskey(device) {
debug("RequestPasskey", device);
if (this.impl.RequestPasskey) {
const dev = await this.bluez.getDeviceFromObject(device);
return this.impl.RequestPasskey(dev);
}
else {
throw new DBus.DBusError("org.bluez.Error.Rejected", "Not Supported", true);
}
}
/**
void DisplayPasskey(object device, uint32 passkey,
uint16 entered)
This method gets called when the service daemon
needs to display a passkey for an authentication.
The entered parameter indicates the number of already
typed keys on the remote side.
An empty reply should be returned. When the passkey
needs no longer to be displayed, the Cancel method
of the agent will be called.
During the pairing process this method might be
called multiple times to update the entered value.
Note that the passkey will always be a 6-digit number,
so the display should be zero-padded at the start if
the value contains less than 6 digits.
*/
async DisplayPasskey(device, passkey, entered) {
debug("DisplayPasskey", device, passkey, entered);
if (this.impl.DisplayPasskey) {
const dev = await this.bluez.getDeviceFromObject(device);
return this.impl.DisplayPasskey(dev, passkey, entered);
}
else {
throw new DBus.DBusError("org.bluez.Error.Rejected", "Not Supported", true);
}
}
/**
void RequestConfirmation(object device, uint32 passkey)
This method gets called when the service daemon
needs to confirm a passkey for an authentication.
To confirm the value it should return an empty reply
or an error in case the passkey is invalid.
Note that the passkey will always be a 6-digit number,
so the display should be zero-padded at the start if
the value contains less than 6 digits.
Possible errors: org.bluez.Error.Rejected
org.bluez.Error.Canceled
*/
async RequestConfirmation(device, passkey) {
debug("RequestConfirmation", device, passkey);
if (this.impl.RequestConfirmation) {
const dev = await this.bluez.getDeviceFromObject(device);
return this.impl.RequestConfirmation(dev, passkey);
}
else {
throw new DBus.DBusError("org.bluez.Error.Rejected", "Not Supported", true);
}
}
/**
void RequestAuthorization(object device)
This method gets called to request the user to
authorize an incoming pairing attempt which
would in other circumstances trigger the just-works
model, or when the user plugged in a device that
implements cable pairing. In the latter case, the
device would not be connected to the adapter via
Bluetooth yet.
Possible errors: org.bluez.Error.Rejected
org.bluez.Error.Canceled
*/
async RequestAuthorization(device) {
debug("RequestAuthorization", device);
if (this.impl.RequestAuthorization) {
const dev = await this.bluez.getDeviceFromObject(device);
return this.impl.RequestAuthorization(dev);
}
else {
throw new DBus.DBusError("org.bluez.Error.Rejected", "Not Supported", true);
}
}
/**
void AuthorizeService(object device, string uuid)
This method gets called when the service daemon
needs to authorize a connection/service request.
Possible errors: org.bluez.Error.Rejected
org.bluez.Error.Canceled
*/
async AuthorizeService(device, uuid) {
debug("AuthorizeService", device);
if (this.impl.AuthorizeService) {
const dev = await this.bluez.getDeviceFromObject(device);
return this.impl.AuthorizeService(dev, uuid);
}
else {
throw new DBus.DBusError("org.bluez.Error.Rejected", "Not Supported", true);
}
}
/**
void Cancel()
This method gets called to indicate that the agent
request failed before a reply was returned.
*/
async Cancel() {
debug("Cancel");
if (this.impl.Cancel)
return this.impl.Cancel();
}
}
exports.AgentWrapper = AgentWrapper;
AgentWrapper.configureMembers({
methods: {
Release: {},
RequestPinCode: { inSignature: "o", outSignature: "s" },
DisplayPinCode: { inSignature: "os" },
RequestPasskey: { inSignature: "o", outSignature: "u" },
DisplayPasskey: { inSignature: "ouq" },
RequestConfirmation: { inSignature: "ou" },
RequestAuthorization: { inSignature: "o" },
AuthorizeService: { inSignature: "os" },
Cancel: {},
},
});
//# sourceMappingURL=agentWrapper.js.map