-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Latest version doesn't work with Cloudflare Workers #1127
Comments
➤ Automation for Jira commented: The link to the corresponding Jira issue is https://ably.atlassian.net/browse/SDK-3340 |
Hey @Braden1996, thanks for reporting this! Before we look into this I just want to check, did you mean to reopen the issue with that last comment? |
Hey! Sorry, this issue still seems to be happening. Importing from import type { Types } from "ably";
import AblyWebWorker from "ably/build/ably-webworker.min"; // Types don't seem to work here.
export default class Ably {
private ably: Types.RestPromise;
constructor(ablyApiKey: string) {
const clientOptions: Types.ClientOptions = {
key: ablyApiKey,
};
this.ably = new AblyWebWorker.Rest.Promise(clientOptions);
}
// This works
async createTokenRequest(userId: string) {
const tokenRequest = await this.ably.auth.createTokenRequest({
clientId: userId,
capability: {
[`user:${userId}`]: ["subscribe", "publish"],
},
});
return tokenRequest;
}
// This does not work :(
async publishToChannel(
channelName: string,
messageName: string,
messagePayload: string
) {
const channel = this.ably.channels.get(channelName);
await channel.publish(messageName, messagePayload);
}
} In the example code, the
|
For the time being, I'm getting round this by: async publishToChannel(
channelName: string,
messageName: string,
messagePayload: string
) {
const encodedChannelName = encodeURIComponent(channelName);
const b64Key = btoa(this.ablyApiKey);
fetch(`https://rest.ably.io/channels/${encodedChannelName}/messages`, {
method: "POST",
headers: {
Authorization: `Basic ${b64Key}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
name: messageName,
data: messagePayload,
}),
});
} |
Hey @Braden1996 , we've updated the library in 1.2.37 to not send the credentials field when using the webworker version. I hope this helps and please let us know if you have any further issues :) |
Error occurred on version
1.2.36
:Importing from
ably/build/ably-webworker.min
gives me:Temporarily downgrading to
1.2.4
resolves the issue, but I am still unable to publish to channels.The text was updated successfully, but these errors were encountered: