diff --git a/server.js b/server.js index 2e9558f..609840f 100644 --- a/server.js +++ b/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'); } }); diff --git a/src/ui/Home.js b/src/ui/Home.js index e3a79ec..7d54cbe 100644 --- a/src/ui/Home.js +++ b/src/ui/Home.js @@ -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 {
- 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:
Bookmark this page! It is unique to the function in your .bashrc
file.
Notifications will be sent to all open pages with the same ID code in the URL.
Lose the link to this page? Just run Notica again:
+
+ $ notica
+
+ https://notica.us/{id}
+
Use quotes on messages with special characters: