feat: 接口加白与联通性校验特殊处理

pull/64/head
moonrailgun 2 years ago
parent 56387371ab
commit f8a73d1a77

@ -100,6 +100,8 @@ class AgoraService extends TcService {
payload: 'any', payload: 'any',
}, },
}); });
this.registerAuthWhitelist(['/webhook']);
} }
generateJoinInfo( generateJoinInfo(
@ -176,16 +178,25 @@ class AgoraService extends TcService {
}> }>
) { ) {
const { eventType, payload } = ctx.params; const { eventType, payload } = ctx.params;
const channelName = payload.channelName;
this.logger.info('webhook received', { eventType, payload });
if (channelName === 'test_webhook') {
// 连通性检查
return true;
}
if (eventType === 101) { if (eventType === 101) {
// 频道被创建 // 频道被创建
const { channelName } = payload; const ts = payload.ts;
const converseId = this.getConverseIdFromChannelName(channelName); const converseId = this.getConverseIdFromChannelName(channelName);
const meeting = await this.adapter.model.create({ const meeting = await this.adapter.model.create({
channelName, channelName,
converseId, converseId,
active: true, active: true,
createdAt: new Date(ts),
}); });
this.roomcastNotify(ctx, converseId, 'agoraChannelCreate', { this.roomcastNotify(ctx, converseId, 'agoraChannelCreate', {
converseId, converseId,
@ -193,7 +204,8 @@ class AgoraService extends TcService {
}); });
} else if (eventType === 102) { } else if (eventType === 102) {
// 频道被销毁 // 频道被销毁
const { channelName } = payload; const ts = payload.ts;
const converseId = this.getConverseIdFromChannelName(channelName); const converseId = this.getConverseIdFromChannelName(channelName);
const meeting = await this.adapter.model.findLastestMeetingByConverseId( const meeting = await this.adapter.model.findLastestMeetingByConverseId(
@ -204,6 +216,7 @@ class AgoraService extends TcService {
} }
meeting.active = false; meeting.active = false;
meeting.endAt = new Date(ts);
await meeting.save(); await meeting.save();
this.roomcastNotify(ctx, converseId, 'agoraChannelDestroy', { this.roomcastNotify(ctx, converseId, 'agoraChannelDestroy', {
converseId, converseId,
@ -273,7 +286,7 @@ class AgoraService extends TcService {
const [groupId, converseId] = channelName.split('|'); const [groupId, converseId] = channelName.split('|');
if (!db.Types.ObjectId.isValid(converseId)) { if (!db.Types.ObjectId.isValid(converseId)) {
this.logger.error('converseId invalid', converseId); this.logger.error('converseId invalid:', converseId);
throw new Error('converseId invalid'); throw new Error('converseId invalid');
} }

Loading…
Cancel
Save