aframe-babia-components 1.2.5 → 1.2.6

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.
Files changed (101) hide show
  1. package/components/filters/babia-treebuilder.js +17 -12
  2. package/components/others/babia-camera.js +52 -40
  3. package/components/others/babia-experiment.js +457 -0
  4. package/components/others/babia-poster.js +383 -0
  5. package/components/others/babia-task.js +247 -0
  6. package/components/others/babia-ui.js +312 -147
  7. package/components/others/common.js +36 -5
  8. package/components/visualizers/babia-boats.js +708 -87
  9. package/components/visualizers/babia-network.js +268 -212
  10. package/dist/aframe-babia-components.js +20590 -18317
  11. package/dist/aframe-babia-components.min.js +3 -3
  12. package/dist/aframe-babia-components.min.js.map +1 -1
  13. package/docs/APIs/CHARTS.md +233 -207
  14. package/docs/APIs/OTHERS.md +143 -56
  15. package/docs/RELEASE_NOTES.md +5 -0
  16. package/docs/Tutorials/how_to_prepare_an_experiment.md +148 -0
  17. package/examples/assets/palettes/bluetored.jpg +0 -0
  18. package/examples/assets/textures/360-panorama.jpg +0 -0
  19. package/examples/assets/textures/floor-texture.jpg +0 -0
  20. package/examples/assets/textures/metalic-texture.jpg +0 -0
  21. package/examples/boats/boats_dependency/dependencieslist_cloudinary.json +1 -0
  22. package/examples/boats/boats_dependency/dependencieslist_express.json +4376 -0
  23. package/examples/boats/boats_dependency/dependencieslist_filestash.json +39533 -0
  24. package/examples/boats/boats_dependency/dependencieslist_ghdesktop.json +127660 -0
  25. package/examples/boats/boats_dependency/dependencieslist_karma.json +1 -0
  26. package/examples/boats/boats_dependency/dependencieslist_pm2.json +13726 -0
  27. package/examples/boats/boats_dependency/dependencieslist_portainer.json +41818 -0
  28. package/examples/boats/boats_dependency/dependencieslist_sh.json +5194 -0
  29. package/examples/boats/boats_dependency/experiment.html +277 -0
  30. package/examples/boats/boats_dependency/index.html +300 -0
  31. package/examples/boats/boats_dependency/index_gradient.html +209 -0
  32. package/examples/boats/boats_dependency/index_normalcity.html +207 -0
  33. package/examples/boats/boats_dependency/index_quarter_levels_01.html +213 -0
  34. package/examples/boats/boats_dependency/index_quarter_levels_02.html +213 -0
  35. package/examples/boats/boats_dependency/index_quarter_levels_03.html +213 -0
  36. package/examples/boats/boats_dependency/index_quarter_levels_querystring.html +243 -0
  37. package/examples/boats/boats_dependency/index_tree.html +211 -0
  38. package/examples/boats/boats_dependency/index_tree_gradient.html +212 -0
  39. package/examples/boats/boats_dependency/index_tree_wireframe.html +243 -0
  40. package/examples/charts/network_chart/network_chart.html +10 -2
  41. package/examples/charts/pie/index.html +3 -4
  42. package/examples/codecityjs/perceval2021/index.html +1 -1
  43. package/examples/codecityjs/projects_analysis/argouml_landscape.html +1 -1
  44. package/examples/codecityjs/projects_analysis/argouml_numfuns.html +3 -3
  45. package/examples/codecityjs/projects_analysis/argouml_table.html +1 -1
  46. package/examples/codecityjs/projects_analysis/argouml_tokens.html +1 -1
  47. package/examples/codecityjs/projects_analysis/experiment_interface.html +1 -1
  48. package/examples/codecityjs/projects_analysis/experiment_interface_task5.html +1 -1
  49. package/examples/codecityjs/projects_analysis/experiment_interface_vr_2021.html +1 -1
  50. package/examples/codecityjs/projects_analysis/experiment_interface_vr_task5.html +1 -1
  51. package/examples/codecityjs/projects_analysis/perceval_landscape.html +1 -1
  52. package/examples/codecityjs/projects_analysis/perceval_table.html +1 -1
  53. package/examples/dashboard/chaoss-dashboards.html +1 -1
  54. package/examples/dashboard/chaoss-issues.html +1 -1
  55. package/examples/dashboard/chaoss-pr.html +1 -1
  56. package/examples/dashboard/range.html +1 -1
  57. package/examples/dashboard/template.html +1 -1
  58. package/examples/experiment/city.html +352 -0
  59. package/examples/experiment/index.html +527 -0
  60. package/examples/experiment/pie.html +90 -0
  61. package/examples/experiment/sample-3s.mp3 +0 -0
  62. package/examples/experiment/sample.mp4 +0 -0
  63. package/examples/experiment/staticdata/80-percent-open-time-issues2.json +1 -0
  64. package/examples/experiment/staticdata/80-percent-open-time-pr.json +1 -0
  65. package/examples/experiment/staticdata/issues-by-organization.json +1 -0
  66. package/examples/experiment/staticdata/issues.json +1 -0
  67. package/examples/experiment/staticdata/jetuml_code_data.json +1 -0
  68. package/examples/experiment/staticdata/median-open-time-issues.json +1 -0
  69. package/examples/experiment/staticdata/median-open-time-pr.json +1 -0
  70. package/examples/experiment/staticdata/organizations-issues.json +1 -0
  71. package/examples/experiment/staticdata/organizations-pr.json +1 -0
  72. package/examples/experiment/staticdata/projects-issues.json +1 -0
  73. package/examples/experiment/staticdata/projects-pr.json +1 -0
  74. package/examples/experiment/staticdata/pull-requests-by-organization.json +1 -0
  75. package/examples/experiment/staticdata/pull-requests.json +1 -0
  76. package/examples/experiment/staticdata/repositories-issues-asignees.json +1 -0
  77. package/examples/experiment/staticdata/repositories-issues-avgdays.json +1 -0
  78. package/examples/experiment/staticdata/repositories-issues-count.json +1 -0
  79. package/examples/experiment/staticdata/repositories-issues-submitters.json +1 -0
  80. package/examples/experiment/staticdata/repositories-pr-asignees.json +1 -0
  81. package/examples/experiment/staticdata/repositories-pr-avgdays.json +1 -0
  82. package/examples/experiment/staticdata/repositories-pr-count.json +1 -0
  83. package/examples/experiment/staticdata/repositories-pr-submitters.json +1 -0
  84. package/examples/experiment/staticdata/status-issues.json +1 -0
  85. package/examples/experiment/staticdata/status-pr.json +1 -0
  86. package/examples/experiment/staticdata/submitter-issues-avgdays.json +1 -0
  87. package/examples/experiment/staticdata/submitter-issues-count.json +1 -0
  88. package/examples/experiment/staticdata/submitter-issues-repo.json +1 -0
  89. package/examples/experiment/staticdata/submitter-pr-avgdays.json +1 -0
  90. package/examples/experiment/staticdata/submitter-pr-count.json +1 -0
  91. package/examples/experiment/staticdata/submitter-pr-repo.json +1 -0
  92. package/examples/experiment/staticdata/submitters-issues.json +1 -0
  93. package/examples/experiment/staticdata/submitters-pr.json +1 -0
  94. package/examples/multi_boats/jetuml_evolution_experiment.html +1 -1
  95. package/index.js +23 -9
  96. package/package.json +1 -1
  97. package/examples/charts_querier/network_chart_querier/data.json +0 -123
  98. package/examples/charts_querier/network_chart_querier/links.json +0 -13
  99. package/examples/charts_querier/network_chart_querier/network_chart_querier.html +0 -68
  100. package/examples/charts_querier/network_chart_querier/network_chart_querier_nodes_links.html +0 -74
  101. package/examples/charts_querier/network_chart_querier/nodes.json +0 -12
@@ -0,0 +1,457 @@
1
+ /* global AFRAME */
2
+ if (typeof AFRAME === 'undefined') {
3
+ throw new Error('Component attempted to register before AFRAME was available.');
4
+ }
5
+
6
+
7
+ AFRAME.registerComponent('babia-experiment', {
8
+ schema: {
9
+ taskTitle: { type: 'string', default: 'Default task title' },
10
+ taskDescription: { type: 'string', default: 'Default task text' },
11
+ openTaskImg: { type: 'string' },
12
+ closeTaskImg: { type: 'string' },
13
+ timeLimitEnding: { type: 'boolean', default: false }, // If false, go for the button
14
+ timeLimitTime: { type: 'number', default: 300 }, // In seconds
15
+ forceFinishWhenTimeLimit: { type: 'boolean', default: false }, // In seconds
16
+ finishButton: { type: 'boolean', default: true },
17
+ recordDelta: { type: 'number', default: 3000 }, // In milliseconds, each delta the position and rotation will be recorded
18
+ recordAudio: { type: 'boolean', default: true },
19
+ taskAudio: { type: 'boolean', default: false },
20
+ taskAudioUrl: { type: 'string', default: null },
21
+ taskVideo: { type: 'boolean', default: false },
22
+ taskVideoId: { type: 'string', default: null },
23
+ taskVideoWidth: { type: 'number', default: 3 },
24
+ taskVideoHeight: { type: 'number', default: 1.75 },
25
+ lookat: {type: 'string', default: "[camera]" }
26
+ },
27
+
28
+ /**
29
+ * Set if component needs multiple instancing.
30
+ */
31
+ multiple: true,
32
+
33
+ /**
34
+ * Data recorded during the experiment
35
+ */
36
+ recordedData: {},
37
+
38
+ /**
39
+ * If the experiment is still running
40
+ */
41
+ runningExperiment: false,
42
+
43
+ /**
44
+ * Initial creation and setting of the mesh.
45
+ */
46
+ init: function () { },
47
+
48
+ /**
49
+ * Called when component is attached and when component data changes.
50
+ * Generally modifies the entity based on the data.
51
+ */
52
+
53
+ update: function (oldData) {
54
+ const self = this
55
+ if (this.data != this.oldData) {
56
+ // Get camera
57
+ let isThereBabiaCamera = this.el.querySelectorAll("[babia-camera]")
58
+ if (isThereBabiaCamera.length > 0) {
59
+ this.babiaCameraEl = isThereBabiaCamera[0]
60
+
61
+ // Add raycaster things and others attributes
62
+ let babiaCameraAttribute = this.babiaCameraEl.getAttribute("babia-camera")
63
+ this.babiaCameraEl.setAttribute("babia-camera", {
64
+ raycasterMouse: babiaCameraAttribute['raycasterMouse'] + ', #babiaTaskPopup, #babiaTaskPopup--close-icon, #babiaStartButton, #babiaFinishButton, #babiaTaskAudio, #babiaTaskVideo',
65
+ raycasterHand: babiaCameraAttribute['raycasterHand'] + ', #babiaTaskPopup, #babiaTaskPopup--close-icon, #babiaStartButton, #babiaFinishButton, #babiaTaskAudio, #babiaTaskVideo'
66
+ })
67
+
68
+ } else {
69
+ this.babiaCameraEl = this.el.sceneEl.camera.el;
70
+ }
71
+
72
+ // Find babia visualizations
73
+ this.findBabiaCharts()
74
+ // Hide babia visualizations
75
+ this.hideCharts()
76
+ // Add task if not babia task
77
+ if (this.el.querySelectorAll('[babia-task]').length == 0) {
78
+ if (this.data.taskAudio) {
79
+ this.addAudioTask()
80
+ } else if (this.data.taskVideo) {
81
+ this.addVideoTask()
82
+ } else {
83
+ this.addTask()
84
+ }
85
+ }
86
+ // Add start button
87
+ this.addStartButton()
88
+
89
+ // Add finish button
90
+ if (this.data.finishButton) {
91
+ this.addFinishButton()
92
+ }
93
+
94
+
95
+ }
96
+ },
97
+
98
+ findBabiaCharts: function () {
99
+ this.babiaCharts = this.el.querySelectorAll("[babia-pie], [babia-bars], [babia-barsmap], [babia-bubbles], [babia-city], [babia-cyls], [babia-cylsmap], [babia-doughnut], [babia-terrain], [babia-boats], [babia-network], [babiaxr-codecity]")
100
+ },
101
+
102
+ hideCharts: function () {
103
+ // Hide charts
104
+ for (let child of this.babiaCharts) {
105
+ child.setAttribute('visible', false)
106
+ }
107
+ },
108
+
109
+ showCharts: function () {
110
+ // Hide charts
111
+ for (let child of this.babiaCharts) {
112
+ child.setAttribute('visible', true)
113
+ };
114
+ },
115
+
116
+ addTask: function () {
117
+ const self = this
118
+
119
+ this.taskEntity = document.createElement('a-entity');
120
+ this.taskEntity.setAttribute('class', 'babiaxrayscasterclass')
121
+ this.taskEntity.setAttribute('id', 'babiaTaskPopup')
122
+ this.taskEntity.setAttribute('babia-poster', {
123
+ openIconImage: '../assets/popups/info.jpg',
124
+ closeIconImage: '../assets/popups/close.jpg',
125
+ title: self.data.taskTitle,
126
+ titleWrapCount: 30,
127
+ titleColor: 'black',
128
+ bodyColor: 'black',
129
+ posterBoxColor: 'white',
130
+ bodyFont: 'roboto',
131
+ posterBoxHeight: 4.5,
132
+ body: self.data.taskDescription
133
+ })
134
+ this.taskEntity.setAttribute('scale', { x: 0.5, y: 0.5, z: 0.5 })
135
+
136
+
137
+
138
+ // Add position
139
+ this.babiaCameraPosition = this.babiaCameraEl.getAttribute('position')
140
+ this.taskEntity.setAttribute('position', { x: this.babiaCameraPosition.x, y: this.babiaCameraPosition.y + 1.5, z: this.babiaCameraPosition.z - 4 })
141
+ this.taskEntity.setAttribute('babia-lookat', this.data.lookat)
142
+
143
+
144
+ // Add to the scene
145
+ this.el.parentElement.append(this.taskEntity)
146
+ },
147
+
148
+ /**
149
+ * Things related to the audio task
150
+ */
151
+ audioPlaying: false,
152
+ addAudioTask: function () {
153
+ const self = this
154
+
155
+ this.taskAudioEntity = document.createElement('a-entity');
156
+ this.taskAudioEntity.setAttribute('class', 'babiaxrayscasterclass')
157
+ this.taskAudioEntity.setAttribute('geometry', {
158
+ primitive: 'plane',
159
+ width: 1.1,
160
+ height: 0.5
161
+ })
162
+ this.taskAudioEntity.setAttribute('text', {
163
+ value: 'Play audio!',
164
+ color: 'white',
165
+ align: 'center',
166
+ wrapCount: 30,
167
+ width: 3.6,
168
+ })
169
+ this.taskAudioEntity.setAttribute('id', 'babiaTaskAudio')
170
+ this.taskAudioEntity.setAttribute('sound', {
171
+ src: `url(${self.data.taskAudioUrl})`
172
+ })
173
+
174
+ // Play Sound when click
175
+ this.taskAudioEntity.addEventListener('click', function (event) {
176
+ if (self.audioPlaying) {
177
+ self.audioPlaying = false
178
+ self.taskAudioEntity.components.sound.stopSound()
179
+ self.taskAudioEntity.setAttribute('text', 'value', 'Play audio!')
180
+ } else {
181
+ self.audioPlaying = true
182
+ self.taskAudioEntity.components.sound.playSound()
183
+ self.taskAudioEntity.setAttribute('text', 'value', 'Stop audio!')
184
+ }
185
+
186
+ }, false)
187
+
188
+ // When audio finished
189
+ this.taskAudioEntity.addEventListener('sound-ended', function (event) {
190
+ self.audioPlaying = false
191
+ self.taskAudioEntity.setAttribute('text', 'value', 'Play audio!')
192
+ }, false)
193
+
194
+
195
+ // Add position
196
+ this.babiaCameraPosition = this.babiaCameraEl.getAttribute('position')
197
+ this.taskAudioEntity.setAttribute('position', { x: this.babiaCameraPosition.x, y: this.babiaCameraPosition.y + 1.5, z: this.babiaCameraPosition.z - 4 })
198
+ this.taskAudioEntity.setAttribute('babia-lookat', this.data.lookat)
199
+
200
+
201
+ // Add to the scene
202
+ this.el.parentElement.append(this.taskAudioEntity)
203
+ },
204
+
205
+ /**
206
+ * Things related to the audio task
207
+ */
208
+ videoPlaying: false,
209
+ addVideoTask: function () {
210
+ const self = this
211
+
212
+ this.taskVideoEntity = document.createElement('a-video');
213
+ this.taskVideoEntity.setAttribute('class', 'babiaxrayscasterclass')
214
+ this.taskVideoEntity.setAttribute('id', 'babiaTaskVideo')
215
+ this.taskVideoEntity.setAttribute('src', self.data.taskVideoId)
216
+ this.taskVideoStream = document.querySelector(self.data.taskVideoId)
217
+ this.taskVideoEntity.setAttribute('width', self.data.taskVideoWidth)
218
+ this.taskVideoEntity.setAttribute('height', self.data.taskVideoHeight)
219
+
220
+
221
+ // Play Sound when click
222
+ this.taskVideoEntity.addEventListener('click', function (event) {
223
+ if (self.videoPlaying) {
224
+ self.videoPlaying = false
225
+ self.taskVideoStream.pause();
226
+ } else {
227
+ self.videoPlaying = true
228
+ self.taskVideoStream.play();
229
+ }
230
+
231
+ }, false)
232
+
233
+
234
+ // Add position
235
+ this.babiaCameraPosition = this.babiaCameraEl.getAttribute('position')
236
+ this.taskVideoEntity.setAttribute('position', { x: this.babiaCameraPosition.x, y: this.babiaCameraPosition.y + 1.5, z: this.babiaCameraPosition.z - 4 })
237
+ this.taskVideoEntity.setAttribute('babia-lookat', this.data.lookat)
238
+
239
+
240
+ // Add to the scene
241
+ this.el.parentElement.append(this.taskVideoEntity)
242
+ },
243
+
244
+ addStartButton: function () {
245
+ const self = this
246
+ this.startButtonEntity = document.createElement('a-plane')
247
+ this.startButtonEntity.setAttribute('id', 'babiaStartButton')
248
+ this.startButtonEntity.setAttribute('scale', { x: 0.4, y: 0.4, z: 0.4 })
249
+ this.startButtonEntity.setAttribute('babia-lookat', this.data.lookat)
250
+ this.startButtonEntity.setAttribute('class', '.babiaxrayscasterclass')
251
+ this.startButtonEntity.setAttribute('color', '#3ac961')
252
+ this.startButtonEntity.setAttribute('geometry', {
253
+ primitive: 'plane',
254
+ width: 1.8,
255
+ height: 0.5
256
+ })
257
+ this.startButtonEntity.setAttribute('text', {
258
+ value: 'Start!',
259
+ color: 'white',
260
+ align: 'center',
261
+ wrapCount: 30,
262
+ width: 3.6
263
+ })
264
+
265
+ this.babiaCameraPosition = this.babiaCameraEl.getAttribute('position')
266
+ this.startButtonEntity.setAttribute('position', { x: this.babiaCameraPosition.x - 0.5, y: this.babiaCameraPosition.y + 1, z: this.babiaCameraPosition.z - 1.5 })
267
+
268
+ // Start recording time
269
+ this.startButtonEntity.addEventListener('click', async function (event) {
270
+ self.showCharts()
271
+ self.runningExperiment = true;
272
+ // Start Recording
273
+ self.recordingData = window.setInterval(function () {
274
+ recordData(self)
275
+ }, self.data.recordDelta);
276
+ self.recordedData['startTime'] = Date.now();
277
+ // Audio
278
+ if (self.data.recordAudio) {
279
+ self.audioRecorder = await recordAudio();
280
+ self.audioRecorder.start();
281
+ }
282
+ self.startButtonEntity.setAttribute('visible', false)
283
+
284
+ // Show finish button
285
+ if (self.data.finishButton) {
286
+ self.finishButtonEntity.setAttribute('visible', true)
287
+ }
288
+
289
+ // Time Limit defined
290
+ if (self.data.timeLimitEnding) {
291
+ self.recordedData['maxTime'] = self.recordedData['startTime'] + self.data.timeLimitTime * 1000
292
+ }
293
+
294
+ }, false);
295
+
296
+ this.el.parentElement.append(this.startButtonEntity);
297
+ },
298
+
299
+ addFinishButton: function () {
300
+ const self = this
301
+ this.finishButtonEntity = document.createElement('a-plane')
302
+ this.finishButtonEntity.setAttribute('id', 'babiaFinishButton')
303
+ this.finishButtonEntity.setAttribute('scale', { x: 0.4, y: 0.4, z: 0.4 })
304
+ this.finishButtonEntity.setAttribute('babia-lookat', this.data.lookat)
305
+ this.finishButtonEntity.setAttribute('class', 'babiaxrayscasterclass')
306
+ this.finishButtonEntity.setAttribute('color', '#9e0000')
307
+ this.finishButtonEntity.setAttribute('visible', false)
308
+ this.finishButtonEntity.setAttribute('geometry', {
309
+ primitive: 'plane',
310
+ width: 1.8,
311
+ height: 0.5
312
+ })
313
+ this.finishButtonEntity.setAttribute('text', {
314
+ value: 'Finish!',
315
+ color: 'white',
316
+ align: 'center',
317
+ wrapCount: 30,
318
+ width: 3.6
319
+ })
320
+
321
+ this.finishButtonEntity.setAttribute('position', { x: this.babiaCameraPosition.x + 0.5, y: this.babiaCameraPosition.y + 1, z: this.babiaCameraPosition.z - 1.5 })
322
+
323
+ // Start recording time
324
+ this.finishButtonEntity.addEventListener('click', function (event) {
325
+ self.hideCharts()
326
+ // Stop recording
327
+ self.runningExperiment = false;
328
+ recordData(self)
329
+ clearInterval(this.recordingData)
330
+ if (self.audioRecorder) {
331
+ self.stopAndDownloadAudio()
332
+ }
333
+
334
+ self.recordedData['finishTime'] = Date.now();
335
+ self.recordedData['totalDuration'] = self.recordedData['finishTime'] - self.recordedData['startTime'];
336
+ downloadObjectAsJson(self.recordedData, "experimentdetails")
337
+ self.finishButtonEntity.setAttribute('visible', false)
338
+
339
+
340
+ }, false);
341
+
342
+ this.el.parentElement.append(this.finishButtonEntity);
343
+ },
344
+
345
+ stopAndDownloadAudio: async function () {
346
+ let audio = await this.audioRecorder.stop()
347
+ const a = document.createElement("a");
348
+ document.body.appendChild(a);
349
+ a.style = "display: none";
350
+ a.href = audio.audioUrl;
351
+ a.download = "audio.webm";
352
+ a.click();
353
+ window.URL.revokeObjectURL(audio.audioUrl)
354
+ },
355
+
356
+ tick: function () {
357
+ const self = this
358
+ // Check if the experiment is running
359
+ if (this.runningExperiment) {
360
+ // Check if the time limit
361
+ if (this.data.timeLimitEnding) {
362
+ if (Date.now() > this.recordedData.maxTime) {
363
+ // Reached the time
364
+ this.recordedData['finishTime'] = this.recordedData.maxTime
365
+ this.recordedData['totalDuration'] = this.recordedData['finishTime'] - this.recordedData['startTime'];
366
+ this.runningExperiment = false
367
+ // If forced, hide charts and download data
368
+ if (this.data.forceFinishWhenTimeLimit) {
369
+ alert("The time limit is done! Thank you!")
370
+ this.hideCharts()
371
+ downloadObjectAsJson(self.recordedData, "experimentdetails")
372
+ self.finishButtonEntity.setAttribute('visible', false)
373
+ recordData(self)
374
+ clearInterval(this.recordingData)
375
+ if (self.audioRecorder) {
376
+ self.stopAndDownloadAudio()
377
+ }
378
+ } else {
379
+ alert("The time limit is done, but you can continue doing the experiment, please, click on Finish when done!")
380
+ }
381
+ }
382
+ }
383
+ }
384
+ }
385
+
386
+ })
387
+
388
+ function recordData(self) {
389
+ // Save Position and rotation of the camera
390
+ let cameraEl = self.el.sceneEl.camera.el;
391
+ self.recordedData[Date.now()] = {
392
+ position: cameraEl.getAttribute('position'),
393
+ rotation: cameraEl.getAttribute('rotation')
394
+ }
395
+ }
396
+
397
+ function getAttributeByRegex(element, regex, exclude) {
398
+ const attributes = element.attributes;
399
+ for (let i = attributes.length - 1; i >= 0; i--) {
400
+ const attr = attributes[i];
401
+ if (attr.name.startsWith(regex) && attr.name !== exclude && attr.name !== "babia-camera") {
402
+ return true
403
+ }
404
+
405
+ }
406
+ return false
407
+ }
408
+
409
+ function downloadObjectAsJson(exportObj, exportName) {
410
+ let dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj));
411
+ let downloadAnchorNode = document.createElement('a');
412
+ downloadAnchorNode.setAttribute("href", dataStr);
413
+ downloadAnchorNode.setAttribute("download", exportName + ".json");
414
+ document.body.appendChild(downloadAnchorNode); // required for firefox
415
+ downloadAnchorNode.click();
416
+ downloadAnchorNode.remove();
417
+ }
418
+
419
+
420
+
421
+ const recordAudio = () => {
422
+ return new Promise(resolve => {
423
+ navigator.mediaDevices.getUserMedia({ audio: true })
424
+ .then(stream => {
425
+ const mediaRecorder = new MediaRecorder(stream);
426
+ const audioChunks = [];
427
+
428
+ mediaRecorder.addEventListener("dataavailable", event => {
429
+ audioChunks.push(event.data);
430
+ });
431
+
432
+ const start = () => {
433
+ mediaRecorder.start();
434
+ };
435
+
436
+ const stop = () => {
437
+ return new Promise(resolve => {
438
+ mediaRecorder.addEventListener("stop", () => {
439
+ const audioBlob = new Blob(audioChunks);
440
+ const audioUrl = URL.createObjectURL(audioBlob);
441
+ const audio = new Audio(audioUrl);
442
+ const play = () => {
443
+ audio.play();
444
+ };
445
+
446
+ resolve({ audioBlob, audioUrl, play });
447
+ });
448
+
449
+ mediaRecorder.stop();
450
+ });
451
+ };
452
+
453
+
454
+ resolve({ start, stop });
455
+ });
456
+ });
457
+ };