def test_candidate_to_string(self): candidate = RTCIceCandidate(component=1, foundation='0', ip='192.168.99.7', port=33543, priority=2122252543, protocol='UDP', type='host') candidate.sdpMid = 'audio' candidate.sdpMLineIndex = 0 self.assertEqual(object_to_string( candidate ), '{"candidate": "candidate:0 1 UDP 2122252543 192.168.99.7 33543 typ host", "id": "audio", "label": 0, "type": "candidate"}' ) # noqa
def test_candidate_to_string(self): candidate = RTCIceCandidate( component=1, foundation="0", ip="192.168.99.7", port=33543, priority=2122252543, protocol="UDP", type="host", ) candidate.sdpMid = "audio" candidate.sdpMLineIndex = 0 self.assertEqual( object_to_string(candidate), '{"candidate": "candidate:0 1 UDP 2122252543 192.168.99.7 33543 typ host", "id": "audio", "label": 0, "type": "candidate"}', )
async def _handle_ice_candidates(self): """ (*Coroutine*) Coroutine that handle the ICE candidates negotiation. """ while self.readyState == PeerState.CONNECTING or self.readyState == PeerState.CONNECTED: signal = await self._get_signal() if 'type' in signal: if signal['type'] == 'status' and signal[ 'status'] == 'unpaired': if self.readyState == PeerState.CONNECTED: logging.info('unpaired received, disconnecting...') self.disconnection_event.set() elif 'candidate' in signal: logging.info('Got ice candidate:') candi = Candidate.from_sdp(signal['candidate']['candidate']) candidate = RTCIceCandidate( component=candi.component, foundation=candi.foundation, ip=candi.host, port=candi.port, priority=candi.priority, protocol=candi.transport, relatedAddress=candi.related_address, relatedPort=candi.related_port, tcpType=candi.tcptype, type=candi.type, sdpMLineIndex=signal['candidate']['sdpMLineIndex'], sdpMid=signal['candidate']['sdpMid']) logging.debug(candidate) self._pc.addIceCandidate(candidate) else: raise Exception('Received an unexpected signal: ', signal)
async def addCandidate(candidate): self.candidates.append(candidate) # decode the candidate info split_candidate = candidate["candidate"].split(" ") sdpMLineIndex = candidate["sdpMLineIndex"] sdpMid = candidate["sdpMid"] foundation = split_candidate[0].split(":")[-1] component = int(split_candidate[1]) protocol = split_candidate[2] priority = int(split_candidate[3]) ip = split_candidate[4] port = int(split_candidate[5]) candidate_type = split_candidate[7] tcp_type = split_candidate[9] new_candidate = RTCIceCandidate(component=component, foundation=foundation, ip=ip, port=port, priority=priority, protocol=protocol, type=candidate_type, sdpMid=sdpMid, sdpMLineIndex=sdpMLineIndex, tcpType=tcp_type) await self.pc.addIceCandidate(new_candidate) print("successfully add new candidate")
def _dict_to_candidate(candidate_node: dict) -> RTCIceCandidate: host_port_combo: str = candidate_node.get('transportAddress') candidate_type: str = candidate_node.get('type') priority: int = int(candidate_node.get('priority')) foundation: str = candidate_node.get('foundation') protocol: str = candidate_node.get('transport') # TODO: whats component? component = 0 host, port = host_port_combo.rsplit(':', maxsplit=1) return RTCIceCandidate(component, foundation, host, port, priority, protocol, candidate_type)