Mini program integration
Platforms and prerequisites
WeChat, Alipay and Douyin entries live in platforms/miniprogram/wechat, alipay and douyin. They share Headless and Rust Core; platform entries install native HTTP, IM and Worker support.
Source bundles require a host monotonicNowMs function, Worker/WASM configuration and provider adapters. Test base-library clock compatibility, media, audio routing and multi-user classrooms in developer tools and on target devices.
Build subpackages
From edu-sdks:
make build-wasm
make build-headless-mp
Preserve the platform entry, shared JS, core.worker.js, WASM and referenced adapter paths. Configure host subpackages and Workers. Adjust the example's require, Worker and WASM paths to the actual layout.
Initialize
const { createEduSdk } = require('./edusdk/index');
async function connectClassroom(entry, hostMonotonicNowMs) {
const sdk = createEduSdk({
appId: entry.appId,
backendUrl: entry.backendUrl,
userToken: entry.userToken,
wasmPath: '/subpackages/edusdk/edusdk_core.wasm.br',
workerPath: 'subpackages/edusdk/core.worker.js',
monotonicNowMs: hostMonotonicNowMs,
});
sdk.on('onError', (error) => console.error(error.code));
try {
await sdk.initialize({
classroomId: entry.classroomId,
userId: entry.userId,
displayName: entry.displayName,
});
} catch (error) {
sdk.destroy();
throw error;
}
return sdk;
}
hostMonotonicNowMs must return finite, nonnegative, nondecreasing milliseconds and remain continuous throughout the SDK lifetime. Use a monotonic clock supported by the target base library. Date.now() is affected by system-clock changes, and timer accumulation is not a substitute.
The shared TypeScript entry receives the classroom and enters through initialize. Browser fetch, DOM APIs and browser storage are not mini program host APIs.
Platform differences
| Platform | Native request port | Integration detail |
|---|---|---|
wx.request | Configure request/download/WebSocket domains and Worker paths | |
| Alipay | my.request | The shared adapter handles native fail callbacks and HTTP status; do not rewrite requests in business code |
| Douyin | tt.request | The adapter passes raw response text to the shared executor |
Allow the actual backendUrl for requests and downloads. Use entry-response addresses for IM WebSocket, whiteboard and assets. SDK sound assets are fixed public resources under backendUrl and carry no user token.
On page exit, call await sdk.leaveClassroom() and call sdk.destroy() in finally. Distribute the shared JS, WASM, Worker and all required provider adapters together.