Serving Configuration with JavaScript
Page needs edits
This page is still a stub based on the JIRA issue FS-9896 provided by Andrey Volk:
[mod_v8] Implement Serving Configuration with JavaScript
Details
- Type: New Feature
- Status:CLOSED
- Priority: Minor
- Resolution:Fixed
- Affects Version/s:1.8
- Fix Version/s:1.8.0
- Component/s:mod_v8
- Labels:
None - CPU Architecture:
x86-64 - Kernel:
Linux - Userland:
GNU/Linux - Distribution:
Debian - Distribution Version:
Debian 8 jessie - Compiler:
gcc - FreeSWITCH GIT Revision:
d28f29594faaa881ab3088e55e01cdce72d6dcfa - GIT Master Revision hash::
d28f29594faaa881ab3088e55e01cdce72d6dcfa
Description
The idea of Serving Configuration feature in JavaScript is that it should act as it is done in LUA:
https://wiki.freeswitch.org/wiki/Mod%5Flua/Serving%5FConfiguration
This becomes available after putting settings into "autoload_configs/v8.conf.xml"
<configuration name="v8.conf" description="Google V8 JavaScript Plug-Ins">
<settings>
<param name="xml-handler-script" value="directory.js"/>
<param name="xml-handler-bindings" value="directory"/>
</settings>
<modules>
<!-- <load module="mod_v8_skel"/> -->
</modules>
</configuration>
Here is an example of how to use it (directory.js):
//---------------------------------------------------------
consoleLog('info', '=== [JS SERVING CONFIGURATION TEST] \===');
consoleLog('info', "v8 version: " + version());
consoleLog('info', "key_name: " + XML_REQUEST["key_name"]);
consoleLog('info', "key_value: " + XML_REQUEST["key_value"]);
consoleLog('info', "section: " + XML_REQUEST["section"]);
consoleLog('info', "tag_name: " + XML_REQUEST["tag_name"]);
consoleLog('info', "user header from params: " + params.getHeader("user"));
console_log('info', "Event:\n" + params.serialize());
XML_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?> \
<document type=\"freeswitch/xml\"> \
<section name=\"result\"> \
<result status=\"not found\" /> \
</section> \
</document>";
//---------------------------------------------------------
The example in action:
freeswitch@Andrey-PC> user_exists id 1000 test.com
2016-12-29 03:20:34.022049 [INFO] directory.js:1 === [JS SERVING CONFIGURATION TEST] \===
2016-12-29 03:20:34.022049 [INFO] directory.js:2 v8 version: 3.24.14
2016-12-29 03:20:34.022049 [INFO] directory.js:4 key_name: name
2016-12-29 03:20:34.022049 [INFO] directory.js:5 key_value: test.com
2016-12-29 03:20:34.022049 [INFO] directory.js:6 section: directory
2016-12-29 03:20:34.022049 [INFO] directory.js:7 tag_name: domain
2016-12-29 03:20:34.022049 [INFO] directory.js:8 user header from params: 1000
2016-12-29 03:20:34.022049 [INFO] directory.js:10 Event:
Event-Name: REQUEST_PARAMS
Core-UUID: 4dc9c48e-56a3-4e70-a057-5dba744b97ef
FreeSWITCH-Hostname: Andrey-PC
FreeSWITCH-Switchname: Andrey-PC
FreeSWITCH-IPv4: 192.168.88.234
FreeSWITCH-IPv6: %3A%3A1
Event-Date-Local: 2016-12-29%2003%3A20%3A33
Event-Date-GMT: Thu,%2029%20Dec%202016%2000%3A20%3A33%20GMT
Event-Date-Timestamp: 1482970833962043
Event-Calling-File: switch_xml.c
Event-Calling-Function: switch_xml_locate_user
Event-Calling-Line-Number: 2109
Event-Sequence: 513
key: id
user: 1000
domain: test.com
2016-12-29 03:20:34.022049 [INFO] mod_v8.cpp:676 Javascript result: [<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="freeswitch/xml">
<section name="result">
<result status="not found"/>
</section>
</document>]
false
Currently working on a pull-request.
Permalink
Andrey Volk added a comment - 28/Dec/16 7:07 PM
A pull request is ready.