Skip to content

Commit

Permalink
Merge pull request #54 from pollen-robotics/53-emit-end-of-session
Browse files Browse the repository at this point in the history
enhancement #53: emit end of session
  • Loading branch information
FabienDanieau authored Dec 2, 2024
2 parents ddbdc4d + bc960ed commit 0ee8dc2
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/gst_signalling/gst_abstract_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"GstSession",
[
("peer_id", str),
("session_id", str),
("pc", Gst.Element), # type '__gi__.GstWebRTCBin'
],
)
Expand All @@ -35,6 +36,7 @@ def __init__(

self.peer_id: Optional[str] = None
self.peer_id_evt = asyncio.Event()
self.consume_evt = asyncio.Event()
self._asyncloop = asyncio.get_event_loop()

self.sessions: Dict[str, GstSession] = {}
Expand Down Expand Up @@ -104,17 +106,19 @@ async def connect(self) -> None:

async def close(self) -> None:
await self.signalling.close()
self.consume_evt.set()

async def consume(self) -> None:
while True:
await asyncio.sleep(1000)
# while True:
# await asyncio.sleep(1000)
await self.consume_evt.wait()

# Session management
async def setup_session(self, session_id: str, peer_id: str) -> GstSession:
self.logger.info("setup session")
pc = self.init_webrtc(session_id)

session = GstSession(peer_id, pc)
session = GstSession(peer_id, session_id, pc)

self.sessions[session_id] = session

Expand All @@ -130,11 +134,14 @@ def handle_ice_message(self, webrtc: Gst.Element, ice_msg: Dict[str, Any]) -> No

async def close_session(self, session_id: str) -> None:
self.logger.info("close session")

session = self.sessions.pop(session_id)
self._pipeline.remove(session.pc)
session.pc.set_state(Gst.State.NULL)
self.emit("close_session", session)
try:
session = self.sessions.pop(session_id)
self._pipeline.remove(session.pc)
session.pc.set_state(Gst.State.NULL)
await self.signalling.end_session(session_id)
# self.emit("close_session", session)
except KeyError:
self.logger.warning("Session not found")

async def send_sdp(self, session_id: str, sdp: Dict[str, Dict[str, str]]) -> None:
await self.signalling.send_peer_message(session_id, "sdp", sdp)
Expand Down

0 comments on commit 0ee8dc2

Please sign in to comment.