<div dir="ltr">Hey everyone -<div><br></div><div>At AstriDevCon, we mentioned that two features ARI would need were the ability to raise MWI and the ability to publish state (device state, but theoretically, any event package for some subscribable resource). Initially, we discussed needing two resources in ARI - one that represents the state of mailboxes, and one that represents the state of a "device".</div>
<div><br></div><div style>The more we've thought about it, the more it feels like - from ARI's perspective - these are the same concepts. From the perspective of an ARI client, you want the ability to define a resource that someone can subscribe to. You want to be notified when something subscribes to it; when they unsubscribe to it; and when a resource's state changes. In turn, you want to publish state about that resource to the subscribers. The fact that the resource is a mailbox, or a device, or who knows what else - is immaterial. The application itself should determine this.</div>
<div style><br></div><div style>(Plus, we forgot that in addition to device state and MWI, there's also presence state in Asterisk. So we were already up to 3 things anyway)</div><div style><br></div><div style>We need a more generic concept - a 'blinky light' resource, if you will.</div>
<div style><br></div><div style>The trick, unfortunately, is that in the guts of Asterisk, these are not the same concepts. MWI and device state (or presence state, for that matter) are all handled very differently. As much as it'd be fun to say "let's unify all the implementations!" - that's unrealistic and potentially harmful. So whatever we choose, there has to be a way to map the generic concept back to the actual implementation inside Asterisk.</div>
<div style><br></div><div style>The following is a proposal on how I think this might work:</div><div style><br></div><div style>Add a new resource to ARI to represent a generic resource that can be subscribed to/published about, 'topics'. A topic is something that something can subscribe to, that has state, and that the ARI client can publish state about. (Note that I chose the name 'topic' as it's what the XMPP folks used for their publish/subscribe XEP (XEP-0060), and 'resource' isn't a good name as it's a generic term in REST. Hopefully it doesn't get too confusing with Stasis message bus topics.)</div>
<div style><br></div><div style>Objects:</div><div style><br></div><div style>Topic:</div><div style>    type: string - Valid types initially would be 'mailbox', 'device', 'presence'</div><div style>
    uri: string - The URI subscribers use to subscribe to the topic</div><div style>    subscribers: List[Subscriber] - A list of active subscriptions</div><div style>    id: string - A unique ID for the topic</div><div style>
<br></div><div style>Subscriber</div><div style>    id: string - A unique ID for the subscriber</div><div style>    topic_id: string - The topic ID this subscription refers to</div><div style>    endpoint: Endpoint - If available, the endpoint that subscribed to this Topic</div>
<div style><br></div><div style>TopicSubscriptionCreated : Event - Event raised when a new subscription is created for a topic<br></div><div style><div style>    subscriber : Subscriber</div><div style>    topic: Topic</div>
<div style><br></div><div style>TopicSubscriptionDestroyed : Event - Event raised when a subscription is destroyed for a topic</div><div style>    subscriber : Subscriber</div><div style>    topic : Topic</div><div style>
<br></div><div style>TopicEvent : Event - Event raised in relation to a topic</div><div style>    topic : Topic</div><div style>    body : JSON</div><div style><br></div><div style>TopicCreated : Event - Event raised when a new topic is created</div>
<div style>    topic : Topic</div><div style><br></div><div style>TopicDestroyed : Event - Event raised when a topic is destroyed</div><div style>    topic : Topic</div><div style><br></div></div><div style>Operations:<br>
</div><div style><br></div><div style>GET /topics List[Topic] - list all topics, with optional filter for type</div><div style>GET /topic Topic - get information about a specific topic</div><div style>DELETE /topic - destroy a topic. This should implicitly unsubscribe all subscribers.</div>
<div style>POST /topics Topic - create a new topic. When you create a topic, you are implicitly subscribed to that topic.</div><div style>    type: The type of topic to create. Valid types initially would be 'mailbox', 'device', 'presence'</div>
<div style>    uri: The URI subscribers will use to subscribe to the topic</div><div style>POST /topics/publish - publish an event to a topic. Events are passed as JSON, and are opaque from the perspective of ARI. It would be up to the specific topic types to understand the  event packages.</div>
<div style><br></div><div style>/applications/{applicationName}/subscription will be updated to allow for an ARI client to subscribe to any topic in Asterisk.</div><div style><br></div><div style>Note that a topic doesn't have to be something created by ARI - Asterisk will create a *lot* of topics by itself. There would be a topic for all mailboxes created by voicemail providers; a topic for all producers of extension state (at a minimum; devices as well); a topic for all producers of presence state. Much like the Endpoints resource, the Topics resource lets an ARI client subscribe to other things in the system other than what is directly in their application, so that the client can choose to have knowledge of the whole system, even if it only affects a part.</div>
<div style><br></div><div style>This is quite a big project, but a very necessary one. There's only one thing that has to be fixed in ARI before we can do this - namely the ability to POST JSON (thanks Paul!)  But other than that, I don't think there are any technical barriers to this approach.</div>
<div style><br></div><div style>Thoughts? Comments?</div><div><div><div><br></div>-- <br><div dir="ltr"><div>Matthew Jordan<br></div><div>Digium, Inc. | Engineering Manager</div><div>445 Jan Davis Drive NW - Huntsville, AL 35806 - USA</div>
<div>Check us out at: <a href="http://digium.com" target="_blank">http://digium.com</a> & <a href="http://asterisk.org" target="_blank">http://asterisk.org</a></div></div>
</div></div></div>