-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01-fscli.php
More file actions
61 lines (47 loc) · 1.71 KB
/
01-fscli.php
File metadata and controls
61 lines (47 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
declare(strict_types = 1);
namespace RTCKit\React\ESL\Examples;
error_reporting(-1);
require(__DIR__ . '/../vendor/autoload.php');
use Clue\React\Stdio\Stdio;
use RTCKit\ESL;
use RTCKit\React\ESL\InboundClient;
$stdio = new Stdio;
$client = new InboundClient('127.0.0.1', 8021, 'ClueCon');
$client
->connect()
->then(function (InboundClient $client) {
$request = new ESL\Request\Api;
$request->setParameters('switchname');
return $client->api($request);
})
->then(function (ESL\Response $response) use ($client, $stdio) {
$stdio->setPrompt('freeswitch@' . trim($response->getBody()) . '> ');
$client->log();
$stdio->on('data', function ($line) use ($client, $stdio) {
$line = trim($line);
if (($line === 'exit') || ($line === '...')) {
echo PHP_EOL;
exit(0);
}
$client->api((new ESL\Request\Api)->setParameters($line))
->then (function (ESL\Response $response) use ($stdio) {
$stdio->write($response->getBody() . PHP_EOL);
});
});
$client->on('log', function ($log) use ($stdio) {
$stdio->write($log->getBody());
});
$client->on('disconnect', function (?ESL\Response $response = null) use ($stdio) {
if (!isset($response)) {
echo PHP_EOL . 'FreeSWITCH disconnected unexpectedly' . PHP_EOL;
exit(1);
}
echo PHP_EOL . 'FreeSWITCH disconnected gracefully' . PHP_EOL;
exit(0);
});
})
->otherwise(function (\Throwable $t) {
echo 'Yikes! ' . $t->getMessage() . PHP_EOL;
exit(1);
});