maybe working full?
This commit is contained in:
@@ -10,17 +10,14 @@ import {
|
||||
writeBatch,
|
||||
} from "firebase/firestore";
|
||||
import OfficeRoom, { OfficeRoomState } from "../models/officeRoom";
|
||||
// import AgoraService from "./agoraService";
|
||||
import { Collections } from "./collections";
|
||||
import { getFunctions, httpsCallable } from "firebase/functions";
|
||||
|
||||
interface IAgoraTokenResult {
|
||||
data: { token: string };
|
||||
}
|
||||
|
||||
export default class OfficeRoomService {
|
||||
private db: Firestore = getFirestore();
|
||||
private batch = writeBatch(this.db);
|
||||
private functions = getFunctions();
|
||||
|
||||
// private agoraService = new AgoraService();
|
||||
|
||||
async createInitialOfficeRooms(createdByUserId: string, teamId: string) {
|
||||
const entrance = new OfficeRoom("Entrance", teamId, createdByUserId);
|
||||
@@ -51,47 +48,16 @@ export default class OfficeRoomService {
|
||||
await this.batch.commit();
|
||||
}
|
||||
|
||||
// async createOrUpdateRoom(room: Room) {
|
||||
// if (room.id) {
|
||||
// //update
|
||||
// await this.updateRoom(room);
|
||||
// } else {
|
||||
// //create
|
||||
// const roomDocRef = await addDoc(collection(this.db, Collections.rooms), {
|
||||
// ...room,
|
||||
// createdDate: serverTimestamp(),
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
async joinOfficeRoom(officeRoom: OfficeRoom, userId: string) {
|
||||
// get agoraToken
|
||||
// const agoraToken = await this.agoraService.getAgoraToken();
|
||||
|
||||
async getAgoraToken(): Promise<string> {
|
||||
// const agoraToken = await fetch("/api/agora/token", {
|
||||
// method: "post",
|
||||
// headers: {
|
||||
// "Content-Type": "application/json",
|
||||
// },
|
||||
// body: JSON.stringify({ channelName: "testChannel" }),
|
||||
// });
|
||||
// join channel
|
||||
// await this.agoraService.handleJoinChannel(officeRoom.id, agoraToken);
|
||||
|
||||
const cfResult = httpsCallable(this.functions, "agoraToken");
|
||||
|
||||
return await cfResult({ channelName: "testChannel" })
|
||||
.then((result: IAgoraTokenResult) => {
|
||||
const data = result.data;
|
||||
|
||||
if (!data.token) {
|
||||
throw new Error("No token retrieved from agora");
|
||||
}
|
||||
|
||||
return data.token;
|
||||
})
|
||||
.catch((error) => {
|
||||
// Getting the Error details.
|
||||
const code = error.code;
|
||||
const message = error.message;
|
||||
const details = error.details;
|
||||
throw error;
|
||||
});
|
||||
// update members list in firestore
|
||||
const newMembers = [...officeRoom.members, userId];
|
||||
await this.updateMembersInOfficeRoom(officeRoom.id, newMembers);
|
||||
}
|
||||
|
||||
async updateMembersInOfficeRoom(
|
||||
|
||||
Reference in New Issue
Block a user