新增功能

This commit is contained in:
Your Name
2026-03-04 15:32:30 +08:00
parent a07e844c47
commit ab77f5488d
2266 changed files with 177942 additions and 3444 deletions
+4
View File
@@ -0,0 +1,4 @@
import TRTCCloud from '@tencentcloud/trtc-cloud-wx'
export * from '@tencentcloud/trtc-cloud-wx'
export default TRTCCloud
+96
View File
@@ -0,0 +1,96 @@
import TRTCCloud, {translateTRTCStreamId} from '@tencentcloud/trtc-cloud-wx'
const trtcCloud = TRTCCloud.getTRTCShareInstance()
const trtc = trtcCloud.trtc
const InterfaceEventEmitter = trtcCloud.InterfaceEventEmitter
Component({
properties: {
streamId: String
},
data: {
player: {},
TRTCStreamId: '',
soundMode: ''
},
lifetimes: {
attached() {
trtcCloud.logger.info('trtc-player attached', this.data.streamId)
if (this.data.streamId) {
InterfaceEventEmitter.emit('playerDomReady', {isReady: true, view: this.data.streamId})
}
this.data.TRTCStreamId = this.getTRTCStreamId(this.data.streamId)
this.bindTRTCCloudEvent()
},
detached() {
trtcCloud.logger.info('trtc-player detached', this.data.streamId)
InterfaceEventEmitter.emit('playerDomReady', {isReady: false, streamId: this.data.streamId})
this.unbindTRTCCloudEvent()
}
},
methods: {
// todo room uniapp 特供,因为 uniapp 打包导致组件传惨变量名更替 trtc-player 组建内部无法识别
setTRTCStreamId(id) {
trtcCloud.logger.info('trtc-player setTRTCStreamId', id)
return new Promise((resolve, reject) => {
try {
this.data.streamId = id
this.data.TRTCStreamId = this.getTRTCStreamId(id)
this.setData({streamId: this.data.streamId}, () => {
trtcCloud.logger.info('trtc-player setTRTCStreamId success', id)
resolve()
InterfaceEventEmitter.emit('playerDomReady', {isReady: true, view: id})
})
} catch (err) {
trtcCloud.logger.info('trtc-player setTRTCStreamId fail', id, err)
reject(err)
}
})
},
playerAttributesChange(event) {
const {view, playerAttributes, callback} = event
trtcCloud.logger.info('trtc-player playerAttributesChange', view, JSON.stringify(playerAttributes), this.data.streamId)
if (view === this.data.streamId) {
this.setData({player: playerAttributes}, callback)
}
},
playerAudioRouteChange(event) {
const { soundMode, callback } = event
trtcCloud.logger.info('trtc-player playerAudioRouteChange', soundMode)
this.setData({ soundMode }, callback)
},
getTRTCStreamId(streamId) {
const tempArray = streamId.split('_')
const userId = tempArray.slice(0, -1).join('_')
const streamType = Number(tempArray[tempArray.length - 1])
return translateTRTCStreamId(userId, streamType)
},
bindTRTCCloudEvent() {
InterfaceEventEmitter.on('playerAttributesChange', this.playerAttributesChange, this)
InterfaceEventEmitter.on('playerAudioRouteChange', this.playerAudioRouteChange, this)
},
unbindTRTCCloudEvent() {
InterfaceEventEmitter.off('playerAttributesChange', this.playerAttributesChange)
InterfaceEventEmitter.off('playerAudioRouteChange', this.playerAudioRouteChange)
},
// 请保持跟 wxml 中绑定的事件名称一致
_playerStateChange(event) {
trtc.playerEventHandler(event)
},
_playerFullscreenChange(event) {
trtc.playerFullscreenChange(event)
},
_playerNetStatus(event) {
trtc.playerNetStatus(event)
},
_playerAudioVolumeNotify(event) {
try {
event.currentTarget.dataset.streamid = this.data.player.streamID
trtc.playerAudioVolumeNotify(event)
} catch (err) {
trtcCloud.logger.warn(err)
}
},
}
})
+4
View File
@@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}
+12
View File
@@ -0,0 +1,12 @@
<view class="trtc-player-container">
<live-player wx:if="{{streamId}}" class="trtc-player" id="{{player.streamID}}" data-userid="{{player.userID}}"
data-streamid="{{player.streamID}}" data-streamtype="{{player.streamType}}" src="{{player.src}}" mode="RTC"
autoplay="{{player.autoplay}}" mute-audio="{{player.muteAudio}}" mute-video="{{player.muteVideo}}"
orientation="{{player.orientation}}" object-fit="{{player.objectFit}}"
background-mute="{{player.enableBackgroundMute}}" min-cache="{{player.minCache}}" max-cache="{{player.maxCache}}"
sound-mode="{{soundMode}}" enable-recv-message="{{player.enableRecvMessage}}"
auto-pause-if-navigate="{{player.autoPauseIfNavigate}}" auto-pause-if-open-native="{{player.autoPauseIfOpenNative}}"
debug="{{player.debug}}" bindstatechange="_playerStateChange" bindfullscreenchange="_playerFullscreenChange"
bindnetstatus="_playerNetStatus" bindaudiovolumenotify="_playerAudioVolumeNotify" />
<view wx:if="{{player.stopVideo}}" class="trtc-dark-mask"></view>
</view>
+16
View File
@@ -0,0 +1,16 @@
.trtc-player-container {
height: 100%;
width: 100%;
position: relative;
}
.trtc-player {
height: 100%;
width: 100%;
}
.trtc-dark-mask {
width: 100%;
height: 100%;
background-color: black;
position: absolute;
top: 0;
}
+73
View File
@@ -0,0 +1,73 @@
import TRTCCloud from '@tencentcloud/trtc-cloud-wx'
const trtcCloud = TRTCCloud.getTRTCShareInstance()
const trtc = trtcCloud.trtc
const InterfaceEventEmitter = trtcCloud.InterfaceEventEmitter
Component({
properties: {
},
data: {
pusher: {},
},
lifetimes: {
attached() {
trtcCloud.logger.info('trtc-pusher attached')
this.bindTRTCCloudEvent()
// 注意事件绑定应该放在 domReady 之前,因为此时出发 domReady 会执行 ready 后的后续操作依赖 bindTRTCCloudEvent
InterfaceEventEmitter.emit('pusherDomReady', true)
},
detached() {
trtcCloud.logger.info('trtc-pusher detached')
InterfaceEventEmitter.emit('pusherDomReady', false)
this.unbindTRTCCloudEvent()
trtcCloud.exitRoom()
},
},
methods: {
pusherAttributesChange(event) {
const {pusher, callback} = event
this.setData({pusher}, callback)
},
playerAudioRouteChange(event) {
const { soundMode, callback } = event
trtcCloud.logger.info('trtc-player playerAudioRouteChange', soundMode)
this.setData({ soundMode }, callback)
},
bindTRTCCloudEvent() {
InterfaceEventEmitter.on('pusherAttributesChange', this.pusherAttributesChange, this)
InterfaceEventEmitter.on('playerAudioRouteChange', this.playerAudioRouteChange, this)
},
unbindTRTCCloudEvent() {
InterfaceEventEmitter.off('pusherAttributesChange', this.pusherAttributesChange)
InterfaceEventEmitter.off('playerAudioRouteChange', this.playerAudioRouteChange)
},
// 请保持跟 wxml 中绑定的事件名称一致
_pusherStateChangeHandler(event) {
trtc.pusherEventHandler(event)
},
_pusherNetStatusHandler(event) {
trtc.pusherNetStatusHandler(event)
},
_pusherErrorHandler(event) {
trtc.pusherErrorHandler(event)
},
_pusherBGMStartHandler(event) {
trtc.pusherBGMStartHandler(event)
},
_pusherBGMProgressHandler(event) {
trtc.pusherBGMProgressHandler(event)
},
_pusherBGMCompleteHandler(event) {
trtc.pusherBGMCompleteHandler(event)
},
_pusherAudioVolumeNotify(event) {
if (!trtcCloud.isEnterRoom) {
return
}
trtc.pusherAudioVolumeNotify(event)
}
}
})
+4
View File
@@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}
+22
View File
@@ -0,0 +1,22 @@
<view class="trtc-pusher-container">
<live-pusher class="trtc-pusher" url="{{pusher.url}}" mode="{{'HD'}}" autopush="{{pusher.autopush}}"
enable-camera="{{pusher.enableCamera}}" enable-mic="{{pusher.enableMic}}" muted="{{pusher.muted}}"
enable-agc="{{pusher.enableAgc}}" enable-ans="{{pusher.enableAns}}"
enable-ear-monitor="{{pusher.enableEarMonitor}}" auto-focus="{{pusher.enableAutoFocus}}"
zoom="{{pusher.enableZoom}}" min-bitrate="{{pusher.minBitrate}}" max-bitrate="{{pusher.maxBitrate}}"
video-width="{{pusher.videoWidth}}" video-height="{{pusher.videoHeight}}" beauty="{{pusher.beautyLevel}}"
whiteness="{{pusher.whitenessLevel}}" orientation="{{pusher.videoOrientation}}" aspect="{{pusher.videoAspect}}"
device-position="{{pusher.frontCamera}}" remote-mirror="{{pusher.enableRemoteMirror}}"
local-mirror="{{pusher.localMirror}}" background-mute="{{pusher.enableBackgroundMute}}"
audio-quality="{{pusher.audioQuality}}" audio-volume-type="{{pusher.audioVolumeType}}"
audio-reverb-type="{{pusher.audioReverbType}}" waiting-image="{{pusher.waitingImage}}"
beauty-style="{{pusher.beautyStyle}}" fps="{{pusher.fps}}" filter="{{pusher.filter}}"
audio-quality="{{pusher.audioQuality}}"
bindstatechange="_pusherStateChangeHandler" bindnetstatus="_pusherNetStatusHandler"
binderror="_pusherErrorHandler" bindbgmstart="_pusherBGMStartHandler"
bindbgmprogress="_pusherBGMProgressHandler" bindbgmcomplete="_pusherBGMCompleteHandler"
bindaudiovolumenotify="_pusherAudioVolumeNotify" />
<live-player class="trtc-player" sound-mode="{{soundMode}}">
</live-player>
<!-- <camera wx:if="{{pusher.videoPreview}}" class="trtc-camera" device-position="{{pusher.frontCamera}}"></camera> -->
</view>
+20
View File
@@ -0,0 +1,20 @@
.trtc-pusher-container {
height: 100%;
width: 100%;
position: relative;
}
.trtc-pusher {
height: 100%;
width: 100%;
}
.trtc-camera {
height: 100%;
position: absolute;
top: 0;
}
.trtc-player {
width: 0;
height: 0;
display: flex;
}