add QR code

This commit is contained in:
hatim boufnichel 2021-09-15 21:34:38 +02:00
parent 98080968a4
commit 1ddf75a9cb
6 changed files with 31 additions and 5 deletions

View file

@ -1 +1,2 @@
*.ts *.ts
/public/*.min.js

View file

@ -5,6 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title> <title>Document</title>
<script src="/qrCodeGenerator"></script>
</head> </head>
<body> <body>
<p id="errorContainer"></p> <p id="errorContainer"></p>
@ -16,6 +17,7 @@
<h3>Access Secret</h3> <h3>Access Secret</h3>
<p id="accessSecretState"></p> <p id="accessSecretState"></p>
</div> </div>
<div id="qrcode"></div>
<script> <script>
fetch(`${window.location.origin}/api/accessInfo`) fetch(`${window.location.origin}/api/accessInfo`)
.then(res => res.json()) .then(res => res.json())
@ -25,8 +27,13 @@
document.querySelector('#errorContainer').innerHTML ='there was an error, unable to load access information, reason: '+ j.message document.querySelector('#errorContainer').innerHTML ='there was an error, unable to load access information, reason: '+ j.message
return return
} }
handleTunnelInfo(j)
handleAccessCode(j) const tunnelUrl = handleTunnelInfo(j)
const accessCode = handleAccessCode(j)
const baseUrl = tunnelUrl ? tunnelUrl : window.location.host
const finalUrl = accessCode ? `${accessCode}#${baseUrl}` : baseUrl
new QRCode(document.getElementById("qrcode"), finalUrl);
}) })
.catch(e => { .catch(e => {
@ -34,6 +41,8 @@
}) })
const handleTunnelInfo = (res) => { const handleTunnelInfo = (res) => {
const tunnelState = document.querySelector("#tunnelState") const tunnelState = document.querySelector("#tunnelState")
if(res.tunnelDisabled){ if(res.tunnelDisabled){
tunnelState.innerHTML = 'The tunnel service is disabled' tunnelState.innerHTML = 'The tunnel service is disabled'
@ -44,6 +53,7 @@
return return
} }
tunnelState.innerHTML = `Tunnel URL: ${res.relayId}@${res.relayUrl}` tunnelState.innerHTML = `Tunnel URL: ${res.relayId}@${res.relayUrl}`
return `${res.relayId}@${res.relayUrl}`
} }
const handleAccessCode = (res) => { const handleAccessCode = (res) => {
@ -61,6 +71,7 @@
return return
} }
accessSecretState.innerHTML = `Access Secret: ${res.accessCode}` accessSecretState.innerHTML = `Access Secret: ${res.accessCode}`
return res.accessCode
} }
</script> </script>
</body> </body>

1
public/qrcode.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -2694,7 +2694,7 @@ module.exports = async (
//this is for OBS notifications, not wired with UI. //this is for OBS notifications, not wired with UI.
ap.get('/api/subscribeStream', (req, res) => { ap.get('/api/subscribeStream', (req, res) => {
try { try {
res.sendFile(path.join(__dirname, '/obsOverlay.html')) res.sendFile(path.join(__dirname, '../public/obsOverlay.html'))
} catch (e) { } catch (e) {
logger.error(e) logger.error(e)
res.status(500).json({ res.status(500).json({
@ -2753,7 +2753,19 @@ module.exports = async (
ap.get('/', (req, res) => { ap.get('/', (req, res) => {
try { try {
res.sendFile(path.join(__dirname, '/localHomepage.html')) res.sendFile(path.join(__dirname, '../public/localHomepage.html'))
} catch (e) {
logger.error(e)
res.status(500).json({
errorMessage: e.message
})
}
})
ap.get('/qrCodeGenerator', (req, res) => {
console.log('qrrerrr')
try {
res.sendFile(path.join(__dirname, '../public/qrcode.min.js'))
} catch (e) { } catch (e) {
logger.error(e) logger.error(e)
res.status(500).json({ res.status(500).json({

View file

@ -14,6 +14,7 @@ module.exports = {
"/api/subscribeStream":true, "/api/subscribeStream":true,
"/":true, "/":true,
"/api/accessInfo":true, "/api/accessInfo":true,
"/qrCodeGenerator":true,
}, },
POST: { POST: {
"/api/lnd/connect": true, "/api/lnd/connect": true,
@ -35,5 +36,5 @@ module.exports = {
PUT: {}, PUT: {},
DELETE: {} DELETE: {}
}, },
nonEncryptedRoutes: ['/api/security/exchangeKeys', "/api/encryption/exchange", '/healthz', '/ping', '/tunnel/status', '/api/lnd/wallet/status', '/api/gun/auth',"/api/subscribeStream", "/", "/api/accessInfo"] nonEncryptedRoutes: ['/api/security/exchangeKeys', "/api/encryption/exchange", '/healthz', '/ping', '/tunnel/status', '/api/lnd/wallet/status', '/api/gun/auth',"/api/subscribeStream", "/", "/api/accessInfo","/qrCodeGenerator"]
} }