Initial project import
This commit is contained in:
30
node_modules/@react-three/drei/web/ScreenVideoTexture.js
generated
vendored
Normal file
30
node_modules/@react-three/drei/web/ScreenVideoTexture.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import _extends from '@babel/runtime/helpers/esm/extends';
|
||||
import * as React from 'react';
|
||||
import { forwardRef, useEffect } from 'react';
|
||||
import { suspend, clear } from 'suspend-react';
|
||||
import { VideoTexture } from '../core/VideoTexture.js';
|
||||
|
||||
/**
|
||||
* Create a video texture from [`getDisplayMedia`](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia)
|
||||
*/
|
||||
const ScreenVideoTexture = /* @__PURE__ */forwardRef(({
|
||||
options = {
|
||||
video: true
|
||||
},
|
||||
...props
|
||||
}, fref) => {
|
||||
const mediaStream = suspend(() => navigator.mediaDevices.getDisplayMedia(options), []);
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
mediaStream == null || mediaStream.getTracks().forEach(track => track.stop());
|
||||
clear([]);
|
||||
};
|
||||
}, [mediaStream]);
|
||||
return /*#__PURE__*/React.createElement(VideoTexture, _extends({
|
||||
ref: fref
|
||||
}, props, {
|
||||
src: mediaStream
|
||||
}));
|
||||
});
|
||||
|
||||
export { ScreenVideoTexture };
|
||||
Reference in New Issue
Block a user