Providing A Custom Channels Authoriser
It is possible to modify the default authorisation behaviour of our client libraries by providing a custom authoriser. Consider the following motivating scenario:
Normally when subscribing to a private or presence channel we first send a request to our auth endpoint to get authentication data, and then only after that do we make the call to the Pusher servers to register the subscription. If we know in advance which channels we might need to subscribe to, it would speed up the eventual subscription if we could pre-populate the auth data, and send the subscription request to Pusher immediately upon firing pusher.subscribe(…)
.
We can do this with a custom authoriser that checks for pre-populated auth data, and provides that immediately.
In pusher-js a custom authoriser is of the form
We can then use this by adding it to the return value of the Pusher.Runtime.getAuthorizers
function.
And now we can use it by setting the authTransport
in our options when we initiate the Pusher
object.
For a full example solving the motivating scenario above, see here.
Still have questions? Please reach out to our Support team by visiting this page.
Last updated