Join us
This commit is contained in:
parent
02ac670fe1
commit
814e559ccd
5 changed files with 132 additions and 32 deletions
|
|
@ -1,6 +1,9 @@
|
|||
import { initSocket, subscribe } from "../utils/streams";
|
||||
import { initSocket, socket, subscribe } from "../utils/streams";
|
||||
import { calculateLayout } from "./utils";
|
||||
import { authenticate } from "../utils/auth";
|
||||
import { authenticate, refreshToken } from "../utils/auth";
|
||||
import { initCanvas } from "../rooms/canvas/utils";
|
||||
import { getCanvas } from "../rooms/canvas/index";
|
||||
import { fetchRoomConfig, getCurrentRoomConfig } from "../rooms/index";
|
||||
|
||||
// Initialize the layout
|
||||
calculateLayout();
|
||||
|
|
@ -15,3 +18,29 @@ if (!room) {
|
|||
|
||||
await initSocket();
|
||||
await subscribe(room, "pixel-update");
|
||||
// Main event
|
||||
socket.on("message", async (response) => {
|
||||
console.debug("Received server evemt: ");
|
||||
console.debug(response);
|
||||
if (response.error) {
|
||||
console.error("Got server error: " + response.error.json.message);
|
||||
|
||||
if (response.error.json.data.httpStatus === 401) {
|
||||
await refreshToken();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.result.type === "started") {
|
||||
await fetchRoomConfig(room);
|
||||
}
|
||||
|
||||
const canvasResp = getCanvas(room);
|
||||
|
||||
if (!canvasResp || canvasResp.pixels) {
|
||||
return;
|
||||
}
|
||||
|
||||
initCanvas(getCurrentRoomConfig(), canvasResp.pixels);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue