Display error message if there are no Notica pages connected to ID
This commit is contained in:
parent
1dbc088d17
commit
6e47201299
17
server.js
17
server.js
|
@ -20,20 +20,25 @@ 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:') {
|
||||
let message = data.substring(2);
|
||||
if (io.sockets.adapter.rooms[id]) {
|
||||
let message = data.substring(2);
|
||||
|
||||
log('[NOTICA] Message sent to ' + id + ': ' + message);
|
||||
log('[NOTICA] Message sent to ' + id + ': ' + message);
|
||||
|
||||
io.in(id).emit('message', message);
|
||||
io.in(id).emit('message', message);
|
||||
|
||||
res.end();
|
||||
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');
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue
Block a user