Display error message if there are no Notica pages connected to ID

This commit is contained in:
Tanner Collin 2017-01-09 16:58:42 -07:00
parent 1dbc088d17
commit 6e47201299
2 changed files with 20 additions and 10 deletions

View File

@ -20,10 +20,11 @@ app.get('/*', (req, res) => {
});
app.post('*', (req, res) => {
let id = req.path.substring(1);
let id = req.path.substring(1, 20); // Ignore first, truncate after 20
let data = Object.keys(req.body)[0];
if (data && data.substring(0,2) === 'd:') {
if (io.sockets.adapter.rooms[id]) {
let message = data.substring(2);
log('[NOTICA] Message sent to ' + id + ': ' + message);
@ -31,9 +32,13 @@ app.post('*', (req, res) => {
io.in(id).emit('message', message);
res.end();
} else {
log('No one in room to send data to: ' + id);
res.send('No devices have that Notica ID open. Please open this URL: https://notica.us/' + id + '\n');
}
} else {
log('Ignoring bad POST data to: ' + id);
res.send('Bad POST data.');
res.send('Bad POST data. Expecting prefix of "d:".\n');
}
});

View File

@ -40,7 +40,6 @@ export default class Home extends React.Component {
});
socket.on('message', (data) => {
console.log("Notification: " + data);
this.sendNotification(data);
});
}
@ -56,9 +55,9 @@ export default class Home extends React.Component {
};
if (this.state.registration) {
console.log(this.state.registration.showNotification(title, options));
this.state.registration.showNotification(title, options);
} else {
console.log(new Notification(title, options));
new Notification(title, options);
}
}
@ -129,7 +128,7 @@ export default class Home extends React.Component {
<div className="twelve columns">
<h4>Usage</h4>
<p>
Notica is a Bash function / alias that sends a notification to a tab in your browser when it's ran:
Notica is a tool that sends a notification to a tab in your browser when it's ran:
</p>
</div>
</div>
@ -214,6 +213,12 @@ export default class Home extends React.Component {
<h4>Tips</h4>
<p>Bookmark this page! It is unique to the function in your <code className="smallcode">.bashrc</code> file.
Notifications will be sent to all open pages with the same ID code in the URL.</p>
<p>Lose the link to this page? Just run Notica again: <br />
<code style={{display: 'block'}}>
$ notica <br />
https://notica.us/{id}
</code>
</p>
<p>
Use quotes on messages with special characters: <br />
<code>