@fto-consult/expo-ui 7.10.0 → 7.11.0
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.
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fto-consult/expo-ui",
|
3
|
-
"version": "7.
|
3
|
+
"version": "7.11.0",
|
4
4
|
"description": "Bibliothèque de composants UI Expo,react-native",
|
5
5
|
"scripts": {
|
6
6
|
"clear-npx-cache": "npx clear-npx-cache",
|
@@ -72,7 +72,7 @@
|
|
72
72
|
"@expo/vector-icons": "^13.0.0",
|
73
73
|
"@faker-js/faker": "^8.0.2",
|
74
74
|
"@fto-consult/common": "^3.75.2",
|
75
|
-
"@fto-consult/electron-gen": "^2.
|
75
|
+
"@fto-consult/electron-gen": "^2.1.0",
|
76
76
|
"@pchmn/expo-material3-theme": "^1.3.1",
|
77
77
|
"@react-native-async-storage/async-storage": "1.18.2",
|
78
78
|
"@react-native-community/datetimepicker": "7.2.0",
|
@@ -0,0 +1,364 @@
|
|
1
|
+
import * as FileSaver from "$efile-system/utils/FileSaver";
|
2
|
+
import {isElectron} from "$cplatform";
|
3
|
+
import notify from "$cnotify";
|
4
|
+
import Preloader from "$preloader";
|
5
|
+
import {defaultStr,isNonNullString,defaultObj,getFileExtension,isPromise} from "$cutils";
|
6
|
+
import {HStack} from "$ecomponents/Stack";
|
7
|
+
import Label from "$ecomponents/Label";
|
8
|
+
import DialogProvider from "$ecomponents/Form/FormData/DialogProvider";
|
9
|
+
import session from "$session";
|
10
|
+
|
11
|
+
const startSessionKey = "desktop-capturer-session";
|
12
|
+
const actionsSessionKey = "desktop-capturer-actions";
|
13
|
+
|
14
|
+
export const canRecord = x=> isElectron()? true : typeof navigator !=="undefined" && window?.navigator && (navigator?.mediaDevices) && typeof navigator?.mediaDevices?.getDisplayMedia === 'function';
|
15
|
+
|
16
|
+
export const updateSystemTray = x => isElectron() && typeof ELECTRON !=="undefined" && ELECTRON && typeof ELECTRON?.desktopCapturer?.updateSystemTray ==="function" ? ELECTRON.desktopCapturer.updateSystemTray() : undefined;
|
17
|
+
|
18
|
+
|
19
|
+
export function getUserMedia(constraints) {
|
20
|
+
// if Promise-based API is available, use it
|
21
|
+
if ((navigator?.mediaDevices && typeof navigator?.mediaDevices?.getUserMedia =="function")) {
|
22
|
+
return navigator.mediaDevices.getUserMedia(constraints);
|
23
|
+
}
|
24
|
+
// otherwise try falling back to old, possibly prefixed API...
|
25
|
+
const legacyApi = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
|
26
|
+
if (legacyApi) {
|
27
|
+
return new Promise(function (resolve, reject) {
|
28
|
+
legacyApi.bind(navigator)(constraints, resolve, reject);
|
29
|
+
});
|
30
|
+
}
|
31
|
+
return Promise.reject({status:false,msg:"user media not available"})
|
32
|
+
}
|
33
|
+
export const getAudioConstraint = x=>{
|
34
|
+
return {audio: true,echoCancellation:{exact: true},noiseSuppression:{exact:true}};
|
35
|
+
}
|
36
|
+
export async function getUserMediaAsync(constraints,video) {
|
37
|
+
try {
|
38
|
+
const stream = await (video === false ? getUserMedia(constraints): navigator.mediaDevices.getDisplayMedia(constraints));
|
39
|
+
return stream;
|
40
|
+
} catch (e) {
|
41
|
+
console.error('navigator.getUserMedia error:', e);
|
42
|
+
}
|
43
|
+
return null;
|
44
|
+
}
|
45
|
+
export function handleUserMediaError(e) {
|
46
|
+
console.error(e," stream recording error");
|
47
|
+
notify.error(e);
|
48
|
+
}
|
49
|
+
|
50
|
+
export function getSupportedMimeTypes(mediaTypes,filter) {
|
51
|
+
if(isNonNullString(mediaTypes)){
|
52
|
+
mediaTypes = mediaTypes.split(",");
|
53
|
+
}
|
54
|
+
mediaTypes = Array.isArray(mediaTypes)? mediaTypes : isNonNullString(mediaTypes)? mediaTypes.split(",") : [];
|
55
|
+
filter = typeof filter =="function"? filter : x=>true;
|
56
|
+
if (!mediaTypes.length) mediaTypes.push(...['video', 'audio'])
|
57
|
+
const FILE_EXTENSIONS = ['webm', 'ogg', 'mp4', 'x-matroska']
|
58
|
+
const CODECS = ['vp9', 'vp9.0', 'vp8', 'vp8.0', 'avc1', 'av1', 'h265', 'h.265', 'h264', 'h.264', 'opus']
|
59
|
+
return [...new Set(
|
60
|
+
FILE_EXTENSIONS.flatMap(ext =>
|
61
|
+
CODECS.flatMap(codec =>
|
62
|
+
mediaTypes.flatMap(mediaType => [
|
63
|
+
`${mediaType}/${ext};codecs:${codec}`,
|
64
|
+
`${mediaType}/${ext};codecs=${codec}`,
|
65
|
+
`${mediaType}/${ext};codecs:${codec.toUpperCase()}`,
|
66
|
+
`${mediaType}/${ext};codecs=${codec.toUpperCase()}`,
|
67
|
+
`${mediaType}/${ext}`,
|
68
|
+
]),
|
69
|
+
),
|
70
|
+
),
|
71
|
+
)].filter(variation => MediaRecorder.isTypeSupported(variation) && filter(variation))
|
72
|
+
}
|
73
|
+
const recordingKeys = ['isRecording','isPaused','isInactive'];
|
74
|
+
function mainDesktopCapturer (){
|
75
|
+
let mimeType = "video/webm;codecs=vp9";
|
76
|
+
let recordingOptions = {};
|
77
|
+
var recorder;
|
78
|
+
let blobs = [];
|
79
|
+
const electronDesktopCapturer = isElectron() && typeof window?.ELECTRON !=="undefined" && typeof window?.ELECTRON?.desktopCapturer =="object" && ELECTRON?.desktopCapturer || {};
|
80
|
+
const getRecordingStatus = ()=>{
|
81
|
+
const ret = {}
|
82
|
+
if(recorder){
|
83
|
+
recordingKeys.map((v)=>{
|
84
|
+
if(recorder){
|
85
|
+
ret[v] = recorder.state == v.toLowerCase().split("is")[1]? true : false
|
86
|
+
} else {
|
87
|
+
ret[v] = false;
|
88
|
+
}
|
89
|
+
});
|
90
|
+
} else if(electronDesktopCapturer?.getRecordingStatus){
|
91
|
+
return electronDesktopCapturer?.getRecordingStatus();
|
92
|
+
}
|
93
|
+
return ret;
|
94
|
+
};
|
95
|
+
function handleStream(stream,opts) {
|
96
|
+
opts = Object.assign({},opts);
|
97
|
+
recorder = new MediaRecorder(stream, { mimeType});
|
98
|
+
blobs = [];
|
99
|
+
recorder.ondataavailable = function(event) {
|
100
|
+
if(event.data.size > 0){
|
101
|
+
blobs.push(event.data);
|
102
|
+
}
|
103
|
+
updateSystemTray();
|
104
|
+
};
|
105
|
+
recorder.onstop = function(event){
|
106
|
+
updateSystemTray();
|
107
|
+
if(!blobs.length) return false;
|
108
|
+
const opts = defaultObj(recordingOptions);
|
109
|
+
let {fileName} = opts;
|
110
|
+
fileName = defaultStr(fileName,"video-"+APP.getName()+"-"+(new Date().toFormat("dd-mm-yyyy HHMM"))).trim();
|
111
|
+
fileName = (fileName.rtrim(getFileExtension(fileName,false)))+".webm";
|
112
|
+
return FileSaver.save({content:new Blob(blobs, {type: mimeType}),mimeType,fileName}).then(({path,fileName})=>{
|
113
|
+
if(isNonNullString(path) || isNonNullString(fileName)){
|
114
|
+
notify.info(`Vidéo sauvegardée ${isNonNullString(path)?` à l'emplacement [${path}]`:` avec comme nom de fichier ${fileName}`}`);
|
115
|
+
}
|
116
|
+
}).catch(notify.error).finally(()=>{
|
117
|
+
recorder = undefined;
|
118
|
+
blobs = [];
|
119
|
+
});
|
120
|
+
}
|
121
|
+
recorder.start(1000);
|
122
|
+
updateSystemTray();
|
123
|
+
}
|
124
|
+
|
125
|
+
function startRecording(opts) {
|
126
|
+
if(recorder){
|
127
|
+
recorder.stop();
|
128
|
+
}
|
129
|
+
recorder = undefined;
|
130
|
+
opts = defaultObj(opts)
|
131
|
+
if(!canRecord()){
|
132
|
+
return Promise.reject({stauts:false,isRecording:false,msg:"unable to get user media, get user media is not a function"})
|
133
|
+
}
|
134
|
+
if(isNonNullString(opts.mimeType)){
|
135
|
+
const mimeTypes = getSupportedMimeTypes(x=>!x.startsWith("audio/"))
|
136
|
+
if(mimeTypes.includes(opts.mimeType)){
|
137
|
+
mimeType = opts.mimeType;
|
138
|
+
}
|
139
|
+
}
|
140
|
+
if(typeof electronDesktopCapturer?.startRecording ==='function'){
|
141
|
+
try {
|
142
|
+
const e = electronDesktopCapturer.startRecording({...opts,mimeType,updateSystemTray,handleUserMediaError})
|
143
|
+
const cb = (e)=>{
|
144
|
+
console.log(e," is e of recorder gettted");
|
145
|
+
if(e instanceof MediaRecorder){
|
146
|
+
recorder = e;
|
147
|
+
}
|
148
|
+
return e;
|
149
|
+
}
|
150
|
+
return Promise.resolve(e).then(cb).catch(notify.error);
|
151
|
+
} catch(e){
|
152
|
+
notify.error(e);
|
153
|
+
return Promise.reject(e);
|
154
|
+
}
|
155
|
+
}
|
156
|
+
opts.video = defaultObj(opts.video);
|
157
|
+
const audio = isBool(opts.audio) && !opts.audio ? false : defaultObj(opts.audio);
|
158
|
+
const video = {
|
159
|
+
...opts.video,
|
160
|
+
mediaSource: "screen"
|
161
|
+
}
|
162
|
+
recordingOptions = opts;
|
163
|
+
return new Promise((resolve,reject)=>{
|
164
|
+
if(audio){
|
165
|
+
(async() => {
|
166
|
+
const audioStream = await getUserMediaAsync(getAudioConstraint(),false)
|
167
|
+
const videoStream = await getUserMediaAsync({audio:false,video})
|
168
|
+
if(audioStream && videoStream){
|
169
|
+
const combinedStream = new MediaStream([...videoStream.getVideoTracks(), ...audioStream.getAudioTracks()])
|
170
|
+
handleStream(combinedStream,opts)
|
171
|
+
}
|
172
|
+
resolve({isRecording:true});
|
173
|
+
})();
|
174
|
+
} else {
|
175
|
+
return getUserMediaSync({audio:false,video}).then((stream)=>{
|
176
|
+
handleStream(stream,opts);
|
177
|
+
resolve({isRecording:true})
|
178
|
+
}).catch(handleUserMediaError);
|
179
|
+
}
|
180
|
+
return resolve({isRecording:false});
|
181
|
+
})
|
182
|
+
}
|
183
|
+
|
184
|
+
function pauseRecording(){
|
185
|
+
if(electronDesktopCapturer?.pauseRecording){
|
186
|
+
return electronDesktopCapturer?.pauseRecording();
|
187
|
+
}
|
188
|
+
if(!recorder || !getRecordingStatus().isRecording) return;
|
189
|
+
recorder.pause();
|
190
|
+
updateSystemTray();
|
191
|
+
return true;
|
192
|
+
}
|
193
|
+
function resumeRecording(){
|
194
|
+
if(electronDesktopCapturer?.resumeRecording) return electronDesktopCapturer.resumeRecording();
|
195
|
+
if(!recorder || !getRecordingStatus().isPaused) return;
|
196
|
+
recorder.resume();
|
197
|
+
updateSystemTray();
|
198
|
+
return true;
|
199
|
+
}
|
200
|
+
function stopRecording(opts) {
|
201
|
+
if(electronDesktopCapturer.stopRecording) return electronDesktopCapturer.stopRecording();
|
202
|
+
if(!recorder) return false;
|
203
|
+
let s = getRecordingStatus();
|
204
|
+
if(!s.isPaused && !s.isRecording){
|
205
|
+
recorder = undefined;
|
206
|
+
return false;
|
207
|
+
}
|
208
|
+
if(recorder){
|
209
|
+
let s = getRecordingStatus();
|
210
|
+
if(s.isRecording || s.isPaused){
|
211
|
+
recorder.stop();
|
212
|
+
}
|
213
|
+
}
|
214
|
+
recorder = undefined;
|
215
|
+
return true;
|
216
|
+
}
|
217
|
+
return {
|
218
|
+
canRecord,
|
219
|
+
isUserMediaAvailable:canRecord,
|
220
|
+
getRecordingStatus,
|
221
|
+
startRecording,
|
222
|
+
pauseRecording,
|
223
|
+
resumeRecording,
|
224
|
+
getAudioConstraint,
|
225
|
+
stopRecording,
|
226
|
+
getSupportedMimeTypes,
|
227
|
+
}
|
228
|
+
}
|
229
|
+
|
230
|
+
export const looopForTimer = (timer)=>{
|
231
|
+
return new Promise((resolve,reject)=>{
|
232
|
+
let timerCB = undefined;
|
233
|
+
timer = typeof timer =='number'? timer : 3000;
|
234
|
+
const loopCB = ()=>{
|
235
|
+
clearTimeout(timerCB);
|
236
|
+
const d = Math.ceil(timer/1000);
|
237
|
+
const testID = "RN_PreloaderLooper";
|
238
|
+
if(timer >= 1000){
|
239
|
+
Preloader.open({
|
240
|
+
content : <HStack testID={testID}>
|
241
|
+
<Label>Début capture dans</Label>
|
242
|
+
<Label textBold fontSize={40}>{" "+(d).formatNumber()+" "}</Label>
|
243
|
+
<Label>seconde{d>1 &&"s"}</Label>
|
244
|
+
</HStack>
|
245
|
+
})
|
246
|
+
timer-=1000;
|
247
|
+
timerCB = setTimeout(loopCB,900);
|
248
|
+
return;
|
249
|
+
}
|
250
|
+
Preloader.close();
|
251
|
+
resolve();
|
252
|
+
}
|
253
|
+
return loopCB();
|
254
|
+
})
|
255
|
+
}
|
256
|
+
const desktopCapturer = mainDesktopCapturer();
|
257
|
+
|
258
|
+
export function handleCapture(){
|
259
|
+
if(!canRecord()){
|
260
|
+
const message = "Impossible de faire des enregistrements vidéo sur ce type de périférique";
|
261
|
+
notify.error(message);
|
262
|
+
return Promise.reject({message});
|
263
|
+
}
|
264
|
+
const {isRecording,isPaused} = desktopCapturer.getRecordingStatus();
|
265
|
+
let fields = {},title = "Capture d'écran vidéo en cours", yes = null, no = "Annuler";
|
266
|
+
const mimeTypes = getSupportedMimeTypes("video");
|
267
|
+
let onSuccess = undefined;
|
268
|
+
const sKey = !isPaused && !isRecording ? startSessionKey : actionsSessionKey;
|
269
|
+
const data = Object.assign({},session.get(sKey));
|
270
|
+
if(!isPaused && !isRecording){
|
271
|
+
title = "Effectuer une capture d'écran vidéo";
|
272
|
+
fields = {
|
273
|
+
audio : {
|
274
|
+
text : "Enregistrer le son",
|
275
|
+
type : 'switch',
|
276
|
+
defaultValue : true,
|
277
|
+
checkedValue : true,
|
278
|
+
uncheckedValue : false,
|
279
|
+
},
|
280
|
+
timer : {
|
281
|
+
text : 'Délai d\'attente en secondes',
|
282
|
+
type : 'number',
|
283
|
+
format : 'number',
|
284
|
+
defaultValue : !isElectron() ? 0 : 3,
|
285
|
+
},
|
286
|
+
mimeType : {
|
287
|
+
text : 'Format de la vidéo',
|
288
|
+
type : 'select',
|
289
|
+
items : mimeTypes,
|
290
|
+
defaultValue : mimeTypes[0],
|
291
|
+
itemValue : ({item,index})=>item,
|
292
|
+
renderText : ({item,index}) => item,
|
293
|
+
renderItem : ({item,index}) => item,
|
294
|
+
}
|
295
|
+
}
|
296
|
+
yes = {
|
297
|
+
text : 'Capturer',
|
298
|
+
icon : "record"
|
299
|
+
}
|
300
|
+
onSuccess = ({data})=>{
|
301
|
+
const timer = Math.ceil(typeof data.timer =="number"? data.timer : 0);
|
302
|
+
if(timer > 0){
|
303
|
+
return looopForTimer(timer*1000).then(()=>{
|
304
|
+
desktopCapturer.startRecording(data);
|
305
|
+
});
|
306
|
+
}
|
307
|
+
desktopCapturer.startRecording(data);
|
308
|
+
}
|
309
|
+
} else {
|
310
|
+
const type = isRecording || isPaused ? "radio" : undefined;
|
311
|
+
fields = {
|
312
|
+
action : {
|
313
|
+
text : 'Que voulez vous faire?',
|
314
|
+
type : 'select',
|
315
|
+
items : [
|
316
|
+
isRecording? {
|
317
|
+
code :'pauseRecording',
|
318
|
+
label:'Mettre la capture en pause',
|
319
|
+
type,
|
320
|
+
} : undefined,
|
321
|
+
isPaused ? {
|
322
|
+
code :"resumeRecording",
|
323
|
+
label:'Reprendre la capture vidéo',
|
324
|
+
type,
|
325
|
+
} : undefined,
|
326
|
+
{
|
327
|
+
code:'stopRecording',
|
328
|
+
label:'Arréter la capture vidéo',
|
329
|
+
},
|
330
|
+
],
|
331
|
+
defaultValue : isPaused?'resumeRecording' : 'stopRecording',
|
332
|
+
multiple : false,
|
333
|
+
required : true,
|
334
|
+
}
|
335
|
+
}
|
336
|
+
yes = {
|
337
|
+
text : "Exécuter",
|
338
|
+
icon : "play",
|
339
|
+
}
|
340
|
+
no = {
|
341
|
+
text : "Annuler",
|
342
|
+
icon :"cancel",
|
343
|
+
}
|
344
|
+
onSuccess = ({data})=>{
|
345
|
+
if(typeof desktopCapturer[data.action] ==='function'){
|
346
|
+
return desktopCapturer[data.action]();
|
347
|
+
}
|
348
|
+
}
|
349
|
+
}
|
350
|
+
return DialogProvider.open({
|
351
|
+
title,
|
352
|
+
actions : [yes],
|
353
|
+
onSuccess : ({data,...rest})=>{
|
354
|
+
if(onSuccess) onSuccess({data,...rest});
|
355
|
+
DialogProvider.close();
|
356
|
+
session.set(sKey,data);
|
357
|
+
},
|
358
|
+
data,
|
359
|
+
fields,
|
360
|
+
});
|
361
|
+
}
|
362
|
+
|
363
|
+
|
364
|
+
export default desktopCapturer;
|
@@ -7,6 +7,7 @@ import {defaultObj,sortBy,defaultStr,isObj} from "$cutils";
|
|
7
7
|
import appConfig from "$capp/config";
|
8
8
|
import useContext from "$econtext/hooks";
|
9
9
|
import {useMemo,useEffect,useRef} from "react";
|
10
|
+
import eDesktopCapturer,{handleCapture} from "$expo-ui/desktopCapturer";
|
10
11
|
///les items du drawer
|
11
12
|
import { screenName as aboutScreenName} from "$escreens/Help/About";
|
12
13
|
import theme from "$theme";
|
@@ -16,7 +17,7 @@ import Auth,{useIsSignedIn,tableDataPerms} from "$cauth";
|
|
16
17
|
import {getTableDataListRouteName} from "$enavigation/utils";
|
17
18
|
import {isValidElement,usePrevious} from "$react";
|
18
19
|
const useGetItems = (options)=>{
|
19
|
-
const {navigation:{drawerItems,drawerSections,drawerItemsMutator},tablesData} = useContext();
|
20
|
+
const {navigation:{drawerItems,drawerSections,drawerItemsMutator},desktopCapturer,tablesData} = useContext();
|
20
21
|
options = defaultObj(options);
|
21
22
|
const {refresh,force} = options;
|
22
23
|
const showProfilOnDrawer = theme.showProfilAvatarOnDrawer;
|
@@ -94,7 +95,23 @@ const useGetItems = (options)=>{
|
|
94
95
|
if(isObj(item) && isNonNullString(item.drawerSection) && (item.drawerSection.trim()) in items){
|
95
96
|
items[item.drawerSection.trim()].items.push(item);
|
96
97
|
}
|
97
|
-
})
|
98
|
+
});
|
99
|
+
const canCaptureDesktop = !eDesktopCapturer.canRecord()? false : typeof desktopCapturer =="function"? !!desktopCapturer() : typeof desktopCapturer =="boolean"? desktopCapturer : true;
|
100
|
+
const captureSide = canCaptureDesktop ? {
|
101
|
+
text : 'Capture d\'écran vidéo',
|
102
|
+
icon : "record",
|
103
|
+
onPress :()=>{
|
104
|
+
return handleCapture();
|
105
|
+
}
|
106
|
+
}:{};
|
107
|
+
let hasCapture = canCaptureDesktop ? false : true;
|
108
|
+
if(!hasCapture){
|
109
|
+
if(isObj(items.admin) && Array.isArray(items.admin.items)){
|
110
|
+
items.admin = Object.clone(items.admin);
|
111
|
+
items.admin.items.push(captureSide);
|
112
|
+
hasCapture = true;
|
113
|
+
}
|
114
|
+
}
|
98
115
|
if(handleHelp){
|
99
116
|
const dHelp = isObj(items.help)? Object.clone(items.help) : {};
|
100
117
|
items.help = {
|
@@ -105,6 +122,10 @@ const useGetItems = (options)=>{
|
|
105
122
|
...dHelp,
|
106
123
|
items : Array.isArray(dHelp.items)? dHelp.items : [],
|
107
124
|
};
|
125
|
+
if(!hasCapture){
|
126
|
+
items.help.items.push(captureSide);
|
127
|
+
hasCapture = true;
|
128
|
+
}
|
108
129
|
items.help.items.push({
|
109
130
|
icon : 'help',
|
110
131
|
label : 'A propos de '+APP.getName(),
|