Search code examples
agora.ioagora-web-sdk-ng

join channel failed DYNAMIC_USE_STATIC_KEY


I am trying to use Agora.io live video system. But i am getting the following errors in developer console.

After clicking the join button i got the following error.

Agora-SDK [ERROR]: [713FF] Get server node failed [DYNAMIC_USE_STATIC_KEY] https://webrtc2-ap-web-1.agora.io/api/v1 DYNAMIC_USE_STATIC_KEY agora.js:161:41
Agora-SDK [INFO]: [713FF] Join failed: DYNAMIC_USE_STATIC_KEY agora.js:155:41
[ERROR] : join channel failed DYNAMIC_USE_STATIC_KEY live:1146:15

I have to make an arrangement on the agora management panel. What am I doing wrong.

 var rand = <?php echo rand(1111111,9999999); ?>;
 var agoraAppId = 'API ID HERE'; // set app id
 var channelName = "stream_<?php echo $creatorUserID;?>_"+rand; // set channel name
// join a channel
function joinChannel() {
  var token = generateToken();
  var userID = 0; // set to null to auto generate uid on successfull connection

  // set the role
  client.setClientRole('host', function() {
    console.log('Client role set as host.');
  }, function(e) {
    console.log('setClientRole failed', e);
  });

  // client.join(token, 'allThingsRTCLiveStream', 0, function(uid) {
  client.join(token, channelName, userID, function(uid) {
      createCameraStream(uid, {});
      localStreams.uid = uid; // keep track of the stream uid  
      console.log('User ' + uid + ' joined channel successfully');
      $('#main_live_video').html('')
      $('#publishBtn').removeAttr('disabled');
      $('#publishBtn').text("Please Wait");
      $('#publishBtn').addClass('hidden');
      $('.end_vdo_call').removeClass('hidden');

      $.post(requestUrl + "?f=live", {stream_name: channelName}, function(data, textStatus, xhr) {
                    if (data.status == 200) {
                      $('#live_post_id').val(data.post_id);
                    }
                  });
  }, function(err) {
      console.log('[ERROR] : join channel failed', err);
  });
}
function generateToken() {
 return null; // TODO: add a token generation
}

Solution

  • The error you are receiving is because you are attempting to use an AppID that has Token authentication enabled, but not passing a token when you join the channel.

    To resolve this you would generally have three options:

    1. Create a new project and generate a new AppID. Open the Project Management tab within the Agora Console. Click the "Create" button in the upper left section of the screen. Within the dialog box, make sure to select the bottom option. enter image description here

    2. Generate a temporary token (valid for 24hrs) on your project using the Project Management tab within the Agora Console. follow these steps:

      • Select the Generate Temp Token Option enter image description here
      • Enter the channel name and generate a token enter image description here
      • update the generateToken function with your token string, instead of returning null.
    function generateToken() {
      return null; // add a token string here
    }
    
    1. Implement a token server and generate dynamic tokens. Further details check out:
    function generateToken() {
      return null; // add a token string here
    }
    

    The second option would not work for your implementation because you are generating a channel name using a user name and appending a random value. When generating a temp token you need to know the name of the channel.