Permalink
Browse files

Complete Node SignalR Chat (JavaScript)

  • Loading branch information...
moozzyk committed Oct 1, 2017
1 parent 946f85d commit 0f7f71fbd765b41bcff427709f7f505bc02af82e
Showing with 18 additions and 0 deletions.
  1. +18 −0 SignalRChatNode/index.js
View
@@ -10,7 +10,25 @@ rl.question('Enter your name: ', name => {
console.log(name);
let connection = new signalR.HubConnection('http://localhost:5000/chat');
connection.on('broadcastMessage', (name, message) => {
console.log(`${name}: ${message}`);
rl.prompt(true);
});
connection.start()
.then(() => {
rl.prompt();
rl.on('line', input => {
if (input === '!q') {
console.log('Stopping connection...');
connection.stop();
rl.close();
return;
}
connection.send('send', name, input);
});
})
.catch(error => {
console.error(error);
rl.close();

0 comments on commit 0f7f71f

Please sign in to comment.