我正在为我的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); this.localStream.setVideoProfile('720p_3'); this.subscribeToStreams(); }); }
private subscriptionToStreams(){
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的元素。
未捕获(承诺)TypeError:无法在“ RTCPeerConnection”上执行“ getStats”:作为参数1提供的回调不是函数。 在Object.C.t.getStats(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.最后,订阅远程流
答案 0 :(得分:0)
在测试Agora的WebSDK(或任何WebRTC应用程序)时,请确保在尝试运行代码时使用的是https连接,因为大多数浏览器不允许没有https连接的getMedia访问。
有许多在本地计算机上使用https连接的解决方案。我使用{{1}}工具在本地计算机上轻松运行https连接