summaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/src/meshbay_node/hub_client.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/hub_client.py')
-rw-r--r--packages/meshbay-node/src/meshbay_node/hub_client.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/hub_client.py b/packages/meshbay-node/src/meshbay_node/hub_client.py
index 74851c1..3e77ed0 100644
--- a/packages/meshbay-node/src/meshbay_node/hub_client.py
+++ b/packages/meshbay-node/src/meshbay_node/hub_client.py
@@ -250,10 +250,11 @@ class HubClient:
self,
on_incoming: Any = None,
on_revocation: Any = None,
+ on_webrtc_offer: Any = None,
) -> None:
"""
Maintain a persistent WebSocket connection to the hub.
- Receives NAT punch requests and revocation tokens.
+ Receives NAT punch requests, revocation tokens, and WebRTC offers.
Runs until cancelled.
"""
import websockets
@@ -270,6 +271,7 @@ class HubClient:
await ws.send(json.dumps({
"type": "auth",
"token": self._session.access_token,
+ "node_id": self._session.node_id,
}))
auth_resp = json.loads(await ws.recv())
if auth_resp.get("type") != "auth_ok":
@@ -289,6 +291,18 @@ class HubClient:
elif mtype == "revocation" and on_revocation:
on_revocation(msg.get("token", ""))
+ elif mtype == "webrtc_offer" and on_webrtc_offer:
+ answer = await on_webrtc_offer(
+ msg["sdp"], msg["peer_id"],
+ msg.get("ice_candidates", []))
+ if answer:
+ await ws.send(json.dumps({
+ "type": "webrtc_answer",
+ "peer_id": msg["peer_id"],
+ "sdp": answer[0],
+ "ice_candidates": answer[1],
+ }))
+
elif mtype == "pong":
pass