MeetingRouter

Client Configuration Guide

@meeting-baas/sdk - Client API & Bridge / client-configuration

Client Configuration Guide

This guide covers all aspects of configuring the Meeting BaaS SDK client.

Basic Configuration

Creating a Client

import { createBaasClient } from "@meeting-baas/sdk";

const client = createBaasClient({
  api_key: "your-api-key"
});

Configuration Options

API Key (Required)

Your Meeting BaaS API key:

const client = createBaasClient({
  api_key: process.env.MEETING_BAAS_API_KEY!
});

Get your API key at meetingbaas.com

API Version (Optional)

Choose between v1 and v2 API:

// v1 API (default)
const v1Client = createBaasClient({
  api_key: "your-api-key"
  // api_version defaults to "v1"
});

// v2 API
const v2Client = createBaasClient({
  api_key: "your-api-key",
  api_version: "v2"
});

See Version Selection Guide for differences.

Timeout (Optional)

Request timeout in milliseconds:

const client = createBaasClient({
  api_key: "your-api-key",
  timeout: 60000 // 60 seconds (default: 30000)
});

Recommended values:

  • Default operations: 30000 (30 seconds)
  • Long-running operations: 60000-120000 (1-2 minutes)
  • Batch operations: 120000+ (2+ minutes)

Configuration Interface

interface BaasClientConfig {
  api_key: string;           // Required: Your API key
  api_version?: "v1" | "v2"; // Optional: API version (default: "v1")
  base_url?: string;         // Optional: Base URL (internal use only)
  timeout?: number;          // Optional: Request timeout in ms (default: 30000)
}

Environment-Based Configuration

Using Environment Variables

// .env file
MEETING_BAAS_API_KEY=your-api-key
MEETING_BAAS_API_VERSION=v2
MEETING_BAAS_TIMEOUT=60000
// Load configuration from environment
import { createBaasClient } from "@meeting-baas/sdk";

const client = createBaasClient({
  api_key: process.env.MEETING_BAAS_API_KEY!,
  api_version: (process.env.MEETING_BAAS_API_VERSION as "v1" | "v2") || "v1",
  timeout: parseInt(process.env.MEETING_BAAS_TIMEOUT || "30000", 10)
});

Configuration Factory

// lib/config.ts
export interface AppConfig {
  meetingBaas: {
    apiKey: string;
    apiVersion: "v1" | "v2";
    timeout: number;
  };
}

export function loadConfig(): AppConfig {
  const apiKey = process.env.MEETING_BAAS_API_KEY;

  if (!apiKey) {
    throw new Error("MEETING_BAAS_API_KEY is required");
  }

  return {
    meetingBaas: {
      apiKey,
      apiVersion: (process.env.MEETING_BAAS_API_VERSION as "v1" | "v2") || "v1",
      timeout: parseInt(process.env.MEETING_BAAS_TIMEOUT || "30000", 10)
    }
  };
}
// lib/meeting-baas.ts
import { createBaasClient } from "@meeting-baas/sdk";
import { loadConfig } from "./config";

const config = loadConfig();

export const client = createBaasClient({
  api_key: config.meetingBaas.apiKey,
  api_version: config.meetingBaas.apiVersion,
  timeout: config.meetingBaas.timeout
});

Multiple Clients

Multiple API Versions

Use both v1 and v2 simultaneously:

const v1Client = createBaasClient({
  api_key: process.env.MEETING_BAAS_API_KEY!,
  api_version: "v1"
});

const v2Client = createBaasClient({
  api_key: process.env.MEETING_BAAS_API_KEY!,
  api_version: "v2"
});

// Use v2 for new features
await v2Client.createBot({ ... });

// Keep v1 for legacy code
await v1Client.joinMeeting({ ... });

Multiple Accounts

Different API keys for different purposes:

const productionClient = createBaasClient({
  api_key: process.env.PRODUCTION_API_KEY!,
  api_version: "v2"
});

const testingClient = createBaasClient({
  api_key: process.env.TESTING_API_KEY!,
  api_version: "v2"
});

Singleton Pattern

Reuse a single client instance:

// lib/meeting-baas-client.ts
import { createBaasClient } from "@meeting-baas/sdk";

let clientInstance: ReturnType<typeof createBaasClient> | null = null;

export function getMeetingBaasClient() {
  if (!clientInstance) {
    const apiKey = process.env.MEETING_BAAS_API_KEY;

    if (!apiKey) {
      throw new Error("MEETING_BAAS_API_KEY environment variable is required");
    }

    clientInstance = createBaasClient({
      api_key: apiKey,
      api_version: "v2",
      timeout: 60000
    });
  }

  return clientInstance;
}

// Optional: Reset for testing
export function resetClient() {
  clientInstance = null;
}
// Usage throughout your app
import { getMeetingBaasClient } from "./lib/meeting-baas-client";

const client = getMeetingBaasClient();
await client.createBot({ ... });

Advanced Patterns

Lazy Initialization

Initialize client only when needed:

class MeetingBaasService {
  private _client?: ReturnType<typeof createBaasClient>;

  private get client() {
    if (!this._client) {
      this._client = createBaasClient({
        api_key: process.env.MEETING_BAAS_API_KEY!,
        api_version: "v2"
      });
    }
    return this._client;
  }

  async createBot(meetingUrl: string, botName: string) {
    return await this.client.createBot({
      meeting_url: meetingUrl,
      bot_name: botName
    });
  }
}

export const meetingBaasService = new MeetingBaasService();

Dependency Injection

// services/meeting-service.ts
import type { createBaasClient } from "@meeting-baas/sdk";

export class MeetingService {
  constructor(
    private client: ReturnType<typeof createBaasClient>
  ) {}

  async recordMeeting(url: string, name: string) {
    const result = await this.client.createBot({
      meeting_url: url,
      bot_name: name
    });

    if (!result.success) {
      throw new Error(result.error);
    }

    return result.data.bot_id;
  }
}
// app.ts
import { createBaasClient } from "@meeting-baas/sdk";
import { MeetingService } from "./services/meeting-service";

const client = createBaasClient({
  api_key: process.env.MEETING_BAAS_API_KEY!,
  api_version: "v2"
});

const meetingService = new MeetingService(client);

Configuration Validation

Runtime Validation

import { z } from "zod";

const configSchema = z.object({
  MEETING_BAAS_API_KEY: z.string().min(1, "API key is required"),
  MEETING_BAAS_API_VERSION: z.enum(["v1", "v2"]).default("v1"),
  MEETING_BAAS_TIMEOUT: z.coerce.number().min(1000).max(300000).default(30000)
});

function createValidatedClient() {
  const config = configSchema.parse({
    MEETING_BAAS_API_KEY: process.env.MEETING_BAAS_API_KEY,
    MEETING_BAAS_API_VERSION: process.env.MEETING_BAAS_API_VERSION,
    MEETING_BAAS_TIMEOUT: process.env.MEETING_BAAS_TIMEOUT
  });

  return createBaasClient({
    api_key: config.MEETING_BAAS_API_KEY,
    api_version: config.MEETING_BAAS_API_VERSION,
    timeout: config.MEETING_BAAS_TIMEOUT
  });
}

Testing Configuration

Mock Client

// test/mocks/meeting-baas-client.ts
export const mockClient = {
  createBot: jest.fn(),
  getBot: jest.fn(),
  stopBot: jest.fn(),
  // ... other methods
};
// test/meeting-service.test.ts
import { MeetingService } from "../services/meeting-service";
import { mockClient } from "./mocks/meeting-baas-client";

describe("MeetingService", () => {
  let service: MeetingService;

  beforeEach(() => {
    service = new MeetingService(mockClient as any);
    jest.clearAllMocks();
  });

  it("should create bot", async () => {
    mockClient.createBot.mockResolvedValue({
      success: true,
      data: { bot_id: "test-bot-id" }
    });

    const botId = await service.recordMeeting(
      "https://meet.google.com/abc",
      "Test Bot"
    );

    expect(botId).toBe("test-bot-id");
    expect(mockClient.createBot).toHaveBeenCalledWith({
      meeting_url: "https://meet.google.com/abc",
      bot_name: "Test Bot"
    });
  });
});

Test Configuration

// test/setup.ts
import { createBaasClient } from "@meeting-baas/sdk";

export function createTestClient() {
  return createBaasClient({
    api_key: process.env.TEST_API_KEY || "test-key",
    api_version: "v2",
    timeout: 5000 // Shorter timeout for tests
  });
}

Error Handling

Configuration Errors

function createSafeClient() {
  const apiKey = process.env.MEETING_BAAS_API_KEY;

  if (!apiKey) {
    throw new Error(
      "MEETING_BAAS_API_KEY environment variable is not set. " +
      "Get your API key at https://meetingbaas.com"
    );
  }

  if (apiKey.length < 20) {
    throw new Error("Invalid API key format");
  }

  try {
    return createBaasClient({
      api_key: apiKey,
      api_version: "v2"
    });
  } catch (error) {
    console.error("Failed to create Meeting BaaS client:", error);
    throw error;
  }
}

Best Practices

  1. Store API keys securely: Use environment variables, never hardcode

  2. Use singleton pattern: Create one client instance and reuse it

  3. Set appropriate timeouts: Adjust based on your operation types

  4. Validate configuration: Check required variables at startup

  5. Handle errors gracefully: Provide helpful error messages

  6. Use TypeScript: Leverage type safety for configuration

  7. Version consistently: Don't mix v1 and v2 in same code path

  8. Document configuration: Make it clear what variables are needed

Complete Example

// config/meeting-baas.ts
import { createBaasClient } from "@meeting-baas/sdk";
import { z } from "zod";

// Configuration schema
const configSchema = z.object({
  apiKey: z.string().min(20),
  apiVersion: z.enum(["v1", "v2"]),
  timeout: z.number().min(1000).max(300000)
});

// Load and validate configuration
function loadMeetingBaasConfig() {
  const config = configSchema.parse({
    apiKey: process.env.MEETING_BAAS_API_KEY,
    apiVersion: process.env.MEETING_BAAS_API_VERSION || "v2",
    timeout: parseInt(process.env.MEETING_BAAS_TIMEOUT || "60000", 10)
  });

  return config;
}

// Create singleton client
let clientInstance: ReturnType<typeof createBaasClient> | null = null;

export function getMeetingBaasClient() {
  if (!clientInstance) {
    const config = loadMeetingBaasConfig();

    clientInstance = createBaasClient({
      api_key: config.apiKey,
      api_version: config.apiVersion,
      timeout: config.timeout
    });

    console.log(`Meeting BaaS client initialized (${config.apiVersion})`);
  }

  return clientInstance;
}

// For testing
export function resetClient() {
  clientInstance = null;
}
// Usage
import { getMeetingBaasClient } from "./config/meeting-baas";

const client = getMeetingBaasClient();

const result = await client.createBot({
  meeting_url: "https://meet.google.com/abc-def-ghi",
  bot_name: "Meeting Assistant"
});

On this page