thank you Marcus.
for fullness (for future readers) I have pasted the whole ts file below. it contains much that is unlikely to be germane to this issue.
I have given your initialiser format a try (an anonymous function) and it no longer bleats. Thank you. I am unsure why though! (that an anonymous function would work but a named function would not)!
require("@project-chip/matter-node.js");
import { VendorId } from "@project-chip/matter.js/datatype";
import { ServerNode } from "@project-chip/matter.js/node";
import { QrCode } from "@project-chip/matter.js/schema";
import { logEndpoint } from "@project-chip/matter.js/device";
import { EndpointServer } from "@project-chip/matter.js/endpoint";
import { AggregatorEndpoint } from "@project-chip/matter.js/endpoints/AggregatorEndpoint";
import { Endpoint } from "@project-chip/matter.js/endpoint";
import type { Node, NodeAPI, NodeDef, NodeInitializer } from 'node-red';
interface ServerConfig extends NodeDef {
passcode: number | string;
discriminator: number | string;
}
let matterHub: Endpoint<AggregatorEndpoint> = new Endpoint(AggregatorEndpoint, { id: "matterHub" });
export { matterHub };
export { nodeInit };
console.log("loading server file");
let nodeInit: NodeInitializer = (RED: NodeAPI): void => {
console.log("outside matterserver function");
function MatterServer(this: Node, config: ServerConfig) {
console.log("inside the MatterServer function");
RED.nodes.createNode(this, config);
let matterServer: any;
let commissioned: boolean;
let qrcode: string;
let manualPairingCode: string;
let qrCodeURL: string;
console.log("about to load httpadmin endpoint");
RED.httpAdmin.post("/matter-server/:id",
function (request, response) {
if (!request.hasOwnProperty("params")) {
console.log("no params provided");
response.json(JSON.stringify({ message: "no params provided" }));
return null;
}
if (!request.params.hasOwnProperty("id")) {
response.json(JSON.stringify({ message: "no id provided" }));
return null;
}
let node = RED.nodes.getNode(request.params.id);
console.log("node", node);
if (!node) {
response.json(JSON.stringify({
message: "node is null"
}));
} else {
response.json(
JSON.stringify(
{
qrcode: qrcode || null,
qrcodeURL: qrCodeURL || null,
manualPairingCode: manualPairingCode || null,
commissioned: commissioned || false,
message: "OK"
}
)
);
}
}
);
console.log("loaded httpadmin endpoint");
// console.log("server data", config);
if (typeof this.id != "undefined") {
console.log("starting matter server");
const name = "Node-Red Matter.js Hub";
let serverOpts = {
id: this.id,
network: {
port: 5540,
},
commissioning: {
passcode: Number(config.passcode),
discriminator: Number(config.discriminator),
},
productDescription: {
name: name,
deviceType: AggregatorEndpoint.deviceType,
},
basicInformation: {
vendorName: "jpadie",
vendorId: VendorId(65521),
nodeLabel: name,
productName: name,
productLabel: name,
productId: 1,
serialNumber: `NR_Mtr.js-${this.id}`.substring(0, 30),
uniqueId: this.id,
}
};
console.log("server options", serverOpts);
ServerNode
.create(serverOpts)
.then((resolve) => {
matterServer = resolve;
matterServer.add(matterHub)
.then(() => {
matterServer.bringOnline().then(() => {
//do something
}
).catch((error) => {
console.log("problem bringing matter server online", error);
})
});
//console.log("server node", this.matterServer);
if (!matterServer.lifecycle.isCommissioned) {
const qrPairingCode = matterServer.state.commissioning.pairingCodes.qrPairingCode;
manualPairingCode = matterServer.state.commissioning.pairingCodes.manualPairingCode;
qrcode = QrCode.get(qrPairingCode);
qrCodeURL = `https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`;
commissioned = false;
} else {
commissioned = true;
}
setTimeout(() => {
logEndpoint(EndpointServer.forEndpoint(matterServer));
}, 5000);
}).catch((error) => {
console.error("Issue with matter server deployment", error);
});
} else {
console.log("id is null");
}
}
/*start the engine*/
console.log("registering matterserver function");
RED.nodes.registerType("hub", MatterServer);
}