Node.js Javascript

From Yate Documentation
(Difference between revisions)
Jump to: navigation, search
(Created page with "This library is intended for use with [https://nodejs.org/ Node.js] Javascript runtime environment. It implements External Module protocol and is suitable for developing e...")
 
 
Line 1: Line 1:
 
This library is intended for use with [https://nodejs.org/ Node.js] Javascript runtime environment. It implements [[External Module]] protocol and is suitable for developing external Yate scripts.
 
This library is intended for use with [https://nodejs.org/ 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 [[Javascript_Engine|Engine]], [[Javascript_Message|Message]], [[Javascript_JSON|JSON]], [[Javascript_File|File]], [[Javascript_Hasher|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).
+
== Installation ==
 
+
== Download ==
+
  
 
Basics of Node.js are outside the scope of this document.  
 
Basics of Node.js are outside the scope of this document.  
  
cd /usr/src
+
  npm install yate-extmodule
git clone https://bitbucket.org/latysheff/node-yate.git
+
  npm install node-yate [-g]
+
  
==Running outside Yate==
+
==Usage==
If you choose to extend your script with Node.js modules, like, for example [https://www.npmjs.com/package/amqp AMQP] protocol, and many more, then you should run it as Yate external script.
+
  
* make script executable
+
===Example===
  chmod a+x myscript.js
+
  const extmodule = require('yate-extmodule')
* put standard bash instruction at the top of the script to indicate program that will run the script
+
  let connection = extmodule.connect({host: '127.0.0.1', port: 5040}, () => {
  #!/usr/bin/node
+
  console.log('connected')
* put script name to extmodule.conf
+
  })
  [scripts]
+
  connection.watch('engine.timer', (message) => {
  myscript.js
+
  console.log('tick', message.time)
 +
})
  
===Quick start example===
+
More examples in 'examples' directory of this module.
#!/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.
+
===Documentation===
 +
See full documentation here: https://www.npmjs.com/package/yate-extmodule

Latest revision as of 07:02, 14 January 2018

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.

Contents

[edit] Installation

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

npm install yate-extmodule

[edit] Usage

[edit] Example

const extmodule = require('yate-extmodule')
let connection = extmodule.connect({host: '127.0.0.1', port: 5040}, () => {
  console.log('connected')
})
connection.watch('engine.timer', (message) => {
  console.log('tick', message.time)
})

More examples in 'examples' directory of this module.

[edit] Documentation

See full documentation here: https://www.npmjs.com/package/yate-extmodule

Personal tools
Namespaces

Variants
Actions
Preface
Configuration
Administrators
Developers