AKStream.Next · 文档中心

Web/H5 RTC SDK method reference

Web/H5 RTC SDK method reference

Applies to the @akstream/rtc-web-sdk delivered with AKStream.Next the matching version. AkRtcH5Client is an alias of AkRtcWebClient. Android WebView and iOS WKWebView use these browser methods too; the native host still handles certificates, media permissions, and foreground/background behavior. This page documents the public SDK methods, not an application UI. Complete the Web integration walkthrough first.

import { AkRtcWebClient } from '@akstream/rtc-web-sdk'
const client = new AkRtcWebClient(serverUrl, { onState: (state, detail) => console.log(state, detail) })
const joined = await client.join(roomId, accessTicket, { platform: 'pc-web' })
if (joined.admissionStatus === 'Admitted') await client.startCameraAndMicrophone({ audio: true, video: true })

serverUrl is an HTTPS origin trusted by the device. accessTicket is a one-use ticket issued by your business backend for this person and meeting. Unless stated otherwise, asynchronous failures reject the Promise. On 401, obtain a new ticket or login; 403 means the current role, device, or permission is insufficient and must not be retried indefinitely. A missing retryable value means unknown.

Session and identity

Method Input Output Purpose and edge cases
new AkRtcWebClient(serverUrl, events?) HTTPS service origin; optional callbacks Client instance Create one instance per meeting session. Never put a platform API token in the browser.
join(roomId, accessTicket, options?) Room ID and one-use ticket; autoSubscribe, passcode, platform, clientVersion are optional RtcJoinResult: participant, participantToken, expiry, final capabilities, admissionStatus A consumed ticket cannot be replayed. Waiting is admission pending, not permission to capture or publish. The SDK renews the device token.
createMeeting(settings, creator) Room settings and a business-backend creator(settings) callback {roomId, accessTicket, ...} The SDK passes an idempotency key and validates the result. The callback must not expose management credentials. Retry the same business request with the same settings.
listDemoRooms() / createDemoMeeting(settings) / issueDemoAccessTicket(options) Demo room and ticket options Demo room list, creation result, or test ticket Isolated test environment only; production tickets come from your backend.
listMembers() None Member IDs, names, roles, and states Refresh or follow events after leave, device replacement, or host transfer.
refreshMedia() None Promise<void> Reconcile publications and subscriptions. The SDK already reconnects after network loss; do not poll it in a tight loop.
leave(options?) Optional leave options Promise<void> Release this device's media, signaling, and subscriptions. Use one cleanup path for navigation and page teardown.

RtcJoinResult.capabilities are the server's final grants, not the capabilities requested by the client. The SDK manages participantToken; do not persist or log it.

Local capture, devices, and screen sharing

Method Input Output Purpose and edge cases
startCameraAndMicrophone(options?) Audio/video toggles, device IDs, facing mode, desired width/height/frame rate MediaStream Request system permission from a user action, then publish. A local stream does not prove remote viewers received frames.
getLocalMediaState() None Effective mic/camera/screen-sharing and permission flags Render controls from this state rather than flipping a local Boolean on click.
setTrackEnabled(kind, enabled) MicrophoneAudio or CameraVideo; Boolean Promise<void> Mute or disable locally. Setting true cannot override host revocation or an OS denial.
recoverLocalMedia() None Promise<void> Explicit capture recovery; occupied devices, OS permission, or host policy may still block it.
listMicrophones() / listCameras() None Device ID, group ID, and label lists Labels may be blank before permission. Query again after a device change.
setMicrophoneDevice(deviceId) / setCameraDevice(deviceId) Browser device ID New MediaStreamTrack or null Switch the real input and handle lost devices or revoked permission.
getInputDeviceState() None Current microphone and camera IDs Keep a selector in sync; IDs are not stable cross-meeting hardware identities.
switchCamera(deviceIdOrOptions?) Camera ID or capture options New video track Commonly switches front/back cameras on mobile. Trust the returned track and state callback.
getVideoModes() / setCameraQuality(quality) Target width, height, and frame rate Supported modes; quality result or pending Device and host policy constrain targets. pending does not mean the requested mode is active.
startScreenShare() / stopScreenShare() Start requires a user gesture and OS/browser picker MediaStream / void Screen media is a separate publication. Watch onScreenShareEnded for a system-level stop.
getScreenShareSupport() None {available, reason} Check browser and host support before showing the action.
getCameraOverlaySupport() / startCameraOverlay(element) Video element Support result / void Picture-in-picture depends on browser/host support; it does not change server publication.

Remote media and presentation

Method Input Output Purpose and edge cases
listPublications() None RtcPublication[] One member may publish mic, camera, and screen independently. Key media by publicationId.
syncSubscriptions(publications) Current visible publications One PromiseSettledResult<void> per item A failed subscription does not discard successful subscriptions.
attachRemoteMedia(subscriptionId, element, options?) Subscription ID, audio/video element, optional volume/rotation Promise<void> Bind received media to host UI. Browser autoplay may still require a click.
detachRemoteMedia(subscriptionId, element) Same ID and element void Detach when removing a view and on onRemoteTrackRemoved.
attachLocalPreview(element, stream) Local video element and stream or null {hasVideo} Mute the local preview to avoid speaker feedback.
setRemoteAudioVolume(subscriptionId, volume) Subscription ID and 0–1 volume Applied numeric volume Local playback only; this does not mute another participant.
setRemoteVideoTransform(subscriptionId, transform?) / setRemotePresentation(publicationId, transform?) Mirror, flip, rotation Normalized transform Display-only; original recordings are unchanged. Do not mix subscription and publication IDs.
getRemotePresentation(publicationId) / setLocalVideoTransform(element, transform?) Publication ID or local video element Current/normalized transform Presentation state is not a camera's physical orientation.
getActiveSpeakers() / getActiveSpeakerSupport() None Active members and levels / support result Media activity detection, not speech recognition or identity proof.
setRemoteVolume(volume) 0–1 void Overall local output level for remote audio, not a host moderation action.

Collaboration, control, recording, and diagnostics

Method Input Output Purpose and edge cases
sendChatMessage(text, options?) Text; optional targetParticipantId and payload Local request ID A direct message is visible only to sender and target. Confirm final delivery through chat/event callbacks.
listChatHistory(afterSequence?, pageSize?) Sequence cursor and page size {rows, ...} Follow the sequence cursor; one page is not the complete history.
uploadAttachment(file, options?) File/Blob, target, caption, chat/whiteboard purpose, name RtcAttachmentIssue Device and permission are rechecked at commit. A whiteboard image must be referenced by a board operation afterward.
resolveAttachment(downloadUrl, metadata?) Authorized URL; optional name/type Browser object URL Use only for currently visible attachments; do not store it as a permanent public URL.
getWhiteboardEvents() / attachWhiteboard(container) Whiteboard container Current object events / cleanup function The optional UI is hosted by your app. Call cleanup on teardown.
sendSignal(type, payload?) Supported signal type and data Request ID Advanced integration only. Prefer the performRoomAction allowlist for room control.
performRoomAction(action, payload?) Name and fields from room control actions Action response The server rechecks current host, device, and grants. The SDK does not accept arbitrary endpoint URLs.
startContinuousRecording() / stopContinuousRecording(recordingId) / getContinuousRecording() Stop requires this run's ID Active recording state or null Start/stop require the current host. Stopping means finalizing; historical runs use the separate archive client.
getPublicationStats() / getMediaDiagnostics() None Publication stats / media diagnostics Troubleshooting data does not prove server-side recording succeeded.
reportEndpointInfo() / getEndpointInfo() None Local report / online device reports Reports available parameters without hardware-unique identifiers; server reports are recent-window data.
getAudioOutputState() / getAudioOutputCapabilities() / getAudioOutputDevices() / setAudioOutput(deviceId) Output ID State/support/list/void Output selection depends on browser support and permission; failure need not end the meeting.
getNativeScreenSession() / installNativeHostBridge(target?) Trusted native-host Window Temporary context / cleanup function Trusted native host only. The context includes short-lived credentials: never log or forward it to third-party pages.
attachMeetingControls(container) Host element Cleanup function with tab selection Optional example UI. Your app may supply its own UI while keeping protocol handling in the SDK.

Callbacks and failures

Subscribe through constructor events. On teardown, call leave() and remove the DOM your app created. Events may be replayed after reconnect: use event sequence and current session identity, and never apply an old kick or host action to a replacement session.

Callback Main data Host action
onState(state, detail) / onAdmission() / onAdmissionDenied() Connectivity and admission Show waiting without enabling capture; obtain new authorization after denial.
onRemoteTrack(remote) / onRemoteTrackRemoved(subscriptionId) / onTopologyChanged() Publication, subscription, and track Create/release a view per media publication. Screen and camera stay separate.
onLocalMediaState(state) / onCaptureUnavailable(kind, message) / onPublicationUnavailable(kind, message) Effective state and failure reason Update buttons from actual state, not local preview alone.
onContinuousRecordingChanged(recording) {recordingId,state,originAtUtc,...} or null Show Recording/Stopping; null only means no active run.
onRoomEvent(event) / onChatMessage(message) / onWhiteboardChanged(events) Sequenced events, chat, board objects Apply visibility and ordering; do not expose direct messages.
onActiveSpeakersChanged(speakers) / onVideoGeometry(value) / onVideoQualityChanged(result) Level, aspect ratio, effective quality Speaker highlighting is activity detection; distinguish target from actual quality.
onInputDeviceChanged(state) / onAudioOutputChanged(state) / onLocalMicrophoneChanged(track,settings) / onLocalCameraChanged(track,settings) Device IDs, track, effective settings Refresh selectors and preview; detach old tracks from replacement views.
onModeration(notice) / onSignal(message) Host policy notice and raw signaling Check current device session before updating UI. Most apps need not parse raw signaling.
onKicked(reason) / onRoomClosed() / onLeft() / onScreenShareEnded() Lifecycle Release media and views. Do not reuse an old ticket after a kick.

The definitive TypeScript declarations ship in Clients/AKStream.Rtc.WebSDK/index.d.ts. See archive methods and room action payloads for the other public surfaces.