Web Agora.io DYNAMIC_KEY_EXPIRED [英] Web Agora.io DYNAMIC_KEY_EXPIRED

查看:295
本文介绍了Web Agora.io DYNAMIC_KEY_EXPIRED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在mvc中使用c#.

I am using c# with mvc.

我使用此代码生成令牌并成功生成.但是在使用 .join()加入频道时生成令牌后,它将返回DYNAMIC_KEY_EXPIRED. 我使用了"AgoraRTCSDK-3.1.0.js"

I used this code to generate token and generated successfully. but after generate token when join channel using .join() it return DYNAMIC_KEY_EXPIRED. I Used "AgoraRTCSDK-3.1.0.js"

我使用了 https://github.com/AgoraIO/Tools/blob/master/DynamicKey/AgoraDynamicKey/csharp 生成动态令牌

如果有人在Agora.io上有经验,请帮助我.

If any one has experience on Agora.io, please help me.

示例代码是..

AccessToken token = new AccessToken(apiKey, appCertificate, channelName, "0");
token.addPrivilege(Privileges.kJoinChannel, _expiredTs);
token.addPrivilege(Privileges.kPublishAudioStream, _expiredTs);
token.addPrivilege(Privileges.kPublishVideoStream, _expiredTs);
string strToken = token.build();

public string build()
    {
        this._messageRawContent = Utils.pack(this.message);
        this._signature = generateSignature(_appCertificate
                , _appId
                , _channelName
                , _uid
                , _messageRawContent);

        this._crcChannelName = Crc32CAlgorithm.Compute(this._channelName.GetByteArray());
        this._crcUid = Crc32CAlgorithm.Compute(this._uid.GetByteArray());

        PackContent packContent = new PackContent(_signature, _crcChannelName, _crcUid, this._messageRawContent);
        byte[] content = Utils.pack(packContent);
        return getVersion() + this._appId + Utils.base64Encode(content);
    }

推荐答案

无论何时为Agora应用程序生成令牌,都需要记住,到期时间是作为时间戳计算的(自1970年以来的时间),因此您需要确保将到期时间设置为currentTime + expirationTimeInSeconds.

Whenever you generate a token for Agora applications, you need to keep in mind that the expiration time is calculated as a timestamp (time since 1970) so you need to ensure the the expiration time is set to the currentTime + expirationTimeInSeconds.

在上面的示例中,您将到期时间传递为​​0,这会生成已被视为已过期的令牌.

In the above example you are passing the expiration time as 0 which generates a token that is already considered expired.

考虑使用:

  // set a expiration time of 1 hour in seconds
  let expireTime = 3600;

  // calculate current time in seconds
  const currentTime = Math.floor(Date.now() / 1000);

  // calculate privilege expire time
  const privilegeExpireTime = currentTime + expireTime;

这篇关于Web Agora.io DYNAMIC_KEY_EXPIRED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆