- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我创建了以下脚本,它是混合应用程序的一部分,有时它可以正常运行,我可以接收/发送音频/视频调用,但有时 onaddstream
或 ontrack
甚至没有从发送方调用,但 spd 数据包是通过套接字发送的,我已经尝试了 (onaddstream 或 ontrack)
但没有成功:
在此从 pc
发送报价:
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();
});
}
在其他设备 pc2
上接受答案时:
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();
}
}
我使用 webrtclatest-adapter.js 和 socket.io 作为信令服务器。首先,我在 pc
上发出事件 sdp-offer
以发送 sdp 数据包,并在 pc2
上接收 sdp-offer-incoming
来自 Node 服务器,然后 pc2
发出 offeraccepted
并将 sdp 数据附加到事件,在 pc1
上我收到 sdp 数据包并显示视频/两台电脑上的音频都正常,但有时发送者没有收到流,但接收者总是有两个视频。
最佳答案
创建报价时我必须传递约束:
this.pc.createOffer({
offerToReceiveAudio: 1,
offerToReceiveVideo: 1
})
关于node.js - webrtc onaddstream 未在第一个对等点上调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45467511/
我使用 WebRTC 连接 2 个 Chrome 浏览器。我在第一个客户端上创建 offer 并通过 signalR 将其发送给第二个客户端,如下所示: function initiate_call(
我正在使用 WebRTC 创建一个测试视频聊天应用程序。我有两个对等点成功连接。我想为用户添加一种“重新连接”的方式(断开连接并与另一个用户连接。出于测试目的,“其他”用户与以前的用户相同)。所以,当
我创建了以下脚本,它是混合应用程序的一部分,有时它可以正常运行,我可以接收/发送音频/视频调用,但有时 onaddstream 或 ontrack甚至没有从发送方调用,但 spd 数据包是通过套接字发
我正在尝试设置一个基本的视频聊天示例。目前正在尝试在同一台计算机上的两个 Chrome 选项卡之间聊天。 一切看起来都很好,直到我获得远程视频流,当我使用 URL.createObjectURI 将其
我是一名优秀的程序员,十分优秀!