@ably/cli
Version:
Ably CLI for Pub/Sub, Chat and Spaces
37 lines (36 loc) • 1.44 kB
JavaScript
// Dynamic import to handle module structure issues
let SpacesConstructor = null;
async function getSpacesConstructor() {
if (!SpacesConstructor) {
const spacesModule = await import("@ably/spaces");
const moduleAsRecord = spacesModule;
const defaultProperty = moduleAsRecord.default;
SpacesConstructor = (defaultProperty?.default || moduleAsRecord.default || moduleAsRecord);
}
return SpacesConstructor;
}
import { AblyBaseCommand } from "./base-command.js";
export class SpacesBaseCommand extends AblyBaseCommand {
// Ensure we have the spaces client and its related authentication resources
async setupSpacesClient(flags, spaceName) {
// First create an Ably client
const realtimeClient = await this.createAblyRealtimeClient(flags);
if (!realtimeClient) {
this.error("Failed to create Ably client");
}
// Create a Spaces client using the Ably client
const Spaces = await getSpacesConstructor();
const spacesClient = new Spaces(realtimeClient);
// Get a space instance with the provided name
const space = await spacesClient.get(spaceName);
return {
realtimeClient,
space,
spacesClient,
};
}
async createSpacesClient(realtimeClient) {
const Spaces = await getSpacesConstructor();
return new Spaces(realtimeClient);
}
}