NexmoBroadcastInboundCallCommand.php
2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace NexmoBundle\Command;
use AppBundle\Entity\AdminUser;
use AppBundle\Entity\OpentokSessionTypes;
use AppBundle\Entity\Patient;
use AppBundle\Entity\VoiceCall;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Monolog\Logger;
use NexmoBundle\Manager\InboundCallManager;
use OpenTokBundle\Pool\GlobalAdminOpenTokPool;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class NexmoBroadcastInboundCallCommand extends ContainerAwareCommand
{
/**
* @var Logger
*/
private $logger;
protected function configure()
{
$this
->setName('nexmo:broadcast-inbound-call')
->setDescription('Broadcast inbound voice call')
->addArgument('voice_call', InputArgument::REQUIRED, 'Voice call id')
->addOption("cobrand", "c", InputOption::VALUE_OPTIONAL, 'Cobrand code of executing context')
;
}
private function logString($s)
{
return "[{$this->getName()}]: {$s}";
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int|void|null
* @throws \Exception
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->logger = $this->getContainer()->get("logger");
/** @var InboundCallManager $manager */
$manager = $this->getContainer()->get("nexmo.manager.inbound_call");
/** @var VoiceCall $voiceCall */
$voiceCall = $manager->getObjectOrHalt($input->getArgument('voice_call'));
$manager->initThreadContent($voiceCall);
$opentokData = $manager->asOpenTokSignalData($voiceCall);
if ($voiceCall->getRecipient() instanceof AdminUser) {
/** @var GlobalAdminOpenTokPool $pool */
$pool = $this->getContainer()->get("opentok_pool_factory")->get(OpentokSessionTypes::ADMIN_POOL);
// send opentok signal to admin user
$pool->sendSignal("inbound-call", $opentokData);
}
$this->logger->info($this->logString("Broadcasting voice call #{$voiceCall->getId()}"));
}
}