Repository navigation
Description
There are plans to simplify the API by removing the Factory and ActionSender and instead replacing them with a simpler AmiClient constructor. In other words, this:
$factory = new Clue\React\Ami\Factory();
$factory->createClient('user:secret@localhost')->then(function (Clue\React\Ami\Client $client) {
$sender = new Clue\React\Ami\ActionSender($client);
$sender->listCommands()->then(function (Clue\React\Ami\Protocol\Response $response) {
var_dump($response);
});
});Could potentially look like this:
$ami = new Clue\React\Ami\AmiClient('user:secret@localhost');
$commands = $ami->listCommands();
var_dump($commands);In line with the upcoming ReactPHP v3, listCommands() would return the list of commands directly, while listCommandsAsync() would return a promise that can be awaited to get the same result.
Internally, the AmiClient would automatically create the underlying connection to Asterisk only when it's actually needed. All actions would be available directly on the AmiClient and incoming events would be emitted on the same instance, so there would be no need for separate Factory, Client and ActionSender classes anymore.
Additionally, we'll probably fire "open" and "close" events as needed (loosely inspired by https://github.com/clue/reactphp-eventsource). Unlike the current version, my idea is to also keep the instance in a usable state even after calling close() on it. Reusing the same instance at a later time makes a lot more sense in long-running applications instead of locking it in an unusable state.
This is obviously a BC break, so this would be part of the next major release. We'd skip v2 and align this with v3 of ReactPHP (https://github.com/orgs/reactphp/discussions/481) to keep version numbers consistent across projects.
The same API discussion also applies to SQLite (clue/reactphp-sqlite#47), Redis (clue/reactphp-redis#118), MySQL (friends-of-reactphp/mysql#147) and others
This would be a big step forward for this project and I'd love to make it happen! More sponsors directly translate to more features like this, so if you or your company would like to see this land, consider becoming a sponsor or reach out to sponsor this feature specifically ❤️
Activity