Agora.io DYNAMIC_USE_STATIC_KEY 使用生成的 RTC 令牌 (php)
Agora.io DYNAMIC_USE_STATIC_KEY with generated RTC Token (php)
我有一个问题:
我在尝试建立连接的控制台中得到 DYNAMIC_USE_STATIC_KEY。
2 Agora Console 和rtcTokenBuilder 生成的Token 不一样,第二个比较长,使用会出现这个错误。有了console Token就ok了
令牌示例:
控制台:0068bedd2631cf24edea47479b64ad219ceIAAYXDdhxjKQyDWQEoqK0qEiAYo+dLSyd/YNAaflVD4PJO/ZQc0AAAAAEACMMKzfQDg1YAEAAQA/ODVg
rtcTokenBuilder:
0068bedd2631cf24edea47479b64ad219ceIAADpmWghbJIToZQMC9YrQjBhtFgpdZS4tIlOkXTjk+LKe/ZQc0h39v0IgCa0wUAjQY2YAQAAQA5tjRgAwA5tjRgAgA5tjRgBAA5tjRg
rtcTokenBuilder 代码片段:
$appID = "8*************************";
$appCertificate = "+++++++++++++++++++++++++++7";
$channelName = "Test Chamber";
$uid = 0;
$role = RtcTokenBuilder::RoleAttendee;
$expireTimeInSeconds = 300; // 5 min for test purposes
$currentTimestamp = (new DateTime("now", new DateTimeZone('UTC')))->getTimestamp();
$privilegeExpiredTs = $currentTimestamp + $expireTimeInSeconds;
$token = RtcTokenBuilder::buildTokenWithUid($appID, $appCertificate, $channelName, $uid, $role, $privilegeExpiredTs);
echo $token;
js文件:
client.join(token, room, 0, (uid) => { // 0 -> uid
let localStream = AgoraRTC.createStream({
audio: true,
video: true
});
localStream.init(() =>
.....
client.on("onTokenPrivilegeWillExpire", function(){
$.ajax({
url: tokenGenPath, // path to rtcTokenBuilder php generator
method: "POST",
success: function(data){
newToken = data;
},
error: function(){
}
});
client.renewToken(newToken);
});
这里说,我不提供 Token 优先连接:Agora Docs
P.S。我还注意到,如果我一开始在 Agora 控制台中生成一个令牌,并且在这个令牌过期的情况下,一个新的 valid 令牌从 rtcTokenBuilder 生成并且 connection/conversation 继续.
所以,问题出在 2 个地方。首先,我改变了AJAX调用
来自
client.on("onTokenPrivilegeWillExpire", function(){
$.ajax({
url: tokenGenPath, // path to rtcTokenBuilder php generator
method: "POST",
success: function(data){
newToken = data;
},
error: function(){
}
});
client.renewToken(newToken);
});
收件人:
client.on("onTokenPrivilegeWillExpire", function(){
$.post(tokenGenPath, function (token){
client.renewToken(token);
});
});
其次,我通过客户端初始化将第一个令牌生成移出了主函数:
$.post(tokenGenPath, function (data){
token = data;
});
function runApp (room, client, token){
client.join(token, room, 0, (uid) => { // 0 -> uid
let localStream = AgoraRTC.createStream({
audio: true,
video: true
});
localStream.init(() =>
.....
}
我有一个问题: 我在尝试建立连接的控制台中得到 DYNAMIC_USE_STATIC_KEY。
2 Agora Console 和rtcTokenBuilder 生成的Token 不一样,第二个比较长,使用会出现这个错误。有了console Token就ok了
令牌示例: 控制台:0068bedd2631cf24edea47479b64ad219ceIAAYXDdhxjKQyDWQEoqK0qEiAYo+dLSyd/YNAaflVD4PJO/ZQc0AAAAAEACMMKzfQDg1YAEAAQA/ODVg
rtcTokenBuilder: 0068bedd2631cf24edea47479b64ad219ceIAADpmWghbJIToZQMC9YrQjBhtFgpdZS4tIlOkXTjk+LKe/ZQc0h39v0IgCa0wUAjQY2YAQAAQA5tjRgAwA5tjRgAgA5tjRgBAA5tjRg
rtcTokenBuilder 代码片段:
$appID = "8*************************";
$appCertificate = "+++++++++++++++++++++++++++7";
$channelName = "Test Chamber";
$uid = 0;
$role = RtcTokenBuilder::RoleAttendee;
$expireTimeInSeconds = 300; // 5 min for test purposes
$currentTimestamp = (new DateTime("now", new DateTimeZone('UTC')))->getTimestamp();
$privilegeExpiredTs = $currentTimestamp + $expireTimeInSeconds;
$token = RtcTokenBuilder::buildTokenWithUid($appID, $appCertificate, $channelName, $uid, $role, $privilegeExpiredTs);
echo $token;
js文件:
client.join(token, room, 0, (uid) => { // 0 -> uid
let localStream = AgoraRTC.createStream({
audio: true,
video: true
});
localStream.init(() =>
.....
client.on("onTokenPrivilegeWillExpire", function(){
$.ajax({
url: tokenGenPath, // path to rtcTokenBuilder php generator
method: "POST",
success: function(data){
newToken = data;
},
error: function(){
}
});
client.renewToken(newToken);
});
这里说,我不提供 Token 优先连接:Agora Docs
P.S。我还注意到,如果我一开始在 Agora 控制台中生成一个令牌,并且在这个令牌过期的情况下,一个新的 valid 令牌从 rtcTokenBuilder 生成并且 connection/conversation 继续.
所以,问题出在 2 个地方。首先,我改变了AJAX调用
来自
client.on("onTokenPrivilegeWillExpire", function(){
$.ajax({
url: tokenGenPath, // path to rtcTokenBuilder php generator
method: "POST",
success: function(data){
newToken = data;
},
error: function(){
}
});
client.renewToken(newToken);
});
收件人:
client.on("onTokenPrivilegeWillExpire", function(){
$.post(tokenGenPath, function (token){
client.renewToken(token);
});
});
其次,我通过客户端初始化将第一个令牌生成移出了主函数:
$.post(tokenGenPath, function (data){
token = data;
});
function runApp (room, client, token){
client.join(token, room, 0, (uid) => { // 0 -> uid
let localStream = AgoraRTC.createStream({
audio: true,
video: true
});
localStream.init(() =>
.....
}