Comments (9)
have you generated token and use it when joining channel? could you pls give me an example token you generated?
from api-examples-web.
Yes I have.
Example of a generated token by RtcTokenBuilder.buildTokenWithUid
: 00630b9f4f0c35942538a8f567fda992004IADI/tNaitcwQh4k+YQ7nXBWu/heVQ0gnvwdJjvSv8RtjLO8GNtx9/GRIgAjCtQXZ5BCYwQAAQD3TEFjAgD3TEFjAwD3TEFjBAD3TEFj
Here is the code that I am using to generate the token:
async generateToken(channel: string): Promise<string> {
const appId = environment.agora.appId;
const appCertificate = environment.agora.appCertificate;
const channelName = channel;
const role = RtcRole.PUBLISHER;
const expirationTimeInSeconds = environment.agora.expirationTimeInSeconds;
const currentTimestamp = Math.floor(Date.now() / 1000);
const privilegeExpiredTs = currentTimestamp + expirationTimeInSeconds;
// the uid that we use is the username but agora.io does not support string
// so we will pass it as the current timestamp
const uid = currentTimestamp;
return RtcTokenBuilder.buildTokenWithUid(appId, appCertificate, channelName, uid, role, privilegeExpiredTs);
}
And here it is the code that I am using to join a voice call:
async joinVoiceCall(idUser: string, channel: string): Promise<boolean> {
try {
const agoraConfig = environment.agora;
console.log('channel', channel);
this.agoraEngine.on("user-published", async (user, mediaType) => {
await this.agoraEngine.subscribe(user, mediaType);
console.log("subscribe success");
if (mediaType == "audio") {
this.remoteUid = user.uid;
this.remoteAudioTrack = user.audioTrack;
this.remoteAudioTrack?.play();
console.log("Remote user connected: " + user.uid);
}
this.agoraEngine.on("user-unpublished", user => {
console.log(user.uid + "has left the channel");
});
});
const uid: string = idUser;
const appId: string = agoraConfig.appId;
const channelName: string = channel;
const token: string = await this.fetchToken(channelName);
console.log('token', token);
if (token === '' || token === undefined || token === null) {
throw new Error("No token provided");
}
await this.agoraEngine.join(appId, channelName, token, uid);
console.log("Joined channel: " + channelName);
this.localAudioTrack = await AgoraRTC.createMicrophoneAudioTrack();
await this.agoraEngine.publish(this.localAudioTrack);
console.log("Publish success!");
return true;
}
catch (error) {
console.error(error);
return false;
}
}
from api-examples-web.
@plutoless do you have some feedback?
Thanks
from api-examples-web.
i see the uid type you put here is string, while for our sdk it's actually required to be int. what kind of uid are you using here?
from api-examples-web.
I am sending the username because I don't have a user ID as integer but I can pass a integer if the problem is that.
from api-examples-web.
@plutoless I have tested with a number (12345) and now I got another error:
15:52:54:695 Agora-SDK [ERROR]: [client-013b0] join number: 1, Joining channel failed, rollback
from api-examples-web.
The data that I am sending to agora.io join
method:
appId: cce2692fe7d443939970d5deafd41263
channelName: 1663866110273
token: 00630b9f4f0c35942538a8f567fda992004IACoAqW09I7Ro/ACeIxCuv3lGFngf4KETychQbJWLqhhnrO8GNsPr5LBIgAmQM3X7iZIYwQAAQB+40ZjAgB+40ZjAwB+40ZjBAB+40Zj
uid: 12345
from api-examples-web.
And here are the logs:
from api-examples-web.
It is solved.
The problem was with the uid.
Thanks for helping.
from api-examples-web.
Related Issues (20)
- 怎么建立通道 HOT 2
- Unable to set volume indicator interval HOT 3
- OpenLive在首次加入时,接口请求的参数不对,导致接口一直报502 HOT 1
- Local camera not shown after granting camera use on Chrome HOT 1
- OpenLive can't run HOT 3
- @iceshou 您的token是怎么生成的呢
- OPEN-LIVE的demo报错频道名未定义 HOT 1
- 请教一下,自定义视频源和自定义音视频采集两个demo有啥区别 HOT 1
- localTracks.audioTrack.setEnabled(false) not working HOT 11
- calling AgoraRTC.createMicrophoneAndCameraTracks() does not show prompt permission for audio and camera in chrome HOT 1
- web demo 提示 CAN_NOT_GET_GATEWAY_SERVER 错误 HOT 1
- AgoraRTCException: AgoraRTCError NOT_SUPPORTED: your browser does not support setting the audio output device HOT 5
- 报错 TypeError: e.AudioBuffer is not a constructor HOT 2
- user-info-updated emits wrong state about video audio initial two states HOT 1
- basicVideoCall项目中用户无法看到主播视频 HOT 2
- I want to build a twitch clone but i couldnt understand how to use obs with agora
- AgoraRTCError UNEXPECTED_RESPONSE: ERR_SUBSCRIBE_REQUEST_INVALID: no such stream id
- change audio source input on the fly!
- How to style the video player?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from api-examples-web.