2019-09-15 15:03:44 -04:00
|
|
|
package com.chameleonvision.web;
|
2019-09-10 23:47:06 +03:00
|
|
|
|
2019-09-15 15:03:44 -04:00
|
|
|
import com.chameleonvision.settings.SettingsManager;
|
2019-09-10 23:47:06 +03:00
|
|
|
import io.javalin.Javalin;
|
2019-09-15 01:55:29 +03:00
|
|
|
|
2019-09-11 20:28:56 +03:00
|
|
|
|
2019-09-10 23:47:06 +03:00
|
|
|
public class Server {
|
2019-09-21 16:04:58 +03:00
|
|
|
public static ServerHandler handler;
|
2019-09-16 04:10:26 +03:00
|
|
|
|
2019-09-10 23:47:06 +03:00
|
|
|
public static void main(int port) {
|
2019-09-21 16:04:58 +03:00
|
|
|
handler = new ServerHandler();
|
|
|
|
|
|
2019-09-11 20:28:56 +03:00
|
|
|
Javalin app = Javalin.create();
|
|
|
|
|
app.config.addStaticFiles("web");
|
2019-09-16 04:10:26 +03:00
|
|
|
app.ws("/websocket", ws -> {
|
2019-09-11 20:28:56 +03:00
|
|
|
ws.onConnect(ctx -> {
|
2019-09-21 16:04:58 +03:00
|
|
|
handler.onConnect(ctx);
|
2019-09-11 20:28:56 +03:00
|
|
|
System.out.println("Socket Connected");
|
|
|
|
|
});
|
|
|
|
|
ws.onClose(ctx -> {
|
2019-09-21 16:04:58 +03:00
|
|
|
handler.onClose(ctx);
|
2019-09-11 20:28:56 +03:00
|
|
|
System.out.println("Socket Disconnected");
|
2019-09-20 19:54:59 -04:00
|
|
|
SettingsManager.saveSettings();
|
2019-09-11 20:28:56 +03:00
|
|
|
});
|
2019-10-12 03:38:42 +03:00
|
|
|
ws.onBinaryMessage(ctx -> {
|
|
|
|
|
handler.onBinaryMessage(ctx);
|
2019-09-11 20:28:56 +03:00
|
|
|
});
|
|
|
|
|
});
|
2019-10-20 10:13:07 +03:00
|
|
|
|
|
|
|
|
app.start(port);
|
2019-09-11 20:28:56 +03:00
|
|
|
}
|
2019-10-12 03:38:42 +03:00
|
|
|
}
|