8000 Merge pull request #11 from MarshalX/main · MarshalX/python-webrtc@6c81a42 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6c81a42

Browse files
authored
Merge pull request #11 from MarshalX/main
0.0.6 dev
2 parents 0b0f883 + 899694d commit 6c81a42

38 files changed

+438
-161
lines changed

.github/codeql/codeql_config.yaml

-5
This file was deleted.

.github/codeql/codeql_config.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: "CodeQL config"
2+
paths:
3+
- 'python-webrtc'

.github/workflows/black.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Black
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
black:
7+
name: Black
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout repository.
12+
uses: actions/checkout@v2
13+
14+
- name: Setup Python.
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: 3.9
18+
19+
- name: Check code style.
20+
run: |
21+
pip install black
22+
black --check python-webrtc

.github/workflows/build.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Build
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
schedule:
8+
- cron: '0 8 * * 1'
9+
10+
jobs:
11+
build:
12+
name: Build
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository.
17+
uses: actions/checkout@v2
18+
with:
19+
submodules: recursive
20+
21+
- name: Setup Python.
22+
uses: actions/setup-python@v2
23+
with:
24+
python-version: 3.9
25+
26+
- name: Build.
27+
run: |
28+
sudo apt install -y python3.9-dev
29+
python setup.py build

.github/workflows/codeql_analysis.yml

+18-16
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ name: CodeQL
22

33
on:
44
push:
5-
branches: [ main ]
65
pull_request:
7-
# The branches below must be a subset of the branches above
8-
branches: [ main ]
96
schedule:
107
- cron: '0 8 * * 1'
118

@@ -19,31 +16,36 @@ jobs:
1916
strategy:
2017
fail-fast: false
2118
matrix:
22-
language: [ 'cpp', 'python' ]
19+
language: [
20+
# 'cpp',
21+
'python'
22+
]
2323

2424
steps:
25-
- name: Checkout repository
25+
- name: Checkout repository.
2626
uses: actions/checkout@v2
2727
with:
2828
submodules: recursive
2929

30-
- name: Setup Python
31-
uses: actions/setup-python@v1
32-
with:
33-
python-version: 3.9
34-
35-
- name: Initialize CodeQL
30+
- name: Initialize CodeQL.
3631
uses: github/codeql-action/init@v1
3732
with:
3833
languages: ${{ matrix.language }}
39-
config-file: ./.github/codeql/codeql_config.yaml
34+
setup-python-dependencies: false
35+
config-file: ./.github/codeql/codeql_config.yml
36+
37+
- name: Setup Python.
38+
if: matrix.language == 'cpp'
39+
uses: actions/setup-python@v2
40+
with:
41+
python-version: 3.9
4042

41-
- if: matrix.language == 'cpp'
42-
name: Build
43+
- name: Build.
44+
if: matrix.language == 'cpp'
4345
run: |
4446
sudo apt install -y python3.9-dev
45-
export NO_LTO=true
4647
python setup.py build
4748
48-
- name: Perform CodeQL Analysis
49+
# it takes too long for cpp
50+
- name: Perform CodeQL Analysis.
4951
uses: github/codeql-action/analyze@v1

.github/workflows/create_sdist.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: Create and publish Source Distribution
33
on:
44
push:
55
branches:
6-
- main
76
- pypi-dev
87
paths:
98
- '.github/workflows/create_sdist.yml'
@@ -23,7 +22,7 @@ jobs:
2322
submodules: recursive
2423

2524
- name: Setup Python.
26-
uses: actions/setup-python@v1
25+
uses: actions/setup-python@v2
2726
with:
2827
python-version: 3.7
2928

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ include(ExternalProject)
55

66
project(python_webrtc
77
LANGUAGES C CXX
8-
DESCRIPTION "a Python Extension that provides bindings to WebRTC"
8+
DESCRIPTION "a Python extension that provides bindings to WebRTC"
99
HOMEPAGE_URL "https://github.com/MarshalX/python-webrtc"
10-
VERSION "0.0.0.5"
10+
VERSION "0.0.0.6"
1111
)
1212

1313
include(ExternalProject)

SECURITY.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
Only the latest published version on [PyPI](https://pypi.org/project/wrtc/#history) supported with security updates.
6+
7+
## Reporting a Vulnerability
8+
9+
Email for reports: ilya@marshal.dev

docs/links/wrtc/__init__.py

+24-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
import typing
44

55
__all__ = [
6+
"CallbackPythonWebRTCException",
67
"MediaStream",
78
"MediaStreamSourceState",
89
"MediaStreamTrack",
910
"MediaStreamTrackState",
1011
"PeerConnectionFactory",
12+
"PythonWebRTCException",
13+
"PythonWebRTCExceptionBase",
1114
"RTCAudioSource",
15+
"RTCCallbackException",
16+
"RTCException",
1217
"RTCIceConnectionState",
1318
"RTCIceGatheringState",
1419
"RTCOnDataEvent",
@@ -18,6 +23,7 @@
1823
"RTCSdpType",
1924
"RTCSessionDescription",
2025
"RTCSessionDescriptionInit",
26+
"SdpParseException",
2127
"answer",
2228
"checking",
2329
"closed",
@@ -42,6 +48,9 @@
4248
]
4349

4450

51+
class CallbackPythonWebRTCException():
52+
def what(self) -> str: ...
53+
pass
4554
class MediaStream():
4655
def addTrack(self, arg0: MediaStreamTrack) -> None: ...
4756
def clone(self) -> MediaStream: ...
@@ -170,11 +179,20 @@ def getOrCreateDefault() -> PeerConnectionFactory: ...
170179
@staticmethod
171180
def release() -> None: ...
172181
pass
182+
class PythonWebRTCExceptionBase(Exception, BaseException):
183+
pass
184+
class PythonWebRTCException(PythonWebRTCExceptionBase, Exception, BaseException):
185+
pass
173186
class RTCAudioSource():
174187
def __init__(self) -> None: ...
175188
def createTrack(self) -> MediaStreamTrack: ...
176189
def onData(self, arg0: RTCOnDataEvent) -> None: ...
177190
pass
191+
class RTCCallbackException():
192+
def what(self) -> str: ...
193+
pass
194+
class RTCException(PythonWebRTCExceptionBase, Exception, BaseException):
195+
pass
178196
class RTCIceConnectionState():
179197
"""
180198
Members:
@@ -306,10 +324,10 @@ def __init__(self) -> None: ...
306324
@staticmethod
307325
def addTrack(*args, **kwargs) -> typing.Any: ...
308326
def close(self) -> None: ...
309-
def createAnswer(self, arg0: typing.Callable[[RTCSessionDescription], None]) -> None: ...
310-
def createOffer(self, arg0: typing.Callable[[RTCSessionDescription], None]) -> None: ...
311-
def setLocalDescription(self, arg0: typing.Callable[[], None], arg1: RTCSessionDescription) -> None: ...
312-
def setRemoteDescription(self, arg0: typing.Callable[[], None], arg1: RTCSessionDescription) -> None: ...
327+
def createAnswer(self, arg0: typing.Callable[[RTCSessionDescription], None], arg1: typing.Callable[[CallbackPythonWebRTCException], None]) -> None: ...
328+
def createOffer(self, arg0: typing.Callable[[RTCSessionDescription], None], arg1: typing.Callable[[CallbackPythonWebRTCException], None]) -> None: ...
329+
def setLocalDescription(self, arg0: typing.Callable[[], None], arg1: typing.Callable[[CallbackPythonWebRTCException], None], arg2: RTCSessionDescription) -> None: ...
330+
def setRemoteDescription(self, arg0: typing.Callable[[], None], arg1: typing.Callable[[CallbackPythonWebRTCException], None], arg2: RTCSessionDescription) -> None: ...
313331
pass
314332
class RTCPeerConnectionState():
315333
"""
@@ -430,6 +448,8 @@ def type(self) -> RTCSdpType:
430448
def type(self, arg0: RTCSdpType) -> None:
431449
pass
432450
pass
451+
class SdpParseException(PythonWebRTCExceptionBase, Exception, BaseException):
452+
pass
433453
def getUserMedia() -> MediaStream:
434454
pass
435455
def ping() -> None:

examples/telegram_group_calls.py

+12-20
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def parse_sdp(sdp):
2020
def lookup(prefix):
2121
for line in lines:
2222
if line.startswith(prefix):
23-
return line[len(prefix):]
23+
return line[len(prefix) :]
2424

2525
info = {
2626
'fingerprint': lookup('a=fingerprint:').split(' ')[1],
@@ -38,27 +38,23 @@ def lookup(prefix):
3838

3939
def get_params_from_parsed_sdp(info):
4040
return {
41-
'fingerprints': [
42-
{
43-
'fingerprint': info['fingerprint'],
44-
'hash': info['hash'],
45-
'setup': 'active'
46-
}
47-
],
41+
'fingerprints': [{'fingerprint': info['fingerprint'], 'hash': info['hash'], 'setup': 'active'}],
4842
'pwd': info['pwd'],
4943
'ssrc': info['source'],
5044
'ssrc-groups': [],
51-
'ufrag': info['ufrag']
45+
'ufrag': info['ufrag'],
5246
}
5347

5448

5549
def build_answer(sdp):
5650
def add_candidates():
5751
candidates_sdp = []
5852
for cand in sdp['transport']['candidates']:
59-
candidates_sdp.append(f"a=candidate:{cand['foundation']} {cand['component']} {cand['protocol']} "
60-
f"{cand['priority']} {cand['ip']} {cand['port']} typ {cand['type']} "
61-
f"generation {cand['generation']}")
53+
candidates_sdp.append(
54+
f"a=candidate:{cand['foundation']} {cand['component']} {cand['protocol']} "
55+
f"{cand['priority']} {cand['ip']} {cand['port']} typ {cand['type']} "
56+
f"generation {cand['generation']}"
57+
)
6258

6359
return '\n'.join(candidates_sdp)
6460

@@ -114,11 +110,11 @@ def get_ms_time():
114110

115111
if last_read_ms == 0 or start_time - last_read_ms >= 10:
116112
data = f.read(length)
117-
if not data: # eof
113+
if not data: # eof
118114
f.close()
119115
break
120116

121-
event_data = webrtc.RTCOnDataEvent(data, length // 4) # 2 channels
117+
event_data = webrtc.RTCOnDataEvent(data, length // 4) # 2 channels
122118
event_data.channel_count = 2
123119
audio_source.on_data(event_data)
124120

@@ -140,9 +136,7 @@ async def main(client, input_peer, input_filename):
140136
await pc.set_local_description(local_sdp)
141137

142138
app = PyrogramBridge(client)
143-
app.register_group_call_native_callback(
144-
group_call_participants_update_callback, group_call_update_callback
145-
)
139+
app.register_group_call_native_callback(group_call_participants_update_callback, group_call_update_callback)
146140
await app.get_and_set_group_call(input_peer)
147141
await app.resolve_and_set_join_as(None)
148142

@@ -159,9 +153,7 @@ def pre_update_processing():
159153
# await asyncio.wait_for(REMOTE_ANSWER_EVENT.wait(), 30)
160154

161155
await pc.set_remote_description(
162-
webrtc.RTCSessionDescription(
163-
webrtc.RTCSessionDescriptionInit(webrtc.RTCSdpType.answer, remote_sdp)
164-
)
156+
webrtc.RTCSessionDescription(webrtc.RTCSessionDescriptionInit(webrtc.RTCSdpType.answer, remote_sdp))
165157
)
166158

167159
thread = threading.Thread(target=send_audio_data, args=(audio_source, input_filename))

pyproject.toml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[tool.black]
2+
line-length = 120
3+
skip-string-normalization=true
4+
target-version = ['py37']
5+
include = '\.pyi?$'
6+
exclude = '''
7+
(
8+
/(
9+
\.eggs
10+
| \.git
11+
| \.hg
12+
| \.mypy_cache
13+
| \.tox
14+
| \.venv
15+
| _build
16+
| buck-out
17+
| build
18+
| dist
19+
)/
20+
)
21+
'''

python-webrtc/cpp/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ configure_file("${src_loc}/config.h.in" "${src_loc}/config.h")
22

33
file(GLOB_RECURSE MODULE_SRC ${src_loc}/*.cpp ${src_loc}/*.h)
44

5-
if ("$ENV{NO_LTO}" STREQUAL "true")
5+
if(UNIX AND NOT APPLE)
66
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)
77
endif()
88

0 commit comments

Comments
 (0)
0