GithubHelp home page GithubHelp logo

astipcc / freeswitch-esl-php-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lusongcn/freeswitch-esl-php

0.0 0.0 0.0 7 KB

PHP version of freeswitch esl, support any version of PHP (php5, php7, etc.)

PHP 100.00%

freeswitch-esl-php-1's Introduction

This library is based on mod_event_socket'module of freeswitch', and supports all versions of PHP. mod_event_socket is a TCP based interface to control FreeSWITCH. The default values are to bind to 127.0.0.1 port 8021 and the default password is ClueCon

中文文档参考:README-zh.md

Requirements and Installation

You can connect using any version of php, and freeswitch can be either a remote server or a local one.

  • php
  • freeswitch

Quick start

Before using the clone online library, then run the code test demo.php.

git clone 
cd freeswith_php_esl

Run the test code to test:

> php demo.php

FreeSWITCH Version 1.9.0+git~20180619T173242Z~25e9376b29~64bit (git 25e9376 2018-06-19 17:32:42Z 64bit)

API

1、connect(ip,port,password)

Used to connect the freeswitch server and return the result as true or false; the method of use is as follows:

<?php
require_once 'freeSwitchEsl.php';

$freeswitch = new Freeswitchesl();
$connect = $freeswitch->connect("127.0.0.1","8021","ClueCon");
if ($connect) {
	echo "connect success";
}

If the login fails, the error message will be output, and the comment can be removed by itself.

2、api(api comment,args)

The API command is executed by ESL, which returns the result of data execution. If you do not want to wait for data return or asynchronous execution, you can use the following bgapi:

$version = $freeswitch->api("version");
$status = $freeswitch->api("status");
$sofia = $freeswitch->api("sofia status");

More api commands of freeswitch can be executed:

$sofia = $freeswitch->api("show api");

3、bgapi(api comment,args)

Similar to the api comment method, non-blocking mode asynchronous execution:

$originate = $freeswitch->bgapi("originate user/1000 &echo");

4、execute(app,args,uuid)

The execute method is implemented using sendmsg, through which the APP message can be executed:

# playback
$freeswitch->execute("playback","local_stream://moh",$uuid);
# Hang up the phone
$freeswitch->execute("hangup","",$uuid);
# stop detect_speech
$freeswitch->executeAsync("detect_speech","stop",$uuid);

5、executeAsync(app,args,uuid)

The execute method is implemented using sendmsg, through which the APP message can be executed;Similar to execute, only for asynchronous execution:

$freeswitch->executeAsync("playback","local_stream://moh",$uuid);
$freeswitch->executeAsync("hangup","",$uuid);
$freeswitch->executeAsync("detect_speech","stop",$uuid);

6、events(sorts,args)

The event command is used to subscribe to events from FreeSWITCH. You can specify all events monitored on the same line, which should be separated by spaces; sortsis the return data type and args is the monitored event.

$status = $freeswitch->events("plain","ALL");

7、recvEvent()

It is used in conjunction with events(sorts,args), to obtain all data and return the original data of the server.

$received_parameters = $freeswitch->recvEvent();
a、serialize(received_parameters,type)

serialize which returns data in a specified format, is recommended to perform better in the same way as events, which has three types of plain, jsonand xml.

$serialize_info = $freeswitch->serialize($received_parameters,"xml");
b、getHeader(received_parameters,args)

The specified data returned can be retrieved, and empty if it does not exist.

$Event_Name = $freeswitch->getHeader($received_parameters,"Event-Name");

Example:

<?php
require_once 'freeSwitchEsl.php';

$freeswitch = new Freeswitchesl();
$connect = $freeswitch->connect("127.0.0.1","8021","ClueCon");
if ($connect) {
	$status = $freeswitch->events("json","ALL");
	while (true) {
		$received_parameters = $freeswitch->recvEvent();
		if (!empty($received_parameters)) {
			$info = $freeswitch->serialize($received_parameters,"json");
			var_dump($info);
			$Event_Name = $freeswitch->getHeader($received_parameters,"Event-Name");
			echo $Event_Name;
		}
	}
}

8、disconnect()

Disconnect socket between php and freeswitch; it is recommended that it be disconnected after each use.

freeswitch-esl-php-1's People

Contributors

lusongcn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.