Thanks, Josh!
@billsimon, since the CONFBRIDGE_CHANNELS function is now available in all of the latest versions of Asterisk, which are now available in the FreePBX testing repos, I went ahead and tested this.
In extensions_custom.conf
I have a general dialplan to set Hangup Handlers that is being used by many different applications
[set-hangup-handler]
exten => s,1,Noop(Setting Hangup Handler)
exten => s,n,Set(CHANNEL(hangup_handler_push)=${ARG1},${ARG2},${ARG3})
exten => s,n,Return()
Then, I created a Custom Destination:
Finally, the actual Hangup Handler dialplan:
[conf-bridge-handler]
exten => s,1,Noop(In conf bridge hangup handler)
exten => s,n,Gotoif($["${CONFBRIDGE_INFO(parties,${MEETME_ROOMNUM})}"="1"]?kick)
exten => s,n,Return()
exten => s,n(kick),Noop(Redirecting channel ${CONFBRIDGE_CHANNELS(active,${MEETME_ROOMNUM})} to the global hangup)
;This is just hanging up the channel. It would be more ideal to redirect to a custom context that plays a message, something like "You are being removed from the conference because you are the last remaining user.."
exten => s,n,ChannelRedirect(${CONFBRIDGE_CHANNELS(active,${MEETME_ROOMNUM})},app-blackhole,hangup,1)
exten => s,n,Return()
And it works great.
Asterisk logs:
PJSIP/64066-0000000a Internal Gosub(conf-bridge-handler,s,1) start
-- Executing [s@conf-bridge-handler:1] NoOp("PJSIP/64066-0000000a", "In conf bridge hangup handler") in new stack
-- Executing [s@conf-bridge-handler:2] GotoIf("PJSIP/64066-0000000a", "1?kick") in new stack
-- Goto (conf-bridge-handler,s,4)
-- Executing [s@conf-bridge-handler:4] NoOp("PJSIP/64066-0000000a", "Redirecting channel PJSIP/2547-0000000b to the global hangup") in new stack
-- Executing [s@conf-bridge-handler:5] ChannelRedirect("PJSIP/64066-0000000a", "PJSIP/2547-0000000b,app-blackhole,hangup,1") in new stack
-- Executing [s@conf-bridge-handler:6] Return("PJSIP/64066-0000000a", "") in new stack
== Spawn extension (ext-meetme, h, 1) exited non-zero on 'PJSIP/64066-0000000a'
-- PJSIP/64066-0000000a Internal Gosub(conf-bridge-handler,s,1) complete GOSUB_RETVAL=
-- Stopped music on hold on PJSIP/2547-0000000b
-- Channel PJSIP/2547-0000000b left 'softmix' base-bridge <ba446779-b34e-47a3-a6e1-3ace014d08c7>
-- Channel CBAnn/460404-00000005;2 left 'softmix' base-bridge <ba446779-b34e-47a3-a6e1-3ace014d08c7>
-- Executing [hangup@app-blackhole:1] NoOp("PJSIP/2547-0000000b", "Blackhole Dest: Hangup") in new stack
-- Executing [hangup@app-blackhole:2] Hangup("PJSIP/2547-0000000b", "") in new stack
== Spawn extension (app-blackhole, hangup, 2) exited non-zero on 'PJSIP/2547-0000000b'
-- PJSIP/2547-0000000b Internal Gosub(conf-bridge-handler,s,1) start
-- Executing [s@conf-bridge-handler:1] NoOp("PJSIP/2547-0000000b", "In conf bridge hangup handler") in new stack
-- Executing [s@conf-bridge-handler:2] GotoIf("PJSIP/2547-0000000b", "0?kick") in new stack
-- Executing [s@conf-bridge-handler:3] Return("PJSIP/2547-0000000b", "") in new stack
== Spawn extension (app-blackhole, hangup, 2) exited non-zero on 'PJSIP/2547-0000000b'
While working on that, I realized that we didn’t actually have to wait for this function… There’s a Asterisk application ConfKick()
and it works great as well.
[conf-bridge-handler]
exten => s,1,Noop(In conf bridge hangup handler)
exten => s,n,Gotoif($["${CONFBRIDGE_INFO(parties,${MEETME_ROOMNUM})}"="1"]?kick)
exten => s,n,Return()
exten => s,n(kick),Noop(Kicking all participants from ${MEETME_ROOMNUM})
;Pass the conference number. The channel to kick, 'all' to kick all users, or 'participants' to kick all non-admin participants. Default is all.
exten => s,n,ConfKick(${MEETME_ROOMNUM},all)
exten => s,n,Return()
Asterisk logs:
Spawn extension (ext-meetme, h, 1) exited non-zero on 'PJSIP/64066-0000000e'
-- PJSIP/64066-0000000e Internal Gosub(conf-bridge-handler,s,1) start
-- Executing [s@conf-bridge-handler:1] NoOp("PJSIP/64066-0000000e", "In conf bridge hangup handler") in new stack
-- Executing [s@conf-bridge-handler:2] GotoIf("PJSIP/64066-0000000e", "1?kick") in new stack
-- Goto (conf-bridge-handler,s,4)
-- Executing [s@conf-bridge-handler:4] NoOp("PJSIP/64066-0000000e", "Kicking all participants from 460404") in new stack
-- Executing [s@conf-bridge-handler:5] ConfKick("PJSIP/64066-0000000e", "460404,all") in new stack
-- Executing [s@conf-bridge-handler:6] Return("PJSIP/64066-0000000e", "") in new stack
== Spawn extension (ext-meetme, h, 1) exited non-zero on 'PJSIP/64066-0000000e'
-- PJSIP/64066-0000000e Internal Gosub(conf-bridge-handler,s,1) complete GOSUB_RETVAL=
-- Channel PJSIP/2547-0000000f left 'softmix' base-bridge <d2b272ce-de7a-4d2f-a6b3-2df55078a41f>
-- Stopped music on hold on PJSIP/2547-0000000f
-- Channel CBAnn/460404-00000007;2 left 'softmix' base-bridge <d2b272ce-de7a-4d2f-a6b3-2df55078a41f>
-- Executing [STARTMEETME@ext-meetme:6] Macro("PJSIP/2547-0000000f", "hangupcall,") in new stack
-- Executing [s@macro-hangupcall:1] GotoIf("PJSIP/2547-0000000f", "1?theend") in new stack
-- Goto (macro-hangupcall,s,3)
-- Executing [s@macro-hangupcall:3] ExecIf("PJSIP/2547-0000000f", "0?Set(CDR(recordingfile)=)") in new stack
-- Executing [s@macro-hangupcall:4] NoOp("PJSIP/2547-0000000f", " montior file= ") in new stack
-- Executing [s@macro-hangupcall:5] GotoIf("PJSIP/2547-0000000f", "1?skipagi") in new stack
-- Goto (macro-hangupcall,s,7)
-- Executing [s@macro-hangupcall:7] Hangup("PJSIP/2547-0000000f", "") in new stack
== Spawn extension (macro-hangupcall, s, 7) exited non-zero on 'PJSIP/2547-0000000f' in macro 'hangupcall'
== Spawn extension (ext-meetme, STARTMEETME, 6) exited non-zero on 'PJSIP/2547-0000000f'
-- Executing [h@ext-meetme:1] Macro("PJSIP/2547-0000000f", "hangupcall,") in new stack
-- Executing [s@macro-hangupcall:1] GotoIf("PJSIP/2547-0000000f", "1?theend") in new stack
-- Goto (macro-hangupcall,s,3)
-- Executing [s@macro-hangupcall:3] ExecIf("PJSIP/2547-0000000f", "0?Set(CDR(recordingfile)=)") in new stack
-- Executing [s@macro-hangupcall:4] NoOp("PJSIP/2547-0000000f", " montior file= ") in new stack
-- Executing [s@macro-hangupcall:5] GotoIf("PJSIP/2547-0000000f", "1?skipagi") in new stack
-- Goto (macro-hangupcall,s,7)
-- Executing [s@macro-hangupcall:7] Hangup("PJSIP/2547-0000000f", "") in new stack
== Spawn extension (macro-hangupcall, s, 7) exited non-zero on 'PJSIP/2547-0000000f' in macro 'hangupcall'
== Spawn extension (ext-meetme, h, 1) exited non-zero on 'PJSIP/2547-0000000f'
-- PJSIP/2547-0000000f Internal Gosub(conf-bridge-handler,s,1) start
-- Executing [s@conf-bridge-handler:1] NoOp("PJSIP/2547-0000000f", "In conf bridge hangup handler") in new stack
-- Executing [s@conf-bridge-handler:2] GotoIf("PJSIP/2547-0000000f", "0?kick") in new stack
-- Executing [s@conf-bridge-handler:3] Return("PJSIP/2547-0000000f", "") in new stack
== Spawn extension (ext-meetme, h, 1) exited non-zero on 'PJSIP/2547-0000000f'
-- PJSIP/2547-0000000f Internal Gosub(conf-bridge-handler,s,1) complete GOSUB_RETVAL=