Skip to content

Instantly share code, notes, and snippets.

@jrschumacher
Created January 21, 2020 17:09
Show Gist options
  • Save jrschumacher/41184d7160a1a3da8cd67244999a7e4a to your computer and use it in GitHub Desktop.
Save jrschumacher/41184d7160a1a3da8cd67244999a7e4a to your computer and use it in GitHub Desktop.
Virtru Secure Chat 2/3: Application Bootstrap
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