[wip] Provide Node/Dialog convenience wrappers
Ulexus opened this issue · 0 comments
The proxy package should offer the WithNode(ari.Client, string)
and WithDialog(ari.Client, string)
functions, which ari.Client interfaces which, when executed, will filter their commands by that node or dialog, respectively.
Usage concept example:
proxy.WithNode(c, asteriskNode).Channel().Create(...)
This might be accomplished with the client.FromClient
function, passing in the appropropriate OptionFunc for setting the Node or the Dialog.
The critical thing to manage is the client's Bus. It is a reference, so making a copy of the client (as in client.FromClient) will not duplicate the Bus. This seems ideal, in the sense that we do not want to have a whole bunch of Buses running. (perhaps reconsider this; a bus is not a heavy thing; consider whether the user interface of single or multiple buses would be distinguished)
c.bindEvents
may need to be executed, though, if the client bus is not already listening to events from the given dialog and/or ARI application. This may require exposing an ability to query the current bindings of a client's Bus.
Closure of the client's context, its cancel function, and closure of the client itself will all need to be handled carefully. Basically, derived clients (FromClient
) need to:
- subtend their own context and cancel function
- never stop the Bus on closure (maybe... consider previous paragraph on Bus)
- never close the NATS connection on closure