@minx28/

chatroom

Nodejs

Start building your own chatroom in a CLI!

fork
loading
Files
  • index.js
  • package-lock.json

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.2882107552028026","path":"index.js","file":{"path":"index.js","content":{"asEncoding":{"base64":"dmFyIGlvID0gcmVxdWlyZSgnc29ja2V0LmlvLWNsaWVudCcpOwp2YXIgc29ja2V0ID0gaW8oImh0dHBzOi8vY2hhdC1zZXJ2ZXItLW1pbngyOC5yZXBsLmNvIik7CmNvbnN0IGNoYWxrPXJlcXVpcmUoImNoYWxrIikKCmNvbnN0IHJlYWRsaW5lID0gcmVxdWlyZSgncmVhZGxpbmUnKTsKY29uc3QgcmwgPSByZWFkbGluZS5jcmVhdGVJbnRlcmZhY2UoewogIGlucHV0OiBwcm9jZXNzLnN0ZGluLAogIG91dHB1dDogcHJvY2Vzcy5zdGRvdXQKfSk7CgoKdmFyIGlkID0gIiI7CnZhciBidWZmZXIgPSAiIjsKCmZ1bmN0aW9uIGNoYXQoKXsKCXJsLnF1ZXN0aW9uKCLCuyAiLCAoYW5zd2VyKSA9PiB7CiAgICAvKmlmIGNvbG91cj09MCBzb2NrZXQuZW1pdCgibWVzc2FnZSIsIGlkKyI6ICIrY2hhbGsucmVkKGFuc3dlcikpOwogICAgaWYgY29sb3VyPT0xIHNvY2tldC5lbWl0KCJtZXNzYWdlIiwgaWQrIjogIitjaGFsay5ncmVlbihhbnN3ZXIpKTsKICAgIGlmIGNvbG91cj09MiBzb2NrZXQuZW1pdCgibWVzc2FnZSIsIGlkKyI6ICIrY2hhbGsueWVsbG93KGFuc3dlcikpOwogICAgaWYgY29sb3VyPT0zIHNvY2tldC5lbWl0KCJtZXNzYWdlIiwgaWQrIjogIitjaGFsay5ibHVlKGFuc3dlcikpOwogICAgaWYgY29sb3VyPT00IHNvY2tldC5lbWl0KCJtZXNzYWdlIiwgaWQrIjogIitjaGFsay5tYWdlbnRhKGFuc3dlcikpOwogICAgaWYgY29sb3VyPT01IHNvY2tldC5lbWl0KCJtZXNzYWdlIiwgaWQrIjogIitjaGFsay5jeWFuKGFuc3dlcikpOyovCiAgICBzb2NrZXQuZW1pdCgibWVzc2FnZSIsaWQrIjogIitjaGFsay5yZWQoYW5zd2VyKSk7CiAgICBjaGF0KCk7CiAgfSk7Cn0KCgpzb2NrZXQub24oJ2Nvbm5lY3QnLCAoKSA9PiB7CglybC5xdWVzdGlvbihgV2hhdCdzIHlvdXIgbmFtZT8gYCwgKGFuc3dlcikgPT4gewoJCQlzb2NrZXQuZW1pdCgibWVzc2FnZSIsIGDwn5GkICA6ICR7YW5zd2VyfSBoYXMgam9pbmVkIHRoZSBjaGF0YCk7CgkJCWlkID0gYW5zd2VyOwogICAgICAvL2NvbG91ciA9IDA7CiAgICAgIC8vY29sb3VyPXJvdW5kKE1hdGgucmFuZG9tKCkqNSk7CiAgICAgIC8vY29uc29sZS5sb2coY29sb3VyKQoJCQljaGF0KCk7CiAgfSk7CiAgc29ja2V0Lm9uKCdtc2cnLCBmdW5jdGlvbihkYXRhKXsKICAgIGNvbnNvbGUubG9nKCJcbiIgKyBkYXRhKTsKICAgIGNoYXQoKTsKICB9KTsKfSk="},"asBuffer":null},"loaded":true}}
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
39
40
41
42
var io = require('socket.io-client');
var socket = io("https://chat-server--minx28.repl.co");
const chalk=require("chalk")

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});


var id = "";
var buffer = "";

function chat(){
	rl.question("» ", (answer) => {
    /*if colour==0 socket.emit("message", id+": "+chalk.red(answer));
    if colour==1 socket.emit("message", id+": "+chalk.green(answer));
    if colour==2 socket.emit("message", id+": "+chalk.yellow(answer));
    if colour==3 socket.emit("message", id+": "+chalk.blue(answer));
    if colour==4 socket.emit("message", id+": "+chalk.magenta(answer));
    if colour==5 socket.emit("message", id+": "+chalk.cyan(answer));*/
    socket.emit("message",id+": "+chalk.red(answer));
    chat();
  });
}


socket.on('connect', () => {
	rl.question(`What's your name? `, (answer) => {
			socket.emit("message", `👤  : ${answer} has joined the chat`);
			id = answer;
      //colour = 0;
      //colour=round(Math.random()*5);
      //console.log(colour)
			chat();
  });
  socket.on('msg', function(data){
    console.log("\n" + data);
    chat();
  });
})
node v10.16.0