Giter Site home page Giter Site logo

Comments (9)

plutoless avatar plutoless commented on August 24, 2024

have you generated token and use it when joining channel? could you pls give me an example token you generated?

from api-examples-web.

pncsoares avatar pncsoares commented on August 24, 2024

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.

pncsoares avatar pncsoares commented on August 24, 2024

@plutoless do you have some feedback?
Thanks

from api-examples-web.

plutoless avatar plutoless commented on August 24, 2024

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.

pncsoares avatar pncsoares commented on August 24, 2024

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.

pncsoares avatar pncsoares commented on August 24, 2024

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

pncsoares avatar pncsoares commented on August 24, 2024

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.

pncsoares avatar pncsoares commented on August 24, 2024

And here are the logs:

image

from api-examples-web.

pncsoares avatar pncsoares commented on August 24, 2024

It is solved.
The problem was with the uid.
Thanks for helping.

from api-examples-web.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.