feat: add common service available check

pull/90/head
moonrailgun
parent 1fa1293d1a
commit 0cb61bcf85

@ -313,6 +313,16 @@ export abstract class TcService extends Service {
}); });
} }
/**
* action
*
* ,
*/
registerAvailableAction(checkFn: () => boolean) {
this.registerAction('available', checkFn);
this.registerAuthWhitelist(['/available']);
}
/** /**
* *
* @param panelFeature * @param panelFeature

@ -76,13 +76,26 @@ class AgoraService extends TcService {
return process.env.AGORA_CUSTOMER_SECRET; return process.env.AGORA_CUSTOMER_SECRET;
} }
onInit() { /**
*
*/
get serverAvailable(): boolean {
if ( if (
!this.serverAppId || this.serverAppId &&
!this.serverAppCertificate || this.serverAppCertificate &&
!this.serverCustomerKey || this.serverCustomerKey &&
!this.serverCustomerSecret this.serverCustomerSecret
) { ) {
return true;
}
return false;
}
onInit() {
this.registerAvailableAction(() => this.serverAvailable);
if (!this.serverAvailable) {
console.warn( console.warn(
'声网服务启动失败, 缺少必要的环境变量: AGORA_APP_ID, AGORA_APP_CERT, AGORA_CUSTOMER_KEY, AGORA_CUSTOMER_SECRET' '声网服务启动失败, 缺少必要的环境变量: AGORA_APP_ID, AGORA_APP_CERT, AGORA_CUSTOMER_KEY, AGORA_CUSTOMER_SECRET'
); );

@ -32,6 +32,8 @@ class GetuiService extends TcService {
} }
onInit() { onInit() {
this.registerAvailableAction(() => this.getuiAvailable);
if (!this.getuiAvailable) { if (!this.getuiAvailable) {
console.warn( console.warn(
'[plugin:com.msgbyte.getui] require env: GETUI_APPID, GETUI_APPKEY, GETUI_MASTERSECRET' '[plugin:com.msgbyte.getui] require env: GETUI_APPID, GETUI_APPKEY, GETUI_MASTERSECRET'

@ -20,7 +20,7 @@ class MeetingService extends TcService {
onInit() { onInit() {
// this.registerLocalDb(require('../models/meeting').default); // this.registerLocalDb(require('../models/meeting').default);
this.registerAction('available', this.available); this.registerAvailableAction(() => Boolean(this.tailchatMeetingUrl));
if (!isValidStr(this.tailchatMeetingUrl)) { if (!isValidStr(this.tailchatMeetingUrl)) {
return; return;
@ -41,10 +41,6 @@ class MeetingService extends TcService {
); );
} }
available(ctx: TcContext) {
return Boolean(this.tailchatMeetingUrl);
}
/** /**
* *
*/ */

Loading…
Cancel
Save