ably-js
ably-js copied to clipboard
Ably Realtime WebWorker Issue
When using Ably.Realtime inside a web worker combined with client options containing an authUrl value it does not connect.
const clientParams: AblyTypes.ClientOptions = {
authUrl: environment.ablyAuthUrl,
clientId,
};
The logs show this warning Ably: Auth.requestToken(): token request signing call returned error; err = [e: Request invoked before assigned to; statusCode=500]
while the actual endpoint is never called.
This same constructor code seems to work fine in a non web worker environment.
Using the Realtime constructor with a demo key and not client options seems to work fine.
Seems like the issue is that there is no http request factory compatible with web worker.
https://github.com/ably/ably-js/blob/3386abae8f35f5d41f016c0feeb7406bb5537cb2/src/platform/web/lib/util/http.ts#L48
Hi @psionline-jliddell,
We do provide a bundle which works in a standard webworker context, but service workers generally don't support XmlHttpRequest
which is what the library currently uses to make HTTP requests. We are planning on adding support for the Fetch API to the library soon which will resolve this issue. I'll let you know in this issue when the work to add fetch is done.
For now, the best workaround for this is to use the authCallback
client option (see my comment here for some more details on usage). The library still won't be able to make HTTP requests by itself, so you won't be able to use the REST API methods, but realtime features should still work fine.