UNPKG

@tencentcloud/trtc-component-uniapp

Version:

TRTC Uni-app Components for WeChat Mini Program

307 lines (306 loc) 11.7 kB
import v, { translateTRTCStreamId as _ } from "@tencentcloud/trtc-cloud-wx"; export * from "@tencentcloud/trtc-cloud-wx"; import { default as G } from "@tencentcloud/trtc-cloud-wx"; import { resolveComponent as d, openBlock as h, createElementBlock as y, createVNode as g, createBlock as T, createCommentVNode as C } from "vue"; const b = (e, n) => { const r = e.__vccOpts || e; for (const [a, t] of n) r[a] = t; return r; }, l = v.getTRTCShareInstance(), u = l.trtc, c = l.InterfaceEventEmitter, I = { name: "TRTCPusher", props: { pictureInPictureMode: { type: [String, Array], default: void 0 } }, data() { return { pusher: {}, soundMode: "" }; }, mounted() { l.logger.info("trtc-pusher attached"), this.bindTRTCCloudEvent(), c.emit("pusherDomReady", !0); }, beforeUnmount() { this.executeCleanup(); }, beforeDestroy() { this.executeCleanup(); }, methods: { executeCleanup() { l.logger.info("trtc-pusher detached"), c.emit("pusherDomReady", !1), this.unbindTRTCCloudEvent(), l.exitRoom(); }, pusherAttributesChange(e) { const { pusher: n, callback: r } = e; this.pusher = { ...this.pusher, ...n }, r && this.$nextTick(r); }, playerAudioRouteChange(e) { const { soundMode: n, callback: r } = e; this.soundMode = n, r && r(); }, bindTRTCCloudEvent() { c.on("pusherAttributesChange", this.pusherAttributesChange), c.on("playerAudioRouteChange", this.playerAudioRouteChange); }, unbindTRTCCloudEvent() { c.off("pusherAttributesChange", this.pusherAttributesChange), c.off("playerAudioRouteChange", this.playerAudioRouteChange); }, emitDocEvent(e, n) { this.$emit(e, n); }, handleStateChange(e) { u.pusherEventHandler(e), this.emitDocEvent("statechange", e); }, handleNetStatus(e) { u.pusherNetStatusHandler(e), this.emitDocEvent("netstatus", e); }, handleError(e) { u.pusherErrorHandler(e), this.emitDocEvent("error", e); }, handleBGMStart(e) { u.pusherBGMStartHandler(e), this.emitDocEvent("bgmstart", e); }, handleBGMProgress(e) { u.pusherBGMProgressHandler(e), this.emitDocEvent("bgmprogress", e); }, handleBGMComplete(e) { u.pusherBGMCompleteHandler(e), this.emitDocEvent("bgmcomplete", e); }, handleAudioVolumeNotify(e) { l.isEnterRoom && u.pusherAudioVolumeNotify(e), this.emitDocEvent("audiovolumenotify", e); }, handleEnterPictureInPicture(e) { this.emitDocEvent("enterpictureinpicture", e); }, handleLeavePictureInPicture(e) { this.emitDocEvent("leavepictureinpicture", e); } } }, R = { class: "trtc-pusher-container" }; function E(e, n, r, a, t, i) { const m = d("live-pusher"), f = d("live-player"); return h(), y("div", R, [ g(m, { class: "trtc-pusher", url: t.pusher.url, mode: "HD", autopush: t.pusher.autopush, "enable-camera": t.pusher.enableCamera, "enable-mic": t.pusher.enableMic, muted: t.pusher.muted, "enable-agc": t.pusher.enableAgc, "enable-ans": t.pusher.enableAns, "enable-ear-monitor": t.pusher.enableEarMonitor, "auto-focus": t.pusher.enableAutoFocus, zoom: t.pusher.enableZoom, "min-bitrate": t.pusher.minBitrate, "max-bitrate": t.pusher.maxBitrate, "video-width": t.pusher.videoWidth, "video-height": t.pusher.videoHeight, beauty: t.pusher.beautyLevel, whiteness: t.pusher.whitenessLevel, orientation: t.pusher.videoOrientation, aspect: t.pusher.videoAspect, "device-position": t.pusher.frontCamera, "remote-mirror": t.pusher.enableRemoteMirror, "local-mirror": t.pusher.localMirror, "background-mute": t.pusher.enableBackgroundMute, "audio-quality": t.pusher.audioQuality, "audio-volume-type": t.pusher.audioVolumeType, "audio-reverb-type": t.pusher.audioReverbType, "waiting-image": t.pusher.waitingImage, "picture-in-picture-mode": r.pictureInPictureMode, "beauty-style": t.pusher.beautyStyle, fps: t.pusher.fps, filter: t.pusher.filter, onStatechange: i.handleStateChange, onNetstatus: i.handleNetStatus, onError: i.handleError, onBgmstart: i.handleBGMStart, onBgmprogress: i.handleBGMProgress, onBgmcomplete: i.handleBGMComplete, onAudiovolumenotify: i.handleAudioVolumeNotify, onEnterpictureinpicture: i.handleEnterPictureInPicture, onLeavepictureinpicture: i.handleLeavePictureInPicture }, null, 8, ["url", "autopush", "enable-camera", "enable-mic", "muted", "enable-agc", "enable-ans", "enable-ear-monitor", "auto-focus", "zoom", "min-bitrate", "max-bitrate", "video-width", "video-height", "beauty", "whiteness", "orientation", "aspect", "device-position", "remote-mirror", "local-mirror", "background-mute", "audio-quality", "audio-volume-type", "audio-reverb-type", "waiting-image", "picture-in-picture-mode", "beauty-style", "fps", "filter", "onStatechange", "onNetstatus", "onError", "onBgmstart", "onBgmprogress", "onBgmcomplete", "onAudiovolumenotify", "onEnterpictureinpicture", "onLeavepictureinpicture"]), g(f, { class: "trtc-player", "sound-mode": t.soundMode }, null, 8, ["sound-mode"]) ]); } const S = /* @__PURE__ */ b(I, [["render", E], ["__scopeId", "data-v-3e2e5059"]]); const o = v.getTRTCShareInstance(), p = o.trtc, s = o.InterfaceEventEmitter, P = { name: "TRTCPlayer", props: { streamId: { type: String, default: "" }, pictureInPictureMode: { type: [String, Array], default: void 0 }, pictureInPictureInitPosition: { type: String, default: void 0 }, enableSystemPip: { type: Boolean, default: void 0 }, enableCasting: { type: Boolean, default: void 0 } }, data() { return { player: {}, TRTCStreamId: "", soundMode: "" }; }, watch: { streamId(e) { this.setTRTCStreamId(e); } }, mounted() { o.logger.info("trtc-player attached", this.streamId), this.streamId && s.emit("playerDomReady", { isReady: !0, view: this.streamId }), this.TRTCStreamId = this.getTRTCStreamId(this.streamId), this.bindTRTCCloudEvent(); }, beforeUnmount() { this.executeCleanup(); }, beforeDestroy() { this.executeCleanup(); }, methods: { executeCleanup() { o.logger.info("trtc-player detached", this.streamId), s.emit("playerDomReady", { isReady: !1, streamId: this.streamId }), this.unbindTRTCCloudEvent(); }, setTRTCStreamId(e) { return o.logger.info("trtc-player setTRTCStreamId", e), new Promise((n, r) => { try { this.$emit("update:streamId", e), this.TRTCStreamId = this.getTRTCStreamId(e), this.$nextTick(() => { o.logger.info("trtc-player setTRTCStreamId success", e), n(), s.emit("playerDomReady", { isReady: !0, view: e }); }); } catch (a) { o.logger.info("trtc-player setTRTCStreamId fail", e, a), r(a); } }); }, // 其他方法保持原有逻辑... getTRTCStreamId(e) { const n = e.split("_"), r = n.slice(0, -1).join("_"), a = Number(n[n.length - 1]); return _(r, a); }, bindTRTCCloudEvent() { s.on("playerAttributesChange", this.playerAttributesChange), s.on("playerAudioRouteChange", this.playerAudioRouteChange); }, unbindTRTCCloudEvent() { s.off("playerAttributesChange", this.playerAttributesChange), s.off("playerAudioRouteChange", this.playerAudioRouteChange); }, playerAttributesChange(e) { const { view: n, playerAttributes: r, callback: a } = e; n === this.streamId && (this.player = { ...this.player, ...r }, a && a()); }, playerAudioRouteChange(e) { const { soundMode: n, callback: r } = e; this.soundMode = n, r && r(); }, emitDocEvent(e, n) { this.$emit(e, n); }, _playerStateChange(e) { p.playerEventHandler(e), this.emitDocEvent("statechange", e); }, _playerFullscreenChange(e) { p.playerFullscreenChange(e), this.emitDocEvent("fullscreenchange", e); }, _playerNetStatus(e) { p.playerNetStatus(e), this.emitDocEvent("netstatus", e); }, _playerAudioVolumeNotify(e) { try { e.currentTarget.dataset.streamid = this.player.streamID, p.playerAudioVolumeNotify(e); } catch (n) { o.logger.warn(n); } finally { this.emitDocEvent("audiovolumenotify", e); } }, _playerEnterPictureInPicture(e) { this.emitDocEvent("enterpictureinpicture", e); }, _playerLeavePictureInPicture(e) { this.emitDocEvent("leavepictureinpicture", e); }, _playerCastingUserSelect(e) { this.emitDocEvent("castinguserselect", e); }, _playerCastingStateChange(e) { this.emitDocEvent("castingstatechange", e); }, _playerCastingInterrupt(e) { this.emitDocEvent("castinginterrupt", e); } } }, A = { class: "trtc-player-container" }, D = { key: 1, class: "trtc-dark-mask" }; function M(e, n, r, a, t, i) { const m = d("live-player"); return h(), y("div", A, [ r.streamId ? (h(), T(m, { key: 0, class: "trtc-player", id: t.player.streamID, "data-userid": t.player.userID, "data-streamid": t.player.streamID, "data-streamtype": t.player.streamType, src: t.player.src, mode: "RTC", autoplay: t.player.autoplay, "mute-audio": t.player.muteAudio, "mute-video": t.player.muteVideo, orientation: t.player.orientation, "object-fit": t.player.objectFit, "background-mute": t.player.enableBackgroundMute, "min-cache": t.player.minCache, "max-cache": t.player.maxCache, "sound-mode": t.soundMode, "enable-recv-message": t.player.enableRecvMessage, "auto-pause-if-navigate": t.player.autoPauseIfNavigate, "auto-pause-if-open-native": t.player.autoPauseIfOpenNative, "picture-in-picture-mode": r.pictureInPictureMode, "picture-in-picture-init-position": r.pictureInPictureInitPosition, "enable-system-pip": r.enableSystemPip, "enable-casting": r.enableCasting, debug: t.player.debug, onStatechange: i._playerStateChange, onFullscreenchange: i._playerFullscreenChange, onNetstatus: i._playerNetStatus, onAudiovolumenotify: i._playerAudioVolumeNotify, onEnterpictureinpicture: i._playerEnterPictureInPicture, onLeavepictureinpicture: i._playerLeavePictureInPicture, onCastinguserselect: i._playerCastingUserSelect, onCastingstatechange: i._playerCastingStateChange, onCastinginterrupt: i._playerCastingInterrupt }, null, 8, ["id", "data-userid", "data-streamid", "data-streamtype", "src", "autoplay", "mute-audio", "mute-video", "orientation", "object-fit", "background-mute", "min-cache", "max-cache", "sound-mode", "enable-recv-message", "auto-pause-if-navigate", "auto-pause-if-open-native", "picture-in-picture-mode", "picture-in-picture-init-position", "enable-system-pip", "enable-casting", "debug", "onStatechange", "onFullscreenchange", "onNetstatus", "onAudiovolumenotify", "onEnterpictureinpicture", "onLeavepictureinpicture", "onCastinguserselect", "onCastingstatechange", "onCastinginterrupt"])) : C("", !0), t.player.stopVideo ? (h(), y("div", D)) : C("", !0) ]); } const B = /* @__PURE__ */ b(P, [["render", M], ["__scopeId", "data-v-51905de0"]]), k = (e) => { e.component("TRTCPusher", S), e.component("TRTCPlayer", B); }; export { B as TRTCPlayer, S as TRTCPusher, G as default, k as install };