Completed
Push — master ( 737d26...4f4b54 )
by Jignesh
09:33
created

initMeeting::initHooksDestroy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace JoisarJignesh\Bigbluebutton\Services;
5
6
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 Illuminate\Support\Str;
19
20
trait initMeeting
21
{
22
23
    /*
24
     * required fields
25
     * meetingID
26
     * meetingName
27
     *
28
     */
29
    public function initCreateMeeting(array $parameters)
30
    {
31
        $request = Fluent($parameters);
32
        $meetingParams = new CreateMeetingParameters($request->meetingID, $request->meetingName);
33
        $meetingParams->setModeratorPassword($request->get('moderatorPW', Str::random(config('bigbluebutton.create.passwordLength', 8))));
34
        $meetingParams->setAttendeePassword($request->get('attendeePW', Str::random(config('bigbluebutton.create.passwordLength', 8))));
35
        $meetingParams->setDuration($request->get('duration', config('bigbluebutton.create.duration', 0)));
36
        $meetingParams->setRecord($request->get('record', config('bigbluebutton.create.record', false)));
37
        $meetingParams->setMaxParticipants($request->get('maxParticipants', config('bigbluebutton.create.maxParticipants', 0)));
38
        $meetingParams->setLogoutUrl($request->get('logoutUrl', config('bigbluebutton.create.logoutUrl', null)));
39
        $meetingParams->setWelcomeMessage(
40
            $request->get('welcomeMessage', config('bigbluebutton.create.welcomeMessage', null))
41
        );
42
        $meetingParams->setDialNumber(
43
            $request->get('dialNumber', config('bigbluebutton.create.dialNumber', null))
44
        );
45
        $meetingParams->setBreakout(
46
            $request->get('isBreakout', config('bigbluebutton.create.isBreakout', false))
47
        );
48
        $meetingParams->setModeratorOnlyMessage(
49
            $request->get('moderatorOnlyMessage', config('bigbluebutton.create.moderatorOnlyMessage', null))
50
        );
51
        $meetingParams->setAutoStartRecording(
52
            $request->get('autoStartRecording', config('bigbluebutton.create.autoStartRecording', false))
53
        );
54
        $meetingParams->setAllowStartStopRecording(
55
            $request->get('allowStartStopRecording', config('bigbluebutton.create.allowStartStopRecording', true))
56
        );
57
        $meetingParams->setWebcamsOnlyForModerator(
58
            $request->get('webcamsOnlyForModerator', config('bigbluebutton.create.webcamsOnlyForModerator', false))
59
        );
60
        $meetingParams->setLogo(
61
            $request->get('logo', config('bigbluebutton.create.logo', null))
62
        );
63
        $meetingParams->setCopyright(
64
            $request->get('copyright', config('bigbluebutton.create.copyright', null))
65
        );
66
        $meetingParams->setMuteOnStart(
67
            $request->get('muteOnStart', config('bigbluebutton.create.muteOnStart', false))
68
        );
69
70
        $meetingParams->setLockSettingsDisableCam(
71
            $request->get('lockSettingsDisableCam', config('bigbluebutton.create.lockSettingsDisableCam', false))
72
        );
73
        $meetingParams->setLockSettingsDisableMic(
74
            $request->get('lockSettingsDisableMic', config('bigbluebutton.create.lockSettingsDisableMic', false))
75
        );
76
        $meetingParams->setLockSettingsDisablePrivateChat(
77
            $request->get('lockSettingsDisablePrivateChat', config('bigbluebutton.create.lockSettingsDisablePrivateChat', false))
78
        );
79
        $meetingParams->setLockSettingsDisablePublicChat(
80
            $request->get('lockSettingsDisablePublicChat', config('bigbluebutton.create.lockSettingsDisablePublicChat', false))
81
        );
82
        $meetingParams->setLockSettingsDisableNote(
83
            $request->get('lockSettingsDisableNote', config('bigbluebutton.create.lockSettingsDisableNote', false))
84
        );
85
        $meetingParams->setLockSettingsLockedLayout(
86
            $request->get('lockSettingsLockedLayout', config('bigbluebutton.create.lockSettingsLockedLayout', false))
87
        );
88
        $meetingParams->setLockSettingsLockOnJoin(
89
            $request->get('lockSettingsLockOnJoin', config('bigbluebutton.create.lockSettingsLockOnJoin', false))
90
        );
91
        $meetingParams->setLockSettingsLockOnJoinConfigurable(
92
            $request->get('lockSettingsLockOnJoinConfigurable', config('bigbluebutton.create.lockSettingsLockOnJoinConfigurable', false))
93
        );
94
95
        if (!is_null($request->get('endCallbackUrl', null))) {
96
            $meetingParams->setEndCallbackUrl($request->get('endCallbackUrl', null));
97
        }
98
99
        if (!is_null($request->get('bbb-recording-ready-url', null))) {
100
            $meetingParams->setRecordingReadyCallbackUrl($request->get('bbb-recording-ready-url', null));
101
        }
102
103
        $meetingParams->setFreeJoin($request->get('freeJoin', false));
104
105
        $presentation = (array)$request->get('presentation', null);
106
        foreach ($presentation as $item) {
107
            if (isset($item['fileName']) && !empty($item['fileName'])) {
108
                if (isset($item['link']) && !empty($item['link'])) {
109
                    $meetingParams->addPresentation(trim($item['link']), null, trim($item['fileName']));
110
                } elseif (isset($item['content']) && !empty($item['content'])) {
111
                    $meetingParams->addPresentation(trim($item['fileName']), trim($item['content']), null);
112
                }
113
            }
114
        }
115
116
        $meta = (array)$request->get('meta', null);
117
        foreach ($meta as $key => $value) {
118
            $meetingParams->addMeta(trim($key), trim($value));
119
        }
120
121
        return $meetingParams;
122
    }
123
124
    /*
125
     * required fields:
126
     * meetingID
127
     * moderatorPW close meeting must be there moderator password
128
     */
129
    public function initCloseMeeting(array $parameters)
130
    {
131
        $request = Fluent($parameters);
132
133
        return (new EndMeetingParameters($request->meetingID, $request->moderatorPW));
134
    }
135
136
    /*
137
     *  required fields
138
     *
139
     *  meetingID
140
     *  userName join by name
141
     *  password which role want to join
142
     */
143
    public function initJoinMeeting(array $parameters)
144
    {
145
        $request = Fluent($parameters);
146
        $meetingParams = new JoinMeetingParameters($request->meetingID, $request->userName, $request->password);
147
        $meetingParams->setRedirect($request->get('redirect', config('bigbluebutton.join.redirect', true)));
148
        $meetingParams->setJoinViaHtml5($request->get('joinViaHtml5', config('bigbluebutton.join.joinViaHtml5', true)));
149
        $meetingParams->setUserId($request->get('userId', null));
150
        if ($request->createTime) {
151
            $meetingParams->setCreationTime($request->createTime);
152
        }
153
        if ($request->configToken) {
154
            $meetingParams->setConfigToken($request->configToken);
155
        }
156
        if ($request->webVoiceConf) {
157
            $meetingParams->setWebVoiceConf($request->webVoiceConf);
158
        }
159
        if ($request->avatarUrl) {
160
            $meetingParams->setAvatarURL($request->avatarUrl);
161
        }
162
        if ($request->clientUrl) {
163
            $meetingParams->setClientURL($request->clientUrl);
164
        }
165
166
        return $meetingParams;
167
    }
168
169
    /*
170
     * required fields
171
     * meetingID
172
     */
173
    public function initIsMeetingRunning(array $parameters)
174
    {
175
        $meetingID = "";
0 ignored issues
show
Unused Code introduced by
$meetingID is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
176
        if (!is_array($parameters)) {
177
            $meetingID = $parameters;
178
        } else {
179
            $meetingID = Fluent($parameters)->get('meetingID');
180
        }
181
182
        return (new IsMeetingRunningParameters($meetingID));
183
    }
184
185
    /*
186
     * required fields
187
     * meetingID
188
     * moderatorPW must be there moderator password
189
     */
190
    public function initGetMeetingInfo($parameters)
191
    {
192
        $request = Fluent($parameters);
193
194
        return (new GetMeetingInfoParameters($request->meetingID, $request->moderatorPW));
195
    }
196
197
    /*
198
     *
199
     * optional fields
200
     * meetingID
201
     * recordID
202
     * state
203
     */
204
    public function initGetRecordings(array $parameters)
205
    {
206
        $request = Fluent($parameters);
207
        $recordings = new GetRecordingsParameters();
208
209
        $recordings->setMeetingId(implode(',', (array)$request->get('meetingID')));
210
        $recordings->setRecordId(implode(',', (array)$request->get('recordID')));
211
        $recordings->setState($request->get('state', config('bigbluebutton.getRecordings.state')));
212
213
        return $recordings;
214
    }
215
216
    /**
217
     * @param array $parameters
218
     *
219
     * @return PublishRecordingsParameters
220
     */
221
    public function initPublishRecordings(array $parameters)
222
    {
223
        $request = Fluent($parameters);
224
        $recordings = new PublishRecordingsParameters(null, $request->get('publish', true));
225
        $recordings->setRecordingId(implode(',', (array)$request->get('recordID')));
226
227
        return $recordings;
228
    }
229
230
    /*
231
     * required fields
232
     * recordingID
233
     */
234
    public function initDeleteRecordings($recording)
235
    {
236
        $request = Fluent($recording);
237
238
        return (new DeleteRecordingsParameters(implode(',', (array)$request->get('recordID'))));
239
    }
240
241
    private function makeJoinMeetingArray($object, $parameters)
242
    {
243
        $pass['meetingID'] = $object->get('meetingID');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$pass was never initialized. Although not strictly required by PHP, it is generally a good practice to add $pass = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
244
        $pass['password'] = $object->get('moderatorPW');
245
        if (isset($parameters['userName'])) {
246
            $pass['userName'] = $parameters['userName'];
247
        }
248
        $pass['meetingName'] = $object->get('meetingName');
249
        if (isset($parameters['redirect'])) {
250
            $pass['redirect'] = $parameters['redirect'];
251
        }
252
253
        return $pass;
254
    }
255
256
    /*
257
     * required fields
258
     * meetingID
259
     * meetingName
260
     * userName
261
     * attendeePW
262
     * moderatorPW
263
     * redirect
264
     */
265
    public function initStart(array $parameters)
266
    {
267
        if ($this->getMeetingInfo($parameters)->isEmpty()) {
0 ignored issues
show
Bug introduced by
The method getMeetingInfo() does not exist on JoisarJignesh\Bigbluebutton\Services\initMeeting. Did you maybe mean initGetMeetingInfo()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
268
            $object = $this->create($parameters);
0 ignored issues
show
Bug introduced by
The method create() does not exist on JoisarJignesh\Bigbluebutton\Services\initMeeting. Did you maybe mean initCreateMeeting()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
269
            if (method_exists($object, 'isEmpty') && !$object->isEmpty()) {
270
                return $this->join($this->makeJoinMeetingArray($object, $parameters));
0 ignored issues
show
Bug introduced by
It seems like join() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
271
            }
272
        } else {
273
            if (isset($parameters['moderatorPW'])) {
274
                $parameters['password'] = trim($parameters['moderatorPW']);
275
            }
276
277
            return $this->join($parameters);
0 ignored issues
show
Bug introduced by
It seems like join() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
278
        }
279
    }
280
281
    /**
282
     * @param $parameters
283
     *
284
     * @return SetConfigXMLParameters
285
     */
286
    public function initSetConfigXml(array $parameters)
287
    {
288
        $parameters = Fluent($parameters);
289
        $configXml = new SetConfigXMLParameters($parameters->get('meetingID'));
290
        $rawXml = $parameters->xml;
291
        if (!$parameters->xml instanceof \SimpleXMLElement) {
292
            $rawXml = new \SimpleXMLElement($parameters->xml);
293
        }
294
295
        $configXml->setRawXml($rawXml);
296
297
        return $configXml;
298
    }
299
300
    /**
301
     * @param array $parameters
302
     *
303
     * @return HooksCreateParameters
304
     */
305
    public function initHooksCreate(array $parameters)
306
    {
307
        $parameters = Fluent($parameters);
308
        $hooksCreate = new HooksCreateParameters($parameters->get('callbackURL'));
309
        if ($parameters->meetingID) {
310
            $hooksCreate->setMeetingId($parameters->meetingID);
311
        }
312
        $hooksCreate->setGetRaw($parameters->get('getRaw', false));
313
314
        return $hooksCreate;
315
    }
316
317
    /**
318
     * @param array $parameters
319
     *
320
     * @return HooksDestroyParameters
321
     */
322
    public function initHooksDestroy(array $parameters)
323
    {
324
        $parameters = Fluent($parameters);
325
        $hooksDestroy = new HooksDestroyParameters($parameters->get('hooksID'));
326
327
        return $hooksDestroy;
328
    }
329
330
    /**
331
     * Check if connection to api can be established with the end point url and secret
332
     * @return array connection successful
333
     */
334
    private function initIsConnect()
335
    {
336
        if (!filter_var(config('bigbluebutton.BBB_SERVER_BASE_URL'), FILTER_VALIDATE_URL)) {
337
            return [
338
                'flag'    => false,
339
                'message' => 'invalid url'
340
            ];
341
        }
342
343
        try {
344
            $response = $this->bbb->isMeetingRunning(
0 ignored issues
show
Bug introduced by
The property bbb does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
345
                new IsMeetingRunningParameters('connection_check')
346
            );
347
348
            // url and secret working
349
            if ($response->success()) {
350
                return ['flag' => true];
351
            }
352
353
            // Checksum error - invalid secret
354
            if ($response->failed() && $response->getMessageKey() == "checksumError") {
355
                return [
356
                    'flag'    => false,
357
                    'message' => 'invalid secret key'
358
                ];
359
            }
360
361
            // HTTP exception or XML parse
362
        } catch (\Exception $e) {
363
            return [
364
                'flag'    => false,
365
                'message' => 'invalid url and secret key'
366
            ];
367
        }
368
369
        return [
370
            'flag'    => false,
371
            'message' => 'invalid url'
372
        ];
373
    }
374
}
375