@corti/dictation-web 0.6.0 → 0.6.1-rc.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
@@ -962,36 +962,43 @@ function c5({ context: c6, subscribe: e10 }) {
962
962
  }
963
963
 
964
964
  // dist/utils/devices.js
965
- async function requestMicAccess() {
966
- if (!navigator.permissions) {
967
- const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
968
- stream.getTracks().forEach((track) => {
969
- track.stop();
965
+ async function primeMicStream() {
966
+ if (navigator.permissions) {
967
+ const permissionStatus = await navigator.permissions.query({
968
+ name: "microphone"
970
969
  });
971
- return;
970
+ if (permissionStatus.state === "denied") {
971
+ throw new Error("Microphone permission is denied");
972
+ }
972
973
  }
973
- const permissionStatus = await navigator.permissions.query({
974
- name: "microphone"
974
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
975
+ stream.getTracks().forEach((track) => {
976
+ track.stop();
975
977
  });
976
- if (permissionStatus.state === "denied") {
977
- throw new Error("Microphone permission is denied");
978
- }
979
- if (permissionStatus.state === "prompt") {
980
- const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
981
- stream.getTracks().forEach((track) => {
982
- track.stop();
983
- });
984
- }
985
978
  }
986
979
  async function getAudioDevices() {
987
980
  if (!navigator.mediaDevices?.enumerateDevices) {
988
981
  throw new Error("MediaDevices API is not available");
989
982
  }
990
- await requestMicAccess();
983
+ let audioDevices = await listAudioInputs();
984
+ if (needsMicPriming(audioDevices)) {
985
+ await primeMicStream();
986
+ audioDevices = await listAudioInputs();
987
+ }
988
+ return {
989
+ defaultDevice: audioDevices[0],
990
+ devices: audioDevices
991
+ };
992
+ }
993
+ async function listAudioInputs() {
991
994
  const devices = await navigator.mediaDevices.enumerateDevices();
992
- const audioDevices = devices.filter((device) => device.kind === "audioinput");
993
- const defaultDevice = audioDevices.length > 0 ? audioDevices[0] : void 0;
994
- return { defaultDevice, devices: audioDevices };
995
+ return devices.filter((device) => device.kind === "audioinput");
996
+ }
997
+ function needsMicPriming(audioInputs) {
998
+ if (audioInputs.length === 0) {
999
+ return false;
1000
+ }
1001
+ return audioInputs.some((d3) => d3.deviceId === "" || d3.label === "");
995
1002
  }
996
1003
 
997
1004
  // dist/utils/events.js
@@ -12845,11 +12852,10 @@ function normalizeKeybinding(keybinding) {
12845
12852
  if (!keybinding) {
12846
12853
  return null;
12847
12854
  }
12848
- const trimmed = keybinding.trim();
12849
- if (trimmed === "") {
12855
+ if (keybinding !== " " && keybinding.trim() === "") {
12850
12856
  return null;
12851
12857
  }
12852
- return normalizeKeyForKeybinding(trimmed);
12858
+ return normalizeKeyForKeybinding(keybinding);
12853
12859
  }
12854
12860
  function matchesKeybinding(event, keybinding) {
12855
12861
  const normalizedKeybinding = normalizeKeybinding(keybinding);