Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am trying to initiate a video call with agora and its throwing following error on console, this happens when I try to join the call .

code: "CAN_NOT_GET_GATEWAY_SERVER"
data: {retry: false}
message: "AgoraRTCError CAN_NOT_GET_GATEWAY_SERVER: dynamic use static key"
name: "AgoraRTCException"

I have attached the react JS code here I am using react js module of Agora,and have followed the docs , I have verified email and proper APP created , it worked with the web demo of Agora but not here. Please help

import React, { useEffect, useState, useRef } from "react";
import ReactDOM from "react-dom";
import "./App.css";
import { options, rtc } from "./constants";
import AgoraRTC from "agora-rtc-sdk-ng";
function App() {
  async function handleSubmit(e) {
    try {
      if (channelRef.current.value === "") {
        return console.log("Please Enter Channel Name");
      setJoined(true);
      rtc.client = AgoraRTC.createClient({ mode: "rtc", codec: "h264" });
      const uid = await rtc.client.join(
        options.appId,
        channelRef.current.value,
        options.token,
      // Create an audio track from the audio captured by a microphone
      rtc.localAudioTrack = await AgoraRTC.createMicrophoneAudioTrack();
      // Create a video track from the video captured by a camera
      rtc.localVideoTrack = await AgoraRTC.createCameraVideoTrack();
      rtc.localVideoTrack.play("local-stream");
      rtc.client.on("user-published", async (user, mediaType) => {
        // Subscribe to a remote user
        await rtc.client.subscribe(user);
        console.log("subscribe success");
        // console.log(user);
        if (mediaType === "video" || mediaType === "all") {
          // Get `RemoteVideoTrack` in the `user` object.
          const remoteVideoTrack = user.videoTrack;
          console.log(remoteVideoTrack);
          // Dynamically create a container in the form of a DIV element for playing the remote video track.
          const PlayerContainer = React.createElement("div", {
            id: user.uid,
            className: "stream",
          ReactDOM.render(
            PlayerContainer,
            document.getElementById("remote-stream")
          user.videoTrack.play(`${user.uid}`);
        if (mediaType === "audio" || mediaType === "all") {
          // Get `RemoteAudioTrack` in the `user` object.
          const remoteAudioTrack = user.audioTrack;
          // Play the audio track. Do not need to pass any DOM element
          remoteAudioTrack.play();
      rtc.client.on("user-unpublished", (user) => {
        // Get the dynamically created DIV container
        const playerContainer = document.getElementById(user.uid);
        console.log(playerContainer);
        // Destroy the container
        playerContainer.remove();
      // Publish the local audio and video tracks to the channel
      await rtc.client.publish([rtc.localAudioTrack, rtc.localVideoTrack]);
      console.log("publish success!");
    } catch (error) {
      console.error(error);
  async function handleLeave() {
    try {
      const localContainer = document.getElementById("local-stream");
      rtc.localAudioTrack.close();
      rtc.localVideoTrack.close();
      setJoined(false);
      localContainer.textContent = "";
      // Traverse all remote users
      rtc.client.remoteUsers.forEach((user) => {
        // Destroy the dynamically created DIV container
        const playerContainer = document.getElementById(user.uid);
        playerContainer && playerContainer.remove();
      // Leave the channel
      await rtc.client.leave();
    } catch (err) {
      console.error(err);
  const [joined, setJoined] = useState(false);
  const channelRef = useRef("");
  const remoteRef = useRef("");
  const leaveRef = useRef("");
  return (
      <div className="container">
        <input
          type="text"
          ref={channelRef}
          id="channel"
          placeholder="Enter Channel name"
        <input
          type="submit"
          value="Join"
          onClick={handleSubmit}
          disabled={joined ? true : false}
        <input
          type="button"
          ref={leaveRef}
          value="Leave"
          onClick={handleLeave}
          disabled={joined ? false : true}
      {joined ? (
          <div id="local-stream" className="stream local-stream"></div>
            id="remote-stream"
            ref={remoteRef}
            className="stream remote-stream"
      ) : null}
export default App;
  • Enable the Live Mode of the project
  • Enable Secondary Certificate and use that
  • Last and most important if you are getting token invalid or authentication failed error then put 0 in the Uid and generate RtcTokenBuilder::buildTokenWithUid
  • This solved my problem, I hope it helps yours

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question . Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers .