FreeSWITCH Event Socket Layer library for PHP

Overview

FreeSWITCH Event Socket Layer library for PHP

Build Status Latest Stable Version Test Coverage Maintainability License

Quickstart

FreeSWITCH's Event Socket Layer is a TCP control interface enabling the development of complex dynamic dialplans/workflows. You can learn more about its inbound mode as well as its outbound mode on the FreeSWITCH website.

This library provides an I/O agnostic implementation of the ESL protocol.

ESL Message Parsing

The authentication stage of an ESL connection can be summarized as follows:

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;">
/* 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 Message Rendering

The reverse procedure, rendering to string, is straightforward:

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;">
$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 Connection

Although this library is I/O independent, a Connection interface and base class are being provided; since ESL runs over TCP, a stream oriented transport, it behooves to handle the message framing in a higher level library. An implementing project would simply invoke the ConnectionInterface::consume() method when input is available and would implement a ConnectionInterface::emitBytes() method which performs the corresponding I/O-specific write operations.

The Connection constructor requires a $role argument, which must be one of the following:

  • ConnectionInterface::INBOUND_CLIENT to be used by ESL clients connecting to FreeSWITCH ESL servers;
  • ConnectionInterface::OUTBOUND_SERVER to be used by ESL servers FreeSWITCH connects to in outbound mode;

The other two options are less common:

  • ConnectionInterface::INBOUND_SERVER to impersonate a FreeSWITCH ESL server;
  • ConnectionInterface::OUTBOUND_CLIENT to impersonate FreeSWITCH connecting to a remote ESL endpoint in outbound mode;

The latter two roles can be useful in test suites, implementing message relays, security research etc. Please note the inbound and outbound terms are relative to the FreeSWITCH endpoint (matching the mod_event_socket nomenclature).

Requirements

RTCKit\ESL is compatible with PHP 7.4+ and has no external library and extension dependencies.

Installation

You can add the library as project dependency using Composer:

composer require rtckit/esl

If you only need the library during development, for instance when used in your test suite, then you should add it as a development-only dependency:

composer require --dev rtckit/esl

Tests

To run the test suite, clone this repository and then install dependencies via Composer:

composer install

Then, go to the project root and run:

composer phpunit

Static Analysis

In order to ensure high code quality, RTCKit\ESL uses PHPStan and Psalm:

composer phpstan
composer psalm

License

MIT, see LICENSE file.

Acknowledgments

  • FreeSWITCH, FreeSWITCH is a registered trademark of Anthony Minessale II

Contributing

Bug reports (and small patches) can be submitted via the issue tracker. Forking the repository and submitting a Pull Request is preferred for substantial patches.

You might also like...
Lite & fast micro PHP abuse library that is **easy to use**.

Utopia Abuse Utopia framework abuse library is simple and lite library for managing application usage limits. This library is aiming to be as simple a

PHP Coroutine HTTP client - Swoole Humanization Library

PHP Coroutine HTTP client - Swoole Humanization Library

XStatic is a PHP library for enabling static proxy interfaces

XStatic is a PHP library for enabling static proxy interfaces—similar to Laravel 4+ "Facades"—but with any PHP project. XStatic was created by Jeremy Lindblom.

Slim PHP static proxy library

#SlimStatic Slim PHP static proxy library. Contents About Usage API Customizing License About SlimStatic provides a simple static interface to various

Software for an e-book library, in Bulgarian only. Based on Symfony3 and Doctrine 2.

chitanka.info core Това е уеб софтуер, който задвижва „Моята библиотека“. Изграден е с помощта на Symfony3, Doctrine 2 и много други прекрасни свободн

PHPneeds library (classes) package.
PHPneeds library (classes) package.

PHPneeds is a lightweight non-MVC PHP library for quickly start a project. About PHPneeds library (classes) package. Please use with PHPneeds base pro

Library for Open Swoole extension

Open Swoole Library This library works with Open Swoole since release version v4.7.1. WIP Table of Contents How to Contribute Code Requirements Develo

PSR-7 HTTP message library

PSR-7 Message Implementation This repository contains a full PSR-7 message implementation, several stream decorators, and some helpful functionality l

This repository contains a library of optional middleware for your Slim Framework application

Slim Framework Middleware This repository contains a library of optional middleware for your Slim Framework application. How to Install Update your co

Releases(v0.8.0)
Owner
rtckit
:rocket: Real-Time Communications Projects
rtckit
An asynchronous event driven PHP socket framework. Supports HTTP, Websocket, SSL and other custom protocols. PHP>=5.3.

Workerman What is it Workerman is an asynchronous event-driven PHP framework with high performance to build fast and scalable network applications. Wo

walkor 10.2k Dec 31, 2022
PHP HI-REL SOCKET TCP/UDP/ICMP/Serial .高可靠性PHP通信&控制框架SOCKET-TCP/UDP/ICMP/硬件Serial-RS232/RS422/RS485 AND MORE!

OHSCE高可靠性的PHP通信框架. Hey!I'm come back! 官方网站:WWW.OHSCE.ORG WWW.OHSCE.COM 最新版本V0.2.0.2 2017-05-10 开发者QQ群:374756165(新2016-09) 捐助: http://www.ohsce.com/ind

null 212 Dec 26, 2022
PHP Web Socket server

Important ⛔️ This project is no longer maintained ⛔️ We urge you to look for a replacement. Description WebSocket Server and Client library for PHP. W

Chris Tanaskoski 346 Nov 8, 2022
A server side alternative implementation of socket.io in PHP based on workerman.

phpsocket.io A server side alternative implementation of socket.io in PHP based on Workerman. Notice Only support socket.io v1.3.0 or greater. This pr

walkor 2.1k Jan 6, 2023
PHP Websocket Server that is compatible with socket.io

PHP SocketIO Server PHP Websocket Server that is compatible with socket.io So far the function use in this package is almost same with the naming in s

Cydrick Nonog 7 Dec 21, 2022
Event-driven, non-blocking I/O with PHP.

Event-driven, non-blocking I/O with PHP. ReactPHP is a low-level library for event-driven programming in PHP. At its core is an event loop, on top of

ReactPHP 8.5k Dec 26, 2022
Kit is a lightweight, high-performance and event-driven web services framework that provides core components such as config, container, http, log and route.

Kit What is it Kit is a lightweight, high-performance and event-driven web services framework that provides core components such as config, container,

null 2 Sep 23, 2022
🚀 Coroutine-based concurrency library for PHP

English | 中文 Swoole is an event-driven asynchronous & coroutine-based concurrency networking communication engine with high performance written in C++

Swoole Project 17.7k Jan 8, 2023
🐘🎓📝 PHP Library providing an easy way to spellcheck multiple sources of text by many spellcheckers

PHP-Spellchecker Check misspellings from any text source with the most popular PHP spellchecker. About PHP-Spellchecker is a spellchecker abstraction

Philippe SEGATORI 257 Jan 2, 2023
PHP spell check library

php-speller PHP spell check library. Currently supported backends: aspell; hunspell; ispell. Installation With Composer: $ composer require mekras/php

Михаил Красильников 66 Oct 17, 2022