1 | <?php |
||
37 | class Phparia |
||
38 | { |
||
39 | /** |
||
40 | * @var WebSocket |
||
41 | */ |
||
42 | protected $wsClient; |
||
43 | |||
44 | /** |
||
45 | * @var EventLoop\LoopInterface |
||
46 | */ |
||
47 | protected $eventLoop; |
||
48 | |||
49 | /** |
||
50 | * @var LoggerInterface |
||
51 | */ |
||
52 | protected $logger; |
||
53 | |||
54 | /** |
||
55 | * @var AriClient |
||
56 | */ |
||
57 | protected $ariClient; |
||
58 | |||
59 | /** |
||
60 | * @var AmiClient |
||
61 | */ |
||
62 | protected $amiClient; |
||
63 | |||
64 | /** |
||
65 | * @var string |
||
66 | */ |
||
67 | protected $stasisApplicationName; |
||
68 | |||
69 | /** |
||
70 | * @param LoggerInterface $logger |
||
71 | */ |
||
72 | 96 | public function __construct(LoggerInterface $logger) |
|
76 | |||
77 | /** |
||
78 | * Connect to ARI and optionally AMI |
||
79 | * |
||
80 | * @param string $ariAddress |
||
81 | * @param string|null $amiAddress |
||
82 | */ |
||
83 | 96 | public function connect($ariAddress, $amiAddress = null) |
|
84 | { |
||
85 | 96 | $this->eventLoop = EventLoop\Factory::create(); |
|
86 | 96 | $this->ariClient = new AriClient($this->eventLoop, $this->logger); |
|
87 | 96 | $this->ariClient->connect($ariAddress); |
|
88 | 96 | $this->wsClient = $this->ariClient->getWsClient(); |
|
89 | 96 | $this->stasisApplicationName = $this->ariClient->getStasisApplicationName(); |
|
90 | |||
91 | 96 | if ($amiAddress !== null) { |
|
92 | 96 | $this->amiClient = new AmiClient($this->ariClient->getWsClient(), $this->eventLoop, $this->logger); |
|
93 | 96 | $this->amiClient |
|
94 | 96 | ->connect($amiAddress) |
|
95 | 96 | ->done(); |
|
96 | 96 | } |
|
97 | 96 | } |
|
98 | |||
99 | /** |
||
100 | * Connect and start the event loop |
||
101 | */ |
||
102 | 36 | public function run() |
|
107 | |||
108 | /** |
||
109 | * Disconnect and stop the event loop |
||
110 | */ |
||
111 | 22 | public function stop() |
|
116 | |||
117 | /** |
||
118 | * @param callable|callable $callback |
||
119 | */ |
||
120 | 36 | public function onStasisStart(callable $callback) |
|
124 | |||
125 | /** |
||
126 | * @param callable|callable $callback |
||
127 | */ |
||
128 | 1 | public function onStasisEnd(callable $callback) |
|
129 | { |
||
130 | 1 | $this->wsClient->on(Event::STASIS_END, $callback); |
|
131 | 1 | } |
|
132 | |||
133 | /** |
||
134 | * @return WebSocket |
||
135 | */ |
||
136 | 3 | public function getWsClient() |
|
140 | |||
141 | /** |
||
142 | * @return EventLoop\LoopInterface |
||
143 | */ |
||
144 | 4 | public function getEventLoop() |
|
148 | |||
149 | /** |
||
150 | * @return LoggerInterface |
||
151 | */ |
||
152 | 2 | public function getLogger() |
|
156 | |||
157 | /** |
||
158 | * @return AriClient |
||
159 | */ |
||
160 | 39 | public function getAriClient() |
|
164 | |||
165 | /** |
||
166 | * @return AmiClient |
||
167 | */ |
||
168 | 2 | public function getAmiClient() |
|
172 | |||
173 | /** |
||
174 | * @return string |
||
175 | */ |
||
176 | 43 | public function getStasisApplicationName() |
|
180 | |||
181 | /** |
||
182 | * @return Applications |
||
183 | */ |
||
184 | 12 | public function applications() |
|
188 | |||
189 | /** |
||
190 | * @return Asterisk |
||
191 | */ |
||
192 | 7 | public function asterisk() |
|
196 | |||
197 | /** |
||
198 | * @return Bridges |
||
199 | */ |
||
200 | 30 | public function bridges() |
|
204 | |||
205 | /** |
||
206 | * @return Channels |
||
207 | */ |
||
208 | 37 | public function channels() |
|
212 | |||
213 | /** |
||
214 | * @return DeviceStates |
||
215 | */ |
||
216 | 7 | public function deviceStates() |
|
220 | |||
221 | /** |
||
222 | * @return Endpoints |
||
223 | */ |
||
224 | 2 | public function endPoints() |
|
228 | |||
229 | /** |
||
230 | * @return Events |
||
231 | */ |
||
232 | 2 | public function events() |
|
236 | |||
237 | /** |
||
238 | * @return Mailboxes |
||
239 | */ |
||
240 | 6 | public function mailboxes() |
|
241 | { |
||
242 | 6 | return $this->ariClient->mailboxes(); |
|
243 | } |
||
244 | |||
245 | /** |
||
246 | * @return Playbacks |
||
247 | */ |
||
248 | 5 | public function playbacks() |
|
252 | |||
253 | /** |
||
254 | * @return Recordings |
||
255 | */ |
||
256 | 6 | public function recordings() |
|
260 | |||
261 | /** |
||
262 | * @return Sounds |
||
263 | */ |
||
264 | 3 | public function sounds() |
|
268 | |||
269 | } |