1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-30 06:59:01 +01:00

More VoIP progress

This commit is contained in:
Daniil Gentili 2023-09-03 14:54:48 +02:00
parent bb4bfb256c
commit c3cc181dba
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 97 additions and 9 deletions

View File

@ -61,7 +61,7 @@ The following open source projects were created using MadelineProto: you can dir
* [`simpleBot.php`](https://github.com/danog/MadelineProto/blob/v8/examples/simpleBot.php) - Extremely basic example
* [`tgstories_dl_bot.php`](https://github.com/danog/MadelineProto/blob/v8/examples/tgstories_dl_bot.php) - Source code of [@tgstories_dl_bot](https://t.me/tgstories_dl_bot) - Bot to download any Telegram Story!
* [`downloadRenameBot.php`](https://github.com/danog/MadelineProto/blob/v8/examples/downloadRenameBot.php) - Download files by URL and rename Telegram files using this async parallelized bot!
* [`secret_bot.php`](https://github.com/danog/MadelineProto/blob/v8/examples/secret_bot.php) - Secret chat bot!
* [`secret_bot.php`](https://github.com/danog/MadelineProto/blob/) - Secret chat bot!
* [`pipesbot.php`](https://github.com/danog/pipesbot) - Creating inline bots and using other inline bots via a userbot!
* [`bot.php`](https://github.com/danog/MadelineProto/blob/v8/examples/bot.php) - Examples for how to use filters, updates, get download links for any file, Telegram Stories and much more!

View File

@ -0,0 +1,24 @@
<?php
namespace danog\MadelineProto\VoIP;
/** @internal */
enum ProtocolVersion {
case V1;
case V2;
case V3;
public static function fromLibraryVersion(string $version): self {
return match ($version) {
'7.0.0' => self::V1,
'8.0.0' => self::V2,
'9.0.0' => self::V3,
default => self::V2
};
}
public function supportsCompression(): bool {
return $this === self::V3;
}
}

View File

@ -18,6 +18,8 @@
namespace danog\MadelineProto;
use Amp\ByteStream\BufferedReader;
use Amp\ByteStream\ReadableBuffer;
use Amp\ByteStream\ReadableStream;
use danog\Loop\Loop;
use danog\MadelineProto\Loop\VoIP\DjLoop;
@ -410,16 +412,78 @@ final class VoIPController
return;
}
for ($x = 0; $x < strlen($packet);) {
$seq = unpack('V', strrev(substr($packet, $x, 4)))[1];
$result = match (ord(substr($packet, $x+5))) {
1 => [
'_' => ''
]
}
$packet = new BufferedReader(new ReadableBuffer($packet));
$packets = [];
while ($packet->isReadable()) {
$seq = unpack('N', $packet->readLength(4))[1];
$length = unpack('N', $packet->readLength(4))[1];
var_dump($seq, $length);
$packets []= self::deserializeRtc($packet);
}
\var_dump($packet);
var_dump($packets);
}
public static function deserializeRtc(BufferedReader $buffer): array {
switch ($t = ord($buffer->readLength(1))) {
case 1:
$candidates = [];
for ($x = ord($buffer->readLength(1)); $x > 0; $x--) {
$candidates []= self::readString($buffer);
}
return [
'_' => 'candidatesList',
'ufrag' => self::readString($buffer),
'pwd' => self::readString($buffer),
];
case 2:
$formats = [];
for ($x = ord($buffer->readLength(1)); $x > 0; $x--) {
$name = self::readString($buffer);
$parameters = [];
for ($x = ord($buffer->readLength(1)); $x > 0; $x--) {
$key = self::readString($buffer);
$value = self::readString($buffer);
$parameters[$key] = $value;
}
$formats[]= [
'name' => $name,
'parameters' => $parameters
];
}
return [
'_' => 'videoFormats',
'formats' => $formats,
'encoders' => ord($buffer->readLength(1)),
];
case 3:
return ['_' => 'requestVideo'];
case 4:
$state = ord($buffer->readLength(1));
return ['_' => 'remoteMediaState', 'audio' => $state & 0x01, 'video' => ($state >> 1) & 0x03];
case 5:
return ['_' => 'audioData', 'data' => self::readBuffer($buffer)];
case 6:
return ['_' => 'videoData', 'data' => self::readBuffer($buffer)];
case 7:
return ['_' => 'unstructuredData', 'data' => self::readBuffer($buffer)];
case 8:
return ['_' => 'videoParameters', 'aspectRatio' => unpack('V', $buffer->readLength(4))[1]];
case 9:
return ['_' => 'remoteBatteryLevelIsLow', 'isLow' => (bool)ord($buffer->readLength(1))];
case 10:
$lowCost = (bool)ord($buffer->readLength(1));
$isLowDataRequested = (bool)ord($buffer->readLength(1));
return ['_' => 'remoteNetworkStatus', 'lowCost' => $lowCost, 'isLowDataRequested' => $isLowDataRequested];
}
return ['_' => 'unknown', 'type' => $t];
}
private static function readString(BufferedReader $buffer): string {
return $buffer->readLength(ord($buffer->readLength(1)));
}
private static function readBuffer(BufferedReader $buffer): string {
return $buffer->readLength(unpack('n', $buffer->readLength(2))[1]);
}
private function setVoipState(VoIPState $state): bool