Search the Asterisk Blog

Asterisk 14: Publishing Extension State

By Richard Mudgett

Asterisk 14 now has the ability to publish extension state using PJSIP PUBLISH requests to another entity acting as an event state compositor. For larger installations, the advantage of this ability is to offload from Asterisk the SUBSCRIBE and NOTIFY responsibility for state changes to the other entity.

What can be used as an event state compositor? Kamailio! Kamailio is a frequent companion to Asterisk which oddly enough has the ability to act as an event state compositor for the extension states published by Asterisk.

Configuring Asterisk to publish extension state

Publishing extension state is configured by a type=outbound-publish section in pjsip.conf. The standard options for the type=outbound-publish section are documented on the Asterisk wiki [1] by the res_pjsip_outbound_publish configuration page [2]. In addition to the standard section options, the following option values and extended options are available for publishing extension state.

event=
dialog – Publish extension state events
presence – Publish extension presence state events

multi_user=yes
Should be set to yes to allow the other entity to determine what user the published extension state event is for.

@body=
application/cpim-pidf+xml
application/dialog-info+xml
application/pidf+xml
application/xpidf+xml

Specifies the format of the extension and presence state PUBLISH bodies. The PUBLISH will contain the same body that a SUBSCRIBE NOTIFY would. The option is required.

@context=
Regular expression to select the dialplan contexts the section will publish events from. The option is optional. If not specified then events from any context are published. The section’s @context and @exten selection filters must agree to publish an event for it to get published.

@exten=
Regular expression to select the dialplan extensions the section will publish events from. The option is optional. If not specified then events from any exten are published. The section’s @context and @exten selection filters must agree to publish an event for it to get published.

You can have as many type=outbound-publish sections as you want provided the sections have different names. Each one can specify what to publish and where.

Give me a hint

The extension state PUBLISH requests from Asterisk are triggered by state changes made through dialplan hints. How you create the hints is up to you. You can explicitly create each hint or you can have extension state hints automatically created for you.

The companion autohints functionality can create extension state hints automatically as needed. You simply add the autohints=yes line to the dialplan context in extensions.conf where you want the automatic hints created.

When enabled, if a device state change happens on technology/resource and no hint named resource exists then a hint is created.

exten = resource,hint,technology/resource

For example, given the device PJSIP/alice then the hint below is created.

exten = alice,hint,PJSIP/alice

Why couldn’t extension pattern hints be used to create the hints instead? The answer is what triggers the creation of hints from the extension pattern. Specific extension hints are created from the extension pattern hint when someone explicitly SUBSCRIBEs to an extension. Since we are trying to offload handling of these subscriptions to another entity it isn’t going to help.

exten = _XXXX,hint,PJSIP/${EXTEN}

Asterisk 14 has some great new features with the extension state publishing [3] being one of them.

[1] https://wiki.asterisk.org

[2] https://wiki.asterisk.org/wiki/display/AST/Asterisk+14+Configuration_res_pjsip_outbound_publish

[3] https://wiki.asterisk.org/wiki/display/AST/Publishing+Extension+State

No Comments Yet

Get the conversation started!

Add to the Discussion

Your email address will not be published. Required fields are marked *

About the Author

Richard Mudgett

Richard Mudgett is a Senior Software Developer at Digium. While a prolific developer and contributor to Asterisk, he's elusive and can be difficult to spot outside of his native #asterisk-dev environs. We were impressed we got him to write a blog post.

See All of Richard's Articles

More From
The Digium Blog

  • No items