From 532a45406b9ae5365e53c65d1a456bd20a386024 Mon Sep 17 00:00:00 2001 From: cdosoftei Date: Mon, 27 Nov 2023 18:31:22 -0500 Subject: [PATCH] :arrow_up: Update dependencies --- .github/workflows/ci.yaml | 2 ++ composer.json | 16 ++++----- etc/phpstan.neon | 2 +- src/Command/Channel/DTMF/Handler.php | 2 +- src/Command/Channel/Hangup/Handler.php | 2 +- src/Command/Channel/Originate/Handler.php | 7 ++-- src/Command/Channel/Playback/Handler.php | 5 +-- src/Command/Channel/Redirect/Handler.php | 20 ++++++++--- src/Command/Conference/Member/Handler.php | 2 +- src/Command/Conference/Speak/Handler.php | 2 +- src/Plan/CaptureSpeech/Element.php | 3 ++ src/Plan/CaptureSpeech/Handler.php | 41 ++++++++++++++++++----- src/Plan/CaptureTones/Handler.php | 2 +- src/Plan/Conference/Handler.php | 8 ++--- src/Plan/Consumer.php | 35 +++++++++---------- src/Plan/Hangup/Handler.php | 2 +- src/Plan/Playback/Handler.php | 6 ++-- src/Plan/Record/Handler.php | 16 ++++----- src/Plan/Silence/Handler.php | 2 +- src/Plan/Speak/Handler.php | 6 ++-- src/Switch/ESL/Client.php | 2 +- src/Switch/ESL/Event/Custom.php | 2 +- 22 files changed, 111 insertions(+), 74 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5093aa2..19f40f2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,6 +14,8 @@ jobs: - ubuntu-20.04 php: - 8.1 + - 8.2 + - 8.3 steps: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 diff --git a/composer.json b/composer.json index 6fcaa86..4c15fee 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "rtckit/ficore", "description": "FreeSWITCH Integration Core", - "version": "0.0.2", + "version": "0.0.3", "keywords": [ "telecommunications", "voip", @@ -28,19 +28,19 @@ "ext-libxml": "*", "ext-pcre": "*", "ext-simplexml": "*", - "monolog/monolog": "^3.2", - "ramsey/uuid": "^4.4", - "react/event-loop": "^1.3", - "react/promise": "^2.9", + "monolog/monolog": "^3.5", + "ramsey/uuid": "^4.7", + "react/event-loop": "^1.5", + "react/promise": "^3.1", "rtckit/esl": "^0.8", "rtckit/react-esl": "^0.8", "rtckit/sip": "^0.7", "wyrihaximus/react-psr-3-stdio": "^3.0" }, "require-dev": { - "phpstan/phpstan": "^1.9", - "phpunit/phpunit": "^9.5", - "vimeo/psalm": "^5.6" + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^10.4", + "vimeo/psalm": "^5.16" }, "suggest": { "ext-pcntl": "Enables daemonization support", diff --git a/etc/phpstan.neon b/etc/phpstan.neon index 9429dc2..ae9257c 100644 --- a/etc/phpstan.neon +++ b/etc/phpstan.neon @@ -3,4 +3,4 @@ includes: parameters: checkGenericClassInNonGenericObjectType: false ignoreErrors: - - '#Call to an undefined method React\\Promise\\PromiseInterface::otherwise\(\)#' + - '#Parameter \#1 \$onFulfilled of method React\\Promise\\PromiseInterface::then\(\) expects \(callable\(mixed\):#' diff --git a/src/Command/Channel/DTMF/Handler.php b/src/Command/Channel/DTMF/Handler.php index dcfd48e..6d94428 100644 --- a/src/Command/Channel/DTMF/Handler.php +++ b/src/Command/Channel/DTMF/Handler.php @@ -26,7 +26,7 @@ public function execute(RequestInterface $request): PromiseInterface $response = new Response(); - if ($request->action !== ActionEnum::Send) { + if (!isset($request->action)) { $response->successful = false; return resolve($response); diff --git a/src/Command/Channel/Hangup/Handler.php b/src/Command/Channel/Hangup/Handler.php index 730c7bd..a26b1ef 100644 --- a/src/Command/Channel/Hangup/Handler.php +++ b/src/Command/Channel/Hangup/Handler.php @@ -72,7 +72,7 @@ public function execute(RequestInterface $request): PromiseInterface $response->successful = false; } - return resolve(); + return resolve(null); }); } diff --git a/src/Command/Channel/Originate/Handler.php b/src/Command/Channel/Originate/Handler.php index 7f1ddd9..f7b9ce7 100644 --- a/src/Command/Channel/Originate/Handler.php +++ b/src/Command/Channel/Originate/Handler.php @@ -56,7 +56,6 @@ public function execute(RequestInterface $request): PromiseInterface } assert(isset($job)); - assert($job instanceof OriginateJob); $response->originateJobs[] = $job; @@ -215,7 +214,7 @@ public function execute(RequestInterface $request): PromiseInterface $job->originateStr = $originateStr; $this->loopGateways($job) - ->otherwise(function (\Throwable $t) { + ->catch(function (\Throwable $t) { $t = $t->getPrevious() ?: $t; $this->app->eslClient->logger->error('Originate channel exception: ' . $t->getMessage(), [ @@ -323,7 +322,7 @@ protected function loopGateways(OriginateJob $originateJob): PromiseInterface if ($success) { $this->app->commandConsumer->logger->info("Call Attempt OK for RequestUUID {$originateJob->uuid}"); - return resolve(); + return resolve(null); } $this->app->commandConsumer->logger->info("Call Attempt Failed for RequestUUID {$originateJob->uuid}, retrying next gateway ..."); @@ -337,7 +336,7 @@ protected function loopGateways(OriginateJob $originateJob): PromiseInterface return $this->loopGateways($originateJob); }) - ->otherwise(function (\Throwable $t) { + ->catch(function (\Throwable $t) { $t = $t->getPrevious() ?: $t; $this->app->eslClient->logger->error('loopGateways exception: ' . $t->getMessage(), [ diff --git a/src/Command/Channel/Playback/Handler.php b/src/Command/Channel/Playback/Handler.php index d0f744e..be5f044 100644 --- a/src/Command/Channel/Playback/Handler.php +++ b/src/Command/Channel/Playback/Handler.php @@ -60,7 +60,7 @@ public function execute(RequestInterface $request): PromiseInterface $this->app->commandConsumer->logger->error("Play Failed '{$command}': " . ($eslResponse->getBody() ?? '')); } - return resolve(); + return resolve(null); }); } @@ -96,7 +96,7 @@ public function execute(RequestInterface $request): PromiseInterface $this->app->commandConsumer->logger->error("PlayStop Failed '{$command}': " . ($eslResponse->getBody() ?? '')); } - return resolve(); + return resolve(null); }); } @@ -160,6 +160,7 @@ private function getPlayCommands(Request $request): PromiseInterface $ret = []; foreach ($results as $commands) { + assert(is_array($commands)); $ret = array_merge($ret, $commands); } diff --git a/src/Command/Channel/Redirect/Handler.php b/src/Command/Channel/Redirect/Handler.php index 506b7bd..79c83dd 100644 --- a/src/Command/Channel/Redirect/Handler.php +++ b/src/Command/Channel/Redirect/Handler.php @@ -25,7 +25,7 @@ public function execute(RequestInterface $request): PromiseInterface $response = new Response(); - if ($request->action !== ActionEnum::Redirect) { + if (!isset($request->action)) { $response->successful = false; return resolve($response); @@ -48,17 +48,27 @@ public function execute(RequestInterface $request): PromiseInterface ), ]) ->then(function (array $args) use ($request): PromiseInterface { - $destNumber = $args[$this->app->config->appPrefix . '_destination_number']->getBody(); + $prefixedDestNumber = $args[$this->app->config->appPrefix . '_destination_number']; + + assert($prefixedDestNumber instanceof ESL\Response\ApiResponse); + + $destNumber = $prefixedDestNumber->getBody(); + + if (is_string($destNumber) && (($destNumber === '_undef_') || (strpos($destNumber, '-ERR') === 0))) { + assert($args['destination_number'] instanceof ESL\Response\ApiResponse); - if (($destNumber === '_undef_') || (strpos($destNumber, '-ERR') === 0)) { $destNumber = $args['destination_number']->getBody(); + assert(is_string($destNumber)); + return $request->channel->core->client->api( - (new ESL\Request\Api())->setParameters("uuid_setvar {$request->channel->uuid} {$this->app->config->appPrefix}_destination_number " . $destNumber) + (new ESL\Request\Api())->setParameters( + "uuid_setvar {$request->channel->uuid} {$this->app->config->appPrefix}_destination_number {$destNumber}" + ) ); } - return resolve(); + return resolve(null); }) ->then(function () use ($request): PromiseInterface { $request->channel->transferInProgress = true; diff --git a/src/Command/Conference/Member/Handler.php b/src/Command/Conference/Member/Handler.php index bf072c7..075a953 100644 --- a/src/Command/Conference/Member/Handler.php +++ b/src/Command/Conference/Member/Handler.php @@ -42,7 +42,7 @@ public function execute(RequestInterface $request): PromiseInterface $this->app->commandConsumer->logger->debug("`conference {$request->conference->room} {$request->action->value} {$member}` success"); } - return resolve(); + return resolve(null); }); } diff --git a/src/Command/Conference/Speak/Handler.php b/src/Command/Conference/Speak/Handler.php index 77ccc52..81c4daf 100644 --- a/src/Command/Conference/Speak/Handler.php +++ b/src/Command/Conference/Speak/Handler.php @@ -25,7 +25,7 @@ public function execute(RequestInterface $request): PromiseInterface $response = new Response(); - if ($request->action !== ActionEnum::Speak) { + if (!isset($request->action)) { $response->successful = false; return resolve($response); diff --git a/src/Plan/CaptureSpeech/Element.php b/src/Plan/CaptureSpeech/Element.php index 71d6625..97f1767 100644 --- a/src/Plan/CaptureSpeech/Element.php +++ b/src/Plan/CaptureSpeech/Element.php @@ -8,6 +8,8 @@ use RTCKit\FiCore\Plan\AbstractElement; +use stdClass as Event; + class Element extends AbstractElement { public string $sequence; @@ -19,6 +21,7 @@ class Element extends AbstractElement public string $grammar; public string $grammarPath; public TimerInterface $timer; + public Event $event; /** @var list */ public array $setVars = []; diff --git a/src/Plan/CaptureSpeech/Handler.php b/src/Plan/CaptureSpeech/Handler.php index 539b57d..c3434e4 100644 --- a/src/Plan/CaptureSpeech/Handler.php +++ b/src/Plan/CaptureSpeech/Handler.php @@ -15,6 +15,7 @@ PromiseInterface }; use RTCKit\ESL; +use RTCKit\FiCore\Exception\FiCoreException; use RTCKit\FiCore\Plan\{ AbstractElement, HandlerInterface, @@ -63,9 +64,9 @@ public function execute(Channel $channel, AbstractElement $element): PromiseInte if (!$response->isSuccessful()) { $this->app->planConsumer->logger->error('GetSpeech Failed - ' . ($response->getBody() ?? '')); - $deferred->resolve(); + $deferred->resolve(null); - return reject(); + return reject(new FiCoreException('GetSpeech Failed')); } return $element->channel->client->sendMsg( @@ -118,6 +119,21 @@ public function execute(Channel $channel, AbstractElement $element): PromiseInte return $this->app->planConsumer->waitForEvent($element->channel); }) ->then(function (Event $event) use ($element): PromiseInterface { + if ( + ($event->{'Event-Name'} === 'DETECTED_SPEECH') && + in_array($event->{'Speech-Type'}, ['begin-speaking', 'detected-speech']) + ) { + $this->app->planConsumer->logger->debug("GetSpeech Break ({$event->{'Speech-Type'}})"); + + if ($event->{'Speech-Type'} === 'detected-speech') { + $element->event = $event; + } + + return $element->channel->client->bgApi( + (new ESL\Request\BgApi())->setParameters('uuid_break ' . $element->channel->uuid . ' all') + ); + } + $response = $event->{'Application-Response'} ?? ''; $this->app->planConsumer->logger->debug("GetSpeech prompt played ({$response})"); @@ -168,7 +184,7 @@ public function execute(Channel $channel, AbstractElement $element): PromiseInte $signal->channel = $element->channel; - if (isset($args['response'])) { + if (isset($args['response']) && is_string($args['response'])) { $resultXml = simplexml_load_string($args['response']); if ($resultXml === false) { $this->app->planConsumer->logger->error("GetSpeech result failure, cannot parse result"); @@ -222,7 +238,7 @@ public function execute(Channel $channel, AbstractElement $element): PromiseInte ->then(function (bool $break) use ($deferred) { $deferred->resolve($break); }) - ->otherwise(function (Throwable $t) { + ->catch(function (Throwable $t) { $t = $t->getPrevious() ?: $t; $this->app->planConsumer->logger->error("Unhandled getspeech element error: " . $t->getMessage(), [ 'file' => $t->getFile(), @@ -237,14 +253,23 @@ protected function waitForEvent(Element $element): PromiseInterface { return $this->app->planConsumer->waitForEvent($element->channel) ->then(function (?Event $event) use ($element): PromiseInterface { + if (isset($element->event)) { + $event = $element->event; + } + if (!isset($event)) { $this->app->planConsumer->logger->warning('GetSpeech Break (empty event)'); - return resolve(); - } elseif (($event->{'Event-Name'} === 'DETECTED_SPEECH') && ($event->{'Speech-Type'} === 'detected-speech')) { - Loop::cancelTimer($element->timer); + return resolve(null); + } else if ( + ($event->{'Event-Name'} === 'DETECTED_SPEECH') && + in_array($event->{'Speech-Type'}, ['begin-speaking', 'detected-speech']) + ) { + if (isset($element->timer)) { + Loop::cancelTimer($element->timer); + } - $this->app->planConsumer->logger->info("GetSpeech, result '{$event->_body}'"); + $this->app->planConsumer->logger->info("GetSpeech ({$event->{'Speech-Type'}}), result '{$event->_body}'"); return resolve($event->_body); } diff --git a/src/Plan/CaptureTones/Handler.php b/src/Plan/CaptureTones/Handler.php index 189dcca..bc9efee 100644 --- a/src/Plan/CaptureTones/Handler.php +++ b/src/Plan/CaptureTones/Handler.php @@ -119,7 +119,7 @@ public function execute(Channel $channel, AbstractElement $element): PromiseInte $this->app->planConsumer->logger->info('GetDigits, No Digits Received'); } - return resolve(); + return resolve(null); }); } } diff --git a/src/Plan/Conference/Handler.php b/src/Plan/Conference/Handler.php index d8e76e6..cd80c22 100644 --- a/src/Plan/Conference/Handler.php +++ b/src/Plan/Conference/Handler.php @@ -100,7 +100,7 @@ public function execute(Channel $channel, AbstractElement $element): PromiseInte }); } - return resolve(); + return resolve(null); }) ->then(function () use ($element): PromiseInterface { $this->app->planConsumer->logger->info("Entering Conference: Room {$element->room}", $element->flags); @@ -240,7 +240,7 @@ public function execute(Channel $channel, AbstractElement $element): PromiseInte }); } - return resolve(); + return resolve(null); }) ->then(function () use ($element, $digitRealm) { $element->channel->client->sendMsg( @@ -279,7 +279,7 @@ public function execute(Channel $channel, AbstractElement $element): PromiseInte }); } }) - ->otherwise(function (\Throwable $t) { + ->catch(function (\Throwable $t) { $t = $t->getPrevious() ?: $t; $this->app->planConsumer->logger->error('Unhandled exception: ' . $t->getMessage(), [ @@ -307,7 +307,7 @@ protected function waitForEvent(Element $element): PromiseInterface $this->app->signalProducer->produce($floorSignal); } } else { - return resolve(); + return resolve(null); } } diff --git a/src/Plan/Consumer.php b/src/Plan/Consumer.php index d18f692..32ab53a 100644 --- a/src/Plan/Consumer.php +++ b/src/Plan/Consumer.php @@ -129,8 +129,6 @@ public function onConnect(RemoteOutboundClient $client, ESL\Response\CommandRepl $channel->context = $context; } - assert(is_string($targetSequence)); - $channel->client = $client; $channel->coreUuid = $channel->context['core-uuid']; $channel->callerName = urldecode($channel->context['caller-caller-id-name'] ?? ''); @@ -322,10 +320,10 @@ public function consumeEntryPoint(Channel $channel, string $sequence, ?AbstractS $this->logger->info('Reached end of plan'); } }) - ->otherwise(function (HangupException $t) { + ->catch(function (HangupException $t) { $this->logger->warning('Channel has hung up, breaking Processing Call', [$t->getMessage()]); }) - ->otherwise(function (\Throwable $t) { + ->catch(function (\Throwable $t) { $t = $t->getPrevious() ?: $t; $this->logger->error('Processing call failure: ' . $t->getMessage(), [ @@ -333,7 +331,7 @@ public function consumeEntryPoint(Channel $channel, string $sequence, ?AbstractS 'line' => $t->getLine(), ]); }) - ->always(function () use ($channel) { + ->finally(function () use ($channel) { $this->disconnect($channel); $this->logger->info('Processing Call Ended'); }); @@ -456,7 +454,7 @@ public function waitForEvent(Channel $channel, int $timeout = 3600, bool $raiseE $deferred->reject(new HangupException()); } else { $this->logger->debug('wait for action end timed out!'); - $deferred->resolve(); + $deferred->resolve(null); } }); @@ -506,7 +504,7 @@ public function consume(Channel $channel, string $sequence, ?AbstractSignal $sig ->then(function (?array $elements) use ($channel): PromiseInterface { /** @var list $elements */ if (empty($elements)) { - return resolve(); + return resolve(null); } if (isset($channel->hangupCause)) { @@ -517,10 +515,10 @@ public function consume(Channel $channel, string $sequence, ?AbstractSignal $sig return $this->rewindExecuteSequence($channel); }) - ->otherwise(function (HangupException $t) { + ->catch(function (HangupException $t) { $this->logger->warning('Channel has hung up, breaking Processing Call', [$t->getMessage()]); }) - ->otherwise(function (\Throwable $t) { + ->catch(function (\Throwable $t) { $t = $t->getPrevious() ?: $t; $this->logger->error('Processing call failure: ' . $t->getMessage(), [ @@ -540,11 +538,10 @@ public function rewindExecuteSequence(Channel $channel): PromiseInterface public function executeSequence(Channel $channel): PromiseInterface { if (!count($channel->elements)) { - return resolve(); + return resolve(null); } $element = array_shift($channel->elements); - assert($element instanceof AbstractElement); return $this->executeElement($channel, $element) ->then(function (?bool $break = null) use ($channel): PromiseInterface { @@ -553,18 +550,18 @@ public function executeSequence(Channel $channel): PromiseInterface $this->logger->info("[{$elementType}] Done"); if ($break) { - return resolve(); + return resolve(null); } if (isset($channel->transferInProgress)) { $this->logger->info("Transfer in progress, breaking redirect"); - return resolve(); + return resolve(null); } return $this->executeSequence($channel); }) - ->otherwise(function (\Throwable $t) { + ->catch(function (\Throwable $t) { $t = $t->getPrevious() ?: $t; $this->logger->error('Plan exception: ' . $t->getMessage(), [ @@ -589,10 +586,10 @@ public function executeElement(Channel $channel, AbstractElement $element): Prom $channel->answered = true; $channel->status = StatusEnum::InProgress; - return resolve(); + return resolve(null); }); } else { - $promise = resolve(); + $promise = resolve(null); } $handler = $this->handlers[$element::class]; @@ -611,17 +608,17 @@ public function getVariable(Channel $channel, string $variable): PromiseInterfac ) ->then(function (ESL\Response $response): PromiseInterface { if (!($response instanceof ESL\Response\ApiResponse)) { - return resolve(); + return resolve(null); } $body = $response->getBody(); if (empty($body)) { - return resolve(); + return resolve(null); } if (($body === '_undef_') || (strpos($body, '-ERR') === 0)) { - return resolve(); + return resolve(null); } return resolve($body); diff --git a/src/Plan/Hangup/Handler.php b/src/Plan/Hangup/Handler.php index cff1460..0f2e9d6 100644 --- a/src/Plan/Hangup/Handler.php +++ b/src/Plan/Hangup/Handler.php @@ -49,7 +49,7 @@ public function execute(Channel $channel, AbstractElement $element): PromiseInte $this->app->planConsumer->logger->error('Hangup Failed: ' . ($response->getBody() ?? '')); } - return resolve(); + return resolve(null); }); } diff --git a/src/Plan/Playback/Handler.php b/src/Plan/Playback/Handler.php index 4a88755..fb7f363 100644 --- a/src/Plan/Playback/Handler.php +++ b/src/Plan/Playback/Handler.php @@ -31,7 +31,7 @@ public function execute(Channel $channel, AbstractElement $element): PromiseInte if (empty($element->medium)) { $this->app->planConsumer->logger->error('Invalid Sound File - Ignoring Play'); - return resolve(); + return resolve(null); } $element->setVars[] = 'playback_sleep_val=0'; @@ -65,7 +65,7 @@ public function execute(Channel $channel, AbstractElement $element): PromiseInte if (!($response instanceof ESL\Response\CommandReply) || !$response->isSuccessful()) { $this->app->planConsumer->logger->error('Play Failed - ' . ($response->getBody() ?? '')); - return resolve(); + return resolve(null); } return $this->app->planConsumer->waitForEvent($element->channel) @@ -78,7 +78,7 @@ public function execute(Channel $channel, AbstractElement $element): PromiseInte $this->app->planConsumer->logger->info('Play Finished'); - return resolve(); + return resolve(null); }); }); } diff --git a/src/Plan/Record/Handler.php b/src/Plan/Record/Handler.php index bf8a91f..e5876c4 100644 --- a/src/Plan/Record/Handler.php +++ b/src/Plan/Record/Handler.php @@ -60,7 +60,7 @@ public function execute(Channel $channel, AbstractElement $element): PromiseInte return $this->finalize($element, $deferred); }); } else { - $promise = resolve(); + $promise = resolve(null); if (isset($element->playMedium)) { $promise = $element->channel->client->sendMsg( @@ -76,9 +76,9 @@ public function execute(Channel $channel, AbstractElement $element): PromiseInte ->then(function (Event $event) use ($element): PromiseInterface { $element->event = $event; - return resolve(); + return resolve(null); }) - ->otherwise(function (Throwable $t) { + ->catch(function (Throwable $t) { $t = $t->getPrevious() ?: $t; $this->app->planConsumer->logger->error("Unhandled record element error: " . $t->getMessage(), [ 'file' => $t->getFile(), @@ -134,7 +134,7 @@ public function execute(Channel $channel, AbstractElement $element): PromiseInte return $this->finalize($element, $deferred); }) - ->otherwise(function (Throwable $t) { + ->catch(function (Throwable $t) { $t = $t->getPrevious() ?: $t; $this->app->planConsumer->logger->error("Unhandled record element error: " . $t->getMessage(), [ 'file' => $t->getFile(), @@ -169,7 +169,7 @@ protected function finalize(Element $element, Deferred $deferred): PromiseInterf $this->app->signalProducer->produce($signal); if (!isset($element->onCompletedSeq)) { - $deferred->resolve(); + $deferred->resolve(null); } } @@ -178,13 +178,13 @@ protected function finalize(Element $element, Deferred $deferred): PromiseInterf ->then(function () use ($deferred) { $deferred->resolve(true); - return resolve(); + return resolve(null); }); } } else { - $deferred->resolve(); + $deferred->resolve(null); } - return resolve(); + return resolve(null); } } diff --git a/src/Plan/Silence/Handler.php b/src/Plan/Silence/Handler.php index 77ac5b9..9754d9b 100644 --- a/src/Plan/Silence/Handler.php +++ b/src/Plan/Silence/Handler.php @@ -41,7 +41,7 @@ public function execute(Channel $channel, AbstractElement $element): PromiseInte ->then(function () use ($element) { return $this->app->planConsumer->waitForEvent($element->channel) ->then(function () { - return resolve(); + return resolve(null); }); }); } diff --git a/src/Plan/Speak/Handler.php b/src/Plan/Speak/Handler.php index 7a9e0b4..09b5dba 100644 --- a/src/Plan/Speak/Handler.php +++ b/src/Plan/Speak/Handler.php @@ -56,7 +56,7 @@ public function execute(Channel $channel, AbstractElement $element): PromiseInte if (!$response->isSuccessful()) { $this->app->planConsumer->logger->error('Speak Failed - ' . ($response->getBody() ?? '')); - return resolve(); + return resolve(null); } $element->iteration = 0; @@ -70,7 +70,7 @@ protected function waitForEvent(Element $element): PromiseInterface if ($element->iteration >= $element->loop) { $this->app->planConsumer->logger->info('Speak Finished'); - return resolve(); + return resolve(null); } $this->app->planConsumer->logger->debug('Speaking ' . ($element->iteration + 1) . ' times ...'); @@ -80,7 +80,7 @@ protected function waitForEvent(Element $element): PromiseInterface if (!isset($event)) { $this->app->planConsumer->logger->warning('Speak Break (empty event)'); - return resolve(); + return resolve(null); } $this->app->planConsumer->logger->debug('Speak ' . ++$element->iteration . ' times done (' . $event->{'Application-Response'} . ')'); diff --git a/src/Switch/ESL/Client.php b/src/Switch/ESL/Client.php index ef5453d..03ea459 100644 --- a/src/Switch/ESL/Client.php +++ b/src/Switch/ESL/Client.php @@ -177,7 +177,7 @@ protected function connect(Config\Core $config): void ->then(function () use ($config) { $this->logger->info("Connected to FreeSWITCH @ {$config->eslHost}:{$config->eslPort}"); }) - ->otherwise(function (Throwable $t) use ($config) { + ->catch(function (Throwable $t) use ($config) { $t = $t->getPrevious() ?: $t; $this->logger->error("Cannot connect to FreeSWITCH @ {$config->eslHost}:{$config->eslPort}: " . $t->getMessage()); $this->reconnect($config); diff --git a/src/Switch/ESL/Event/Custom.php b/src/Switch/ESL/Event/Custom.php index 52fd255..99abfae 100644 --- a/src/Switch/ESL/Event/Custom.php +++ b/src/Switch/ESL/Event/Custom.php @@ -169,7 +169,7 @@ public function execute(Core $core, Event $event): void $signal->attn = $event->{"variable_{$this->app->config->appPrefix}_amd_attn"}; $this->app->signalProducer->produce($signal) - ->otherwise(function (\Throwable $t) { + ->catch(function (\Throwable $t) { $t = $t->getPrevious() ?: $t; $this->app->eslClient->logger->error('Asynchronous AMD failure: ' . $t->getMessage(), [