Skip to content

Commit

Permalink
Release 1.2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Luligu committed Apr 13, 2024
1 parent 733810b commit 638edbf
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 25 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ node_storage

Eve door_history.json

Dockerfile
Dockerfile
docker-compose.yml
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,5 @@ bridge-groups.json
.matterbridge.backup.json
node_storage

Dockerfile
Dockerfile
docker-compose.yml
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

All notable changes to this project will be documented in this file.

## [1.2.7] - 2024-04-14

### Changed

- [matterbridge]: The default frontend port is now 8283!.
- [matterbridge.service]: Updated matterbridge.service instructions to fix restart when Matterbridge runs as a daemon with systemctl.

### Added

- [frontend]: Added manual pairing code. Allows to pair Matterbridge without using the phone.
- [MatterbridgeDevice]: Added api to create child endpoints (see matterbridge-example-dynamic-platform).
- [MatterbridgeDevice]: Added FlowMeasurement cluster.

## [1.2.6] - 2024-04-11

### Added
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ matterbridge -reset [plugin path or plugin name]
matterbridge -factoryreset
```

This will remove the internal starages. All commissioning information will be lost. All plugins will be unregistered.
This will reset the internal starages. All commissioning informations will be lost. All plugins will be unregistered.

## How to create your plugin

Expand Down Expand Up @@ -315,7 +315,7 @@ After=network-online.target
[Service]
Type=simple
ExecStart=/usr/bin/matterbridge -bridge
ExecStart=/usr/bin/matterbridge -bridge -service
WorkingDirectory=/home/<USER>/Matterbridge
StandardOutput=inherit
StandardError=inherit
Expand Down
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.61f6cf42.css",
"main.js": "/static/js/main.6b861489.js",
"main.js": "/static/js/main.491fc08f.js",
"static/js/453.d855a71b.chunk.js": "/static/js/453.d855a71b.chunk.js",
"index.html": "/index.html",
"main.61f6cf42.css.map": "/static/css/main.61f6cf42.css.map",
"main.6b861489.js.map": "/static/js/main.6b861489.js.map",
"main.491fc08f.js.map": "/static/js/main.491fc08f.js.map",
"453.d855a71b.chunk.js.map": "/static/js/453.d855a71b.chunk.js.map"
},
"entrypoints": [
"static/css/main.61f6cf42.css",
"static/js/main.6b861489.js"
"static/js/main.491fc08f.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.6b861489.js"></script><link href="/static/css/main.61f6cf42.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.491fc08f.js"></script><link href="/static/css/main.61f6cf42.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.491fc08f.js.map

Large diffs are not rendered by default.

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

This file was deleted.

28 changes: 20 additions & 8 deletions frontend/src/components/Home.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Home.js
import React, { useEffect, useState, ChangeEvent } from 'react';
import React, { useEffect, useState } from 'react';
import QRCode from 'qrcode.react';
import { StatusIndicator } from './StatusIndicator';
import QrCode2Icon from '@mui/icons-material/QrCode2';
Expand All @@ -8,7 +8,6 @@ import { sendCommandToMatterbridge } from './Header';
import Snackbar from '@mui/material/Snackbar';
import Alert from '@mui/material/Alert';
import TextField from '@mui/material/TextField';
import Fab from '@mui/material/Fab';
import AddIcon from '@mui/icons-material/Add';
import RemoveIcon from '@mui/icons-material/Remove';
import DownloadIcon from '@mui/icons-material/Download';
Expand All @@ -18,6 +17,7 @@ import DownloadIcon from '@mui/icons-material/Download';

function Home() {
const [qrCode, setQrCode] = useState('');
const [pairingCode, setPairingCode] = useState('');
const [systemInfo, setSystemInfo] = useState({});
const [matterbridgeInfo, setMatterbridgeInfo] = useState({});
const [plugins, setPlugins] = useState([]);
Expand Down Expand Up @@ -52,13 +52,23 @@ function Home() {
/*
*/
useEffect(() => {
// Fetch manual pairingCode
fetch('/api/pairing-code')
.then(response => response.json())
.then(data => {
setPairingCode(data.manualPairingCode);
console.log('/api/pairing-code:', data.manualPairingCode);
localStorage.setItem('pairingCode', data.manualPairingCode); // Save the QR code in localStorage
})
.catch(error => console.error('Error fetching QR code:', error));

// Fetch QR Code
fetch('/api/qr-code')
.then(response => response.json())
.then(data => {
setQrCode(data.qrPairingCode);
console.log('/api/qr-code:', data.qrPairingCode);
localStorage.setItem('qrCode', data.qrPairingCode); // Save the QR code in localStorage
setQrCode(data.qrPairingCode);
console.log('/api/qr-code:', data.qrPairingCode);
localStorage.setItem('qrCode', data.qrPairingCode); // Save the QR code in localStorage
})
.catch(error => console.error('Error fetching QR code:', error));

Expand Down Expand Up @@ -87,10 +97,12 @@ function Home() {
setSelectedRow(-1);
setSelectedPluginName('none');
setQrCode(localStorage.getItem('qrCode'));
setPairingCode(localStorage.getItem('pairingCode'));
} else {
setSelectedRow(row);
setSelectedPluginName(plugins[row].name);
setQrCode(plugins[row].qrPairingCode);
setPairingCode(plugins[row].manualPairingCode);
}
console.log('Selected row:', row, 'plugin:', plugins[row].name, 'qrcode:', plugins[row].qrPairingCode);
};
Expand All @@ -116,7 +128,7 @@ function Home() {
return (
<div style={{ display: 'flex', flexDirection: 'row', height: 'calc(100vh - 60px - 40px)', width: 'calc(100vw - 40px)', gap: '20px', margin: '0', padding: '0' }}>
<div style={{ display: 'flex', flexDirection: 'column', flex: '0 1 auto', gap: '20px' }}>
{qrCode && <QRDiv qrText={qrCode} qrWidth={256} topText="QRCode" bottomText={selectedPluginName==='none'?'Matterbridge':selectedPluginName}/>}
{qrCode && <QRDiv qrText={qrCode} pairingText={pairingCode} qrWidth={256} topText="QRCode" bottomText={selectedPluginName==='none'?'Matterbridge':selectedPluginName}/>}
{systemInfo && <SystemInfoTable systemInfo={systemInfo}/>}
</div>
<div style={{ display: 'flex', flexDirection: 'column', flex: '1 1 auto', gap: '20px' }}>
Expand Down Expand Up @@ -300,7 +312,7 @@ function Home() {

// This function takes four parameters: qrText, qrWidth, topText, and bottomText
// It returns a div element with a rectangle, a QR code, and two texts
function QRDiv({ qrText, qrWidth, topText, bottomText }) {
function QRDiv({ qrText, pairingText, qrWidth, topText, bottomText }) {
return (
<div className="MbfWindowDiv" style={{alignItems: 'center'}}>
<div className="MbfWindowHeader">
Expand All @@ -309,7 +321,7 @@ function Home() {
<QRCode value={qrText} size={qrWidth} bgColor='#9e9e9e' style={{ margin: '20px' }}/>
<div className="MbfWindowFooter">
<div>
<p style={{ margin: 0, textAlign: 'center' }}>Scan me to pair</p>
<p style={{ margin: 0, textAlign: 'center' }}>Use {pairingText} or scan the QR to pair</p>
<p className="text-color-selected" style={{ margin: 0, textAlign: 'center' }}>{bottomText}</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion matterbridge.service
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/matterbridge -bridge
ExecStart=/usr/bin/matterbridge -bridge -service
WorkingDirectory=/home/<USER>/Matterbridge
StandardOutput=inherit
StandardError=inherit
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"matterbridge": "dist/cli.js"
},
"engines": {
"node": "^18.19.0 || ^20.12.0"
"node": ">=18.0.0"
},
"scripts": {
"build": "tsc",
Expand Down
41 changes: 38 additions & 3 deletions src/matterbridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,13 @@ export class Matterbridge extends EventEmitter {
if (process.platform === 'win32' && command === 'npm') {
command = command + '.cmd';
}
if (process.platform === 'linux' && command === 'npm') {
if (process.platform === 'linux' && command === 'npm' && !hasParameter('docker')) {
args.unshift(command);
command = 'sudo';
}
return new Promise((resolve, reject) => {
const childProcess = spawn(command, args, {
stdio: 'inherit',
stdio: ['inherit', 'pipe', 'pipe'],
});

childProcess.on('error', (err) => {
Expand All @@ -355,6 +355,24 @@ export class Matterbridge extends EventEmitter {
childProcess.on('disconnect', () => {
this.log.info('Child process has been disconnected from the parent');
});

if (childProcess.stdout) {
childProcess.stdout.on('data', (data) => {
// Convert the Buffer data to a string.
const message = data.toString();
this.log.info(message);
// TODO: Send this message to the frontend.
});
}

if (childProcess.stderr) {
childProcess.stderr.on('data', (data) => {
// Convert the Buffer data to a string.
const message = data.toString();
this.log.error(message);
// TODO: Handle the error message.
});
}
});
}

Expand Down Expand Up @@ -2349,7 +2367,7 @@ export class Matterbridge extends EventEmitter {
*
* @param port The port number to run the frontend server on. Default is 3000.
*/
async initializeFrontend(port: number = 3000): Promise<void> {
async initializeFrontend(port: number = 8283): Promise<void> {
this.log.debug(`Initializing the frontend on port ${YELLOW}${port}${db} static ${UNDERLINE}${path.join(this.rootDirectory, 'frontend/build')}${UNDERLINEOFF}${rs}`);
this.expressApp = express();

Expand All @@ -2374,6 +2392,23 @@ export class Matterbridge extends EventEmitter {
}
});

// Endpoint to provide manual pairing code
this.expressApp.get('/api/pairing-code', (req, res) => {
this.log.debug('The frontend sent /api/pairing-code');
if (!this.matterbridgeContext) {
this.log.error('/api/pairing-code matterbridgeContext not found');
res.json([]);
return;
}
try {
const qrData = { qrPairingCode: this.matterbridgeContext.get('qrPairingCode'), manualPairingCode: this.matterbridgeContext.get('manualPairingCode') };
res.json(qrData);
} catch (error) {
if (this.bridgeMode === 'bridge') this.log.error('qrPairingCode for /api/qr-code not found');
res.json({});
}
});

// Endpoint to provide QR pairing code
this.expressApp.get('/api/qr-code', (req, res) => {
this.log.debug('The frontend sent /api/qr-code');
Expand Down

0 comments on commit 638edbf

Please sign in to comment.