Node.js Javascript

From Yate Documentation
Jump to: navigation, search

This library is intended for use with Node.js Javascript runtime environment. It implements External Module protocol and is suitable for developing external Yate scripts. It also partly implements Yate native Javascript objects like Engine, Message, JSON, File, Hasher, etc, exactly the same way as javascript.yate module does. This feature makes possible to run native Yate JS scripts externally, taking advantage of existing debuggers and IDEs.

Warning! Library is currently alpha version. No detailed documentation yet. Use best guesses, and in case of doubt look into library code (it is not too complicated).

Contents

Download

Basics of Node.js are outside the scope of this document.

cd /usr/src
git clone https://bitbucket.org/latysheff/node-yate.git
npm install node-yate [-g]

Running outside Yate

If you choose to extend your script with Node.js modules, like, for example AMQP protocol, and many more, then you should run it as Yate external script.

  • make script executable
chmod a+x myscript.js
  • put standard bash instruction at the top of the script to indicate program that will run the script
#!/usr/bin/node
  • put script name to extmodule.conf
[scripts]
myscript.js

Quick start example

#!/usr/bin/node
var engine = require("node-yate");
Engine = engine.Engine;
Message = engine.Message;
Engine.debugMessages(false);
Engine.init();
Engine.connection.on("ready",function(){
   Engine.include("./yate/eliza.js")
});

Using pure extmodule approach

If you don't want to support any compatibility with internal Yate Javascript, you actually don't need implementation of Yate JS objects. Then you can use only the core of the library (YateConnection object).

#!/usr/bin/node
var extmodule = require("node-yate");
var YateConnection = extmodule.YateConnection;
var connection = new YateConnection();
connection.on("connected",function() {
   //...
   var message = connection.createMessage("my.message");
   message.myparam = "myvalue";
   message.dispatch()
});
connection.on("incoming",function(message) {
   // ...
   message.acknowledge()
});
connection.connect();

More examples and explanations: https://bitbucket.org/latysheff/node-yate/.

Running inside Yate

As long as the script uses only Yate's Javascript subset of functions, it is possible to load it back as Yate internal javascript by running "javascript load myscript.js" or putting to javascript.conf:

[scripts] 
myscript.js

Message.dispatch() problem

Due to Node.js pure async nature, synchronous msg.dispatch() method is not implemented, but you can use msg.enqueue() with callback:

msg.enqueue(function(msg){
   // read returned message parameters
})

Note! This relates to Yate Javascript dispatch(). Don't mix with extmodule's message.dispatch() (see above), which actually only enqueues message, not waiting for the answer.

Personal tools
Namespaces

Variants
Actions
Preface
Configuration
Administrators
Developers