Completed
Pull Request — master (#13)
by
unknown
13:13
created

Bridge::onBridgeBlindTransfer()   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 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
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 $channels;
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
     * @todo Should this be renamed to getChannelIds()?
94
     * @return array Ids of channels participating in this bridge
95
     */
96 3
    public function getChannels()
97
    {
98 3
        return $this->channels;
99
    }
100
101
    /**
102
     * @return string Entity that created the bridge
103
     */
104
    public function getCreator()
105
    {
106
        return $this->creator;
107
    }
108
109
    /**
110
     * @return string Unique identifier for this bridge
111
     */
112 2
    public function getId()
113
    {
114 2
        return $this->id;
115
    }
116
117
    /**
118
     * @return string Unique identifier for this bridge
119
     */
120
    public function getName()
121
    {
122
        return $this->name;
123
    }
124
125
    /**
126
     * @return string Name of the current bridging technology
127
     */
128
    public function getTechnology()
129
    {
130
        return $this->technology;
131
    }
132
133
    /**
134
     * @param callable $callback
135
     */
136
    public function onBridgeCreated(callable $callback)
137
    {
138
        $this->on(Event::BRIDGE_CREATED.'_'.$this->getId(), $callback);
139
    }
140
141
    /**
142
     * @param callable $callback
143
     */
144
    public function onceBridgeCreated(callable $callback)
145
    {
146
        $this->once(Event::BRIDGE_CREATED.'_'.$this->getId(), $callback);
147
    }
148
149
    /**
150
     * @param callable $callback
151
     */
152
    public function onBridgeDestroyed(callable $callback)
153
    {
154
        $this->on(Event::BRIDGE_DESTROYED.'_'.$this->getId(), $callback);
155
    }
156
157
    /**
158
     * @param callable $callback
159
     */
160
    public function onceBridgeDestroyed(callable $callback)
161
    {
162
        $this->once(Event::BRIDGE_DESTROYED.'_'.$this->getId(), $callback);
163
    }
164
165
    /**
166
     * @param callable $callback
167
     */
168
    public function onBridgeMerged(callable $callback)
169
    {
170
        $this->on(Event::BRIDGE_MERGED.'_'.$this->getId(), $callback);
171
    }
172
173
    /**
174
     * @param callable $callback
175
     */
176
    public function onceBridgeMerged(callable $callback)
177
    {
178
        $this->once(Event::BRIDGE_MERGED.'_'.$this->getId(), $callback);
179
    }
180
181
    /**
182
     * @param callable $callback
183
     */
184
    public function onBridgeBlindTransfer(callable $callback)
185
    {
186
        $this->on(Event::BRIDGE_BLIND_TRANSFER.'_'.$this->getId(), $callback);
187
    }
188
189
    /**
190
     * @param callable $callback
191
     */
192
    public function onceBridgeBlindTransfer(callable $callback)
193
    {
194
        $this->once(Event::BRIDGE_BLIND_TRANSFER.'_'.$this->getId(), $callback);
195
    }
196
197
    /**
198
     * @param callable $callback
199
     */
200
    public function onBridgeAttendedTransfer(callable $callback)
201
    {
202
        $this->on(Event::BRIDGE_ATTENDED_TRANSFER.'_'.$this->getId(), $callback);
203
    }
204
205
    /**
206
     * @param callable $callback
207
     */
208
    public function onceBridgeAttendedTransfer(callable $callback)
209
    {
210
        $this->once(Event::BRIDGE_ATTENDED_TRANSFER.'_'.$this->getId(), $callback);
211
    }
212
213
    /**
214
     * Shut down a bridge. If any channels are in this bridge, they will be removed and resume whatever they were doing beforehand.
215
     *
216
     * @throws NotFoundException
217
     */
218
    public function deleteBridge()
219
    {
220
        $this->client->bridges()->deleteBridge($this->id);
221
    }
222
223
    /**
224
     * Add a channel to a bridge.
225
     *
226
     * @param string $channel (required) Ids of channels to add to bridge.  Allows comma separated values.
227
     * @param string $role Channel's role in the bridge
228
     * @throws NotFoundException
229
     * @throws ConflictException
230
     * @throws UnprocessableEntityException
231
     */
232
    public function addChannel($channel, $role = null)
233
    {
234
        $this->client->bridges()->addChannel($this->id, $channel, $role);
235
    }
236
237
    /**
238
     * Remove a channel from a bridge.
239
     *
240
     * @param string $channel (required) Ids of channels to remove from bridge.  Allows comma separated values.
241
     * @throws NotFoundException
242
     * @throws ConflictException
243
     * @throws UnprocessableEntityException
244
     */
245
    public function removeChannel($channel)
246
    {
247
        $this->client->bridges()->removeChannel($this->id, $channel);
248
    }
249
250
    /**
251
     * Play music on hold to a bridge or change the MOH class that is playing.
252
     *
253
     * @param string $mohClass Music on hold class to use
254
     * @throws NotFoundException
255
     * @throws ConflictException
256
     */
257
    public function startMusicOnHold($mohClass)
258
    {
259
        $this->client->bridges()->startMusicOnHold($this->id, $mohClass);
260
    }
261
262
    /**
263
     * Stop playing music on hold to a bridge. This will only stop music on hold being played via POST bridges/{bridgeId}/moh.
264
     *
265
     * @throws NotFoundException
266
     * @throws ConflictException
267
     */
268
    public function stopMusicOnHold()
269
    {
270
        $this->client->bridges()->stopMusicOnHold($this->id);
271
    }
272
273
    /**
274
     * Start playback of media on a bridge. The media URI may be any of a number of URI's. Currently
275
     * sound:, recording:, number:, digits:, characters:, and tone: URI's are supported. This operation
276
     * creates a playback resource that can be used to control the playback of media (pause, rewind,
277
     * fast forward, etc.)
278
     *
279
     * @link https://wiki.asterisk.org/wiki/display/AST/ARI+and+Channels%3A+Simple+Media+Manipulation Simple media playback
280
     *
281
     * @param string $media (required) Media's URI to play.
282
     * @param string $lang For sounds, selects language for sound.
283
     * @param int $offsetms Number of media to skip before playing.
284
     * @param int $skipms (3000 default) Number of milliseconds to skip for forward/reverse operations.
285
     * @param string $playbackId Playback Id.
286
     * @return Playback
287
     * @throws NotFoundException
288
     * @throws ConflictException
289
     */
290
    public function playMedia($media, $lang = null, $offsetms = null, $skipms = null, $playbackId = null)
291
    {
292
        return $this->client->bridges()->playMedia($this->id, $media, $lang, $offsetms, $skipms, $playbackId);
293
    }
294
295
    /**
296
     * Start playback of media on a bridge. The media URI may be any of a number of URI's. Currently
297
     * sound:, recording:, number:, digits:, characters:, and tone: URI's are supported. This operation
298
     * creates a playback resource that can be used to control the playback of media (pause, rewind,
299
     * fast forward, etc.)
300
     *
301
     * @link https://wiki.asterisk.org/wiki/display/AST/ARI+and+Channels%3A+Simple+Media+Manipulation Simple media playback
302
     *
303
     * @param string $media (required) Media's URI to play.
304
     * @param string $lang For sounds, selects language for sound.
305
     * @param int $offsetms Number of media to skip before playing.
306
     * @param int $skipms (3000 default) Number of milliseconds to skip for forward/reverse operations.
307
     * @param string $playbackId Playback Id.
308
     * @return Playback
309
     * @throws NotFoundException
310
     * @throws ConflictException
311
     */
312
    public function playMediaWithId($media, $lang = null, $offsetms = null, $skipms = null, $playbackId = null)
313
    {
314
        return $this->client->bridges()->playMediaWithId($this->id, $media, $lang, $offsetms, $skipms, $playbackId);
315
    }
316
317
    /**
318
     * Start a recording. Record audio from a channel. Note that this will not capture audio sent to the
319
     * channel. The bridge itself has a record feature if that's what you want.
320
     *
321
     * @param string $name (required) Recording's filename
322
     * @param string $format (required) Format to encode audio in
323
     * @param int $maxDurationSeconds Maximum duration of the recording, in seconds. 0 for no limit.  Allowed range: Min: 0; Max: None
324
     * @param int $maxSilenceSeconds Maximum duration of silence, in seconds. 0 for no limit.  Allowed range: Min: 0; Max: None
325
     * @param string $ifExists = Action to take if a recording with the same name already exists. default: fail, Allowed values: fail, overwrite, append
326
     * @param boolean $beep Play beep when recording begins
327
     * @param string $terminateOn DTMF input to terminate recording.  Default: none, Allowed values: none, any, *, #
328
     * @return LiveRecording
329
     * @throws InvalidParameterException
330
     * @throws NotFoundException
331
     * @throws ConflictException
332
     * @throws UnprocessableEntityException
333
     */
334 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...
335
        $name,
336
        $format,
337
        $maxDurationSeconds = null,
338
        $maxSilenceSeconds = null,
339
        $ifExists = null,
340
        $beep = null,
341
        $terminateOn = null
342
    ) {
343
        return $this->client->bridges()->record($this->id, $name, $format, $maxDurationSeconds, $maxSilenceSeconds,
344
            $ifExists, $beep, $terminateOn);
345
    }
346
347
    /**
348
     * @param AriClient $client
349
     * @param string $response
350
     */
351 23
    public function __construct(AriClient $client, $response)
352
    {
353 23
        parent::__construct($client, $response);
354
355 23
        $this->bridgeClass = $this->getResponseValue('bridge_class');
356 23
        $this->bridgeType = $this->getResponseValue('bridge_type');
357 23
        $this->channels = $this->getResponseValue('channels');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getResponseValue('channels') of type * is incompatible with the declared type array of property $channels.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
358 23
        $this->creator = $this->getResponseValue('creator');
359 23
        $this->id = $this->getResponseValue('id');
360 23
        $this->name = $this->getResponseValue('name');
361 23
        $this->technology = $this->getResponseValue('technology');
362 23
    }
363
364
}
365