@corti/dictation-web 0.5.0 → 0.5.1

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/dist/bundle.js CHANGED
@@ -1211,7 +1211,7 @@ function getLanguageName(languageCode) {
1211
1211
  }
1212
1212
  }
1213
1213
  function getLanguagesByRegion(region) {
1214
- const languages = DEFAULT_LANGUAGES_BY_REGION[region || "default"] || DEFAULT_LANGUAGES_BY_REGION.default;
1214
+ const languages = DEFAULT_LANGUAGES_BY_REGION[region || "default"] || DEFAULT_LANGUAGES_BY_REGION["default"];
1215
1215
  const defaultLanguage = languages?.[0];
1216
1216
  return { defaultLanguage, languages };
1217
1217
  }
@@ -1347,14 +1347,14 @@ function decodeToken(token) {
1347
1347
  const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
1348
1348
  let jsonPayload;
1349
1349
  try {
1350
- jsonPayload = decodeURIComponent(atob(base64).split("").map((c6) => `%${`00${c6.charCodeAt(0).toString(16)}`.slice(-2)}`).join(""));
1351
- } catch (_error) {
1350
+ jsonPayload = decodeURIComponent(atob(base64).split("").map((c6) => "%" + ("00" + c6.charCodeAt(0).toString(16)).slice(-2)).join(""));
1351
+ } catch (error) {
1352
1352
  throw new Error("Failed to decode token payload");
1353
1353
  }
1354
1354
  let tokenDetails;
1355
1355
  try {
1356
1356
  tokenDetails = JSON.parse(jsonPayload);
1357
- } catch (_error) {
1357
+ } catch (error) {
1358
1358
  throw new Error("Invalid JSON payload in token");
1359
1359
  }
1360
1360
  const issuerUrl = tokenDetails.iss;
@@ -11282,11 +11282,7 @@ var _DictationController_callbacks;
11282
11282
  var _DictationController_lastDictationConfig;
11283
11283
  var _DictationController_lastSocketUrl;
11284
11284
  var _DictationController_lastSocketProxy;
11285
- var _DictationController_messageBuffer;
11286
- var _DictationController_connectionPromise;
11287
11285
  var _DictationController_configHasChanged;
11288
- var _DictationController_establishConnection;
11289
- var _DictationController_flushMessageBuffer;
11290
11286
  var _DictationController_connectProxy;
11291
11287
  var _DictationController_connectAuth;
11292
11288
  var _DictationController_setupWebSocketHandlers;
@@ -11300,18 +11296,7 @@ var DictationController = class {
11300
11296
  _DictationController_lastDictationConfig.set(this, null);
11301
11297
  _DictationController_lastSocketUrl.set(this, void 0);
11302
11298
  _DictationController_lastSocketProxy.set(this, void 0);
11303
- _DictationController_messageBuffer.set(this, []);
11304
- _DictationController_connectionPromise.set(this, null);
11305
11299
  this.mediaRecorderHandler = (data) => {
11306
- if (__classPrivateFieldGet4(this, _DictationController_connectionPromise, "f")) {
11307
- console.log("[DictationController] Buffering audio chunk (connection pending):", data.size);
11308
- __classPrivateFieldGet4(this, _DictationController_messageBuffer, "f").push({ data, type: "audio" });
11309
- return;
11310
- }
11311
- console.log("[DictationController] Sending audio chunk directly:", {
11312
- size: data.size,
11313
- socketState: __classPrivateFieldGet4(this, _DictationController_webSocket, "f")?.readyState
11314
- });
11315
11300
  __classPrivateFieldGet4(this, _DictationController_webSocket, "f")?.sendAudio(data);
11316
11301
  __classPrivateFieldGet4(this, _DictationController_callbacks, "f")?.onNetworkActivity?.("sent", {
11317
11302
  size: data.size,
@@ -11331,8 +11316,7 @@ var DictationController = class {
11331
11316
  if (__classPrivateFieldGet4(this, _DictationController_webSocket, "f")?.readyState === WebSocket.OPEN) {
11332
11317
  throw new Error("Already connected. Disconnect before reconnecting.");
11333
11318
  }
11334
- __classPrivateFieldSet3(this, _DictationController_connectionPromise, __classPrivateFieldGet4(this, _DictationController_instances, "m", _DictationController_establishConnection).call(this, dictationConfig), "f");
11335
- await __classPrivateFieldGet4(this, _DictationController_connectionPromise, "f");
11319
+ __classPrivateFieldSet3(this, _DictationController_webSocket, this.host._socketUrl || this.host._socketProxy ? await __classPrivateFieldGet4(this, _DictationController_instances, "m", _DictationController_connectProxy).call(this, dictationConfig) : await __classPrivateFieldGet4(this, _DictationController_instances, "m", _DictationController_connectAuth).call(this, dictationConfig), "f");
11336
11320
  __classPrivateFieldGet4(this, _DictationController_callbacks, "f")?.onNetworkActivity?.("sent", {
11337
11321
  configuration: dictationConfig,
11338
11322
  type: "config"
@@ -11346,18 +11330,6 @@ var DictationController = class {
11346
11330
  return newConnection;
11347
11331
  }
11348
11332
  async pause() {
11349
- console.log("[DictationController] pause() called", {
11350
- connectionPending: !!__classPrivateFieldGet4(this, _DictationController_connectionPromise, "f"),
11351
- socketState: __classPrivateFieldGet4(this, _DictationController_webSocket, "f")?.readyState
11352
- });
11353
- if (__classPrivateFieldGet4(this, _DictationController_connectionPromise, "f")) {
11354
- console.log("[DictationController] Buffering flush (connection pending)");
11355
- __classPrivateFieldGet4(this, _DictationController_messageBuffer, "f").push({ data: { type: "flush" }, type: "flush" });
11356
- return;
11357
- }
11358
- console.log("[DictationController] Sending flush", {
11359
- socketState: __classPrivateFieldGet4(this, _DictationController_webSocket, "f")?.readyState
11360
- });
11361
11333
  __classPrivateFieldGet4(this, _DictationController_webSocket, "f")?.sendFlush({ type: "flush" });
11362
11334
  __classPrivateFieldGet4(this, _DictationController_callbacks, "f")?.onNetworkActivity?.("sent", { type: "flush" });
11363
11335
  }
@@ -11419,60 +11391,10 @@ var DictationController = class {
11419
11391
  __classPrivateFieldSet3(this, _DictationController_lastDictationConfig, null, "f");
11420
11392
  __classPrivateFieldSet3(this, _DictationController_lastSocketUrl, void 0, "f");
11421
11393
  __classPrivateFieldSet3(this, _DictationController_lastSocketProxy, void 0, "f");
11422
- __classPrivateFieldSet3(this, _DictationController_messageBuffer, [], "f");
11423
- __classPrivateFieldSet3(this, _DictationController_connectionPromise, null, "f");
11424
11394
  }
11425
11395
  };
11426
- _DictationController_cortiClient = /* @__PURE__ */ new WeakMap(), _DictationController_webSocket = /* @__PURE__ */ new WeakMap(), _DictationController_closeTimeout = /* @__PURE__ */ new WeakMap(), _DictationController_callbacks = /* @__PURE__ */ new WeakMap(), _DictationController_lastDictationConfig = /* @__PURE__ */ new WeakMap(), _DictationController_lastSocketUrl = /* @__PURE__ */ new WeakMap(), _DictationController_lastSocketProxy = /* @__PURE__ */ new WeakMap(), _DictationController_messageBuffer = /* @__PURE__ */ new WeakMap(), _DictationController_connectionPromise = /* @__PURE__ */ new WeakMap(), _DictationController_instances = /* @__PURE__ */ new WeakSet(), _DictationController_configHasChanged = function _DictationController_configHasChanged2() {
11396
+ _DictationController_cortiClient = /* @__PURE__ */ new WeakMap(), _DictationController_webSocket = /* @__PURE__ */ new WeakMap(), _DictationController_closeTimeout = /* @__PURE__ */ new WeakMap(), _DictationController_callbacks = /* @__PURE__ */ new WeakMap(), _DictationController_lastDictationConfig = /* @__PURE__ */ new WeakMap(), _DictationController_lastSocketUrl = /* @__PURE__ */ new WeakMap(), _DictationController_lastSocketProxy = /* @__PURE__ */ new WeakMap(), _DictationController_instances = /* @__PURE__ */ new WeakSet(), _DictationController_configHasChanged = function _DictationController_configHasChanged2() {
11427
11397
  return JSON.stringify(this.host._dictationConfig) !== JSON.stringify(__classPrivateFieldGet4(this, _DictationController_lastDictationConfig, "f")) || this.host._socketUrl !== __classPrivateFieldGet4(this, _DictationController_lastSocketUrl, "f") || JSON.stringify(this.host._socketProxy) !== JSON.stringify(__classPrivateFieldGet4(this, _DictationController_lastSocketProxy, "f"));
11428
- }, _DictationController_establishConnection = async function _DictationController_establishConnection2(dictationConfig) {
11429
- try {
11430
- console.log("[DictationController] Delay complete, connecting to WebSocket...");
11431
- __classPrivateFieldSet3(this, _DictationController_webSocket, this.host._socketUrl || this.host._socketProxy ? await __classPrivateFieldGet4(this, _DictationController_instances, "m", _DictationController_connectProxy).call(this, dictationConfig) : await __classPrivateFieldGet4(this, _DictationController_instances, "m", _DictationController_connectAuth).call(this, dictationConfig), "f");
11432
- console.log("[DictationController] Starting connection establishment (10s delay)...");
11433
- await new Promise((resolve) => setTimeout(resolve, 1e4));
11434
- console.log("[DictationController] WebSocket connected, flushing message buffer...", {
11435
- bufferedMessages: __classPrivateFieldGet4(this, _DictationController_messageBuffer, "f").length,
11436
- socketState: __classPrivateFieldGet4(this, _DictationController_webSocket, "f")?.readyState
11437
- });
11438
- __classPrivateFieldGet4(this, _DictationController_instances, "m", _DictationController_flushMessageBuffer).call(this);
11439
- } catch (error) {
11440
- console.error("[DictationController] Connection establishment failed:", error);
11441
- __classPrivateFieldSet3(this, _DictationController_messageBuffer, [], "f");
11442
- throw error;
11443
- } finally {
11444
- console.log("[DictationController] Connection promise cleared");
11445
- __classPrivateFieldSet3(this, _DictationController_connectionPromise, null, "f");
11446
- }
11447
- }, _DictationController_flushMessageBuffer = function _DictationController_flushMessageBuffer2() {
11448
- console.log("[DictationController] Flushing buffer:", {
11449
- messages: __classPrivateFieldGet4(this, _DictationController_messageBuffer, "f").length,
11450
- socketState: __classPrivateFieldGet4(this, _DictationController_webSocket, "f")?.readyState
11451
- });
11452
- for (const message of __classPrivateFieldGet4(this, _DictationController_messageBuffer, "f")) {
11453
- switch (message.type) {
11454
- case "audio":
11455
- console.log("[DictationController] Sending buffered audio chunk:", message.data.size);
11456
- __classPrivateFieldGet4(this, _DictationController_webSocket, "f")?.sendAudio(message.data);
11457
- __classPrivateFieldGet4(this, _DictationController_callbacks, "f")?.onNetworkActivity?.("sent", {
11458
- size: message.data.size,
11459
- type: "audio"
11460
- });
11461
- break;
11462
- case "flush":
11463
- console.log("[DictationController] Sending buffered flush");
11464
- __classPrivateFieldGet4(this, _DictationController_webSocket, "f")?.sendFlush(message.data);
11465
- __classPrivateFieldGet4(this, _DictationController_callbacks, "f")?.onNetworkActivity?.("sent", message.data);
11466
- break;
11467
- case "end":
11468
- console.log("[DictationController] Sending buffered end");
11469
- __classPrivateFieldGet4(this, _DictationController_webSocket, "f")?.sendEnd(message.data);
11470
- __classPrivateFieldGet4(this, _DictationController_callbacks, "f")?.onNetworkActivity?.("sent", message.data);
11471
- break;
11472
- }
11473
- }
11474
- console.log("[DictationController] Buffer cleared");
11475
- __classPrivateFieldSet3(this, _DictationController_messageBuffer, [], "f");
11476
11398
  }, _DictationController_connectProxy = async function _DictationController_connectProxy2(dictationConfig) {
11477
11399
  const proxyOptions = this.host._socketProxy || {
11478
11400
  url: this.host._socketUrl || ""
@@ -11738,6 +11660,7 @@ var _MediaController_audioLevel;
11738
11660
  var _MediaController_onTrackEnded;
11739
11661
  var _MediaController_onAudioLevelChange;
11740
11662
  var _MediaController_dataHandler;
11663
+ var _MediaController_bufferedChunks;
11741
11664
  var MediaController = class {
11742
11665
  constructor(host) {
11743
11666
  _MediaController_mediaStream.set(this, null);
@@ -11749,15 +11672,15 @@ var MediaController = class {
11749
11672
  _MediaController_onTrackEnded.set(this, void 0);
11750
11673
  _MediaController_onAudioLevelChange.set(this, void 0);
11751
11674
  _MediaController_dataHandler.set(this, void 0);
11675
+ _MediaController_bufferedChunks.set(this, []);
11752
11676
  this.host = host;
11753
11677
  host.addController(this);
11754
11678
  }
11755
11679
  hostDisconnected() {
11756
11680
  this.cleanup();
11757
11681
  }
11758
- async initialize(dataHandler, onTrackEnded) {
11682
+ async initialize(onTrackEnded) {
11759
11683
  await this.cleanup();
11760
- __classPrivateFieldSet5(this, _MediaController_dataHandler, dataHandler, "f");
11761
11684
  __classPrivateFieldSet5(this, _MediaController_onTrackEnded, onTrackEnded, "f");
11762
11685
  __classPrivateFieldSet5(this, _MediaController_mediaStream, await getMediaStream(this.host._selectedDevice?.deviceId, this.host._debug_displayAudio), "f");
11763
11686
  __classPrivateFieldGet6(this, _MediaController_mediaStream, "f").getTracks().forEach((track) => {
@@ -11774,7 +11697,9 @@ var MediaController = class {
11774
11697
  __classPrivateFieldGet6(this, _MediaController_mediaRecorder, "f").ondataavailable = (event) => {
11775
11698
  if (__classPrivateFieldGet6(this, _MediaController_dataHandler, "f")) {
11776
11699
  __classPrivateFieldGet6(this, _MediaController_dataHandler, "f").call(this, event.data);
11700
+ return;
11777
11701
  }
11702
+ __classPrivateFieldGet6(this, _MediaController_bufferedChunks, "f").push(event.data);
11778
11703
  };
11779
11704
  }
11780
11705
  getAudioLevel() {
@@ -11825,6 +11750,7 @@ var MediaController = class {
11825
11750
  __classPrivateFieldSet5(this, _MediaController_onTrackEnded, void 0, "f");
11826
11751
  __classPrivateFieldSet5(this, _MediaController_onAudioLevelChange, void 0, "f");
11827
11752
  __classPrivateFieldSet5(this, _MediaController_dataHandler, void 0, "f");
11753
+ __classPrivateFieldSet5(this, _MediaController_bufferedChunks, [], "f");
11828
11754
  }
11829
11755
  /**
11830
11756
  * Stops the media recorder and waits for all buffered data to be flushed.
@@ -11842,6 +11768,20 @@ var MediaController = class {
11842
11768
  __classPrivateFieldGet6(this, _MediaController_mediaRecorder, "f").stop();
11843
11769
  });
11844
11770
  }
11771
+ addDataHandler(handler) {
11772
+ for (const chunk of __classPrivateFieldGet6(this, _MediaController_bufferedChunks, "f")) {
11773
+ handler(chunk);
11774
+ }
11775
+ __classPrivateFieldSet5(this, _MediaController_bufferedChunks, [], "f");
11776
+ __classPrivateFieldSet5(this, _MediaController_dataHandler, handler, "f");
11777
+ }
11778
+ removeDataHandler() {
11779
+ if (__classPrivateFieldGet6(this, _MediaController_bufferedChunks, "f").length > 0) {
11780
+ this.host.dispatchEvent(errorEvent("Connection timeout: server did not respond in time. Buffered audio was not processed."));
11781
+ __classPrivateFieldSet5(this, _MediaController_bufferedChunks, [], "f");
11782
+ }
11783
+ __classPrivateFieldSet5(this, _MediaController_dataHandler, void 0, "f");
11784
+ }
11845
11785
  get mediaRecorder() {
11846
11786
  return __classPrivateFieldGet6(this, _MediaController_mediaRecorder, "f");
11847
11787
  }
@@ -11849,7 +11789,7 @@ var MediaController = class {
11849
11789
  return __classPrivateFieldGet6(this, _MediaController_audioLevel, "f");
11850
11790
  }
11851
11791
  };
11852
- _MediaController_mediaStream = /* @__PURE__ */ new WeakMap(), _MediaController_audioContext = /* @__PURE__ */ new WeakMap(), _MediaController_analyser = /* @__PURE__ */ new WeakMap(), _MediaController_mediaRecorder = /* @__PURE__ */ new WeakMap(), _MediaController_visualiserInterval = /* @__PURE__ */ new WeakMap(), _MediaController_audioLevel = /* @__PURE__ */ new WeakMap(), _MediaController_onTrackEnded = /* @__PURE__ */ new WeakMap(), _MediaController_onAudioLevelChange = /* @__PURE__ */ new WeakMap(), _MediaController_dataHandler = /* @__PURE__ */ new WeakMap();
11792
+ _MediaController_mediaStream = /* @__PURE__ */ new WeakMap(), _MediaController_audioContext = /* @__PURE__ */ new WeakMap(), _MediaController_analyser = /* @__PURE__ */ new WeakMap(), _MediaController_mediaRecorder = /* @__PURE__ */ new WeakMap(), _MediaController_visualiserInterval = /* @__PURE__ */ new WeakMap(), _MediaController_audioLevel = /* @__PURE__ */ new WeakMap(), _MediaController_onTrackEnded = /* @__PURE__ */ new WeakMap(), _MediaController_onAudioLevelChange = /* @__PURE__ */ new WeakMap(), _MediaController_dataHandler = /* @__PURE__ */ new WeakMap(), _MediaController_bufferedChunks = /* @__PURE__ */ new WeakMap();
11853
11793
 
11854
11794
  // dist/styles/buttons.js
11855
11795
  var ButtonStyles = i`
@@ -12213,10 +12153,7 @@ var DictationRecordingButton = class DictationRecordingButton2 extends i4 {
12213
12153
  _DictationRecordingButton_handleWebSocketMessage.set(this, (message) => {
12214
12154
  switch (message.type) {
12215
12155
  case "CONFIG_ACCEPTED":
12216
- console.log("[RecordingButton] CONFIG_ACCEPTED received", {
12217
- recordingState: this._recordingState,
12218
- willSetProcessing: this._recordingState === "initializing"
12219
- });
12156
+ __classPrivateFieldGet7(this, _DictationRecordingButton_mediaController, "f").addDataHandler(__classPrivateFieldGet7(this, _DictationRecordingButton_dictationController, "f").mediaRecorderHandler);
12220
12157
  if (this._recordingState === "initializing") {
12221
12158
  __classPrivateFieldSet6(this, _DictationRecordingButton_processing, true, "f");
12222
12159
  __classPrivateFieldGet7(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, "recording");
@@ -12252,7 +12189,7 @@ var DictationRecordingButton = class DictationRecordingButton2 extends i4 {
12252
12189
  }
12253
12190
  });
12254
12191
  _DictationRecordingButton_handleWebSocketError.set(this, (error) => {
12255
- this.dispatchEvent(errorEvent(`Socket error: ${error.message}`));
12192
+ this.dispatchEvent(errorEvent("Socket error: " + error.message));
12256
12193
  __classPrivateFieldSet6(this, _DictationRecordingButton_processing, false, "f");
12257
12194
  __classPrivateFieldSet6(this, _DictationRecordingButton_connection, "CLOSED", "f");
12258
12195
  __classPrivateFieldGet7(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
@@ -12382,17 +12319,14 @@ _DictationRecordingButton_dispatchRecordingStateChanged = function _DictationRec
12382
12319
  }));
12383
12320
  };
12384
12321
  _DictationRecordingButton_handleStart = async function _DictationRecordingButton_handleStart2() {
12385
- console.log("[RecordingButton] handleStart() called");
12386
12322
  __classPrivateFieldGet7(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, "initializing");
12387
12323
  try {
12388
- console.log("[RecordingButton] Initializing media controller...");
12389
- await __classPrivateFieldGet7(this, _DictationRecordingButton_mediaController, "f").initialize(__classPrivateFieldGet7(this, _DictationRecordingButton_dictationController, "f").mediaRecorderHandler, () => {
12324
+ await __classPrivateFieldGet7(this, _DictationRecordingButton_mediaController, "f").initialize(() => {
12390
12325
  if (this._recordingState === "recording") {
12391
12326
  this.dispatchEvent(errorEvent("Recording device access was lost."));
12392
12327
  __classPrivateFieldGet7(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
12393
12328
  }
12394
12329
  });
12395
- console.log("[RecordingButton] Starting MediaRecorder...");
12396
12330
  __classPrivateFieldGet7(this, _DictationRecordingButton_mediaController, "f").mediaRecorder?.start(AUDIO_CHUNK_INTERVAL_MS);
12397
12331
  __classPrivateFieldGet7(this, _DictationRecordingButton_mediaController, "f").startAudioLevelMonitoring((level) => {
12398
12332
  this.dispatchEvent(audioLevelChangedEvent(level));
@@ -12401,7 +12335,6 @@ _DictationRecordingButton_handleStart = async function _DictationRecordingButton
12401
12335
  __classPrivateFieldSet6(this, _DictationRecordingButton_connection, "CONNECTING", "f");
12402
12336
  }
12403
12337
  __classPrivateFieldGet7(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, "recording");
12404
- console.log("[RecordingButton] Connecting to WebSocket...");
12405
12338
  const isNewConnection = await __classPrivateFieldGet7(this, _DictationRecordingButton_dictationController, "f").connect(this._dictationConfig, {
12406
12339
  onClose: __classPrivateFieldGet7(this, _DictationRecordingButton_handleWebSocketClose, "f"),
12407
12340
  onError: __classPrivateFieldGet7(this, _DictationRecordingButton_handleWebSocketError, "f"),
@@ -12410,34 +12343,27 @@ _DictationRecordingButton_handleStart = async function _DictationRecordingButton
12410
12343
  this.dispatchEvent(networkActivityEvent(direction, data));
12411
12344
  }
12412
12345
  });
12413
- console.log("[RecordingButton] Connection established", { isNewConnection });
12414
12346
  if (!isNewConnection) {
12347
+ __classPrivateFieldGet7(this, _DictationRecordingButton_mediaController, "f").addDataHandler(__classPrivateFieldGet7(this, _DictationRecordingButton_dictationController, "f").mediaRecorderHandler);
12415
12348
  __classPrivateFieldSet6(this, _DictationRecordingButton_processing, true, "f");
12416
12349
  }
12417
12350
  __classPrivateFieldSet6(this, _DictationRecordingButton_connection, "OPEN", "f");
12418
12351
  __classPrivateFieldGet7(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, "recording");
12419
12352
  } catch (error) {
12420
- console.error("[RecordingButton] Error in handleStart:", error);
12421
12353
  this.dispatchEvent(errorEvent(error));
12422
12354
  await __classPrivateFieldGet7(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
12423
12355
  }
12424
12356
  };
12425
12357
  _DictationRecordingButton_handleStop = async function _DictationRecordingButton_handleStop2() {
12426
- console.log("[RecordingButton] handleStop() called");
12427
12358
  __classPrivateFieldGet7(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, "stopping");
12428
12359
  try {
12429
- console.log("[RecordingButton] Stopping audio level monitoring...");
12430
12360
  __classPrivateFieldGet7(this, _DictationRecordingButton_mediaController, "f").stopAudioLevelMonitoring();
12431
- console.log("[RecordingButton] Stopping media recorder...");
12432
12361
  await __classPrivateFieldGet7(this, _DictationRecordingButton_mediaController, "f").stopRecording();
12362
+ __classPrivateFieldGet7(this, _DictationRecordingButton_mediaController, "f").removeDataHandler();
12433
12363
  __classPrivateFieldGet7(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, "stopped");
12434
- console.log("[RecordingButton] Calling dictationController.pause()...");
12435
12364
  await __classPrivateFieldGet7(this, _DictationRecordingButton_dictationController, "f").pause();
12436
- console.log("[RecordingButton] Cleaning up media controller...");
12437
12365
  await __classPrivateFieldGet7(this, _DictationRecordingButton_mediaController, "f").cleanup();
12438
- console.log("[RecordingButton] Stop complete");
12439
12366
  } catch (error) {
12440
- console.error("[RecordingButton] Error in handleStop:", error);
12441
12367
  this.dispatchEvent(errorEvent(error));
12442
12368
  }
12443
12369
  };
@@ -44,10 +44,7 @@ let DictationRecordingButton = class DictationRecordingButton extends LitElement
44
44
  _DictationRecordingButton_handleWebSocketMessage.set(this, (message) => {
45
45
  switch (message.type) {
46
46
  case "CONFIG_ACCEPTED":
47
- console.log("[RecordingButton] CONFIG_ACCEPTED received", {
48
- recordingState: this._recordingState,
49
- willSetProcessing: this._recordingState === "initializing",
50
- });
47
+ __classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").addDataHandler(__classPrivateFieldGet(this, _DictationRecordingButton_dictationController, "f").mediaRecorderHandler);
51
48
  if (this._recordingState === "initializing") {
52
49
  __classPrivateFieldSet(this, _DictationRecordingButton_processing, true, "f");
53
50
  __classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, "recording");
@@ -84,7 +81,7 @@ let DictationRecordingButton = class DictationRecordingButton extends LitElement
84
81
  }
85
82
  });
86
83
  _DictationRecordingButton_handleWebSocketError.set(this, (error) => {
87
- this.dispatchEvent(errorEvent(`Socket error: ${error.message}`));
84
+ this.dispatchEvent(errorEvent("Socket error: " + error.message));
88
85
  __classPrivateFieldSet(this, _DictationRecordingButton_processing, false, "f");
89
86
  __classPrivateFieldSet(this, _DictationRecordingButton_connection, "CLOSED", "f");
90
87
  __classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
@@ -226,17 +223,14 @@ _DictationRecordingButton_dispatchRecordingStateChanged = function _DictationRec
226
223
  }));
227
224
  };
228
225
  _DictationRecordingButton_handleStart = async function _DictationRecordingButton_handleStart() {
229
- console.log("[RecordingButton] handleStart() called");
230
226
  __classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, "initializing");
231
227
  try {
232
- console.log("[RecordingButton] Initializing media controller...");
233
- await __classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").initialize(__classPrivateFieldGet(this, _DictationRecordingButton_dictationController, "f").mediaRecorderHandler, () => {
228
+ await __classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").initialize(() => {
234
229
  if (this._recordingState === "recording") {
235
230
  this.dispatchEvent(errorEvent("Recording device access was lost."));
236
231
  __classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
237
232
  }
238
233
  });
239
- console.log("[RecordingButton] Starting MediaRecorder...");
240
234
  __classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").mediaRecorder?.start(AUDIO_CHUNK_INTERVAL_MS);
241
235
  __classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").startAudioLevelMonitoring((level) => {
242
236
  this.dispatchEvent(audioLevelChangedEvent(level));
@@ -245,7 +239,6 @@ _DictationRecordingButton_handleStart = async function _DictationRecordingButton
245
239
  __classPrivateFieldSet(this, _DictationRecordingButton_connection, "CONNECTING", "f");
246
240
  }
247
241
  __classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, "recording");
248
- console.log("[RecordingButton] Connecting to WebSocket...");
249
242
  const isNewConnection = await __classPrivateFieldGet(this, _DictationRecordingButton_dictationController, "f").connect(this._dictationConfig, {
250
243
  onClose: __classPrivateFieldGet(this, _DictationRecordingButton_handleWebSocketClose, "f"),
251
244
  onError: __classPrivateFieldGet(this, _DictationRecordingButton_handleWebSocketError, "f"),
@@ -254,36 +247,29 @@ _DictationRecordingButton_handleStart = async function _DictationRecordingButton
254
247
  this.dispatchEvent(networkActivityEvent(direction, data));
255
248
  },
256
249
  });
257
- console.log("[RecordingButton] Connection established", { isNewConnection });
258
250
  if (!isNewConnection) {
251
+ __classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").addDataHandler(__classPrivateFieldGet(this, _DictationRecordingButton_dictationController, "f").mediaRecorderHandler);
259
252
  __classPrivateFieldSet(this, _DictationRecordingButton_processing, true, "f");
260
253
  }
261
254
  __classPrivateFieldSet(this, _DictationRecordingButton_connection, "OPEN", "f");
262
255
  __classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, "recording");
263
256
  }
264
257
  catch (error) {
265
- console.error("[RecordingButton] Error in handleStart:", error);
266
258
  this.dispatchEvent(errorEvent(error));
267
259
  await __classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
268
260
  }
269
261
  };
270
262
  _DictationRecordingButton_handleStop = async function _DictationRecordingButton_handleStop() {
271
- console.log("[RecordingButton] handleStop() called");
272
263
  __classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, "stopping");
273
264
  try {
274
- console.log("[RecordingButton] Stopping audio level monitoring...");
275
265
  __classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").stopAudioLevelMonitoring();
276
- console.log("[RecordingButton] Stopping media recorder...");
277
266
  await __classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").stopRecording();
267
+ __classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").removeDataHandler();
278
268
  __classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, "stopped");
279
- console.log("[RecordingButton] Calling dictationController.pause()...");
280
269
  await __classPrivateFieldGet(this, _DictationRecordingButton_dictationController, "f").pause();
281
- console.log("[RecordingButton] Cleaning up media controller...");
282
270
  await __classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").cleanup();
283
- console.log("[RecordingButton] Stop complete");
284
271
  }
285
272
  catch (error) {
286
- console.error("[RecordingButton] Error in handleStop:", error);
287
273
  this.dispatchEvent(errorEvent(error));
288
274
  }
289
275
  };
@@ -1 +1 @@
1
- {"version":3,"file":"recording-button.js","sourceRoot":"","sources":["../../src/components/recording-button.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAEL,IAAI,EACJ,UAAU,GAEX,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,wBAAwB,EACxB,sBAAsB,EACtB,2BAA2B,EAC3B,qBAAqB,EACrB,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,6BAA6B,GAC9B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,mBAAmB,GAEpB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,YAAY,MAAM,sBAAsB,CAAC;AAChD,OAAO,qBAAqB,MAAM,+BAA+B,CAAC;AAElE,OAAO,EAC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;6DAC0B;AAIlC;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACpD,KAAK,EAAE;yDACS;AAIjB;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACxD,KAAK,EAAE;6DACa;AAIrB;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAC7D,KAAK,EAAE;kEACkC;AAI1C;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACvD,KAAK,EAAE;4DACY;AAIpB;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACzD,KAAK,EAAE;8DACoB;AAI5B;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,wBAAwB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAC/D,KAAK,EAAE;qEACsB;AAI9B;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,2BAA2B,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAClE,KAAK,EAAE;uEAC8B;AAItC;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,6BAA6B,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACpE,KAAK,EAAE;yEACgC;AAGxC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;kEACM;AAlDvB,wBAAwB;IADpC,aAAa,CAAC,4BAA4B,CAAC;GAC/B,wBAAwB,CA4VpC","sourcesContent":["import type { Corti } from \"@corti/sdk\";\nimport { consume } from \"@lit/context\";\nimport {\n type CSSResultGroup,\n html,\n LitElement,\n type PropertyValues,\n} from \"lit\";\nimport { customElement, property, state } from \"lit/decorators.js\";\nimport { AUDIO_CHUNK_INTERVAL_MS } from \"../constants.js\";\nimport {\n accessTokenContext,\n authConfigContext,\n debugDisplayAudioContext,\n dictationConfigContext,\n pushToTalkKeybindingContext,\n recordingStateContext,\n regionContext,\n selectedDeviceContext,\n socketProxyContext,\n socketUrlContext,\n tenantNameContext,\n toggleToTalkKeybindingContext,\n} from \"../contexts/dictation-context.js\";\nimport {\n DictationController,\n type TranscribeMessage,\n} from \"../controllers/dictation-controller.js\";\nimport { KeybindingController } from \"../controllers/keybinding-controller.js\";\nimport { MediaController } from \"../controllers/media-controller.js\";\nimport ButtonStyles from \"../styles/buttons.js\";\nimport RecordingButtonStyles from \"../styles/recording-button.js\";\nimport type { ProxyOptions, RecordingState } from \"../types.js\";\nimport {\n audioLevelChangedEvent,\n commandEvent,\n errorEvent,\n networkActivityEvent,\n type RecordingStateChangedEventDetail,\n recordingStateChangedEvent,\n streamClosedEvent,\n transcriptEvent,\n usageEvent,\n} from \"../utils/events.js\";\n\nimport \"./audio-visualiser.js\";\nimport \"../icons/icons.js\";\n\n@customElement(\"dictation-recording-button\")\nexport class DictationRecordingButton extends LitElement {\n @consume({ context: recordingStateContext, subscribe: true })\n @state()\n _recordingState: RecordingState = \"stopped\";\n\n @consume({ context: selectedDeviceContext, subscribe: true })\n @state()\n _selectedDevice?: MediaDeviceInfo;\n\n @consume({ context: accessTokenContext, subscribe: true })\n @state()\n _accessToken?: string;\n\n @consume({ context: authConfigContext, subscribe: true })\n @state()\n _authConfig?: Corti.BearerOptions;\n\n @consume({ context: regionContext, subscribe: true })\n @state()\n _region?: string;\n\n @consume({ context: tenantNameContext, subscribe: true })\n @state()\n _tenantName?: string;\n\n @consume({ context: dictationConfigContext, subscribe: true })\n @state()\n _dictationConfig?: Corti.TranscribeConfig;\n\n @consume({ context: socketUrlContext, subscribe: true })\n @state()\n _socketUrl?: string;\n\n @consume({ context: socketProxyContext, subscribe: true })\n @state()\n _socketProxy?: ProxyOptions;\n\n @consume({ context: debugDisplayAudioContext, subscribe: true })\n @state()\n _debug_displayAudio?: boolean;\n\n @consume({ context: pushToTalkKeybindingContext, subscribe: true })\n @state()\n _pushToTalkKeybinding?: string | null;\n\n @consume({ context: toggleToTalkKeybindingContext, subscribe: true })\n @state()\n _toggleToTalkKeybinding?: string | null;\n\n @property({ type: Boolean })\n allowButtonFocus: boolean = false;\n\n #mediaController = new MediaController(this);\n #dictationController = new DictationController(this);\n #keybindingController = new KeybindingController(this);\n #closeConnectionOnInit = false;\n #processing = false;\n #connection: RecordingStateChangedEventDetail[\"connection\"] = \"CLOSED\";\n\n static styles: CSSResultGroup = [RecordingButtonStyles, ButtonStyles];\n\n protected update(changedProperties: PropertyValues) {\n if (\n changedProperties.has(\"_recordingState\") &&\n this._recordingState === \"recording\" &&\n this.#closeConnectionOnInit\n ) {\n this.#closeConnectionOnInit = false;\n this.#handleStop();\n }\n\n super.update(changedProperties);\n }\n\n #handleClick(event: MouseEvent): void {\n if (!this.allowButtonFocus) {\n event.preventDefault();\n }\n\n this.toggleRecording();\n }\n\n #handleWebSocketMessage = (message: TranscribeMessage): void => {\n switch (message.type) {\n case \"CONFIG_ACCEPTED\":\n console.log(\"[RecordingButton] CONFIG_ACCEPTED received\", {\n recordingState: this._recordingState,\n willSetProcessing: this._recordingState === \"initializing\",\n });\n if (this._recordingState === \"initializing\") {\n this.#processing = true;\n this.#dispatchRecordingStateChanged(\"recording\");\n }\n break;\n case \"CONFIG_DENIED\":\n this.dispatchEvent(\n errorEvent(`Config denied: ${message.reason ?? \"Unknown reason\"}`),\n );\n this.#handleStop();\n break;\n case \"CONFIG_TIMEOUT\":\n this.dispatchEvent(errorEvent(\"Config timeout\"));\n this.#handleStop();\n break;\n case \"transcript\":\n this.dispatchEvent(transcriptEvent(message));\n break;\n case \"command\":\n this.dispatchEvent(commandEvent(message));\n break;\n case \"usage\":\n this.dispatchEvent(usageEvent(message));\n break;\n case \"error\":\n this.dispatchEvent(errorEvent(message.error));\n this.#handleStop();\n break;\n case \"flushed\":\n if (\n this._recordingState === \"stopped\" ||\n this._recordingState === \"stopping\"\n ) {\n this.#processing = false;\n this.#dispatchRecordingStateChanged(this._recordingState);\n }\n break;\n }\n };\n\n #handleWebSocketError = (error: Error): void => {\n this.dispatchEvent(errorEvent(`Socket error: ${error.message}`));\n this.#processing = false;\n this.#connection = \"CLOSED\";\n this.#handleStop();\n };\n\n #handleWebSocketClose = (event: unknown): void => {\n // When we already have new socket opened\n if (this.#dictationController.isConnectionOpen()) {\n return;\n }\n\n this.#processing = false;\n this.#connection = \"CLOSED\";\n this.dispatchEvent(streamClosedEvent(event));\n this.#dispatchRecordingStateChanged(this._recordingState);\n };\n\n #dispatchRecordingStateChanged(state: RecordingState): void {\n this.dispatchEvent(\n recordingStateChangedEvent(state, {\n connection: this.#connection,\n processing: this.#processing,\n }),\n );\n }\n\n async #handleStart(): Promise<void> {\n console.log(\"[RecordingButton] handleStart() called\");\n this.#dispatchRecordingStateChanged(\"initializing\");\n\n try {\n console.log(\"[RecordingButton] Initializing media controller...\");\n await this.#mediaController.initialize(\n this.#dictationController.mediaRecorderHandler,\n () => {\n if (this._recordingState === \"recording\") {\n this.dispatchEvent(errorEvent(\"Recording device access was lost.\"));\n this.#handleStop();\n }\n },\n );\n console.log(\"[RecordingButton] Starting MediaRecorder...\");\n this.#mediaController.mediaRecorder?.start(AUDIO_CHUNK_INTERVAL_MS);\n this.#mediaController.startAudioLevelMonitoring((level) => {\n this.dispatchEvent(audioLevelChangedEvent(level));\n });\n\n if (this.#connection !== \"OPEN\") {\n this.#connection = \"CONNECTING\";\n }\n\n this.#dispatchRecordingStateChanged(\"recording\");\n\n console.log(\"[RecordingButton] Connecting to WebSocket...\");\n const isNewConnection = await this.#dictationController.connect(\n this._dictationConfig,\n {\n onClose: this.#handleWebSocketClose,\n onError: this.#handleWebSocketError,\n onMessage: this.#handleWebSocketMessage,\n onNetworkActivity: (direction, data) => {\n this.dispatchEvent(networkActivityEvent(direction, data));\n },\n },\n );\n\n console.log(\"[RecordingButton] Connection established\", { isNewConnection });\n\n if (!isNewConnection) {\n this.#processing = true;\n }\n\n this.#connection = \"OPEN\";\n\n this.#dispatchRecordingStateChanged(\"recording\");\n } catch (error) {\n console.error(\"[RecordingButton] Error in handleStart:\", error);\n this.dispatchEvent(errorEvent(error));\n await this.#handleStop();\n }\n }\n\n async #handleStop(): Promise<void> {\n console.log(\"[RecordingButton] handleStop() called\");\n this.#dispatchRecordingStateChanged(\"stopping\");\n\n try {\n console.log(\"[RecordingButton] Stopping audio level monitoring...\");\n this.#mediaController.stopAudioLevelMonitoring();\n console.log(\"[RecordingButton] Stopping media recorder...\");\n await this.#mediaController.stopRecording();\n\n this.#dispatchRecordingStateChanged(\"stopped\");\n\n console.log(\"[RecordingButton] Calling dictationController.pause()...\");\n await this.#dictationController.pause();\n console.log(\"[RecordingButton] Cleaning up media controller...\");\n await this.#mediaController.cleanup();\n console.log(\"[RecordingButton] Stop complete\");\n } catch (error) {\n console.error(\"[RecordingButton] Error in handleStop:\", error);\n this.dispatchEvent(errorEvent(error));\n }\n }\n\n public startRecording(): void {\n if (this._recordingState !== \"stopped\") {\n return;\n }\n\n this.#handleStart();\n }\n\n public stopRecording(): void {\n if (\n this._recordingState === \"stopped\" ||\n this._recordingState === \"stopping\"\n ) {\n return;\n }\n\n if (this._recordingState === \"initializing\") {\n this.#closeConnectionOnInit = true;\n return;\n }\n\n this.#handleStop();\n }\n\n public toggleRecording(): void {\n if (this._recordingState === \"stopped\") {\n this.startRecording();\n } else if (this._recordingState === \"recording\") {\n this.stopRecording();\n }\n }\n\n public async openConnection(): Promise<void> {\n if (this._recordingState !== \"stopped\" || this.#processing) {\n return;\n }\n\n if (this.#dictationController.isConnectionOpen()) {\n return;\n }\n\n try {\n this.#connection = \"CONNECTING\";\n this.#dispatchRecordingStateChanged(\"stopped\");\n\n await this.#dictationController.connect(this._dictationConfig, {\n onClose: this.#handleWebSocketClose,\n onError: this.#handleWebSocketError,\n onMessage: this.#handleWebSocketMessage,\n onNetworkActivity: (direction, data) => {\n this.dispatchEvent(networkActivityEvent(direction, data));\n },\n });\n\n this.#connection = \"OPEN\";\n this.#dispatchRecordingStateChanged(\"stopped\");\n } catch (error) {\n this.#connection = \"CLOSED\";\n this.dispatchEvent(errorEvent(error));\n }\n }\n\n public async closeConnection(): Promise<void> {\n if (this._recordingState !== \"stopped\" || this.#processing) {\n return;\n }\n\n if (!this.#dictationController.isConnectionOpen()) {\n this.#connection = \"CLOSED\";\n this.#dispatchRecordingStateChanged(\"stopped\");\n return;\n }\n\n try {\n this.#connection = \"CLOSING\";\n this.#dispatchRecordingStateChanged(\"stopped\");\n await this.#dictationController.closeConnection(\n this.#handleWebSocketClose,\n );\n } catch (error) {\n this.dispatchEvent(errorEvent(error));\n }\n }\n\n render() {\n const isLoading =\n this._recordingState === \"initializing\" ||\n this._recordingState === \"stopping\";\n const isRecording = this._recordingState === \"recording\";\n\n return html`\n <button\n @click=${this.#handleClick}\n ?disabled=${isLoading}\n class=${isRecording ? \"red\" : \"accent\"}\n aria-label=${isRecording ? \"Stop recording\" : \"Start recording\"}\n aria-pressed=${isRecording}\n >\n ${\n isLoading\n ? html`<icon-loading-spinner />`\n : isRecording\n ? html`<icon-recording />`\n : html`<icon-mic-on />`\n }\n <dictation-audio-visualiser\n .level=${this.#mediaController.audioLevel}\n ?active=${isRecording}\n />\n </button>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"dictation-recording-button\": DictationRecordingButton;\n }\n}\n"]}
1
+ {"version":3,"file":"recording-button.js","sourceRoot":"","sources":["../../src/components/recording-button.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAEL,IAAI,EACJ,UAAU,GAEX,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OA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IACxD,KAAK,EAAE;6DACa;AAIrB;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAC7D,KAAK,EAAE;kEACkC;AAI1C;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACvD,KAAK,EAAE;4DACY;AAIpB;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACzD,KAAK,EAAE;8DACoB;AAI5B;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,wBAAwB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAC/D,KAAK,EAAE;qEACsB;AAI9B;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,2BAA2B,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAClE,KAAK,EAAE;uEAC8B;AAItC;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,6BAA6B,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACpE,KAAK,EAAE;yEACgC;AAGxC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;kEACM;AAlDvB,wBAAwB;IADpC,aAAa,CAAC,4BAA4B,CAAC;GAC/B,wBAAwB,CA+UpC","sourcesContent":["import type { Corti } from \"@corti/sdk\";\nimport { consume } from \"@lit/context\";\nimport {\n type CSSResultGroup,\n html,\n LitElement,\n type PropertyValues,\n} from \"lit\";\nimport { customElement, property, state } from \"lit/decorators.js\";\nimport { AUDIO_CHUNK_INTERVAL_MS } from \"../constants.js\";\nimport {\n accessTokenContext,\n authConfigContext,\n debugDisplayAudioContext,\n dictationConfigContext,\n pushToTalkKeybindingContext,\n recordingStateContext,\n regionContext,\n selectedDeviceContext,\n socketProxyContext,\n socketUrlContext,\n tenantNameContext,\n toggleToTalkKeybindingContext,\n} from \"../contexts/dictation-context.js\";\nimport {\n DictationController,\n type TranscribeMessage,\n} from \"../controllers/dictation-controller.js\";\nimport { KeybindingController } from \"../controllers/keybinding-controller.js\";\nimport { MediaController } from \"../controllers/media-controller.js\";\nimport ButtonStyles from \"../styles/buttons.js\";\nimport RecordingButtonStyles from \"../styles/recording-button.js\";\nimport type { ProxyOptions, RecordingState } from \"../types.js\";\nimport {\n audioLevelChangedEvent,\n commandEvent,\n errorEvent,\n networkActivityEvent,\n type RecordingStateChangedEventDetail,\n recordingStateChangedEvent,\n streamClosedEvent,\n transcriptEvent,\n usageEvent,\n} from \"../utils/events.js\";\n\nimport \"./audio-visualiser.js\";\nimport \"../icons/icons.js\";\n\n@customElement(\"dictation-recording-button\")\nexport class DictationRecordingButton extends LitElement {\n @consume({ context: recordingStateContext, subscribe: true })\n @state()\n _recordingState: RecordingState = \"stopped\";\n\n @consume({ context: selectedDeviceContext, subscribe: true })\n @state()\n _selectedDevice?: MediaDeviceInfo;\n\n @consume({ context: accessTokenContext, subscribe: true })\n @state()\n _accessToken?: string;\n\n @consume({ context: authConfigContext, subscribe: true })\n @state()\n _authConfig?: Corti.BearerOptions;\n\n @consume({ context: regionContext, subscribe: true })\n @state()\n _region?: string;\n\n @consume({ context: tenantNameContext, subscribe: true })\n @state()\n _tenantName?: string;\n\n @consume({ context: dictationConfigContext, subscribe: true })\n @state()\n _dictationConfig?: Corti.TranscribeConfig;\n\n @consume({ context: socketUrlContext, subscribe: true })\n @state()\n _socketUrl?: string;\n\n @consume({ context: socketProxyContext, subscribe: true })\n @state()\n _socketProxy?: ProxyOptions;\n\n @consume({ context: debugDisplayAudioContext, subscribe: true })\n @state()\n _debug_displayAudio?: boolean;\n\n @consume({ context: pushToTalkKeybindingContext, subscribe: true })\n @state()\n _pushToTalkKeybinding?: string | null;\n\n @consume({ context: toggleToTalkKeybindingContext, subscribe: true })\n @state()\n _toggleToTalkKeybinding?: string | null;\n\n @property({ type: Boolean })\n allowButtonFocus: boolean = false;\n\n #mediaController = new MediaController(this);\n #dictationController = new DictationController(this);\n #keybindingController = new KeybindingController(this);\n #closeConnectionOnInit = false;\n #processing = false;\n #connection: RecordingStateChangedEventDetail[\"connection\"] = \"CLOSED\";\n\n static styles: CSSResultGroup = [RecordingButtonStyles, ButtonStyles];\n\n protected update(changedProperties: PropertyValues) {\n if (\n changedProperties.has(\"_recordingState\") &&\n this._recordingState === \"recording\" &&\n this.#closeConnectionOnInit\n ) {\n this.#closeConnectionOnInit = false;\n this.#handleStop();\n }\n\n super.update(changedProperties);\n }\n\n #handleClick(event: MouseEvent): void {\n if (!this.allowButtonFocus) {\n event.preventDefault();\n }\n\n this.toggleRecording();\n }\n\n #handleWebSocketMessage = (message: TranscribeMessage): void => {\n switch (message.type) {\n case \"CONFIG_ACCEPTED\":\n this.#mediaController.addDataHandler(\n this.#dictationController.mediaRecorderHandler,\n );\n\n if (this._recordingState === \"initializing\") {\n this.#processing = true;\n this.#dispatchRecordingStateChanged(\"recording\");\n }\n break;\n case \"CONFIG_DENIED\":\n this.dispatchEvent(\n errorEvent(`Config denied: ${message.reason ?? \"Unknown reason\"}`),\n );\n this.#handleStop();\n break;\n case \"CONFIG_TIMEOUT\":\n this.dispatchEvent(errorEvent(\"Config timeout\"));\n this.#handleStop();\n break;\n case \"transcript\":\n this.dispatchEvent(transcriptEvent(message));\n break;\n case \"command\":\n this.dispatchEvent(commandEvent(message));\n break;\n case \"usage\":\n this.dispatchEvent(usageEvent(message));\n break;\n case \"error\":\n this.dispatchEvent(errorEvent(message.error));\n this.#handleStop();\n break;\n case \"flushed\":\n if (\n this._recordingState === \"stopped\" ||\n this._recordingState === \"stopping\"\n ) {\n this.#processing = false;\n this.#dispatchRecordingStateChanged(this._recordingState);\n }\n break;\n }\n };\n\n #handleWebSocketError = (error: Error): void => {\n this.dispatchEvent(errorEvent(\"Socket error: \" + error.message));\n this.#processing = false;\n this.#connection = \"CLOSED\";\n this.#handleStop();\n };\n\n #handleWebSocketClose = (event: unknown): void => {\n // When we already have new socket opened\n if (this.#dictationController.isConnectionOpen()) {\n return;\n }\n\n this.#processing = false;\n this.#connection = \"CLOSED\";\n this.dispatchEvent(streamClosedEvent(event));\n this.#dispatchRecordingStateChanged(this._recordingState);\n };\n\n #dispatchRecordingStateChanged(state: RecordingState): void {\n this.dispatchEvent(\n recordingStateChangedEvent(state, {\n connection: this.#connection,\n processing: this.#processing,\n }),\n );\n }\n\n async #handleStart(): Promise<void> {\n this.#dispatchRecordingStateChanged(\"initializing\");\n\n try {\n await this.#mediaController.initialize(() => {\n if (this._recordingState === \"recording\") {\n this.dispatchEvent(errorEvent(\"Recording device access was lost.\"));\n this.#handleStop();\n }\n });\n this.#mediaController.mediaRecorder?.start(AUDIO_CHUNK_INTERVAL_MS);\n this.#mediaController.startAudioLevelMonitoring((level) => {\n this.dispatchEvent(audioLevelChangedEvent(level));\n });\n\n if (this.#connection !== \"OPEN\") {\n this.#connection = \"CONNECTING\";\n }\n\n this.#dispatchRecordingStateChanged(\"recording\");\n\n const isNewConnection = await this.#dictationController.connect(\n this._dictationConfig,\n {\n onClose: this.#handleWebSocketClose,\n onError: this.#handleWebSocketError,\n onMessage: this.#handleWebSocketMessage,\n onNetworkActivity: (direction, data) => {\n this.dispatchEvent(networkActivityEvent(direction, data));\n },\n },\n );\n\n if (!isNewConnection) {\n this.#mediaController.addDataHandler(\n this.#dictationController.mediaRecorderHandler,\n );\n this.#processing = true;\n }\n\n this.#connection = \"OPEN\";\n\n this.#dispatchRecordingStateChanged(\"recording\");\n } catch (error) {\n this.dispatchEvent(errorEvent(error));\n await this.#handleStop();\n }\n }\n\n async #handleStop(): Promise<void> {\n this.#dispatchRecordingStateChanged(\"stopping\");\n\n try {\n this.#mediaController.stopAudioLevelMonitoring();\n await this.#mediaController.stopRecording();\n this.#mediaController.removeDataHandler();\n\n this.#dispatchRecordingStateChanged(\"stopped\");\n\n await this.#dictationController.pause();\n await this.#mediaController.cleanup();\n } catch (error) {\n this.dispatchEvent(errorEvent(error));\n }\n }\n\n public startRecording(): void {\n if (this._recordingState !== \"stopped\") {\n return;\n }\n\n this.#handleStart();\n }\n\n public stopRecording(): void {\n if (\n this._recordingState === \"stopped\" ||\n this._recordingState === \"stopping\"\n ) {\n return;\n }\n\n if (this._recordingState === \"initializing\") {\n this.#closeConnectionOnInit = true;\n return;\n }\n\n this.#handleStop();\n }\n\n public toggleRecording(): void {\n if (this._recordingState === \"stopped\") {\n this.startRecording();\n } else if (this._recordingState === \"recording\") {\n this.stopRecording();\n }\n }\n\n public async openConnection(): Promise<void> {\n if (this._recordingState !== \"stopped\" || this.#processing) {\n return;\n }\n\n if (this.#dictationController.isConnectionOpen()) {\n return;\n }\n\n try {\n this.#connection = \"CONNECTING\";\n this.#dispatchRecordingStateChanged(\"stopped\");\n\n await this.#dictationController.connect(this._dictationConfig, {\n onClose: this.#handleWebSocketClose,\n onError: this.#handleWebSocketError,\n onMessage: this.#handleWebSocketMessage,\n onNetworkActivity: (direction, data) => {\n this.dispatchEvent(networkActivityEvent(direction, data));\n },\n });\n\n this.#connection = \"OPEN\";\n this.#dispatchRecordingStateChanged(\"stopped\");\n } catch (error) {\n this.#connection = \"CLOSED\";\n this.dispatchEvent(errorEvent(error));\n }\n }\n\n public async closeConnection(): Promise<void> {\n if (this._recordingState !== \"stopped\" || this.#processing) {\n return;\n }\n\n if (!this.#dictationController.isConnectionOpen()) {\n this.#connection = \"CLOSED\";\n this.#dispatchRecordingStateChanged(\"stopped\");\n return;\n }\n\n try {\n this.#connection = \"CLOSING\";\n this.#dispatchRecordingStateChanged(\"stopped\");\n await this.#dictationController.closeConnection(\n this.#handleWebSocketClose,\n );\n } catch (error) {\n this.dispatchEvent(errorEvent(error));\n }\n }\n\n render() {\n const isLoading =\n this._recordingState === \"initializing\" ||\n this._recordingState === \"stopping\";\n const isRecording = this._recordingState === \"recording\";\n\n return html`\n <button\n @click=${this.#handleClick}\n ?disabled=${isLoading}\n class=${isRecording ? \"red\" : \"accent\"}\n aria-label=${isRecording ? \"Stop recording\" : \"Start recording\"}\n aria-pressed=${isRecording}\n >\n ${\n isLoading\n ? html`<icon-loading-spinner />`\n : isRecording\n ? html`<icon-recording />`\n : html`<icon-mic-on />`\n }\n <dictation-audio-visualiser\n .level=${this.#mediaController.audioLevel}\n ?active=${isRecording}\n />\n </button>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"dictation-recording-button\": DictationRecordingButton;\n }\n}\n"]}