Initial commit

This commit is contained in:
talksik
2021-12-31 04:01:41 -08:00
commit 36092e8af7
10 changed files with 2851 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
{
"projects": {
"default": "nirvana-ccf04"
}
}
+2
View File
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
+66
View File
@@ -0,0 +1,66 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
firebase-debug.log*
firebase-debug.*.log*
# Firebase cache
.firebase/
# Firebase config
# Uncomment this if you'd like others to create their own Firebase project.
# For a team working on the same Firebase project(s), it is recommended to leave
# it commented so all members can deploy to the same project(s) in .firebaserc.
# .firebaserc
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
+5
View File
@@ -0,0 +1,5 @@
{
"functions": {
"predeploy": []
}
}
+14
View File
@@ -0,0 +1,14 @@
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
extends: [
"eslint:recommended",
"google",
],
rules: {
quotes: ["error", "double"],
},
};
+1
View File
@@ -0,0 +1 @@
node_modules/
+37
View File
@@ -0,0 +1,37 @@
const {
RtcTokenBuilder,
RtmTokenBuilder,
RtcRole,
RtmRole,
} = require('agora-access-token');
function getAgoraToken(channelName) {
// 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;
}
module.exports = { getAgoraToken };
+23
View File
@@ -0,0 +1,23 @@
const functions = require('firebase-functions');
const admin = require('firebase-admin');
var express = require('express');
const app = express();
admin.initializeApp();
app.get('/', (req, res) => res.send('Hello World!'));
exports.helloworld = functions.https.onRequest(app);
const agora = require('./agora');
exports.agoraToken = functions.https.onCall((data, context) => {
console.log(data);
console.log("user's id: " + context.auth.uid);
const channelName = data.channelName;
let token = agora.getAgoraToken(channelName);
return { token };
});
+2670
View File
File diff suppressed because it is too large Load Diff
+28
View File
@@ -0,0 +1,28 @@
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint .",
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "16"
},
"main": "index.js",
"dependencies": {
"agora-access-token": "^2.0.4",
"express": "^4.17.2",
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1"
},
"devDependencies": {
"eslint": "^7.6.0",
"eslint-config-google": "^0.14.0",
"firebase-functions-test": "^0.2.0"
},
"private": true
}