优化进入频道消息提示
This commit is contained in:
parent
4824180441
commit
481009985e
|
|
@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
using SharpCompress;
|
using SharpCompress;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using WGShare.API.Controllers.Basic;
|
using WGShare.API.Controllers.Basic;
|
||||||
|
|
@ -32,15 +33,21 @@ namespace WGShare.API.Controllers.Frontend
|
||||||
private readonly ILogger<AgoraCallbackController> _logger;
|
private readonly ILogger<AgoraCallbackController> _logger;
|
||||||
private readonly AgoraHelper _agoraHelper;
|
private readonly AgoraHelper _agoraHelper;
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
|
private readonly ISqlSugarClient _sqlSugarClient;
|
||||||
|
private readonly IHostEnvironment _hostEnvironment;
|
||||||
|
|
||||||
public AgoraCallbackController(
|
public AgoraCallbackController(
|
||||||
ILogger<AgoraCallbackController> logger,
|
ILogger<AgoraCallbackController> logger,
|
||||||
AgoraHelper agoraHelper,
|
AgoraHelper agoraHelper,
|
||||||
IConfiguration configuration)
|
IConfiguration configuration,
|
||||||
|
ISqlSugarClient sqlSugarClient,
|
||||||
|
IHostEnvironment hostEnvironment)
|
||||||
{
|
{
|
||||||
this._logger = logger;
|
this._logger = logger;
|
||||||
this._agoraHelper = agoraHelper;
|
this._agoraHelper = agoraHelper;
|
||||||
this._configuration = configuration;
|
this._configuration = configuration;
|
||||||
|
this._sqlSugarClient = sqlSugarClient;
|
||||||
|
this._hostEnvironment = hostEnvironment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -84,9 +91,10 @@ namespace WGShare.API.Controllers.Frontend
|
||||||
switch (body.eventType)
|
switch (body.eventType)
|
||||||
{
|
{
|
||||||
case Domain.Enums.EventType.channel_create:
|
case Domain.Enums.EventType.channel_create:
|
||||||
CreateChannel(body);
|
await CreateChannel(body);
|
||||||
break;
|
break;
|
||||||
case Domain.Enums.EventType.channel_destroy:
|
case Domain.Enums.EventType.channel_destroy:
|
||||||
|
await DestroyChannel(body);
|
||||||
break;
|
break;
|
||||||
case Domain.Enums.EventType.broadcaster_join_channel:
|
case Domain.Enums.EventType.broadcaster_join_channel:
|
||||||
case Domain.Enums.EventType.audience_join_channel:
|
case Domain.Enums.EventType.audience_join_channel:
|
||||||
|
|
@ -130,11 +138,34 @@ namespace WGShare.API.Controllers.Frontend
|
||||||
RedisHelper.Instance.LPush(RedisKeyConstant.PubSub.MeetingRecord, bodyString);
|
RedisHelper.Instance.LPush(RedisKeyConstant.PubSub.MeetingRecord, bodyString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static List<string> excludeChannel = new();
|
||||||
|
static ConcurrentDictionary<string, int> existsChannel = new();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建频道
|
/// 创建频道
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[NonAction]
|
[NonAction]
|
||||||
private void CreateChannel(EventBody eventBody)
|
private async Task CreateChannel(EventBody eventBody)
|
||||||
|
{
|
||||||
|
if (_hostEnvironment.IsDevelopment())
|
||||||
|
{
|
||||||
|
_logger.LogDebug($"测试环境不通知创建频道");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (excludeChannel.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
// 缓存测试区域房间
|
||||||
|
excludeChannel = await _sqlSugarClient.Queryable<Room>().Where(x => x.TenantId == "559167236182085")
|
||||||
|
.Select(x => x.RoomNum).ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (excludeChannel.Any(x => x == eventBody.payload.channelName))
|
||||||
|
{
|
||||||
|
_logger.LogDebug($"正式环境的测试区域不通知创建频道");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(existsChannel.TryAdd(eventBody.payload.channelName, 0))
|
||||||
{
|
{
|
||||||
ExceptionNotice.JoinAsync(eventBody);
|
ExceptionNotice.JoinAsync(eventBody);
|
||||||
}
|
}
|
||||||
|
|
@ -142,4 +173,19 @@ namespace WGShare.API.Controllers.Frontend
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 销毁频道
|
||||||
|
/// </summary>
|
||||||
|
[NonAction]
|
||||||
|
private async Task DestroyChannel(EventBody eventBody)
|
||||||
|
{
|
||||||
|
if (_hostEnvironment.IsDevelopment())
|
||||||
|
return;
|
||||||
|
existsChannel.TryRemove(eventBody.payload.channelName, out _);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,11 @@
|
||||||
创建频道
|
创建频道
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:WGShare.API.Controllers.Frontend.AgoraCallbackController.DestroyChannel(WGShare.Domain.DTOs.AgoraCallback.EventBody)">
|
||||||
|
<summary>
|
||||||
|
销毁频道
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="T:WGShare.API.Controllers.Frontend.HomeController">
|
<member name="T:WGShare.API.Controllers.Frontend.HomeController">
|
||||||
<summary>
|
<summary>
|
||||||
首页接口
|
首页接口
|
||||||
|
|
|
||||||
|
|
@ -43,13 +43,33 @@ namespace WGShare.Domain.FriendlyException
|
||||||
|
|
||||||
public static async Task JoinAsync(EventBody eventBody)
|
public static async Task JoinAsync(EventBody eventBody)
|
||||||
{
|
{
|
||||||
|
// 获取当前的日期
|
||||||
|
DateTime today = DateTime.Today;
|
||||||
|
|
||||||
|
// 定义东八区的时区信息
|
||||||
|
TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("China Standard Time");
|
||||||
|
|
||||||
|
// 创建东八区今天00:00:01的DateTime对象
|
||||||
|
DateTime startOfDayLocal = new DateTime(today.Year, today.Month, today.Day, 0, 0, 1, DateTimeKind.Unspecified);
|
||||||
|
|
||||||
|
// 创建东八区今天23:59:00的DateTime对象
|
||||||
|
DateTime endOfDayLocal = new DateTime(today.Year, today.Month, today.Day, 23, 59, 0, DateTimeKind.Unspecified);
|
||||||
|
|
||||||
|
// 将时间转换为UTC
|
||||||
|
DateTimeOffset startOfDayUtc = TimeZoneInfo.ConvertTimeToUtc(startOfDayLocal, timeZoneInfo);
|
||||||
|
DateTimeOffset endOfDayUtc = TimeZoneInfo.ConvertTimeToUtc(endOfDayLocal, timeZoneInfo);
|
||||||
|
|
||||||
|
// 获取Unix时间戳(秒)
|
||||||
|
long startTimestamp = startOfDayUtc.ToUnixTimeSeconds();
|
||||||
|
long endTimestamp = endOfDayUtc.ToUnixTimeSeconds();
|
||||||
|
|
||||||
var reponse = await httpClient.PostAsync(string.Empty, JsonContent.Create(new
|
var reponse = await httpClient.PostAsync(string.Empty, JsonContent.Create(new
|
||||||
{
|
{
|
||||||
msgtype = "markdown",
|
msgtype = "markdown",
|
||||||
markdown = new
|
markdown = new
|
||||||
{
|
{
|
||||||
title = "有人入会通知",
|
title = "有人入会通知",
|
||||||
text = $"有人进入会议室了,会议号:{eventBody.payload.channelName},点击查看:https://analytics-lab.agora.io/analytics/call/search?projectId=0tOpVUrmf"
|
text = $"有人进入会议室了,会议号:{eventBody.payload.channelName},点击查看:https://analytics-lab.agora.io/analytics/call/search?projectId=0tOpVUrmf&fromTs={startTimestamp}&toTs={endTimestamp}"
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue