Amazon Chime SDK for JavaScript
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
-
TypeError: meetingSession.audioVideo.chooseVideoInputDevice is not a function
cause The method name `chooseVideoInputDevice` was changed in version 3.0.0 of the SDK.fixFor selecting a video input without immediately starting it, use `meetingSession.audioVideo.selectVideoInputDevice(device)`. To select and start video input, use `meetingSession.audioVideo.startVideoInputDevice(device)`. -
Meeting failed: AudioCallAtCapacity
cause The meeting has reached its maximum attendee limit, typically 250.fixThis is a server-side limit. Ensure that the number of attendees does not exceed the maximum limit. Track attendee counts in your server application using Amazon Chime SDK event notifications to prevent exceeding capacity. -
Meeting failed: MeetingEnded
cause The meeting was terminated by a backend API call or automatically ended due to inactivity.fixVerify that the `DeleteMeeting` API action was not called prematurely on your server application. Implement logic to handle meeting inactivity detection and inform users if a meeting is ending. -
AccessDeniedException: User is not authorized to perform this operation.
cause The IAM credentials used by your backend service lack the necessary permissions to call Amazon Chime SDK APIs (e.g., `CreateMeeting`, `CreateAttendee`).fixReview your AWS IAM policy associated with the credentials used by your backend. Ensure it grants sufficient permissions for the specific Amazon Chime SDK API actions being invoked.
Warnings
- breaking Version 3.0.0 introduced significant breaking changes, primarily decoupling the device controller from the audio/video controller. This requires updates to how devices are managed and selected outside of an active meeting session.
- breaking Support for Safari 12 and WebRTC Plan B was deprecated and removed in version 3.0.0. This may affect older browser compatibility.
- gotcha The Amazon Chime SDK for JavaScript is a client-side library and *requires* a custom backend service to provision meetings and attendees. It does not directly interact with AWS Chime API endpoints from the client.
- gotcha Meeting sessions have capacity limits (e.g., 250 attendees) and can automatically end due to inactivity or if deleted via the API. Client-side errors like 'AudioCallAtCapacity' or 'MeetingEnded' indicate these server-side conditions.
- gotcha Browser permissions for microphone and camera are critical. Failure to grant these can lead to `deviceLabelTriggerFailed`, `audioInputFailed`, or `videoInputFailed` events, preventing users from participating in audio/video.
Install
-
npm install amazon-chime-sdk-js -
yarn add amazon-chime-sdk-js -
pnpm add amazon-chime-sdk-js
Imports
- ConsoleLogger
const { ConsoleLogger } = require('amazon-chime-sdk-js');import { ConsoleLogger, LogLevel } from 'amazon-chime-sdk-js'; - DefaultMeetingSession
import DefaultMeetingSession from 'amazon-chime-sdk-js';
import { DefaultMeetingSession } from 'amazon-chime-sdk-js'; - MeetingSessionConfiguration
import { MessagingSessionConfiguration } from 'amazon-chime-sdk-js'; // for meeting configimport { MeetingSessionConfiguration } from 'amazon-chime-sdk-js'; - DefaultDeviceController
import { DefaultDeviceController } from 'amazon-chime-sdk-js';
Quickstart
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();