cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              html
	head
		title Chat Room

	body
		div.body-wrapper
			div.room-name
				h2 Chat Room
			div.users-container
				h2 Connected User
				div.users
			div.message-box
				div.display-msg
				div.update
				div.feedback
			div.inputs-container
				div.log-in
					form#submit-name
						input#name(type="text" placeholder="Your name")
						button(type="submit") Enter
				div.submit-message-container
					form#submit-message
						input#message(type="text" placeholder="Your message")
						button(type="submit") Send

            
          
!
            
              body {
  box-sizing: border-box;
  font: 14px Nunito, Helvetica, Arial, sans-serif;
}

h2{
    font-size: 18px;
    padding: 10px 20px;
    color: #575ed8;
}

.body-wrapper{
	display: grid;
	grid-template-columns: 2fr 1fr;
	grid-template-rows: 10% 70% 20%;
	border: 1px solid #ddd;
	box-shadow: 1px 3px 5px rgba(0,0,0,0.05);
    border-radius: 2px;
}

.room-name {
	grid-row: 1;
	grid-column: 1 / -1;
	border-bottom: 1px solid #ddd;
}

.message-box {
	grid-column: 1;
	grid-row: 2;
	border-right: 1px solid #ddd;
	width: 65vw;
	height: 70vh;
	display: flex;
	flex-direction: column;
	flex-wrap: wrap;
	overflow: auto;
	background: #f9f9f9;

}
.users-container {
	grid-column: 2;
	grid-row: 2;
	display: flex;
	flex-direction: column;
	text-align: center;
	flex-wrap: wrap;
}

.inputs-container {
	grid-row: 3;
	grid-column: 1 / -1;
	border-top: 1px solid #ddd;
}

.log-in, .submit-message-container{
	margin-top: 0.5rem;
	margin-left: 0.5rem;
}
input {
	width: 60%;
	margin-right: 1rem;
	padding: 10px 20px;
    box-sizing: border-box;
    background: #eee;
    border: 0;
    background: #fff;
    border-bottom: 1px solid #eee;
    font-family: Nunito;
    font-size: 16px;
}

button{
    background: #575ed8;
    color: #fff;
    font-size: 18px;
    border: 0;
    padding: 12px 0;
    width: 10%;
    border-radius: 0 0 2px 2px;
}

p {
	font-size: 1.5rem;
	padding: 14px 0px;
    margin: 0 20px;
    border-bottom: 1px solid #e9e9e9;
    color: #555;

}

.update {
	font-size: 2rem;
	padding: 14px 0px;
    margin: 0 20px;
	color: #575ed8;
}
a {
  color: #00B7FF;
}

            
          
!
            
              //Front end JS
//should connect to the socket.io 
var io = 'io';
$(document).ready(function(){
	var socketio = io.connect('http://localhost:3000');
    var msgHTML = '';
    var currentUserName = '';
    var usersDiv = $('.users');
    var updateMsgDiv = $('.update');
    var messageDiv = $(".display-msg");

    socketio.on('currentUserList', (list)=>{
        for (let name of list){
            usersDiv.append(`<p>${name}</p>`);
        }
    });
    socketio.on('updateUserListToServer', (list)=>{
        usersDiv.html("");
        for (let name of list){
            usersDiv.append(`<p>${name}</p>`);
        }
    });
    $('#submit-name').submit(function(e){
        e.preventDefault();
        currentUserName = $('#name').val();
        if (currentUserName != ""){
            socketio.emit('join', currentUserName);
            $("#message").focus();
        }else {
            updateMsgDiv.html('<strong>You need to enter a name.</strong>')
            setTimeout(()=>{
                updateMsgDiv.html("");
            }, 2000);
        }
        $('form')[0].reset();
    });


    socketio.on('name', (name)=>{
        usersDiv.append(`<p>${name}</p>`);
    });
    socketio.on('chatHistory', (chat)=>{
        for (let msg of chat){
            messageDiv.append(`<p>${msg}</p>`);
        }
    });
    socketio.on('update', (update)=>{
        updateMsgDiv.html(`<strong>${update}</strong>`);
        setTimeout(()=>{
            updateMsgDiv.html("");
        }, 2000);
    });


    $('#submit-message').submit((e)=>{
        e.preventDefault();
        var newMsg  = $('#message').val();
        socketio.emit('send', newMsg);
        $('form')[1].reset();
    });

    socketio.on('newMsg', (msg)=>{
        messageDiv.append(`<p>${msg}</p>`);
    });

    socketio.on('mention', (bool)=>{
        console.log(bool);
        if(bool){
            messageDiv.css("color", "red");
        }
    })

    // 'is typing message'
    var typing = false;
    var timeout = 0;

    function timeoutFunction(){
        typing = false;
        socketio.emit("typing", false);
    }
    $("#message").keypress((e)=>{
        if(e.which !== 13){
        	if(typing === false && $('#message').is(":focus")){
                typing = true;
                socketio.emit("typing", true);
            }else {
                clearTimeout(timeout);
                timeout = setTimeout(timeoutFunction, 5000);
            }
        }
    });
    socketio.on('typing', (msg)=>{
        $('.feedback').html(`<p>${msg}</p>`);
        setTimeout(()=>{
            $('.feedback').html("");
        }, 2000);
    })
});


            
          
!
999px
Loading ..................

Console