summaryrefslogtreecommitdiff
path: root/rushs/eplace/src/rooms/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'rushs/eplace/src/rooms/index.js')
-rw-r--r--rushs/eplace/src/rooms/index.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/rushs/eplace/src/rooms/index.js b/rushs/eplace/src/rooms/index.js
new file mode 100644
index 0000000..dde88e6
--- /dev/null
+++ b/rushs/eplace/src/rooms/index.js
@@ -0,0 +1,50 @@
+// FIXME: This file should handle the rooms API
+// Functions may include:
+
+import { subscribe } from "../utils/streams";
+import { authedAPIRequest } from "../utils/auth";
+
+// - fetchRoomConfig (get the configuration of a room)
+export async function fetchRoomConfig(slug) {
+ const config = {
+ method: "get",
+ };
+
+ return authedAPIRequest(`/rooms/${slug}/config`, config)
+ .then(async (res) => {
+ if (!res) {
+ return null;
+ }
+
+ const response = await res.json();
+
+ document.getElementById("room-name").innerHTML =
+ response.metadata.name;
+ const description = document.getElementById("room-description");
+
+ if (response.metadata.description) {
+ description.innerHTML = response.metadata.description;
+ description.style.display = "inherit";
+ } else {
+ description.style.display = "none";
+ }
+
+ return response;
+ })
+ .catch((error) => {
+ console.log(error);
+ return null;
+ });
+}
+// - joinRoom (join a room by its slug)
+export function joinRoom(slug) {
+ if (!slug) {
+ slug = "epi-place";
+ }
+
+ subscribe(slug);
+}
+// - listRooms (list all the rooms available)
+// - createRoom (create a room)
+// - updateRoom (update a room's configuration)
+// - deleteRoom (delete a room)