annotate libervia/backend/plugins/plugin_xep_0166/models.py @ 4332:71c939e34ca6

XEP-0373 (OX): Adjust to gpgme updates: generate with explicit algorithm and subkeys
author Syndace <me@syndace.dev>
date Sat, 13 Jul 2024 18:28:28 +0200
parents 0d7bb4df2343
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # Libervia plugin for Jingle (XEP-0166)
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 import abc
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from dataclasses import dataclass
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from typing import Awaitable, Callable, Union
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
23
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from twisted.internet import defer
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from twisted.words.xish import domish
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
26
4112
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
27 from libervia.backend.core import exceptions
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4052
diff changeset
28 from libervia.backend.core.core_types import SatXMPPEntity
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4052
diff changeset
29 from libervia.backend.core.i18n import _
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
30
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
31
4112
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
32 class BaseApplicationHandler(abc.ABC):
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
33
4112
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
34 @abc.abstractmethod
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
35 async def jingle_preflight(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
36 self, client: SatXMPPEntity, session: dict, description_elt: domish.Element
4112
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
37 ) -> None:
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
38 """Called when preparation steps are needed by a plugin
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
39
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
40 Notably used by XEP-0353 when a initiation message is received
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
41 """
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
42 pass
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
43
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
44 @abc.abstractmethod
4115
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
45 async def jingle_preflight_info(
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
46 self,
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
47 client: SatXMPPEntity,
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
48 session: dict,
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
49 info_type: str,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
50 info_data: dict | None = None,
4115
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
51 ) -> None:
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
52 """Called when we have new information during preflight
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
53
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
54 Notably used by XEP-0353 to signal ringing
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
55 """
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
56 pass
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
57
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
58 @abc.abstractmethod
4112
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
59 async def jingle_preflight_cancel(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
60 self, client: SatXMPPEntity, session: dict, cancel_error: exceptions.CancelError
4112
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
61 ) -> None:
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
62 """Called when preflight initiation is cancelled
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
63
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
64 Notably used by XEP-0353 when an initiation message is cancelled
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
65 """
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
66 pass
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
67
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 @abc.abstractmethod
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 def jingle_request_confirmation(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 self,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 client: SatXMPPEntity,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 action: str,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 session: dict,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 content_name: str,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 desc_elt: domish.Element,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 ) -> Union[
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
77 Callable[..., Union[bool, defer.Deferred]], Callable[..., Awaitable[bool]]
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 ]:
4112
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
79 """If present, it is called on when session must be accepted.
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 If not present, a generic accept dialog will be used.
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
81
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 @param session: Jingle Session
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 @param desc_elt: <description> element
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 @return: True if the session is accepted.
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 A Deferred can be returned.
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 """
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 pass
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
88
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 @abc.abstractmethod
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 def jingle_session_init(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
91 self, client: SatXMPPEntity, session: dict, content_name: str, *args, **kwargs
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
92 ) -> Union[Callable[..., domish.Element], Callable[..., Awaitable[domish.Element]]]:
4112
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
93 """Must return the domish.Element used for initial content.
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
94
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 @param client: SatXMPPEntity instance
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 @param session: Jingle Session
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 @param content_name: Name of the content
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 @return: The domish.Element used for initial content
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 """
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 pass
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
101
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 @abc.abstractmethod
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 def jingle_handler(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 self,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 client: SatXMPPEntity,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 action: str,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 session: dict,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 content_name: str,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
109 transport_elt: domish.Element,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
110 ) -> Union[Callable[..., None], Callable[..., Awaitable[None]]]:
4112
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
111 """Called on several actions to negotiate the application or transport.
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
112
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 @param client: SatXMPPEntity instance
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 @param action: Jingle action
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 @param session: Jingle Session
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 @param content_name: Name of the content
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 @param transport_elt: Transport element
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 """
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 pass
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
120
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 @abc.abstractmethod
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 def jingle_terminate(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 self,
4052
2ced30f6d5de plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
124 client: SatXMPPEntity,
2ced30f6d5de plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
125 action: str,
2ced30f6d5de plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
126 session: dict,
2ced30f6d5de plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
127 content_name: str,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
128 reason_elt: domish.Element,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
129 ) -> Union[Callable[..., None], Callable[..., Awaitable[None]]]:
4112
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
130 """Called on session terminate, with reason_elt.
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 May be used to clean session.
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
132
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 @param reason_elt: Reason element
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 """
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 pass
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
136
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
137
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 class BaseTransportHandler(abc.ABC):
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
139
4231
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4115
diff changeset
140 def is_usable(self, client, content_data: "ContentData") -> bool:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4115
diff changeset
141 """Return True if this transport is usable with given content
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4115
diff changeset
142
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4115
diff changeset
143 This method provides a default implementation that always returns True. It can
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4115
diff changeset
144 be overridden in subclasses to provide custom usability logic.
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4115
diff changeset
145
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4115
diff changeset
146 @param client: SatXMPPEntity instance
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4115
diff changeset
147 @param content_data: Jingle content data.
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4115
diff changeset
148 @return: True if the transport is usable with this content, False otherwise
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4115
diff changeset
149 """
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4115
diff changeset
150 return True
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4115
diff changeset
151
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 @abc.abstractmethod
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 def jingle_session_init(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
154 self, client: SatXMPPEntity, session: dict, content_name: str, *args, **kwargs
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
155 ) -> Union[Callable[..., domish.Element], Callable[..., Awaitable[domish.Element]]]:
4112
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
156 """Must return the domish.Element used for initial content.
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
157
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 @param client: SatXMPPEntity instance
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 @param session: Jingle Session
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 @param content_name: Name of the content
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 @return: The domish.Element used for initial content
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 """
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 pass
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
164
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 @abc.abstractmethod
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 def jingle_handler(
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 self,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 client: SatXMPPEntity,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 action: str,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 session: dict,
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 content_name: str,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
172 reason_elt: domish.Element,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
173 ) -> Union[Callable[..., None], Callable[..., Awaitable[None]]]:
4112
bc60875cb3b8 plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
174 """Called on several actions to negotiate the application or transport.
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
175
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 @param client: SatXMPPEntity instance
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 @param action: Jingle action
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 @param session: Jingle Session
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 @param content_name: Name of the content
4052
2ced30f6d5de plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents: 4044
diff changeset
180 @param reason_elt: <reason> element
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 """
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 pass
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
183
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
184
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 @dataclass(frozen=True)
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 class ApplicationData:
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 namespace: str
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 handler: BaseApplicationHandler
4240
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
189 priority: int
4044
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
190
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
191
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 @dataclass(frozen=True)
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 class TransportData:
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 namespace: str
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 handler: BaseTransportHandler
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 priority: int
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
197
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
198
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 @dataclass(frozen=True)
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 class ContentData:
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 application: ApplicationData
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 app_args: list
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 app_kwargs: dict
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
204 transport_data: dict
3900626bc100 plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
205 content_name: str