Amazon Chime SDK for JavaScript

3.30.0 · active · verified Sun Apr 19

The Amazon Chime SDK for JavaScript, currently at version 3.30.0, provides a comprehensive set of real-time communication components for web applications. It enables developers to integrate features such as messaging, audio, video, and screen sharing, leveraging AWS's global communication infrastructure. The SDK operates by connecting to meeting session resources provisioned within an AWS account, offering a robust API for configuring sessions, managing audio/video devices, handling screen sharing, and controlling various meeting features. With a roughly monthly release cadence, the library is actively maintained and supports modern browser environments (Chrome 78+, Firefox 75+, Safari 13+). Key differentiators include its deep integration with AWS services for scalable backend provisioning and a modular design that allows for either custom UI development or integration with higher-level libraries like the Amazon Chime SDK React Component Library. It also offers native SDKs for iOS and Android, providing a consistent cross-platform development experience.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize an Amazon Chime SDK meeting session, including setting up a logger, device controller, and handling basic audio/video events. It simulates backend responses for meeting and attendee information, which are crucial for client-side session configuration and connection. It also includes steps for requesting permissions and selecting audio input devices.

import { 
  ConsoleLogger, 
  LogLevel, 
  DefaultDeviceController, 
  MeetingSessionConfiguration, 
  DefaultMeetingSession,
  MeetingSessionStatus, 
  MeetingSessionStatusCode,
  type AudioVideoFacade, 
  type MeetingSession,
  type MeetingSessionDelegate
} from 'amazon-chime-sdk-js';

// --- Backend-provided meeting and attendee information (simulated) ---
// In a real application, this data comes from your backend service
// after calling Chime SDK CreateMeeting and CreateAttendee APIs.
const mockMeetingResponse = {
  Meeting: {
    MeetingId: 'mock-meeting-id',
    MediaPlacement: {
      AudioHostUrl: 'wss://chime.us-east-1.chime.aws/ws?X-Amz-ChannelID=...',
      ScreenDataUrl: 'wss://chime.us-east-1.chime.aws/v2/screenshare/meetingId/...',
      ScreenSharingUrl: 'wss://chime.us-east-1.chime.aws/v2/screenshare/meetingId/...',
      ScreenViewingUrl: 'wss://chime.us-east-1.chime.aws/v2/screencapture/meetingId/...',
      SignalingUrl: 'wss://signal.us-east-1.chime.aws/ws?X-Amz-ChannelID=...',
      TurnControlUrl: 'https://global.turn.chime.aws/v1/turn?X-Amz-ChannelID=...',
      EventIngestionUrl: 'https://events.chime.aws/v2/meetings/.../events'
    },
    MediaRegion: 'us-east-1'
  }
};

const mockAttendeeResponse = {
  Attendee: {
    AttendeeId: 'mock-attendee-id',
    JoinToken: 'mock-join-token',
    ExternalUserId: 'test-user-123'
  }
};

async function initializeMeetingSession() {
  const logger = new ConsoleLogger('ChimeMeetingLogger', LogLevel.INFO);
  const deviceController = new DefaultDeviceController(logger);

  const configuration = new MeetingSessionConfiguration(
    mockMeetingResponse,
    mockAttendeeResponse
  );

  const meetingSession = new DefaultMeetingSession(
    configuration,
    logger,
    deviceController
  );

  // Implement a delegate to receive meeting events
  const meetingDelegate: MeetingSessionDelegate = {
    audioVideoDidStart: () => {
      logger.info('Audio/Video started!');
    },
    audioVideoDidStop: (sessionStatus: MeetingSessionStatus) => {
      logger.warn(`Audio/Video stopped with code: ${MeetingSessionStatusCode[sessionStatus.statusCode]}`);
    },
    audioVideoDidStartConnecting: (reconnecting: boolean) => {
      logger.info(reconnecting ? 'Reconnecting to meeting...' : 'Connecting to meeting...');
    },
    connectionDidSuggestStop: () => {
        logger.info('Connection suggested stop. Leaving meeting...');
        meetingSession.audioVideo.stop();
    },
    // ... other delegate methods as needed
  };
  
  meetingSession.audioVideo.addObserver(meetingDelegate);

  try {
    // Ensure microphone and camera permissions are granted before starting
    await navigator.mediaDevices.getUserMedia({ audio: true, video: true });
    logger.info('Microphone and camera permissions granted.');

    await meetingSession.audioVideo.start();
    logger.info('Meeting session started successfully!');

    // Example: List and select audio input devices
    const audioInputDevices = await meetingSession.audioVideo.listAudioInputDevices();
    if (audioInputDevices.length > 0) {
      await meetingSession.audioVideo.chooseAudioInputDevice(audioInputDevices[0].deviceId);
      logger.info(`Selected audio input device: ${audioInputDevices[0].label}`);
    }

    // Clean up after 30 seconds for demonstration
    setTimeout(() => {
      meetingSession.audioVideo.stop();
      logger.info('Meeting session stopped after 30 seconds.');
    }, 30000);

  } catch (error) {
    logger.error(`Error starting meeting session: ${error}`);
  }
}

initializeMeetingSession();

view raw JSON →