我正在为我的 Angular 项目设置 agora SDK 并收到以下错误。代码:这是我的示例代码,正在调用 ngOnInit 中的 startCall 方法。我有一个带有 id 的 div 元素。
startCall() { this.agoraService.client.join(null, '1000', null, (uid) => { this.localStream = this.agoraService.createStream(uid, true, null, null, true, false); 这个.localStream.setVideoProfile('720p_3'); this.subscribeToStreams(); }); }
私人订阅流(){
this.localStream.on("accessAllowed", () => {
console.log("accessAllowed");
});
// The user has denied access to the camera and mic.
this.localStream.on("accessDenied", () => {
console.log("accessDenied");
});
this.localStream.init(() => {
console.log("getUserMedia successfully");
this.localStream.play('agora_local');
this.agoraService.client.publish(this.localStream, function (err) {
console.log("Publish local stream error: " + err);
});
this.agoraService.client.on('stream-published', function (evt) {
console.log("Publish local stream successfully");
});
}, function (err) {
console.log("getUserMedia failed", err);
});
// Add
this.agoraService.client.on('error', (err) => {
console.log("Got error msg:", err.reason);
if (err.reason === 'DYNAMIC_KEY_TIMEOUT') {
this.agoraService.client.renewChannelKey("", () => {
console.log("Renew channel key successfully");
}, (err) => {
console.log("Renew channel key failed: ", err);
});
}
});
// Add
this.agoraService.client.on('stream-added', (evt) => {
const stream = evt.stream;
this.agoraService.client.subscribe(stream, (err) => {
console.log("Subscribe stream failed", err);
});
});
// Add
this.agoraService.client.on('stream-subscribed', (evt) => {
const stream = evt.stream;
if (!this.remoteCalls.includes(`agora_remote${stream.getId()}`)) this.remoteCalls.push(`agora_remote${stream.getId()}`);
setTimeout(() => stream.play(`agora_remote${stream.getId()}`), 2000);
});
// Add
this.agoraService.client.on('stream-removed', (evt) => {
const stream = evt.stream;
stream.stop();
this.remoteCalls = this.remoteCalls.filter(call => call !== `#agora_remote${stream.getId()}`);
console.log(`Remote stream is removed ${stream.getId()}`);
});
// Add
this.agoraService.client.on('peer-leave', (evt) => {
const stream = evt.stream;
if (stream) {
stream.stop();
this.remoteCalls = this.remoteCalls.filter(call => call === `#agora_remote${stream.getId()}`);
console.log(`${evt.uid} left from this channel`);
}
});
}
我有一个带有 id 的 div 元素。
未捕获(承诺中)类型错误:无法在“RTCPeerConnection”上执行“getStats”:作为参数 1 提供的回调不是函数。在 Object.CtgetStats (AgoraRTCSDK.min.js:2) 在 AgoraRTCSDK.min.js:2 在 ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)在 Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195) 在 push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask ( zone.js:498) 在 ZoneTask.invoke (zone.js:487) 在计时器 (zone.js:2281)
有没有人面临同样的问题?谁能帮我这个?谢谢。
我已关注此链接 https://docs.agora.io/en/Interactive%20Broadcast/web_prepare?platform=Web
我已经完成的步骤,在此处输入代码 1. 将 Agora Web SDK 导入您的项目 2. 创建并初始化客户端 3. 加入频道 4. 最后,订阅远程流