
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
@qiniu/miku-delivery-mp
Advanced tools
npm install @qiniu/miku-delivery-mp --save
关于小程序中使用 npm 安装第三方包的注意事项,详见 npm 支持
在使用前,需要在小程序管理后台( https://mp.weixin.qq.com/ )进行如下配置:
“开发/开发管理/开发设置/服务器域名/”页面,向“request合法域名”中添加
https://api.qiniudns.com;
使用 Miku Delivery SDK 分为 2 步:
在小程序的 App 定义处(一般是 app.js
)引入 SDK 并在 App onLaunch
回调中初始化:
import { init as initMD } from '@qiniu/miku-delivery-mp'
App({
onLaunch() {
initMD({
/** Miku 应用信息 */
app: { appID: '<APP_ID>', appSalt: '<APP_SALT>' },
/** 需要被代理的域名列表 */
domains: ['proxy-example.com']
})
}
})
对于基础媒体组件 image
& video
,Miku Delivery SDK 提供了与之对应的组件;这里以视频(video
)为例:
在使用视频(video
)的页面对应的 json 文件中添加
{
"usingComponents": {
"md-video": "@qiniu/miku-delivery-mp/components/video"
}
}
在页面对应的 wxml 文件中,将
<video src="..."><video>
替换为
<md-video src="..."><md-video>
即可(<md-video>
与 <video>
的属性、事件均一致);如果该视频 src
对应的域名出现在上面初始化 SDK 时指定的 domains
中,则该视频资源会被 SDK 代理;若视频 src
对应的域名不在初始化 SDK 时指定的 domains
中,则 SDK 不会对该资源进行代理,即,此时 <md-video>
的行为等价于 <video>
。
video
组件上面提到,<md-video>
与 <video>
的属性、事件均一致;不过如果要通过 VideoContext 操作对应的 video
组件,这里需调整获取 VideoContext 实例的姿势:
首先给 <md-video>
添加 id
(如 video-1
):
<md-video id="video-1" src="..."><md-video>
然后通过 selectComponent
获取到组件的导出:
let mdVideo = this.selectComponent('#video-1')
通过组件实例(mdVideo
)上的 getVideoContext
方法即可得到对应的 VideoContext 实例,如:
let videoContext = mdVideo.getVideoContext()
videoContext.play()
即可控制视频开始播放。
/** 初始化 SDK */
async function init(
/** 初始化配置 */
config: InitConfig
): Promise<void>
/** SDK 初始化配置信息 */
export type InitConfig = {
/** 应用信息 */
app: AppInfo
/** 需要被代理的域名列表 */
domains: string[]
/** 开启 debug 模式 */
debug?: boolean
}
/** App 信息 */
type AppInfo = {
appID: string
appSalt: string
}
/** 组件 @qiniu/miku-delivery-mp/components/video */
// 同 video,见 https://developers.weixin.qq.com/miniprogram/dev/component/video.html
/** 组件 @qiniu/miku-delivery-mp/components/image */
// 同 image,见 https://developers.weixin.qq.com/miniprogram/dev/component/image.html
FAQs
Mini Program SDK for Miku Delivery
The npm package @qiniu/miku-delivery-mp receives a total of 1 weekly downloads. As such, @qiniu/miku-delivery-mp popularity was classified as not popular.
We found that @qiniu/miku-delivery-mp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.