|
|
@@ -3,17 +3,18 @@ const {RtcTokenBuilder, RtmTokenBuilder, RtcRole} = pkg;
|
|
|
|
|
|
export class AgoraTokenService {
|
|
|
private appId: string
|
|
|
- private appSecret: string
|
|
|
+ private primaryCert: string
|
|
|
private tokenExpiry: number
|
|
|
|
|
|
constructor() {
|
|
|
this.appId = process.env.AGORA_APP_ID || ''
|
|
|
- this.appSecret = process.env.AGORA_APP_SECRET || ''
|
|
|
+ // this.primaryCert = process.env.AGORA_APP_SECRET || ''
|
|
|
+ this.primaryCert = process.env.AGORA_PRIMARY_CERT || ''
|
|
|
this.tokenExpiry = parseInt(process.env.AGORA_TOKEN_EXPIRY || '3600')
|
|
|
|
|
|
// 在生产环境中检查配置,测试环境中允许为空
|
|
|
- if (process.env.NODE_ENV === 'production' && (!this.appId || !this.appSecret)) {
|
|
|
- throw new Error('Agora配置缺失:请设置AGORA_APP_ID和AGORA_APP_SECRET环境变量')
|
|
|
+ if (process.env.NODE_ENV === 'production' && (!this.appId || !this.primaryCert)) {
|
|
|
+ throw new Error('Agora配置缺失:请设置AGORA_APP_ID和AGORA_PRIMARY_CERT环境变量')
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -27,7 +28,7 @@ export class AgoraTokenService {
|
|
|
|
|
|
console.debug('生成RTC Token参数:', {
|
|
|
appId: this.appId ? '已设置' : '未设置',
|
|
|
- appSecret: this.appSecret ? '已设置' : '未设置',
|
|
|
+ primaryCert: this.primaryCert ? '已设置' : '未设置',
|
|
|
channelName,
|
|
|
userId,
|
|
|
privilegeExpiredTs
|
|
|
@@ -35,7 +36,7 @@ export class AgoraTokenService {
|
|
|
|
|
|
const token = RtcTokenBuilder.buildTokenWithUid(
|
|
|
this.appId,
|
|
|
- this.appSecret,
|
|
|
+ this.primaryCert,
|
|
|
channelName,
|
|
|
typeof userId === 'number' ? userId : parseInt(userId),
|
|
|
RtcRole.PUBLISHER,
|
|
|
@@ -62,7 +63,7 @@ export class AgoraTokenService {
|
|
|
|
|
|
const token = RtmTokenBuilder.buildToken(
|
|
|
this.appId,
|
|
|
- this.appSecret,
|
|
|
+ this.primaryCert,
|
|
|
userId,
|
|
|
privilegeExpiredTs
|
|
|
)
|