v1.6.0/speculative fix for call conflict
This commit is contained in:
@@ -1,16 +1,23 @@
|
||||
const admin = require('firebase-admin');
|
||||
const admin = require("firebase-admin");
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
const { conference, partyName, partyPin, userName, uid } = JSON.parse(req.body);
|
||||
const { conference, partyName, partyPin, userName, uid } = JSON.parse(
|
||||
req.body
|
||||
);
|
||||
// GET ROOM PIN
|
||||
const [exists, roomPin, conferencePending, partyConference] = await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.collection("rooms")
|
||||
.doc(partyName)
|
||||
.get()
|
||||
.then((roomSnap) => {
|
||||
const data = roomSnap.exists ? roomSnap.data() : {};
|
||||
return [roomSnap.exists, data.pin, data.conferencePending, data.conference];
|
||||
return [
|
||||
roomSnap.exists,
|
||||
data.pin,
|
||||
data.conferencePending,
|
||||
data.conference,
|
||||
];
|
||||
});
|
||||
// CHECK IF ROOM EXISTS
|
||||
if (exists === true) {
|
||||
@@ -22,47 +29,61 @@ module.exports = async (req, res) => {
|
||||
// UPDATE CONFERENCE DETAILS
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.collection("rooms")
|
||||
.doc(partyName)
|
||||
.update({ conference })
|
||||
.catch((err) =>
|
||||
res.status(500).send({ message: 'Unable to update the call details', error: err })
|
||||
res.status(500).send({
|
||||
message: "Unable to update the call details",
|
||||
error: err,
|
||||
})
|
||||
);
|
||||
// REMOVE PENDING STATUS
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(partyName)
|
||||
.update({ conferencePending : admin.firestore.FieldValue.delete() })
|
||||
.catch((err) => console.error('Failed to remove pending status', err));
|
||||
.firestore()
|
||||
.collection("rooms")
|
||||
.doc(partyName)
|
||||
.update({
|
||||
conferencePending: admin.firestore.FieldValue.delete(),
|
||||
})
|
||||
.catch((err) =>
|
||||
console.error("Failed to remove pending status", err)
|
||||
);
|
||||
// ADD SYSTEM MESSAGE
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.collection("rooms")
|
||||
.doc(partyName)
|
||||
.collection('messages')
|
||||
.collection("messages")
|
||||
.add({
|
||||
uid: '<system>',
|
||||
name: '',
|
||||
uid: "<system>",
|
||||
name: "",
|
||||
text: `${userName} started the call, everyone can join now.`,
|
||||
time: new Date(),
|
||||
})
|
||||
.catch((err) => console.error('Failed to add update conference message', err));
|
||||
res.status(200).send({ message: 'Started the conference' });
|
||||
.catch((err) =>
|
||||
console.error("Failed to add update conference message", err)
|
||||
);
|
||||
res.status(200).send({ message: "Started the conference" });
|
||||
} else {
|
||||
res.status(409).send({ message: 'Looks like someone is already starting a call' });
|
||||
res.status(409).send({
|
||||
message: "Looks like someone is already starting a call",
|
||||
});
|
||||
}
|
||||
} else if (partyConference) {
|
||||
res.status(409).send({ message: 'Call already exists', conference: partyConference });
|
||||
res.status(409).send({
|
||||
message: "Call already exists",
|
||||
conference: partyConference,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// WRONG ROOM PIN
|
||||
res.status(401).send({ message: 'Wrong party pin, try rejoining' });
|
||||
res.status(401).send({ message: "Wrong party pin, try rejoining" });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// ROOM DOESN'T EXIST
|
||||
res.status(404).send({ message: 'Party Not Found' });
|
||||
res.status(404).send({ message: "Party Not Found" });
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -1,30 +1,70 @@
|
||||
const admin = require('firebase-admin');
|
||||
const admin = require("firebase-admin");
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
console.info(`[START]\tWEBHOOKS/Conference End\nID:${req.body.conference.confId}\nParty:${req.body.conference.confAlias}`);
|
||||
if (req.body.eventType === 'Conference.Ended') {
|
||||
console.info(
|
||||
`[START]\tWEBHOOKS/Conference End\tID:${req.body.conference.confId}\tParty:${req.body.conference.confAlias}`
|
||||
);
|
||||
// MAKE SURE CORRECT EVENT TYPE
|
||||
if (req.body.eventType === "Conference.Ended") {
|
||||
// MAKE SURE IT'S NOT A DUPLICATE FROM CREATE CONFLICT
|
||||
if (req.body.participants.length > 0) {
|
||||
if (req.body.confAlias.startsWith('AUTODELETE_')) {
|
||||
// MAKE SURE ELIGIBLE FOR DELETE
|
||||
if (req.body.confAlias.startsWith("AUTODELETE_")) {
|
||||
const partyName = req.body.confAlias.replace(/AUTODELETE_/, "");
|
||||
admin.firestore()
|
||||
.collection('rooms')
|
||||
.doc(partyName)
|
||||
.update({ conference: admin.firestore.FieldValue.delete() })
|
||||
.then(() => {
|
||||
console.info(`[DONE]\tWEBHOOKS/Conference End\nID:${req.body.conference.confId}\nParty:${req.body.conference.confAlias}`);
|
||||
return;
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(`[ERROR]\tWEBHOOKS/Conference End/Firebase Error\nID:${req.body.conference.confId}\nParty:${req.body.conference.confAlias}\nError:${JSON.stringify(err)}`)
|
||||
});
|
||||
res.status(200).send({ message: 'Processed conference end'});
|
||||
const existingConference = await admin
|
||||
.firestore()
|
||||
.collection("rooms")
|
||||
.doc(partyName)
|
||||
.get()
|
||||
.then((snap) => (snap.exists ? snap.data().conference : null));
|
||||
// MAKE SURE EXISTS AND HAS NOT BEEN REPLACED
|
||||
if (
|
||||
existingConference &&
|
||||
existingConference._id === req.body.conference.confId
|
||||
) {
|
||||
// REMOVE CONFERENCE DETAILS
|
||||
await admin
|
||||
.firestore()
|
||||
.collection("rooms")
|
||||
.doc(partyName)
|
||||
.update({ conference: admin.firestore.FieldValue.delete() })
|
||||
.then(() => {
|
||||
console.info(
|
||||
`[DONE]\tWEBHOOKS/Conference End\tID:${req.body.conference.confId}\tParty:${req.body.conference.confAlias}`
|
||||
);
|
||||
return;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(
|
||||
`[ERROR]\tWEBHOOKS/Conference End/Firebase Error\tID:${
|
||||
req.body.conference.confId
|
||||
}\tParty:${
|
||||
req.body.conference.confAlias
|
||||
}\tError:${JSON.stringify(err)}`
|
||||
);
|
||||
});
|
||||
} else {
|
||||
console.info(
|
||||
`[DONE]\tWEBHOOKS/Conference End/Conference Was Already Replaced\tID:${req.body.conference.confId}\tParty:${req.body.conference.confAlias}`
|
||||
);
|
||||
}
|
||||
res.status(200).send({ message: "Processed conference end" });
|
||||
} else {
|
||||
console.info(
|
||||
`[DONE]\tWEBHOOKS/Conference End/Not Eligible For Autodelete\tID:${req.body.conference.confId}\tParty:${req.body.conference.confAlias}`
|
||||
);
|
||||
res.status(200).send({ message: "Processed conference end" });
|
||||
}
|
||||
} else {
|
||||
console.info(`[DONE]\tWEBHOOKS/Conference End/End Of Duplicate Conference\nID:${req.body.conference.confId}\nParty:${req.body.conference.confAlias}`);
|
||||
console.info(
|
||||
`[DONE]\tWEBHOOKS/Conference End/End Of Duplicate Conference\tID:${req.body.conference.confId}\tParty:${req.body.conference.confAlias}`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
console.error(`[ERROR]\tWEBHOOKS/Conference End/Wrong Event Type\nID:${req.body.conference.confId}\nParty:${req.body.conference.confAlias}`)
|
||||
res.status(400).send({ message: 'Wrong event type' });
|
||||
console.error(
|
||||
`[ERROR]\tWEBHOOKS/Conference End/Wrong Event Type\tID:${req.body.conference.confId}\tParty:${req.body.conference.confAlias}`
|
||||
);
|
||||
res.status(400).send({ message: "Wrong event type" });
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user