@edifice.io/react 2.3.1-develop-b2school.20250916133741 → 2.3.1-develop-b2school-actualites.20250916153920

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,86 +0,0 @@
1
- import { useState, useEffect } from "react";
2
- import { useTranslation } from "react-i18next";
3
- import useBrowserInfo from "../../../hooks/useBrowserInfo/useBrowserInfo.js";
4
- const VIDEO_HEIGHT = 9, VIDEO_WIDTH = 16;
5
- function useCameras() {
6
- const {
7
- device
8
- } = useBrowserInfo(navigator.userAgent), {
9
- t
10
- } = useTranslation(), [inputDevices, setInputDevices] = useState([]), [mediaStreamConstraints, setMediaStreamConstraints] = useState({
11
- audio: !0,
12
- video: {
13
- facingMode: "environment",
14
- aspectRatio: VIDEO_WIDTH / VIDEO_HEIGHT
15
- }
16
- }), [stream, setStream] = useState();
17
- async function getVideoInputDevices() {
18
- return (await navigator.mediaDevices.enumerateDevices()).filter((device2) => device2.kind === "videoinput");
19
- }
20
- async function enableStream(mediaStreamConstraints2) {
21
- try {
22
- const mediaStream = await navigator.mediaDevices.getUserMedia(mediaStreamConstraints2);
23
- setStream((previousStream) => (previousStream == null || previousStream.getTracks().forEach((track) => track.stop()), mediaStream));
24
- } catch (err) {
25
- console.error(err);
26
- }
27
- }
28
- const restartStream = () => {
29
- enableStream(mediaStreamConstraints);
30
- }, setPreferedDevice = (device2) => {
31
- let mediaStreamConstraints2 = {};
32
- device2 != null && device2.deviceId ? ((device2 == null ? void 0 : device2.deviceId) === "environment" || (device2 == null ? void 0 : device2.deviceId) === "user" ? mediaStreamConstraints2 = {
33
- audio: !0,
34
- video: {
35
- aspectRatio: VIDEO_WIDTH / VIDEO_HEIGHT,
36
- facingMode: device2 == null ? void 0 : device2.deviceId
37
- }
38
- } : mediaStreamConstraints2 = {
39
- audio: !0,
40
- video: {
41
- aspectRatio: VIDEO_WIDTH / VIDEO_HEIGHT,
42
- deviceId: device2.deviceId
43
- }
44
- }, setMediaStreamConstraints(mediaStreamConstraints2), restartStream()) : console.error("Selected input device id is null");
45
- };
46
- return useEffect(() => {
47
- async function initInputDevices() {
48
- await enableStream(mediaStreamConstraints);
49
- const videoDevices = await getVideoInputDevices();
50
- switch (device.type) {
51
- case "mobile":
52
- case "tablet": {
53
- const backCamera = {
54
- deviceId: "environment",
55
- label: t("video.back.camera"),
56
- groupId: "",
57
- kind: "videoinput"
58
- }, frontCamera = {
59
- deviceId: "user",
60
- label: t("video.front.camera"),
61
- groupId: "",
62
- kind: "videoinput"
63
- };
64
- (videoDevices == null ? void 0 : videoDevices.length) > 1 ? setInputDevices([backCamera, frontCamera]) : setInputDevices([backCamera]);
65
- break;
66
- }
67
- default:
68
- setInputDevices(videoDevices);
69
- break;
70
- }
71
- }
72
- initInputDevices();
73
- }, []), {
74
- /** Readonly list (array) of available video input devices. */
75
- inputDevices,
76
- /** Select which input video device to use. */
77
- setPreferedDevice,
78
- /** The current video stream. */
79
- stream,
80
- /** Start a video stream from the default or prefered device. */
81
- restartStream
82
- };
83
- }
84
- export {
85
- useCameras
86
- };