1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-26 19:45:01 +01:00

Final improvements

This commit is contained in:
Daniil Gentili 2023-08-14 20:54:16 +02:00
parent 89efbda46a
commit bd07cfccb8
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
8 changed files with 27 additions and 37 deletions

View File

@ -163,10 +163,8 @@ Want to add your own open-source project to this list? [Click here!](https://doc
* [Logging](https://docs.madelineproto.xyz/docs/LOGGING.html) - MadelineProto provides a unified class for logging messages to the logging destination defined in settings.
* [Telegram VoIP phone calls](https://docs.madelineproto.xyz/docs/CALLS.html) - MadelineProto provides an easy wrapper to work with phone calls.
* [Requesting a call](https://docs.madelineproto.xyz/docs/CALLS.html#requesting-a-call)
* [Playing mp3 files](https://docs.madelineproto.xyz/docs/CALLS.html#playing-mp3-files)
* [Playing streams](https://docs.madelineproto.xyz/docs/CALLS.html#playing-streams)
* [Changing audio quality](https://docs.madelineproto.xyz/docs/CALLS.html#changing-audio-quality)
* [Putting it all together](https://docs.madelineproto.xyz/docs/CALLS.html#putting-it-all-together)
* [Playing audio files](https://docs.madelineproto.xyz/docs/CALLS.html#playing-audio-files)
* [Webhost support!](https://docs.madelineproto.xyz/docs/CALLS.html#webhost-support)
* [Accepting calls](https://docs.madelineproto.xyz/docs/CALLS.html#accepting-calls)
* [Uploading and downloading files](https://docs.madelineproto.xyz/docs/FILES.html) - MadelineProto provides fully parallelized wrapper methods to upload and download files that support bot API file ids, direct upload by URL and file renaming.
* [Bot API file IDs](https://docs.madelineproto.xyz/docs/FILES.html#bot-api-file-ids)

2
docs

@ -1 +1 @@
Subproject commit 71f5df203c83c7ef7f4454c09966e03a2f6307da
Subproject commit 0d7e20c2895a1d87e1f22d6eb46aed2c878bbbd7

View File

@ -33,9 +33,9 @@ use danog\MadelineProto\EventHandler\Message\Service\DialogPhotoChanged;
use danog\MadelineProto\EventHandler\SimpleFilter\FromAdmin;
use danog\MadelineProto\EventHandler\SimpleFilter\Incoming;
use danog\MadelineProto\EventHandler\SimpleFilter\IsReply;
use danog\MadelineProto\LocalFile;
use danog\MadelineProto\Logger;
use danog\MadelineProto\ParseMode;
use danog\MadelineProto\RemoteUrl;
use danog\MadelineProto\Settings;
use danog\MadelineProto\Settings\Database\Mysql;
use danog\MadelineProto\Settings\Database\Postgres;
@ -43,8 +43,6 @@ use danog\MadelineProto\Settings\Database\Redis;
use danog\MadelineProto\SimpleEventHandler;
use danog\MadelineProto\VoIP;
use function Amp\delay;
// MadelineProto is already loaded
if (class_exists(API::class)) {
// Otherwise, if a stable version of MadelineProto was installed via composer, load composer autoloader
@ -298,15 +296,13 @@ class MyEventHandler extends SimpleEventHandler
#[FilterCommand('call')]
public function callVoip(Incoming&Message $message): void
{
$this->requestCall($message->senderId)->play(new LocalFile('/../music.ogg'));
$this->requestCall($message->senderId)->play(new RemoteUrl('http://icestreaming.rai.it/1.mp3'));
}
#[Handler]
public function handleIncomingCall(VoIP&Incoming $call): void
{
$c=$call->accept()->play(new LocalFile(__DIR__.'/../music.ogg'));
delay(2.0);
$c->skip()->play(new LocalFile(__DIR__.'/../music.ogg'));
$c=$call->accept()->play(new RemoteUrl('http://icestreaming.rai.it/1.mp3'));
}
public static function getPluginPaths(): string|array|null

View File

@ -289,11 +289,10 @@ abstract class InternalDoc
}
/**
* Play files on hold in call.
* @param array<LocalFile|RemoteUrl|ReadableStream> $files
*/
public function callPlayOnHold(int $id, array $files): void
public function callPlayOnHold(int $id, \danog\MadelineProto\LocalFile|\danog\MadelineProto\RemoteUrl|\Amp\ByteStream\ReadableStream ...$files): void
{
$this->wrapper->getAPI()->callPlayOnHold($id, $files);
$this->wrapper->getAPI()->callPlayOnHold($id, ...$files);
}
/**
* Cancel a running broadcast.

View File

@ -125,11 +125,10 @@ final class VoIP extends Update implements SimpleFilters
/**
* Files to play on hold.
* @param array<LocalFile|RemoteUrl|ReadableStream> $files
*/
public function playOnHold(array $files): self
public function playOnHold(LocalFile|RemoteUrl|ReadableStream ...$files): self
{
$this->getClient()->callPlayOnHold($this->callID, $files);
$this->getClient()->callPlayOnHold($this->callID, ...$files);
return $this;
}

View File

@ -172,11 +172,10 @@ trait AuthKeyHandler
/**
* Play files on hold in call.
* @param array<LocalFile|RemoteUrl|ReadableStream> $files
*/
public function callPlayOnHold(int $id, array $files): void
public function callPlayOnHold(int $id, LocalFile|RemoteUrl|ReadableStream ...$files): void
{
($this->calls[$id] ?? null)?->playOnHold($files);
($this->calls[$id] ?? null)?->playOnHold(...$files);
}
/**

View File

@ -550,15 +550,9 @@ final class VoIPController
}
Logger::log("Starting play loop in $this!");
$file = \array_shift($this->inputFiles);
if ($file) {
$this->playingHold = false;
} else {
$this->playingHold = true;
if (!$this->holdFiles) {
Logger::log("Pausing play loop in $this because there are no hold files!");
return GenericLoop::PAUSE;
}
$file = $this->holdFiles[($this->holdIndex++) % \count($this->holdFiles)];
if (!$file) {
Logger::log("Pausing play loop in $this!");
return GenericLoop::PAUSE;
}
try {
$this->startPlaying($file);
@ -577,7 +571,16 @@ final class VoIPController
private function pullPacket(): ?string
{
if ($this->packetQueue->isEmpty()) {
if ($this->callState === CallState::ENDED || $this->playLoop->isPaused()) {
if ($this->callState === CallState::ENDED) {
return null;
}
if ($this->playLoop->isPaused()) {
if (!$this->holdFiles || $this->inputFiles) {
return null;
}
$this->playingHold = true;
$this->inputFiles []= $this->holdFiles[($this->holdIndex++) % \count($this->holdFiles)];
Assert::true($this->playLoop->resume());
return null;
}
$this->packetDeferred ??= new DeferredFuture;
@ -669,6 +672,7 @@ final class VoIPController
{
$this->inputFiles[] = $file;
if ($this->playingHold) {
$this->playingHold = false;
$this->skip();
}
Assert::true($this->playLoop->resume());
@ -698,13 +702,10 @@ final class VoIPController
}
/**
* Files to play on hold.
*
* @param array<LocalFile|RemoteUrl|ReadableStream> $files
*/
public function playOnHold(array $files): self
public function playOnHold(LocalFile|RemoteUrl|ReadableStream ...$files): self
{
$this->holdFiles = $files;
Assert::true($this->playLoop->resume());
return $this;
}

View File

@ -40,7 +40,6 @@ use danog\MadelineProto\TON\ADNLConnection;
use danog\MadelineProto\TON\APIFactory as TONAPIFactory;
use danog\MadelineProto\TON\InternalDoc as TONInternalDoc;
use danog\MadelineProto\TON\Lite;
use danog\MadelineProto\VoIP;
use danog\PhpDoc\PhpDocBuilder;
require 'vendor/autoload.php';
@ -73,7 +72,6 @@ $ignore = [ // Disallow list
SettingsAbstract::class,
Snitch::class,
AsyncConstruct::class,
VoIP::class,
Crypt::class,
NothingInTheSocketException::class,