comparison libervia/backend/plugins/plugin_xep_0166/models.py @ 4071:4b842c1fb686

refactoring: renamed `sat` package to `libervia.backend`
author Goffi <goffi@goffi.org>
date Fri, 02 Jun 2023 11:49:51 +0200
parents sat/plugins/plugin_xep_0166/models.py@2ced30f6d5de
children bc60875cb3b8
comparison
equal deleted inserted replaced
4070:d10748475025 4071:4b842c1fb686
1 #!/usr/bin/env python3
2
3 # Libervia plugin for Jingle (XEP-0166)
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
5
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
15
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19
20 import abc
21 from dataclasses import dataclass
22 from typing import Awaitable, Callable, Union
23
24 from twisted.internet import defer
25 from twisted.words.xish import domish
26
27 from libervia.backend.core.core_types import SatXMPPEntity
28 from libervia.backend.core.i18n import _
29
30
31 class BaseApplicationHandler(abc.ABC):
32
33 @abc.abstractmethod
34 def jingle_request_confirmation(
35 self,
36 client: SatXMPPEntity,
37 action: str,
38 session: dict,
39 content_name: str,
40 desc_elt: domish.Element,
41 ) -> Union[
42 Callable[..., Union[bool, defer.Deferred]],
43 Callable[..., Awaitable[bool]]
44 ]:
45 """
46 If present, it is called on when session must be accepted.
47 If not present, a generic accept dialog will be used.
48
49 @param session: Jingle Session
50 @param desc_elt: <description> element
51 @return: True if the session is accepted.
52 A Deferred can be returned.
53 """
54 pass
55
56 @abc.abstractmethod
57 def jingle_session_init(
58 self,
59 client: SatXMPPEntity,
60 session: dict,
61 content_name: str,
62 *args, **kwargs
63 ) -> Union[
64 Callable[..., domish.Element],
65 Callable[..., Awaitable[domish.Element]]
66 ]:
67 """
68 Must return the domish.Element used for initial content.
69
70 @param client: SatXMPPEntity instance
71 @param session: Jingle Session
72 @param content_name: Name of the content
73 @return: The domish.Element used for initial content
74 """
75 pass
76
77 @abc.abstractmethod
78 def jingle_handler(
79 self,
80 client: SatXMPPEntity,
81 action: str,
82 session: dict,
83 content_name: str,
84 transport_elt: domish.Element
85 ) -> Union[
86 Callable[..., None],
87 Callable[..., Awaitable[None]]
88 ]:
89 """
90 Called on several actions to negotiate the application or transport.
91
92 @param client: SatXMPPEntity instance
93 @param action: Jingle action
94 @param session: Jingle Session
95 @param content_name: Name of the content
96 @param transport_elt: Transport element
97 """
98 pass
99
100 @abc.abstractmethod
101 def jingle_terminate(
102 self,
103 client: SatXMPPEntity,
104 action: str,
105 session: dict,
106 content_name: str,
107 reason_elt: domish.Element
108 ) -> Union[
109 Callable[..., None],
110 Callable[..., Awaitable[None]]
111 ]:
112 """
113 Called on session terminate, with reason_elt.
114 May be used to clean session.
115
116 @param reason_elt: Reason element
117 """
118 pass
119
120
121 class BaseTransportHandler(abc.ABC):
122
123 @abc.abstractmethod
124 def jingle_session_init(
125 self,
126 client: SatXMPPEntity,
127 session: dict,
128 content_name: str,
129 *args, **kwargs
130 ) -> Union[
131 Callable[..., domish.Element],
132 Callable[..., Awaitable[domish.Element]]
133 ]:
134 """
135 Must return the domish.Element used for initial content.
136
137 @param client: SatXMPPEntity instance
138 @param session: Jingle Session
139 @param content_name: Name of the content
140 @return: The domish.Element used for initial content
141 """
142 pass
143
144 @abc.abstractmethod
145 def jingle_handler(
146 self,
147 client: SatXMPPEntity,
148 action: str,
149 session: dict,
150 content_name: str,
151 reason_elt: domish.Element
152 ) -> Union[
153 Callable[..., None],
154 Callable[..., Awaitable[None]]
155 ]:
156 """
157 Called on several actions to negotiate the application or transport.
158
159 @param client: SatXMPPEntity instance
160 @param action: Jingle action
161 @param session: Jingle Session
162 @param content_name: Name of the content
163 @param reason_elt: <reason> element
164 """
165 pass
166
167
168 @dataclass(frozen=True)
169 class ApplicationData:
170 namespace: str
171 handler: BaseApplicationHandler
172
173
174 @dataclass(frozen=True)
175 class TransportData:
176 namespace: str
177 handler: BaseTransportHandler
178 priority: int
179
180
181 @dataclass(frozen=True)
182 class ContentData:
183 application: ApplicationData
184 app_args: list
185 app_kwargs: dict
186 transport_data: dict
187 content_name: str