Skip to content

Commit

Permalink
实现了群视频通话和群聊详情,目前基本完善
Browse files Browse the repository at this point in the history
  • Loading branch information
OblivionTime committed Apr 23, 2023
1 parent a68b349 commit 70677ef
Show file tree
Hide file tree
Showing 30 changed files with 2,229 additions and 217 deletions.
44 changes: 35 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@



# <center>翎<center>
# 🎥项目演示地址
🔗[https://www.bilibili.com/video/BV1Fg4y1u76d/](https://www.bilibili.com/video/BV1Fg4y1u76d/)
Expand All @@ -25,6 +22,22 @@ flush privileges;
exit;
```
3. 使用连接工具尝试连接mysql数据库(navicat)

# docker生成的mysql8,后端无法连接成功,navicat能连接
![在这里插入图片描述](https://img-blog.csdnimg.cn/8eb821b5875d4b04a2d868530ca89e68.png)
### 问题分析
MySQL 8 默认情况下不允许使用旧的身份验证插件,而某些 Node.js MySQL 驱动程序(例如 mysql 模块)可能仍在使用这些插件。如果您遇到这个问题,可以在 MySQL 8 中启用旧的身份验证插件。您可以使用以下命令在 MySQL 8 中启用旧的身份验证插件:
### 解决方案
1. 进入到你的数据库
```shell
mysql -u root -p
```
2. 输入以下命令
```shell
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的密码';
flush privileges;
exit;
```
## 后端安装依赖出现问题(node-gyp)
![在这里插入图片描述](https://img-blog.csdnimg.cn/8aac61eee61a4a00b9b7451dbb4ab737.png)
### 问题分析
Expand All @@ -33,8 +46,8 @@ node-pty需要python依赖,这个只能根据错误去一个一个查找问题
错误可忽略,不影响程序运行

# 🧨项目目前存在的问题
* 如果在同一台电脑上,进行视频通话,是不成功的,因为会出现摄像头也被占用问题,但是语音通话是可以的
* 目前视频通话存在画质模糊问题(待修复)
* 目前视频通话存在画质模糊问题
* 如果想使用需要将chat.exe放在windows上运行
# 🥑已修复的bug
1. 文件下载出现了白屏
2. 聊天框没有置底
Expand All @@ -61,10 +74,8 @@ node-pty需要python依赖,这个只能根据错误去一个一个查找问题
* 集成`new bing`
* 群聊
* 修改好友备注
# 🎗️待完成功能
* 搜索好友和群聊
* 邀请好友进入群聊
* 群视频
* 共享屏幕
# 🖼️ 项目截图
![在这里插入图片描述](https://img-blog.csdnimg.cn/163aa1f40fc14711915900ff7df25ce0.png)
![在这里插入图片描述](https://img-blog.csdnimg.cn/515d30cb15194de3972bf838ec8c8b59.png)![在这里插入图片描述](https://img-blog.csdnimg.cn/ec92a4770c5642758c248c4b93ce7cc7.png)
Expand All @@ -73,6 +84,12 @@ node-pty需要python依赖,这个只能根据错误去一个一个查找问题
![在这里插入图片描述](https://img-blog.csdnimg.cn/76c65c9dd9f0417aab6a5de5bc0a92b1.png)
![在这里插入图片描述](https://img-blog.csdnimg.cn/0e93ab57d76e424e88d381c9d9db3cb8.png)

![在这里插入图片描述](https://img-blog.csdnimg.cn/c046fd41571746c29d1e2df22b493fb3.png)

![在这里插入图片描述](https://img-blog.csdnimg.cn/5cd9ce85876843cfa205620c44aedf11.png)
![在这里插入图片描述](https://img-blog.csdnimg.cn/bc8dcc804b774c1b96c4116ef05350d7.png)
![在这里插入图片描述](https://img-blog.csdnimg.cn/b17a50a8de884d51b82c6a9637e1cf18.png)

# 🤖如何在项目使用new bing
## 你必须要满足以下条件
1. 科学上网
Expand Down Expand Up @@ -338,7 +355,7 @@ git clone https://github.com/OblivionTime/chat.git
cd ui
yarn
#调试
yarn server
yarn serve
#打包
yarn build
```
Expand All @@ -363,3 +380,12 @@ yarn build
- 进入到**C:\Users\自己的用户名\AppData\Local\electron-builder\Cache\nsis**目录下,将**electron必须安装包**目录下分别解压成如下图所示的样子
![在这里插入图片描述](https://img-blog.csdnimg.cn/6d91296313c9490a9de1b58c0db6373e.png)
详细教程:[https://www.cnblogs.com/liliyou/p/13423709.html](https://www.cnblogs.com/liliyou/p/13423709.html)



# 结语


![在这里插入图片描述](https://img-blog.csdnimg.cn/e8be97b67c1b43a68add5c6c5944fbc9.jpeg)

![在这里插入图片描述](https://img-blog.csdnimg.cn/f297cd5a91cf4b73b8a377a1408a6776.jpeg)
16 changes: 16 additions & 0 deletions server/app/routes/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,25 @@ function authenticateToken(req, res, next) {
});
}
module.exports = function () {
//群聊列表
router.get('/list', authenticateToken, group.List)
//获取群聊中所有群员
router.get('/members_list', authenticateToken, group.MembersList)
//创建群聊
router.post('/create_group', authenticateToken, upload.single('avatar'), group.CreateGroupChat)
//搜索群聊
router.get('/search', authenticateToken, group.SearchGroupChat)
//加入群聊
router.get('/join', authenticateToken, group.JoinGroupChat)
//群聊信息
router.get('/info', authenticateToken, group.GroupInfo)
//重命名
router.post('/rename', authenticateToken, group.RenameGroup)
//邀请群聊
router.post('/invitation', authenticateToken, group.invitedUsersToGroup)
//退出群聊
router.post('/exitGroupChat', authenticateToken, group.DeleteUserFromGroup)
//获取音视频房间的所有用户
router.get('/getRTCUser', authenticateToken, group.GetRTCUser)
return router
}
1 change: 0 additions & 1 deletion server/app/routes/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ function authenticateToken(req, res, next) {
}
module.exports = function () {
router.get('/list', authenticateToken, message.List)

router.ws('/chat', message.ChatConnect)
return router
}
1 change: 1 addition & 0 deletions server/app/routes/rtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ const rtc = require("../../container/rtc/index")

module.exports = function () {
router.ws('/single',rtc.SingleRTCConnect)
router.ws('/group',rtc.groupRTCConnect)
return router
}
84 changes: 57 additions & 27 deletions server/container/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
};
const jwt = require('jsonwebtoken');
const secretKey = 'xWbiNA3FqnK77MnVCj5CAcfA-VlXj7xoQLd1QaAme6l_t0Yp1TdHbSw';
let rooms = {}
let codeRooms = {}
let { RespUserOrPassErr, RespParamErr, RespServerErr, RespUserExitErr, RespUpdateErr, RespUserNotExitErr } = require('../../model/error');
const { RespData, RespSuccess } = require('../../model/resp');
const { Query } = require('../../db/query');
Expand Down Expand Up @@ -189,18 +189,18 @@ function LoginCode(ws, req) {
let room = params.get("room")
let name = params.get("name")
if (name == 'device') {
rooms[room] = {}
rooms[room][name] = ws
} else if (rooms[room] && name == 'user') {
rooms[room][name] = ws
codeRooms[room] = {}
codeRooms[room][name] = ws
} else if (codeRooms[room] && name == 'user') {
codeRooms[room][name] = ws
} else {
ws.close()
}
ws.on('message', function (Resp_data) {
let data = JSON.parse(Resp_data)
if (name == 'user') {
if (data.operation == "connect") {
rooms[room]['device'].send(JSON.stringify(data))
codeRooms[room]['device'].send(JSON.stringify(data))
} else if (data.operation == "login") {
let username = data.username
const sql = 'select * from user where username=?'
Expand All @@ -224,26 +224,26 @@ function LoginCode(ws, req) {
phone: results[0].phone,
}
}
rooms[room]['device'].send(JSON.stringify(data))
codeRooms[room]['device'].send(JSON.stringify(data))
} else {
ws.send(JSON.stringify({ operation: "error", error: "登录失败" }))
}
})
}
} else {
rooms[room]['user'].send(Resp_data)
codeRooms[room]['user'].send(Resp_data)
}
});
ws.on('close', function () {
if (name == 'device') {
delete rooms[room][name]
for (const key in rooms[room]) {
rooms[room][key].close()
delete codeRooms[room][name]
for (const key in codeRooms[room]) {
codeRooms[room][key].close()
}
delete rooms[room]
delete codeRooms[room]
} else {
if (rooms[room]) {
delete rooms[room][name]
if (codeRooms[room]) {
delete codeRooms[room][name]
}
}
})
Expand Down Expand Up @@ -275,15 +275,16 @@ function initUserNotification(ws, req) {
let url = req.url.split("?")[1];
let params = new URLSearchParams(url)
let username = params.get("username")
//音视频状态,用户
var status = false
//如果用户已经登录则强制退出当前用户
if (LoginRooms[username]) {
LoginRooms[username].send(JSON.stringify({ name: "logout" }))
LoginRooms[username].close()
// if (LoginRooms[username]) {
// LoginRooms[username].send(JSON.stringify({ name: "logout" }))
// LoginRooms[username].close()
// }
LoginRooms[username] = {
ws: ws,
status: false,
}
LoginRooms[username] = ws
ws.on('message', function (Resp_data) {
ws.on('message', async (Resp_data) => {
let data = JSON.parse(Resp_data)
//接收者
let receiver_username = data.receiver_username
Expand All @@ -292,30 +293,59 @@ function initUserNotification(ws, req) {
ws.send(JSON.stringify({ name: "reject", message: "对方当前不在线!!!" }))
return
}
if (LoginRooms[receiver_username].status) {
ws.send(JSON.stringify({ name: "reject", message: "对方正在通话中!!!" }))
return
}
//当用户已经在音视频通话了则需要告知发送方
if (status) {
if (LoginRooms[username].status) {
ws.send(JSON.stringify({ name: "reject", message: "你正在通话中,请勿发送其他通话请求...." }))
return
} else {
status = true
}
LoginRooms[username].status = true
//对方在线
if (LoginRooms[receiver_username]) {
LoginRooms[receiver_username].send(Resp_data)
LoginRooms[receiver_username].ws.send(Resp_data)
data.method = data.name
data.name = 'peer'
ws.send(JSON.stringify(data))
return
}
} else if (data.name == 'group_audio' || data.name == 'group_video') {
if (LoginRooms[username].status || (group_rooms[data.room] && Object.keys(group_rooms[data.room]).length != 0)) {
ws.send(JSON.stringify({ name: "reject", message: "无法创建群音视频...." }))
return
}
/**
* 群视频逻辑处理
*
*/
group_rooms[data.room] = {}
group_rooms[data.room][username] = ""
LoginRooms[username].status = true
for (const user of data.userList) {
if (user == data.sender_name) {
continue
}
//对方在线且并未通话
if (LoginRooms[user] && !LoginRooms[user].status) {
group_rooms[data.room][user] = ""
LoginRooms[user].ws.send(Resp_data)
}
}
data.method = data.name
data.name = 'group_peer'
ws.send(JSON.stringify(data))
return
}
//拒绝通话
if (data.name == 'reject') {
status = false
LoginRooms[username].status = false
return
}
//对方在线
if (LoginRooms[receiver_username]) {
LoginRooms[receiver_username].send(Resp_data)
LoginRooms[receiver_username].ws.send(Resp_data)
}
});
ws.on('close', function () {
Expand Down
8 changes: 4 additions & 4 deletions server/container/bing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ let { RespUserOrPassErr, RespParamErr, RespServerErr, RespUserExitErr, RespUpdat
const { Query } = require('../../db/query');
const { getConversation } = require('../../utils/newBing');
const { v4: uuidv4 } = require('uuid');
let rooms = {}
let bing_rooms = {}
/**
* 生成Conversation
* 1.获取当前登录的用户名,并获取到前端传来的代理服务器地址
Expand Down Expand Up @@ -104,7 +104,7 @@ async function BingConnect(ws, req) {
let url = req.url.split("?")[1];
let params = new URLSearchParams(url)
let room = params.get("room")
rooms[room] = ws
bing_rooms[room] = ws
//获取所有聊天记录
let sql = 'SELECT m.*,u.avatar FROM (SELECT sender_id, receiver_id, content, room, link_list,ai_message.created_at,invocation_id FROM ai_message WHERE `room` =? ORDER BY created_at ASC) AS m LEFT JOIN user as u ON u.`id`=m.`sender_id`'
let { err, results } = await Query(sql, [room])
Expand Down Expand Up @@ -133,8 +133,8 @@ async function BingConnect(ws, req) {
sql = `update ai_conversation set count=? where conversation_id=? and conversation_signature=?`
await Query(sql, [message.numUserMessagesInConversation, message.conversation_id, message.conversation_signature])
if (message.numUserMessagesInConversation == 20) {
if (rooms[room]) {
rooms[room].send(JSON.stringify({ "name": "reset" }))
if (bing_rooms[room]) {
bing_rooms[room].send(JSON.stringify({ "name": "reset" }))
}
}
return
Expand Down
10 changes: 8 additions & 2 deletions server/container/friend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,13 @@ async function AddFriend(req, res) {
await Query(sql, { room: uuid, total: 1 })
//通知对方,让其好友列表进行更新
NotificationUser({ receiver_username: username, name: "friend" })
return RespSuccess(res)
let options = {
room: uuid,
user_id: usr2.results[0].user_id,
name: username,
receiver_name: username
}
return RespData(res,options)
}
/**
* 查询用户
Expand Down Expand Up @@ -258,7 +264,7 @@ async function getFriendGroupList(req, res) {
RespData(res, results)
}
/**
* 修改好友分组
* 重命名好友分组
*/
async function updateFriendGroup(req, res) {
const { name, user_id, old_name } = req.body
Expand Down
Loading

0 comments on commit 70677ef

Please sign in to comment.