mirror of
https://github.com/abrendan/MicDropMessages.git
synced 2025-08-25 22:12:02 +02:00
Initial commit
This commit is contained in:
55
html/script.js
Normal file
55
html/script.js
Normal file
@@ -0,0 +1,55 @@
|
||||
var socket;
|
||||
var usernameInput
|
||||
var chatIDInput;
|
||||
var messageInput;
|
||||
var chatRoom;
|
||||
var dingSound;
|
||||
var messages = [];
|
||||
var delay = true;
|
||||
|
||||
function onload(){
|
||||
socket = io();
|
||||
usernameInput = document.getElementById("NameInput");
|
||||
chatIDInput = document.getElementById("IDInput");
|
||||
messageInput = document.getElementById("ComposedMessage");
|
||||
chatRoom = document.getElementById("RoomID");
|
||||
dingSound = document.getElementById("Ding");
|
||||
|
||||
socket.on("join", function(room){
|
||||
chatRoom.innerHTML = "Current Chatroom : " + room;
|
||||
})
|
||||
|
||||
socket.on("recieve", function(message){
|
||||
console.log(message);
|
||||
if (messages.length < 9){
|
||||
messages.push(message);
|
||||
dingSound.currentTime = 0;
|
||||
dingSound.play();
|
||||
}
|
||||
else{
|
||||
messages.shift();
|
||||
messages.push(message);
|
||||
}
|
||||
for (i = 0; i < messages.length; i++){
|
||||
document.getElementById("Message"+i).innerHTML = messages[i];
|
||||
document.getElementById("Message"+i).style.color = "#b30000";
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function Connect(){
|
||||
socket.emit("join", chatIDInput.value, usernameInput.value);
|
||||
}
|
||||
|
||||
function Send(){
|
||||
if (delay && messageInput.value.replace(/\s/g, "") != ""){
|
||||
delay = false;
|
||||
setTimeout(delayReset, 1000);
|
||||
socket.emit("send", messageInput.value);
|
||||
messageInput.value = "";
|
||||
}
|
||||
}
|
||||
|
||||
function delayReset(){
|
||||
delay = true;
|
||||
}
|
Reference in New Issue
Block a user