diff --git a/README.md b/README.md index 160660314..a3377f185 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/docs b/docs index 71f5df203..0d7e20c28 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 71f5df203c83c7ef7f4454c09966e03a2f6307da +Subproject commit 0d7e20c2895a1d87e1f22d6eb46aed2c878bbbd7 diff --git a/examples/bot.php b/examples/bot.php index 174eeab61..88375adaf 100755 --- a/examples/bot.php +++ b/examples/bot.php @@ -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 diff --git a/src/InternalDoc.php b/src/InternalDoc.php index 08e990b95..e57cac92a 100644 --- a/src/InternalDoc.php +++ b/src/InternalDoc.php @@ -289,11 +289,10 @@ abstract class InternalDoc } /** * Play files on hold in call. - * @param array $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. diff --git a/src/VoIP.php b/src/VoIP.php index 3b694df7e..bdb4c96ec 100644 --- a/src/VoIP.php +++ b/src/VoIP.php @@ -125,11 +125,10 @@ final class VoIP extends Update implements SimpleFilters /** * Files to play on hold. - * @param array $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; } diff --git a/src/VoIP/AuthKeyHandler.php b/src/VoIP/AuthKeyHandler.php index 63149f864..e6e866d88 100644 --- a/src/VoIP/AuthKeyHandler.php +++ b/src/VoIP/AuthKeyHandler.php @@ -172,11 +172,10 @@ trait AuthKeyHandler /** * Play files on hold in call. - * @param array $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); } /** diff --git a/src/VoIPController.php b/src/VoIPController.php index da15d34aa..2aa5fd6ee 100644 --- a/src/VoIPController.php +++ b/src/VoIPController.php @@ -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 $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; } diff --git a/tools/phpdoc.php b/tools/phpdoc.php index 291ebcfac..32be26394 100644 --- a/tools/phpdoc.php +++ b/tools/phpdoc.php @@ -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,