AgoraIO / API-Examples-Web

MIT License
221 stars 199 forks source link

Cannot join with self-generated token #85

Closed neilyoung closed 6 months ago

neilyoung commented 6 months ago

First, I'm patching around in a Vue app, currently not exactly knowing, what I'm doing.

The (inherited) source code contains lines like this:

  agoraClient.setClientRole('audience', { level: 2 })
  if (agoraClient.connectionState === 'DISCONNECTED') {
    await agoraClient.join(agoraPara.appid, agoraPara.channel, agoraPara.token.toString())
  }

The join works and later on the code continues to subscribe to a stream, magically published by -- I need to say -- "somebody else", because that "somebody else" is some code in a DJI Pilot2 app, which is NOT accessible to me.

agoraClient.on('user-published', async (user: IAgoraRTCRemoteUser, mediaType: 'audio' | 'video') => {
    await agoraClient.subscribe(user, mediaType)
    if (mediaType === 'video') {
      console.log('subscribe success')
      // Get `RemoteVideoTrack` in the `user` object.
      const remoteVideoTrack = user.videoTrack!
      // Dynamically create a container in the form of a DIV element for playing the remote video track.
      remoteVideoTrack.play(document.getElementById('player') as HTMLElement)
    }
  })

At least the join works with the temp token from the Agora console and the subscribe too. The userID used by the publisher is 123456 (number), no idea, where this is taken from.

Now I started to generate my own token using JS code. I already managed to join with this token, but I don't currently get the role of the UID in the token.

AgoraRTC_N-production.js:14 Uncaught (in promise) AgoraRTCException: AgoraRTCError CAN_NOT_GET_GATEWAY_SERVER: flag: 4096, message: AgoraRTCError CAN_NOT_GET_GATEWAY_SERVER: invalid token, authorized failed
    at SJ (https://app.ca-test.votix.com/node_modules/.vite/agora-rtc-sdk-ng.js?v=c5087107:12143:418)
    at https://app.ca-test.votix.com/node_modules/.vite/agora-rtc-sdk-ng.js?v=c5087107:12120:48
    at Generator.next (<anonymous>)
    at fulfilled (https://app.ca-test.votix.com/node_modules/.vite/chunk-N2UNTUOU.js?v=c5087107:67:24)

I currently have no idea anymore, how to make my tokens work.

Do you?

neilyoung commented 6 months ago

Update: If I set my uid to 0 (which means don't care, I think), my generated token is accepted. I'm now getting all the time a new ID.

plutoless commented 6 months ago

sorry i saw you reopen the issue. does the issue persists?

neilyoung commented 6 months ago

No, thanks for asking. I was tricked by the fact, that a token with "valid" UID (!= 0) needs to be uniquely used in the "room".

Thanks