Completed
Push — master ( 0e6f1b...69c814 )
by Brian
02:51
created

Bridge::onBridgeAttendedTransfer()   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
     * @param callable $callback
198
     */
199
    public function onBridgeBlindTransfer(callable $callback)
200
    {
201
        $this->on(Event::BRIDGE_BLIND_TRANSFER.'_'.$this->getId(), $callback);
202
    }
203
204
    /**
205
     * @param callable $callback
206
     */
207
    public function onceBridgeBlindTransfer(callable $callback)
208
    {
209
        $this->once(Event::BRIDGE_BLIND_TRANSFER.'_'.$this->getId(), $callback);
210
    }
211
212
    /**
213
     * @param callable $callback
214
     */
215
    public function onBridgeAttendedTransfer(callable $callback)
216
    {
217
        $this->on(Event::BRIDGE_ATTENDED_TRANSFER.'_'.$this->getId(), $callback);
218
    }
219
220
    /**
221
     * @param callable $callback
222
     */
223
    public function onceBridgeAttendedTransfer(callable $callback)
224
    {
225
        $this->once(Event::BRIDGE_ATTENDED_TRANSFER.'_'.$this->getId(), $callback);
226
    }
227
228
    /**
229
     * Shut down a bridge. If any channels are in this bridge, they will be removed and resume whatever they were doing beforehand.
230
     *
231
     * @throws NotFoundException
232
     */
233
    public function deleteBridge()
234
    {
235
        $this->client->bridges()->deleteBridge($this->id);
236
    }
237
238
    /**
239
     * Add a channel to a bridge.
240
     *
241
     * @param string $channel (required) Ids of channels to add to bridge.  Allows comma separated values.
242
     * @param string $role Channel's role in the bridge
243
     * @throws NotFoundException
244
     * @throws ConflictException
245
     * @throws UnprocessableEntityException
246
     */
247
    public function addChannel($channel, $role = null)
248
    {
249
        $this->client->bridges()->addChannel($this->id, $channel, $role);
250
    }
251
252
    /**
253
     * Remove a channel from a bridge.
254
     *
255
     * @param string $channel (required) Ids of channels to remove from bridge.  Allows comma separated values.
256
     * @throws NotFoundException
257
     * @throws ConflictException
258
     * @throws UnprocessableEntityException
259
     */
260
    public function removeChannel($channel)
261
    {
262
        $this->client->bridges()->removeChannel($this->id, $channel);
263
    }
264
265
    /**
266
     * Play music on hold to a bridge or change the MOH class that is playing.
267
     *
268
     * @param string $mohClass Music on hold class to use
269
     * @throws NotFoundException
270
     * @throws ConflictException
271
     */
272
    public function startMusicOnHold($mohClass)
273
    {
274
        $this->client->bridges()->startMusicOnHold($this->id, $mohClass);
275
    }
276
277
    /**
278
     * Stop playing music on hold to a bridge. This will only stop music on hold being played via POST bridges/{bridgeId}/moh.
279
     *
280
     * @throws NotFoundException
281
     * @throws ConflictException
282
     */
283
    public function stopMusicOnHold()
284
    {
285
        $this->client->bridges()->stopMusicOnHold($this->id);
286
    }
287
288
    /**
289
     * Start playback of media on a bridge. The media URI may be any of a number of URI's. Currently
290
     * sound:, recording:, number:, digits:, characters:, and tone: URI's are supported. This operation
291
     * creates a playback resource that can be used to control the playback of media (pause, rewind,
292
     * fast forward, etc.)
293
     *
294
     * @link https://wiki.asterisk.org/wiki/display/AST/ARI+and+Channels%3A+Simple+Media+Manipulation Simple media playback
295
     *
296
     * @param string $media (required) Media's URI to play.
297
     * @param string $lang For sounds, selects language for sound.
298
     * @param int $offsetms Number of media to skip before playing.
299
     * @param int $skipms (3000 default) Number of milliseconds to skip for forward/reverse operations.
300
     * @param string $playbackId Playback Id.
301
     * @return Playback
302
     * @throws NotFoundException
303
     * @throws ConflictException
304
     */
305
    public function playMedia($media, $lang = null, $offsetms = null, $skipms = null, $playbackId = null)
306
    {
307
        return $this->client->bridges()->playMedia($this->id, $media, $lang, $offsetms, $skipms, $playbackId);
308
    }
309
310
    /**
311
     * Start playback of media on a bridge. The media URI may be any of a number of URI's. Currently
312
     * sound:, recording:, number:, digits:, characters:, and tone: URI's are supported. This operation
313
     * creates a playback resource that can be used to control the playback of media (pause, rewind,
314
     * fast forward, etc.)
315
     *
316
     * @link https://wiki.asterisk.org/wiki/display/AST/ARI+and+Channels%3A+Simple+Media+Manipulation Simple media playback
317
     *
318
     * @param string $media (required) Media's URI to play.
319 23
     * @param string $lang For sounds, selects language for sound.
320
     * @param int $offsetms Number of media to skip before playing.
321 23
     * @param int $skipms (3000 default) Number of milliseconds to skip for forward/reverse operations.
322
     * @param string $playbackId Playback Id.
323 23
     * @return Playback
324 23
     * @throws NotFoundException
325 23
     * @throws ConflictException
326 23
     */
327 23
    public function playMediaWithId($media, $lang = null, $offsetms = null, $skipms = null, $playbackId = null)
328 23
    {
329 23
        return $this->client->bridges()->playMediaWithId($this->id, $media, $lang, $offsetms, $skipms, $playbackId);
330 23
    }
331
332
    /**
333
     * Start a recording. Record audio from a channel. Note that this will not capture audio sent to the
334
     * channel. The bridge itself has a record feature if that's what you want.
335
     *
336
     * @param string $name (required) Recording's filename
337
     * @param string $format (required) Format to encode audio in
338
     * @param int $maxDurationSeconds Maximum duration of the recording, in seconds. 0 for no limit.  Allowed range: Min: 0; Max: None
339
     * @param int $maxSilenceSeconds Maximum duration of silence, in seconds. 0 for no limit.  Allowed range: Min: 0; Max: None
340
     * @param string $ifExists = Action to take if a recording with the same name already exists. default: fail, Allowed values: fail, overwrite, append
341
     * @param boolean $beep Play beep when recording begins
342
     * @param string $terminateOn DTMF input to terminate recording.  Default: none, Allowed values: none, any, *, #
343
     * @return LiveRecording
344
     * @throws InvalidParameterException
345
     * @throws NotFoundException
346
     * @throws ConflictException
347
     * @throws UnprocessableEntityException
348
     */
349 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...
350
        $name,
351
        $format,
352
        $maxDurationSeconds = null,
353
        $maxSilenceSeconds = null,
354
        $ifExists = null,
355
        $beep = null,
356
        $terminateOn = null
357
    ) {
358
        return $this->client->bridges()->record($this->id, $name, $format, $maxDurationSeconds, $maxSilenceSeconds,
359
            $ifExists, $beep, $terminateOn);
360
    }
361
362
    /**
363
     * @param AriClient $client
364
     * @param string $response
365
     */
366
    public function __construct(AriClient $client, $response)
367
    {
368
        parent::__construct($client, $response);
369
370
        $this->bridgeClass = $this->getResponseValue('bridge_class');
371
        $this->bridgeType = $this->getResponseValue('bridge_type');
372
        $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...
373
        $this->creator = $this->getResponseValue('creator');
374
        $this->id = $this->getResponseValue('id');
375
        $this->name = $this->getResponseValue('name');
376
        $this->technology = $this->getResponseValue('technology');
377
    }
378
379
}
380