[asterisk-gui] Contributing to the GUI

Brandon Kruse bkruse at digium.com
Thu Jun 14 13:27:10 CDT 2007


Well,

since javascript (as you should know :D ) does not wait for one
thing to execute before doing another, you need a callback function to
get the response back from manager.

I should have examples of this in graphs.html, I believe.

Basically, in other languages, if I have (php for example)

function woot() {
sleep(10);
echo "done with function";
return true;
}

echo "hello, we are about to wait 10 seconds, then echo out";
woot();


You would wait 10 seconds then see the "done with function"

But with javascript, its all clientside and executed in order, thats
why there is NO sleep function in javascript, and the reason we use
setTimeout() and setInterval() so very often.

To combat this (and I love how jscript executes like this) you use callbacks.

for example

var tmp_command = "sh " + asterisk_scriptsFolder + "graphs.sh cpu > /var/lib/asterisk/static-http/config/graphs/data_cpu.html";
parent.astmanEngine.run_tool(tmp_command, function(t) { alert("response was " + t); });

So, run_tool callsback function(t) with the data it got back from manager.

A better example of this is in astman.js I added the cliCommand function, for even easier use of action: command

        this.cliCommand = function(cmd, callback) {
                var opt = {
                        method: 'get',
                        asynchronous: true,
                        onSuccess: function(originalRequest) {
                                if (callback)
                                        callback(originalRequest.responseText);
                        },
                        onFailure: function(t) {
                                gui_alert("Tool Error: " + t.status + ": " + t.statusText);
                        }
                };
                var tmp;
                opt.parameters="action=command&command=" + encodeURIComponent(cmd);
                tmp = new Ajax.Request(this.url, opt);
        };


so....

parent.astmanEngine.cliCommand("core show channels", function(response) { 
    alert("response was " + response);
    });


and if you look at this.cliCommand, if callback is set, it responds back to that function with the responsetext from manager.


Pari actually made a function somewhere to stripoff and parse the response: follows  success, and all that.


Callbacks Callbacks Callbacks!!!

dont think 
var response = parent.astmanEngine.cliCommand("core show channels");    <---NO NO NO 

Callbacks Callbacks Callbacks.


I basically just typed out the lecture pari gave to me, so props to him :]

Hope all this helps! :]

-bkruse

(and kevin, if your reading this, it does hurt to smile like this  ;]  )
----- Original Message -----
From: "Leonardo Andrés Gallego" <lag.asterisk at gmail.com>
To: "Asterisk GUI project discussion" <asterisk-gui at lists.digium.com>
Sent: Thursday, June 14, 2007 10:44:14 AM (GMT-0800) America/Tijuana
Subject: Re: [asterisk-gui] Contributing to the GUI

On 6/11/07, bkruse <bkruse at digium.com> wrote:
>
> Rawman is a way to execute all the manager commands
> over http through asterisk's http webserver. Keep in mind
> that you have to uriencode everything as its just like an ajax
> call, but all of that is already taken care of for you. astman.js
> would be a great place to start, and there is a TON of sample
> code in the GUI of where we call asterisk. We have to get config
> files and the monitoring of channels is done through calling
> astman. Usually what happens is you can call alot of functions
> such as updating extensions in extensions.conf, that is all done
> through building the configuration file through manager.
>
> Usually you call a function from the html pages ( a function that
> you can access from including astman.js ) and those functions
> access the interface directly, and provide a callback for response
> text from the manager.
>
> My advice is to start messing around with the manager interface
> (as there is TONS and TONS of stuff you can do, even with monitoring
> events and storing them in a global array, not the best idea, but its
> possible!!)
> You can see the different ways to originate a call, hangup a call with
> the given channel id, transfer calls....etc etc.
>

Thanks for all the info.

We are already messing around with it :)
And we already run into a couple of problems, which we don't know if
they are bugs or what.

Here are the couple of issues:

1) action=command
Is it working? we cant get it to output anything we send to it.

2) action=monitor

According to
http://www.voip-info.org/wiki/index.php?page=Asterisk+Manager+API+Action+Monitor
The command should start monitoring to a wav file defined in the parameters.

The thing is, although the channel gets monitored (we are running the
commands directly through http and get the "Response Success"
message), the file is always 44 bytes long, and doesn't increase its
size, no matter how long the channel is open or if there is any
conversation on it.

Here is how we are calling it:

/rawman?action=monitor&channel=SIP%2Fx7062618529-643d&file=archivo-monitor.wav

Is something wrong calling it like this?


Update:

I just realized that if i make a call and don't answer the other end,
so the voicemail pops, and monitor the channel, i get the recording.
So the above command seems to be OK, but something must be missing...
any ideas?


> I did not say it would be easy, if you do not know javascript, it will
> get hard fast. Most of the js is somewhat optimized, and pari is a
> genius, but we are always open for questions. Any question I cannot
> answer, he can.
>
> So keep working hard, start submitting some sample code, and look
> at the code that the gui is already made up. Find a page you like, and
> start picking stuff out.....stay on the mailing list, I will keep responding
> with as much help as I can. :]
>
> -bkruse
>
> Leonardo Andrés Gallego wrote:
> > Hi Brandon,
> >
> > On 6/9/07, Brandon Kruse <bkruse at digium.com> wrote:
> >> Hey!
> >>
> >> Its great to see some contributors for the GUI.
> >>
> >>
> >> Use those lines for guidelines and fill out a disclaimer and we can
> >> readily accept and filter code from you.
> >
> > Great! We will begin checking the code before submitting it.
> >
> >>
> >>
> >> You can use the bug tracker (http://bugs.digium.com)
> >>
> >> Or contact me and pari directly (bkruse at digium.com and
> >> pari at digium.com) for major
> >> patches and ideas.
> >>
> >> Of course you can also use this mailing list to bounce ideas and
> >> implementations.
> >>
> >
> > The current idea is to expand to the functionality named in Ariel's
> > mail, we need to make the recording of a call an easy task, and doing
> > so through the GUI using what is already available in the "Active
> > Channels" submenu would work nicely.
> >
> >>
> >>
> >> Thank you!
> >>
> >> -brandon
> >>
> >>
> >> P.S.
> >>
> >> I can give you some tips on the API that is currently implemented and
> >> how things are done.
> >>
> >> Most of it is not documented, but there are a lot of live examples in
> >> the code.
> >>
> >
> > We would really appreciate some tips, as we cant figure a way to
> > extend the "action" command to include the actions we need.
> >
> > We don't understand where is "rawman", and how do you call it to make
> > it execute the code in the AMI (Asterisk manager interface). Is rawman
> > extensible? The commands used by it, are related to the AMI?
> >
> > Like in:
> >
> > We need to monitor (as in record) a channel. From 'manager show
> > commands', I see there are two commands for this, the "monitor" and
> > "stopmonitor" commands, which should do what i need.
> >
> > So the idea would be to implement an action=record which would call
> > the monitor AMI command, and allow a recordstop or something
> > equivalent to stop it.
> >
> > Can you, or Pari, give us a tip on where to look to start implementing
> > this?
> >
> > We read everything related to AJAM/AMI we could find, but there is not
> > much really useful to extend them, just to use what is already
> > available.
> >
> > Regards and thanks in advance,
> > Leonardo
> >
> >
> > ps. Here are some of the sources we have been checking:
> > http://www.voip-info.org/wiki-Asterisk+manager+API
> > http://www.voip-info.org/wiki/index.php?page=Asterisk+Manager+API+Action+Monitor
> >
> > http://www.voip-info.org/wiki/view/Aynchronous+Javascript+Asterisk+Manager+%28AJAM%29
> >
> > http://www.asterisknow.org/developers/gui-guide
> >
> >>
> >> ----- Original Message -----
> >> From: "Ariel Hernan Curiale" <curiale at gmail.com>
> >> To: asterisk-gui at lists.digium.com
> >> Sent: Friday, June 8, 2007 2:40:03 PM (GMT-0800) America/Tijuana
> >> Subject: [asterisk-gui] Contributing to the GUI
> >>
> >> Hello everyone,
> >>
> >> We are working on several deployments of Asterisk (including the GUI)
> >> and we
> >> need to make a couple of changes, actually, there are a couple of
> >> additions and some fixes for now.
> >>
> >> Here are the features we are currently working on:
> >>
> >> 1) The "Active Channels" submenu.
> >>
> >> a) We already have the "Transfer" and "Hangup" working, which were
> >> broken. (If you want these lines of code, contact me, as I don't know
> >> yet what are the coding contribution rules and ways)
> >>
> >> b) We are working on a extension to this page, we want to be able to
> >> record a channel (or more), in the way MixMonitor allows via CLI.
> >> To accomplish this, we were thinking in using some of the AJAM/AMI
> >> calls.
> >> The idea is to implement an "action=record" function (just like
> >> action=status,
> >> action=command, etc.) or similar, but we need some details on how to
> >> access the API and expand it. Is this possible? Is there
> >> documentation on this?
> >>
> >>
> >> Also, are there any requirements for code contribution?
> >> Besides this:
> >> http://asterisk.org/developers/coding-guidelines
> >> http://asterisk.org/developers/bug-guidelines
> >> http://asterisknow.org/developers/gui-guide
> >>
> >>
> >> Right now, its a 3 people team, any of us might send an email to the
> >> list regarding the same issues.
> >>
> >> Just in case, here we are:
> >>
> >> Ariel Curiale
> >> Alexis Tcach
> >> Leonardo A. Gallego
> >>
> >> Regards from Argentina.
> >>
> >>
> >>
> >> --
> >>     .~.
> >>    / V \
> >>   / /  \ \    Salu2 Ariel
> >>  / (    ) \
> >>  ^^-^^
> >>  ---------------------
> >> _______________________________________________
> >> --Bandwidth and Colocation provided by Easynews.com --
> >>
> >> asterisk-gui mailing list
> >> To UNSUBSCRIBE or update options visit:
> >>    http://lists.digium.com/mailman/listinfo/asterisk-gui
> >>
> >> _______________________________________________
> >> --Bandwidth and Colocation provided by Easynews.com --
> >>
> >> asterisk-gui mailing list
> >> To UNSUBSCRIBE or update options visit:
> >>    http://lists.digium.com/mailman/listinfo/asterisk-gui
> >>
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > --Bandwidth and Colocation provided by Easynews.com --
> >
> > asterisk-gui mailing list
> > To UNSUBSCRIBE or update options visit:
> >    http://lists.digium.com/mailman/listinfo/asterisk-gui
>
> _______________________________________________
> --Bandwidth and Colocation provided by Easynews.com --
>
> asterisk-gui mailing list
> To UNSUBSCRIBE or update options visit:
>    http://lists.digium.com/mailman/listinfo/asterisk-gui
>


--
Leonardo Andrés Gallego
http://www.hombrepac.com.ar


-- 
Leonardo Andrés Gallego
http://www.hombrepac.com.ar



More information about the asterisk-gui mailing list