Skip to main content

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:

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](http://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](http://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](http://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

Permalink
andywolkAndrey Volk added a comment - 28/Dec/16 7:07 PM

A pull request is ready.