Skip to content

Commit

Permalink
fix readthedocs build
Browse files Browse the repository at this point in the history
  • Loading branch information
bakatrouble committed Feb 19, 2019
1 parent 4cefda2 commit a9d2af3
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 65 deletions.
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@

autodoc_member_order = 'bysource'

autodoc_mock_imports = ['_tgvoip']


# -- Options for HTML output -------------------------------------------------

Expand Down
43 changes: 39 additions & 4 deletions docs/module/tgvoip.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,43 @@ Enums
Data structures
---------------

.. autoclass:: tgvoip.Stats
:members:

.. autoclass:: tgvoip.Endpoint
:members:
.. py:class:: tgvoip.Stats
Object storing call stats

.. attribute:: bytes_sent_wifi

Amount of data sent over WiFi
:type: ``int``

.. attribute:: bytes_sent_mobile

Amount of data sent over mobile network
:type: ``int``

.. attribute:: bytes_recvd_wifi

Amount of data received over WiFi
:type: ``int``

.. attribute:: bytes_recvd_mobile

Amount of data received over mobile network
:type: ``int``


.. py:class:: tgvoip.Endpoint
Object storing endpoint info

:param _id: Endpoint ID
:type _id: ``int``
:param ip: Endpoint IPv4 address
:type ip: ``str``
:param ipv6: Endpoint IPv6 address
:type ipv6: ``str``
:param port: Endpoint port
:type port: ``int``
:param peer_tag: Endpoint peer tag
:type peer_tag: ``bytes``
21 changes: 2 additions & 19 deletions src/_tgvoip_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,7 @@ PYBIND11_MODULE(_tgvoip, m) {
.value("PROXY", CallError::ERROR_PROXY)
.export_values();

py::class_<Stats>(m, "Stats", R"doc(
An object storing call stats
Attributes:
bytes_sent_wifi (``int``): Amount of data sent over WiFi
bytes_sent_mobile (``int``): Amount of data sent over mobile network
bytes_recvd_wifi (``int``): Amount of data received over WiFi
bytes_recvd_mobile (``int``): Amount of data received over mobile network
)doc")
py::class_<Stats>(m, "Stats")
.def_readonly("bytes_sent_wifi", &Stats::bytes_sent_wifi)
.def_readonly("bytes_sent_mobile", &Stats::bytes_sent_mobile)
.def_readonly("bytes_recvd_wifi", &Stats::bytes_recvd_wifi)
Expand All @@ -95,16 +87,7 @@ PYBIND11_MODULE(_tgvoip, m) {
return repr.str();
});

py::class_<Endpoint>(m, "Endpoint", R"doc(
An object storing endpoint info
Args:
_id (``int``): Endpoint ID
ip (``str``): Endpoint IPv4 address
ipv6 (``str``): Endpoint IPv6 address
port (``int``): Endpoint port
peer_tag (``bytes``): Endpoint peer tag
)doc")
py::class_<Endpoint>(m, "Endpoint")
.def(py::init<long, const std::string &, const std::string &, int, const std::string &>())
.def_readwrite("_id", &Endpoint::id)
.def_readwrite("ip", &Endpoint::ip)
Expand Down
79 changes: 37 additions & 42 deletions src/tgvoip/tgvoip.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,15 @@
from enum import Enum
from typing import Union, List

from _tgvoip import (
NetType as _NetType,
DataSaving as _DataSaving,
CallState as _CallState,
CallError as _CallError,
Stats,
Endpoint,
VoIPController as _VoIPController,
VoIPServerConfig as _VoIPServerConfig
)
import _tgvoip

from tgvoip.utils import get_real_elapsed_time


Stats = _tgvoip.Stats
Endpoint = _tgvoip.Endpoint


# docstring magic ahead


Expand All @@ -59,18 +54,18 @@ class NetType(Enum):
* OTHER_MOBILE = 11
"""

UNKNOWN = _NetType.UNKNOWN
GPRS = _NetType.GPRS
EDGE = _NetType.EDGE
NET_3G = _NetType.NET_3G
HSPA = _NetType.HSPA
LTE = _NetType.LTE
WIFI = _NetType.WIFI
ETHERNET = _NetType.ETHERNET
OTHER_HIGH_SPEED = _NetType.OTHER_HIGH_SPEED
OTHER_LOW_SPEED = _NetType.OTHER_LOW_SPEED
DIALUP = _NetType.DIALUP
OTHER_MOBILE = _NetType.OTHER_MOBILE
UNKNOWN = _tgvoip.NetType.UNKNOWN
GPRS = _tgvoip.NetType.GPRS
EDGE = _tgvoip.NetType.EDGE
NET_3G = _tgvoip.NetType.NET_3G
HSPA = _tgvoip.NetType.HSPA
LTE = _tgvoip.NetType.LTE
WIFI = _tgvoip.NetType.WIFI
ETHERNET = _tgvoip.NetType.ETHERNET
OTHER_HIGH_SPEED = _tgvoip.NetType.OTHER_HIGH_SPEED
OTHER_LOW_SPEED = _tgvoip.NetType.OTHER_LOW_SPEED
DIALUP = _tgvoip.NetType.DIALUP
OTHER_MOBILE = _tgvoip.NetType.OTHER_MOBILE


class CallState(Enum):
Expand All @@ -93,11 +88,11 @@ class CallState(Enum):
* BUSY = 17
"""

WAIT_INIT = _CallState.WAIT_INIT
WAIT_INIT_ACK = _CallState.WAIT_INIT_ACK
ESTABLISHED = _CallState.ESTABLISHED
FAILED = _CallState.FAILED
RECONNECTING = _CallState.RECONNECTING
WAIT_INIT = _tgvoip.CallState.WAIT_INIT
WAIT_INIT_ACK = _tgvoip.CallState.WAIT_INIT_ACK
ESTABLISHED = _tgvoip.CallState.ESTABLISHED
FAILED = _tgvoip.CallState.FAILED
RECONNECTING = _tgvoip.CallState.RECONNECTING
HANGING_UP = 10
ENDED = 11
EXCHANGING_KEYS = 12
Expand All @@ -117,9 +112,9 @@ class DataSaving(Enum):
* MOBILE = 1
* ALWAYS = 2
"""
NEVER = _DataSaving.NEVER
MOBILE = _DataSaving.MOBILE
ALWAYS = _DataSaving.ALWAYS
NEVER = _tgvoip.DataSaving.NEVER
MOBILE = _tgvoip.DataSaving.MOBILE
ALWAYS = _tgvoip.DataSaving.ALWAYS


class CallError(Enum):
Expand All @@ -133,14 +128,14 @@ class CallError(Enum):
* AUDIO_IO = 3
* PROXY = 4
"""
UNKNOWN = _CallError.UNKNOWN
INCOMPATIBLE = _CallError.INCOMPATIBLE
TIMEOUT = _CallError.TIMEOUT
AUDIO_IO = _CallError.AUDIO_IO
PROXY = _CallError.PROXY
UNKNOWN = _tgvoip.CallError.UNKNOWN
INCOMPATIBLE = _tgvoip.CallError.INCOMPATIBLE
TIMEOUT = _tgvoip.CallError.TIMEOUT
AUDIO_IO = _tgvoip.CallError.AUDIO_IO
PROXY = _tgvoip.CallError.PROXY


class VoIPController(_VoIPController):
class VoIPController(_tgvoip.VoIPController):
"""
A wrapper around C++ wrapper for libtgvoip ``VoIPController``
Expand Down Expand Up @@ -168,7 +163,7 @@ class VoIPController(_VoIPController):
"""

def __init__(self, persistent_state_file: str = '', debug=False, logs_dir='logs'):
super().__init__(persistent_state_file) # _VoIPController.__init__(self, persistent_state_file)
super().__init__(persistent_state_file) # _tgvoip.VoIPController.__init__(self, persistent_state_file)
self.debug = debug
self.logs_dir = logs_dir
self.start_time = 0
Expand Down Expand Up @@ -272,7 +267,7 @@ def set_network_type(self, _type: NetType):
Args:
_type (:class:`NetType`): Network type to set
"""
super().set_network_type(_NetType(_type.value))
super().set_network_type(_tgvoip.NetType(_type.value))

def set_mic_mute(self, mute: bool):
"""
Expand Down Expand Up @@ -335,7 +330,7 @@ def set_config(self,
status_dump_path = self._get_log_file_path('voip_stats') if self.debug else ''
if log_packet_stats is None:
log_packet_stats = self.debug
super().set_config(recv_timeout, init_timeout, _DataSaving(data_saving_mode.value), enable_aec, enable_ns, enable_agc,
super().set_config(recv_timeout, init_timeout, _tgvoip.DataSaving(data_saving_mode.value), enable_aec, enable_ns, enable_agc,
log_file_path, status_dump_path, log_packet_stats)

def debug_ctl(self, request: int, param: int):
Expand Down Expand Up @@ -425,7 +420,7 @@ def need_rate(self) -> bool:
return super().need_rate()

# native code callback
def _handle_state_change(self, state: _CallState):
def _handle_state_change(self, state: _tgvoip.CallState):
state = CallState(state)

if state == CallState.ESTABLISHED and not self.start_time:
Expand Down Expand Up @@ -495,7 +490,7 @@ def _get_log_file_path_for_call_id(self, call_id: int) -> str:
return os.path.abspath(os.path.join(self.logs_dir, '{}.log'.format(call_id)))


class VoIPServerConfig(_VoIPServerConfig):
class VoIPServerConfig(_tgvoip.VoIPServerConfig):
"""
Global server config class. This class contains default config in its source
"""
Expand Down Expand Up @@ -541,7 +536,7 @@ def set_config(cls, _json: Union[str, dict]):
if isinstance(_json, dict):
_json = json.dumps(_json)
cls.config.update(json.loads(_json))
_VoIPServerConfig.set_config(_json)
_tgvoip.VoIPServerConfig.set_config(_json)
except json.JSONDecodeError as e:
print('Error parsing VoIP config', e, file=sys.stderr)
except TypeError as e:
Expand Down

0 comments on commit a9d2af3

Please sign in to comment.