UNPKG

@tencentcloud/trtc-component-uniapp

Version:

TRTC Uni-app Components for WeChat Mini Program

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