asterisk / node-ari-client

Node.js client for ARI. This library is best effort with limited support.
Other
253 stars 99 forks source link

lib/client: Make ari.start() return a Promise that resolves on WS open #28

Closed matt-jordan closed 9 years ago

matt-jordan commented 9 years ago

When a WebSocket connection is made via ari.start, it is often useful to know when that connection has fully established. This is particularly true when REST calls have to be made that are application dependent (such as subscribing for particular event sources), as those calls will fail if a WebSocket connection is not made.

This patch modifies ari.start such that it returns a Promise that is resolved on the open callback of the underlying WebSocket library, and is rejected on any error returned back from the same library.

samuelg commented 9 years ago

It might be good to add documentation for this. However, since using as Callback will simply return a Promise that will be ignored by current applications, it's not paramount.

Looks good to me.