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\Api; |
20
|
|
|
|
21
|
|
|
use GuzzleHttp\Exception\RequestException; |
22
|
|
|
use phparia\Resources\Bridge; |
23
|
|
|
use phparia\Exception\ConflictException; |
24
|
|
|
use phparia\Exception\InvalidParameterException; |
25
|
|
|
use phparia\Exception\NotFoundException; |
26
|
|
|
use phparia\Exception\UnprocessableEntityException; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Bridges API |
30
|
|
|
* |
31
|
|
|
* @author Brian Smith <[email protected]> |
32
|
|
|
*/ |
33
|
|
|
class Bridges extends MediaBase |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* List all active bridges in Asterisk. |
37
|
|
|
* |
38
|
|
|
* @return Bridge[] |
39
|
|
|
*/ |
40
|
|
View Code Duplication |
public function getBridges() |
41
|
|
|
{ |
42
|
|
|
$uri = 'bridges'; |
43
|
|
|
$response = $this->client->getEndpoint()->get($uri); |
44
|
|
|
|
45
|
|
|
$bridges = []; |
46
|
|
|
foreach (\GuzzleHttp\json_decode($response->getBody()) as $bridge) { |
47
|
|
|
$bridges[] = new Bridge($this->client, $bridge); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $bridges; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Create a new bridge. This bridge persists until it has been shut down, or Asterisk has been shut down. |
55
|
|
|
* |
56
|
|
|
* @param string $bridgeId Unique ID to give to the bridge being created. |
57
|
|
|
* @param string $type Comma separated list of bridge type attributes (mixing, holding, dtmf_events, proxy_media). |
58
|
|
|
* @param string $name Name to give to the bridge being created. |
59
|
|
|
* @return Bridge |
60
|
|
|
*/ |
61
|
12 |
|
public function createBridge($bridgeId, $type, $name) |
62
|
|
|
{ |
63
|
12 |
|
$uri = 'bridges'; |
64
|
12 |
|
$response = $this->client->getEndpoint()->post($uri, [ |
65
|
|
|
'form_params' => [ |
66
|
12 |
|
'bridgeId' => $bridgeId, |
67
|
12 |
|
'type' => $type, |
68
|
12 |
|
'name' => $name, |
69
|
|
|
] |
70
|
12 |
|
]); |
71
|
|
|
|
72
|
|
|
return new Bridge($this->client, \GuzzleHttp\json_decode($response->getBody())); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Create a new bridge or updates an existing one. This bridge persists until it has been shut down, or Asterisk has been shut down. |
77
|
|
|
* |
78
|
|
|
* @param string $bridgeId Unique ID to give to the bridge being created. |
79
|
|
|
* @param string $type Comma separated list of bridge type attributes (mixing, holding, dtmf_events, proxy_media) to set. |
80
|
|
|
* @param string $name Set the name of the bridge. |
81
|
|
|
* @return Bridge |
82
|
|
|
*/ |
83
|
|
|
public function updateBridge($bridgeId, $type, $name) |
84
|
|
|
{ |
85
|
|
|
$uri = "bridges/$bridgeId"; |
86
|
|
|
$response = $this->client->getEndpoint()->post($uri, [ |
87
|
|
|
'form_params' => [ |
88
|
|
|
'type' => $type, |
89
|
|
|
'name' => $name, |
90
|
|
|
] |
91
|
|
|
]); |
92
|
|
|
|
93
|
|
|
return new Bridge($this->client, \GuzzleHttp\json_decode($response->getBody())); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Get bridge details. |
98
|
|
|
* |
99
|
|
|
* @param string $bridgeId Bridge's id |
100
|
|
|
* @return Bridge |
101
|
|
|
* @throws NotFoundException |
102
|
|
|
*/ |
103
|
2 |
View Code Duplication |
public function getBridge($bridgeId) |
104
|
|
|
{ |
105
|
2 |
|
$uri = "bridges/$bridgeId"; |
106
|
|
|
try { |
107
|
2 |
|
$response = $this->client->getEndpoint()->get($uri); |
108
|
2 |
|
} catch (RequestException $e) { |
109
|
2 |
|
$this->processRequestException($e); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return new Bridge($this->client, \GuzzleHttp\json_decode($response->getBody())); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Shut down a bridge. If any channels are in this bridge, they will be removed and resume whatever they were doing beforehand. |
117
|
|
|
* |
118
|
|
|
* @param string $bridgeId Bridge's id |
119
|
|
|
* @throws NotFoundException |
120
|
|
|
*/ |
121
|
2 |
|
public function deleteBridge($bridgeId) |
122
|
|
|
{ |
123
|
2 |
|
$uri = "bridges/$bridgeId"; |
124
|
|
|
try { |
125
|
2 |
|
$this->client->getEndpoint()->delete($uri); |
126
|
2 |
|
} catch (RequestException $e) { |
127
|
2 |
|
$this->processRequestException($e); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Add a channel to a bridge. |
133
|
|
|
* |
134
|
|
|
* @param string $bridgeId Bridge's id |
135
|
|
|
* @param string $channel (required) Ids of channels to add to bridge. Allows comma separated values. |
136
|
|
|
* @param string $role Channel's role in the bridge |
137
|
|
|
* @throws NotFoundException |
138
|
|
|
* @throws ConflictException |
139
|
|
|
* @throws UnprocessableEntityException |
140
|
|
|
*/ |
141
|
|
|
public function addChannel($bridgeId, $channel, $role = null) |
142
|
|
|
{ |
143
|
|
|
$uri = "bridges/$bridgeId/addChannel"; |
144
|
|
|
try { |
145
|
|
|
$this->client->getEndpoint()->post($uri, [ |
146
|
|
|
'form_params' => [ |
147
|
|
|
'channel' => $channel, |
148
|
|
|
'role' => $role, |
149
|
|
|
] |
150
|
|
|
]); |
151
|
|
|
} catch (RequestException $e) { |
152
|
|
|
$this->processRequestException($e); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Remove a channel from a bridge. |
158
|
|
|
* |
159
|
|
|
* @param string $bridgeId Bridge's id |
160
|
|
|
* @param string $channel (required) Ids of channels to remove from bridge. Allows comma separated values. |
161
|
|
|
* @throwe InvalidParameterException |
162
|
|
|
* @throws NotFoundException |
163
|
|
|
* @throws ConflictException |
164
|
|
|
* @throws UnprocessableEntityException |
165
|
|
|
*/ |
166
|
|
|
public function removeChannel($bridgeId, $channel) |
167
|
|
|
{ |
168
|
|
|
$uri = "bridges/$bridgeId/removeChannel"; |
169
|
|
|
try { |
170
|
|
|
$this->client->getEndpoint()->post($uri, [ |
171
|
|
|
'form_params' => [ |
172
|
|
|
'channel' => $channel, |
173
|
|
|
] |
174
|
|
|
]); |
175
|
|
|
} catch (RequestException $e) { |
176
|
|
|
$this->processRequestException($e); |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Set a channel as the video source in a multi-party mixing bridge. This operation has no effect on bridges with |
182
|
|
|
* two or fewer participants. |
183
|
|
|
* |
184
|
|
|
* @param string $id Bridge's id |
185
|
|
|
* @param string $channelId Channel's id |
186
|
|
|
* @throws NotFoundException |
187
|
|
|
* @throws ConflictException |
188
|
|
|
* @throws UnprocessableEntityException |
189
|
|
|
*/ |
190
|
|
|
public function setVideoSource($id, $channelId) |
191
|
|
|
{ |
192
|
|
|
$uri = "bridges/$id/videoSource/$channelId"; |
193
|
|
|
try { |
194
|
|
|
$this->client->getEndpoint()->post($uri); |
195
|
|
|
} catch (RequestException $e) { |
196
|
|
|
$this->processRequestException($e); |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Removes any explicit video source in a multi-party mixing bridge. This operation has no effect on bridges with |
202
|
|
|
* two or fewer participants. When no explicit video source is set, talk detection will be used to determine the |
203
|
|
|
* active video stream. |
204
|
|
|
* |
205
|
|
|
* @param string $id Bridge's id |
206
|
|
|
* @throws NotFoundException |
207
|
|
|
* @throws ConflictException |
208
|
|
|
* @throws UnprocessableEntityException |
209
|
|
|
*/ |
210
|
|
|
public function clearVideoSource($id) |
211
|
|
|
{ |
212
|
|
|
$uri = "bridges/$id/videoSource"; |
213
|
|
|
try { |
214
|
|
|
$this->client->getEndpoint()->delete($uri); |
215
|
|
|
} catch (RequestException $e) { |
216
|
|
|
$this->processRequestException($e); |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
public function getType() |
221
|
|
|
{ |
222
|
|
|
return 'bridges'; |
223
|
|
|
} |
224
|
|
|
} |
225
|
|
|
|