metadata or call variables?

classic Classic list List threaded Threaded
3 messages Options
KC
Reply | Threaded
Open this post in threaded view
|

metadata or call variables?

KC
hi all, this is probably a dumb question. When it comes to passing around controllers and their user data, whats the pros and cons of metadata vs call variables? Or there is something else better? I can't find many examples of controllers returning metadata
 
thanks
Kai

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: metadata or call variables?

Ben Klang-2
Il giorno Nov 19, 2015, alle ore 5:38 PM, KC <[hidden email]> ha scritto:

hi all, this is probably a dumb question. When it comes to passing around controllers and their user data, whats the pros and cons of metadata vs call variables? Or there is something else better? I can't find many examples of controllers returning metadata
 
thanks
Kai


Hi Kai,

There are two main ways within Adhearsion you can share data among controllers:

* Call object variables: treating the `call` object as a hash and assigning values to it like `call[:my_thing] = “foo”`
* CallController metadata: passing a hash of data when you transfer control to a new controller with either `pass` or `throw`

Both have their place, but if you’re in doubt, I’d suggest you lean toward CallController metadata. Here’s why.

You can think of `call` variables as being semi-global, at least in the sense that they are present to any and all code which interacts with that call.  Thus, you want to reserve them for things that really need to be global, such as a handle on a full-call recording object, or perhaps some kind of account data that you want present in every call controller or in event handlers.

CallController metadata, on the other hand, is scoped explicitly to the controller. This allows you to manage what data is in scope much more reliably. It also makes testing the controller in isolation much easier. You’re able to be more explicit about which information the CallController relies upon to do its job, for which you can document and write tests.  With call object variables, this isn’t quite as obvious.  Note that you may very well end up passing metadata from controller to controller, and in my opinion, this is perfectly acceptable.

PS:  I’ll also call out the fact that you can set Asterisk channel variables, but that we explicitly discourage this. There are two main reasons: first, we’ve seen that there can be an AGI performance impact to setting/fetching channel variables; and second, it makes your app dependent on Asterisk. Avoid whenever possible.

Hope that helps,
/BAK/
-- 
Ben Klang
Principal/Technology Strategist, Mojo Lingo
+1.404.475.4841

Mojo Lingo -- Voice applications that work like magic
Twitter: @MojoLingo


--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

signature.asc (858 bytes) Download Attachment
KC
Reply | Threaded
Open this post in threaded view
|

Re: metadata or call variables?

KC
In reply to this post by KC
thanks Ben! definitely helps me with understanding Adhearsion.


On Thursday, November 19, 2015 at 5:38:13 PM UTC-5, KC wrote:
hi all, this is probably a dumb question. When it comes to passing around controllers and their user data, whats the pros and cons of metadata vs call variables? Or there is something else better? I can't find many examples of controllers returning metadata
 
thanks
Kai

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.