Best way to "communicate" both sides of local channel

Hi all

I’m trying to send information from one side of a local channel to the other. The local channel is created by an external originate call:

My first try was to use __variables, but they don’t get updated on both sides. Then I found about shared variables, so I put some code like this:

[from-local] exten => 3000,1,Set(REDIRECTING_CALLER_SEND_MACRO=caller) same => n,Set(LEN=${MATH(${LEN(${CHANNEL})}-2,i)}) same => n,Set(__PEER=${CHANNEL:0:${LEN}}\;1) same => n,Dial(SIP/sipp/4004711881,30,t)

[macro-caller] exten => s,1,GotoIf(${ALLOW_REDIRECT}=false?Hangup) same => n,MacroExit same => n(Hangup),Set(SHARED(REDIRECT,${PEER})=1)

[tts] exten => 3001,1,Set(RESULT=SUCCESS) same => n,GotoIf(${SHARED(REDIRECT,${CHANNEL})}=1?Hangup) same => n,Playback(/dev/shm/${AUDIO}) same => n(Hangup),Hangup()
It’s seems to work in a test call. The ;2 side of the channel start first, sets the REDIRECT shared variable, when the call get answered the ;1 side starts and can read the value. My questions are… is this correct ? is it going to work always like this ? is there a better way to accomplish the same thing ?

One other way is to use IMPORT.

I will test it using IMPORT from the ;1 side. I’m not sure when the local channels disappear. Would you say that both approaches are “correct” and can I use any of them in production with a medium load (100 concurrent calls) ? Which one do you prefer ?

I’ve only used IMPORT, but I don’t see why SHARED won’t work. I don’t have a view on relative performance. The earliest that a local channel can disappear is when it is bridged to another channel that is answered.