|
@@ -2,6 +2,7 @@ const express = require('express');
|
|
|
const app = express();
|
|
|
const http = require('http');
|
|
|
const { Server } = require('socket.io');
|
|
|
+const ChatModel = require('./model/chat');
|
|
|
const cors = require('cors');
|
|
|
const logger = require('morgan');
|
|
|
const helmet = require('helmet');
|
|
@@ -21,11 +22,23 @@ const io = new Server(server, {
|
|
|
});
|
|
|
|
|
|
io.on('connection', (socket) => {
|
|
|
- console.log('connect', socket.id);
|
|
|
+ console.log(socket.id);
|
|
|
socket.emit('me', socket.id);
|
|
|
- socket.on('call', ({ userToCall, signalData, from, name }) => {
|
|
|
- io.to(userToCall).emit('call', { signal: signalData, from, name });
|
|
|
- });
|
|
|
+ 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 });
|
|
|
});
|