Skip to main content

Uniapp SDK quick integration

The current DCloud plugin is meshstream-p2p 1.0.6, available from the DCloud plugin market. It targets uni-app Vue 3 App and does not provide a player or decoder.

Before running the code, complete Installation and setup, prepare your SDK Key and playable media URL, and configure the application network policy.

Minimal integration​

Use the JavaScript entry point from a page:

import { MeshStream } from '@/uni_modules/meshstream-p2p/javascript.js'

const client = await MeshStream.create({
key: 'your_sdk_key',
p2pEnabled: true,
})
const session = await MeshStream.createPlaybackSession(client.clientId, {
url: 'https://cdn.example.com/live/playlist.m3u8',
contentId: 'live-channel-42',
mimeType: 'm3u8',
})

// Bind session.playbackUrl to the existing video player.
await MeshStream.updateCurrentPositionMs(client.clientId, session.sessionId, positionMs)
await MeshStream.updateBufferedDurationMs(client.clientId, session.sessionId, bufferedDurationMs)

Close resources when content changes or the page is destroyed:

await MeshStream.closeSession(client.clientId, session.sessionId)
await MeshStream.closeClient(client.clientId)

When P2P is unavailable, playback continues through CDN. Use await MeshStream.preload(client.clientId, session.sessionId) for a candidate session, and pair subscribeEvents with unsubscribeEvents.

Version and verification​

The Uniapp plugin version is independent of the native Android/iOS SDK versions. Record the plugin, HBuilderX base, platform, and player versions when diagnosing issues. See the Uniapp SDK repository for the example and release records.

Related guides: Installation and setup · Advanced usage.