View source
<?php
namespace Drupal\bbb\Service;
use BigBlueButton\Parameters\CreateMeetingParameters;
use BigBlueButton\Parameters\EndMeetingParameters;
use BigBlueButton\Parameters\GetMeetingInfoParameters;
use BigBlueButton\Parameters\JoinMeetingParameters;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\PrivateKey;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class Meeting implements MeetingInterface {
use StringTranslationTrait;
protected $currentUser;
protected $entityTypeManager;
protected $moduleHandler;
protected $meetingCollection;
protected $log;
protected $api;
protected $privateKey;
protected static $meetings = [];
public function __construct(Api $api, PrivateKey $private_key, ModuleHandlerInterface $module_handler, KeyValueFactoryInterface $keyvalue, EntityTypeManagerInterface $entity_type_manager, AccountInterface $current_user, LoggerChannelFactoryInterface $logger_factory) {
$this->api = $api;
$this->privateKey = $private_key;
$this->currentUser = $current_user;
$this->entityTypeManager = $entity_type_manager;
$this->moduleHandler = $module_handler;
$this->meetingCollection = $keyvalue
->get('bbb_meetings');
$this->log = $logger_factory
->get('bbb');
}
public function get($id, AccountInterface $account = NULL, $cached = TRUE) {
if (empty($account)) {
$account = $this->currentUser;
}
if (!isset(self::$meetings[$id]) || !$cached) {
$meeting_created = $this->meetingCollection
->get($id);
if ($meeting_created) {
$meeting_info = $this->api
->getMeetingInfo(new GetMeetingInfoParameters($meeting_created
->getMeetingId(), $meeting_created
->getModeratorPassword()));
if ($meeting_info) {
$url = [
'attend' => $this->api
->joinMeeting(new JoinMeetingParameters($meeting_created
->getMeetingId(), $account
->getDisplayName(), $meeting_created
->getAttendeePassword())),
'moderate' => $this->api
->joinMeeting(new JoinMeetingParameters($meeting_created
->getMeetingId(), $account
->getDisplayName(), $meeting_created
->getModeratorPassword())),
];
$meeting = [
'info' => $meeting_info,
'created' => $meeting_created,
'url' => $url,
];
$this->moduleHandler
->alter('bbb_get_meeting', $meeting);
self::$meetings[$id] = $meeting;
}
}
}
return isset(self::$meetings[$id]) ? self::$meetings[$id] : [];
}
public function update($key, CreateMeetingParameters $params) {
$this->meetingCollection
->set($key, $params);
return $key;
}
public function create($key, CreateMeetingParameters $params) {
if ($data = $this->api
->createMeeting($params)) {
return $data;
}
return FALSE;
}
public function store($key, CreateMeetingParameters $params) {
return $this
->update($key, $params);
}
public function delete($key) {
if ($this->meetingCollection
->has($key)) {
$this->meetingCollection
->delete($key);
}
else {
$this->log
->warning($this
->t('Meeting @key not found during removal: It was removed before manually or never exists.', [
'@key' => $key,
]));
}
$meeting = $this
->get($key);
$params = new EndMeetingParameters($meeting->meetingID, $meeting->moderatorPW);
$request = $this->api
->endMeeting($params);
return $request;
}
}