|
@@ -24,23 +24,21 @@ const io = new Server(server, {
|
|
io.on('connection', (socket) => {
|
|
io.on('connection', (socket) => {
|
|
console.log(socket.id);
|
|
console.log(socket.id);
|
|
socket.emit('me', socket.id);
|
|
socket.emit('me', socket.id);
|
|
- socket.on(
|
|
|
|
- 'call',
|
|
|
|
- async ({ socketId, signalData, from, userId, companionId }) => {
|
|
|
|
- const { name, lastName } = await ChatModel.getByField(
|
|
|
|
- userId,
|
|
|
|
- companionId
|
|
|
|
- );
|
|
|
|
- io.to(socketId).emit('call', {
|
|
|
|
- signal: signalData,
|
|
|
|
- from,
|
|
|
|
- name,
|
|
|
|
- lastName,
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- );
|
|
|
|
- socket.on('answer', (data) => {
|
|
|
|
- io.to(data.to).emit('accepted', { signal: data.signal });
|
|
|
|
|
|
+ socket.on('callTo', async ({ to, signalData, from, userId, companionId }) => {
|
|
|
|
+ const { name, lastName, color, avatarUrl, number } =
|
|
|
|
+ await ChatModel.getByField(userId, companionId);
|
|
|
|
+ io.to(to).emit('incomeCall', {
|
|
|
|
+ signal: signalData,
|
|
|
|
+ from,
|
|
|
|
+ name,
|
|
|
|
+ lastName,
|
|
|
|
+ color,
|
|
|
|
+ avatarUrl,
|
|
|
|
+ number,
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ socket.on('answerCall', (data) => {
|
|
|
|
+ io.to(data.to).emit('acceptedCall', { signal: data.signal });
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
|