1.1.0 • Published yesterday
rtn-miniprogram-sdk
Licence
MIT
Version
1.1.0
Deps
0
Size
204 kB
Vulns
0
Weekly
0
rtn-miniprogram-sdk
RTN SDK for WeChat Mini Program RTC scenarios.
The package exposes a URL-based Client facade for Mini Program components:
publish()returns an RTMP URL forlive-pusher.subscribe(uid)returns an RTMP URL forlive-player.- Signaling uses the shared SignalAccess protocol from
@open/infra. - Runtime I/O uses Mini Program APIs through
wx.requestandwx.connectSocket.
Install
import { Client } from 'rtn-miniprogram-sdk';
Basic flow
const client = new Client();
client.setParameters({
ConfPriCloudAddr: {
ServerAdd: 'primary.example.com',
Port: 1443,
Wss: true,
},
ConfPriCloudAddr1: {
ServerAdd: 'backup.example.com',
Port: 8080,
Wss: false,
},
});
await client.init(appId);
await client.join(token, channel, uid, false);
const pushUrl = await client.publish();
const { url: playUrl } = await client.subscribe(remoteUid);
await client.unpublish();
await client.unsubscribe(remoteUid);
await client.leave();
SignalAccess gateways
Configure custom SignalAccess gateways with the same setParameters contract used by open-rtn-sdk.
ConfPriCloudAddr and ConfPriCloudAddr1 are read when join() creates the SignalAccess session. When no custom gateway is configured, the SDK falls back to the open-rtn mainline default gateway:
https://pro.openrtn.agrtc.cn:1443
Wss controls both the gateway request scheme and the preferred WebSocket transport passed into service.access.resolve:
Wss: trueuseshttpsgateway requests and expects securewsssignaling nodes.Wss: falseuseshttpgateway requests and expects plainwssignaling nodes.
Lifecycle rules
- Call
init(appId)beforejoin(). join()resolves the gateway, connects SignalAccess, sendsauth.session.login, storessessionId, and then reportsclient.status.updatewithout waiting for a response.leave()sendsauth.session.logoutwith the storedsessionId, closes signaling, and clears local session, publish, and subscribe state.- If logout fails, local state is still cleared and the logout error is surfaced to the caller.
destroy()closes the local connection and clears state without sending logout.
Publish and subscribe rules
publish()is only valid forhost.- The first
publish()sendsrtc.stream.publishwithallocUrlType: 'rtmp', storesrtmpUrlandpubSessionId, and returns the RTMP push URL. - Repeated
publish()returns the cached push URL. unpublish()sendsrtc.stream.unpublishonly when a publish exists. Calling it with no publish is a no-op.subscribe(uid)sendsrtc.stream.subscribewithallocUrlType: 'rtmp', stores the returnedrtmpUrl, and returns{ url, rotation }.- Repeated
subscribe(uid)returns the cached play URL. unsubscribe(uid)sendsrtc.stream.unsubscribeonly when a subscription exists. Calling it with no subscription is a no-op.
Role rules
setRole(role)beforejoin()only updates local role and writes the selected role into the next login request.setRole(role)afterjoin()sendsrtc.stream.setrole.- Switching from published
hosttoaudienceinvalidates the existing push URL and clears the local publish session id. The Mini Program demo must clear the boundlive-pusherURL at the same time.
Current limitations
- WHEP playback is intentionally deferred. The current implementation stabilizes RTMP publish and subscribe first.
- Component status reporting methods,
setAudioCodec, and channel media relay APIs are not part of the current public Mini Program SDK surface. muteLocal,unmuteLocal,mute,unmute,setRemoteVideoStreamType, andupdatePushUrlreturnNOT_IMPLEMENTEDuntil matching protocol commands and server behavior are confirmed.- SignalAccess reconnect is implemented: initial join retries recoverable SignalAccess failures while staying in
CONNECTING, and an established session entersRECONNECTINGbefore logging in again. Native Mini Programlive-pusher/live-playerpublish and subscribe URL recovery remains application-controlled.
Verification
pnpm --filter rtn-miniprogram-sdk run check
pnpm --filter rtn-miniprogram-sdk run build
pnpm --filter rtn-miniprogram-sdk run docs:api
pnpm consume:check:rtn-miniprogram-sdk
pnpm release:check rtn-miniprogram-sdk