Completed
Push — master ( 2cdd56...cec501 )
by Brian
08:59
created

Bridge::onBridgeMerged()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
/*
4
 * Copyright 2014 Brian Smith <[email protected]>.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *      http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace phparia\Resources;
20
21
use phparia\Client\AriClient;
22
use phparia\Events\Event;
23
use phparia\Exception\ConflictException;
24
use phparia\Exception\InvalidParameterException;
25
use phparia\Exception\NotFoundException;
26
use phparia\Exception\UnprocessableEntityException;
27
28
/**
29
 * The merging of media from one or more channels.
30
 * Everyone on the bridge receives the same audio.
31
 *
32
 * @author Brian Smith <[email protected]>
33
 */
34
class Bridge extends Resource
35
{
36
    const TYPE_MIXING = 'mixing';
37
    const TYPE_HOLDING = 'holding';
38
    const TYPE_DTMF_EVENTS = 'dtmf_events';
39
    const TYPE_PROXY_MEDIA = 'proxy_media';
40
    
41
    /**
42
     * @var string Bridging class
43
     */
44
    private $bridgeClass;
45
46
    /**
47
     * @var string Type of bridge technology (mixing, holding, dtmf_events, proxy_media)
48
     */
49
    private $bridgeType;
50
51
    /**
52
     * @var array Ids of channels participating in this bridge
53
     */
54
    private $channelIds;
55
56
    /**
57
     * @var string  Entity that created the bridge
58
     */
59
    private $creator;
60
61
    /**
62
     * @var string Unique identifier for this bridge
63
     */
64
    private $id;
65
66
    /**
67
     * @var string Unique identifier for this bridge
68
     */
69
    private $name;
70
71
    /**
72
     * @var string Name of the current bridging technology
73
     */
74
    private $technology;
75
76
    /**
77
     * @return string Bridging class
78
     */
79
    public function getBridgeClass()
80
    {
81
        return $this->bridgeClass;
82
    }
83
84
    /**
85
     * @return string Type of bridge technology (mixing, holding, dtmf_events, proxy_media)
86
     */
87
    public function getBridgeType()
88
    {
89
        return $this->bridgeType;
90
    }
91
92
    /**
93
     * @return array Ids of channels participating in this bridge
94
     */
95
    public function getChannelIds()
96 3
    {
97
        return $this->channelIds;
98 3
    }
99
100
    /**
101
     * @return string Entity that created the bridge
102
     */
103
    public function getCreator()
104
    {
105
        return $this->creator;
106
    }
107
108
    /**
109
     * @return string Unique identifier for this bridge
110
     */
111
    public function getId()
112 2
    {
113
        return $this->id;
114 2
    }
115
116
    /**
117
     * @return string Unique identifier for this bridge
118
     */
119
    public function getName()
120
    {
121
        return $this->name;
122
    }
123
124
    /**
125
     * @return string Name of the current bridging technology
126
     */
127
    public function getTechnology()
128
    {
129
        return $this->technology;
130
    }
131
132
    /**
133
     * @param callable $callback
134
     */
135
    public function onBridgeCreated(callable $callback)
136
    {
137
        $this->on(Event::BRIDGE_CREATED.'_'.$this->getId(), $callback);
138
    }
139
140
    /**
141
     * @param callable $callback
142
     */
143
    public function onceBridgeCreated(callable $callback)
144
    {
145
        $this->once(Event::BRIDGE_CREATED.'_'.$this->getId(), $callback);
146
    }
147
148
    /**
149
     * @param callable $callback
150
     */
151
    public function onBridgeDestroyed(callable $callback)
152
    {
153
        $this->on(Event::BRIDGE_DESTROYED.'_'.$this->getId(), $callback);
154
    }
155
156
    /**
157
     * @param callable $callback
158
     */
159
    public function onceBridgeDestroyed(callable $callback)
160
    {
161
        $this->once(Event::BRIDGE_DESTROYED.'_'.$this->getId(), $callback);
162
    }
163
164
    /**
165
     * @param callable $callback
166
     */
167
    public function onBridgeVideoSourceChanged(callable $callback)
168
    {
169
        $this->on(Event::BRIDGE_VIDEO_SOURCE_CHANGED.'_'.$this->getId(), $callback);
170
    }
171
172
    /**
173
     * @param callable $callback
174
     */
175
    public function onceBridgeVideoSourceChanged(callable $callback)
176
    {
177
        $this->once(Event::BRIDGE_VIDEO_SOURCE_CHANGED.'_'.$this->getId(), $callback);
178
    }
179
180
    /**
181
     * @param callable $callback
182
     */
183
    public function onPeerStatusChange(callable $callback)
184
    {
185
        $this->on(Event::PEER_STATUS_CHANGE.'_'/* @todo Something unique to the peer */, $callback);
186
    }
187
188
    /**
189
     * @param callable $callback
190
     */
191
    public function oncePeerStatusChange(callable $callback)
192
    {
193
        $this->once(Event::PEER_STATUS_CHANGE.'_'/* @todo Something unique to the peer */, $callback);
194
    }
195
196
    /**
197
     * Shut down a bridge. If any channels are in this bridge, they will be removed and resume whatever they were doing beforehand.
198
     *
199
     * @throws NotFoundException
200
     */
201
    public function deleteBridge()
202
    {
203
        $this->client->bridges()->deleteBridge($this->id);
204
    }
205
206
    /**
207
     * Add a channel to a bridge.
208
     *
209
     * @param string $channel (required) Ids of channels to add to bridge.  Allows comma separated values.
210
     * @param string $role Channel's role in the bridge
211
     * @throws NotFoundException
212
     * @throws ConflictException
213
     * @throws UnprocessableEntityException
214
     */
215
    public function addChannel($channel, $role = null)
216
    {
217
        $this->client->bridges()->addChannel($this->id, $channel, $role);
218
    }
219
220
    /**
221
     * Remove a channel from a bridge.
222
     *
223
     * @param string $channel (required) Ids of channels to remove from bridge.  Allows comma separated values.
224
     * @throws NotFoundException
225
     * @throws ConflictException
226
     * @throws UnprocessableEntityException
227
     */
228
    public function removeChannel($channel)
229
    {
230
        $this->client->bridges()->removeChannel($this->id, $channel);
231
    }
232
233
    /**
234
     * Play music on hold to a bridge or change the MOH class that is playing.
235
     *
236
     * @param string $mohClass Music on hold class to use
237
     * @throws NotFoundException
238
     * @throws ConflictException
239
     */
240
    public function startMusicOnHold($mohClass)
241
    {
242
        $this->client->bridges()->startMusicOnHold($this->id, $mohClass);
243
    }
244
245
    /**
246
     * Stop playing music on hold to a bridge. This will only stop music on hold being played via POST bridges/{bridgeId}/moh.
247
     *
248
     * @throws NotFoundException
249
     * @throws ConflictException
250
     */
251
    public function stopMusicOnHold()
252
    {
253
        $this->client->bridges()->stopMusicOnHold($this->id);
254
    }
255
256
    /**
257
     * Start playback of media on a bridge. The media URI may be any of a number of URI's. Currently
258
     * sound:, recording:, number:, digits:, characters:, and tone: URI's are supported. This operation
259
     * creates a playback resource that can be used to control the playback of media (pause, rewind,
260
     * fast forward, etc.)
261
     *
262
     * @link https://wiki.asterisk.org/wiki/display/AST/ARI+and+Channels%3A+Simple+Media+Manipulation Simple media playback
263
     *
264
     * @param string $media (required) Media's URI to play.
265
     * @param string $lang For sounds, selects language for sound.
266
     * @param int $offsetms Number of media to skip before playing.
267
     * @param int $skipms (3000 default) Number of milliseconds to skip for forward/reverse operations.
268
     * @param string $playbackId Playback Id.
269
     * @return Playback
270
     * @throws NotFoundException
271
     * @throws ConflictException
272
     */
273
    public function playMedia($media, $lang = null, $offsetms = null, $skipms = null, $playbackId = null)
274
    {
275
        return $this->client->bridges()->playMedia($this->id, $media, $lang, $offsetms, $skipms, $playbackId);
276
    }
277
278
    /**
279
     * Start playback of media on a bridge. The media URI may be any of a number of URI's. Currently
280
     * sound:, recording:, number:, digits:, characters:, and tone: URI's are supported. This operation
281
     * creates a playback resource that can be used to control the playback of media (pause, rewind,
282
     * fast forward, etc.)
283
     *
284
     * @link https://wiki.asterisk.org/wiki/display/AST/ARI+and+Channels%3A+Simple+Media+Manipulation Simple media playback
285
     *
286
     * @param string $media (required) Media's URI to play.
287
     * @param string $lang For sounds, selects language for sound.
288
     * @param int $offsetms Number of media to skip before playing.
289
     * @param int $skipms (3000 default) Number of milliseconds to skip for forward/reverse operations.
290
     * @param string $playbackId Playback Id.
291
     * @return Playback
292
     * @throws NotFoundException
293
     * @throws ConflictException
294
     */
295
    public function playMediaWithId($media, $lang = null, $offsetms = null, $skipms = null, $playbackId = null)
296
    {
297
        return $this->client->bridges()->playMediaWithId($this->id, $media, $lang, $offsetms, $skipms, $playbackId);
298
    }
299
300
    /**
301
     * Start a recording. Record audio from a channel. Note that this will not capture audio sent to the
302
     * channel. The bridge itself has a record feature if that's what you want.
303
     *
304
     * @param string $name (required) Recording's filename
305
     * @param string $format (required) Format to encode audio in
306
     * @param int $maxDurationSeconds Maximum duration of the recording, in seconds. 0 for no limit.  Allowed range: Min: 0; Max: None
307
     * @param int $maxSilenceSeconds Maximum duration of silence, in seconds. 0 for no limit.  Allowed range: Min: 0; Max: None
308
     * @param string $ifExists = Action to take if a recording with the same name already exists. default: fail, Allowed values: fail, overwrite, append
309
     * @param boolean $beep Play beep when recording begins
310
     * @param string $terminateOn DTMF input to terminate recording.  Default: none, Allowed values: none, any, *, #
311
     * @return LiveRecording
312
     * @throws InvalidParameterException
313
     * @throws NotFoundException
314
     * @throws ConflictException
315
     * @throws UnprocessableEntityException
316
     */
317 View Code Duplication
    public function record(
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...
318
        $name,
319 23
        $format,
320
        $maxDurationSeconds = null,
321 23
        $maxSilenceSeconds = null,
322
        $ifExists = null,
323 23
        $beep = null,
324 23
        $terminateOn = null
325 23
    ) {
326 23
        return $this->client->bridges()->record($this->id, $name, $format, $maxDurationSeconds, $maxSilenceSeconds,
327 23
            $ifExists, $beep, $terminateOn);
328 23
    }
329 23
330 23
    /**
331
     * @param AriClient $client
332
     * @param string $response
333
     */
334
    public function __construct(AriClient $client, $response)
335
    {
336
        parent::__construct($client, $response);
337
338
        $this->bridgeClass = $this->getResponseValue('bridge_class');
339
        $this->bridgeType = $this->getResponseValue('bridge_type');
340
        $this->channels = $this->getResponseValue('channels');
0 ignored issues
show
Bug introduced by
The property channels 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...
341
        $this->creator = $this->getResponseValue('creator');
342
        $this->id = $this->getResponseValue('id');
343
        $this->name = $this->getResponseValue('name');
344
        $this->technology = $this->getResponseValue('technology');
345
    }
346
347
}
348