Is Order Of Channels Shown By Function_CHANNELS Consistently Newest First?

Home » Asterisk Users » Is Order Of Channels Shown By Function_CHANNELS Consistently Newest First?
Asterisk Users No Comments

After originating a PJSIP call, I need to get the channel for that call, so I can end it later in a hangup handler. So I use this:

https://wiki.asterisk.org/wiki/display/AST/Function_CHANNELS

In this bit of dialplan:

same => n,Originate(PJSIP/0203123456@voipfone-205
,exten,bcab-bridge-conference,s,1)
same => n,Verbose(1,***CHANNELS ARE ${CHANNELS()})
same => n,SET(GLOBAL(chan)=${CHANNELS(PJSIP\/voipfone-205-(.*))})

Now, of course, I get more than one channel shown, like this:

***CHAN WE WANT IS PJSIP/voipfone-205-00000249 PJSIP/voipfone-205-0000024c PJSIP/voipfone-205-0000024d

Assuming I use CUT to trim out the first in the list, can we ALWAYS be absolutely sure that the channel just created by Originate is the highest numbered/first in list?

Otherwise, I’m wondering if there’s a reliable way to get the channel created by originate, when there may be many other active channels on the system, too.

In case anyone’s wondering, I’m using it so that when there is only one party left in a conference, it’ll clear down the newly created external channel. For which I need the outgoing name, of course…

same => n,GotoIf($[“${CONFBRIDGE_INFO(parties,1234)}” = “1”]?hangchan)
same => n,Return()
same => n(hangchan),SoftHangup(${GLOBAL(chan)})