我已经下载了 azure 通信聊天服务,并按照视频https://www.youtube.com/watch?v=2pyKhoIZhJo中所示的方式工作 。
但他们是问题..我如何克服令牌过期..它继续过期的treadID,我不能再聊天了..
我已经提到了 RefreshToken,虽然它并不令人耳目一新。下面是我所做的更改的代码,
var userCredential = new CommunicationUserCredential
(
initialToken: moderator.token,
refreshProactively: true,
tokenRefresher: cancellationToken => fetchNewTokenForCurrentUser(moderator.identity).GetAwaiter().GetResult(),
asyncTokenRefresher: cancellationToken => fetchNewTokenForCurrentUserasync(moderator.identity)
);
fetchNewTokenForCurrentUser 方法如下
private async Task<string> fetchNewTokenForCurrentUser( string identity)
{
CommunicationIdentityClient communicationIdentityClient = new CommunicationIdentityClient(resourceConnectionString);
CommunicationUser user = new CommunicationUser(identity);
Azure.Response<CommunicationUserToken> tokenResponse = await communicationIdentityClient.IssueTokenAsync
(
user,
scopes: new[] { CommunicationTokenScope.Chat }
);
string token = tokenResponse.Value.Token;
return token;
}
但是这段代码不起作用..希望有人能帮助我..提前谢谢