libtgvoip wrapper¶
VoIPController¶
-
class
tgvoip.VoIPController(persistent_state_file: str = '', debug=False, logs_dir='logs')[source]¶ A wrapper around C++ wrapper for libtgvoip
VoIPControllerParameters: - persistent_state_file (
str, optional) – ?, empty to not use - debug (
bool, optional) – Modifies logging behavior - logs_dir (
str, optional) – Logs directory
- Class attributes:
- LIBTGVOIP_VERSION
- Used
libtgvoipversion - CONNECTION_MAX_LAYER
- Maximum layer supported by used
libtgvoipversion
-
persistent_state_file¶ Value set in the constructor
-
call_state_changed_handlers¶ listof call state change callbacks, callbacks receive aCallStateobject as argument
-
signal_bars_changed_handlers¶ listof signal bars count change callbacks, callbacks receive anintobject as argument
-
call_duration¶ Current call duration in seconds as
intif call was started, otherwise 0
-
set_proxy(address: str, port: int = 1080, username: str = '', password: str = '')[source]¶ Set SOCKS5 proxy config
Parameters: - address (
str) – Proxy hostname or IP address - port (
int, optional) – Proxy port - username (
int, optional) – Proxy username - password (
int, optional) – Proxy password
Raises: ValueErrorifaddressis empty- address (
-
set_encryption_key(key: bytes, is_outgoing: bool)[source]¶ Set call auth key
Parameters: - key (
bytes) – Auth key, must be exactly 256 bytes - is_outgoing (
bool) – Is call outgoing
Raises: ValueErrorif provided auth key has wrong length- key (
-
set_remote_endpoints(endpoints: List[<sphinx.ext.autodoc.importer._MockObject object at 0x7f98eedf7cf8>], allow_p2p: bool, tcp: bool, connection_max_layer: int)[source]¶ Set remote endpoints received in call object from Telegram.
Usually it’s
[call.connection] + call.alternative_connections.You must build
Endpointobjects from MTProtophoneConnectionobjects and pass them in list.Parameters: - endpoints (
listofEndpoint) – List of endpoints - allow_p2p (
bool) – Is p2p connection allowed, usually call.p2p_allowed value is used - tcp (
bool) – Connect via TCP, not recommended - connection_max_layer (
int) – Use a value provided byVoIPController.CONNECTION_MAX_LAYER
Raises: ValueErrorif either no endpoints are provided or endpoints without IPv4 or with wrongpeer_tag(must be eitherNoneor have length of 16 bytes) are detected- endpoints (
-
set_network_type(_type: tgvoip.tgvoip.NetType)[source]¶ Set network type
Parameters: _type ( NetType) – Network type to set
-
set_mic_mute(mute: bool)[source]¶ Set “microphone” state. If muted, audio is not being sent
Parameters: mute ( bool) – Whether to mute “microphone”
-
set_config(recv_timeout: float, init_timeout: float, data_saving_mode: tgvoip.tgvoip.DataSaving, call_id: int, enable_aec: bool = True, enable_ns: bool = True, enable_agc: bool = True, log_file_path: str = None, status_dump_path: str = None, log_packet_stats: bool = None)[source]¶ Set call config
Parameters: - recv_timeout (
float) – Packet receive timeout, usually value received fromhelp.getConfig()is used - init_timeout (
float) – Packet init timeout, usually value received fromhelp.getConfig()is used - data_saving_mode (
DataSaving) – Data saving mode - call_id (
int) – Call ID - enable_aec (
bool, optional) – Whether to enable automatic echo cancellation, defaults toTrue - enable_ns (
bool, optional) – Whether to enable noise suppression, defaults toTrue - enable_agc (
bool, optional) – Whether to enable automatic gain control, defaults toTrue - log_file_path (
str, optional) – Call log file path, calculated automatically if not provided - status_dump_path (
str, optional) – Status dump path, calculated automatically if not provided anddebugis enabled - log_packet_stats (
bool, optional) – Whether to log packet stats, defaults todebugvalue
- recv_timeout (
-
debug_ctl(request: int, param: int)[source]¶ Debugging options
Parameters: - request (
int) – Option (1for max bitrate,2for packet loss (in percents),3for toggling p2p,4for toggling echo cancelling) - param (
int) – Numeric value for options 1 and 2,0or1for options 3 and 4
- request (
-
get_preferred_relay_id() → int[source]¶ Get preferred relay ID (used in
discardCallMTProto request)Returns: intID
-
get_last_error() → tgvoip.tgvoip.CallError[source]¶ Get last error type
Returns: CallErrormatching last occurred error type
-
get_stats() → <sphinx.ext.autodoc.importer._MockObject object at 0x7f98eedf7c88>[source]¶ Get call stats
Returns: Statsobject
-
set_audio_output_gain_control_enabled(enabled: bool)[source]¶ Toggle output gain control
Parameters: enabled ( bool) – Whether to enable output gain control
-
set_echo_cancellation_strength(strength: int)[source]¶ Set echo cancellation strength, does nothing currently but was in Java bindings (?)
Parameters: strength ( int) – Strength value
-
get_peer_capabilities() → int[source]¶ Get peer capabilities
Returns: intwith bit mask, looks like it is used only for experimental features (group, video calls)
-
native_io¶ Get native I/O status (file I/O implemented in C++)
Returns: boolstatus (enabled or not)
-
play(path: str) → bool[source]¶ Add a file to play queue for native I/O
Parameters: path ( str) – File pathReturns: boolwhether opening the file was successful. File is not added to queue on failure.
-
play_on_hold(paths: List[str]) → None[source]¶ Replace the hold queue for native I/O
Parameters: paths ( listofstr) – List of file paths
-
set_output_file(path: str) → bool[source]¶ Set output file for native I/O
Parameters: path ( str) – File pathReturns: boolwhether opening the file was successful. Output file is not replaced on failure.
-
update_state(state: tgvoip.tgvoip.CallState)[source]¶ Manually update state (only triggers handlers)
Parameters: state ( CallState) – State to set
-
set_send_audio_frame_callback(func: callable)[source]¶ Set callback providing audio data to send
Should accept one argument (
intlength of requested audio frame) and returnbytesobject with audio data encoded in 16-bit signed PCMIf returned object has insufficient length, it will be automatically padded with zero bytes
Parameters: func ( callable) – Callback function
- persistent_state_file (
VoIPServerConfig¶
-
class
tgvoip.VoIPServerConfig(*args, **kwargs)[source]¶ Global server config class. This class contains default config in its source
-
classmethod
set_config(_json: Union[str, dict])[source]¶ Set global server config
Parameters: _json ( str|dict) – either JSON-encoded object ordictcontaining config values. Might be received from MTProtophone.getCallConfig()call, if not set default values are usedRaises: Prints an error to stderrif JSON parsing (forstrargument) or encoding (fordictargument) has occurred
-
classmethod
set_bitrate_config(init_bitrate: int = 16000, max_bitrate: int = 20000, min_bitrate: int = 8000, decrease_step: int = 1000, increase_step: int = 1000)[source]¶ Helper method for setting bitrate options
Parameters: - init_bitrate (
int) – Initial bitrate value - max_bitrate (
int) – Maximum bitrate value - min_bitrate (
int) – Minimum bitrate value - decrease_step (
int) – Bitrate decrease step - increase_step (
int) – Bitrate increase step
Raises: Same as
set_config()- init_bitrate (
-
classmethod
Enums¶
-
class
tgvoip.NetType[source]¶ An enumeration of network types
- Members:
- UNKNOWN = 0
- GPRS = 1
- EDGE = 2
- NET_3G = 3
- HSPA = 4
- LTE = 5
- WIFI = 6
- ETHERNET = 7
- OTHER_HIGH_SPEED = 8
- OTHER_LOW_SPEED = 9
- DIALUP = 10
- OTHER_MOBILE = 11
-
class
tgvoip.DataSaving[source]¶ An enumeration of data saving modes
- Members:
- NEVER = 0
- MOBILE = 1
- ALWAYS = 2
Data structures¶
-
class
tgvoip.Stats¶ Object storing call stats
-
bytes_sent_wifi¶ Amount of data sent over WiFi :type:
int
-
bytes_sent_mobile¶ Amount of data sent over mobile network :type:
int
-
bytes_recvd_wifi¶ Amount of data received over WiFi :type:
int
-
bytes_recvd_mobile¶ Amount of data received over mobile network :type:
int
-
-
class
tgvoip.Endpoint¶ Object storing endpoint info
Parameters: - _id (
int) – Endpoint ID - ip (
str) – Endpoint IPv4 address - ipv6 (
str) – Endpoint IPv6 address - port (
int) – Endpoint port - peer_tag (
bytes) – Endpoint peer tag
- _id (