Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to use agora renewToken #124

Open
peterujah opened this issue Dec 8, 2020 · 1 comment
Open

Not able to use agora renewToken #124

peterujah opened this issue Dec 8, 2020 · 1 comment

Comments

@peterujah
Copy link

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?

@plutoless
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants