Skip to content

Classroom & Permissions API

Classroom control (start/end/mute/layout) and permission checks.

API Reference

canControlClass()

Whether the current user can control the classroom lifecycle (start/end class; usually teacher only).

Returns: boolean


canManageMember()

Whether the current user can manage members (kick/mute/stage/grant; usually teacher/assistant only).

Returns: boolean


canOpenCamera()

Whether the current user can open the camera (considering global video-off state + individual permission).

Returns: boolean


canOpenMic()

Whether the current user can open the microphone (considering global mute-all state + individual permission).

Returns: boolean


canOperateBoard()

Whether the current user has whiteboard permission (draw, switch tools, turn pages, etc.).

后台只有一个统一的 board 权限,涵盖所有白板操作。 The backend has a single unified board permission covering all whiteboard operations. Teacher/assistant default true; students need explicit grant via memberAction(Board_Enable).

Returns: boolean


canOperateDocument()

Whether the current user can manage courseware (upload/delete/bind to board; usually teacher/assistant only).

Returns: boolean


canSendChatMessage()

Whether the current user can send chat messages (considering silence mode + role permission + individual mute state).

Returns: boolean


canShareScreen()

Whether the current user can share their screen (requires screenSharePermission > 0).

Returns: boolean


endClass()

End the class (teacher/assistant only). The final state update is driven by IM class_end signal, not immediately reflected locally.

Returns: Promise<TResult<void>>

Example:

ts
const result = await classroom.endClass();
if (result.ok) {
  // 结课请求已发送,等待 IM 信令确认后 classStatus$ 变为 'ended'
  // End request sent; classStatus$ updates to 'ended' once IM signal arrives
}

getAllPermissions()

Get the permission info list for all online users.

Returns: MemberInfo[]

Example:

ts
const all = classroom.getAllPermissions();
const onStage = all.filter((p) => p.stage);

getClassInfo()

Actively fetch the latest classroom info (SDK auto-updates on join; use this for forced refresh scenarios).

ParameterTypeDescription
allTask?booleantrue=同时拉取所有任务列表(成本较高,按需使用)/ true=also fetch all tasks (costly; use sparingly)

Returns: Promise<TResult<ClassInfo>>

Example:

ts
const result = await classroom.getClassInfo();
if (result.ok) console.log('课堂名:', result.data.className);

getTasks()

Query the classroom task list (local cache first; when seq is provided, compares with server and refreshes only on diff).

ParameterTypeDescription
seq?numberLocally known latest task seq (for incremental check)

Returns: Promise<TResult<GetTaskListResult>>

Example:

ts
const r = await classroom.getTasks();
if (r.ok) renderTaskPanel(r.data.list);

getTranslateConfig()

Get the current translation config synchronously from local cache (includes enabled state and target language).

Returns: TranslateConfig

Example:

ts
const cfg = classroom.getTranslateConfig();
if (cfg.state === 1) console.log('当前自动翻译目标语言:', cfg.lang);

getUserPermission()

Get permission info for a specific user (from the local memberMap$ cache).

ParameterTypeDescription
userIdstringTarget user ID

Returns: MemberInfo | null

Example:

ts
const perm = classroom.getUserPermission('student_001');
if (perm?.stage) { /* 在台上 / on stage */ }

isFeatureAvailable()

Three-layer permission check: package feature toggle → dynamic grant (teacher grants/revokes at runtime) → role default capability.

Pass a key from PackageFeatureConfig or RoleCapabilities to check if the current user has that capability.

ParameterTypeDescription
featurekeyof PackageFeatureConfig | keyof RoleCapabilitiesFeature or capability name

Returns: boolean

Example:

ts
if (classroom.isFeatureAvailable('memberManage')) {
  // 可管理成员 / Can manage members
}
if (classroom.isFeatureAvailable('enableBeauty')) {
  // 套餐支持美颜 / Package supports beauty
}

isOnStage()

Whether the current user is currently on stage (stage=true, can use audio/video capabilities).

Returns: boolean


muteAudioAll()

Mute/unmute all participants' audio (teacher/assistant only), affecting all students' microphone permissions.

Status is reflected in state.muteAll$; students should call canOpenMic() to check whether opening the mic is allowed.

ParameterTypeDescription
mutebooleantrue=全体静音 / mute all, false=解除全体静音 / unmute all

Returns: Promise<TResult<void>>

Example:

ts
await classroom.muteAudioAll(true);   // 全员禁麦 / mute all
await classroom.muteAudioAll(false);  // 解除 / unmute

muteVideoAll()

Disable/enable all participants' video (teacher/assistant only), affecting all students' camera permissions.

Status is reflected in state.muteVideoAll$; students should call canOpenCamera() to check.

ParameterTypeDescription
mutebooleantrue=全体禁视频 / disable all video, false=解除 / re-enable

Returns: Promise<TResult<void>>

Example:

ts
await classroom.muteVideoAll(true);  // 全员关摄像头 / disable all video

releaseResource()

Release a held resource (e.g., release the lock when stopping screen share, allowing others to use it).

ParameterTypeDescription
namestringResource name

Returns: Promise<TResult<void>>

Example:

ts
await classroom.releaseResource('screen_share');

requireResource()

Acquire a resource (fails when the current holder count reaches the limit); once acquired, other users' requests are rejected.

ParameterTypeDescription
namestringResource name (e.g., 'screen_share', 'mic')

Returns: Promise<TResult<void>>

Example:

ts
const r = await classroom.requireResource('screen_share');
if (!r.ok) toast.warn('资源被占用');

revokeClassMessage()

Revoke a group chat message by IM sequence number (teacher/assistant only).

revokeMessage() 的区别:此方法按 IM seq 撤回他人消息(需老师/助教权限); Difference from revokeMessage(): this uses IM seq and revokes others' messages (teacher/assistant required); revokeMessage() uses message ID and only revokes the caller's own messages.

ParameterTypeDescription
messageSeqnumberIM message sequence number (Message.seq)

Returns: Promise<TResult<void>>

Example:

ts
await classroom.revokeClassMessage(message.seq);

setClassCustomData()

Set classroom custom data (stored on server; readable by all participants via state.classInfo$.customData).

Used to extend classroom-level custom state (e.g., teaching phase, current docId, temporary config).

ParameterTypeDescription
dataobjectAny serializable JSON object

Returns: Promise<TResult<void>>

Example:

ts
await classroom.setClassCustomData({ phase: 'lecture', currentDocId: 'doc_123' });

setEnableStage()

Enable/disable the hand-raise-to-stage feature (teacher/assistant only); when disabled, students cannot raise hands.

Status is reflected in state.enableStage$ and emits TEvent.ENABLE_STAGE_CHANGED.

ParameterTypeDescription
enablebooleantrue=开启举手功能 / enable hand-raise, false=关闭 / disable

Returns: Promise<TResult<void>>

Example:

ts
await classroom.setEnableStage(false); // 关闭举手 / disable hand-raise

setLayout()

Switch the classroom view layout (teacher/assistant only); all participants switch synchronously.

The result is pushed via state.classLayout$; the UIKit layer re-arranges the main area accordingly.

ParameterTypeDescription
layoutClassLayoutLayout type:

Returns: Promise<TResult<void>>

Example:

ts
await classroom.setLayout('doc');     // 课件优先 / doc-priority
await classroom.setLayout('default'); // 还原默认 / restore default

setResourceLimit()

Set a resource concurrency limit for exclusive resource management (e.g., only one person can screen-share at a time).

Works with requireResource() / releaseResource() to achieve distributed lock semantics.

ParameterTypeDescription
namestringResource name (e.g., 'screen_share')
limitnumberMaximum number of concurrent holders

Returns: Promise<TResult<void>>

Example:

ts
// 排他锁:屏幕共享同一时刻只允许 1 人 / Exclusive lock: only 1 screen-share at a time
await classroom.setResourceLimit('screen_share', 1);
// 学生端开启屏幕共享前先抢锁 / Acquire lock before sharing
const r = await classroom.requireResource('screen_share');
if (r.ok) {
  await classroom.startScreenShare();
} else {
  toast.warn('已有他人在共享屏幕');
}
// 停止共享时释放锁 / Release on stop
await classroom.stopScreenShare();
await classroom.releaseResource('screen_share');

setSilenceMode()

Set the chat silence mode to control students' messaging permissions in the classroom (teacher/assistant only).

ParameterTypeDescription
modeSilenceModeSilence mode:

Returns: Promise<TResult<void>>

Example:

ts
// 全员禁言 / Mute all students
await classroom.setSilenceMode('muteAll');
// 恢复自由发言 / Restore free chat
await classroom.setSilenceMode('freeChat');
// 仅允许私聊(学生不能发公屏消息)/ Only allow private messages
await classroom.setSilenceMode('privateOnly');

setTranslate()

Enable/disable automatic IM message translation.

Once enabled, incoming group messages include translations in the target language (via Message.translation).

ParameterTypeDescription
state0 | 10=关闭自动翻译 / disable, 1=开启自动翻译 / enable
langstringTarget language code (e.g., 'zh', 'en', 'ja')

Returns: Promise<TResult<void>>

Example:

ts
// 把所有消息自动翻译成英文 / Auto-translate all messages to English
await classroom.setTranslate(1, 'en');

// 关闭自动翻译 / Disable
await classroom.setTranslate(0, 'en');

startClass()

Start the class (teacher/assistant only). Classroom status transitions to started; all participants receive TEvent.CLASS_START synchronously.

Returns: Promise<TResult<void>>

Example:

ts
const result = await classroom.startClass();
if (result.ok) {
  // 课堂已开始,UI 可切换到上课状态
  // Class started — switch UI to in-class mode
}

stopTask()

Stop a classroom task (teacher only); after stopping, the task is no longer displayed to students.

ParameterTypeDescription
taskIdstringTask ID (from updateTask result)

Returns: Promise<TResult<void>>

Example:

ts
await classroom.stopTask('task_001');

submitClassRate()

Submit post-class rating (1-5 stars + comment text; call after class ends).

ParameterTypeDescription
paramSubmitRateParamRating params (score + comment)

Returns: Promise<TResult<void>>

Example:

ts
await classroom.submitClassRate({ score: 5, content: '老师讲得很好' });

translate()

Manually translate a single IM message (used when auto-translation is off and the user clicks a message for on-demand translation).

The translation is pushed to recipients via a message update event, written to Message.translation.

ParameterTypeDescription
fromstringSender userId
seqnumberMessage's IM sequence number
messagestringOriginal message text content
langstringTarget language code

Returns: Promise<TResult<void>>

Example:

ts
// 用户点击某条消息的"翻译"按钮 / User clicks "translate" on a message
await classroom.translate(msg.from, msg.seq, msg.text, 'zh');

updateTask()

Create or update a classroom task (quiz/timer, etc.; teacher only).

After update, state.taskList$ auto-syncs and TEvent.TASK_UPDATED fires.

ParameterTypeDescription
paramUpdateTaskParamTask params (type, content, config, etc.)

Returns: Promise<TResult<TaskInfo>>

Example:

ts
const result = await classroom.updateTask({
  taskType: 1,                     // 任务类型(业务约定)/ task type (business-defined)
  content: { question: '1+1=?' },  // 自定义内容 / custom content
});
if (result.ok) console.log('taskId:', result.data.taskId);