jclic 2.1.21 → 2.1.23

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 (175) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/jclic-node.js +9 -8
  3. package/dist/jclic-node.js.map +1 -1
  4. package/dist/jclic.min.js +2 -2
  5. package/dist/jclic.min.js.map +1 -1
  6. package/package.json +4 -4
  7. package/src/GlobalData.js +1 -1
  8. package/src/JClicPlayer.js +2 -2
  9. package/src/bags/MediaBag.js +6 -5
  10. package/dist/1078.jclic-node.js +0 -282
  11. package/dist/1078.jclic-node.js.map +0 -1
  12. package/dist/1196.jclic-node.js +0 -808
  13. package/dist/1196.jclic-node.js.map +0 -1
  14. package/dist/1253.jclic-node.js +0 -1432
  15. package/dist/1253.jclic-node.js.map +0 -1
  16. package/dist/13.jclic-node.js +0 -103
  17. package/dist/13.jclic-node.js.map +0 -1
  18. package/dist/1567.jclic-node.js +0 -2313
  19. package/dist/1567.jclic-node.js.map +0 -1
  20. package/dist/1588.jclic-node.js +0 -602
  21. package/dist/1588.jclic-node.js.map +0 -1
  22. package/dist/1725.jclic-node.js +0 -836
  23. package/dist/1725.jclic-node.js.map +0 -1
  24. package/dist/1731.jclic-node.js +0 -438
  25. package/dist/1731.jclic-node.js.map +0 -1
  26. package/dist/1842.jclic-node.js +0 -651
  27. package/dist/1842.jclic-node.js.map +0 -1
  28. package/dist/2160.jclic-node.js +0 -1016
  29. package/dist/2160.jclic-node.js.map +0 -1
  30. package/dist/222.jclic-node.js +0 -129
  31. package/dist/222.jclic-node.js.map +0 -1
  32. package/dist/2316.jclic-node.js +0 -949
  33. package/dist/2316.jclic-node.js.map +0 -1
  34. package/dist/2355.jclic-node.js +0 -371
  35. package/dist/2355.jclic-node.js.map +0 -1
  36. package/dist/2366.jclic-node.js +0 -431
  37. package/dist/2366.jclic-node.js.map +0 -1
  38. package/dist/2379.jclic-node.js +0 -202
  39. package/dist/2379.jclic-node.js.map +0 -1
  40. package/dist/2437.jclic-node.js +0 -450
  41. package/dist/2437.jclic-node.js.map +0 -1
  42. package/dist/2531.jclic-node.js +0 -869
  43. package/dist/2531.jclic-node.js.map +0 -1
  44. package/dist/2608.jclic-node.js +0 -160
  45. package/dist/2608.jclic-node.js.map +0 -1
  46. package/dist/2715.jclic-node.js +0 -554
  47. package/dist/2715.jclic-node.js.map +0 -1
  48. package/dist/277.jclic-node.js +0 -22
  49. package/dist/277.jclic-node.js.map +0 -1
  50. package/dist/2921.jclic-node.js +0 -660
  51. package/dist/2921.jclic-node.js.map +0 -1
  52. package/dist/2952.jclic-node.js +0 -101
  53. package/dist/2952.jclic-node.js.map +0 -1
  54. package/dist/3018.jclic-node.js +0 -421
  55. package/dist/3018.jclic-node.js.map +0 -1
  56. package/dist/3019.jclic-node.js +0 -682
  57. package/dist/3019.jclic-node.js.map +0 -1
  58. package/dist/3231.jclic-node.js +0 -274
  59. package/dist/3231.jclic-node.js.map +0 -1
  60. package/dist/331.jclic-node.js +0 -115
  61. package/dist/331.jclic-node.js.map +0 -1
  62. package/dist/3391.jclic-node.js +0 -276
  63. package/dist/3391.jclic-node.js.map +0 -1
  64. package/dist/3502.jclic-node.js +0 -671
  65. package/dist/3502.jclic-node.js.map +0 -1
  66. package/dist/3653.jclic-node.js +0 -982
  67. package/dist/3653.jclic-node.js.map +0 -1
  68. package/dist/371.jclic.min.js +0 -2
  69. package/dist/371.jclic.min.js.map +0 -1
  70. package/dist/3856.jclic-node.js +0 -575
  71. package/dist/3856.jclic-node.js.map +0 -1
  72. package/dist/4112.jclic-node.js +0 -659
  73. package/dist/4112.jclic-node.js.map +0 -1
  74. package/dist/4123.jclic-node.js +0 -910
  75. package/dist/4123.jclic-node.js.map +0 -1
  76. package/dist/427.jclic-node.js +0 -894
  77. package/dist/427.jclic-node.js.map +0 -1
  78. package/dist/4483.jclic-node.js +0 -327
  79. package/dist/4483.jclic-node.js.map +0 -1
  80. package/dist/4548.jclic-node.js +0 -1078
  81. package/dist/4548.jclic-node.js.map +0 -1
  82. package/dist/466.jclic-node.js +0 -99
  83. package/dist/466.jclic-node.js.map +0 -1
  84. package/dist/485.jclic-node.js +0 -783
  85. package/dist/485.jclic-node.js.map +0 -1
  86. package/dist/4921.jclic-node.js +0 -500
  87. package/dist/4921.jclic-node.js.map +0 -1
  88. package/dist/5091.jclic-node.js +0 -239
  89. package/dist/5091.jclic-node.js.map +0 -1
  90. package/dist/520.jclic-node.js +0 -550
  91. package/dist/520.jclic-node.js.map +0 -1
  92. package/dist/5312.jclic-node.js +0 -1126
  93. package/dist/5312.jclic-node.js.map +0 -1
  94. package/dist/5338.jclic-node.js +0 -212
  95. package/dist/5338.jclic-node.js.map +0 -1
  96. package/dist/5344.jclic-node.js +0 -229
  97. package/dist/5344.jclic-node.js.map +0 -1
  98. package/dist/5550.jclic-node.js +0 -238
  99. package/dist/5550.jclic-node.js.map +0 -1
  100. package/dist/5626.jclic-node.js +0 -614
  101. package/dist/5626.jclic-node.js.map +0 -1
  102. package/dist/5977.jclic-node.js +0 -1081
  103. package/dist/5977.jclic-node.js.map +0 -1
  104. package/dist/6148.jclic-node.js +0 -345
  105. package/dist/6148.jclic-node.js.map +0 -1
  106. package/dist/6176.jclic-node.js +0 -481
  107. package/dist/6176.jclic-node.js.map +0 -1
  108. package/dist/6221.jclic-node.js +0 -1072
  109. package/dist/6221.jclic-node.js.map +0 -1
  110. package/dist/6238.jclic-node.js +0 -718
  111. package/dist/6238.jclic-node.js.map +0 -1
  112. package/dist/6454.jclic-node.js +0 -1413
  113. package/dist/6454.jclic-node.js.map +0 -1
  114. package/dist/6565.jclic-node.js +0 -294
  115. package/dist/6565.jclic-node.js.map +0 -1
  116. package/dist/6579.jclic-node.js +0 -719
  117. package/dist/6579.jclic-node.js.map +0 -1
  118. package/dist/6715.jclic-node.js +0 -148
  119. package/dist/6715.jclic-node.js.map +0 -1
  120. package/dist/6777.jclic-node.js +0 -171
  121. package/dist/6777.jclic-node.js.map +0 -1
  122. package/dist/6782.jclic-node.js +0 -1611
  123. package/dist/6782.jclic-node.js.map +0 -1
  124. package/dist/6847.jclic-node.js +0 -601
  125. package/dist/6847.jclic-node.js.map +0 -1
  126. package/dist/6856.jclic-node.js +0 -252
  127. package/dist/6856.jclic-node.js.map +0 -1
  128. package/dist/696.jclic-node.js +0 -1821
  129. package/dist/696.jclic-node.js.map +0 -1
  130. package/dist/698.jclic-node.js +0 -583
  131. package/dist/698.jclic-node.js.map +0 -1
  132. package/dist/704.jclic-node.js +0 -80
  133. package/dist/704.jclic-node.js.map +0 -1
  134. package/dist/7046.jclic-node.js +0 -735
  135. package/dist/7046.jclic-node.js.map +0 -1
  136. package/dist/7220.jclic-node.js +0 -156
  137. package/dist/7220.jclic-node.js.map +0 -1
  138. package/dist/7257.jclic-node.js +0 -931
  139. package/dist/7257.jclic-node.js.map +0 -1
  140. package/dist/743.jclic-node.js +0 -583
  141. package/dist/743.jclic-node.js.map +0 -1
  142. package/dist/757.jclic-node.js +0 -1072
  143. package/dist/757.jclic-node.js.map +0 -1
  144. package/dist/7781.jclic-node.js +0 -202
  145. package/dist/7781.jclic-node.js.map +0 -1
  146. package/dist/7912.jclic-node.js +0 -2103
  147. package/dist/7912.jclic-node.js.map +0 -1
  148. package/dist/827.jclic-node.js +0 -708
  149. package/dist/827.jclic-node.js.map +0 -1
  150. package/dist/8276.jclic-node.js +0 -409
  151. package/dist/8276.jclic-node.js.map +0 -1
  152. package/dist/8322.jclic-node.js +0 -498
  153. package/dist/8322.jclic-node.js.map +0 -1
  154. package/dist/8641.jclic-node.js +0 -360
  155. package/dist/8641.jclic-node.js.map +0 -1
  156. package/dist/8837.jclic-node.js +0 -651
  157. package/dist/8837.jclic-node.js.map +0 -1
  158. package/dist/8895.jclic-node.js +0 -151
  159. package/dist/8895.jclic-node.js.map +0 -1
  160. package/dist/9072.jclic-node.js +0 -1285
  161. package/dist/9072.jclic-node.js.map +0 -1
  162. package/dist/9078.jclic-node.js +0 -935
  163. package/dist/9078.jclic-node.js.map +0 -1
  164. package/dist/9103.jclic-node.js +0 -718
  165. package/dist/9103.jclic-node.js.map +0 -1
  166. package/dist/9359.jclic-node.js +0 -145
  167. package/dist/9359.jclic-node.js.map +0 -1
  168. package/dist/9409.jclic-node.js +0 -921
  169. package/dist/9409.jclic-node.js.map +0 -1
  170. package/dist/9513.jclic-node.js +0 -720
  171. package/dist/9513.jclic-node.js.map +0 -1
  172. package/dist/9704.jclic-node.js +0 -81
  173. package/dist/9704.jclic-node.js.map +0 -1
  174. package/dist/9950.jclic-node.js +0 -827
  175. package/dist/9950.jclic-node.js.map +0 -1
@@ -1,239 +0,0 @@
1
- "use strict";
2
- exports.id = 5091;
3
- exports.ids = [5091];
4
- exports.modules = {
5
-
6
- /***/ 5091:
7
- /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
8
-
9
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
10
- /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
11
- /* harmony export */ });
12
- /* unused harmony export AudioBuffer */
13
- /* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1253);
14
- /**
15
- * File : media/EventSoundsElement.js
16
- * Created : 01/04/2015
17
- * By : Francesc Busquets <francesc@gmail.com>
18
- *
19
- * JClic.js
20
- * An HTML5 player of JClic activities
21
- * https://projectestac.github.io/jclic.js
22
- *
23
- * @source https://github.com/projectestac/jclic.js
24
- *
25
- * @license EUPL-1.2
26
- * @licstart
27
- * (c) 2000-2020 Educational Telematic Network of Catalonia (XTEC)
28
- *
29
- * Licensed under the EUPL, Version 1.1 or -as soon they will be approved by
30
- * the European Commission- subsequent versions of the EUPL (the "Licence");
31
- * You may not use this work except in compliance with the Licence.
32
- *
33
- * You may obtain a copy of the Licence at:
34
- * https://joinup.ec.europa.eu/software/page/eupl
35
- *
36
- * Unless required by applicable law or agreed to in writing, software
37
- * distributed under the Licence is distributed on an "AS IS" basis, WITHOUT
38
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
39
- * Licence for the specific language governing permissions and limitations
40
- * under the Licence.
41
- * @licend
42
- * @module
43
- */
44
-
45
- /* global navigator, window, document, Blob, URL, MediaRecorder */
46
-
47
-
48
-
49
- /**
50
- * The AudioBuffer object provides sound recording and replaying to activities.
51
- */
52
- class AudioBuffer {
53
- /**
54
- * AudioBuffer constructor
55
- * @param {number} [seconds] - The maximum amount of time allowed to be recorded by this AudioBuffer
56
- */
57
- constructor(seconds) {
58
- if (navigator && navigator.mediaDevices && navigator.mediaDevices.getUserMedia)
59
- this.enabled = true;
60
- if (seconds)
61
- this.seconds = seconds;
62
- this.chunks = [];
63
- }
64
-
65
- /**
66
- * Starts playing the currently recorded audio, if any.
67
- */
68
- play() {
69
- this.stop();
70
- if (this.mediaPlayer) {
71
- this.mediaPlayer.currentTime = 0;
72
- this.mediaPlayer.play();
73
- } else {
74
- this.playWhenFinished = true;
75
- }
76
- }
77
-
78
- /**
79
- * Stops the current operation, either recording or playing audio
80
- */
81
- stop() {
82
- if (this.mediaRecorder && this.mediaRecorder.state === 'recording')
83
- this.mediaRecorder.stop();
84
- else if (this.mediaPlayer && !this.mediaPlayer.paused)
85
- this.mediaPlayer.pause();
86
- }
87
-
88
- /**
89
- * Starts recording audio, or stops the recording if already started.
90
- * @param {external:jQuery} [$div] - Optional `div` element where the recording is performed, as a jQuery ref.
91
- */
92
- record($div) {
93
- if (this.mediaRecorder && this.mediaRecorder.state === 'recording')
94
- this.mediaRecorder.stop();
95
- else if (this.enabled) {
96
- this.stop();
97
- this.mediaPlayer = null;
98
-
99
- navigator.mediaDevices.getUserMedia({ audio: true, video: false })
100
- .then(mediaStream => {
101
-
102
- this.mediaRecorder = new MediaRecorder(mediaStream);
103
-
104
- this.mediaRecorder.ondataavailable = ev => this.chunks.push(ev.data);
105
-
106
- this.mediaRecorder.onerror = err => {
107
- (0,_Utils_js__WEBPACK_IMPORTED_MODULE_0__/* .log */ .Rm)('error', `Error recording audio: ${err}`);
108
- this.mediaRecorder = null;
109
- };
110
-
111
- this.mediaRecorder.onstart = () => {
112
- (0,_Utils_js__WEBPACK_IMPORTED_MODULE_0__/* .log */ .Rm)('debug', 'Recording audio started');
113
- this.visualFeedbak(true, $div);
114
- };
115
-
116
- this.mediaRecorder.onstop = () => {
117
- (0,_Utils_js__WEBPACK_IMPORTED_MODULE_0__/* .log */ .Rm)('debug', 'Recording audio finished');
118
- this.visualFeedbak(false, $div);
119
-
120
- if (this.timeoutID) {
121
- window.clearTimeout(this.timeoutID);
122
- this.timeoutID = null;
123
- }
124
-
125
- const options = {};
126
- if (this.chunks.length > 0 && this.chunks[0].type)
127
- options.type = this.chunks[0].type;
128
- const blob = new Blob(this.chunks, options);
129
- this.chunks = [];
130
- this.mediaPlayer = document.createElement('audio');
131
- this.mediaPlayer.src = URL.createObjectURL(blob);
132
- this.mediaPlayer.pause();
133
- this.mediaRecorder = null;
134
- if (this.playWhenFinished) {
135
- this.playWhenFinished = false;
136
- this.mediaPlayer.play();
137
- }
138
- };
139
-
140
- this.mediaRecorder.onwarning = ev => (0,_Utils_js__WEBPACK_IMPORTED_MODULE_0__/* .log */ .Rm)('warn', `Warning recording audio: ${ev}`);
141
-
142
- this.playWhenFinished = false;
143
-
144
- this.mediaRecorder.start();
145
-
146
- this.timeoutID = window.setTimeout(() => {
147
- if (this.mediaRecorder);
148
- this.mediaRecorder.stop();
149
- }, this.seconds * 1000);
150
- })
151
- .catch(err => {
152
- (0,_Utils_js__WEBPACK_IMPORTED_MODULE_0__/* .log */ .Rm)('error', err.toString());
153
- this.visualFeedbak(false, $div);
154
- });
155
- }
156
- }
157
-
158
- /**
159
- * Set visual feedback to the user while the system is recording audio
160
- * Currently changes the cursor pointer associated to the HTML element
161
- * containing the recorder.
162
- * @param {boolean} enabled - Flag indicating if the visual feedback should be active or inactive
163
- * @param {external:jQuery} [$div] - Optional `div` element where the recording is performed, as a jQuery ref.
164
- */
165
- visualFeedbak(enabled, $div) {
166
- if ($div)
167
- $div.css('cursor', enabled ? 'progress' : 'inherit');
168
- }
169
-
170
- /**
171
- * Clears all data associated to this AudioBuffer
172
- */
173
- clear() {
174
- this.stop();
175
- this.mediaPlayer = null;
176
- }
177
- }
178
-
179
- Object.assign(AudioBuffer.prototype, {
180
- /**
181
- * AudioBuffer is enabled only in browsers with `navigator.MediaDevices.getuserMedia`
182
- * @name module:media/AudioBuffer.AudioBuffer#enabled
183
- * @type {boolean}
184
- */
185
- enabled: false,
186
- /**
187
- * Maximum length of recordings allowed to this AudioBuffer (in seconds)
188
- * @name module:media/AudioBuffer.AudioBuffer#seconds
189
- * @type {number}
190
- */
191
- seconds: 20,
192
- /**
193
- * The object used to record audio data and convert it to a valid stream for the {@link module:media/ActiveMediaPlayer.ActiveMediaPlayer ActiveMediaPlayer}
194
- * @name module:media/AudioBuffer.AudioBuffer#mediaRecorder
195
- * @type {external:MediaRecorder}
196
- */
197
- mediaRecorder: null,
198
- /**
199
- * Array of data chunks collected during the recording
200
- * @name module:media/AudioBuffer.AudioBuffer#chunks
201
- * @type {external:Blob[]}
202
- */
203
- chunks: null,
204
- /**
205
- * The HTML audio element used to play the recorded sound
206
- * @name module:media/AudioBuffer.AudioBuffer#mediaPlayer
207
- * @type {external:HTMLAudioElement}
208
- */
209
- mediaPlayer: null,
210
- /**
211
- * The identifier of the timer launched to stop the recording when the maximum time is exceeded.
212
- * This member is `null` when no timeout function is associated to this AudioBuffer
213
- * @name module:media/AudioBuffer.AudioBuffer#timeoutID
214
- * @type {number}
215
- */
216
- timeoutID: null,
217
- /**
218
- * Instructs this AudioBuffer recorder to start playing the collected audio at the end of the
219
- * current `mediaRecorder` task.
220
- * @name module:media/AudioBuffer.AudioBuffer#playWhenFinished
221
- * @type {boolean}
222
- */
223
- playWhenFinished: false,
224
- });
225
-
226
- /**
227
- * Maximum amount of time allowed for recordings (in seconds)
228
- * @type {number}
229
- */
230
- AudioBuffer.MAX_RECORD_LENGTH = 180;
231
-
232
- /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (AudioBuffer);
233
-
234
-
235
- /***/ })
236
-
237
- };
238
- ;
239
- //# sourceMappingURL=5091.jclic-node.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"5091.jclic-node.js","mappings":";;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEkC;;AAElC;AACA;AACA;AACO;AACP;AACA;AACA,aAAa,QAAQ;AACrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,aAAa,iBAAiB;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,4CAA4C,2BAA2B;AACvE;;AAEA;;AAEA;;AAEA;AACA,YAAY,wDAAG,oCAAoC,IAAI;AACvD;AACA;;AAEA;AACA,YAAY,wDAAG;AACf;AACA;;AAEA;AACA,YAAY,wDAAG;AACf;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,+CAA+C,wDAAG,qCAAqC,GAAG;;AAE1F;;AAEA;;AAEA;AACA;AACA;AACA,WAAW;AACX,SAAS;AACT;AACA,UAAU,wDAAG;AACb;AACA,SAAS;AACT;AACA;;AAEA;AACA;AACA;AACA;AACA,aAAa,SAAS;AACtB,aAAa,iBAAiB;AAC9B;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA,oFAAoF;AACpF;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;AACA;AACA,YAAY;AACZ;AACA;AACA,CAAC;;AAED;AACA;AACA,UAAU;AACV;AACA;;AAEA,iEAAe,WAAW,EAAC","sources":["webpack://jclic/./src/media/AudioBuffer.js"],"sourcesContent":["/**\n * File : media/EventSoundsElement.js\n * Created : 01/04/2015\n * By : Francesc Busquets <francesc@gmail.com>\n *\n * JClic.js\n * An HTML5 player of JClic activities\n * https://projectestac.github.io/jclic.js\n *\n * @source https://github.com/projectestac/jclic.js\n *\n * @license EUPL-1.2\n * @licstart\n * (c) 2000-2020 Educational Telematic Network of Catalonia (XTEC)\n *\n * Licensed under the EUPL, Version 1.1 or -as soon they will be approved by\n * the European Commission- subsequent versions of the EUPL (the \"Licence\");\n * You may not use this work except in compliance with the Licence.\n *\n * You may obtain a copy of the Licence at:\n * https://joinup.ec.europa.eu/software/page/eupl\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the Licence is distributed on an \"AS IS\" basis, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * Licence for the specific language governing permissions and limitations\n * under the Licence.\n * @licend\n * @module\n */\n\n/* global navigator, window, document, Blob, URL, MediaRecorder */\n\nimport { log } from '../Utils.js';\n\n/**\n * The AudioBuffer object provides sound recording and replaying to activities.\n */\nexport class AudioBuffer {\n /**\n * AudioBuffer constructor\n * @param {number} [seconds] - The maximum amount of time allowed to be recorded by this AudioBuffer\n */\n constructor(seconds) {\n if (navigator && navigator.mediaDevices && navigator.mediaDevices.getUserMedia)\n this.enabled = true;\n if (seconds)\n this.seconds = seconds;\n this.chunks = [];\n }\n\n /**\n * Starts playing the currently recorded audio, if any.\n */\n play() {\n this.stop();\n if (this.mediaPlayer) {\n this.mediaPlayer.currentTime = 0;\n this.mediaPlayer.play();\n } else {\n this.playWhenFinished = true;\n }\n }\n\n /**\n * Stops the current operation, either recording or playing audio\n */\n stop() {\n if (this.mediaRecorder && this.mediaRecorder.state === 'recording')\n this.mediaRecorder.stop();\n else if (this.mediaPlayer && !this.mediaPlayer.paused)\n this.mediaPlayer.pause();\n }\n\n /**\n * Starts recording audio, or stops the recording if already started.\n * @param {external:jQuery} [$div] - Optional `div` element where the recording is performed, as a jQuery ref.\n */\n record($div) {\n if (this.mediaRecorder && this.mediaRecorder.state === 'recording')\n this.mediaRecorder.stop();\n else if (this.enabled) {\n this.stop();\n this.mediaPlayer = null;\n\n navigator.mediaDevices.getUserMedia({ audio: true, video: false })\n .then(mediaStream => {\n\n this.mediaRecorder = new MediaRecorder(mediaStream);\n\n this.mediaRecorder.ondataavailable = ev => this.chunks.push(ev.data);\n\n this.mediaRecorder.onerror = err => {\n log('error', `Error recording audio: ${err}`);\n this.mediaRecorder = null;\n };\n\n this.mediaRecorder.onstart = () => {\n log('debug', 'Recording audio started');\n this.visualFeedbak(true, $div);\n };\n\n this.mediaRecorder.onstop = () => {\n log('debug', 'Recording audio finished');\n this.visualFeedbak(false, $div);\n\n if (this.timeoutID) {\n window.clearTimeout(this.timeoutID);\n this.timeoutID = null;\n }\n\n const options = {};\n if (this.chunks.length > 0 && this.chunks[0].type)\n options.type = this.chunks[0].type;\n const blob = new Blob(this.chunks, options);\n this.chunks = [];\n this.mediaPlayer = document.createElement('audio');\n this.mediaPlayer.src = URL.createObjectURL(blob);\n this.mediaPlayer.pause();\n this.mediaRecorder = null;\n if (this.playWhenFinished) {\n this.playWhenFinished = false;\n this.mediaPlayer.play();\n }\n };\n\n this.mediaRecorder.onwarning = ev => log('warn', `Warning recording audio: ${ev}`);\n\n this.playWhenFinished = false;\n\n this.mediaRecorder.start();\n\n this.timeoutID = window.setTimeout(() => {\n if (this.mediaRecorder);\n this.mediaRecorder.stop();\n }, this.seconds * 1000);\n })\n .catch(err => {\n log('error', err.toString());\n this.visualFeedbak(false, $div);\n });\n }\n }\n\n /**\n * Set visual feedback to the user while the system is recording audio\n * Currently changes the cursor pointer associated to the HTML element\n * containing the recorder.\n * @param {boolean} enabled - Flag indicating if the visual feedback should be active or inactive\n * @param {external:jQuery} [$div] - Optional `div` element where the recording is performed, as a jQuery ref.\n */\n visualFeedbak(enabled, $div) {\n if ($div)\n $div.css('cursor', enabled ? 'progress' : 'inherit');\n }\n\n /**\n * Clears all data associated to this AudioBuffer\n */\n clear() {\n this.stop();\n this.mediaPlayer = null;\n }\n}\n\nObject.assign(AudioBuffer.prototype, {\n /**\n * AudioBuffer is enabled only in browsers with `navigator.MediaDevices.getuserMedia`\n * @name module:media/AudioBuffer.AudioBuffer#enabled\n * @type {boolean}\n */\n enabled: false,\n /**\n * Maximum length of recordings allowed to this AudioBuffer (in seconds)\n * @name module:media/AudioBuffer.AudioBuffer#seconds\n * @type {number}\n */\n seconds: 20,\n /**\n * The object used to record audio data and convert it to a valid stream for the {@link module:media/ActiveMediaPlayer.ActiveMediaPlayer ActiveMediaPlayer}\n * @name module:media/AudioBuffer.AudioBuffer#mediaRecorder\n * @type {external:MediaRecorder}\n */\n mediaRecorder: null,\n /**\n * Array of data chunks collected during the recording\n * @name module:media/AudioBuffer.AudioBuffer#chunks\n * @type {external:Blob[]}\n */\n chunks: null,\n /**\n * The HTML audio element used to play the recorded sound\n * @name module:media/AudioBuffer.AudioBuffer#mediaPlayer\n * @type {external:HTMLAudioElement}\n */\n mediaPlayer: null,\n /**\n * The identifier of the timer launched to stop the recording when the maximum time is exceeded.\n * This member is `null` when no timeout function is associated to this AudioBuffer\n * @name module:media/AudioBuffer.AudioBuffer#timeoutID\n * @type {number}\n */\n timeoutID: null,\n /**\n * Instructs this AudioBuffer recorder to start playing the collected audio at the end of the\n * current `mediaRecorder` task.\n * @name module:media/AudioBuffer.AudioBuffer#playWhenFinished\n * @type {boolean}\n */\n playWhenFinished: false,\n});\n\n/**\n * Maximum amount of time allowed for recordings (in seconds)\n * @type {number}\n */\nAudioBuffer.MAX_RECORD_LENGTH = 180;\n\nexport default AudioBuffer;\n"],"names":[],"sourceRoot":""}