Completed
Push — master ( c638ef...737d26 )
by Jignesh
01:16
created

Bbb::isConnect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
4
namespace JoisarJignesh\Bigbluebutton;
5
6
use BigBlueButton\BigBlueButton;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, JoisarJignesh\Bigbluebutton\BigBlueButton.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
7
use BigBlueButton\Parameters\CreateMeetingParameters;
8
use BigBlueButton\Parameters\DeleteRecordingsParameters;
9
use BigBlueButton\Parameters\EndMeetingParameters;
10
use BigBlueButton\Parameters\GetMeetingInfoParameters;
11
use BigBlueButton\Parameters\GetRecordingsParameters;
12
use BigBlueButton\Parameters\HooksCreateParameters;
13
use BigBlueButton\Parameters\HooksDestroyParameters;
14
use BigBlueButton\Parameters\IsMeetingRunningParameters;
15
use BigBlueButton\Parameters\JoinMeetingParameters;
16
use BigBlueButton\Parameters\PublishRecordingsParameters;
17
use BigBlueButton\Parameters\SetConfigXMLParameters;
18
use JoisarJignesh\Bigbluebutton\Services\initMeeting;
19
20
class Bbb
21
{
22
    use initMeeting;
23
24
    /**
25
     * @var
26
     */
27
    private $response;
28
    /**
29
     * @var BigBlueButton
30
     */
31
    protected $bbb;
32
33
34
    /**
35
     * Bbb constructor.
36
     *
37
     * @param BigBlueButton $bbb
38
     */
39
    public function __construct(BigBlueButton $bbb)
40
    {
41
        $this->bbb = $bbb;
42
    }
43
44
    /**
45
     * @return BigBlueButton
46
     */
47
    public function make()
48
    {
49
        return $this->bbb;
50
    }
51
52
    /**
53
     * check url and secret is working
54
     * @return bool
55
     */
56
    public function isConnect()
57
    {
58
        $response = $this->initIsConnect();
59
        if($response['flag'] === true){
60
            return true;
61
        }
62
63
        return false;
64
    }
65
66
    /**
67
     *  Return a list of all meetings
68
     *
69
     * @return \Illuminate\Support\Collection
70
     */
71
    public function all()
72
    {
73
        $this->response = $this->bbb->getMeetings();
74 View Code Duplication
        if ($this->response->success()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
            if (count($this->response->getRawXml()->meetings->meeting) > 0) {
76
                $meetings = [];
77
                foreach ($this->response->getRawXml()->meetings->meeting as $meeting) {
78
                    $meetings[] = XmlToArray($meeting);
79
                }
80
81
                return collect(XmlToArray($meetings));
82
            }
83
        }
84
85
        return collect([]);
86
    }
87
88
89
    /**
90
     * $meeting
91
     *
92
     * @param $meeting
93
     *
94
     * required fields
95
     * meetingID
96
     * meetingName
97
     *
98
     * @return mixed
99
     */
100 View Code Duplication
    public function create($meeting)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
101
    {
102
        if (!$meeting instanceof CreateMeetingParameters) {
103
            $meeting = $this->initCreateMeeting($meeting);
104
        }
105
106
        $this->response = $this->bbb->createMeeting($meeting);
107
        if ($this->response->failed()) {
108
            return $this->response->getMessage();
109
        } else {
110
            return collect(XmlToArray($this->response->getRawXml()));
111
        }
112
    }
113
114
    /**
115
     * @param $meeting
116
     *
117
     * required fields:
118
     * meetingID
119
     *
120
     * @return bool
121
     */
122 View Code Duplication
    public function isMeetingRunning($meeting)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
123
    {
124
        if (!$meeting instanceof IsMeetingRunningParameters) {
125
            $meeting = $this->initIsMeetingRunning($meeting);
126
        }
127
128
        $this->response = $this->bbb->isMeetingRunning($meeting);
129
        if ($this->response->success()) {
130
            $response = XmlToArray($this->response->getRawXml());
131
            if (isset($response['running']) && $response['running'] == "true") {
132
                return true;
133
            }
134
        }
135
136
        return false;
137
    }
138
139
    /**
140
     *  Join meeting
141
     *
142
     * @param $meeting
143
     * required fields
144
     *
145
     *  meetingID
146
     *  userName join by name
147
     *  password which role want to join
148
     *
149
     * @return string
150
     */
151
    public function join($meeting)
152
    {
153
        if (!$meeting instanceof JoinMeetingParameters) {
154
            $meeting = $this->initJoinMeeting($meeting);
155
        }
156
157
        if ($meeting->isRedirect()) {
158
            return $this->bbb->getJoinMeetingURL($meeting);
159
        }
160
161
        return $this->bbb->joinMeeting($meeting)->getUrl();
162
    }
163
164
    /**
165
     *  Returns information about the meeting
166
     *
167
     * @param $meeting
168
     * required fields
169
     * meetingID
170
     * moderatorPW must be there moderator password
171
     *
172
     * @return \Illuminate\Support\Collection
173
     */
174 View Code Duplication
    public function getMeetingInfo($meeting)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
175
    {
176
        if (!$meeting instanceof GetMeetingInfoParameters) {
177
            $meeting = $this->initGetMeetingInfo($meeting);
178
        }
179
180
        $this->response = $this->bbb->getMeetingInfo($meeting);
181
        if ($this->response->success()) {
182
            return collect(XmlToArray($this->response->getRawXml()));
183
        }
184
185
        return collect([]);
186
    }
187
188
    /**
189
     * @param $parameters
190
     *
191
     *  required fields
192
     * meetingID
193
     * meetingName
194
     * userName
195
     * attendeePW
196
     * moderatorPW
197
     *
198
     * @return mixed
199
     */
200
    public function start($parameters)
201
    {
202
        return $this->initStart($parameters);
203
    }
204
205
    /**
206
     *  Close meeting
207
     *
208
     * @param  $meeting
209
     * required fields:
210
     * meetingID
211
     * moderatorPW close meeting must be there moderator password
212
     *
213
     * @return bool
214
     */
215
    public function close($meeting)
216
    {
217
        if (!$meeting instanceof EndMeetingParameters) {
218
            $meeting = $this->initCloseMeeting($meeting);
219
        }
220
221
        $this->response = $this->bbb->endMeeting($meeting);
222
        if ($this->response->success()) {
223
            return true;
224
        }
225
226
        return false;
227
    }
228
229
    /**
230
     *
231
     * @param $recording
232
     * required fields
233
     * meetingID
234
     *
235
     * optional fields
236
     * recordID
237
     * state
238
     *
239
     * @return \Illuminate\Support\Collection
240
     */
241
    public function getRecordings($recording)
242
    {
243
        if (!$recording instanceof GetRecordingsParameters) {
244
            $recording = $this->initGetRecordings($recording);
245
        }
246
247
        $this->response = $this->bbb->getRecordings($recording);
248 View Code Duplication
        if (count($this->response->getRawXml()->recordings->recording) > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
249
            $recordings = [];
250
            foreach ($this->response->getRawXml()->recordings->recording as $r) {
251
                $recordings[] = XmlToArray($r);
252
            }
253
254
            return collect($recordings);
255
        }
256
257
        return collect([]);
258
    }
259
260
    /**
261
     * @param $recording
262
     * recordID as string(sepeate by commma)
263
     * publish as bool
264
     *
265
     * @return bool
266
     */
267 View Code Duplication
    public function publishRecordings($recording)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
268
    {
269
        if (!$recording instanceof PublishRecordingsParameters) {
270
            $recording = $this->initPublishRecordings($recording);
271
        }
272
273
        $this->response = $this->bbb->publishRecordings($recording);
274
        if ($this->response->success()) {
275
            $response = XmlToArray($this->response->getRawXml());
276
            if (isset($response['published']) && $response['published'] == "true") {
277
                return true;
278
            }
279
        }
280
281
        return false;
282
    }
283
284
    /**
285
     * @param $recording
286
     *
287
     * required fields
288
     * recordingID
289
     *
290
     * @return \Illuminate\Support\Collection
291
     */
292
    public function deleteRecordings($recording)
293
    {
294
        if (!$recording instanceof DeleteRecordingsParameters) {
295
            $recording = $this->initDeleteRecordings($recording);
296
        }
297
298
        $this->response = $this->bbb->deleteRecordings($recording);
299
300
        return collect(XmlToArray($this->response->getRawXml()));
301
    }
302
303
    /**
304
     * @param $configXml
305
     *
306
     * @return \Illuminate\Support\Collection
307
     */
308
    public function setConfigXml($configXml)
309
    {
310
        if (!$configXml instanceof SetConfigXMLParameters) {
311
            $configXml = $this->initSetConfigXml($configXml);
312
        }
313
314
        $this->response = $this->bbb->setConfigXML($configXml);
315
316
        return collect(XmlToArray($this->response->getRawXml()));
317
    }
318
319
    /**
320
     * @return \BigBlueButton\Responses\GetDefaultConfigXMLResponse
321
     */
322
    public function getDefaultConfigXml()
323
    {
324
        $this->response = $this->bbb->getDefaultConfigXML();
325
326
        return $this->response;
327
    }
328
329
    /**
330
     * @return \Illuminate\Support\Collection
331
     */
332
    public function getApiVersion()
333
    {
334
        $this->response = $this->bbb->getApiVersion();
335
336
        return collect(XmlToArray($this->response->getRawXml()));
337
    }
338
339
    /**
340
     * @param $hooks
341
     *
342
     * @return \Illuminate\Support\Collection
343
     */
344
    public function hooksCreate($hooks)
345
    {
346
        if (!$hooks instanceof HooksCreateParameters) {
347
            $hooks = $this->initHooksCreate($hooks);
348
        }
349
350
        $this->response = $this->bbb->hooksCreate($hooks);
351
352
        return collect(XmlToArray($this->response->getRawXml()));
353
    }
354
355
    /**
356
     * @param $hooks
357
     *
358
     * @return  \Illuminate\Support\Collection
359
     */
360
    public function hooksDestroy($hooks)
361
    {
362
        if (!$hooks instanceof HooksDestroyParameters) {
363
            $hooks = $this->initHooksDestroy($hooks);
364
        }
365
366
        $this->response = $this->bbb->hooksDestroy($hooks);
367
368
        return collect(XmlToArray($this->response->getRawXml()));
369
    }
370
371
}
372