File: chat-websocket/public/chat.js

Recommend this page to a friend!
  Classes of Igor Escobar   Terminal Crossword   ???   Download  
File: chat-websocket/public/???
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Terminal Crossword
Generate a crosswords board on a text console
Author: By
Last change: Update of chat-websocket/public/chat.js
Date: 17 days ago
Size: 1,018 bytes
 

Contents

Class file image Download
$(document).ready(function () { var sendBox = $("#sendbox"), messageBox = $("#message"), messageList = $("#message_list"), userName = prompt("Digite seu apelido:","Apelido"), clientCounter = $("#client_count"); var socket = io.connect("http://localhost:8080/"); messageBox.focus(); // when a message has been sent sendBox.on("submit", function (e) { e.preventDefault(); var messageBoxContent = messageBox.val(), messagePackage = {"user": userName, "text": messageBoxContent}; // sends the message to server if(/^ *$/g.test(messageBoxContent) === false ) { socket.emit("new_message", messagePackage); } }); // when a message arrives from server socket.on('broadcast_message', function (data){ messageList.append("<li>" + data.user + ": " + data.text + "</li>"); messageBox.val(""); }); // when a generic message event was triggered from server socket.on('message', function (data) { clientCounter.html(data); }); });