Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
CloudRecordingClient
✓ import { CloudRecordingClient } from 'agora-rest-client'
✗ const CloudRecordingClient = require('agora-rest-client')
ESM-only since v0.1.0; CommonJS require will fail.
BasicCredential
✓ import { BasicCredential } from 'agora-rest-client'
✗ import AgoraRestClient from 'agora-rest-client'; const { BasicCredential } = AgoraRestClient;
Named export, not default.
DomainArea
✓ import { DomainArea } from 'agora-rest-client'
✗ import { DomainAreaEnum } from 'agora-rest-client'
DomainArea is an enum object, not a string union.
AcquireResourceRes
✓ import { AcquireResourceRes } from 'agora-rest-client'
TypeScript type import; use `import type` for type-only imports.
Shows how to initialize CloudRecordingClient with BasicCredential, acquire a resource, and start cloud recording using the mix scenario API.
import { CloudRecordingClient, BasicCredential, DomainArea, AcquireResourceRes, StartResourceRes, RecordingRequestChannelTypeEnum, QueryMixHLSAndMP4RecordingResourceRes, StopResourceRes } from 'agora-rest-client';
const appId = process.env.AGORA_APP_ID ?? '';
const cname = process.env.AGORA_CHANNEL ?? '';
const uid = process.env.AGORA_UID ?? '';
const username = process.env.AGORA_USERNAME ?? '';
const password = process.env.AGORA_PASSWORD ?? '';
const token = process.env.AGORA_TOKEN ?? '';
if (!appId || !cname || !uid || !username || !password) {
console.error('Missing required environment variables');
process.exit(1);
}
const credential = new BasicCredential(username, password);
const client = new CloudRecordingClient({ appId, credential, domainArea: DomainArea.CN });
async function startRecording() {
const acquireRes: AcquireResourceRes = await client.mixScenario().acquire(cname, uid, { resourceExpiredHour: 1 });
const resourceId = acquireRes.resourceId!;
const startRes: StartResourceRes = await client.mixScenario().start(cname, uid, resourceId, {
token,
recordingConfig: {
channelType: RecordingRequestChannelTypeEnum.Live,
streamTypes: 2,
maxIdleTime: 30,
audioProfile: 2,
transcodingConfig: { width: 640, height: 480, fps: 15 },
},
});
console.log('Recording started:', startRes.sid);
return { resourceId, sid: startRes.sid };
}
startRecording().catch(console.error);
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module /path/to/node_modules/agora-rest-client/dist/index.js not supported.
The package is ESM-only and cannot be required() in CommonJS contexts.
fixConvert your project to ESM (set "type": "module" in package.json) or use dynamic import(): const { CloudRecordingClient } = await import('agora-rest-client'). Error: BasicCredential is not a constructor
Attempting to use BasicCredential without importing it correctly (e.g., using default import or destructuring from the wrong object).
fixEnsure you use: import { BasicCredential } from 'agora-rest-client' TypeError: client.mixScenario is not a function
Trying to call mixScenario on an incorrectly instantiated CloudRecordingClient or using an older version of the SDK.
fixVerify that CloudRecordingClient is imported correctly and instantiated with the required { appId, credential, domainArea }. Property 'resourceId' does not exist on type 'AcquireResourceRes'
Not accounting for the type structure; AcquireResourceRes has resourceId? as optional.
fixCheck the response shape: const resourceId = acquireRes.resourceId; if (!resourceId) throw new Error('Failed to acquire resource'); Audit
Dependencies
No dependency data recorded yet.