Can app receive key event in background?

Community based support for the Digium Phone Application Programming Interface (API).

Moderators: jwitt, sruffell, malcolmd, Moderator

Can app receive key event in background?

Postby eartaza » Thu Apr 11, 2013 9:50 pm

When the app is running in foreground, it can receive all keys events, but the line 1 key is always linked to close the app.

In background app can not be closed by line 1 key, but does not receive any key events.

So, is there a way to avoid closing the app with line 1 key when in foreground ?
or a way to receive events in background.

All that is for just a simple situation.

Assumes that Digium phones are made ​​thinking asterisk (although they can be used with any other SIP server), Asterisk has special features like blind transfer, that can by used sending some dtmf (define in config)

How do I configure digium phone to send that dtmf when I press transfer hardkey?
I know the answer... I can't not doit

So I wana make an app, that take digium control, and avoid normal operation of the phone when in calling. Allowing me to send whatever I want in response to user action.

But, when my app is running, user can close it by presing line 1 key, I need to avoid that.

Or I need to receive key and calling event in background

How can I do that ?
eartaza
Newsterisk
 
Posts: 2
Joined: Wed Apr 10, 2013 1:31 am

Re: Can app receive key event in background?

Postby sruffell » Fri Apr 12, 2013 10:42 am

Basically, what you want to do is allow your app to continue running in the background. There is an attribute of the digium.app object that will allow you to control whether your application shuts down when running in the foreground window is closed. digium.app.exitAfterBackground. Set this to false to avoid closing the app when the line 1 key is pressed.

Look at startup.js lines 2-3 in the bigclock demo for an example. You can also look in the callerid for an example of how an app running in the background can then shut itself down by setting exitAfterBackground to true and then backgrounding itself.
sruffell
Oldsterisk
 
Posts: 200
Joined: Fri Jan 07, 2011 2:02 pm

Re: Can app receive key event in background?

Postby eartaza » Sun Apr 14, 2013 7:45 am

Thans sruffell for info, but that's solve only part of the situation.

Once my app is running in bacground, it does not receive key events anymore, until it goes to forground again.

That's why my first question. How to make my app receiving key events in background.

If that is not posible, my app should never go to background. It must be always in foreground to receive keys events. And while be in foreground I must remove line1 function to avoid closing the app.

My goal is simple, when I answer a call, I want to control the key action,
If I press "tranfer" key, I DONT WANT phone start transfer by itself, i just want phone send some DTMF to asterisk server, to let asterisk makes the transfer.

How can I avoid phone transfer normal operation, letting asterisk do it for us?

Why I wana do that...? easy

asterisk transfer (blind) work this way

1. answer the call
2. send asterisk config dtmf requesting transfer ( # by dafault )
3. dial the number

automatically asterisk do the transfer

phone transfer way

1. answer the call
2. press transfer
3. dial the number
4. press trabsfer again

I dont like to make things twice, If I press transfer is to make the transfer, I don need to press transfer again after dial the number.

If we move to attended transfer is again easier using asterisk way

1. answer the call
2. press transfer
3. dial the number
4. ask to person for receive a call

5.a if person accepts the call, just hangup and asterisk do the transfer without press any other phone key

5.b if person does not receive the call, just wait until he or she hangs up, and asterisk rcover the calling for me.

As you can see, asterisk way is more intuivive that phone way, so, I wana phone works using asterisk transfer functions, not the phone features.

I want to hook key events to send transfer dtmf keydcodes to asterisk when user press keys.

If my app is in background, it does not respond to key pressing, and phone will made transfers by its features (badly)
eartaza
Newsterisk
 
Posts: 2
Joined: Wed Apr 10, 2013 1:31 am

Re: Can app receive key event in background?

Postby sruffell » Mon Apr 15, 2013 8:02 am

Ok, I think I understand now, and I'm not aware of anyway to either receive key events in the background or disable the LINE1 key (which closes a foreground app window).

About the closest I can get is to have the apps bring themselves back to the foreground if the LINE1 key is pressed.

So in the following snippet, an application says that it wants to run in the background, and then if the app is being placed in the background (because the user pressed the line 1 key) it schedules a call to digium.foreground() to bring itself back to foreground immediately. This unfortunately, still results in a flash of the screen as the app is placed momentarily in the background.

Code: Select all
var app = require('app');
app.init();
var util = require('util');
var screen = require('screen'); screen.clear();
var hello = new Text(0, 0, window.w, Text.LINE_HEIGHT, 'Block Close');
window.add(hello);

digium.app.exitAfterBackground = false;

var prevent_background = function() {
    util.debug('Trying to go to the background');
    setTimeout(digium.foreground, 1);
};

digium.event.observe({
    'eventName'     : 'digium.app.background',
    'callback'      : prevent_background
});
sruffell
Oldsterisk
 
Posts: 200
Joined: Fri Jan 07, 2011 2:02 pm


Return to Digium Phone API

Who is online

Users browsing this forum: No registered users and 1 guest