UNPKG

@class100/webrtc

Version:

TODO

49 lines 2.04 kB
import React, { useRef, useEffect } from 'react'; const MediaPlayer = (props) => { var _a, _b; const container = useRef(null); const isPlayAudio = ((_a = props) === null || _a === void 0 ? void 0 : _a.isPlayAudio) === false ? false : true; const isPlayVideo = ((_b = props) === null || _b === void 0 ? void 0 : _b.isPlayVideo) === false ? false : true; useEffect(() => { var _a, _b; if (!container.current) return; if (isPlayVideo) { (_a = props.videoTrack) === null || _a === void 0 ? void 0 : _a.play(container.current, { fit: (props === null || props === void 0 ? void 0 : props.fit) || "contain" }); } else { (_b = props.videoTrack) === null || _b === void 0 ? void 0 : _b.stop(); } return () => { var _a; (_a = props.videoTrack) === null || _a === void 0 ? void 0 : _a.stop(); }; }, [container, props.videoTrack, isPlayVideo]); useEffect(() => { var _a, _b; if (!container.current) return; if (isPlayAudio) { (_a = props.audioTrack) === null || _a === void 0 ? void 0 : _a.play(); } else { (_b = props.audioTrack) === null || _b === void 0 ? void 0 : _b.stop(); } return () => { var _a; (_a = props.audioTrack) === null || _a === void 0 ? void 0 : _a.stop(); }; }, [props.audioTrack, isPlayAudio]); useEffect(() => { if (props.audioTrack) { if (props.audioOutputDeviceId) { props.audioTrack.setPlaybackDevice(props.audioOutputDeviceId); } } }, [props.audioTrack, props.audioOutputDeviceId]); return (React.createElement("div", { ref: container, "data-uid": props === null || props === void 0 ? void 0 : props.uid, className: "video-player", style: { width: '320px', height: '240px' } })); }; export default MediaPlayer; //# sourceMappingURL=AgoraWebView.js.map