generated from pollen-robotics/python-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhancement #36: working exchanging of message. draft
- Loading branch information
1 parent
268a217
commit 83e83f6
Showing
6 changed files
with
98 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,38 +76,29 @@ def __del__(self) -> None: | |
Gst.deinit() | ||
|
||
def make_send_sdp(self, sdp, type: str, session_id: str): # type: ignore[no-untyped-def] | ||
self.logger.debug(f"send sdp {type} {sdp}") | ||
# self.logger.debug(f"send sdp {type} {sdp}") | ||
text = sdp.sdp.as_text() | ||
msg = {"type": type, "sdp": text} | ||
asyncio.run_coroutine_threadsafe( | ||
self.send_sdp(session_id, msg), self._asyncloop | ||
) | ||
|
||
def send_ice_candidate_message(self, _, mlineindex, candidate): # type: ignore[no-untyped-def] | ||
icemsg = {"ice": {"candidate": candidate, "sdpMLineIndex": mlineindex}} | ||
self.logger.debug(icemsg) | ||
# loop = asyncio.new_event_loop() | ||
# loop.run_until_complete(self.send_sdp(session_id, icemsg)) | ||
def send_ice_candidate_message(self, _, mlineindex, candidate, session_id: str): # type: ignore[no-untyped-def] | ||
icemsg = {"candidate": candidate, "sdpMLineIndex": mlineindex} | ||
# self.logger.debug(f"hello {icemsg} {session_id}") | ||
asyncio.run_coroutine_threadsafe( | ||
self.send_ice(session_id, icemsg), self._asyncloop | ||
) | ||
|
||
def init_webrtc(self, session_id: str): # type: ignore[no-untyped-def] | ||
webrtc = Gst.ElementFactory.make("webrtcbin") | ||
assert webrtc | ||
|
||
# webrtc.set_property("bundle-policy", "max-bundle") | ||
# webrtc.set_property("stun-server", "stun://stun.l.google.com:19302") | ||
# webrtc.set_property( | ||
# "turn-server", | ||
# "turn://gstreamer:[email protected]:3478", | ||
# ) | ||
webrtc.set_property("stun-server", None) | ||
webrtc.set_property("turn-server", None) | ||
|
||
# webrtc.connect("on-ice-candidate", lambda *args: self._ices.append(args)) | ||
# webrtc.connect("on-negotiation-needed", self.on_negotiation_needed, session_id) | ||
webrtc.connect("on-ice-candidate", self.send_ice_candidate_message) | ||
# webrtc.connect( | ||
# "notify::ice-gathering-state", self.on_ice_gathering_state_notify | ||
# ) | ||
webrtc.set_property("bundle-policy", "max-bundle") | ||
# webrtc.set_property("stun-server", None) | ||
# webrtc.set_property("turn-server", None) | ||
|
||
webrtc.connect("on-ice-candidate", self.send_ice_candidate_message, session_id) | ||
|
||
self._pipeline.set_state(Gst.State.READY) | ||
self._pipeline.add(webrtc) | ||
|
@@ -143,6 +134,11 @@ async def peer_for_session( | |
) -> None: | ||
self.logger.info(f"peer for session {session_id} {message}") | ||
|
||
def handle_ice_message(self, webrtc, ice_msg) -> None: # type: ignore[no-untyped-def] | ||
candidate = ice_msg["candidate"] | ||
sdpmlineindex = ice_msg["sdpMLineIndex"] | ||
webrtc.emit("add-ice-candidate", sdpmlineindex, candidate) | ||
|
||
async def close_session(self, session_id: str) -> None: | ||
self.logger.info("close session") | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters