|
@@ -334,7 +334,8 @@ export const startLive = async () => {
|
|
|
* 关闭直播
|
|
|
*/
|
|
|
export const closeLive = async () => {
|
|
|
- removeMedia(runtime.mediaStreams, runtime.mediaStreamTrack)
|
|
|
+ // removeMedia(runtime.mediaStreams, runtime.mediaStreamTrack)
|
|
|
+ // request.post('')
|
|
|
runtime.videoStatus = 'stopped'
|
|
|
for (const key in runtime.activeTracks) {
|
|
|
if (Object.prototype.hasOwnProperty.call(runtime.activeTracks, key)) {
|
|
@@ -352,7 +353,7 @@ export const closeLive = async () => {
|
|
|
export const loopSyncLike = async () => {
|
|
|
if (runtime.likeCount !== runtime.lastLikeCount) {
|
|
|
try {
|
|
|
- await request.post('/api/live/like', {})
|
|
|
+ await request.post('/api-web/imLiveBroadcastRoom/syncLike', {})
|
|
|
runtime.lastLikeCount = runtime.likeCount
|
|
|
} catch (error) {}
|
|
|
}
|
|
@@ -404,36 +405,27 @@ export const sendMessage = async (msg: any, type: SendMessageType = 'text') => {
|
|
|
await RongIMLib.sendMessage(conversation, message)
|
|
|
}
|
|
|
|
|
|
-export const toggleMicrophone = async () => {
|
|
|
- if (runtime.videoStatus === 'liveing' && runtime.joinedRoom) {
|
|
|
- if (runtime.activeTracks['microphone']) {
|
|
|
- await removeTrack([runtime.activeTracks['microphone']] as RTC.RCLocalTrack[], 'microphone')
|
|
|
- } else {
|
|
|
- const track = await getTrack('microphone')
|
|
|
- await setTrack([track], 'microphone')
|
|
|
- }
|
|
|
+export const openDevice = async (trackType: TrackType, needPublish = true) => {
|
|
|
+ const track = await getTrack(trackType)
|
|
|
+ await setTrack([track], trackType, needPublish)
|
|
|
+ if (runtime.videoRef) {
|
|
|
+ track.play(runtime.videoRef)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export const toggleCamera = async () => {
|
|
|
- const track = runtime.activeTracks['camera']
|
|
|
- console.log(track)
|
|
|
+export const closeDevice = async (trackType: TrackType, needPublish = true) => {
|
|
|
+ const track = runtime.activeTracks[trackType]
|
|
|
+ await removeTrack([track] as RTC.RCLocalTrack[], trackType, needPublish)
|
|
|
+ track?.destroy()
|
|
|
+}
|
|
|
+
|
|
|
+export const toggleDevice = async (trackType: TrackType) => {
|
|
|
+ const track = runtime.activeTracks[trackType]
|
|
|
+ const needPublish = runtime.videoStatus === 'liveing'
|
|
|
if (track) {
|
|
|
- if (runtime.videoStatus === 'liveing') {
|
|
|
- await removeTrack([track] as RTC.RCLocalTrack[], 'camera')
|
|
|
- }
|
|
|
- track.destroy()
|
|
|
- if (runtime.videoRef) {
|
|
|
- // console.log(runtime.videoRef.srcObject.removeTrack(runtime.videoRef.srcObject?.getVideoTracks?.()[0]))
|
|
|
- // runtime.videoRef.srcObject = null
|
|
|
- }
|
|
|
+ closeDevice(trackType, needPublish)
|
|
|
} else {
|
|
|
- const track = await getTrack('camera')
|
|
|
- if (runtime.videoStatus === 'liveing') {
|
|
|
- await setTrack([track], 'camera')
|
|
|
- }
|
|
|
- if (runtime.videoRef) {
|
|
|
- track.play(runtime.videoRef)
|
|
|
- }
|
|
|
+ openDevice(trackType, needPublish)
|
|
|
}
|
|
|
}
|
|
|
+
|