diff --git a/src/jdom/bus.ts b/src/jdom/bus.ts index 16b980fcf..875149591 100644 --- a/src/jdom/bus.ts +++ b/src/jdom/bus.ts @@ -185,6 +185,11 @@ export interface BusOptions { * Additional serial connection vendor ids */ serialVendorIds?: number[] + + /** + * Custom services + */ + services?: jdspec.ServiceSpec[] } /** @@ -276,6 +281,7 @@ export class JDBus extends JDNode { serviceProviderIdSalt, resetIn, serialVendorIds, + services, } = options || {} this._roleManagerClient = undefined @@ -292,7 +298,6 @@ export class JDBus extends JDNode { // some transport may be undefined transports?.filter(tr => !!tr).map(tr => this.addTransport(tr)) - // tell loggers to send data, every now and then // send resetin packets this.on(SELF_ANNOUNCE, this.handleSelfAnnounce.bind(this)) @@ -301,7 +306,8 @@ export class JDBus extends JDNode { // grab the default role manager if (!disableRoleManager) this.on(DEVICE_CHANGE, this.handleRoleManager.bind(this)) - + // extra services + if (services?.length) loadServiceSpecifications(services) // start all timers this.start() } diff --git a/src/jdom/spec.ts b/src/jdom/spec.ts index 737e37a51..96e119c8c 100644 --- a/src/jdom/spec.ts +++ b/src/jdom/spec.ts @@ -53,6 +53,11 @@ export function loadServiceSpecifications( const shortIds = new Set(specs.map(s => s.shortId)) for (const spec of specifications) { if (serviceClasses.has(spec.classIdentifier)) { + const existingSpec = specs.find( + s => s.classIdentifier === spec.classIdentifier + ) + if (JSON.stringify(existingSpec) === JSON.stringify(spec)) + continue // inserting a duplicate, ignore errors.push({ message: "classIdentifier already in use", spec,