Fix websockets
This commit is contained in:
parent
a7b0a16a01
commit
069c599a7c
@ -31,6 +31,8 @@ use Amp\Http\Client\Cookie\CookieJar;
|
|||||||
use Amp\Http\Client\Cookie\InMemoryCookieJar;
|
use Amp\Http\Client\Cookie\InMemoryCookieJar;
|
||||||
use Amp\Http\Client\DelegateHttpClient;
|
use Amp\Http\Client\DelegateHttpClient;
|
||||||
use Amp\Http\Client\HttpClientBuilder;
|
use Amp\Http\Client\HttpClientBuilder;
|
||||||
|
use Amp\Http\Client\Interceptor\ModifyRequest;
|
||||||
|
use Amp\Http\Client\Interceptor\RemoveRequestHeader;
|
||||||
use Amp\Http\Client\Request;
|
use Amp\Http\Client\Request;
|
||||||
use Amp\Socket\ConnectContext;
|
use Amp\Socket\ConnectContext;
|
||||||
use Amp\Websocket\Client\Rfc6455Connector;
|
use Amp\Websocket\Client\Rfc6455Connector;
|
||||||
|
@ -180,7 +180,7 @@ class Magic
|
|||||||
$DohConfig = new DoHConfig(
|
$DohConfig = new DoHConfig(
|
||||||
[
|
[
|
||||||
new Nameserver('https://mozilla.cloudflare-dns.com/dns-query'),
|
new Nameserver('https://mozilla.cloudflare-dns.com/dns-query'),
|
||||||
new Nameserver('https://google.com/resolve', Nameserver::GOOGLE_JSON, ["Host" => "dns.google.com"]),
|
new Nameserver('https://dns.google/resolve'),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
resolver(new Rfc8484StubResolver($DohConfig));
|
resolver(new Rfc8484StubResolver($DohConfig));
|
||||||
|
@ -20,6 +20,7 @@ namespace danog\MadelineProto\Stream\Transport;
|
|||||||
|
|
||||||
use Amp\Promise;
|
use Amp\Promise;
|
||||||
use Amp\Socket\EncryptableSocket;
|
use Amp\Socket\EncryptableSocket;
|
||||||
|
use Amp\Websocket\Client\Connector;
|
||||||
use Amp\Websocket\Client\Handshake;
|
use Amp\Websocket\Client\Handshake;
|
||||||
use danog\MadelineProto\Stream\Async\RawStream;
|
use danog\MadelineProto\Stream\Async\RawStream;
|
||||||
use danog\MadelineProto\Stream\ConnectionContext;
|
use danog\MadelineProto\Stream\ConnectionContext;
|
||||||
@ -67,8 +68,8 @@ class WsStream implements RawStreamInterface, ProxyStreamInterface
|
|||||||
{
|
{
|
||||||
$this->dc = $ctx->getIntDc();
|
$this->dc = $ctx->getIntDc();
|
||||||
|
|
||||||
$handshake = new Handshake(\str_replace('tcp://', $ctx->isSecure() ? 'ws://' : 'wss://', $ctx->getStringUri()));
|
$handshake = new Handshake(\str_replace('tcp://', $ctx->isSecure() ? 'wss://' : 'ws://', $ctx->getStringUri()));
|
||||||
|
|
||||||
$this->stream = yield ($this->connector ?? connector())->connect($handshake, $ctx->getCancellationToken());
|
$this->stream = yield ($this->connector ?? connector())->connect($handshake, $ctx->getCancellationToken());
|
||||||
|
|
||||||
yield $this->write($header);
|
yield $this->write($header);
|
||||||
@ -96,7 +97,7 @@ class WsStream implements RawStreamInterface, ProxyStreamInterface
|
|||||||
$data = yield $this->message->buffer();
|
$data = yield $this->message->buffer();
|
||||||
$this->message = null;
|
$this->message = null;
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Throwable $e) {
|
||||||
if ($e->getReason() !== 'Client closed the underlying TCP connection') {
|
if ($e->getReason() !== 'Client closed the underlying TCP connection') {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
@ -129,7 +130,9 @@ class WsStream implements RawStreamInterface, ProxyStreamInterface
|
|||||||
}
|
}
|
||||||
public function setExtra($extra)
|
public function setExtra($extra)
|
||||||
{
|
{
|
||||||
$this->connector = $extra;
|
if ($extra instanceof Connector) {
|
||||||
|
$this->connector = $extra;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getName(): string
|
public static function getName(): string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user