Fix indentation
This commit is contained in:
parent
ac474aacbd
commit
7b920dd6a9
@ -4,8 +4,12 @@ root = true
|
|||||||
|
|
||||||
[*]
|
[*]
|
||||||
charset = utf-8
|
charset = utf-8
|
||||||
indent_style = space
|
indent_style = tab
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
end_of_line = lf
|
end_of_line = lf
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.css]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
@ -7,9 +7,9 @@ import io.vertx.core.VertxOptions;
|
|||||||
|
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
var vertx = Vertx.builder().with(new VertxOptions().setPreferNativeTransport(true)).build();
|
var vertx = Vertx.builder().with(new VertxOptions().setPreferNativeTransport(true)).build();
|
||||||
vertx.deployVerticle(new MainVerticle(), new DeploymentOptions().setThreadingModel(ThreadingModel.VIRTUAL_THREAD));
|
vertx.deployVerticle(new MainVerticle(), new DeploymentOptions().setThreadingModel(ThreadingModel.VIRTUAL_THREAD));
|
||||||
Thread.currentThread().join();
|
Thread.currentThread().join();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,42 +14,42 @@ import java.time.Duration;
|
|||||||
|
|
||||||
public class MainVerticle extends AbstractVerticle {
|
public class MainVerticle extends AbstractVerticle {
|
||||||
|
|
||||||
private Single<HttpServer> httpServer;
|
private Single<HttpServer> httpServer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Completable rxStart() {
|
public Completable rxStart() {
|
||||||
|
|
||||||
vertx.eventBus().consumer("connect2x.move")
|
vertx.eventBus().consumer("connect2x.move")
|
||||||
.handler(event -> System.out.println("Received: " + event.body()));
|
.handler(event -> System.out.println("Received: " + event.body()));
|
||||||
|
|
||||||
var server = vertx.createHttpServer();
|
var server = vertx.createHttpServer();
|
||||||
|
|
||||||
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
|
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
|
||||||
SockJSBridgeOptions sockJSBridgeOptions = new SockJSBridgeOptions()
|
SockJSBridgeOptions sockJSBridgeOptions = new SockJSBridgeOptions()
|
||||||
.addInboundPermitted(new PermittedOptions().setAddress("connect2x.move"))
|
.addInboundPermitted(new PermittedOptions().setAddress("connect2x.move"))
|
||||||
.addOutboundPermitted(new PermittedOptions().setAddress("connect2x.moved"));
|
.addOutboundPermitted(new PermittedOptions().setAddress("connect2x.moved"));
|
||||||
|
|
||||||
Router router = Router.router(vertx);
|
Router router = Router.router(vertx);
|
||||||
router
|
router
|
||||||
.get("/*")
|
.get("/*")
|
||||||
.handler(StaticHandler
|
.handler(StaticHandler
|
||||||
.create(FileSystemAccess.RELATIVE,"webroot")
|
.create(FileSystemAccess.RELATIVE,"webroot")
|
||||||
//.setDirectoryListing(true)
|
//.setDirectoryListing(true)
|
||||||
.setCachingEnabled(true)
|
.setCachingEnabled(true)
|
||||||
.setAlwaysAsyncFS(true)
|
.setAlwaysAsyncFS(true)
|
||||||
.setIndexPage("static/index.html")
|
.setIndexPage("static/index.html")
|
||||||
.setSendVaryHeader(true)
|
.setSendVaryHeader(true)
|
||||||
.setEnableRangeSupport(true)
|
.setEnableRangeSupport(true)
|
||||||
.setMaxAgeSeconds(Duration.ofSeconds(1).toSeconds()));
|
.setMaxAgeSeconds(Duration.ofSeconds(1).toSeconds()));
|
||||||
|
|
||||||
router.get("/eventbus/*").subRouter(sockJSHandler.bridge(sockJSBridgeOptions));
|
router.get("/eventbus/*").subRouter(sockJSHandler.bridge(sockJSBridgeOptions));
|
||||||
|
|
||||||
this.httpServer = server.requestHandler(router).listen(8081).cache();
|
this.httpServer = server.requestHandler(router).listen(8081).cache();
|
||||||
return httpServer.ignoreElement();
|
return httpServer.ignoreElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Completable rxStop() {
|
public Completable rxStop() {
|
||||||
return httpServer.flatMapCompletable(HttpServer::close);
|
return httpServer.flatMapCompletable(HttpServer::close);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,118 +1,118 @@
|
|||||||
const chars = ["AN","AR","AT","CA","CH","CO","DE","DI","EL","EN","ER","ES","HE","IA","IL","IN","IO","LA","LE","LI","LL","MA","ME","NA","NE","NO","NT","OL","ON","OR","PE","RA","RE","RI","RO","SE","SI","SO","ST","TA","TE","TI","TO","TR","TT","UN","TO","RE","ER","ON","CO","DI","TA","EN","IN","TE","AT","RA","AN","NO","NT","ST","LA","AR","AL","OR","CH","RI","TI","IO","LE","DE","ES","NE","ME","TT","EL","PE","IL","UN","IA","LI","SE","SO","LL","SI","OL","RO","MA","CA","NA","TR","HE","ALE","ALL","ANC","AND","ANT","ARE","ATO","ATT","CHE","CHI","COM","CON","DEL","ELL","ENT","ERA","ERE","ESS","EST","ETT","GLI","ION","LLA","MEN","NON","NTE","NTI","NTO","OLO","ONE","ONO","PER","QUE","SON","STA","STO","TAT","TRA","TTO","UNA","VER","ZIO","ENT","CHE","ATO","PER","NTE","CON","ELL","STA","ARE","MEN","ION","DEL","LLA","TTO","TAT","ESS","ERE","ETT","EST","ONE","ONO","ZIO","NON","ERA","CHI","GLI","COM","TRA","STO","NTI","SON","VER","ATT","UNA","QUE","NTO","AND","ALL","OLO","ANC","ANT","ALE"];
|
const chars = ["AN","AR","AT","CA","CH","CO","DE","DI","EL","EN","ER","ES","HE","IA","IL","IN","IO","LA","LE","LI","LL","MA","ME","NA","NE","NO","NT","OL","ON","OR","PE","RA","RE","RI","RO","SE","SI","SO","ST","TA","TE","TI","TO","TR","TT","UN","TO","RE","ER","ON","CO","DI","TA","EN","IN","TE","AT","RA","AN","NO","NT","ST","LA","AR","AL","OR","CH","RI","TI","IO","LE","DE","ES","NE","ME","TT","EL","PE","IL","UN","IA","LI","SE","SO","LL","SI","OL","RO","MA","CA","NA","TR","HE","ALE","ALL","ANC","AND","ANT","ARE","ATO","ATT","CHE","CHI","COM","CON","DEL","ELL","ENT","ERA","ERE","ESS","EST","ETT","GLI","ION","LLA","MEN","NON","NTE","NTI","NTO","OLO","ONE","ONO","PER","QUE","SON","STA","STO","TAT","TRA","TTO","UNA","VER","ZIO","ENT","CHE","ATO","PER","NTE","CON","ELL","STA","ARE","MEN","ION","DEL","LLA","TTO","TAT","ESS","ERE","ETT","EST","ONE","ONO","ZIO","NON","ERA","CHI","GLI","COM","TRA","STO","NTI","SON","VER","ATT","UNA","QUE","NTO","AND","ALL","OLO","ANC","ANT","ALE"];
|
||||||
function randomID() {
|
function randomID() {
|
||||||
var u8 = crypto.getRandomValues(new Uint8Array(3));
|
var u8 = crypto.getRandomValues(new Uint8Array(3));
|
||||||
return Array.from(u8).map(n => chars[n % chars.length]).reduce((a, b) => a + b);
|
return Array.from(u8).map(n => chars[n % chars.length]).reduce((a, b) => a + b);
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", e => {
|
document.addEventListener("DOMContentLoaded", e => {
|
||||||
|
|
||||||
const gameCode = document.getElementById("game-code");
|
const gameCode = document.getElementById("game-code");
|
||||||
const gameCodeLink = document.getElementById("game-code-link");
|
const gameCodeLink = document.getElementById("game-code-link");
|
||||||
const newGameLink = document.getElementById("new-game-link");
|
const newGameLink = document.getElementById("new-game-link");
|
||||||
const mainBody = document.getElementById("main-body");
|
const mainBody = document.getElementById("main-body");
|
||||||
|
|
||||||
const eb = new EventBus(`${document.location.origin}/eventbus`);
|
const eb = new EventBus(`${document.location.origin}/eventbus`);
|
||||||
eb.enableReconnect(true);
|
eb.enableReconnect(true);
|
||||||
eb.onopen = function() {}; // Set up handlers here, will be called on initial connection and all reconnections
|
eb.onopen = function() {}; // Set up handlers here, will be called on initial connection and all reconnections
|
||||||
eb.onreconnect = function() {}; // Optional, will only be called on reconnections
|
eb.onreconnect = function() {}; // Optional, will only be called on reconnections
|
||||||
|
|
||||||
// Alternatively, pass in an options object
|
// Alternatively, pass in an options object
|
||||||
var options = {
|
var options = {
|
||||||
vertxbus_reconnect_attempts_max: Infinity, // Max reconnect attempts
|
vertxbus_reconnect_attempts_max: Infinity, // Max reconnect attempts
|
||||||
vertxbus_reconnect_delay_min: 1000, // Initial delay (in ms) before first reconnect attempt
|
vertxbus_reconnect_delay_min: 1000, // Initial delay (in ms) before first reconnect attempt
|
||||||
vertxbus_reconnect_delay_max: 5000, // Max delay (in ms) between reconnect attempts
|
vertxbus_reconnect_delay_max: 5000, // Max delay (in ms) between reconnect attempts
|
||||||
vertxbus_reconnect_exponent: 2, // Exponential backoff factor
|
vertxbus_reconnect_exponent: 2, // Exponential backoff factor
|
||||||
vertxbus_randomization_factor: 0.5 // Randomization factor between 0 and 1
|
vertxbus_randomization_factor: 0.5 // Randomization factor between 0 and 1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const connect2x = document.connect2x = {
|
const connect2x = document.connect2x = {
|
||||||
clientId: randomID(),
|
clientId: randomID(),
|
||||||
gameId: null
|
gameId: null
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("hashchange", e=> {
|
window.addEventListener("hashchange", e=> {
|
||||||
onHashChange(e.target.location.hash);
|
onHashChange(e.target.location.hash);
|
||||||
})
|
})
|
||||||
|
|
||||||
onHashChange(document.location.hash);
|
onHashChange(document.location.hash);
|
||||||
|
|
||||||
function onHashChange(hash) {
|
function onHashChange(hash) {
|
||||||
if (hash != null && hash.length > 0) {
|
if (hash != null && hash.length > 0) {
|
||||||
hash = hash.substring(1);
|
hash = hash.substring(1);
|
||||||
} else {
|
} else {
|
||||||
hash = "";
|
hash = "";
|
||||||
}
|
}
|
||||||
if (hash.length === 0) {
|
if (hash.length === 0) {
|
||||||
if (connect2x.gameId == null) {
|
if (connect2x.gameId == null) {
|
||||||
onGameIdChange(randomID());
|
onGameIdChange(randomID());
|
||||||
} else {
|
} else {
|
||||||
console.warn("Game hash unchanged.");
|
console.warn("Game hash unchanged.");
|
||||||
}
|
}
|
||||||
} else if (hash.length > 32) {
|
} else if (hash.length > 32) {
|
||||||
console.error("Invalid page hash length", hash);
|
console.error("Invalid page hash length", hash);
|
||||||
document.body.innerHTML = `<h1>Invalid page hash length</h1><p><pre><code id="hash-text"></code></pre></p><p><a id="redirect-link">Go back</a></p>`;
|
document.body.innerHTML = `<h1>Invalid page hash length</h1><p><pre><code id="hash-text"></code></pre></p><p><a id="redirect-link">Go back</a></p>`;
|
||||||
document.getElementById("hash-text").innerText = hash;
|
document.getElementById("hash-text").innerText = hash;
|
||||||
const redirectLink = document.location.origin;
|
const redirectLink = document.location.origin;
|
||||||
document.getElementById("redirect-link").href = redirectLink;
|
document.getElementById("redirect-link").href = redirectLink;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
document.location.href = redirectLink;
|
document.location.href = redirectLink;
|
||||||
}, 5000);
|
}, 5000);
|
||||||
} else if (connect2x.gameId !== hash) {
|
} else if (connect2x.gameId !== hash) {
|
||||||
if (connect2x.gameId != null) {
|
if (connect2x.gameId != null) {
|
||||||
console.log("Game id changed, reloading...");
|
console.log("Game id changed, reloading...");
|
||||||
document.location.reload();
|
document.location.reload();
|
||||||
} else {
|
} else {
|
||||||
onGameIdChange(hash);
|
onGameIdChange(hash);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.warn("Game hash unchanged.");
|
console.warn("Game hash unchanged.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onGameIdChange(gameId) {
|
function onGameIdChange(gameId) {
|
||||||
connect2x.gameId = gameId;
|
connect2x.gameId = gameId;
|
||||||
console.info("Game ID", gameId);
|
console.info("Game ID", gameId);
|
||||||
gameCode.innerText = gameId;
|
gameCode.innerText = gameId;
|
||||||
const gameLink = `${document.location.origin}#${gameId}`;
|
const gameLink = `${document.location.origin}#${gameId}`;
|
||||||
document.location.hash = gameId;
|
document.location.hash = gameId;
|
||||||
gameCodeLink.href = gameLink;
|
gameCodeLink.href = gameLink;
|
||||||
gameCodeLink.onclick = async e => {
|
gameCodeLink.onclick = async e => {
|
||||||
if (navigator.share !== undefined) {
|
if (navigator.share !== undefined) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
await navigator.share({
|
await navigator.share({
|
||||||
title: "Connect 2x",
|
title: "Connect 2x",
|
||||||
text: "Play Connect 2x game with me",
|
text: "Play Connect 2x game with me",
|
||||||
url: gameLink
|
url: gameLink
|
||||||
}).then(() => console.log("Shared!")).catch(err => {
|
}).then(() => console.log("Shared!")).catch(err => {
|
||||||
console.error("Share failed", err);
|
console.error("Share failed", err);
|
||||||
navigateToGame(gameId);
|
navigateToGame(gameId);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
navigateToGame(gameId);
|
navigateToGame(gameId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onGameLoad();
|
onGameLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
function navigateToGame(gameId) {
|
function navigateToGame(gameId) {
|
||||||
document.location.hash = gameId;
|
document.location.hash = gameId;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onGameLoad() {
|
function onGameLoad() {
|
||||||
mainBody.classList.add("js-loaded");
|
mainBody.classList.add("js-loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
eb.onopen = () => {
|
eb.onopen = () => {
|
||||||
|
|
||||||
// set a handler to receive a message
|
// set a handler to receive a message
|
||||||
eb.registerHandler('connect2x.moved', (error, message) => {
|
eb.registerHandler('connect2x.moved', (error, message) => {
|
||||||
console.log('received a message: ' + JSON.stringify(message));
|
console.log('received a message: ' + JSON.stringify(message));
|
||||||
});
|
});
|
||||||
|
|
||||||
// send a message
|
// send a message
|
||||||
eb.send('connect2x.move', {name: 'tim', age: 587});
|
eb.send('connect2x.move', {name: 'tim', age: 587});
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Connect 2x</title>
|
<title>Connect 2x</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<link rel="stylesheet" href="/static/style.css">
|
<link rel="stylesheet" href="/static/style.css">
|
||||||
<script src="https://unpkg.io/sockjs-client@1.5.0/dist/sockjs.min.js"></script>
|
<script src="https://unpkg.io/sockjs-client@1.5.0/dist/sockjs.min.js"></script>
|
||||||
<script src='https://unpkg.io/@vertx/eventbus-bridge-client.js@1.0.0-1/vertx-eventbus.js'></script>
|
<script src='https://unpkg.io/@vertx/eventbus-bridge-client.js@1.0.0-1/vertx-eventbus.js'></script>
|
||||||
<script src='/static/connect2x.js'></script>
|
<script src='/static/connect2x.js'></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="main-body">
|
<div id="main-body">
|
||||||
<h1>Connect 2x</h1>
|
<h1>Connect 2x</h1>
|
||||||
<p>Game code: <span id="game-code"></span> <a id="game-code-link" href="#">[share]</a> <a id="new-game" href="/">[new game]</a></p>
|
<p>Game code: <span id="game-code"></span> <a id="game-code-link" href="#">[share]</a> <a id="new-game" href="/">[new game]</a></p>
|
||||||
<main id="board">
|
<main id="board">
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user