Link eventHandler APIFactory

This commit is contained in:
Daniil Gentili 2020-02-28 16:02:19 +01:00
parent 997b3d3b3b
commit 38382bf053
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
6 changed files with 24 additions and 7 deletions

View File

@ -136,6 +136,7 @@ class API extends InternalDoc
$unserialized->session = $session;
APIWrapper::link($this, $unserialized);
APIWrapper::link($this->wrapper, $this);
AbstractAPIFactory::link($this->wrapper->getFactory(), $this);
if (isset($this->API)) {
$this->storage = $this->API->storage ?? $this->storage;

View File

@ -34,6 +34,7 @@ use Amp\Http\Client\HttpClientBuilder;
use Amp\Http\Client\Request;
use Amp\Socket\ConnectContext;
use Amp\Socket\DnsConnector;
use Amp\Websocket\Client\Handshake;
use Amp\Websocket\Client\Rfc6455Connector;
use danog\MadelineProto\MTProto\PermAuthKey;
use danog\MadelineProto\MTProto\TempAuthKey;
@ -233,9 +234,11 @@ class DataCenter
$this->nonProxiedDoHClient = Magic::$altervista || Magic::$zerowebhost ? new Rfc1035StubResolver() : new Rfc8484StubResolver($nonProxiedDoHConfig);
$this->dnsConnector = new DnsConnector(new Rfc1035StubResolver());
if (\class_exists(Rfc6455Connector::class)) {
$this->webSocketConnnector = new Rfc6455Connector($this->HTTPClient);
}
}
}
public function dcConnect(string $dc_number, int $id = -1): \Generator
{
$old = isset($this->sockets[$dc_number]) && ($this->sockets[$dc_number]->shouldReconnect() || $id !== -1 && $this->sockets[$dc_number]->hasConnection($id) && $this->sockets[$dc_number]->getConnection($id)->shouldReconnect());
@ -468,6 +471,9 @@ class DataCenter
$stream[1] = $useDoH ? new DoHConnector($this, $ctx) : $this->dnsConnector;
}
if (\in_array($stream[0], [WsStream::class, WssStream::class]) && $stream[1] === []) {
if (!\class_exists(Handshake::class)) {
throw new Exception('Please install amphp/websocket-client by running "composer require amphp/websocket-client:dev-master"');
}
$stream[1] = $this->webSocketConnnector;
}
$ctx->addStream(...$stream);

View File

@ -138,7 +138,7 @@ class FeedLoop extends ResumableSignalLoop
foreach ($updates as $update) {
$res = $this->feedSingle($update);
if ($res instanceof \Generator) {
$res = yield $res;
$res = yield from $res;
}
$result[$res] = true;
}

View File

@ -20,6 +20,7 @@
namespace danog\MadelineProto\Wrappers;
use danog\MadelineProto\EventHandler;
use danog\MadelineProto\Tools;
/**
* Event handler.
@ -84,6 +85,9 @@ trait Events
$this->settings['updates']['callback'] = [$this, 'eventUpdateHandler'];
$this->settings['updates']['handle_updates'] = true;
$this->settings['updates']['run_callback'] = true;
if (method_exists($this->event_handler_instance, 'onStart')) {
Tools::callFork($this->event_handler_instance->onStart());
}
if ($this->inited()) {
$this->startUpdateSystem();
}

View File

@ -60,7 +60,13 @@ composer config platform.php "7.4"
composer clearcache
composer update
composer require amphp/mysql
[ $PHP_MAJOR_VERSION -eq 5 ] && composer require dstuecken/php7ify && composer require symfony/polyfill-php70
[ $PHP_MAJOR_VERSION -eq 5 ] && {
composer require dstuecken/php7ify
composer require symfony/polyfill-php70
composer require symfony/polyfill-php71
composer require symfony/polyfill-php72
composer require symfony/polyfill-php73
}
[ $PHP_MAJOR_VERSION -eq 7 ] && [ $PHP_MINOR_VERSION -eq 0 ] && {
composer require symfony/polyfill-php71
composer require symfony/polyfill-php72