Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nginx/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<title>Office Hours</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js"></script>
</head>
<body>
<body style="background-color:Dodgerblue;">

<br/>

<h3 id="message">Welcome!</h3>

<p>Name</p>
<p>Name:</p>
<input type="text" id="name"/>
<button onclick="enterQueue();">Enter Queue</button>
<br/><br/>
Expand Down
2 changes: 1 addition & 1 deletion nginx/public/officeHours.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function displayQueue(queueJSON) {
const queue = JSON.parse(queueJSON);
let formattedQueue = "";
for (const student of queue) {
formattedQueue += student['username'] + " has been waiting since " + student['timestamp'] + "<br/>"
formattedQueue += student['username'] + " has been waiting since " + student['timestamp'] + " and is in position " + student['position'] + "<br/>"
}
document.getElementById("queue").innerHTML = formattedQueue;
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/scala/model/OfficeHoursServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class OfficeHoursServer() {
setPort(8080)
}

var nextPosition: Int = 0

val server: SocketIOServer = new SocketIOServer(config)

server.addDisconnectListener(new DisconnectionListener(this))
Expand Down Expand Up @@ -60,7 +62,8 @@ 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()))
val position: Int = server.database.getQueue.sortBy(_.timestamp).length + 1
server.database.addStudentToQueue(StudentInQueue(username, System.nanoTime(), position))
server.socketToUsername += (socket -> username)
server.usernameToSocket += (username -> socket)
server.server.getBroadcastOperations.sendEvent("queue", server.queueJSON())
Expand Down
9 changes: 5 additions & 4 deletions src/main/scala/model/StudentInQueue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@ object StudentInQueue {
output
}

def apply(username: String, timestamp: Long): StudentInQueue = {
new StudentInQueue(cleanString(username), timestamp)
def apply(username: String, timestamp: Long, position: Int): StudentInQueue = {
new StudentInQueue(cleanString(username), timestamp, position)
}


}

class StudentInQueue(val username: String, val timestamp: Long) {
class StudentInQueue(val username: String, val timestamp: Long, position: Int) {

def asJsValue(): JsValue ={
val messageMap: Map[String, JsValue] = Map(
"username" -> Json.toJson(username),
"timestamp" -> Json.toJson(timestamp)
"timestamp" -> Json.toJson(timestamp),
"position" -> Json.toJson(position)
)
Json.toJson(messageMap)
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/model/database/Database.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class Database extends DatabaseAPI{
while (result.next()) {
val username = result.getString("username")
val timestamp = result.getLong("timestamp")
queue = new StudentInQueue(username, timestamp) :: queue
val position = result.getInt("position")
queue = new StudentInQueue(username, timestamp, position) :: queue
}

queue.reverse
Expand Down