mirror of
https://github.com/danog/MadelineProto.git
synced 2025-01-22 13:31:21 +01:00
Allow playing remote URLs and streams
This commit is contained in:
parent
e8ad2791bd
commit
f0d156adea
@ -18,6 +18,7 @@ namespace danog\MadelineProto;
|
||||
|
||||
use danog\MadelineProto\EventHandler\SimpleFilters;
|
||||
use danog\MadelineProto\EventHandler\Update;
|
||||
use danog\MadelineProto\Ipc\Wrapper\ReadableStream;
|
||||
use danog\MadelineProto\VoIP\CallState;
|
||||
use danog\MadelineProto\VoIP\DiscardReason;
|
||||
|
||||
@ -87,7 +88,7 @@ final class VoIP extends Update implements SimpleFilters
|
||||
/**
|
||||
* Play file.
|
||||
*/
|
||||
public function play(string $file): self
|
||||
public function play(string|LocalFile|RemoteUrl|ReadableStream $file): self
|
||||
{
|
||||
$this->getClient()->callPlay($this->callID, $file);
|
||||
|
||||
@ -97,7 +98,7 @@ final class VoIP extends Update implements SimpleFilters
|
||||
/**
|
||||
* Play file.
|
||||
*/
|
||||
public function then(string $file): self
|
||||
public function then(string|LocalFile|RemoteUrl|ReadableStream $file): self
|
||||
{
|
||||
$this->getClient()->callPlay($this->callID, $file);
|
||||
|
||||
@ -106,7 +107,7 @@ final class VoIP extends Update implements SimpleFilters
|
||||
|
||||
/**
|
||||
* Files to play on hold.
|
||||
* @param array<string> $files
|
||||
* @param array<string|LocalFile|RemoteUrl|ReadableStream> $files
|
||||
*/
|
||||
public function playOnHold(array $files): self
|
||||
{
|
||||
|
@ -21,10 +21,13 @@ declare(strict_types=1);
|
||||
namespace danog\MadelineProto\VoIP;
|
||||
|
||||
use Amp\DeferredFuture;
|
||||
use danog\MadelineProto\Ipc\Wrapper\ReadableStream;
|
||||
use danog\MadelineProto\LocalFile;
|
||||
use danog\MadelineProto\Logger;
|
||||
use danog\MadelineProto\Magic;
|
||||
use danog\MadelineProto\MTProtoTools\Crypt;
|
||||
use danog\MadelineProto\PeerNotInDbException;
|
||||
use danog\MadelineProto\RemoteUrl;
|
||||
use danog\MadelineProto\VoIP;
|
||||
use danog\MadelineProto\VoIPController;
|
||||
use phpseclib3\Math\BigInteger;
|
||||
@ -151,14 +154,14 @@ trait AuthKeyHandler
|
||||
/**
|
||||
* Play file in call.
|
||||
*/
|
||||
public function callPlay(int $id, string $file): void
|
||||
public function callPlay(int $id, string|LocalFile|RemoteUrl|ReadableStream $file): void
|
||||
{
|
||||
($this->calls[$id] ?? null)?->play($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Play files on hold in call.
|
||||
* @param array<string> $files
|
||||
* @param array<string|LocalFile|RemoteUrl|ReadableStream> $files
|
||||
*/
|
||||
public function callPlayOnHold(int $id, array $files): void
|
||||
{
|
||||
|
@ -18,6 +18,9 @@
|
||||
|
||||
namespace danog\MadelineProto;
|
||||
|
||||
use Amp\ByteStream\ReadableStream;
|
||||
use Amp\Http\Client\HttpClientBuilder;
|
||||
use Amp\Http\Client\Request;
|
||||
use danog\MadelineProto\MTProtoTools\Crypt;
|
||||
use danog\MadelineProto\Stream\Common\FileBufferedStream;
|
||||
use danog\MadelineProto\Stream\ConnectionContext;
|
||||
@ -100,9 +103,9 @@ final class VoIPController
|
||||
|
||||
private array $call;
|
||||
|
||||
/** @var array<string> */
|
||||
/** @var array<string|LocalFile|RemoteUrl|ReadableStream> */
|
||||
private array $holdFiles = [];
|
||||
/** @var list<string> */
|
||||
/** @var list<string|LocalFile|RemoteUrl|ReadableStream> */
|
||||
private array $inputFiles = [];
|
||||
private int $holdIndex = 0;
|
||||
|
||||
@ -551,17 +554,22 @@ final class VoIPController
|
||||
/**
|
||||
* Open OGG file for reading.
|
||||
*/
|
||||
private function openFile(string $file): Ogg
|
||||
private function openFile(string|LocalFile|RemoteUrl|ReadableStream $file): Ogg
|
||||
{
|
||||
$ctx = new ConnectionContext;
|
||||
$ctx->addStream(FileBufferedStream::class, openFile($file, 'r'));
|
||||
$ctx->addStream(FileBufferedStream::class, match (true) {
|
||||
is_string($file) => openFile($file, 'r'),
|
||||
$file instanceof LocalFile => openFile($file->file, 'r'),
|
||||
$file instanceof RemoteUrl => HttpClientBuilder::buildDefault()->request(new Request($file->url))->getBody(),
|
||||
$file instanceof ReadableStream => $file,
|
||||
});
|
||||
$stream = $ctx->getStream();
|
||||
return new Ogg($stream);
|
||||
}
|
||||
/**
|
||||
* Play file.
|
||||
*/
|
||||
public function play(string $file): self
|
||||
public function play(string|LocalFile|RemoteUrl|ReadableStream $file): self
|
||||
{
|
||||
$this->inputFiles[] = $file;
|
||||
if ($this->playingHold) {
|
||||
@ -574,7 +582,7 @@ final class VoIPController
|
||||
/**
|
||||
* Files to play on hold.
|
||||
*
|
||||
* @param array<string> $files
|
||||
* @param array<string|LocalFile|RemoteUrl|ReadableStream> $files
|
||||
*/
|
||||
public function playOnHold(array $files): self
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user