-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
38 lines (31 loc) · 808 Bytes
/
script.js
File metadata and controls
38 lines (31 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var io = require('socket.io-client');
var socket = io("https://Socket-io-thingy.jbyt27.repl.co");
const chalk=require("chalk")
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function chat(){
rl.question(">>> ", (answer) => {
socket.emit("message",id+": "+chalk.green(answer));
chat();
});
}
socket.on('connect', () => {
console.clear()
rl.question(`What's your USERNAME? `, (answer) => {
console.clear()
socket.emit("message", `👤: ${answer} has joined the chat`);
id = answer;
chat();
});
socket.on('msg', function(data){
console.log("\n" + data);
chat();
});
})
socket.off('disconnect', () => {
socket.emit("message", `Ω : ${answer} has left the chat`);
chat();
})