Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
jitsilite.php
1<?php
2
3
5
6
16
17class JitsiLite extends Controller
18{
19 protected function processBeforeAction(Action $action): bool
20 {
21 if (!Loader::includeModule('im'))
22 {
23 $this->addError(new Error("Module IM is not installed"));
24
25 return false;
26 }
27
28 if (User::getInstance()->isExtranet())
29 {
30 $this->addError(new Error("You dont have access to this action"));
31
32 return false;
33 }
34
35 return true;
36 }
37
38 public function createConferenceAction(string $dialogId, CurrentUser $currentUser)
39 {
40 if (!\Bitrix\Im\Dialog::hasAccess($dialogId, $currentUser->getId()))
41 {
42 $this->addError(new Error("You must be a member of the chat to call it"));
43
44 return null;
45 }
46
47 $chatId = Dialog::getChatId($dialogId);
48
49 $aliasData = Alias::addUnique([
50 "ENTITY_TYPE" => Alias::ENTITY_TYPE_JITSICONF,
51 "ENTITY_ID" => $chatId
52 ]);
53
54 $message = Loc::getMessage("IM_JITSI_LITE_INVITE_TO_CONF");
55
56 $keyboard = new \Bitrix\Im\Bot\Keyboard();
57 $keyboard->addButton([
58 "TEXT" => Loc::getMessage("IM_JITSI_LITE_OPEN_CONF"),
59 "FUNCTION" => "if ('BXIM' in window) {BXIM.openVideoconf('{$aliasData['ALIAS']}')} else {ChatUtils.openVideoconf('{$aliasData['ALIAS']}')};",
60 "BG_COLOR" => "#29619b",
61 "TEXT_COLOR" => "#fff",
62 "DISPLAY" => "LINE",
63 ]);
64
65 \CIMChat::AddMessage([
66 "FROM_USER_ID" => $currentUser->getId(),
67 "TO_CHAT_ID" => $chatId,
68 "MESSAGE" => $message,
69 "SYSTEM" => 'Y',
70 "KEYBOARD" => $keyboard,
71 ]);
72
73 return [
74 'ALIAS_DATA' => $aliasData
75 ];
76 }
77}
static addUnique(array $fields)
Definition alias.php:55
const ENTITY_TYPE_JITSICONF
Definition alias.php:14
createConferenceAction(string $dialogId, CurrentUser $currentUser)
Definition jitsilite.php:38
processBeforeAction(Action $action)
Definition jitsilite.php:19
static getChatId($dialogId, $userId=null)
Definition dialog.php:91
static hasAccess($dialogId, $userId=null)
Definition dialog.php:143
static getInstance($userId=null)
Definition user.php:44
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29