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

add opentok code examples #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions firebase/JavaScript/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const admin = require('firebase-admin');
admin.initializeApp();

exports.messaging = require('./messaging');
exports.opentok = require('./opentok');
exports.sms = require('./sms');
exports.voice = require('./voice');
exports.verify = require('./verify');
Expand Down
1 change: 1 addition & 0 deletions firebase/JavaScript/functions/opentok/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.session = require('./session');
27 changes: 27 additions & 0 deletions firebase/JavaScript/functions/opentok/session.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const OpenTok = require('opentok');

const {
api_key,
api_secret,
} = functions.config().opentok;

const opentok = new OpenTok(api_key, api_secret);

let db = admin.firestore();

function createSession(opts = {}) {
return new Promise((resolve, reject) => {
opentok.createSession(opts, (err, res) => {
if (err) reject(err);
resolve(res);
});
});
}

exports.method = functions.https.create(async (req, res) => {
let session = await createSession();
let ref = await db.collection('opentok-sessions').add(session);
res.send(200).send({sessionRef: ref.id});
});
Loading