Browse Source

work on call

unknown 1 year ago
parent
commit
5e2f73db2a
3 changed files with 44 additions and 0 deletions
  1. 27 0
      controllers/chats.js
  2. 16 0
      model/schemas/chat.js
  3. 1 0
      routes/chats.js

+ 27 - 0
controllers/chats.js

@@ -170,6 +170,32 @@ const muteChat = async (req, res, next) => {
 	}
 };
 
+const mediaControllersChat = async (req, res, next) => {
+	try {
+		const { companionId, mutedMyVideo, mutedMyAudio } = req.body;
+		const userId = req.user.id;
+		const isChat = await ChatModel.getByField(companionId, userId);
+		const isCompanionChat = await ChatModel.getByField(companionId, userId);
+		if (isChat && isCompanionChat) {
+			await ChatModel.update(isChat._id, userId, {
+				mutedMyVideo,
+				mutedMyAudio,
+			});
+			await ChatModel.update(isCompanionChat._id, companionId, {
+				companionMutedVideo: mutedMyVideo,
+				companionMutedAudio: mutedMyAudio,
+			});
+			return res.status(200).json({
+				status: 'success',
+				code: 200,
+				data: {},
+			});
+		}
+	} catch (e) {
+		next(e);
+	}
+};
+
 const sortChat = async (req, res, next) => {
 	try {
 		const id = req.body.id;
@@ -292,6 +318,7 @@ module.exports = {
 	startChat,
 	removeChatForBoth,
 	muteChat,
+	mediaControllersChat,
 	sortChat,
 	socketIdChat,
 	seenChat,

+ 16 - 0
model/schemas/chat.js

@@ -95,6 +95,22 @@ const chatSchema = new Schema(
 			type: String,
 			default: false,
 		},
+		mutedMyVideo: {
+			type: Boolean,
+			default: true,
+		},
+		mutedMyAudio: {
+			type: Boolean,
+			default: false,
+		},
+		companionMutedVideo: {
+			type: Boolean,
+			default: true,
+		},
+		companionMutedAudio: {
+			type: Boolean,
+			default: false,
+		},
 		owner: {
 			type: SchemaTypes.ObjectId,
 			ref: 'user',

+ 1 - 0
routes/chats.js

@@ -9,6 +9,7 @@ router
 	.get('/:companionId', guard, controllers.getChatById)
 	.post('/', guard, validation.startChat, controllers.startChat)
 	.patch('/mute/', guard, controllers.muteChat)
+	.patch('/controllers/', guard, controllers.mediaControllersChat)
 	.patch('/socketId/', guard, controllers.socketIdChat)
 	.patch('/sort/', guard, controllers.sortChat)
 	.patch('/seen/', guard, controllers.seenChat)