|
|
|
@ -26,6 +26,7 @@ namespace _24Hour.Controllers.Common
|
|
|
|
|
private readonly IConfiguration _configuration; |
|
|
|
|
Result result = new Result(); |
|
|
|
|
private static Dictionary<string, WebSocket> CONNECT_POOL = new Dictionary<string, WebSocket>();//用户连接池 |
|
|
|
|
private static Dictionary<string, WebSocketSending> meeting_pool = new Dictionary<string, WebSocketSending>();//会议连接池 |
|
|
|
|
//private static Dictionary<string, List<MessageInfo>> MESSAGE_POOL = new Dictionary<string, List<MessageInfo>>();//离线消息池 |
|
|
|
|
public WebSocketController(ILogger<LoginController> logger, SqlSugarClient db,User userdata,IConfiguration configuration) |
|
|
|
|
{ |
|
|
|
@ -74,6 +75,10 @@ namespace _24Hour.Controllers.Common
|
|
|
|
|
if (result.MessageType == WebSocketMessageType.Close) |
|
|
|
|
{ |
|
|
|
|
await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None); |
|
|
|
|
if (meeting_pool.ContainsKey(user)) meeting_pool.Remove(user);//删除会议 |
|
|
|
|
if (CONNECT_POOL.ContainsKey(user)) CONNECT_POOL.Remove(user);//删除socket |
|
|
|
|
socket.Dispose(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
@ -257,9 +262,10 @@ namespace _24Hour.Controllers.Common
|
|
|
|
|
if (socket.State != WebSocketState.Open)//连接关闭 |
|
|
|
|
{ |
|
|
|
|
if (CONNECT_POOL.ContainsKey(_userdata.Id)) CONNECT_POOL.Remove(_userdata.Id);//删除连接池 |
|
|
|
|
result.IsSucceed = true; |
|
|
|
|
result.result = "未上线"; |
|
|
|
|
return result; |
|
|
|
|
if (meeting_pool.ContainsKey(_userdata.Id)) meeting_pool.Remove(_userdata.Id);//删除会议 |
|
|
|
|
//result.IsSucceed = true; |
|
|
|
|
//result.result = "未上线"; |
|
|
|
|
//return result; |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
@ -269,9 +275,7 @@ namespace _24Hour.Controllers.Common
|
|
|
|
|
if (Senddata.typenum == "1" && Senddata.deviceno != "") |
|
|
|
|
{ |
|
|
|
|
//设备发送给app |
|
|
|
|
//查询远程会见记录 |
|
|
|
|
var Devicedata = await _db.Queryable<App_DeviceModel>().Where(q => q.deviceno == Senddata.deviceno).ToListAsync(); |
|
|
|
|
Senddata.content = $"{_configuration.GetSection("Videoaddress:rtsp").Value}{Devicedata.FirstOrDefault()?.deviceno}"; |
|
|
|
|
Senddata.content = $"{_configuration.GetSection("Videoaddress:rtsp").Value}{Senddata.deviceno}"; |
|
|
|
|
//对象序列化 |
|
|
|
|
content = JsonConvert.SerializeObject(Senddata); |
|
|
|
|
buffer = new ArraySegment<byte>(Encoding.UTF8.GetBytes(content)); |
|
|
|
@ -291,19 +295,31 @@ namespace _24Hour.Controllers.Common
|
|
|
|
|
WebSocket destSocket = CONNECT_POOL[Senddata.recipient]; |
|
|
|
|
//判断客户端是否连接 |
|
|
|
|
if (destSocket != null && destSocket.State == WebSocketState.Open) |
|
|
|
|
await socket.SendAsync(buffer, WebSocketMessageType.Text, true, CancellationToken.None); |
|
|
|
|
{ |
|
|
|
|
if (meeting_pool.ContainsKey(Senddata.recipient)) |
|
|
|
|
{ |
|
|
|
|
// |
|
|
|
|
var data = meeting_pool[Senddata.recipient]; |
|
|
|
|
//当前用户消息对象序列化 |
|
|
|
|
var dqcontent = JsonConvert.SerializeObject(data); |
|
|
|
|
var dqbuffer = new ArraySegment<byte>(Encoding.UTF8.GetBytes(dqcontent)); |
|
|
|
|
//当前用户socket发送 |
|
|
|
|
await socket.SendAsync(dqbuffer, WebSocketMessageType.Text, true, CancellationToken.None); |
|
|
|
|
} |
|
|
|
|
//目的客户端发送 |
|
|
|
|
await destSocket.SendAsync(buffer, WebSocketMessageType.Text, true, CancellationToken.None); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
result.IsSucceed = false; |
|
|
|
|
result.result = "用户未上线"; |
|
|
|
|
return result; |
|
|
|
|
meeting_pool.Add(_userdata.Id, Senddata); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
result.IsSucceed = false; |
|
|
|
|
result.result = "用户未上线"; |
|
|
|
|
return result; |
|
|
|
|
meeting_pool.Add(_userdata.Id, Senddata); |
|
|
|
|
//result.IsSucceed = false; |
|
|
|
|
//result.result = "用户未上线"; |
|
|
|
|
//return result; |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
} |
|
|
|
@ -326,6 +342,22 @@ namespace _24Hour.Controllers.Common
|
|
|
|
|
result.result = ""; |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 推出会议 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="Sendingdata"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[HttpPost] |
|
|
|
|
[Route("close")] |
|
|
|
|
public async Task<Result> close() |
|
|
|
|
{ |
|
|
|
|
if (meeting_pool.ContainsKey(_userdata.Id)) meeting_pool.Remove(_userdata.Id);//删除会议 |
|
|
|
|
result.IsSucceed = true; |
|
|
|
|
result.result = ""; |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
@ -338,6 +370,7 @@ namespace _24Hour.Controllers.Common
|
|
|
|
|
/// </summary> |
|
|
|
|
[DataMember] |
|
|
|
|
public string? sender { get; set; } |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 发送内容 |
|
|
|
|
/// </summary> |
|
|
|
|