Created
January 21, 2020 17:09
-
-
Save jrschumacher/41184d7160a1a3da8cd67244999a7e4a to your computer and use it in GitHub Desktop.
Virtru Secure Chat 2/3: Application Bootstrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
const user = socket.nickname; | |
if (!user) throw new Error('Your session is not registered. Please make sure to login.'); | |
const response = await pouchDB.addMessage(channel, message, user); | |
const payload = { ...response, message, user }; | |
// Send ok response | |
socket.emit('add-message-ok', response); | |
// Broadcast message to room | |
socket.broadcast.to(channel).emit('new-message', payload); | |
// Send new message to user | |
socket.emit('new-message', payload); | |
} catch (e) { | |
// Send error response | |
socket.emit('add-message-error', e.message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment