diff --git a/nginx/public/officeHours.js b/nginx/public/officeHours.js index 3514c14..5357673 100644 --- a/nginx/public/officeHours.js +++ b/nginx/public/officeHours.js @@ -3,6 +3,8 @@ const socket = io.connect("http://localhost:8080", {transports: ['websocket']}); socket.on('queue', displayQueue); socket.on('message', displayMessage); + + function displayMessage(newMessage) { document.getElementById("message").innerHTML = newMessage; } diff --git a/src/main/scala/model/OfficeHoursServer.scala b/src/main/scala/model/OfficeHoursServer.scala index 09ef61b..b2cd3b9 100644 --- a/src/main/scala/model/OfficeHoursServer.scala +++ b/src/main/scala/model/OfficeHoursServer.scala @@ -60,10 +60,15 @@ class DisconnectionListener(server: OfficeHoursServer) extends DisconnectListene class EnterQueueListener(server: OfficeHoursServer) extends DataListener[String] { override def onData(socket: SocketIOClient, username: String, ackRequest: AckRequest): Unit = { - server.database.addStudentToQueue(StudentInQueue(username, System.nanoTime())) - server.socketToUsername += (socket -> username) - server.usernameToSocket += (username -> socket) - server.server.getBroadcastOperations.sendEvent("queue", server.queueJSON()) + var usernameList=server.usernameToSocket.keySet + if (usernameList.contains(username)) { + server.usernameToSocket(username).sendEvent("message","This username has been taken, plz change a username!! ") + }else { + server.database.addStudentToQueue(StudentInQueue(username, System.nanoTime())) + server.socketToUsername += (socket -> username) + server.usernameToSocket += (username -> socket) + server.server.getBroadcastOperations.sendEvent("queue", server.queueJSON()) + } } }