Repository navigation
en US sdk mini program
WeChat uses the standalone CommonJS AkRtcMiniClient and the matching Demo in Clients/AKStream.Rtc.WeChatMiniProgram. Room control, identity, grants, chat and recording belong to AKStream.Next. Media uses RTMP publishing through live-pusher and HTTP-FLV playback through live-player, rather than browser WebRTC/WHIP/WHEP.
New component error callbacks, playback retry and lifecycle repairs require the updated Mini Program SDK/Demo; replacing only a page or calling new methods on an older SDK directory is insufficient. The SDK implements admission tickets, waiting rooms, combined publication, playback tickets, token renewal, signaling recovery, topology, moderation, attachments and whiteboard. Automated tests use a mocked WeChat runtime. Real publishing/playback, codecs, transforms, permissions and background behavior still require an eligible AppID and physical WeChat devices. Importing the project or passing Node tests does not establish complete device acceptance.
| Capability | Current behavior and limit |
|---|---|
| Camera and microphone | One MiniProgramCombined publication; an input can be disabled locally, while authorization applies to combined publishing |
| Remote media | One HTTP-FLV player per active publication; no additional fixed Demo stream-count limit; stable capacity needs device testing |
| Web/native interoperability | Mini Program publishing declares H264/AAC. Playback depends on actual codecs and media output; an Opus audio track or arbitrary video codec is not made playable by changing its URL |
| UDP/TCP choice | Only mediaTransport: 'auto'; udp/tcp return UNSUPPORTED_MEDIA_TRANSPORT. TURN settings cannot rewrite WeChat component transports |
| Desktop capture, separate audio/video publications, arbitrary microphone selection | Not provided by this adapter; compatible screen video published by another client can be viewed |
| Audio output and volume | speaker/ear selection without physical-route readback; scalar volume degrades to mute/unmute, with fine control via device volume |
| Mirror, rotation and maximize | SDK view settings; maximize is a page layout, not system fullscreen/PiP. Native component transforms need device verification |
| Host actions and recording | Server capabilities authorize actions. Recording is performed by the server, not local device recording |
The pusher's mode="RTC" is a WeChat component mode name. It does not create RTCPeerConnection or establish TURN/TCP support. See media transports.
- Import the Demo into WeChat Developer Tools and configure your AppID.
touristappidpermits inspecting project structure, not proof of media permissions. The Demo currently selects base library 3.7.12; verify the actual WeChat version and available features on devices. - Obtain an eligible category and enable
live-pusher/live-playerunder current WeChat rules. Do not treat AKStream.Next product authorization as component permission. Check the official pusher and player references for current eligibility. - API requests require trusted HTTPS. Configure the actual request, socket, upload and download domains separately. Media URLs must also satisfy native component rules; request-domain registration does not authorize every media destination. See WeChat networking.
- Have the administrator verify the product's public RTMP and HTTPS-FLV entries, certificates, port mappings and publishing/playback authorization callbacks. Third-party integrations use public APIs and do not need server source or database edits.
- Complete the privacy declaration and required privacy/camera/microphone consent. Text in
app.json.permissiondoes not replace user authorization. Follow the official privacy authorization flow; the SDK does not consent for a user.
This AKStream.Next media path does not require embedding TRTC, SDKAppID or media administration secrets in the client. WeChat component eligibility remains a separate requirement.
Your backend authorizes the user and issues a room admission ticket through the public API. Send the approved device baseUrl, roomId, accessTicket and an optional meeting passcode. Management API tokens stay in the backend, outside app.js, device storage and shared URLs. Rejoining requires a fresh one-time ticket.
Demo room discovery, automatic test tickets and meeting creation are Development conveniences. When disabled in production, connect your own ticket backend or use manual entry. This is not an SDK admission failure. The Demo protects a newly created host ticket and asks before replacing it with a regular participant ticket.
Copy the complete miniprogram/sdk directory with its dependencies. In the page below, meeting comes from your backend. Keep SDK state in the current page and avoid logging credentials. See the Mini Program API for details.
const { AkRtcMiniClient } = require('../../sdk')
Page({
data: { waiting: false, players: [], notice: '' },
onLoad() {
this.disposed = false
const update = patch => { if (!this.disposed) this.setData(patch) }
this.rtc = new AkRtcMiniClient({
onSession: patch => update(patch),
onTopology: state => update({ players: state.players }),
onState: message => update({ notice: message }),
onError: error => update({ notice: error.message }),
onLeft: () => update({ players: [], waiting: false })
})
},
async joinWithBusinessTicket(meeting) {
await this.rtc.join({ baseUrl: meeting.baseUrl, roomId: meeting.roomId,
accessTicket: meeting.accessTicket, passcode: meeting.passcode,
audio: false, video: false })
},
onHide() { void this.rtc.setForeground(false) },
onShow() { if (this.rtc) void this.rtc.setForeground(true) },
onUnload() { this.disposed = true; void this.rtc.leave() }
})<text wx:if="{{waiting}}">Waiting for admission</text>
<live-player wx:for="{{players}}" wx:key="publicationId"
src="{{item.url}}" mode="live" autoplay object-fit="contain" />This minimal sketch omits production component callbacks. Forward statechange/error/netstatus, bind audio settings, handle background changes and suppress late callbacks after page disposal as the Demo does. Receive-only admission does not proactively request local camera/microphone permission; waiting clients do not read members or media before admission.
After the user explicitly enables an input, call setMicrophoneEnabled(true) or setCameraEnabled(true). The SDK creates a permitted combined publication and emits pusherUrl/publicationId/sessionGeneration. Bind the URL and autopush, then hand a rendered wx.createLivePusherContext to bindPusherContext.
Bind the current component's generation/publication ID to data-* and forward them unchanged:
| Component event | SDK method |
|---|---|
| Pusher statechange | onPusherState(code, generation, publicationId) |
| Pusher error | onPusherError(detail, generation, publicationId) |
| Pusher netstatus | onPusherNetStatus(detail, generation, publicationId) |
| Player statechange/error |
onPlayerState(publicationId, code, generation) / onPlayerError(publicationId, detail, generation)
|
| Player netstatus | onPlayerNetStatus(publicationId, detail, generation) |
| Audio volume | onAudioVolume(publicationId, volume, generation, local) |
Local preview or a successful request is not proof of delivery. Actual local media state is reported after the component starts publishing; a second device must confirm media reception. On terminal playback failure the Demo exposes a retry button. retryPlayback() renews playback URLs and refreshes players without creating endless new participant sessions.
Moderating either input stops the entire combined publication. Lifting a restriction does not automatically enable capture: the user chooses when to resume.
The SDK handles chat, history, attachment transfer and whiteboard state. Upload/download domains must be registered. WeChat temporary file paths are not durable business file URLs. Your page supplies Canvas context, dimensions and touch events; the SDK manages whiteboard data and write access.
Use performRoomAction(action, payload) or the convenience methods for authorized operations. Only the current host can close the entire meeting; ordinary leave uses leave(). Recording, playback packages and whiteboard writing remain server-authorized. A visible button grants no capability. See room actions and recording/archive.
| Symptom | Check |
|---|---|
| Tool opens the project, but devices show no media | Real AppID, component eligibility, privacy permission, trusted certificates and domains |
| Automatic ticket failure | Development-only endpoint; production uses your business ticket backend |
| 401, consumed ticket or expired identity | Request a fresh admission ticket; do not replay a consumed one; check device time |
| No media while waiting | Expected isolation; obtain host admission first |
| Local preview but no remote video | Real publishing state/error callbacks, public RTMP address and server publication status |
| Black video or missing audio | Actual codecs, HTTPS-FLV output, player callbacks, device mute and routing |
| -2301 or persistent disconnection | Native retries are exhausted; check connectivity and call retryPlayback() without consuming admission tickets repeatedly |
| Previously denied camera/microphone access | Guide the user to settings; do not loop permission prompts or claim enabled media |
| Background/network transition inconsistency | Lifecycle forwarding, component generation, matching SDK distribution and server state |
Before launch, verify receive-only and speaker roles, two physical WeChat devices, actual codecs with Web/Android/iOS, waiting admission/denial, reconnect, backgrounding, moderation, long-session renewal, attachments, whiteboard, recording and leave cleanup. Source delivery and mocked tests do not replace real media acceptance.