8000 0.0.6 dev by MarshalX · Pull Request #11 · MarshalX/python-webrtc · GitHub
[go: up one dir, main page]

Skip to content

0.0.6 dev #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .github/codeql/codeql_config.yaml

This file was deleted.

3 changes: 3 additions & 0 deletions .github/codeql/codeql_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: "CodeQL config"
paths:
- 'python-webrtc'
22 changes: 22 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Black

on: [push, pull_request]

jobs:
black:
name: Black
runs-on: ubuntu-latest

steps:
- name: Checkout repository.
uses: actions/checkout@v2

- name: Setup Python.
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Check code style.
run: |
pip install black
black --check python-webrtc
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build

on:
pull_request:
branches:
- main
schedule:
- cron: '0 8 * * 1'

jobs:
build:
name: Build
runs-on: ubuntu-latest

steps:
- name: Checkout repository.
uses: actions/checkout@v2
with:
submodules: recursive

- name: Setup Python.
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Build.
run: |
sudo apt install -y python3.9-dev
python setup.py build
34 changes: 18 additions & 16 deletions .github/workflows/codeql_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ name: CodeQL

on:
push:
branches: [ main ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
schedule:
- cron: '0 8 * * 1'

Expand All @@ -19,31 +16,36 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'cpp', 'python' ]
language: [
# 'cpp',
'python'
]

steps:
- name: Checkout repository
- name: Checkout repository.
uses: actions/checkout@v2
with:
submodules: recursive

- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.9

- name: Initialize CodeQL
- name: Initialize CodeQL.
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
config-file: ./.github/codeql/codeql_config.yaml
setup-python-dependencies: false
config-file: ./.github/codeql/codeql_config.yml

- name: Setup Python.
if: matrix.language == 'cpp'
uses: actions/setup-python@v2
with:
python-version: 3.9

- if: matrix.language == 'cpp'
name: Build
- name: Build.
if: matrix.language == 'cpp'
run: |
sudo apt install -y python3.9-dev
export NO_LTO=true
python setup.py build

- name: Perform CodeQL Analysis
# it takes too long for cpp
- name: Perform CodeQL Analysis.
uses: github/codeql-action/analyze@v1
3 changes: 1 addition & 2 deletions .github/workflows/create_sdist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: Create and publish Source Distribution
on:
push:
branches:
- main
- pypi-dev
paths:
- '.github/workflows/create_sdist.yml'
Expand All @@ -23,7 +22,7 @@ jobs:
submodules: recursive

- name: Setup Python.
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: 3.7

Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ include(ExternalProject)

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

include(ExternalProject)
Expand Down
9 changes: 9 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Security Policy

## Supported Versions

Only the latest published version on [PyPI](https://pypi.org/project/wrtc/#history) supported with security updates.

## Reporting a Vulnerability

Email for reports: ilya@marshal.dev
28 changes: 24 additions & 4 deletions docs/links/wrtc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
import typing

__all__ = [
"CallbackPythonWebRTCException",
"MediaStream",
"MediaStreamSourceState",
"MediaStreamTrack",
"MediaStreamTrackState",
"PeerConnectionFactory",
"PythonWebRTCException",
"PythonWebRTCExceptionBase",
"RTCAudioSource",
"RTCCallbackException",
"RTCException",
"RTCIceConnectionState",
"RTCIceGatheringState",
"RTCOnDataEvent",
Expand All @@ -18,6 +23,7 @@
"RTCSdpType",
"RTCSessionDescription",
"RTCSessionDescriptionInit",
"SdpParseException",
"answer",
"checking",
"closed",
Expand All @@ -42,6 +48,9 @@
]


class CallbackPythonWebRTCException():
def what(self) -> str: ...
pass
class MediaStream():
def addTrack(self, arg0: MediaStreamTrack) -> None: ...
def clone(self) -> MediaStream: ...
Expand Down Expand Up @@ -170,11 +179,20 @@ def getOrCreateDefault() -> PeerConnectionFactory: ...
@staticmethod
def release() -> None: ...
pass
class PythonWebRTCExceptionBase(Exception, BaseException):
pass
class PythonWebRTCException(PythonWebRTCExceptionBase, Exception, BaseException):
pass
class RTCAudioSource():
def __init__(self) -> None: ...
def createTrack(self) -> MediaStreamTrack: ...
def onData(self, arg0: RTCOnDataEvent) -> None: ...
pass
class RTCCallbackException():
def what(self) -> str: ...
pass
class RTCException(PythonWebRTCExceptionBase, Exception, BaseException):
pass
class RTCIceConnectionState():
"""
Members:
Expand Down Expand Up @@ -306,10 +324,10 @@ def __init__(self) -> None: ...
@staticmethod
def addTrack(*args, **kwargs) -> typing.Any: ...
def close(self) -> None: ...
def createAnswer(self, arg0: typing.Callable[[RTCSessionDescription], None]) -> None: ...
def createOffer(self, arg0: typing.Callable[[RTCSessionDescription], None]) -> None: ...
def setLocalDescription(self, arg0: typing.Callable[[], None], arg1: RTCSessionDescription) -> None: ...
def setRemoteDescription(self, arg0: typing.Callable[[], None], arg1: RTCSessionDescription) -> None: ...
def createAnswer(self, arg0: typing.Callable[[RTCSessionDescription], None], arg1: typing.Callable[[CallbackPythonWebRTCException], None]) -> None: ...
def createOffer(self, arg0: typing.Callable[[RTCSessionDescription], None], arg1: typing.Callable[[CallbackPythonWebRTCException], None]) -> None: ...
def setLocalDescription(self, arg0: typing.Callable[[], None], arg1: typing.Callable[[CallbackPythonWebRTCException], None], arg2: RTCSessionDescription) -> None: ...
def setRemoteDescription(self, arg0: typing.Callable[[], None], arg1: typing.Callable[[CallbackPythonWebRTCException], None], arg2: RTCSessionDescription) -> None: ...
pass
class RTCPeerConnectionState():
"""
Expand Down Expand Up @@ -430,6 +448,8 @@ def type(self) -> RTCSdpType:
def type(self, arg0: RTCSdpType) -> None:
pass
pass
class SdpParseException(PythonWebRTCExceptionBase, Exception, BaseException):
pass
def getUserMedia() -> MediaStream:
pass
def ping() -> None:
Expand Down
32 changes: 12 additions & 20 deletions examples/telegram_group_calls.py
FBDE
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def parse_sdp(sdp):
def lookup(prefix):
for line in lines:
if line.startswith(prefix):
return line[len(prefix):]
return line[len(prefix) :]

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

def get_params_from_parsed_sdp(info):
return {
'fingerprints': [
{
'fingerprint': info['fingerprint'],
'hash': info['hash'],
'setup': 'active'
}
],
'fingerprints': [{'fingerprint': info['fingerprint'], 'hash': info['hash'], 'setup': 'active'}],
'pwd': info['pwd'],
'ssrc': info['source'],
'ssrc-groups': [],
'ufrag': info['ufrag']
'ufrag': info['ufrag'],
}


def build_answer(sdp):
def add_candidates():
candidates_sdp = []
for cand in sdp['transport']['candidates']:
candidates_sdp.append(f"a=candidate:{cand['foundation']} {cand['component']} {cand['protocol']} "
f"{cand['priority']} {cand['ip']} {cand['port']} typ {cand['type']} "
f"generation {cand['generation']}")
candidates_sdp.append(
f"a=candidate:{cand['foundation']} {cand['component']} {cand['protocol']} "
f"{cand['priority']} {cand['ip']} {cand['port']} typ {cand['type']} "
f"generation {cand['generation']}"
)

return '\n'.join(candidates_sdp)

Expand Down Expand Up @@ -114,11 +110,11 @@ def get_ms_time():

if last_read_ms == 0 or start_time - last_read_ms >= 10:
data = f.read(length)
if not data: # eof
if not data: # eof
f.close()
break

event_data = webrtc.RTCOnDataEvent(data, length // 4) # 2 channels
event_data = webrtc.RTCOnDataEvent(data, length // 4) # 2 channels
event_data.channel_count = 2
audio_source.on_data(event_data)

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

app = PyrogramBridge(client)
app.register_group_call_native_callback(
group_call_participants_update_callback, group_call_update_callback
)
app.register_group_call_native_callback(group_call_participants_update_callback, group_call_update_callback)
await app.get_and_set_group_call(input_peer)
await app.resolve_and_set_join_as(None)

Expand All @@ -159,9 +153,7 @@ def pre_update_processing():
# aw 1241 ait asyncio.wait_for(REMOTE_ANSWER_EVENT.wait(), 30)

await pc.set_remote_description(
webrtc.RTCSessionDescription(
webrtc.RTCSessionDescriptionInit(webrtc.RTCSdpType.answer, remote_sdp)
)
webrtc.RTCSessionDescription(webrtc.RTCSessionDescriptionInit(webrtc.RTCSdpType.answer, remote_sdp))
)

thread = threading.Thread(target=send_audio_data, args=(audio_source, input_filename))
Expand Down
21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[tool.black]
line-length = 120
skip-string-normalization=true
target-version = ['py37']
include = '\.pyi?$'
exclude = '''
(
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
)/
)
'''
2 changes: 1 addition & 1 deletion python-webrtc/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ configure_file("${src_loc}/config.h.in" "${src_loc}/config.h")

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

if ("$ENV{NO_LTO}" STREQUAL "true")
if(UNIX AND NOT APPLE)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)
endif()

Expand Down
Loading
0