Basic-Video-Broadcasting icon indicating copy to clipboard operation
Basic-Video-Broadcasting copied to clipboard

Not able to use agora renewToken

Open peterujah opened this issue 5 years ago • 1 comments

I created live streaming on agora android. Before opening the live activity I always check from server if token is valid and if no generate new token using the agora php SDK like below.

<?php 
   Include_once(/vendor/Agora/RtcTokenBuilder.php');
   $appID = "MY_APP_ID";
    $appCertificate = "MY_APP_CERT";
    $channelName = $app->CreateRandomChannelName();
    $uid = 0;
    $role = RtcTokenBuilder::RolePublisher;
    $expireTimeInSeconds = 3600;
    $currentTimestamp = (new DateTime("now", new DateTimeZone('UTC')))->getTimestamp();
    $privilegeExpiredTs = $currentTimestamp + $expireTimeInSeconds;

    $token = RtcTokenBuilder::buildTokenWithUid($appID, $appCertificate, $channelName, $uid, $role, $privilegeExpiredTs);
    $response =  array(
        "status" => 200,
        "token" => $token,
        "channel" => $channelName,
    );
?>

And call rtcEngine().renewToken("tokeFromServer..."); then also set the channel name which I used in generating token 'config().setChannelName(liveName);, yet it doesn't work except when i add the token in string_config.xml. I also tried adding the token which I generated from agora server to a static string then pass it tortcEngine().renewToken("tokeFromServerStatic");` but it seems not working.

Please how do I renewToken before starting live?

peterujah avatar Dec 08 '20 16:12 peterujah

@peterujah just generate a new token every time, renewToken is used if you have already joined channel, while the live broadcasting is so long that it exceeds the expire time you set for the original token, there will be a tokenWillExpire callback from sdk and then you call renewToken to renew it while in channel. This is usually not needed, just generate a new token every time.

plutoless avatar Dec 12 '20 17:12 plutoless