npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-agora-live

v0.23.0

Published

Live call in Agora

Downloads

7

Readme

Work with AGORA Live (Simple Way)

this package simplify the using of agora live call so you don't have to know anything about tokens and channels you just have to return BtnJoin Component and pass the correct parameters to it, and it's DONE!

Read the documentation carefully.

If you are searching for agora call not live you can use the react-agora-call package

BtnJoin component

please make sure to name the parameters correctly like this:

{
  <BtnJoin
    fetchURL={'https://..../Channel'}
    endURL={'https://..../Leave'}
    clientID={clientID}
    broadcastID={broadcastID}
    referenceID={referenceID}
    token="xxxxxxx"
    setError={setError}
    users={Users}
    setUsers={setUsers}
    setReply={setReply}
    setStatus={setStatus}
    btnText="Join Broadcast 📞"
  />;
} // it returns a button with the provided Style and Text and a video player that appears when the call is on going

the response for 'https://..../Channel' API should be like:

{
  "response": 0,
  "message": "string",
  "data": {
    "agoraAppID": "string",
    "agoraUserID": "string",
    "rtmToken": "string",
    "channel": "string",
    "rtcToken": "string",
    "duration": 0
  }
}

the response for 'https://..../Leave' API should be like:

{
  "authenticationKey": "string",
  "lang": "string",
  "clientID": 0,
  "token": "string",
  "broadcastID": 0,
  "referenceID": "string"
}

Example:

import { BtnJoin } from 'react-agora-live';
import { useState } from 'react';
import 'react-agora-live/src/index.css';

function TestPackage() {
  const clientID = 25;
  const broadcastID = 93;
  const [Error, setError] = useState('');
  const [Users, setUsers] = useState('');
  const [Reply, setReply] = useState('');
  const [Status, setStatus] = useState('');

  return (
    <div>
      <BtnJoin
        fetchURL={'https://..../Channel'}
        endURL={'https://..../Leave'}
        clientID={clientID}
        broadcastID={broadcastID}
        referenceID={referenceID}
        token="xxxxxx"
        setError={setError}
        users={Users}
        setUsers={setUsers}
        setReply={setReply}
        setStatus={setStatus}
        btnText="Join Broadcast 📞"
      />
    </div>
  );
} // it returns a button with the provided Style and Text and a video player that appears when the call is on going

export default TestPackage;

Here where I call function called channel.

In the channel function I talk to the Channel api after that I create RTM client rtmClient function and login to RTM rtmLogin function.

Then I create an RTC Client rtcClient function.

Then I handle the states of the call by calling handleCallStates.

After that I used the RTC client to join the channel rtcJoin function.

Styling

if you need to use default style you can import this file

import 'react-agora-live/src/index.css';

or you can Customize Style by creating another CSS file and override the classes mentioned in the index.css file

index.css

.call-button-agora {
  background-color: #833dcc;
  margin: 10px;
  padding: 10px 20px;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

.videos-container-agora {
  border: solid 2px #ebebeb;
  border-radius: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 30vw;
  height: 100vh;
  margin: auto;
}
.video-player-container-agora {
  margin-bottom: 30px;
}
.agora-video-player-agora {
  width: 30vw;
  height: 80vh;
}

.top-buttons-container-agora {
  margin: auto;
  width: 100%;
  border-radius: 50px 50px 0 0;
  background-color: transparent;
}

.buttons-container-agora {
  width: 100%;
}

.button-style-agora {
  background-color: #f1e7fc;
  color: #a28cb6;
  border: none;
  border-radius: 10px;
  height: 7vh;
  width: 100%;
  cursor: pointer;
  font-size: 15px;
  margin-bottom: 10px;
}

.button-icon-agora {
  width: 50%;
  height: 50%;
}

.live-flag {
  background-color: red;
  color: white;
  width: 50px;
  height: 25px;
  position: absolute;
  top: 10vh;
  right: 37vw;
  border-radius: 6px;
}

More details if you need it

Video player (Videos) component

please make sure to name the parameters correctly like this:

{
  <Videos
    endURL={endURL}
    users={users}
    clientID={clientID}
    token={token}
    broadcastID={broadcastID}
    referenceID={referenceID}
  />;
} // return a video player

Here where I talk with the Leave api when leaving the live call

Channel function

please make sure to name the parameters correctly like this:

{
  channel({
    fetchURL,
    clientID,
    broadcastID,
    referenceID,
    token,
    setError,
    setUsers,
    setReply,
    setStatus,
  });
} // Do most of the functionality

rtmClient function

please make sure to name the parameters correctly like this:

{
  rtmClient({ appId: appId });
} // return RTM client

rtmLogin function

please make sure to name the parameters correctly like this:

{
  rtmLogin({
    uid: data.data.agoraUserID,
    rtmToken: data.data.rtmToken,
    appId: data.data.agoraAppID,
  });
}

rtcClient function

please make sure to name the parameters correctly like this:

{
  rtcClient();
}

handleCallStates function

please make sure to name the parameters correctly like this:

{
  handleCallStates({
    RtcClient: rtcClient,
    setUsers: setUsers,
    setReply: setReply,
    setStatus: setStatus,
  });
}

this function tracks the states of the call

rtcJoin function

please make sure to name the parameters correctly like this:

{
  rtcJoin({
    rtcClient: rtcClient,
    appId: data.data.agoraAppID,
    channel: data.data.channel,
    rtcToken: data.data.rtcToken,
    uid: data.data.agoraUserID,
  });
}