Skip to content

Commit

Permalink
some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
octo-kumo committed Jul 24, 2020
1 parent 9d414ec commit 1bc0bb2
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
import sg.edu.appventure.examclock.PreferenceController;
import sg.edu.appventure.examclock.model.Exam;

import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.DateTimeException;
import java.time.LocalDate;
import java.time.LocalTime;
Expand All @@ -32,9 +35,11 @@ public ClientSocket(MainController controller) {
IO.setDefaultOkHttpWebSocketFactory(okHttpClient);
IO.setDefaultOkHttpCallFactory(okHttpClient);
IO.Options opts = new IO.Options();
opts.path = "/socket.clocks";
opts.callFactory = okHttpClient;
opts.webSocketFactory = okHttpClient;
try {
opts.query = "clock=" + URLEncoder.encode(identifySelf(), String.valueOf(StandardCharsets.UTF_8));
socket = IO.socket("https://exam-clock-nush.tk", opts);
// socket = IO.socket("http://localhost:3000", opts);
socket.on(Socket.EVENT_CONNECT, args -> {
Expand Down Expand Up @@ -66,7 +71,7 @@ public ClientSocket(MainController controller) {
});
controller.toiletOccupied.addListener((observable, oldValue, newValue) -> socket.emit("toilet", newValue ? "occupied" : "vacant"));
socket.open();
} catch (URISyntaxException e) {
} catch (URISyntaxException | UnsupportedEncodingException e) {
e.printStackTrace();
}
}
Expand Down Expand Up @@ -149,14 +154,14 @@ private void onDeleteExam(Object... objects) {
});
}

private void identifySelf() {
private String identifySelf() {
JSONObject obj = new JSONObject();
obj.put("clockID", PreferenceController.clockID);
obj.put("clockName", PreferenceController.lanNameProperty.get());
JSONArray array = new JSONArray();
array.addAll(controller.exams);
obj.put("exams", array);
socket.emit("clock_connected", obj.toJSONString());
return obj.toJSONString();
}

public void onClockIDClash(Object... args) {
Expand Down

0 comments on commit 1bc0bb2

Please sign in to comment.