我正在开发基于 webrtc 的音频/视频会议应用程序。为此,我在 Angular 11 和后端节点(快速服务器)中创建了一个前端。所以我使用 vanilla JS、HTML、CSS 创建了这个应用程序,它工作正常。但是当我试图将前端转换为 Angular 应用程序时,问题就来了。
应用程序的工作是这样的,首先我创建了房间,然后我会得到一个roomId
我发送给另一个人的信息,他用它roomId
来加入房间进行聊天。
当另一个人加入房间 onRoomJoined()
时,我会被处决。
async onRoomJoined(data) {
await this.setUpConnection(data['client-id'], data['client-name']);
this.socket.emit('send-metadata', { 'room-id': this.roomId, 'client-name': this.clientName,
'client-id': this.clientId, 'peer-id': data['client-id'] });
}
现在这个函数进一步调用setUpConnection()
函数如下,
async setUpConnection(peerId, peerName, initiateCall = false){
const videoElement = this.getVideoElement(peerId, 0, peerName);
videoElement.autoplay = true;
videoElement.playsInline = true;
this.peerConnections[peerId] = { 'peer-name': peerName, 'pc': new RTCPeerConnection(iceServers) };
this.peerConnections[peerId].pc.ontrack = (track) => { this.setRemoteStream(track, peerId); };
this.addLocalStreamTracks(peerId);
this.peerConnections[peerId].pc.onicecandidate = (iceCandidate) => { this.gatherIceCandidates(iceCandidate, peerId); };
this.peerConnections[peerId].pc.oniceconnectionstatechange = (event) => { this.checkPeerDisconnection(event, peerId); };
if (initiateCall === true) {
await this.createOffer(peerId);
}
}
以下是我在我身边的浏览器控制台中遇到的错误(房间创建者),
ERROR Error: Uncaught (in promise): TypeError: this.setUpConnection is not a function
TypeError: this.setUpConnection is not a function
at Socket.<anonymous> (home.component.ts:440)
at Generator.next (<anonymous>)
at tslib.es6.js:76
at new ZoneAwarePromise (zone-evergreen.js:960)
at __awaiter (tslib.es6.js:72)
at Socket.onRoomJoined (home.component.ts:438)
at Socket.push.cpc2.Emitter.emit (index.js:145)
at Socket.emit (typed-events.js:46)
at Socket.emitEvent (socket.js:263)
at Socket.onevent (socket.js:250)
at resolvePromise (zone-evergreen.js:798)
at new ZoneAwarePromise (zone-evergreen.js:963)
at __awaiter (tslib.es6.js:72)
at Socket.onRoomJoined (home.component.ts:438)
at Socket.push.cpc2.Emitter.emit (index.js:145)
at Socket.emit (typed-events.js:46)
at Socket.emitEvent (socket.js:263)
at Socket.onevent (socket.js:250)
at Socket.onpacket (socket.js:214)
at Manager.push.cpc2.Emitter.emit (index.js:145)
Here 以上两个函数onRoomJoined()
都setUpConnection()
在home.component.ts
文件中。我仍然得到TypeError: this.setUpConnection is not a function
.
这怎么可能?
任何帮助表示赞赏,谢谢!