rtckit/esl

FreeSWITCH 事件套接字层 (ESL) 库

0.8.0 2022-01-15 00:41 UTC

This package is auto-updated.

Last update: 2024-09-15 06:45:06 UTC


README

Build Status Latest Stable Version Test Coverage Maintainability License

快速入门

FreeSWITCH 的事件套接字层是一个 TCP 控制接口,它允许开发复杂的动态拨号计划/工作流程。您可以在 FreeSWITCH 网站上了解更多关于其 入站模式 以及其 出站模式 的信息。

此库提供了一种对 ESL 协议的无 I/O 实现方式。

ESL 消息解析

ESL 连接的认证阶段可以总结如下

/* This is a typical FreeSWITCH ESL server greeting */
$response = \RTCKit\ESL\Response::Parse("Content-Type: auth/request\n\n");

echo 'A server sends: ' . get_class($response) . PHP_EOL;

/* Since we've been told to authenticate, let's prepare our auth request */
$request = \RTCKit\ESL\Request::parse("auth ClueCon\n\n");

echo 'A client responds with: ' . get_class($request) . '; ';
echo 'password: ' . $request->getParameters() . PHP_EOL;

/* If our secret is correct, the ESL server should confirm that */
$followup = \RTCKit\ESL\Response::parse("Content-Type: command/reply\nReply-Text: +OK accepted\n\n");

echo 'Then the server replies with: ' . get_class($followup) . '; ';
echo ($followup->isSuccessful() ? 'Success!' : 'Yikes!') . PHP_EOL;

ESL 消息渲染

反向过程,渲染为字符串,是直接的

$response = new \RTCKit\ESL\Response\AuthRequest;

echo 'A server sends: "' . $response->render() . '"' . PHP_EOL;

$request = new \RTCKit\ESL\Request\Auth;
$request->setParameters('ClueCon');

echo 'A client responds with: "' . $request->render() . '"' . PHP_EOL;

$followup = new \RTCKit\ESL\Response\CommandReply;
$followup->setHeader('reply-text', '+OK accepted');

echo 'Then the server replies with: "' . $followup->render() . '"' . PHP_EOL;

ESL 连接

尽管这个库是 I/O 独立的,但它提供了一个 接口基类;由于 ESL 在 TCP 上运行,这是一种面向流的传输,因此有必要在更高层的库中处理消息帧。实现项目只需在输入可用时调用 ConnectionInterface::consume() 方法,并实现一个 ConnectionInterface::emitBytes() 方法,该方法执行相应的 I/O 特定的写入操作。

连接构造函数需要一个 $role 参数,它必须是以下之一

  • ConnectionInterface::INBOUND_CLIENT 供 ESL 客户端连接到 FreeSWITCH ESL 服务器使用;
  • ConnectionInterface::OUTBOUND_SERVER 供在出站模式下连接到 FreeSWITCH 的 ESL 服务器使用;

其他两种选项较少见

  • ConnectionInterface::INBOUND_SERVER 用于伪装 FreeSWITCH ESL 服务器;
  • ConnectionInterface::OUTBOUND_CLIENT 用于在出站模式下伪装 FreeSWITCH 连接到远程 ESL 端点;

后两种角色可用于测试套件、实现消息中继、安全研究等。请注意,入站和出站术语相对于 FreeSWITCH 端点(与 mod_event_socket 命名法相匹配)。

需求

RTCKit\ESL 与 PHP 7.4+ 兼容,没有外部库和扩展依赖。

安装

您可以使用 Composer 将库作为项目依赖项添加

composer require rtckit/esl

如果您仅在开发期间需要此库,例如在您的测试套件中使用,那么您应将其添加为开发依赖项

composer require --dev rtckit/esl

测试

要运行测试套件,请克隆此存储库,然后使用 Composer 安装依赖项

composer install

然后,转到项目根目录并运行

composer phpunit

静态分析

为了确保代码质量高,RTCKit\ESL 使用 PHPStanPsalm

composer phpstan
composer psalm

许可

MIT,请参阅 LICENSE 文件

致谢

  • FreeSWITCH,FreeSWITCH 是 Anthony Minessale II 的注册商标

贡献

可以通过问题跟踪器提交错误报告(以及小补丁)。对于重大补丁,推荐通过分支仓库并提交Pull Request的方式进行。