客户端捕获屏幕实现屏幕共享

import React, { useRef, useEffect } from 'react'
import { desktopCapturer } from 'electron'

import ScreenCapture from '~/shared/webrtc/ScreenCapture'

const screenCapture = new ScreenCapture()
window.screenCapture = screenCapture

export default function TestScreenCapture() {
  const videoElemRef = useRef(null)

  useEffect(() => {
    desktopCapturer.getSources({ types: ['screen'], thumbnailSize: { width: 1280, height: 720 } }, (err, sources) => {
      screenCapture.setScreenInfo({ id: sources[0].id })
      screenCapture.setCaptureArea({
        x: 0,
        y: 0,
        width: 640,
        height: 360,
      })
      screenCapture.start().then(() => {
        videoElemRef.current.onloadedmetadata = () => videoElemRef.current.play()
        videoElemRef.current.srcObject = screenCapture.outputStream
      })
    })

    return () => {
      screenCapture.stop()
    }
  })

  return (
    
<video ref={videoElemRef} style={{ width: 320, }} controls autoPlay />
) }

 

转载于:https://www.cnblogs.com/chenbeibei520/p/11151750.html

你可能感兴趣的:(客户端捕获屏幕实现屏幕共享)