mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-30 11:18:59 +01:00
Misc fixes
This commit is contained in:
parent
944d6bd1e2
commit
5419a35075
@ -19,7 +19,6 @@ namespace danog\MadelineProto\Db\Driver;
|
||||
use Amp\Redis\Connection\ReconnectingRedisLink;
|
||||
use Amp\Redis\RedisClient;
|
||||
use Amp\Redis\RedisConfig;
|
||||
use Amp\Redis\RemoteExecutorFactory;
|
||||
use Amp\Sync\LocalKeyedMutex;
|
||||
use danog\MadelineProto\Settings\Database\Redis as DatabaseRedis;
|
||||
|
||||
|
@ -24,6 +24,7 @@ use danog\MadelineProto\EventHandler\Media;
|
||||
use danog\MadelineProto\EventHandler\Media\Audio;
|
||||
use danog\MadelineProto\EventHandler\Media\Document;
|
||||
use danog\MadelineProto\EventHandler\Media\Photo;
|
||||
use danog\MadelineProto\EventHandler\Media\Video;
|
||||
use danog\MadelineProto\EventHandler\Message;
|
||||
use danog\MadelineProto\EventHandler\Update;
|
||||
use danog\MadelineProto\Ipc\Client;
|
||||
@ -305,6 +306,13 @@ abstract class InternalDoc
|
||||
{
|
||||
$this->wrapper->getAPI()->callPlayOnHold($id, ...$files);
|
||||
}
|
||||
/**
|
||||
* Whether we can convert any audio/video file to a VoIP OGG OPUS file, or the files must be preconverted using @libtgvoipbot.
|
||||
*/
|
||||
public static function canConvertOgg(): bool
|
||||
{
|
||||
return \danog\MadelineProto\Tools::canConvertOgg();
|
||||
}
|
||||
/**
|
||||
* Cancel a running broadcast.
|
||||
*
|
||||
|
@ -30,9 +30,9 @@ use AssertionError;
|
||||
use danog\Loop\Loop;
|
||||
use danog\MadelineProto\LocalFile;
|
||||
use danog\MadelineProto\Loop\VoIPLoop;
|
||||
use danog\MadelineProto\Magic;
|
||||
use danog\MadelineProto\Ogg;
|
||||
use danog\MadelineProto\RemoteUrl;
|
||||
use danog\MadelineProto\Tools;
|
||||
use danog\MadelineProto\VoIP;
|
||||
use danog\MadelineProto\VoIP\CallState;
|
||||
use danog\MadelineProto\VoIPController;
|
||||
@ -201,7 +201,7 @@ final class DjLoop extends VoIPLoop
|
||||
}
|
||||
}
|
||||
if (!$it) {
|
||||
if (!Magic::canConvertOgg()) {
|
||||
if (!Tools::canConvertOgg()) {
|
||||
throw new AssertionError("The passed file was not generated by MadelineProto or @libtgvoipbot, please pre-convert it using @libtgvoip bot or install FFI and ffmpeg to perform realtime conversion!");
|
||||
}
|
||||
$this->instance->log("Starting conversion fiber...");
|
||||
|
@ -20,8 +20,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace danog\MadelineProto;
|
||||
|
||||
use Amp\ByteStream\ReadableBuffer;
|
||||
use Amp\ByteStream\WritableBuffer;
|
||||
use Amp\DeferredFuture;
|
||||
use Amp\SignalException;
|
||||
use danog\MadelineProto\TL\Conversion\Extension;
|
||||
@ -391,18 +389,4 @@ final class Magic
|
||||
self::$initedIpv6 = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static ?bool $canConvert = null;
|
||||
public static function canConvertOgg(): bool {
|
||||
if (self::$canConvert !== null) {
|
||||
return self::$canConvert;
|
||||
}
|
||||
try {
|
||||
Ogg::convert(new LocalFile(__DIR__.'/empty.wav'), new WritableBuffer);
|
||||
self::$canConvert = true;
|
||||
} catch (\Throwable $e) {
|
||||
self::$canConvert = false;
|
||||
}
|
||||
return self::$canConvert;
|
||||
}
|
||||
}
|
||||
|
@ -551,7 +551,8 @@ final class Ogg
|
||||
} finally {
|
||||
$cancel->cancel();
|
||||
}
|
||||
} catch (\Throwable) {}
|
||||
} catch (\Throwable) {
|
||||
}
|
||||
if (!$ok) {
|
||||
throw new AssertionError("The passed file was not generated by MadelineProto or @libtgvoipbot, please pre-convert it using @libtgvoip bot or install FFI and ffmpeg to perform realtime conversion!");
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ namespace danog\MadelineProto;
|
||||
use Amp\ByteStream\Pipe;
|
||||
use Amp\ByteStream\ReadableBuffer;
|
||||
use Amp\ByteStream\ReadableStream;
|
||||
use Amp\ByteStream\WritableBuffer;
|
||||
use Amp\Cancellation;
|
||||
use Amp\File\File;
|
||||
use Amp\Http\Client\HttpClient;
|
||||
@ -874,4 +875,22 @@ abstract class Tools extends AsyncTools
|
||||
|
||||
return $issues;
|
||||
}
|
||||
|
||||
private static ?bool $canConvert = null;
|
||||
/**
|
||||
* Whether we can convert any audio/video file to a VoIP OGG OPUS file, or the files must be preconverted using @libtgvoipbot.
|
||||
*/
|
||||
public static function canConvertOgg(): bool
|
||||
{
|
||||
if (self::$canConvert !== null) {
|
||||
return self::$canConvert;
|
||||
}
|
||||
try {
|
||||
Ogg::convert(new LocalFile(__DIR__.'/empty.wav'), new WritableBuffer);
|
||||
self::$canConvert = true;
|
||||
} catch (\Throwable $e) {
|
||||
self::$canConvert = false;
|
||||
}
|
||||
return self::$canConvert;
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ use danog\MadelineProto\MTProtoTools\Crypt;
|
||||
use danog\MadelineProto\Ogg;
|
||||
use danog\MadelineProto\PeerNotInDbException;
|
||||
use danog\MadelineProto\RemoteUrl;
|
||||
use danog\MadelineProto\Tools;
|
||||
use danog\MadelineProto\VoIP;
|
||||
use danog\MadelineProto\VoIPController;
|
||||
use phpseclib3\Math\BigInteger;
|
||||
@ -163,7 +164,7 @@ trait AuthKeyHandler
|
||||
*/
|
||||
public function callPlay(int $id, LocalFile|RemoteUrl|ReadableStream $file): void
|
||||
{
|
||||
if (!Magic::canConvertOgg()) {
|
||||
if (!Tools::canConvertOgg()) {
|
||||
if ($file instanceof LocalFile || $file instanceof RemoteUrl) {
|
||||
Ogg::validateOgg($file);
|
||||
} else {
|
||||
@ -236,7 +237,7 @@ trait AuthKeyHandler
|
||||
*/
|
||||
public function callPlayOnHold(int $id, LocalFile|RemoteUrl|ReadableStream ...$files): void
|
||||
{
|
||||
if (!Magic::canConvertOgg()) {
|
||||
if (!Tools::canConvertOgg()) {
|
||||
foreach ($files as $file) {
|
||||
if ($file instanceof LocalFile || $file instanceof RemoteUrl) {
|
||||
Ogg::validateOgg($file);
|
||||
|
@ -17,7 +17,6 @@
|
||||
namespace danog\MadelineProto\VoIP;
|
||||
|
||||
use Amp\DeferredFuture;
|
||||
use Amp\Future;
|
||||
use Amp\Socket\ConnectContext;
|
||||
use Amp\Socket\Socket;
|
||||
use Amp\Websocket\ClosedException;
|
||||
@ -88,6 +87,7 @@ final class Endpoint
|
||||
$this->socket = $context->getStream();
|
||||
$f = $this->connectFuture;
|
||||
$this->connectFuture = null;
|
||||
assert($f !== null);
|
||||
$f->complete();
|
||||
if ($this->udp) {
|
||||
$this->udpPing();
|
||||
@ -101,8 +101,8 @@ final class Endpoint
|
||||
public function __sleep(): array
|
||||
{
|
||||
$vars = \get_object_vars($this);
|
||||
unset($vars['socket']);
|
||||
unset($vars['connectFuture']);
|
||||
unset($vars['socket'], $vars['connectFuture']);
|
||||
|
||||
return \array_keys($vars);
|
||||
}
|
||||
|
||||
@ -432,7 +432,7 @@ final class Endpoint
|
||||
$this->socket->getWriteBuffer(\strlen($payload))->bufferWrite($payload);
|
||||
} catch (ClosedException) {
|
||||
$this->socket = null;
|
||||
return $this->socket;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -446,7 +446,7 @@ final class Endpoint
|
||||
$this->socket->getWriteBuffer(\strlen($data))->bufferWrite($data);
|
||||
} catch (ClosedException) {
|
||||
$this->socket = null;
|
||||
return $this->socket;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -638,9 +638,9 @@ final class VoIPController
|
||||
/**
|
||||
* Whether the file we're currently playing is paused.
|
||||
*/
|
||||
public function isPaused(): void
|
||||
public function isPaused(): bool
|
||||
{
|
||||
$this->diskJockey->isAudioPaused();
|
||||
return $this->diskJockey->isAudioPaused();
|
||||
}
|
||||
/**
|
||||
* Files to play on hold.
|
||||
|
Loading…
Reference in New Issue
Block a user