Join your first RTC channel
This guide walks you through one video channel: your server creates a channel that requires tickets and issues a ticket to a user, and a signed-in Web client joins with it. Channels are unrelated to IM groups and call invitations. For what each platform supports, see Channel overview.
1. Check it's enabled and your versions
Choose the tenant and app in the console and make sure all of these hold:
- The app is active and the audio/video policy
rtc_enabledis on. - The platform's global channel switch and the app's channel switch are both on. The app's channel switch is on by default, and the platform can turn it off separately.
- The app's audio/video balance is positive. Top up under "Audio/video billing" by WeChat Pay or bank transfer; the balance only increases once the payment arrives. The plan balance and other apps' balances can't be used instead; see Top-ups. Apps not yet switched to the new billing are checked against their old plan's permissions.
- The platform has a media service available that supports the new metering protocol, with concurrency allowance to spare.
- The client uses an SDK version with the channel API, with
rtc_channels_enabled=trueandrtc_channels_protocol_version=1, andchannels.supportedistrueon the current platform. Each SDK's docs give its version and how to get it; upgrading the server doesn't upgrade clients.
Getting an App Token, creating users and getting sign-in tokens work as in Send your first message. For what $IM_API, $ORG, $APP and $APP_TOKEN mean below, see Server overview.
2. Create a channel
On your server, run:
curl -X PUT "$IM_API/$ORG/$APP/rtc/channels/meeting-demo" \
-H "Authorization: Bearer $APP_TOKEN" -H "Content-Type: application/json" \
-d '{"name":"项目会议","media":"video","access_mode":"ticket","max_participants":16}'The channel.channel_id in the response is the channel ID the client uses to join. For creation parameters and repeated requests, see Managing channels.
3. Issue a ticket to the user
Assuming alice is already an active user of this app:
curl -X POST "$IM_API/$ORG/$APP/rtc/channels/meeting-demo/tickets" \
-H "Authorization: Bearer $APP_TOKEN" -H "Content-Type: application/json" \
-d '{"users":[{"username":"alice","role":"publisher"}],"ttl_seconds":120}'Hand alice's ticket from the response to alice through your own authenticated business API; don't give it to anyone else or write it to logs. If the response to an issue request is lost, don't just retry the issue; see Channel tickets for the rules. To let a second person join, issue them their own ticket.
4. Sign in and join
Below, im is already signed in as alice per the Web quickstart, and the ticket is kept only in a variable in memory:
if (!im.channels.supported) throw new Error('当前环境不支持频道媒体');
const channel = await im.channels.join('meeting-demo', {
ticket: ticketFromBusinessServer,
});
// 用户点击麦克风 / 摄像头按钮后调用,默认均关闭。
await channel.setMicrophoneEnabled(true);
await channel.setCameraEnabled(true);
// 页面退出时:
await channel.leave();For showing video, subscribing, unsubscribing and resuming, see Web channels. For Android, Flutter / iOS, Tauri and UniApp, see Client SDKs; for UniApp H5 you can run the H5 Demo directly to try the channel flow, and the UniApp app (Android / iOS) App Demo has a channel page to try on a real device.
5. Check status and usage
Under "RTC channels" in the app's details in the console you can view channels and sessions, remove or ban members, and close channels; developer can only view, while admin can manage; see RTC channel management. For finalizing and correcting usage, see Channel stats and Standalone channel usage and automatic corrections.
The same user can't be in a call and a channel at once; right after leaving, media resources may still be being reclaimed, and joining meanwhile says busy. A 202 means cleanup is still in progress, not that the resources are released.
6. Check usage and troubleshoot
First try a short voice and video session in a separate test app, then check this month's standard duration, deducted minutes and transactions under "Audio/video billing". The daily participant minutes from the channel stats API are a different measure and aren't charged again. For example, two people each receiving HD video for 10 minutes come to 80 standard minutes at the default rates; see Worked examples.
When joining fails, check in this order: app and balance → whether the top-up order has arrived → audio/video and channel switches → concurrency allowance and whether the user is already in another call or channel → media service and network. Note the error code, details.reason and request ID; don't keep re-issuing tickets or recreating channels, which hides configuration problems.
