@jp-web/ts-sdk
Version:
视频客服,视频会议Web端及微信小程序端SDK
80 lines (78 loc) • 2.32 kB
JavaScript
Component({
properties: {
config: {
type: Object,
value: {},
observer: function (newVal, oldVal) {
this._propertyObserver(newVal);
}
}
},
data: {
player: null,
playerId: null,
playConfig: {
src: null,
mode: 'RTC',
autoplay: false,
muted: false,
orientation: 'vertical',
objectFit: 'contain',
minCache: 0.1,
maxCache: 0.3,
soundMode: 'speaker',
pictureInPictureMode: [],
autoPauseIfNavigate: true,
autoPauseIfOpenNative: true,
debug: false,
hidden: false
}
},
lifetimes: {
created() {
this.data.playerId = Date.now().toString(10);
},
attached: function () {
this.setData({
playerId: this.data.playerId,
})
this.data.player = wx.createLivePlayerContext(this.data.playerId, this);
},
error(err) {
console.log(err);
}
},
methods: {
play(options) { this.data.player.play(options); },
stop(options) { this.data.player.stop(options); },
mute(options) { this.data.player.mute(options); },
pause(options) { this.data.player.pause(options); },
resume(options) { this.data.player.resume(options); },
requestFullScreen(direction, options) { this.data.player.requestFullScreen({direction, ...options}); },
exitFullScreen(options) { this.data.player.exitFullScreen(options); },
exitPictureInPicture(options) { this.data.player.exitPictureInPicture(options); },
snapshot(quality) { this.data.player.snapshot(quality); },
init(config) {
Object.assign(this.data.playConfig, config);
this.setData({
playConfig: this.data.playConfig
});
},
onStateChange(event) {},
onFullScreenChange(event) {},
onNetStateChange(event) {},
onAudioVolumeNotify(event) {},
onEnterPictureInPicture(event) {},
onLeavePictureInPicture(event) {},
_propertyObserver(data) {
return new Promise((resolve, reject) => {
if (!data) {
reject(`parameter is null.`);
return;
}
Object.assign(this.data.playConfig, data.options);
this.setData({playConfig: this.data.playConfig}, () => resolve());
});
}
}
})