Yate Community Forum

Yate server => Other Yate server issues => Topic started by: evgeniy on June 30, 2016, 08:33:39 AM

Title: javascript routing, redis
Post by: evgeniy on June 30, 2016, 08:33:39 AM
How can I request redis from javascript routing script? Or do http request?
Do I need to patch javascript.cpp ?

Also JSON object is not defined in javascript routing script, how can I enable it?
http://docs.yate.ro/wiki/Javascript_Reference
Title: Re: javascript routing, redis
Post by: marian on July 01, 2016, 01:13:56 AM
If you need database access:
See 'database' message description
http://docs.yate.ro/wiki/Database
Yate has support for mysql, postgresql, sqlite

JSON:
var obj = {};
var str = JSON.stringify(obj);
obj = JSON.parse(str);

Title: Re: javascript routing, redis
Post by: evgeniy on July 01, 2016, 01:51:09 AM
Thank you for help.

Regarding JSON, I tried exacly your example, but it fails.
<JsCode:WARN> Evaluator error: Function 'JSON.stringify' call failed in routing.js:2:
Code: [Select]
var obj = {};
var str = JSON.stringify(obj);
obj = JSON.parse(str);

Looks like I dont have JSON at all, any call fails.
I Tried this:
Code: [Select]
Engine.output("JSON module: " + JSON);
Engine.output("File module: " + File);

and get output:
Code: [Select]
JSON module:
File module: [object File]
Title: Re: javascript routing, redis
Post by: marian on July 01, 2016, 02:42:39 AM
JSON support was added in 2014.
Unless you redefined the JSON object the example should work (I tested it).
You don't have to create a JSON object.
The following will lead to failure:
var j = new JSON;
j.stringify(some_object);

You should update to latest svn version anyway.