@sdata/web-vue 3.22.2 → 3.22.3

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.
@@ -13,6 +13,7 @@ class SdSenderAudioProcessor extends AudioWorkletProcessor {
13
13
  this.bufferSize = Math.max(128, options.processorOptions?.bufferSize || ${DEFAULT_BUFFER_SIZE});
14
14
  this.buffer = new Float32Array(this.bufferSize);
15
15
  this.offset = 0;
16
+ this.stopped = false;
16
17
  this.port.onmessage = (event) => {
17
18
  if (event.data?.type !== 'flush') return;
18
19
  if (this.offset > 0) {
@@ -20,11 +21,13 @@ class SdSenderAudioProcessor extends AudioWorkletProcessor {
20
21
  this.port.postMessage(chunk.buffer, [chunk.buffer]);
21
22
  this.offset = 0;
22
23
  }
24
+ this.stopped = true;
23
25
  this.port.postMessage({ type: 'flushed' });
24
26
  };
25
27
  }
26
28
 
27
29
  process(inputs) {
30
+ if (this.stopped) return false;
28
31
  const channels = inputs[0];
29
32
  if (!channels?.length) return true;
30
33
  const frames = channels[0].length;
@@ -66,7 +69,8 @@ function useSpeech(allowSpeech, options) {
66
69
  const chunks = shallowRef(0);
67
70
  const sequence = shallowRef(0);
68
71
  let generatedWorkletUrl;
69
- let resolveWorkletFlush;
72
+ let resolveWorkletStop;
73
+ let workletStopRequested = false;
70
74
  let workletReady = false;
71
75
  let disposed = false;
72
76
  const recording = computed(() => controlled.value && typeof config.value === "object" ? Boolean(config.value.recording) : internalRecording.value);
@@ -123,25 +127,36 @@ function useSpeech(allowSpeech, options) {
123
127
  else reject(errorEvent.error);
124
128
  };
125
129
  });
126
- const flushWorklet = () => new Promise((resolve) => {
130
+ const stopWorklet = () => new Promise((resolve) => {
127
131
  var _workletNode$value;
128
132
  const port = (_workletNode$value = workletNode.value) === null || _workletNode$value === void 0 ? void 0 : _workletNode$value.port;
129
- if (!port) {
133
+ if (!port || workletStopRequested) {
130
134
  resolve();
131
135
  return;
132
136
  }
133
- const timeout = window.setTimeout(resolve, 100);
134
- resolveWorkletFlush = () => {
137
+ workletStopRequested = true;
138
+ let settled = false;
139
+ const finish = () => {
140
+ if (settled) return;
141
+ settled = true;
135
142
  window.clearTimeout(timeout);
136
- resolveWorkletFlush = void 0;
143
+ resolveWorkletStop = void 0;
137
144
  resolve();
138
145
  };
146
+ const timeout = window.setTimeout(finish, 100);
147
+ resolveWorkletStop = finish;
139
148
  port.postMessage({ type: "flush" });
140
149
  });
141
150
  const releaseResources = function() {
142
151
  var _ref = _asyncToGenerator(function* () {
143
- var _workletNode$value2, _sourceNode$value, _stream$value, _audioContext$value;
144
- (_workletNode$value2 = workletNode.value) === null || _workletNode$value2 === void 0 || _workletNode$value2.disconnect();
152
+ var _sourceNode$value, _stream$value, _audioContext$value;
153
+ const currentWorkletNode = workletNode.value;
154
+ yield stopWorklet();
155
+ if (currentWorkletNode) {
156
+ currentWorkletNode.port.onmessage = null;
157
+ currentWorkletNode.port.close();
158
+ currentWorkletNode.disconnect();
159
+ }
145
160
  (_sourceNode$value = sourceNode.value) === null || _sourceNode$value === void 0 || _sourceNode$value.disconnect();
146
161
  (_stream$value = stream.value) === null || _stream$value === void 0 || _stream$value.getTracks().forEach((track) => track.stop());
147
162
  if (((_audioContext$value = audioContext.value) === null || _audioContext$value === void 0 ? void 0 : _audioContext$value.state) === "running") yield audioContext.value.suspend();
@@ -171,7 +186,7 @@ function useSpeech(allowSpeech, options) {
171
186
  stopping.value = true;
172
187
  try {
173
188
  var _socket$value, _config$value$onRecor, _config$value;
174
- yield flushWorklet();
189
+ yield stopWorklet();
175
190
  const endedAt = performance.now();
176
191
  internalRecording.value = false;
177
192
  if (((_socket$value = socket.value) === null || _socket$value === void 0 ? void 0 : _socket$value.readyState) === WebSocket.OPEN && typeof config.value === "object" && config.value.sendMetadata !== false) socket.value.send(JSON.stringify({
@@ -246,12 +261,13 @@ function useSpeech(allowSpeech, options) {
246
261
  channelCount: 1,
247
262
  processorOptions: _objectSpread2(_objectSpread2({}, speechConfig === null || speechConfig === void 0 ? void 0 : speechConfig.processorOptions), {}, { bufferSize })
248
263
  });
264
+ workletStopRequested = false;
249
265
  workletNode.value = nextWorkletNode;
250
266
  sourceNode.value = nextAudioContext.createMediaStreamSource(stream.value);
251
267
  nextWorkletNode.port.onmessage = (event) => {
252
268
  var _socket$value2;
253
269
  if (!(event.data instanceof ArrayBuffer) && "type" in event.data) {
254
- if (event.data.type === "flushed") resolveWorkletFlush === null || resolveWorkletFlush === void 0 || resolveWorkletFlush();
270
+ if (event.data.type === "flushed") resolveWorkletStop === null || resolveWorkletStop === void 0 || resolveWorkletStop();
255
271
  return;
256
272
  }
257
273
  if (!internalRecording.value) return;
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json",
3
3
  "framework": "vue",
4
4
  "name": "@sdata/web-vue",
5
- "version": "3.22.1",
5
+ "version": "3.22.2",
6
6
  "contributions": {
7
7
  "html": {
8
8
  "types-syntax": "typescript",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdata/web-vue",
3
- "version": "3.22.2",
3
+ "version": "3.22.3",
4
4
  "description": "SD Design Vue: A Vue.js 3 UI Library",
5
5
  "keywords": [
6
6
  "sd",