在Asterisk中传输后重复的通道变量

时间:2017-07-20 22:37:20

标签: asterisk

通过(参加)转移,我发现以下情况:

1) A calls B1
2) B2 calls C
3) B2 transfers call to A
4) A talks to C

在步骤3,通道A连接到通道C,B1和B2挂起。 在频道B2的h分机中,频道被重命名为B2和i 看到A的通道变量已合并到B2中。如果有 变量的重复名称,通道现在有这些变量 一倍。从h扩展调用的DumpChan()应用程序确认了这一点。

在我的情况下,频道都是SIP频道,在我想要的h分机中 访问A通道的SIPCALLID变量。每次访问都给了我 错误的值即通道B1的值。我如何访问第二个 通道中名为SIPCALLID的变量?

丑陋的解决方案:

我找到的解决方案是来自:

same => n,Set(myVariable=10) 
same => n,NoOp(The value of myVariable is ${myVariable})

为:

same => n,Set(${CHANNEL:6:8}myVariable=10) 
same => n,NoOp(The value of myVariable is ${${CHANNEL:6:8}myVariable})

通过这个技巧,我将通道的id附加到所有变量。我必须使用6:8,因为一旦我转移了呼叫,频道ID现在包含<ZOMBIE>。我不想将$ {CHANNEL:6:8}附加到我的所有变量中。你们推荐什么?

1 个答案:

答案 0 :(得分:1)

您可以使用SHARED功能

pro-sip*CLI> core show function SHARED

  -= Info about function 'SHARED' =- 

[Synopsis]
Gets or sets the shared variable specified. 

[Description]
Implements a shared variable area, in which you may share variables between
channels.
The variables used in this space are separate from the general namespace
of the channel and thus ${SHARED(foo)} and ${foo}  represent two completely
different variables, despite sharing the same name.
Finally, realize that there is an inherent race between channels operating
at the same time, fiddling with each others' internal variables, which is
why this special variable namespace exists; it is to remind you that variables
in the SHARED namespace may change at any time, without warning.  You should
therefore take special care to ensure that when using the SHARED namespace,
you retrieve the variable and store it in a regular channel variable before
using it in a set of calculations (or you might be surprised by the
result).

[Syntax]
SHARED(varname[,channel])

[Arguments]
varname
    Variable name
channel
    If not specified will default to current channel. It is the complete
    channel name: 'SIP/12-abcd1234' or the prefix only 'SIP/12'.

[See Also]
Not available