Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/create-room #31

Merged
merged 21 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3a32076
feat(backend): add route to create a room, and methods to add it in t…
TheRealSharKzy Jan 9, 2024
7d28516
feat(frontend) : added a part of the frontend of the creating a room …
TheRealSharKzy Jan 9, 2024
d2db4f6
fix(backend) : fixing CORS problem
TheRealSharKzy Jan 10, 2024
f7a86d3
fix(backend) : fixing code smell for parameters checking in RoomPost,…
TheRealSharKzy Jan 10, 2024
f62dbf5
feat(frontend) : end of the frontend before review
TheRealSharKzy Jan 10, 2024
b110fa2
feat(frontend) : Adjustement on CSS and frontend in general
TheRealSharKzy Jan 11, 2024
af00c9f
chore : Adding an endpoint for streaming services and using it in fro…
TheRealSharKzy Jan 13, 2024
561d20b
chore : Giving directly the streaming service id to the createRoom me…
TheRealSharKzy Jan 13, 2024
93341b4
fix(frontend) : changed backend url to make them dynamic
TheRealSharKzy Jan 13, 2024
7af4876
chore: deleting assets files of spotify and souncloud logo. Also rena…
TheRealSharKzy Jan 14, 2024
a8e3b87
fix: Using cookies to create supabase clients and retrieve id
TheRealSharKzy Jan 15, 2024
bfbab95
chore: Adding a method to create supabase client
TheRealSharKzy Jan 15, 2024
0ef3493
refactor: fixed rooms routing
MAXOUXAX Jan 15, 2024
1f44fa5
chore(deps): updated package-lock.json
MAXOUXAX Jan 15, 2024
4f74868
refactor(backend): changed endpoint of streaming services
MAXOUXAX Jan 15, 2024
7a0aa30
style(ui): improved style of CustomTextInput
MAXOUXAX Jan 15, 2024
b6af2d4
refactor(frontend): improved ServicesList component
MAXOUXAX Jan 15, 2024
15f11eb
chore: added .env.local.example file
MAXOUXAX Jan 15, 2024
75df51e
chore: improved typing in RoomPOST route
MAXOUXAX Jan 15, 2024
df4dc03
chore(types): changed any to actual type
MAXOUXAX Jan 15, 2024
7b7347d
Merge branch 'main' of github.com:datsmysong/app into feat/create-room
MAXOUXAX Jan 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions backend/.env.local.exemple

This file was deleted.

3 changes: 2 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"dotenv": "^16.3.1",
"fastify": "^4.25.2",
"fastify-socket.io": "^5.0.0",
"socket.io": "^4.7.3"
"socket.io": "^4.7.3",
"@fastify/cors": "^8.5.0"
},
"devDependencies": {
"@types/node": "^20.10.5",
Expand Down
131 changes: 131 additions & 0 deletions backend/src/room.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { supabase } from "./server";

let roomId: string | null = null;
let roomQueue: string[] = [];
MAXOUXAX marked this conversation as resolved.
Show resolved Hide resolved

export async function createRoom(
name: string,
code: string,
voteSkipping: boolean,
voteSkippingNeeded: number,
maxMusicPerUser: number,
maxMusicPerUserDuration: number,
serviceName: string,
) {
let created_at = new Date();
MAXOUXAX marked this conversation as resolved.
Show resolved Hide resolved
let configurationId: string | null = null;
let hostUserProfileId: string | null = null;
let streamingServicesId: string | null = null;

const userProfileRes = await supabase
.from("user_profile")
.select("user_profile_id");

if (userProfileRes.error) {
console.error(userProfileRes.error);
} else {
hostUserProfileId = userProfileRes.data[0].user_profile_id;
console.log("Host user profile id retrieved");
}
MAXOUXAX marked this conversation as resolved.
Show resolved Hide resolved

const streamingServicesRes = await supabase
.from("streaming_services")
.select("*")
.eq("service_name", serviceName);

if (streamingServicesRes.error) {
console.error(streamingServicesRes.error);
} else {
streamingServicesId = streamingServicesRes.data[0].service_id;
console.log("Streaming services id retrieved");
}
MAXOUXAX marked this conversation as resolved.
Show resolved Hide resolved

const roomConfigRes = await supabase
.from("active_room_configurations")
.insert([
{
vote_skipping: voteSkipping,
vote_skipping_needed_percentage: voteSkippingNeeded,
max_music_count_in_queue_per_participant: maxMusicPerUser,
max_music_duration: maxMusicPerUserDuration,
},
])
.select("id");

if (roomConfigRes.error) {
console.error(roomConfigRes.error);
MAXOUXAX marked this conversation as resolved.
Show resolved Hide resolved
} else {
configurationId = roomConfigRes.data[0].id;
console.log("Room configurations created");
}

const roomRes = await supabase
.from("active_rooms")
.insert([
{
name: name,
code: code,
created_at: created_at,
MAXOUXAX marked this conversation as resolved.
Show resolved Hide resolved
configuration_id: configurationId,
host_user_profile_id: hostUserProfileId,
service_id: streamingServicesId,
},
])
.select("id");

if (roomRes.error) {
console.error(roomRes.error);
MAXOUXAX marked this conversation as resolved.
Show resolved Hide resolved
} else {
roomId = roomRes.data[0].id;
console.log("Room created");
}
}

export function endRoom(roomId: string) {
let ended_at = new Date();
let created_at: Date | null = null;
let configurationId: string | null = null;
let hostUserProfileId: string | null = null;

supabase
.from("active_rooms")
.delete()
.eq("id", roomId)
.select("*")
.then((res) => {
if (res.error) {
console.error(res.error);
MAXOUXAX marked this conversation as resolved.
Show resolved Hide resolved
} else {
created_at = res.data[0].created_at;
configurationId = res.data[0].configuration_id;
hostUserProfileId = res.data[0].host_user_profile_id;
console.log("Room ended");
}
});

supabase
.from("rooms")
.insert([
{
created_at: created_at,
ended_at: ended_at,
MAXOUXAX marked this conversation as resolved.
Show resolved Hide resolved
configuration_id: configurationId,
host_user_profile_id: hostUserProfileId,
},
])
.then((res) => {
if (res.error) {
console.error(res.error);
MAXOUXAX marked this conversation as resolved.
Show resolved Hide resolved
} else {
console.log("Room added to rooms");
MAXOUXAX marked this conversation as resolved.
Show resolved Hide resolved
}
});
}

function addMusic(music: any) {
roomQueue.push(music);
}

function removeMusic(music: any) {
roomQueue.splice(roomQueue.indexOf(music), 1);
}
MAXOUXAX marked this conversation as resolved.
Show resolved Hide resolved
35 changes: 35 additions & 0 deletions backend/src/route/RoomPOST.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { FastifyReply, FastifyRequest } from "fastify";
import { createRoom } from "../room";

interface BodyParams {
name: string;
code: string;
service: string;
voteSkipping: boolean;
voteSkippingNeeded: number;
maxMusicPerUser: number;
maxMusicPerUserDuration: number;
}

export default function RoomPOST(req: FastifyRequest, reply: FastifyReply) {
const name = (req.body as BodyParams).name;
const code = (req.body as BodyParams).code;
const voteSkipping = (req.body as BodyParams).voteSkipping;
const voteSkippingNeeded = (req.body as BodyParams).voteSkippingNeeded;
const maxMusicPerUser = (req.body as BodyParams).maxMusicPerUser;
const maxMusicPerUserDuration = (req.body as BodyParams)
.maxMusicPerUserDuration;
const serviceName = (req.body as BodyParams).service;
MAXOUXAX marked this conversation as resolved.
Show resolved Hide resolved

createRoom(
name,
code,
voteSkipping,
voteSkippingNeeded,
maxMusicPerUser,
maxMusicPerUserDuration,
serviceName,
).then(() => {
reply.send({ message: "Room created" });
MAXOUXAX marked this conversation as resolved.
Show resolved Hide resolved
});
}
27 changes: 26 additions & 1 deletion backend/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import fastify from "fastify";
import fastifyIO from "fastify-socket.io";
import cors from "@fastify/cors";
import { Server } from "socket.io";
import HelloGet from "./route/HelloGET";
import RoomsGET from "./route/RoomGET";
import RoomPOST from "./route/RoomPOST";
import { createClient } from "@supabase/supabase-js";
import { config } from "dotenv";
import path from "path";
Expand All @@ -23,15 +25,38 @@ if (!process.env.SUPABASE_URL || !process.env.SERVICE_ROLE) {

export const supabase = createClient(
process.env.SUPABASE_URL,
process.env.SERVICE_ROLE
process.env.SERVICE_ROLE,
);

server.register(fastifyIO);

server.register(cors, {
origin: "*", // Allow all origins
methods: ["GET", "POST", "OPTIONS"],
});

server.get("/rooms", RoomsGET);

server.get("/hello", HelloGet);

const createRoomSchema = {
body: {
type: "object",
required: ["name", "code", "service"],
MAXOUXAX marked this conversation as resolved.
Show resolved Hide resolved
properties: {
name: { type: "string" },
code: { type: "string" },
service: { type: "string" },
voteSkipping: { type: "boolean" },
voteSkippingNeeded: { type: "number" },
maxMusicPerUser: { type: "number" },
maxMusicPerUserDuration: { type: "number" },
},
},
};

server.post("/createRoom", { schema: createRoomSchema }, RoomPOST);

server.ready().then(() => {
// we need to wait for the server to be ready, else `server.io` is undefined
server.io.on("connection", (socket: any) => {
Expand Down
3 changes: 3 additions & 0 deletions expo/app/(tabs)/Rooms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export default function TabsRooms() {
<Link href="/AddMusic" asChild>
Add Music
</Link>
<Link href="/CreateRoom" >
MAXOUXAX marked this conversation as resolved.
Show resolved Hide resolved
Create Room
</Link>
</View>
);
}
Loading
Loading