ハイブリッドアプリケーションの一部である以下のスクリプトを作成しましたが、時には正常に機能し、オーディオ/ビデオコールを送受信できますが、いつかonaddstream
またはontrack
も呼び出されません送信側が、SPDパケットはソケット経由で送信されている、私は(onaddstream or ontrack)
しかし、誰成功の両方試してみました:答えを受け入れるときに、他のデバイスpc2
上webrtc onaddstreamが最初のピアで呼び出されていない
sendOffer() {
let that = this;
that.call_status = 'connecting';
let call_type;
if (that.call_type == 'audio')
call_type = { video: false, audio: true };
else
call_type = { video: true, audio: true };
that.pc = new RTCPeerConnection(that.peerConnectionConfig);
that.haveGum = navigator.mediaDevices.getUserMedia(call_type)
.then(stream => {
that.pc.addStream(that.from_video.nativeElement.srcObject = stream);
that.from_video.nativeElement.style.display = 'block';
}).then(() => that.pc.createOffer())
.then(d => that.pc.setLocalDescription(d))
.catch(log => { alert(log) });
that.pc.oniceconnectionstatechange = function (e) {
that.call_status = that.pc.iceConnectionState;
if (that.pc.iceConnectionState == 'disconnected') {
console.log('Disconnected');
}
}
that.pc.onaddstream = e => {
that.to_video.nativeElement.srcObject = e.stream;
};
that.pc.onicecandidate = e => {
if (e.candidate) {
return;
}
that.offerSent = true;
that.socket.emit('sdp-offer', {
from: that.user,
sdp: that.pc.localDescription.sdp,
call_type: call_type
});
};
that.socket.on('sdp-offer-reply', (sdp: any) => {
that.pc.setRemoteDescription(new RTCSessionDescription(({ type: "answer", sdp: sdp.sdp }))).catch(log => console.log(log));
});
that.socket.on('call-closed', (sdp: any) => {
that.closeConnection();
});
}
と、ここ:ここ
がpc
からのオファーを送信するために:
answerCall() {
let that = this;
let call_type;
if (this.call_type == 'audio')
call_type = { video: false, audio: true };
else
call_type = { video: true, audio: true };
that.pc2 = new RTCPeerConnection(this.peerConnectionConfig);
that.haveGum = navigator.mediaDevices.getUserMedia(call_type)
.then(stream => {
that.pc2.addStream(this.from_video.nativeElement.srcObject = stream);
});
that.pc2.oniceconnectionstatechange = function (e) {
console.log(that.pc2.iceConnectionState);
}
that.pc2.onaddstream = e => {
that.to_video.nativeElement.srcObject = e.stream;
that.to_video.nativeElement.style.display = 'block';
};
if (that.pc2.signalingState != "stable") {
that.call_status = that.pc2.signalingState;
alert("not stable");
return;
}
that.pc2.setRemoteDescription(new RTCSessionDescription(({ type: "offer", sdp: this.sdp.sdp })))
.then(() => that.pc2.createAnswer())
.then(d => {
that.sendSdpAnswer = d; that.pc2.setLocalDescription(d);
this.call_connected = true;
})
.catch(log => console.log(log));
that.pc2.onicecandidate = e => {
if (e.candidate) {
console.log("not e.candidate");
return;
}
that.socket.emit('offeraccepted', {
from: that.user,
sdp: that.sendSdpAnswer.sdp
});
};
that.socket.on('call-closed', (sdp: any) => {
that.closeConnection();
that.call_status = "Hung Up";
});
}
、ここで最後の関数は、私は、コールが終了したときに、両側のピア接続を閉じるように呼び出しています:
closeConnection() {
if (typeof this.pc !== "undefined" && this.pc.signalingState != "closed") {
this.pc.close();
}
if (typeof this.pc2 !== "undefined" && this.pc2.signalingState != "closed") {
this.pc2.close();
}
}
私は、サーバーをシグナルとしてsocket.ioと最新adapter.jsをのWebRTC使用しています。まず私は、SDPパケットを送信するpc
にイベントsdp-offer
を放出し、pc2
はofferaccepted
を発するよりもpc2
に私は、ノードサーバからsdp-offer-incoming
を受け取り、私はSDPパケットを受信pc1
に、イベントにSDPデータを添付し、それは両方のPCの上のビデオ/オーディオを表示するようにいつか送信者がストリームを受信する必要がありますが、受信者は常に両方のビデオを持っています。
あなたがこれを理解しました、MDNこのどこでも –
HIはあなたがそこにある言及していませんか –