加入通话时出现 CAN_NOT_GET_GATEWAY_SERVER 异常
Posted
技术标签:
【中文标题】加入通话时出现 CAN_NOT_GET_GATEWAY_SERVER 异常【英文标题】:Getting CAN_NOT_GET_GATEWAY_SERVER exception on joining a call 【发布时间】:2020-10-27 18:03:20 【问题描述】:我正在尝试使用 agora 发起视频通话,并在控制台上抛出以下错误,当我尝试加入通话时会发生这种情况。
code: "CAN_NOT_GET_GATEWAY_SERVER"
data: retry: false
message: "AgoraRTCError CAN_NOT_GET_GATEWAY_SERVER: dynamic use static key"
name: "AgoraRTCException"
我在这里附加了 react JS 代码我正在使用 Agora 的 react js 模块,并遵循了文档,我已经验证了电子邮件并创建了正确的 APP,它与 Agora 的 web 演示一起工作,但不是在这里。请帮忙
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,
null
);
// 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
/>
</div>
joined ? (
<>
<div id="local-stream" className="stream local-stream"></div>
<div
id="remote-stream"
ref=remoteRef
className="stream remote-stream"
></div>
</>
) : null
</>
);
export default App;
【问题讨论】:
【参考方案1】:由于令牌过期,您需要在选项对象中再次设置令牌和频道名称。您可以从https://console.agora.io/project/ 生成新令牌
【讨论】:
【参考方案2】:奇怪的是,示例相关文档说令牌是可选的,但实际上它是必需的。添加它并解决问题
【讨论】:
【参考方案3】:此问题的另一个可能原因是用于生成令牌的 uid 与用于加入频道的 uid 不匹配。因此,请确保令牌相同。
【讨论】:
【参考方案4】:如果您使用 agora sdk 并且发生这种情况,您必须尝试这些
启用项目的实时模式 启用辅助证书并使用它 最后也是最重要的,如果您遇到令牌无效或身份验证失败错误,则将 0 放入 Uid 并生成
RtcTokenBuilder::buildTokenWithUid
这解决了我的问题,希望对你有帮助
【讨论】:
以上是关于加入通话时出现 CAN_NOT_GET_GATEWAY_SERVER 异常的主要内容,如果未能解决你的问题,请参考以下文章
为啥在使用 pyspark 加入 Spark 数据帧时出现这些 Py4JJavaError showString 错误?