freeswitch esl using node js - node.js

I am implementing freeswitch ESL using nodejs, for which i am using modesl module, it works fine and i can call dialplan tools using the execute function.
However execute function is an asynchronous implementation in modesl module of nodejs.
What i need is a synchronous call so that when i call execute function the execution should wait till freeswitch finishes executing that application.
In the below code sample i get the output "ivr finished" before the playback gets finished.
exports.process_ivr = function (conn, id)
{
conn.execute('answer');
conn.execute('playback','/root/before.wav');
console.log('ivr finished');
};
As per modesl there is no asynchronous way of calling freeswitch commands, is there any other way to implement this using nodejs?

Try this.
conn.execute('answer',function(){
conn.execute('playback','/root/before.wav',function(){
console.log('ivr finished');
});
});

Related

gRPC with synchronous calls in node application

I have an application which implements multiple gRPC servers.
The client side is implemented in nodeJS.
The client invokes multiple gRPC calls one after another.
Since in nodeJS, channel is created per ServiceClient , how to ensure that the first gRPC call is complete before the second gRPC call is invoked.
Is there a way to specify multiple ServiceClient to use same channel for all the communication ?
Is there a way to use synchronous gRPC calls in nodeJS ?
Node gRPC does not have synchronous calls. As with any asynchronous Node operation, you can ensure that two calls are made sequentially by invoking the second one in the completion callback of the first.
And no, there is not currently an API to have multiple client objects use the same channel.
I noticed this question is quite old, answered just in case someone still needs it in the future.
YES, call the second gRPC after the end event. Below is the client example.
const target = "localhost:50055";
const client = new proto.APINAME(target, grpc.credentials.createInsecure());
const call = client.APIMETHOD(metadata);
call.on("data", function(data) {
console.log(data);
});
call.on("end", function() {
// call the second gRPC
});

In Meteor, is Meteor.wrapAsync blocking other calls?

In Meteor JS code, I am using HTTP.get method to call server inside a method. I must return result to client, so I am wrapping this function with
Meteor.wrapAsync to get a Synchronous function.
var httpSync = Meteor.wrapAsync(HTTP.get, this);
var result = httpSync(myUrl);
My question is - Will Meteor.wrapAsync(AsyncFunction) block other requests? Will it affect parallel execution of multiple requests?
It won't block the entire server. Meteor uses the fibers package to provide "synchronous looking" functions which don't block the entire server.
However, it will block other methods from the same user. If you want other methods from that user to run simultaneously, call this.unblock() inside the method:
On the server, methods from a given client run one at a time. The N+1th invocation from a client won't start until the Nth invocation returns. However, you can change this by calling this.unblock. This will allow the N+1th invocation to start running in a new fiber.
By the way, you don't need to Meteor.wrapAsync HTTP.get, since it can already be used synchronously. wrapAsync is intended to be used with external libraries that are not designed for Meteor.

Synchronization in Firefox OS (B2G)

I would like to stop a function in order to wait the end of another section of code.
Is there in Firefox OS some synchronization method like wait() and notify() in Java?
Thanks
JavaScript doesn't has this concept, but generally speaking uses callbacks (function pointers). A bit like the anonymous classes in Java. For example, I'm making a call to a web server:
function callToWebServer(url, doneCallback) {
// do all kinds of magic, waiting for the web server to reply etc.
// when done:
doneCallback();
}
Now using it via:
callToWebServer(function() {
// this is executed after the call to the web server succeeded
});
alert(1); // this is executed straight away
We can never wait, as JS is a single-thread execution environment. All code is written async.

Using edge.js is it possible for the .Net C# module to call the node.js part of the process, i.e. do the reverse call?

You can see the interop model for going from Node.js -> C#, here.
What I want to know is, can the C# code then make a call to a method in the Node.js part of the process from the C#, before returning?
Imagine if you had a call, like
var webApi = edge.func('/MyDotNetApi.csx');
webApi(function (error, result) { log.('api started'); });
where the MyDotNetApi.csx returns, but leaves a socket listener thread running to handle HTTP requests. Now, if the Node.js part of the process holds (ever changing) information which the .Net code needs to access for inclusion in its HTTP responses, can it somehow ask Node.js for it?
Calling back Node.js from C# with Edge.js is possible and documented.

Communicating with MongoDB from TypeScript using NodeJS

As far as I understand , one have to use async callbacks for all IO in NodeJS (?)
I'm trying to wrap my head around this example code provied by Microsoft.
They start with a db.open(function() {});
That is, no code is provided in the callback of "open"..
So all code that interacts with the db object will execute before open has completed.
How can their sample work?
For me in my own code to be able to write any data to the DB I have to provide the writing code as a callback to the db.open function.
another weird problem when running my code, after the data is written, the nodejs server doesnt exit even though all user code have completed.
Why is that?

Resources