having one solution for different components of app
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
env: {
|
||||
es6: true,
|
||||
node: true,
|
||||
},
|
||||
extends: [
|
||||
// "eslint:recommended",
|
||||
// "plugin:import/errors",
|
||||
// "plugin:import/warnings",
|
||||
// "plugin:import/typescript",
|
||||
// "google",
|
||||
// "plugin:@typescript-eslint/recommended",
|
||||
|
||||
"eslint:recommended",
|
||||
"plugin:import/errors",
|
||||
"plugin:import/warnings",
|
||||
"plugin:import/typescript",
|
||||
],
|
||||
parser: "@typescript-eslint/parser",
|
||||
parserOptions: {
|
||||
project: ["tsconfig.json", "tsconfig.dev.json"],
|
||||
sourceType: "module",
|
||||
tsconfigRootDir: __dirname,
|
||||
},
|
||||
ignorePatterns: [
|
||||
"/lib/**/*", // Ignore built files.
|
||||
],
|
||||
plugins: ["@typescript-eslint", "import"],
|
||||
rules: {
|
||||
quotes: ["error", "double"],
|
||||
// "import/no-unresolved": 0,
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
# Compiled JavaScript files
|
||||
lib/**/*.js
|
||||
lib/**/*.js.map
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Node.js dependency directory
|
||||
node_modules/
|
||||
Generated
+7644
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "functions",
|
||||
"scripts": {
|
||||
"lint": "eslint --ext .js,.ts .",
|
||||
"build": "npm run lint && tsc",
|
||||
"serve": "npm run build && firebase emulators:start --only functions & tsc --watch",
|
||||
"shell": "npm run build && firebase functions:shell",
|
||||
"start": "npm run shell",
|
||||
"deploy": "firebase deploy --only functions",
|
||||
"logs": "firebase functions:log",
|
||||
"hotReload": "tsc --watch"
|
||||
},
|
||||
"engines": {
|
||||
"node": "16"
|
||||
},
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"agora-access-token": "^2.0.4",
|
||||
"firebase-admin": "^9.8.0",
|
||||
"firebase-functions": "^3.14.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "^3.9.1",
|
||||
"@typescript-eslint/parser": "^3.8.0",
|
||||
"eslint": "^7.6.0",
|
||||
"eslint-config-google": "^0.14.0",
|
||||
"eslint-plugin-import": "^2.22.0",
|
||||
"firebase-functions-test": "^0.2.0",
|
||||
"typescript": "^3.8.0"
|
||||
},
|
||||
"private": true
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import * as functions from "firebase-functions";
|
||||
import * as admin from "firebase-admin";
|
||||
admin.initializeApp();
|
||||
|
||||
// exports.agoraToken = functions.https.onCall((data, context) => {
|
||||
// console.log(data);
|
||||
|
||||
// console.log("user's id: " + context.auth?.uid);
|
||||
// const channelName = data.channelName;
|
||||
|
||||
// const token = agora.getAgoraToken(channelName);
|
||||
|
||||
// return {token};
|
||||
// });
|
||||
|
||||
export const agoraToken = functions.https.onCall((data, context) => {
|
||||
console.log(data);
|
||||
|
||||
console.log("user's id: " + context.auth?.uid);
|
||||
const channelName: string = data.channelName;
|
||||
|
||||
let token = getAgoraToken(channelName);
|
||||
|
||||
return { token };
|
||||
});
|
||||
|
||||
import { RtcTokenBuilder, RtcRole } from "agora-access-token";
|
||||
|
||||
function getAgoraToken(channelName: string) {
|
||||
// Rtc Examples
|
||||
const appID = "c8dfd65deb5c4741bd564085627139d0";
|
||||
const appCertificate = "aa57b809934b4efcb407cf30089d9f25";
|
||||
const uid = 0; // no need to use this as we have authenticated this user
|
||||
const role = RtcRole.PUBLISHER;
|
||||
|
||||
const expirationTimeInSeconds = 3600;
|
||||
|
||||
const currentTimestamp = Math.floor(Date.now() / 1000);
|
||||
|
||||
const privilegeExpiredTs = currentTimestamp + expirationTimeInSeconds;
|
||||
|
||||
// IMPORTANT! Build token with either the uid or with the user account. Comment out the option you do not want to use below.
|
||||
|
||||
// Build token with uid
|
||||
const tokenA = RtcTokenBuilder.buildTokenWithUid(
|
||||
appID,
|
||||
appCertificate,
|
||||
channelName,
|
||||
uid,
|
||||
role,
|
||||
privilegeExpiredTs
|
||||
);
|
||||
console.log("Token With Integer Number Uid: " + tokenA);
|
||||
|
||||
return tokenA;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import * as functions from "firebase-functions";
|
||||
import * as admin from "firebase-admin";
|
||||
|
||||
admin.initializeApp();
|
||||
|
||||
// // Start writing Firebase Functions
|
||||
// // https://firebase.google.com/docs/functions/typescript
|
||||
//
|
||||
export const helloWorld = functions.https.onRequest((request, response) => {
|
||||
functions.logger.info("Hello no!", { structuredData: true });
|
||||
response.send("Hello from woahhhhhh!");
|
||||
});
|
||||
|
||||
import { agoraToken } from "./agora";
|
||||
exports.agoraToken = agoraToken;
|
||||
@@ -0,0 +1,14 @@
|
||||
// import * as functions from "firebase-functions";
|
||||
|
||||
// exports.inviteUserToTeam = functions.firestore
|
||||
// .document('teamMembers/{userId}')
|
||||
// .onCreate((snap, context) => {
|
||||
// // Get an object representing the document
|
||||
// // e.g. {'name': 'Marie', 'age': 66}
|
||||
// const newValue = snap.data();
|
||||
|
||||
// // access a particular field as you would any JS property
|
||||
// const name = newValue.name;
|
||||
|
||||
// // perform desired operations ...
|
||||
// });
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"include": [".eslintrc.js"]
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"noImplicitReturns": true,
|
||||
"noUnusedLocals": true,
|
||||
"outDir": "lib",
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"target": "es2017",
|
||||
"strictNullChecks": true
|
||||
},
|
||||
"compileOnSave": true,
|
||||
"include": ["src"]
|
||||
}
|
||||
Reference in New Issue
Block a user