Meeting::getViewers()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 4
c 2
b 0
f 0
dl 0
loc 9
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
5
 *
6
 * Copyright (c) 2016-2024 BigBlueButton Inc. and by respective authors (see below).
7
 *
8
 * This program is free software; you can redistribute it and/or modify it under the
9
 * terms of the GNU Lesser General Public License as published by the Free Software
10
 * Foundation; either version 3.0 of the License, or (at your option) any later
11
 * version.
12
 *
13
 * BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
14
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public License along
18
 * with BigBlueButton; if not, see <https://www.gnu.org/licenses/>.
19
 */
20
21
namespace BigBlueButton\Core;
22
23
use BigBlueButton\Enum\Role;
24
25
/**
26
 * Class Meeting.
27
 */
28
class Meeting
29
{
30
    protected \SimpleXMLElement $rawXml;
31
32
    private string $meetingId;
33
34
    private string $meetingName;
35
36
    private float $creationTime;
37
38
    private string $creationDate;
39
40
    private int $voiceBridge;
41
42
    private string $dialNumber;
43
44
    private string $attendeePassword;
45
46
    private string $moderatorPassword;
47
48
    private bool $hasBeenForciblyEnded;
49
50
    private bool $isRunning;
51
52
    private int $participantCount;
53
54
    private int $listenerCount;
55
56
    private int $voiceParticipantCount;
57
58
    private int $videoCount;
59
60
    private int $duration;
61
62
    private bool $hasUserJoined;
63
64
    private string $internalMeetingId;
65
66
    private bool $isRecording;
67
68
    private float $startTime;
69
70
    private float $endTime;
71
72
    private int $maxUsers;
73
74
    private int $moderatorCount;
75
76
    private bool $isBreakout;
77
78
    /**
79
     * Meeting constructor.
80
     */
81
    public function __construct(\SimpleXMLElement $xml)
82
    {
83
        $this->rawXml                = $xml;
84
        $this->meetingId             = $xml->meetingID->__toString();
85
        $this->meetingName           = $xml->meetingName->__toString();
86
        $this->creationTime          = (float) $xml->createTime;
87
        $this->creationDate          = $xml->createDate->__toString();
88
        $this->voiceBridge           = (int) $xml->voiceBridge;
89
        $this->dialNumber            = $xml->dialNumber->__toString();
90
        $this->attendeePassword      = $xml->attendeePW->__toString();
91
        $this->moderatorPassword     = $xml->moderatorPW->__toString();
92
        $this->hasBeenForciblyEnded  = 'true' === $xml->hasBeenForciblyEnded->__toString();
93
        $this->isRunning             = 'true' === $xml->running->__toString();
94
        $this->participantCount      = (int) $xml->participantCount;
95
        $this->listenerCount         = (int) $xml->listenerCount;
96
        $this->voiceParticipantCount = (int) $xml->voiceParticipantCount;
97
        $this->videoCount            = (int) $xml->videoCount;
98
        $this->duration              = (int) $xml->duration;
99
        $this->hasUserJoined         = 'true' === $xml->hasUserJoined->__toString();
100
        $this->internalMeetingId     = $xml->internalMeetingID->__toString();
101
        $this->isRecording           = 'true' === $xml->recording->__toString();
102
        $this->startTime             = (float) $xml->startTime;
103
        $this->endTime               = (float) $xml->endTime;
104
        $this->maxUsers              = (int) $xml->maxUsers->__toString();
105
        $this->moderatorCount        = (int) $xml->moderatorCount->__toString();
106
        $this->isBreakout            = 'true' === $xml->isBreakout->__toString();
107
    }
108
109
    public function getMeetingId(): string
110
    {
111
        return $this->meetingId;
112
    }
113
114
    public function getMeetingName(): string
115
    {
116
        return $this->meetingName;
117
    }
118
119
    public function getCreationTime(): float
120
    {
121
        return $this->creationTime;
122
    }
123
124
    public function getCreationDate(): string
125
    {
126
        return $this->creationDate;
127
    }
128
129
    public function getVoiceBridge(): int
130
    {
131
        return $this->voiceBridge;
132
    }
133
134
    public function getDialNumber(): string
135
    {
136
        return $this->dialNumber;
137
    }
138
139
    public function getAttendeePassword(): string
140
    {
141
        return $this->attendeePassword;
142
    }
143
144
    public function getModeratorPassword(): string
145
    {
146
        return $this->moderatorPassword;
147
    }
148
149
    public function hasBeenForciblyEnded(): ?bool
150
    {
151
        return $this->hasBeenForciblyEnded;
152
    }
153
154
    public function isRunning(): ?bool
155
    {
156
        return $this->isRunning;
157
    }
158
159
    public function getParticipantCount(): int
160
    {
161
        return $this->participantCount;
162
    }
163
164
    public function getListenerCount(): int
165
    {
166
        return $this->listenerCount;
167
    }
168
169
    public function getVoiceParticipantCount(): int
170
    {
171
        return $this->voiceParticipantCount;
172
    }
173
174
    public function getVideoCount(): int
175
    {
176
        return $this->videoCount;
177
    }
178
179
    public function getDuration(): int
180
    {
181
        return $this->duration;
182
    }
183
184
    public function hasUserJoined(): ?bool
185
    {
186
        return $this->hasUserJoined;
187
    }
188
189
    public function getInternalMeetingId(): string
190
    {
191
        return $this->internalMeetingId;
192
    }
193
194
    public function isRecording(): ?bool
195
    {
196
        return $this->isRecording;
197
    }
198
199
    public function getStartTime(): float
200
    {
201
        return $this->startTime;
202
    }
203
204
    public function getEndTime(): float
205
    {
206
        return $this->endTime;
207
    }
208
209
    public function getMaxUsers(): int
210
    {
211
        return $this->maxUsers;
212
    }
213
214
    public function getModeratorCount(): int
215
    {
216
        return $this->moderatorCount;
217
    }
218
219
    /**
220
     * Attendees of Meeting (MODERATORS and VIEWERS).
221
     *
222
     * @return Attendee[]
223
     */
224
    public function getAttendees(): array
225
    {
226
        $attendees = [];
227
228
        foreach ($this->rawXml->attendees->attendee as $attendeeXml) {
229
            if ($attendeeXml) {
230
                $attendees[] = new Attendee($attendeeXml);
231
            }
232
        }
233
234
        return $attendees;
235
    }
236
237
    /**
238
     * Moderators of Meeting - Subset of Attendees.
239
     *
240
     * @return Attendee[]
241
     */
242
    public function getModerators(): array
243
    {
244
        $attendees = $this->getAttendees();
245
246
        $moderators = array_filter($attendees, function($attendee) {
247
            return Role::MODERATOR === $attendee->getRole();
248
        });
249
250
        return array_values($moderators);
251
    }
252
253
    /**
254
     * Viewers of Meeting - Subset of Attendees.
255
     *
256
     * @return Attendee[]
257
     */
258
    public function getViewers(): array
259
    {
260
        $attendees = $this->getAttendees();
261
262
        $viewers = array_filter($attendees, function($attendee) {
263
            return Role::VIEWER === $attendee->getRole();
264
        });
265
266
        return array_values($viewers);
267
    }
268
269
    /**
270
     * @return array<string, string>
271
     */
272
    public function getMetas(): array
273
    {
274
        $metas = [];
275
        foreach ($this->rawXml->metadata->children() as $metadataXml) {
276
            $metas[$metadataXml->getName()] = $metadataXml->__toString();
277
        }
278
279
        return $metas;
280
    }
281
282
    public function isBreakout(): bool
283
    {
284
        return $this->isBreakout;
285
    }
286
}
287