Completed
Push — master ( fe47f8...2aa7aa )
by Brian
09:43
created

Bridge::getChannelIds()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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 onBridgeMerged(callable $callback)
168
    {
169
        $this->on(Event::BRIDGE_MERGED.'_'.$this->getId(), $callback);
170
    }
171
172
    /**
173
     * @param callable $callback
174
     */
175
    public function onceBridgeMerged(callable $callback)
176
    {
177
        $this->once(Event::BRIDGE_MERGED.'_'.$this->getId(), $callback);
178
    }
179
180
    /**
181
     * Shut down a bridge. If any channels are in this bridge, they will be removed and resume whatever they were doing beforehand.
182
     *
183
     * @throws NotFoundException
184
     */
185
    public function deleteBridge()
186
    {
187
        $this->client->bridges()->deleteBridge($this->id);
188
    }
189
190
    /**
191
     * Add a channel to a bridge.
192
     *
193
     * @param string $channel (required) Ids of channels to add to bridge.  Allows comma separated values.
194
     * @param string $role Channel's role in the bridge
195
     * @throws NotFoundException
196
     * @throws ConflictException
197
     * @throws UnprocessableEntityException
198
     */
199
    public function addChannel($channel, $role = null)
200
    {
201
        $this->client->bridges()->addChannel($this->id, $channel, $role);
202
    }
203
204
    /**
205
     * Remove a channel from a bridge.
206
     *
207
     * @param string $channel (required) Ids of channels to remove from bridge.  Allows comma separated values.
208
     * @throws NotFoundException
209
     * @throws ConflictException
210
     * @throws UnprocessableEntityException
211
     */
212
    public function removeChannel($channel)
213
    {
214
        $this->client->bridges()->removeChannel($this->id, $channel);
215
    }
216
217
    /**
218
     * Play music on hold to a bridge or change the MOH class that is playing.
219
     *
220
     * @param string $mohClass Music on hold class to use
221
     * @throws NotFoundException
222
     * @throws ConflictException
223
     */
224
    public function startMusicOnHold($mohClass)
225
    {
226
        $this->client->bridges()->startMusicOnHold($this->id, $mohClass);
227
    }
228
229
    /**
230
     * Stop playing music on hold to a bridge. This will only stop music on hold being played via POST bridges/{bridgeId}/moh.
231
     *
232
     * @throws NotFoundException
233
     * @throws ConflictException
234
     */
235
    public function stopMusicOnHold()
236
    {
237
        $this->client->bridges()->stopMusicOnHold($this->id);
238
    }
239
240
    /**
241
     * Start playback of media on a bridge. The media URI may be any of a number of URI's. Currently
242
     * sound:, recording:, number:, digits:, characters:, and tone: URI's are supported. This operation
243
     * creates a playback resource that can be used to control the playback of media (pause, rewind,
244
     * fast forward, etc.)
245
     *
246
     * @link https://wiki.asterisk.org/wiki/display/AST/ARI+and+Channels%3A+Simple+Media+Manipulation Simple media playback
247
     *
248
     * @param string $media (required) Media's URI to play.
249
     * @param string $lang For sounds, selects language for sound.
250
     * @param int $offsetms Number of media to skip before playing.
251
     * @param int $skipms (3000 default) Number of milliseconds to skip for forward/reverse operations.
252
     * @param string $playbackId Playback Id.
253
     * @return Playback
254
     * @throws NotFoundException
255
     * @throws ConflictException
256
     */
257
    public function playMedia($media, $lang = null, $offsetms = null, $skipms = null, $playbackId = null)
258
    {
259
        return $this->client->bridges()->playMedia($this->id, $media, $lang, $offsetms, $skipms, $playbackId);
260
    }
261
262
    /**
263
     * Start playback of media on a bridge. The media URI may be any of a number of URI's. Currently
264
     * sound:, recording:, number:, digits:, characters:, and tone: URI's are supported. This operation
265
     * creates a playback resource that can be used to control the playback of media (pause, rewind,
266
     * fast forward, etc.)
267
     *
268
     * @link https://wiki.asterisk.org/wiki/display/AST/ARI+and+Channels%3A+Simple+Media+Manipulation Simple media playback
269
     *
270
     * @param string $media (required) Media's URI to play.
271
     * @param string $lang For sounds, selects language for sound.
272
     * @param int $offsetms Number of media to skip before playing.
273
     * @param int $skipms (3000 default) Number of milliseconds to skip for forward/reverse operations.
274
     * @param string $playbackId Playback Id.
275
     * @return Playback
276
     * @throws NotFoundException
277
     * @throws ConflictException
278
     */
279
    public function playMediaWithId($media, $lang = null, $offsetms = null, $skipms = null, $playbackId = null)
280
    {
281
        return $this->client->bridges()->playMediaWithId($this->id, $media, $lang, $offsetms, $skipms, $playbackId);
282
    }
283
284
    /**
285
     * Start a recording. Record audio from a channel. Note that this will not capture audio sent to the
286
     * channel. The bridge itself has a record feature if that's what you want.
287
     *
288
     * @param string $name (required) Recording's filename
289
     * @param string $format (required) Format to encode audio in
290
     * @param int $maxDurationSeconds Maximum duration of the recording, in seconds. 0 for no limit.  Allowed range: Min: 0; Max: None
291
     * @param int $maxSilenceSeconds Maximum duration of silence, in seconds. 0 for no limit.  Allowed range: Min: 0; Max: None
292
     * @param string $ifExists = Action to take if a recording with the same name already exists. default: fail, Allowed values: fail, overwrite, append
293
     * @param boolean $beep Play beep when recording begins
294
     * @param string $terminateOn DTMF input to terminate recording.  Default: none, Allowed values: none, any, *, #
295
     * @return LiveRecording
296
     * @throws InvalidParameterException
297
     * @throws NotFoundException
298
     * @throws ConflictException
299
     * @throws UnprocessableEntityException
300
     */
301 View Code Duplication
    public function record(
0 ignored issues
show
Duplication introduced by Brian Smith
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...
302
        $name,
303
        $format,
304
        $maxDurationSeconds = null,
305
        $maxSilenceSeconds = null,
306
        $ifExists = null,
307
        $beep = null,
308
        $terminateOn = null
309
    ) {
310
        return $this->client->bridges()->record($this->id, $name, $format, $maxDurationSeconds, $maxSilenceSeconds,
311
            $ifExists, $beep, $terminateOn);
312
    }
313
314
    /**
315
     * @param AriClient $client
316
     * @param string $response
317
     */
318
    public function __construct(AriClient $client, $response)
319 23
    {
320
        parent::__construct($client, $response);
321 23
322
        $this->bridgeClass = $this->getResponseValue('bridge_class');
323 23
        $this->bridgeType = $this->getResponseValue('bridge_type');
324 23
        $this->channels = $this->getResponseValue('channels');
0 ignored issues
show
Bug introduced by Brian Smith
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...
325 23
        $this->creator = $this->getResponseValue('creator');
326 23
        $this->id = $this->getResponseValue('id');
327 23
        $this->name = $this->getResponseValue('name');
328 23
        $this->technology = $this->getResponseValue('technology');
329 23
    }
330 23
331
}
332