Skip to content

Commit

Permalink
Added mattermdnsinterface, matteripv4address and matteripv6address
Browse files Browse the repository at this point in the history
  • Loading branch information
Luligu committed Sep 1, 2024
1 parent 0ad6c89 commit 1d597c8
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 23 deletions.
6 changes: 3 additions & 3 deletions frontend/build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"files": {
"main.css": "/static/css/main.1cf003ae.css",
"main.js": "/static/js/main.cfcfbb06.js",
"main.js": "/static/js/main.6725e5ab.js",
"static/js/453.abd36b29.chunk.js": "/static/js/453.abd36b29.chunk.js",
"index.html": "/index.html",
"main.1cf003ae.css.map": "/static/css/main.1cf003ae.css.map",
"main.cfcfbb06.js.map": "/static/js/main.cfcfbb06.js.map",
"main.6725e5ab.js.map": "/static/js/main.6725e5ab.js.map",
"453.abd36b29.chunk.js.map": "/static/js/453.abd36b29.chunk.js.map"
},
"entrypoints": [
"static/css/main.1cf003ae.css",
"static/js/main.cfcfbb06.js"
"static/js/main.6725e5ab.js"
]
}
2 changes: 1 addition & 1 deletion frontend/build/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/matterbridge 32x32.png"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>Matterbridge</title><link rel="manifest" href="/manifest.json"/><script defer="defer" src="/static/js/main.cfcfbb06.js"></script><link href="/static/css/main.1cf003ae.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/matterbridge 32x32.png"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>Matterbridge</title><link rel="manifest" href="/manifest.json"/><script defer="defer" src="/static/js/main.6725e5ab.js"></script><link href="/static/css/main.1cf003ae.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions frontend/build/static/js/main.6725e5ab.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion frontend/build/static/js/main.cfcfbb06.js.map

This file was deleted.

4 changes: 3 additions & 1 deletion frontend/src/components/MatterbridgeInfoTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { TruncatedText } from './TruncatedText';

// This function takes systemInfo as a parameter and returns a table element with the systemInfo
export function MatterbridgeInfoTable({ matterbridgeInfo }) {
const excludeKeys = ['matterbridgeVersion', 'matterbridgeLatestVersion', 'matterFileLogger', 'fileLogger', 'matterLoggerLevel', 'debugEnabled', 'loggerLevel', 'bridgeMode', 'restartMode', 'matterbridgeFabricInformations', 'matterbridgeSessionInformations', 'restartRequired', 'refreshRequired'];
const excludeKeys = ['matterbridgeVersion', 'matterbridgeLatestVersion', 'matterFileLogger', 'fileLogger', 'matterLoggerLevel', 'loggerLevel',
'bridgeMode', 'restartMode', 'matterbridgeFabricInformations', 'matterbridgeSessionInformations', 'restartRequired', 'refreshRequired',
'mattermdnsinterface', 'matteripv4address', 'matteripv6address'];
if(matterbridgeInfo.bridgeMode === 'childbridge') excludeKeys.push('matterbridgePaired', 'matterbridgeConnected');
return (
<div className="MbfWindowDiv" style={{ minWidth: '302px' }}>
Expand Down
19 changes: 10 additions & 9 deletions frontend/src/components/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function MatterbridgeSettings({ matterbridgeInfo, showSnackbarMessage }) {
<div style={{ display: 'flex', alignItems: 'center', gap: '15px' }}>
<FormLabel color='readonly' style={{padding: '0px', margin: '0px'}} id="mb-password">Frontend password:</FormLabel>
<TextField value={password} onChange={handleChangePassword} size="small" id="matterbridgePassword" type="password" autoComplete="current-password" variant="outlined"
style={{ height: '30px', marginTop: '5px' }} InputProps={{
style={{ height: '30px', flexGrow: 1 }} InputProps={{
style: {
height: '30px',
padding: '0',
Expand All @@ -165,10 +165,11 @@ function MatterSettings({ matterbridgeInfo, showSnackbarMessage }) {

useEffect(() => {
if (matterbridgeInfo.bridgeMode === undefined) return;

setSelectedMjLoggerLevel(['Debug', 'Info', 'Notice', 'Warn', 'Error', 'Fatal'][matterbridgeInfo.matterLoggerLevel]);

setLogOnFileMj(matterbridgeInfo.matterFileLogger);
setmdnsInterface(matterbridgeInfo.mattermdnsinterface);
setIpv4Address(matterbridgeInfo.matteripv4address);
setIpv6Address(matterbridgeInfo.matteripv6address);
}, [matterbridgeInfo]);

// Define a function to handle change debug level
Expand Down Expand Up @@ -227,8 +228,8 @@ function MatterSettings({ matterbridgeInfo, showSnackbarMessage }) {
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: '15px' }}>
<FormLabel color='readonly' style={{padding: '0px', margin: '0px'}}>Mdns interface:</FormLabel>
<TextField disabled value={mdnsInterface} onChange={handleChangeMdnsInterface} size="small" variant="outlined"
style={{ height: '30px', marginTop: '5px' }} InputProps={{
<TextField value={mdnsInterface} onChange={handleChangeMdnsInterface} size="small" variant="outlined"
style={{ height: '30px', flexGrow: 1 }} InputProps={{
style: {
height: '30px',
padding: '0',
Expand All @@ -237,8 +238,8 @@ function MatterSettings({ matterbridgeInfo, showSnackbarMessage }) {
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: '15px' }}>
<FormLabel color='readonly' style={{padding: '0px', margin: '0px'}}>Ipv4 address:</FormLabel>
<TextField disabled value={ipv4Address} onChange={handleChangeIpv4Address} size="small" variant="outlined"
style={{ height: '30px', marginTop: '5px' }} InputProps={{
<TextField value={ipv4Address} onChange={handleChangeIpv4Address} size="small" variant="outlined"
style={{ height: '30px', flexGrow: 1 }} InputProps={{
style: {
height: '30px',
padding: '0',
Expand All @@ -247,8 +248,8 @@ function MatterSettings({ matterbridgeInfo, showSnackbarMessage }) {
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: '15px' }}>
<FormLabel color='readonly' style={{padding: '0px', margin: '0px'}}>Ipv6 address:</FormLabel>
<TextField disabled value={ipv6Address} onChange={handleChangeIpv6Address} size="small" variant="outlined"
style={{ height: '30px', marginTop: '5px' }} InputProps={{
<TextField value={ipv6Address} onChange={handleChangeIpv6Address} size="small" variant="outlined"
style={{ height: '30px', flexGrow: 1 }} InputProps={{
style: {
height: '30px',
padding: '0',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "matterbridge",
"version": "1.5.3-dev.1",
"version": "1.5.3-dev.2",
"description": "Matterbridge plugin manager for Matter",
"author": "https://github.com/Luligu",
"license": "Apache-2.0",
Expand Down
99 changes: 95 additions & 4 deletions src/matterbridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ export class Matterbridge extends EventEmitter {
fileLogger: false,
matterLoggerLevel: Level.INFO,
matterFileLogger: false,
mattermdnsinterface: undefined,
matteripv4address: undefined,
matteripv6address: undefined,
restartRequired: false,
refreshRequired: false,
};
Expand Down Expand Up @@ -169,6 +172,8 @@ export class Matterbridge extends EventEmitter {

// Matter
private mdnsInterface: string | undefined; // matter server mdnsInterface: e.g. 'eth0' or 'wlan0' or 'WiFi'
private ipv4address: string | undefined; // matter commissioning server listeningAddressIpv4
private ipv6address: string | undefined; // matter commissioning server listeningAddressIpv6
private port = 5540; // first commissioning server port
private passcode?: number; // first commissioning server passcode
private discriminator?: number; // first commissioning server discriminator
Expand Down Expand Up @@ -239,8 +244,6 @@ export class Matterbridge extends EventEmitter {
* @returns A Promise that resolves when the initialization is complete.
*/
public async initialize() {
// Set the interface to use for the matter server mdnsInterface
this.mdnsInterface = getParameter('mdnsinterface');
// Set the first port to use for the commissioning server (will be incremented in childbridge mode)
this.port = getIntParameter('port') ?? 5540;
// Set the first passcode to use for the commissioning server (will be incremented in childbridge mode)
Expand Down Expand Up @@ -334,6 +337,30 @@ export class Matterbridge extends EventEmitter {
}
this.log.debug(`Matter logLevel: ${Logger.defaultLogLevel} fileLoger: ${this.matterbridgeInformation.matterFileLogger}.`);

// Set the interface to use for the matter server mdnsInterface
if (hasParameter('mdnsinterface')) {
this.mdnsInterface = getParameter('mdnsinterface');
} else {
this.mdnsInterface = await this.nodeContext?.get<string>('mattermdnsinterface', undefined);
if (this.mdnsInterface === '') this.mdnsInterface = undefined;
}

// Set the listeningAddressIpv4 for the matter commissioning server
if (hasParameter('ipv4address')) {
this.ipv4address = getParameter('ipv4address');
} else {
this.ipv4address = await this.nodeContext?.get<string>('matteripv4address', undefined);
if (this.ipv4address === '') this.ipv4address = undefined;
}

// Set the listeningAddressIpv6 for the matter commissioning server
if (hasParameter('ipv6address')) {
this.ipv6address = getParameter('ipv6address');
} else {
this.ipv6address = await this.nodeContext?.get<string>('matteripv6address', undefined);
if (this.ipv6address === '') this.ipv6address = undefined;
}

// Initialize PluginManager
this.plugins = new PluginManager(this);
await this.plugins.loadFromStorage();
Expand Down Expand Up @@ -2045,10 +2072,41 @@ export class Matterbridge extends EventEmitter {
this.log.debug(`Creating matter commissioning server for plugin ${plg}${pluginName}${db} with softwareVersion ${softwareVersion} softwareVersionString ${softwareVersionString}`);
this.log.debug(`Creating matter commissioning server for plugin ${plg}${pluginName}${db} with hardwareVersion ${hardwareVersion} hardwareVersionString ${hardwareVersionString}`);
this.log.debug(`Creating matter commissioning server for plugin ${plg}${pluginName}${db} with nodeLabel '${productName}' port ${this.port} passcode ${this.passcode} discriminator ${this.discriminator}`);

// Validate ipv4address
if (this.ipv4address) {
const networkInterfaces = os.networkInterfaces();
const availableAddresses = Object.values(networkInterfaces)
.flat()
.filter((iface): iface is os.NetworkInterfaceInfo => iface !== undefined && iface.family === 'IPv4' && !iface.internal)
.map((iface) => iface.address);
if (!availableAddresses.includes(this.ipv4address)) {
this.log.error(`Invalid ipv4address: ${this.ipv4address}. Available addresses are: ${availableAddresses.join(', ')}. Using all available addresses.`);
this.mdnsInterface = undefined;
} else {
this.log.info(`Using ipv4address '${this.ipv4address}' for the Matter commissioning server.`);
}
}

// Validate ipv6address
if (this.ipv6address) {
const networkInterfaces = os.networkInterfaces();
const availableAddresses = Object.values(networkInterfaces)
.flat()
.filter((iface): iface is os.NetworkInterfaceInfo => iface !== undefined && iface.family === 'IPv6' && !iface.internal)
.map((iface) => iface.address);
if (!availableAddresses.includes(this.ipv6address)) {
this.log.error(`Invalid ipv6address: ${this.ipv6address}. Available addresses are: ${availableAddresses.join(', ')}. Using all available addresses.`);
this.mdnsInterface = undefined;
} else {
this.log.info(`Using ipv6address '${this.ipv6address}' for the Matter commissioning server.`);
}
}

const commissioningServer = new CommissioningServer({
port: this.port++,
listeningAddressIpv4: getParameter('ipv4address'),
listeningAddressIpv6: getParameter('ipv6address'),
listeningAddressIpv4: this.ipv4address,
listeningAddressIpv6: this.ipv6address,
passcode: this.passcode,
discriminator: this.discriminator,
deviceName,
Expand Down Expand Up @@ -2795,6 +2853,9 @@ export class Matterbridge extends EventEmitter {
this.matterbridgeInformation.restartMode = this.restartMode;
this.matterbridgeInformation.loggerLevel = this.log.logLevel;
this.matterbridgeInformation.matterLoggerLevel = Logger.defaultLogLevel;
this.matterbridgeInformation.mattermdnsinterface = (await this.nodeContext?.get<string>('mattermdnsinterface', '')) || '';
this.matterbridgeInformation.matteripv4address = (await this.nodeContext?.get<string>('matteripv4address', '')) || '';
this.matterbridgeInformation.matteripv6address = (await this.nodeContext?.get<string>('matteripv6address', '')) || '';
this.matterbridgeInformation.matterbridgePaired = this.matterbridgePaired;
this.matterbridgeInformation.matterbridgeConnected = this.matterbridgeConnected;
this.matterbridgeInformation.matterbridgeQrPairingCode = this.matterbridgeQrPairingCode;
Expand Down Expand Up @@ -3105,6 +3166,36 @@ export class Matterbridge extends EventEmitter {
return;
}

// Handle the command setmdnsinterface from Settings
if (command === 'setmdnsinterface') {
param = param.slice(1, -1); // Remove the first and last characters *mdns*
this.matterbridgeInformation.mattermdnsinterface = param;
this.log.debug('Matter.js mdns interface:', param === '' ? 'All interfaces' : param);
await this.nodeContext?.set('mattermdnsinterface', param);
res.json({ message: 'Command received' });
return;
}

// Handle the command setipv4address from Settings
if (command === 'setipv4address') {
param = param.slice(1, -1); // Remove the first and last characters *ip*
this.matterbridgeInformation.matteripv4address = param;
this.log.debug('Matter.js ipv4 address:', param === '' ? 'All ipv4 addresses' : param);
await this.nodeContext?.set('matteripv4address', param);
res.json({ message: 'Command received' });
return;
}

// Handle the command setipv6address from Settings
if (command === 'setipv6address') {
param = param.slice(1, -1); // Remove the first and last characters *ip*
this.matterbridgeInformation.matteripv6address = param;
this.log.debug('Matter.js ipv6 address:', param === '' ? 'All ipv6 addresses' : param);
await this.nodeContext?.set('matteripv6address', param);
res.json({ message: 'Command received' });
return;
}

// Handle the command setmbloglevel from Settings
if (command === 'setmblogfile') {
this.log.debug('Matterbridge file log:', param);
Expand Down
3 changes: 3 additions & 0 deletions src/matterbridgeTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ export interface MatterbridgeInformation {
fileLogger: boolean;
matterLoggerLevel: number;
matterFileLogger: boolean;
mattermdnsinterface: string | undefined;
matteripv4address: string | undefined;
matteripv6address: string | undefined;
restartRequired: boolean;
refreshRequired: boolean;
}
Expand Down

0 comments on commit 1d597c8

Please sign in to comment.