Mercurial > libervia-backend
comparison libervia/cli/cmd_call.py @ 4233:d01b8d002619
cli (call, file), frontends: implement webRTC data channel transfer:
- file send/receive commands now supports webRTC transfer. In `send` command, the
`--webrtc` flags is currenty used to activate it.
- WebRTC related code have been factorized and moved to `libervia.frontends.tools.webrtc*`
modules.
rel 442
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 06 Apr 2024 13:43:09 +0200 |
parents | 9218d4331bb2 |
children | 79c8a70e1813 |
comparison
equal
deleted
inserted
replaced
4232:0fbe5c605eb6 | 4233:d01b8d002619 |
---|---|
19 | 19 |
20 | 20 |
21 from functools import partial | 21 from functools import partial |
22 import importlib | 22 import importlib |
23 import logging | 23 import logging |
24 from typing import Any | |
24 | 25 |
25 | 26 |
26 from libervia.backend.core.i18n import _ | 27 from libervia.backend.core.i18n import _ |
27 from libervia.backend.tools.common import data_format | 28 from libervia.backend.tools.common import data_format |
28 from libervia.cli.constants import Const as C | 29 from libervia.cli.constants import Const as C |
29 from libervia.frontends.tools import jid | 30 from libervia.frontends.tools import jid |
31 from libervia.frontends.tools.webrtc_models import CallData | |
30 | 32 |
31 from . import base | 33 from . import base |
32 from .call_webrtc import CallData, WebRTCCall | |
33 | 34 |
34 __commands__ = ["Call"] | 35 __commands__ = ["Call"] |
35 | 36 |
36 | 37 |
37 class Common(base.CommandBase): | 38 class Common(base.CommandBase): |
56 | 57 |
57 def add_parser_options(self): | 58 def add_parser_options(self): |
58 self.parser.add_argument( | 59 self.parser.add_argument( |
59 "--no-ui", action="store_true", help=_("disable user interface") | 60 "--no-ui", action="store_true", help=_("disable user interface") |
60 ) | 61 ) |
62 sources_group = self.parser.add_mutually_exclusive_group() | |
63 sources_group.add_argument( | |
64 "-s", "--sources", choices=['auto', 'test'], default='auto', | |
65 help='Well-known sources to use (default: "auto").' | |
66 ) | |
67 | |
68 def get_call_data_kw(self) -> dict[str, Any]: | |
69 """Get relevant keyword arguments for CallData""" | |
70 kwargs: dict[str, Any] = {} | |
71 if self.args.sources == "test": | |
72 kwargs["sources"] = "test" | |
73 return kwargs | |
74 | |
61 | 75 |
62 async def start(self): | 76 async def start(self): |
63 root_logger = logging.getLogger() | 77 root_logger = logging.getLogger() |
64 # we don't want any formatting for messages from webrtc | 78 # we don't want any formatting for messages from webrtc |
65 for handler in root_logger.handlers: | 79 for handler in root_logger.handlers: |
118 | 132 |
119 async def start(self): | 133 async def start(self): |
120 await super().start() | 134 await super().start() |
121 await super().output(CallData( | 135 await super().output(CallData( |
122 callee=jid.JID(self.args.entity), | 136 callee=jid.JID(self.args.entity), |
137 kwargs=self.get_call_data_kw() | |
123 )) | 138 )) |
124 | 139 |
125 | 140 |
126 class Receive(Common): | 141 class Receive(Common): |
127 def __init__(self, host): | 142 def __init__(self, host): |
176 self.disp(_("✅ Incoming call from {caller} accepted.").format(caller=caller)) | 191 self.disp(_("✅ Incoming call from {caller} accepted.").format(caller=caller)) |
177 | 192 |
178 await super().output(CallData( | 193 await super().output(CallData( |
179 callee=peer_jid, | 194 callee=peer_jid, |
180 sid=action_data["session_id"], | 195 sid=action_data["session_id"], |
181 action_id=action_id | 196 action_id=action_id, |
197 kwargs=self.get_call_data_kw() | |
182 )) | 198 )) |
183 | 199 |
184 async def start(self): | 200 async def start(self): |
185 await super().start() | 201 await super().start() |
186 self.host.bridge.register_signal("action_new", self.on_action_new, "core") | 202 self.host.bridge.register_signal("action_new", self.on_action_new, "core") |