[macro-multimeet-2]
;this module joins the user to the conference, and initates outbound calls to
;other conferences
; To call this macro you enter
; exten => _X.,n,macro(multimeet-2,<conf number>,<trunk1 code>,<trunk2 code>,... etc)
; I put the above line of code in from-internal-custom
; ARG1 is the conference number. All other ARG's are the access codes for the
; remote boxes. This software requires that a conference number of ARG1
; be set up in advance on each box. The interconnecting trunks must be
; from-internal on the remote machines.
; This section counts the number of trunks. You need to know how many .call files
; to make and this number is needed when you tear down the conferences at the end
exten => s,1,Set(meetmepin=${ARG1}) ;the conference number
exten => s,n,Set(ArgCount=2) ;Set the loop counter to start at 2
exten => s,n(toploop),Noop(Parse ARG's to see how many there are)
exten => s,n,Gotoif(${ARG${ArgCount}}?:loopout)
exten => s,n,Set(ArgCount=$[${ArgCount} + 1])
exten => s,n,Goto(toploop)
; Set the Argument count to the correct number
exten => s,n(loopout),Set(ArgCount=$[${ArgCount} - 1])
exten => s,n,NoOp(Joining current caller to conference number ${meetmepin})
; See if the conference is already set up by counting the number of users
; already there. If there is more than one, we assume it is set up and
; skip to the bottom and just add this user.
exten => s,n,MeetMeCount(${meetmepin}|count)
exten => s,n,NoOp()
exten => s,n,Gotoif,$[${count} >=1]?100
; If this is the first user, we set up the links between the servers
; Start reading data with $ARG2
exten => s,n,Set(newcount=2)
; Kick out of the loop if we have read all of the Arguments
exten => s,n(newtop),gotoif($[${newcount} > ${ArgCount}]?moveon)
; Create the .call file and send it to the outgoing directory
exten => s,n,system(echo "Channel: Local/${meetmepin}@from-internal/n" > /etc/asterisk/${ARG${newcount}}${meetmepin}.call)
exten => s,n,system(echo "MaxRetries: 1" >> /etc/asterisk/${ARG${newcount}}${meetmepin}.call)
exten => s,n,system(echo "WaitTime:5" >> /etc/asterisk/${ARG${newcount}}${meetmepin}.call)
exten => s,n,system(echo "Context: from-internal" >> /etc/asterisk/${ARG${newcount}}${meetmepin}.call)
exten => s,n,system(echo "Extension: ${ARG${newcount}}${meetmepin}" >> /etc/asterisk/${ARG${newcount}}${meetmepin}.call)
exten => s,n,system(echo "Priority: 1" >> /etc/asterisk/${ARG${newcount}}${meetmepin}.call)
exten => s,n,system(chown asterisk:asterisk ${ARG${newcount}}${meetmepin}.call)
exten => s,n,Wait(1)
exten => s,n,system(mv /etc/asterisk/${ARG${newcount}}${meetmepin}.call /var/spool/asterisk/outgoing)
; Increment the counter and go back to the top
exten => s,n,Set(newcount=$[${newcount} + 1])
exten => s,n,goto(newtop)
;this code above creates a ".call file" that will be placed into /var/spool/asterisk/outgoing.
;This call file automatically generates a call within the asterisk PBX.
;The entry "Channel" defines the 'local' meeting the computer should join
;The entry "Extension" is the destination meeting it should join.
;This creates a 'trunk' between the two.
; The call file created is unique for each trunk called. I found that if you didn't
; create a different call file for each trunk, the existing one would be overwritten
; before it completed its connection.
;On my two asterisk PBX's, I had created a meeting '6000' using FreePBX on each.
;In the above example, my 'far end' PBX is contacted with an outbound prefix of 77.
;So, when the person enters in the meeting they want to contact as 6000,
;the system will call 776000
;an outbound route in FreePBX simply of 77|. will send 6000 to the far end system.
;the far end system matches that to the local meeting and a link is made between
;the two systems.
;make sense? :)
;If you have multiple sites that you want to call, just repeat the code,
;modify the s,XX accordingly
;as well as the "EXTENSION" entry to reflect the outbound dial prefix that you need.
exten => s,n(moveon),Goto(s,100)
; This adds this user to the local conference
exten => s,100,MeetMe(${meetmepin}|Mdsp)
; This line sets things up for the hangup
exten => s,n,goto(h,1)
exten => h,1,goto(h,101)
exten => h,101,Noop(Break down trunk when all callers have left)
exten => h,102,MeetMeCount(${meetmepin}|newcount2)
exten => h,103,Gotoif($[${newcount2} > ${ArgCount} - 1]?104:106)
exten => h,104,Wait(30)
exten => h,105,goto(s,102)
exten => h,106,System(/usr/sbin/asterisk -rx "meetme kick ${meetmepin} all")
exten => h,n,hangup()
; the first three contexts are separated in order to group them by the appropriate dundi priority