ThreadContentVoiceCallEventSubscriber.php
1.86 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\Event\Subscriber;
use AppBundle\Entity\ThreadContent;
use AppBundle\Entity\ThreadContentTypes;
use AppBundle\Entity\VoiceCall;
use AppBundle\Event\VoiceCallEvent;
use AppBundle\Event\VoiceCallEvents;
use AppBundle\Service\OpentokSignalingService;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Class ThreadContentVoiceCallEventSubscriber
*
*/
class ThreadContentVoiceCallEventSubscriber implements EventSubscriberInterface
{
/**
* @var Registry
*/
protected $doctrine;
/**
* @var OpentokSignalingService
*/
protected $opentokSignaling;
public function setDoctrine(Registry $v)
{
$this->doctrine = $v;
}
public function setOpentokSignaling(OpentokSignalingService $v)
{
$this->opentokSignaling = $v;
}
public function onStatusChange(VoiceCallEvent $event)
{
if (!$event->getVoiceCall() instanceof VoiceCall) {
return;
}
/** @var ThreadContent $threadContent */
$threadContent = $this->doctrine->getRepository("AppBundle:ThreadContent")
->findOneBy(["contentId" => $event->getVoiceCall()->getId(), "type" => ThreadContentTypes::VOICE_CALL_LOG]);
if (!$threadContent instanceof ThreadContent) {
return;
}
$this->opentokSignaling->sendSignal($threadContent->getThread(), "voice_call_update_content", ["thread_content" => $threadContent->getId()]);
}
public static function getSubscribedEvents()
{
return [
VoiceCallEvents::STARTED_VOICE_CALL => 'onStatusChange',
VoiceCallEvents::ANSWERED_VOICE_CALL => 'onStatusChange',
VoiceCallEvents::COMPLETED_VOICE_CALL => 'onStatusChange',
VoiceCallEvents::FAILED_VOICE_CALL => 'onStatusChange'
];
}
}