多次调用client.join, 第二次时报UID_CONFLICT错误

我使用的是websdk 2.8.0
我的操作步骤:

  1. client.init(appId)
  2. client.join(accessToken, channel, uid)
  3. localStream = AgoraRTCSDK.createStream()
  4. localStream.init() && localStream.play
  5. 调用sdk停止本地流的播放和离开房间
localStream.stop();
localStream.close();
client.leave();
  1. 当我再次重复第1个流程时,发生了一个错误
16:45:18:548 Agora-SDK [ERROR]: [F1679]  UID_CONFLICT {uid: 10101, cname: "yTutuQu1vX"}

请问是因为我没有正确的离开频道吗?还是有别的原因。

谢谢

UID_CONFLICT 报错原因:同一个 uid 多次加入一个频道导致互踢。怀疑是你多次调用了 join ,或者是没有成功离开频道,你可以在 leave 方法里打印一下

console.log("client leaves channel");

看下是否有成功离开频道?

在下面已经成功离开了频道。再次join就会报错

AgoraRTCSDK.min.js:183 17:17:36:761 Agora-SDK [INFO]: processId: process-172f7059-a9e4-49c6-8297-ca09fc88599b
AgoraRTCSDK.min.js:183 17:17:36:762 Agora-SDK [DEBUG]: Flush cached event reporting: 3
AgoraRTCSDK.min.js:183 17:17:36:774 Agora-SDK [INFO]: Creating client, MODE: rtc CODEC: vp8
AgoraRTCSDK.min.js:183 17:17:36:775 Agora-SDK [INFO]: [8FF0D] Initializing AgoraRTC client, appId: 8e99e984bc5c4abf81ee9b53e6e21fe5.
AgoraRTCSDK.min.js:183 17:17:37:319 Agora-SDK [DEBUG]: Get UserAccount Successfully {uid: 10102, url: "https://ap-web-1.agora.io/api/v1"}
AgoraRTCSDK.min.js:183 17:17:37:320 Agora-SDK [DEBUG]: getUserAccount Success https://ap-web-1.agora.io/api/v1 C-FNVStGidN-3fo1AABh => 10102
AgoraRTCSDK.min.js:183 17:17:37:325 Agora-SDK [DEBUG]: [3323A] Connect to choose_server: https://ap-web-1.agora.io/api/v1
AgoraRTCSDK.min.js:183 17:17:37:328 Agora-SDK [DEBUG]: [3323A] Connect to choose_server: https://ap-web-2.agoraio.cn/api/v1
AgoraRTCSDK.min.js:183 17:17:37:695 Agora-SDK [DEBUG]: [3323A] Get gateway address: (3) ["webrtc-119-84-82-46.agora.io:5872", "webrtc-113-143-100-182.agoraio.cn:5876", "webrtc-113-143-100-164.agora.io:5877"]
AgoraRTCSDK.min.js:183 17:17:37:696 Agora-SDK [INFO]: [3323A] Joining channel: yTutuQu1vX
AgoraRTCSDK.min.js:183 17:17:37:697 Agora-SDK [DEBUG]: [3323A] register client Channel yTutuQu1vX Uid 10102
AgoraRTCSDK.min.js:183 17:17:37:698 Agora-SDK [DEBUG]: [3323A] start connect:webrtc-119-84-82-46.agora.io:5872
AgoraRTCSDK.min.js:183 17:17:37:991 Agora-SDK [DEBUG]: [3323A] websockect opened: webrtc-119-84-82-46.agora.io:5872
AgoraRTCSDK.min.js:183 17:17:38:23 Agora-SDK [DEBUG]: [3323A] Connected to gateway server
AgoraRTCSDK.min.js:183 17:17:38:132 Agora-SDK [INFO]: [3323A] Join channel yTutuQu1vX success, join with uid: C-FNVStGidN-3fo1AABh.
AgoraRTCSDK.min.js:183 17:17:38:134 Agora-SDK [DEBUG]: Create stream
AgoraRTCSDK.min.js:183 17:17:38:147 Agora-SDK [DEBUG]: [C-FNVStGidN-3fo1AABh] Requested access to local media
AgoraRTCSDK.min.js:183 17:17:38:151 Agora-SDK [DEBUG]: GetUserMedia {"video":{"deviceId":{"exact":"58e959d8948fc9529e25350ca242a53c46c1bfa60db08ff5140bd321f033c9a3"},"width":640,"height":360,"frameRate":{"ideal":15,"max":15}},"audio":{"deviceId":{"exact":"default"}}}
AgoraRTCSDK.min.js:183 17:17:38:608 Agora-SDK [DEBUG]: [C-FNVStGidN-3fo1AABh] User has granted access to local media
AgoraRTCSDK.min.js:183 17:17:38:611 Agora-SDK [DEBUG]: [C-FNVStGidN-3fo1AABh] play(). agora_rtc_localstream undefined
AgoraRTCSDK.min.js:183 17:17:40:833 Agora-SDK [INFO]: [8FF0D] Publishing stream, uid C-FNVStGidN-3fo1AABh
AgoraRTCSDK.min.js:8146 Uncaught TypeError: Cannot read property 'stringUid' of undefined
    at Object.Ke.t._publish (AgoraRTCSDK.min.js:8146)
    at Object.Ke.t.publish (AgoraRTCSDK.min.js:8194)
    at LocalStream.js:39
Show 11 more frames
AgoraRTCSDK.min.js:183 17:17:40:866 Agora-SDK [DEBUG]: Player 0 video Status Changed Detected by Timer: init=>paused
AgoraRTCSDK.min.js:183 17:17:40:867 Agora-SDK [DEBUG]: Media Player Status Change {type: "player-status-change", playerId: 0, mediaType: "video", status: "paused", reason: "timer", …}
AgoraRTCSDK.min.js:183 17:17:40:870 Agora-SDK [DEBUG]: Player 0 audio Status Changed Detected by Timer: init=>play
AgoraRTCSDK.min.js:183 17:17:40:871 Agora-SDK [DEBUG]: Media Player Status Change {type: "player-status-change", playerId: 0, mediaType: "audio", status: "play", reason: "timer", …}
AgoraRTCSDK.min.js:183 17:17:40:932 Agora-SDK [DEBUG]: [C-FNVStGidN-3fo1AABh] video dimensions: 640 360
AgoraRTCSDK.min.js:183 17:17:42:191 Agora-SDK [DEBUG]: [C-FNVStGidN-3fo1AABh] Stop stream player with id  C-FNVStGidN-3fo1AABh
AgoraRTCSDK.min.js:183 17:17:42:192 Agora-SDK [DEBUG]: destroy local Player C-FNVStGidN-3fo1AABh
AgoraRTCSDK.min.js:183 17:17:42:196 Agora-SDK [DEBUG]: Media Player Status Change Triggered by destroy() {type: "player-status-change", playerId: 0, mediaType: "video", status: "aborted", reason: "stop", …}
AgoraRTCSDK.min.js:183 17:17:42:196 Agora-SDK [DEBUG]: Media Player Status Change Triggered by destroy() {type: "player-status-change", playerId: 0, mediaType: "audio", status: "aborted", reason: "stop", …}
AgoraRTCSDK.min.js:183 17:17:42:197 Agora-SDK [DEBUG]: [C-FNVStGidN-3fo1AABh] Close stream with id C-FNVStGidN-3fo1AABh
AgoraRTCSDK.min.js:183 17:17:42:199 Agora-SDK [INFO]: [8FF0D] Leaving channel
备注:这里已经是断开了
AgoraRTCSDK.min.js:183 17:17:42:200 Agora-SDK [DEBUG]: [8FF0D] Client Already in DISCONNECTED status
AgoraRTCSDK.min.js:183 17:17:42:201 Agora-SDK [DEBUG]: renewSession CC22E5620FAA4CC29DD01E8F5B525856 => 27060AE6C44746A7AA5FB0097208A14C
AgoraRTCSDK.min.js:183 17:17:47:788 Agora-SDK [DEBUG]: Flush cached event reporting: 14
AgoraRTCSDK.min.js:183 17:17:47:801 Agora-SDK [INFO]: Creating client, MODE: rtc CODEC: vp8
AgoraRTCSDK.min.js:183 17:17:47:802 Agora-SDK [INFO]: [B99DF] Initializing AgoraRTC client, appId: 8e99e984bc5c4abf81ee9b53e6e21fe5.
AgoraRTCSDK.min.js:183 17:17:48:116 Agora-SDK [DEBUG]: Get UserAccount Successfully {uid: 10102, url: "https://ap-web-1.agora.io/api/v1"}
AgoraRTCSDK.min.js:183 17:17:48:117 Agora-SDK [DEBUG]: getUserAccount Success https://ap-web-1.agora.io/api/v1 C-FNVStGidN-3fo1AABh => 10102
AgoraRTCSDK.min.js:183 17:17:48:122 Agora-SDK [DEBUG]: [8FF0D] Connect to choose_server: https://ap-web-1.agora.io/api/v1
AgoraRTCSDK.min.js:183 17:17:48:125 Agora-SDK [DEBUG]: [8FF0D] Connect to choose_server: https://ap-web-2.agoraio.cn/api/v1
AgoraRTCSDK.min.js:183 17:17:48:418 Agora-SDK [DEBUG]: [8FF0D] Get gateway address: (3) ["webrtc-119-84-82-49.agoraio.cn:5877", "webrtc-113-143-100-181.agora.io:5866", "webrtc-113-143-100-164.agoraio.cn:5869"]
AgoraRTCSDK.min.js:183 17:17:48:419 Agora-SDK [INFO]: [8FF0D] Joining channel: yTutuQu1vX
备注:再次join被抛出了UID_CONFLICT错误
backend.js:6 17:17:48:452 Agora-SDK [ERROR]: [8FF0D]  UID_CONFLICT {uid: 10102, cname: "yTutuQu1vX"}

刚刚查看了一下,leave方法的第一个回调被正常调用,离开频道是成功的

join方法也没有被多次调用,一个调用两次,第二次就失败了

我使用

localStream.stop();
localStream.close();
client.leave(e => {
  console.log('离开成功 ---- ', e)
}, e => {
  console.log('离开失败 ---- ', e)
});

离开一个频道,调试信息如下:

17:42:09:479 Agora-SDK [DEBUG]: [k4MhggibrZSNS0NuAABo] Close stream with id k4MhggibrZSNS0NuAABo
AgoraRTCSDK.min.js:183 17:42:09:481 Agora-SDK [INFO]: [9AA91] Leaving channel
AgoraRTCSDK.min.js:183 17:42:09:481 Agora-SDK [DEBUG]: [9AA91] Client Already in DISCONNECTED status
AgoraRTCSDK.min.js:183 17:42:09:482 Agora-SDK [DEBUG]: renewSession FFC8641E7FA0409AAA2CC65604887CCB => DE71DFC1FFC0436CA9EA32DD4B2FAA6B
Control.js:44 离开成功 ----  undefined

然后我去管理后台通过水晶球查看,实际上并没有成功离开

5d907c4821e6abec00002778
2019/09/29 09:41:28 - 进行中
3min 40s

目前不知道原因。当我关闭浏览器tab后离开正常。

@Zhhhhh你怎么看,是一个bug吗?还是我操作方式有问题

谢谢

我将websdk回退到2.7.1似乎一切正常了。
@Zhhhhh 看起来好像是一个新版本的bug

@Zhhhhh 还有一个问题没解决。

当离开频道关闭音视频

localStream.stop();
    localStream.close();
    client.leave(e => {
      console.log('离开成功 ---- ', e)
    }, e => {
      console.log('离开失败 ---- ', e)
    });

只要web浏览器一直没关闭,我看到水晶球还是一直在计费。这样会造成错误的计费

18:14:08:335 Agora-SDK [DEBUG]: [A192C] Client Already in DISCONNECTED status
AgoraRTCSDK.min.js:183 18:14:08:338 Agora-SDK [DEBUG]: renewSession 06E465763D814E879694EB47464338AE => 43DAD47B9DFC40E9B4515C54AF730825
Control.js:44 离开成功 ----  undefined

你之前是用 2.8.0 测试的对吗?你先升级到最新版 2.9.0 测试看看有没有问题呢?