|
@@ -1,5 +1,5 @@
|
|
|
import AgoraRTM, { ChannelType, RTMClient, RTMConfig, MetadataItem } from "agora-rtm-sdk"
|
|
import AgoraRTM, { ChannelType, RTMClient, RTMConfig, MetadataItem } from "agora-rtm-sdk"
|
|
|
-import { mapToArray, isString, apiGetAgoraToken, getDefaultLanguageSelect, fetchAgoraConfig } from "../../common"
|
|
|
|
|
|
|
+import { mapToArray, isString, getDefaultLanguageSelect } from "../../common"
|
|
|
import { AGEventEmitter } from "../events"
|
|
import { AGEventEmitter } from "../events"
|
|
|
import {
|
|
import {
|
|
|
RtmEvents,
|
|
RtmEvents,
|
|
@@ -38,17 +38,14 @@ export class RtmManager extends AGEventEmitter<RtmEvents> {
|
|
|
this.userName = userName
|
|
this.userName = userName
|
|
|
this.channel = channel
|
|
this.channel = channel
|
|
|
|
|
|
|
|
- // 获取配置
|
|
|
|
|
- await fetchAgoraConfig()
|
|
|
|
|
-
|
|
|
|
|
- // 从配置中获取appId
|
|
|
|
|
|
|
+ // 获取RTM配置和Token
|
|
|
const { agoraClient } = await import("@/client/api")
|
|
const { agoraClient } = await import("@/client/api")
|
|
|
const response = await agoraClient.token.$get({
|
|
const response = await agoraClient.token.$get({
|
|
|
query: { type: 'rtm', channel, userId }
|
|
query: { type: 'rtm', channel, userId }
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
if (!response.ok) {
|
|
|
- throw new Error('配置获取失败')
|
|
|
|
|
|
|
+ throw new Error('RTM配置获取失败')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const data = await response.json()
|
|
const data = await response.json()
|
|
@@ -57,8 +54,8 @@ export class RtmManager extends AGEventEmitter<RtmEvents> {
|
|
|
this.client = new RTM(data.appId, userId, this.rtmConfig)
|
|
this.client = new RTM(data.appId, userId, this.rtmConfig)
|
|
|
}
|
|
}
|
|
|
this._listenRtmEvents()
|
|
this._listenRtmEvents()
|
|
|
- const token = await apiGetAgoraToken({ channel: this.channel, uid: this.userId })
|
|
|
|
|
- await this.client.login({ token })
|
|
|
|
|
|
|
+ // 直接使用API返回的token,避免重复调用
|
|
|
|
|
+ await this.client.login({ token: data.token })
|
|
|
this.joined = true
|
|
this.joined = true
|
|
|
// subscribe message channel
|
|
// subscribe message channel
|
|
|
await this.client.subscribe(channel, {
|
|
await this.client.subscribe(channel, {
|