caprid-relay 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- caprid_relay-0.1.0/LICENSE +202 -0
- caprid_relay-0.1.0/PKG-INFO +90 -0
- caprid_relay-0.1.0/README.md +78 -0
- caprid_relay-0.1.0/pyproject.toml +22 -0
- caprid_relay-0.1.0/pyproject.toml.orig +22 -0
- caprid_relay-0.1.0/src/caprid_relay/__init__.py +133 -0
- caprid_relay-0.1.0/src/caprid_relay/_awaitable.py +59 -0
- caprid_relay-0.1.0/src/caprid_relay/_bounded_events.py +166 -0
- caprid_relay-0.1.0/src/caprid_relay/_frame_reader.py +179 -0
- caprid_relay-0.1.0/src/caprid_relay/_settling_groups.py +136 -0
- caprid_relay-0.1.0/src/caprid_relay/_subscription.py +515 -0
- caprid_relay-0.1.0/src/caprid_relay/_supervision.py +302 -0
- caprid_relay-0.1.0/src/caprid_relay/_validation.py +168 -0
- caprid_relay-0.1.0/src/caprid_relay/_write_slot.py +927 -0
- caprid_relay-0.1.0/src/caprid_relay/cancellation.py +68 -0
- caprid_relay-0.1.0/src/caprid_relay/connect.py +449 -0
- caprid_relay-0.1.0/src/caprid_relay/connect_session.py +563 -0
- caprid_relay-0.1.0/src/caprid_relay/errors.py +153 -0
- caprid_relay-0.1.0/src/caprid_relay/media.py +1076 -0
- caprid_relay-0.1.0/src/caprid_relay/namespace_events.py +218 -0
- caprid_relay-0.1.0/src/caprid_relay/payload.py +30 -0
- caprid_relay-0.1.0/src/caprid_relay/publish.py +349 -0
- caprid_relay-0.1.0/src/caprid_relay/py.typed +0 -0
- caprid_relay-0.1.0/src/caprid_relay/quic/__init__.py +22 -0
- caprid_relay-0.1.0/src/caprid_relay/quic/_aioquic.py +160 -0
- caprid_relay-0.1.0/src/caprid_relay/quic/_client.py +332 -0
- caprid_relay-0.1.0/src/caprid_relay/quic/_errors.py +116 -0
- caprid_relay-0.1.0/src/caprid_relay/quic/_fin_retry.py +105 -0
- caprid_relay-0.1.0/src/caprid_relay/quic/_protocol.py +337 -0
- caprid_relay-0.1.0/src/caprid_relay/quic/_session.py +400 -0
- caprid_relay-0.1.0/src/caprid_relay/quic/_streams.py +373 -0
- caprid_relay-0.1.0/src/caprid_relay/quic/_udp.py +114 -0
- caprid_relay-0.1.0/src/caprid_relay/room_endpoint.py +62 -0
- caprid_relay-0.1.0/src/caprid_relay/subscription_events.py +87 -0
- caprid_relay-0.1.0/src/caprid_relay/supervised_publisher.py +1097 -0
- caprid_relay-0.1.0/src/caprid_relay/supervised_subscriber.py +1817 -0
- caprid_relay-0.1.0/src/caprid_relay/switchable.py +566 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: caprid-relay
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Relay Python SDK
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Dist: caprid-moq-core==0.1.0
|
|
8
|
+
Requires-Dist: aioquic>=1.3,<1.4
|
|
9
|
+
Requires-Python: >=3.11
|
|
10
|
+
Project-URL: Repository, https://github.com/caprids/relay-sdks
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# caprid-relay
|
|
14
|
+
|
|
15
|
+
The Relay Python SDK. `connect_relay_subscriber` subscribes to track objects and
|
|
16
|
+
`connect_relay_publisher` publishes them, through Relay, Mux's Media over QUIC (MoQ) relay service.
|
|
17
|
+
Payloads are bytes the SDK does not interpret; no browser, player, or media catalog is needed.
|
|
18
|
+
|
|
19
|
+
## Requirements
|
|
20
|
+
|
|
21
|
+
- Python 3.11+ and asyncio.
|
|
22
|
+
- The default transport is native QUIC (MOQT directly on QUIC) through aioquic, installed as a dependency. The
|
|
23
|
+
endpoint and network must allow QUIC/UDP traffic. Other transports can be passed as
|
|
24
|
+
`create_transport`.
|
|
25
|
+
- A Relay endpoint and a short-lived Relay JWT authorized for the namespace you use. The SDK
|
|
26
|
+
consumes tokens; it does not issue them.
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
The package is unpublished and its name is provisional. Install it together with its local
|
|
31
|
+
`caprid-moq-core` dependency from a checkout of this repository, as described in
|
|
32
|
+
[Use the local packages in your application](../../README.md#use-the-local-packages-in-your-application).
|
|
33
|
+
|
|
34
|
+
## Publish and subscribe
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
import asyncio
|
|
38
|
+
|
|
39
|
+
from caprid_relay import (
|
|
40
|
+
MoqtObject,
|
|
41
|
+
RelaySubscriptionHandlers,
|
|
42
|
+
connect_relay_publisher,
|
|
43
|
+
connect_relay_subscriber,
|
|
44
|
+
read_text,
|
|
45
|
+
room_endpoint,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
async def main(token: str) -> None:
|
|
50
|
+
url = room_endpoint("https://relay.mux.global", ["team"]) # your token's root as the path
|
|
51
|
+
namespace = ["quickstart", "unique-run"] # relative to that root
|
|
52
|
+
arrived: asyncio.Future[str] = asyncio.get_running_loop().create_future()
|
|
53
|
+
|
|
54
|
+
def on_object(obj: MoqtObject) -> None:
|
|
55
|
+
if obj.status == "normal" and not arrived.done():
|
|
56
|
+
arrived.set_result(read_text(obj))
|
|
57
|
+
|
|
58
|
+
async with (
|
|
59
|
+
await connect_relay_publisher(url, namespace=namespace, get_token=lambda: token) as publisher,
|
|
60
|
+
await connect_relay_subscriber(url, get_token=lambda: token) as subscriber,
|
|
61
|
+
):
|
|
62
|
+
ticker = publisher.register_track("ticker")
|
|
63
|
+
await publisher.announced
|
|
64
|
+
subscription = subscriber.subscribe(namespace, "ticker", RelaySubscriptionHandlers(on_object=on_object))
|
|
65
|
+
await subscription.subscribed # a fresh namespace can briefly reject this with error 16; retry it
|
|
66
|
+
await ticker.write_text("hello from caprid-relay") # waits for the subscriber's demand
|
|
67
|
+
print(await arrived)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The [guide's first round trip](../../README.md#first-round-trip) runs the complete version of this,
|
|
71
|
+
with credential handling, the subscribe retry, a deadline, and cleanup on failure.
|
|
72
|
+
|
|
73
|
+
## Stability
|
|
74
|
+
|
|
75
|
+
Before 1.0, a minor version can break the API, and [CHANGELOG.md](../../CHANGELOG.md) says what
|
|
76
|
+
changed. `caprid-relay`, `caprid-moq-core` and `caprid-moq-media` always release together at the same
|
|
77
|
+
version, and `caprid-relay` pins `caprid-moq-core` exactly. A release supports Python 3.11 or later, and
|
|
78
|
+
MOQT draft 22 (`moqt-22`), with draft 20 (`moqt-20`) as an offered fallback, against moq-relay
|
|
79
|
+
0.15.4 or later.
|
|
80
|
+
|
|
81
|
+
## Documentation
|
|
82
|
+
|
|
83
|
+
- [Python guide](../../README.md): the quickstart, subscription and publishing lifecycles, async
|
|
84
|
+
consumption, the aioquic transport, and the Video.js media example.
|
|
85
|
+
- API reference: run `mise run python:docs` to build it from the source.
|
|
86
|
+
- [Errors and recovery](../../README.md#errors-and-recovery): stable `RelayError.code` and `phase`
|
|
87
|
+
values, preserved exception subclasses and transport causes, and recovering without assuming
|
|
88
|
+
delivery or safe replay.
|
|
89
|
+
- [Shared specification](../../../spec/README.md): the protocol pins, behavior contract, and test
|
|
90
|
+
vectors every Relay SDK implements.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# caprid-relay
|
|
2
|
+
|
|
3
|
+
The Relay Python SDK. `connect_relay_subscriber` subscribes to track objects and
|
|
4
|
+
`connect_relay_publisher` publishes them, through Relay, Mux's Media over QUIC (MoQ) relay service.
|
|
5
|
+
Payloads are bytes the SDK does not interpret; no browser, player, or media catalog is needed.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- Python 3.11+ and asyncio.
|
|
10
|
+
- The default transport is native QUIC (MOQT directly on QUIC) through aioquic, installed as a dependency. The
|
|
11
|
+
endpoint and network must allow QUIC/UDP traffic. Other transports can be passed as
|
|
12
|
+
`create_transport`.
|
|
13
|
+
- A Relay endpoint and a short-lived Relay JWT authorized for the namespace you use. The SDK
|
|
14
|
+
consumes tokens; it does not issue them.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
The package is unpublished and its name is provisional. Install it together with its local
|
|
19
|
+
`caprid-moq-core` dependency from a checkout of this repository, as described in
|
|
20
|
+
[Use the local packages in your application](../../README.md#use-the-local-packages-in-your-application).
|
|
21
|
+
|
|
22
|
+
## Publish and subscribe
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
import asyncio
|
|
26
|
+
|
|
27
|
+
from caprid_relay import (
|
|
28
|
+
MoqtObject,
|
|
29
|
+
RelaySubscriptionHandlers,
|
|
30
|
+
connect_relay_publisher,
|
|
31
|
+
connect_relay_subscriber,
|
|
32
|
+
read_text,
|
|
33
|
+
room_endpoint,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
async def main(token: str) -> None:
|
|
38
|
+
url = room_endpoint("https://relay.mux.global", ["team"]) # your token's root as the path
|
|
39
|
+
namespace = ["quickstart", "unique-run"] # relative to that root
|
|
40
|
+
arrived: asyncio.Future[str] = asyncio.get_running_loop().create_future()
|
|
41
|
+
|
|
42
|
+
def on_object(obj: MoqtObject) -> None:
|
|
43
|
+
if obj.status == "normal" and not arrived.done():
|
|
44
|
+
arrived.set_result(read_text(obj))
|
|
45
|
+
|
|
46
|
+
async with (
|
|
47
|
+
await connect_relay_publisher(url, namespace=namespace, get_token=lambda: token) as publisher,
|
|
48
|
+
await connect_relay_subscriber(url, get_token=lambda: token) as subscriber,
|
|
49
|
+
):
|
|
50
|
+
ticker = publisher.register_track("ticker")
|
|
51
|
+
await publisher.announced
|
|
52
|
+
subscription = subscriber.subscribe(namespace, "ticker", RelaySubscriptionHandlers(on_object=on_object))
|
|
53
|
+
await subscription.subscribed # a fresh namespace can briefly reject this with error 16; retry it
|
|
54
|
+
await ticker.write_text("hello from caprid-relay") # waits for the subscriber's demand
|
|
55
|
+
print(await arrived)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The [guide's first round trip](../../README.md#first-round-trip) runs the complete version of this,
|
|
59
|
+
with credential handling, the subscribe retry, a deadline, and cleanup on failure.
|
|
60
|
+
|
|
61
|
+
## Stability
|
|
62
|
+
|
|
63
|
+
Before 1.0, a minor version can break the API, and [CHANGELOG.md](../../CHANGELOG.md) says what
|
|
64
|
+
changed. `caprid-relay`, `caprid-moq-core` and `caprid-moq-media` always release together at the same
|
|
65
|
+
version, and `caprid-relay` pins `caprid-moq-core` exactly. A release supports Python 3.11 or later, and
|
|
66
|
+
MOQT draft 22 (`moqt-22`), with draft 20 (`moqt-20`) as an offered fallback, against moq-relay
|
|
67
|
+
0.15.4 or later.
|
|
68
|
+
|
|
69
|
+
## Documentation
|
|
70
|
+
|
|
71
|
+
- [Python guide](../../README.md): the quickstart, subscription and publishing lifecycles, async
|
|
72
|
+
consumption, the aioquic transport, and the Video.js media example.
|
|
73
|
+
- API reference: run `mise run python:docs` to build it from the source.
|
|
74
|
+
- [Errors and recovery](../../README.md#errors-and-recovery): stable `RelayError.code` and `phase`
|
|
75
|
+
values, preserved exception subclasses and transport causes, and recovering without assuming
|
|
76
|
+
delivery or safe replay.
|
|
77
|
+
- [Shared specification](../../../spec/README.md): the protocol pins, behavior contract, and test
|
|
78
|
+
vectors every Relay SDK implements.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "caprid-relay"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Relay Python SDK"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.11"
|
|
9
|
+
dependencies = [
|
|
10
|
+
"caprid-moq-core==0.1.0",
|
|
11
|
+
"aioquic>=1.3,<1.4",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[project.urls]
|
|
15
|
+
Repository = "https://github.com/caprids/relay-sdks"
|
|
16
|
+
|
|
17
|
+
[tool.uv.sources.caprid-moq-core]
|
|
18
|
+
workspace = true
|
|
19
|
+
|
|
20
|
+
[build-system]
|
|
21
|
+
requires = ["uv_build>=0.12,<0.13"]
|
|
22
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "caprid-relay"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Relay Python SDK"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.11"
|
|
9
|
+
# The product package owns the Relay API, the authentication convention, and the default
|
|
10
|
+
# transport: native QUIC through aioquic, so this SDK runs natively with no browser.
|
|
11
|
+
# caprid-moq-core is released in lockstep, so the pin is exact; scripts/release_version.py moves it.
|
|
12
|
+
dependencies = ["caprid-moq-core==0.1.0", "aioquic>=1.3,<1.4"]
|
|
13
|
+
|
|
14
|
+
[project.urls]
|
|
15
|
+
Repository = "https://github.com/caprids/relay-sdks"
|
|
16
|
+
|
|
17
|
+
[tool.uv.sources]
|
|
18
|
+
caprid-moq-core = { workspace = true }
|
|
19
|
+
|
|
20
|
+
[build-system]
|
|
21
|
+
requires = ["uv_build>=0.12,<0.13"]
|
|
22
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""Relay Python SDK.
|
|
2
|
+
|
|
3
|
+
Owns the Relay product API and authentication convention, built on ``moq_core``. The default
|
|
4
|
+
transport is native QUIC through aioquic (``caprid_relay.quic``), which reaches a relay natively with no
|
|
5
|
+
browser; ``create_transport`` swaps in another implementation of the same seam.
|
|
6
|
+
|
|
7
|
+
The public names are the rows of ``spec/vocabulary.md``, pinned by ``tests/test_exports.py``. From
|
|
8
|
+
the core this package re-exports exactly what ``@caprid/relay`` re-exports, plus ``Closed``; every
|
|
9
|
+
other protocol type (location filters, fetch, track status, the constants) is imported from
|
|
10
|
+
``moq_core``, a declared dependency.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from moq_core import (
|
|
14
|
+
Closed,
|
|
15
|
+
Goaway,
|
|
16
|
+
KeyValuePair,
|
|
17
|
+
LocationFilter,
|
|
18
|
+
MessageParameters,
|
|
19
|
+
MoqtObject,
|
|
20
|
+
MoqTrackSource,
|
|
21
|
+
MoqtTransport,
|
|
22
|
+
PublishDone,
|
|
23
|
+
RequestError,
|
|
24
|
+
SubscribeOk,
|
|
25
|
+
Subscription,
|
|
26
|
+
SubscriptionHandlers,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
from ._awaitable import RelayAwaitable
|
|
30
|
+
from ._subscription import RelaySubscription, SubscriptionEnd, SubscriptionEndKind
|
|
31
|
+
from ._supervision import SupervisedStatus, SupervisionBackoff
|
|
32
|
+
from .cancellation import CancellationToken, Cancelled
|
|
33
|
+
from .connect import RelaySubscriber, RelaySubscriptionHandlers, connect_relay_subscriber
|
|
34
|
+
from .connect_session import ConnectingTransport, RelayCredential, RelayTransportFactory
|
|
35
|
+
from .errors import RelayError, RelayErrorCode, RelayErrorPhase
|
|
36
|
+
from .namespace_events import NamespaceEvent, NamespaceEvents
|
|
37
|
+
from .payload import read_json, read_text
|
|
38
|
+
from .publish import RelayGroupWriter, RelayPublisher, RelayTrackWriter, connect_relay_publisher
|
|
39
|
+
from .room_endpoint import room_endpoint
|
|
40
|
+
from .subscription_events import (
|
|
41
|
+
GoawayEvent,
|
|
42
|
+
ObjectEvent,
|
|
43
|
+
PublisherDoneEvent,
|
|
44
|
+
StateNotifyEvent,
|
|
45
|
+
SubgroupEndEvent,
|
|
46
|
+
SubgroupResetEvent,
|
|
47
|
+
SubscribedEvent,
|
|
48
|
+
SubscriptionConnectionClosedError,
|
|
49
|
+
SubscriptionEvent,
|
|
50
|
+
SubscriptionEvents,
|
|
51
|
+
SubscriptionOverflowError,
|
|
52
|
+
SubscriptionRequestError,
|
|
53
|
+
UpdateOkEvent,
|
|
54
|
+
)
|
|
55
|
+
from .supervised_publisher import PublisherGeneration, SupervisedPublisher, connect_supervised_publisher
|
|
56
|
+
from .supervised_subscriber import (
|
|
57
|
+
RestartReason,
|
|
58
|
+
SupervisedSubscriber,
|
|
59
|
+
WantHandlers,
|
|
60
|
+
WantSwitchedInfo,
|
|
61
|
+
connect_supervised_subscriber,
|
|
62
|
+
)
|
|
63
|
+
from .switchable import SwitchableHandlers, SwitchableSubscription, SwitchedInfo
|
|
64
|
+
|
|
65
|
+
DEFAULT_ENDPOINT = "https://relay.mux.global"
|
|
66
|
+
"""The default Relay endpoint pinned in ``spec/protocol.json``."""
|
|
67
|
+
|
|
68
|
+
__all__ = [
|
|
69
|
+
"DEFAULT_ENDPOINT",
|
|
70
|
+
"CancellationToken",
|
|
71
|
+
"Cancelled",
|
|
72
|
+
"Closed",
|
|
73
|
+
"ConnectingTransport",
|
|
74
|
+
"Goaway",
|
|
75
|
+
"GoawayEvent",
|
|
76
|
+
"KeyValuePair",
|
|
77
|
+
"LocationFilter",
|
|
78
|
+
"MessageParameters",
|
|
79
|
+
"MoqTrackSource",
|
|
80
|
+
"MoqtObject",
|
|
81
|
+
"MoqtTransport",
|
|
82
|
+
"NamespaceEvent",
|
|
83
|
+
"NamespaceEvents",
|
|
84
|
+
"ObjectEvent",
|
|
85
|
+
"PublishDone",
|
|
86
|
+
"PublisherDoneEvent",
|
|
87
|
+
"PublisherGeneration",
|
|
88
|
+
"RelayAwaitable",
|
|
89
|
+
"RelayCredential",
|
|
90
|
+
"RelayError",
|
|
91
|
+
"RelayErrorCode",
|
|
92
|
+
"RelayErrorPhase",
|
|
93
|
+
"RelayGroupWriter",
|
|
94
|
+
"RelayPublisher",
|
|
95
|
+
"RelaySubscriber",
|
|
96
|
+
"RelaySubscription",
|
|
97
|
+
"RelaySubscriptionHandlers",
|
|
98
|
+
"RelayTrackWriter",
|
|
99
|
+
"RelayTransportFactory",
|
|
100
|
+
"RequestError",
|
|
101
|
+
"RestartReason",
|
|
102
|
+
"StateNotifyEvent",
|
|
103
|
+
"SubgroupEndEvent",
|
|
104
|
+
"SubgroupResetEvent",
|
|
105
|
+
"SubscribeOk",
|
|
106
|
+
"SubscribedEvent",
|
|
107
|
+
"Subscription",
|
|
108
|
+
"SubscriptionConnectionClosedError",
|
|
109
|
+
"SubscriptionEnd",
|
|
110
|
+
"SubscriptionEndKind",
|
|
111
|
+
"SubscriptionEvent",
|
|
112
|
+
"SubscriptionEvents",
|
|
113
|
+
"SubscriptionHandlers",
|
|
114
|
+
"SubscriptionOverflowError",
|
|
115
|
+
"SubscriptionRequestError",
|
|
116
|
+
"SupervisedPublisher",
|
|
117
|
+
"SupervisedStatus",
|
|
118
|
+
"SupervisedSubscriber",
|
|
119
|
+
"SupervisionBackoff",
|
|
120
|
+
"SwitchableHandlers",
|
|
121
|
+
"SwitchableSubscription",
|
|
122
|
+
"SwitchedInfo",
|
|
123
|
+
"UpdateOkEvent",
|
|
124
|
+
"WantHandlers",
|
|
125
|
+
"WantSwitchedInfo",
|
|
126
|
+
"connect_relay_publisher",
|
|
127
|
+
"connect_relay_subscriber",
|
|
128
|
+
"connect_supervised_publisher",
|
|
129
|
+
"connect_supervised_subscriber",
|
|
130
|
+
"read_json",
|
|
131
|
+
"read_text",
|
|
132
|
+
"room_endpoint",
|
|
133
|
+
]
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""The type of every fact the SDK settles once and lets any number of tasks await."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import contextvars
|
|
7
|
+
from collections.abc import Callable, Generator
|
|
8
|
+
from typing import Any, Generic, TypeVar
|
|
9
|
+
|
|
10
|
+
_T = TypeVar("_T")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class RelayAwaitable(Generic[_T]):
|
|
14
|
+
"""A fact the SDK settles once: a subscription's ``subscribed`` or ``ended``, a publisher's
|
|
15
|
+
``announced``, or a connection's ``closed``.
|
|
16
|
+
|
|
17
|
+
Await it as often as needed. Each waiter is isolated: a task cancelled while awaiting, or an
|
|
18
|
+
``asyncio.wait_for`` that times out, never touches the underlying result, where handing out the
|
|
19
|
+
future itself would let one impatient waiter destroy the signal for every later one. ``done()``,
|
|
20
|
+
``result()``, ``exception()`` and ``add_done_callback()`` read the result directly and allocate
|
|
21
|
+
nothing, so polling is free. It is not an :class:`asyncio.Future`: it cannot be cancelled or
|
|
22
|
+
set. Wrap it with :func:`asyncio.ensure_future` for an API that needs a future.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
__slots__ = ("_future",)
|
|
26
|
+
|
|
27
|
+
def __init__(self, future: asyncio.Future[_T]) -> None:
|
|
28
|
+
self._future = future
|
|
29
|
+
|
|
30
|
+
def __await__(self) -> Generator[Any, None, _T]:
|
|
31
|
+
future = self._future
|
|
32
|
+
if not future.done():
|
|
33
|
+
future = asyncio.shield(future)
|
|
34
|
+
return future.__await__()
|
|
35
|
+
|
|
36
|
+
def done(self) -> bool:
|
|
37
|
+
"""Whether the result is in."""
|
|
38
|
+
return self._future.done()
|
|
39
|
+
|
|
40
|
+
def result(self) -> _T:
|
|
41
|
+
"""The result; raises what awaiting would, or ``asyncio.InvalidStateError`` while pending."""
|
|
42
|
+
return self._future.result()
|
|
43
|
+
|
|
44
|
+
def exception(self) -> BaseException | None:
|
|
45
|
+
"""The exception awaiting would raise, ``None`` for a plain result."""
|
|
46
|
+
return self._future.exception()
|
|
47
|
+
|
|
48
|
+
def add_done_callback(
|
|
49
|
+
self, callback: Callable[[asyncio.Future[_T]], object], *, context: contextvars.Context | None = None
|
|
50
|
+
) -> None:
|
|
51
|
+
"""Call ``callback`` with the settled future once the result is in."""
|
|
52
|
+
self._future.add_done_callback(callback, context=context)
|
|
53
|
+
|
|
54
|
+
def remove_done_callback(self, callback: Callable[[asyncio.Future[_T]], object]) -> int:
|
|
55
|
+
"""Forget a callback; returns how many registrations were removed."""
|
|
56
|
+
return self._future.remove_done_callback(callback)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
__all__ = ["RelayAwaitable"]
|