Create a Peer instance and register with PnP signaling server.
()
| 295 | |
| 296 | |
| 297 | async def pnp_service_connect() -> Peer: |
| 298 | """Create a Peer instance and register with PnP signaling server.""" |
| 299 | # Create own peer object with connection to shared PeerJS server |
| 300 | logger.info('creating peer') |
| 301 | # If we already have an assigned peerId, we will reuse it forever. |
| 302 | # We expect that peerId is crypto secure. No need to replace. |
| 303 | # Unless the user explicitly requests a refresh. |
| 304 | global savedPeerId |
| 305 | global config |
| 306 | logger.info('last saved savedPeerId {}', savedPeerId) |
| 307 | new_token = util.randomToken() |
| 308 | logger.info('Peer session token {}', new_token) |
| 309 | |
| 310 | |
| 311 | options = PeerOptions( |
| 312 | host=config['signaling_server'], |
| 313 | port=config['port'], |
| 314 | secure=config['secure'], |
| 315 | token=new_token, |
| 316 | config=RTCConfiguration( |
| 317 | iceServers=[RTCIceServer(**srv) for srv in config['ice_servers']] |
| 318 | ) |
| 319 | ) |
| 320 | peer = Peer(id=savedPeerId, peer_options=options) |
| 321 | logger.info('pnpService: peer created with id {} , options: {}', |
| 322 | peer.id, |
| 323 | peer.options) |
| 324 | await peer.start() |
| 325 | logger.info('peer activated') |
| 326 | _setPnPServiceConnectionHandlers(peer) |
| 327 | return peer |
| 328 | |
| 329 | |
| 330 | async def make_discoverable(peer=None): |
no test coverage detected