Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow gst candidate in aiortc adapter. #27

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.8"
python-version: "3.10"
cache: 'pip' # caching pip dependencies
- name: Install dependencies
run: |
Expand Down
49 changes: 28 additions & 21 deletions src/gst_signalling/aiortc_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,9 @@ def on_welcome(peer_id: str) -> None:
@self.signalling.on("Peer")
async def on_peer(session_id: str, message: dict[str, Any]) -> None:
assert self.session_id == session_id

if "sdp" in message:
message = message["sdp"]
elif "ice" in message:
message = message["ice"]
else:
raise ValueError(f"Invalid message {message}")

if "type" in message:
obj = object_from_string(json.dumps(message))
elif "candidate" in message:
if message["candidate"] == "":
self.logger.info(f"Received empty candidate, ignoring")
return

obj = candidate_from_sdp(message["candidate"].split(":", 1)[1])
obj.sdpMLineIndex = message["sdpMLineIndex"]
else:
self.logger.error(f"Failed to parse message: {message}")
return
await self.peer_msg_queue.put(obj)
obj = self._parse_peer_message(message)
if obj is not None:
await self.peer_msg_queue.put(obj)

@self.signalling.on("EndSession")
async def on_end_session(session_id: str) -> None:
Expand All @@ -106,6 +88,31 @@ async def on_error(details: str) -> None:
self.logger.error(f'Connection closed with error: "{details}"')
await self.peer_msg_queue.put(BYE)

def _parse_peer_message(
self, message: dict[str, Any]
) -> Optional[Union[RTCSessionDescription, RTCIceCandidate]]:
if "sdp" in message:
message = message["sdp"]
elif "ice" in message:
message = message["ice"]
else:
raise ValueError(f"Invalid message {message}")

if "type" in message:
obj = object_from_string(json.dumps(message))
return obj
elif "candidate" in message:
if message["candidate"] == "":
self.logger.info("Received empty candidate, ignoring")
return None

obj = candidate_from_sdp(message["candidate"].split(":", 1)[1])
obj.sdpMLineIndex = message["sdpMLineIndex"]
return obj
else:
self.logger.error(f"Failed to parse message: {message}")
return None

def _setup_producer(self) -> None:
@self.signalling.on("StartSession")
def on_start_session(peer_id: str, session_id: str) -> None:
Expand Down
Loading