Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
BitrixCall.php
1<?php
2
4
9
10class BitrixCall extends Call
11{
12 protected function initCall()
13 {
14 if (!$this->endpoint)
15 {
16 $this->uuid = Util::generateUUID();
17 $this->secretKey = Random::getString(10, true);
18
19 $callControllerClient = new ControllerClient();
20 $createResult = $callControllerClient->createCall(
21 $this->getUuid(),
22 $this->getSecretKey(),
23 $this->getInitiatorId()
24 );
25
26 if (!$createResult->isSuccess())
27 {
28 $this->finish();
29
30 throw new \Exception($createResult->getErrorMessages()[0]);
31 }
32 $callData = $createResult->getData();
33 if (!$callData['endpoint'])
34 {
35 $this->finish();
36
37 throw new \Exception('Empty endpoint');
38 }
39
40 $this->setEndpoint($callData['endpoint']);
41 $this->save();
42 }
43 }
44
45 protected function generateJwt(int $userId): string
46 {
47 return JWT::encode(
48 [
49 'uuid' => $this->getUuid(),
50 'userId' => (string)$userId,
51 ],
52 $this->getSecretKey()
53 );
54 }
55
56 public function getConnectionData(int $userId): array
57 {
58 return [
59 'endpoint' => $this->endpoint ?: null,
60 'jwt' => $this->generateJwt($userId),
61 ];
62 }
63
64 public function inviteUsers(int $senderId, array $toUserIds, $isLegacyMobile, $video = false, $sendPush = true)
65 {
66 foreach ($toUserIds as $toUserId)
67 {
68 $this->getSignaling()->sendInviteToUser(
69 $senderId,
70 $toUserId,
71 $toUserIds,
72 $isLegacyMobile,
73 $video,
74 $sendPush
75 );
76 }
77 }
78
79 public function getMaxUsers()
80 {
81 return static::getMaxCallServerParticipants();
82 }
83}
setEndpoint($endpoint)
Definition call.php:345
inviteUsers(int $senderId, array $toUserIds, $isLegacyMobile, $video=false, $sendPush=true)
static encode($payload, $key, $alg='HS256', $keyId=null, $head=null)
Definition jwt.php:161