getting agoratoken works
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import {
|
||||
ClientConfig,
|
||||
IAgoraRTCRemoteUser,
|
||||
ICameraVideoTrack,
|
||||
IMicrophoneAudioTrack,
|
||||
} from "agora-rtc-sdk-ng";
|
||||
import {
|
||||
AgoraVideoPlayer,
|
||||
createClient,
|
||||
createMicrophoneAndCameraTracks,
|
||||
createMicrophoneAudioTrack,
|
||||
} from "agora-rtc-react";
|
||||
|
||||
const config: ClientConfig = {
|
||||
mode: "rtc",
|
||||
codec: "vp8",
|
||||
};
|
||||
const useClient = createClient(config);
|
||||
const useMicrophoneTracks = createMicrophoneAudioTrack();
|
||||
|
||||
// TODO: move this to env file
|
||||
const appId: string = "c8dfd65deb5c4741bd564085627139d0"; //ENTER APP ID HERE
|
||||
@@ -0,0 +1,15 @@
|
||||
import firebaseAdmin from "firebase-admin/app";
|
||||
|
||||
import serviceAccount from "../nirvana-for-business-firebase-adminsdk";
|
||||
|
||||
const adminApp = firebaseAdmin.initializeApp({
|
||||
credential: credential.cert({
|
||||
privateKey: serviceAccount.private_key,
|
||||
clientEmail: serviceAccount.client_email,
|
||||
projectId: serviceAccount.project_id,
|
||||
}),
|
||||
});
|
||||
|
||||
console.log("initialized firebase admin");
|
||||
|
||||
export { adminApp };
|
||||
@@ -11,10 +11,16 @@ import {
|
||||
} from "firebase/firestore";
|
||||
import OfficeRoom, { OfficeRoomState } from "../models/officeRoom";
|
||||
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();
|
||||
|
||||
async createInitialOfficeRooms(createdByUserId: string, teamId: string) {
|
||||
const entrance = new OfficeRoom("Entrance", teamId, createdByUserId);
|
||||
@@ -58,6 +64,36 @@ export default class OfficeRoomService {
|
||||
// }
|
||||
// }
|
||||
|
||||
async getAgoraToken(): Promise<string> {
|
||||
// const agoraToken = await fetch("/api/agora/token", {
|
||||
// method: "post",
|
||||
// headers: {
|
||||
// "Content-Type": "application/json",
|
||||
// },
|
||||
// body: JSON.stringify({ channelName: "testChannel" }),
|
||||
// });
|
||||
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
async updateMembersInOfficeRoom(
|
||||
officeRoomId: string,
|
||||
newMembersInRoom: string[]
|
||||
|
||||
Reference in New Issue
Block a user