我不能让RTCPeerConnection工作。在我创建了一个RTCPeerConnection对象之后,什么也没有发生。事件不会被激发。这是创建连接的方法:
createPeerConnection() {
console.log('new RtCPeerConnection with stun server.');
this.myPeerConnection = new RTCPeerConnection({stunServer}]
});
console.log('PeerConnection is ', this.myPeerConnection);
this.myPeerConnection.onicecandidate = this.handleICECandidateEvent;
this.myPeerConnection.ontrack = this.handleAddTrackEvent;
this.myPeerConnection.removeTrack = this.handleRemoveStreamEvent;
this.myPeerConnection.oniceconnectionstatechange = this.handleICEConnectionStateChangeEvent;
// this.myPeerConnection.onicegatheringstatechange = this.handleICEGatheringStateChangeEvent;
// this.myPeerConnection.onsignalingstatechange = this.handleSignalingStateChangeEvent;
this.myPeerConnection.onnegotiationneeded = this.handleNegotiationNeededEvent;
}我在控制台中没有错误。什么都没发生。当用户单击另一个用户进行连接时,将调用此方法:
connect() {
console.log('Creating RTCPeerConnetion...');
this.createPeerConnection();
console.log('RTCPeerConnection created');
console.log('Creating new local stream ...');
navigator.mediaDevices.getUserMedia({ video: true, audio: true }).then((localStream) => {
this.localVideo.nativeElement.srcObject = localStream;
console.log('Local stream created', localStream);
}).catch(this.handleGetUserMediaError);
}我使用了火狐和Angular2,并在本地主机上进行了测试。不知道这是不是原因。有什么想法吗?
发布于 2017-02-08 17:53:32
我只是忘了像这样给peerConnection添加蒸汽:
navigator.mediaDevices.getUserMedia({ video: true, audio: true }).then((localStream) => {
this.localVideo.nativeElement.srcObject = localStream;
console.log('Local stream created', localStream);
localStream.getTracks().forEach(track =>
this.myPeerConnection.addTrack(track, localStream)
);https://stackoverflow.com/questions/42109161
复制相似问题