v1.6.0/conference call upgrade
- anyone can start call - colision check for calls - better error handing for calls
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
const VoxeetSecret = require('../VoxeetSecret.json');
|
||||
const admin = require('firebase-admin');
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
const bodyData = JSON.parse(req.body);
|
||||
const { key, secret } = VoxeetSecret;
|
||||
const credentials = Buffer.from(encodeURI(key) + ':' + encodeURI(secret)).toString('base64');
|
||||
const headers = {
|
||||
@@ -14,8 +17,48 @@ module.exports = async (req, res) => {
|
||||
body: JSON.stringify({
|
||||
grant_type: 'client_credentials',
|
||||
}),
|
||||
})
|
||||
.then((oauthResponse) => oauthResponse.json())
|
||||
.catch((err) => res.status(500).send(err));
|
||||
if (oauth) res.status(200).send(oauth);
|
||||
}).then((oauthResponse) => oauthResponse.json())
|
||||
.catch((err) => res.status(500).send({err, message: 'Unable to generate token for call'}));
|
||||
|
||||
const [exists, conferencePending, conference, adminOnly, adminUid] = await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(req.params.partyName)
|
||||
.get()
|
||||
.then(snap => {
|
||||
const data = snap.exists ? snap.data() : {};
|
||||
return [snap.exists, data.conferencePending, data.conference, data.adminOnly, data.adminUid];
|
||||
});
|
||||
|
||||
if (exists === true) {
|
||||
if (conference === undefined || conference === null) {
|
||||
if (conferencePending === undefined || conferencePending === null) {
|
||||
if (!adminOnly || (adminOnly && (adminUid === bodyData.uid)) ) {
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(req.params.partyName)
|
||||
.update({
|
||||
conferencePending: bodyData.uid
|
||||
});
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(req.params.partyName)
|
||||
.collection('messages')
|
||||
.add({
|
||||
uid: '<system>',
|
||||
name: '',
|
||||
text: 'A call session is being created (will be available soon).',
|
||||
time: new Date(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (oauth) res.status(200).send(oauth);
|
||||
} else {
|
||||
res.status(400).send({ message: 'Unable to get party for call.' });
|
||||
}
|
||||
|
||||
return;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user