我有一个工作的WebRTC客户端,我想通过使用aiotrc(python)的WebRTC接收它的视频。另一个客户端作为收件人工作正常,我们已经用浏览器对其进行了测试
使用python,我配置了服务器,创建了一个带有收发器的报价(我只想接收视频),并将报价设置为localDescription:
import json
import socketio
import asyncio
from asgiref.sync import async_to_sync
from aiortc import RTCPeerConnection, RTCSessionDescription, RTCIceCandidate, RTCConfiguration, RTCIceServer, RTCIceGatherer, RTCRtpTransceiver
session_id = 'default'
sio = socketio.Client()
ice_server = RTCIceServer(urls='stun:stun.l.google.com:19302')
pc = RTCPeerConnection(configuration=RTCConfiguration(iceServers=[ice_server]))
pc.addTransceiver("video", direction="recvonly")
def connect():
sio.connect('https://192.168.10.123', namespaces=['/live'])
connect()
@async_to_sync
async def set_local_description():
await pc.setLocalDescription(await pc.createOffer())
print('Local description set to: ', pc.localDescription)
#send_signaling_message(json.dumps({'sdp':{'sdp': pc.localDescription.sdp, 'type':pc.localDescription.type}}))
set_local_description()
(在本例中,socket.io所连接的是一个假地址)。在这之后,我不知道如何收集ice候选人。我尝试过使用iceGatherer,但运气不佳:
ice_gath = RTCIceGatherer(iceServers=[ice_server])
candidates = ice_gath.getLocalCandidates()
我必须将ice候选人发送给收件人。在这一点上,我找不到任何关于如何使用aiortc获得ice候选人的信息。下一步是什么
当您调用
setLocalDescription
时,您发布的代码实际上已经执行了ICE候选对象收集。查看您正在打印的会话描述,您应该会看到标记为srflx
的候选会话,这意味着“服务器自反”:从STUN服务器的角度来看,这些是您的IP地址,例如:另外请注意,默认情况下
aiortc
已经使用了Google的STUN服务器,因此下面是您的示例的一个更简化的版本:相关问题 更多 >
编程相关推荐