@corti/dictation-web 0.6.0 → 0.7.0-ambient
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 +1838 -1455
- package/dist/components/ambient-recording-button.d.ts +16 -0
- package/dist/components/ambient-recording-button.js +68 -0
- package/dist/components/ambient-recording-button.js.map +1 -0
- package/dist/components/corti-ambient.d.ts +27 -0
- package/dist/components/corti-ambient.js +97 -0
- package/dist/components/corti-ambient.js.map +1 -0
- package/dist/components/corti-dictation.d.ts +9 -109
- package/dist/components/corti-dictation.js +12 -187
- package/dist/components/corti-dictation.js.map +1 -1
- package/dist/components/corti-root.d.ts +121 -0
- package/dist/components/corti-root.js +196 -0
- package/dist/components/corti-root.js.map +1 -0
- package/dist/components/device-selector.js +1 -1
- package/dist/components/device-selector.js.map +1 -1
- package/dist/components/dictation-recording-button.d.ts +13 -0
- package/dist/components/dictation-recording-button.js +30 -0
- package/dist/components/dictation-recording-button.js.map +1 -0
- package/dist/components/keybinding-input.js +1 -1
- package/dist/components/keybinding-input.js.map +1 -1
- package/dist/components/keybinding-selector.js +1 -1
- package/dist/components/keybinding-selector.js.map +1 -1
- package/dist/components/language-selector.js +2 -1
- package/dist/components/language-selector.js.map +1 -1
- package/dist/components/{recording-button.d.ts → recording-button-base.d.ts} +7 -9
- package/dist/components/recording-button-base.js +321 -0
- package/dist/components/recording-button-base.js.map +1 -0
- package/dist/components/settings-menu.js +1 -1
- package/dist/components/settings-menu.js.map +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +9 -0
- package/dist/constants.js.map +1 -1
- package/dist/contexts/ambient-context.d.ts +18 -0
- package/dist/contexts/ambient-context.js +48 -0
- package/dist/contexts/ambient-context.js.map +1 -0
- package/dist/contexts/dictation-context.d.ts +3 -92
- package/dist/contexts/dictation-context.js +5 -257
- package/dist/contexts/dictation-context.js.map +1 -1
- package/dist/contexts/mixins/auth-context.d.ts +32 -0
- package/dist/contexts/mixins/auth-context.js +116 -0
- package/dist/contexts/mixins/auth-context.js.map +1 -0
- package/dist/contexts/mixins/devices-context.d.ts +14 -0
- package/dist/contexts/mixins/devices-context.js +58 -0
- package/dist/contexts/mixins/devices-context.js.map +1 -0
- package/dist/contexts/mixins/keybindings-context.d.ts +13 -0
- package/dist/contexts/mixins/keybindings-context.js +62 -0
- package/dist/contexts/mixins/keybindings-context.js.map +1 -0
- package/dist/contexts/mixins/languages-context.d.ts +11 -0
- package/dist/contexts/mixins/languages-context.js +54 -0
- package/dist/contexts/mixins/languages-context.js.map +1 -0
- package/dist/contexts/mixins/proxy-context.d.ts +14 -0
- package/dist/contexts/mixins/proxy-context.js +24 -0
- package/dist/contexts/mixins/proxy-context.js.map +1 -0
- package/dist/contexts/mixins/recording-state-context.d.ts +13 -0
- package/dist/contexts/mixins/recording-state-context.js +30 -0
- package/dist/contexts/mixins/recording-state-context.js.map +1 -0
- package/dist/contexts/mixins/types.d.ts +5 -0
- package/dist/contexts/mixins/types.js +2 -0
- package/dist/contexts/mixins/types.js.map +1 -0
- package/dist/contexts/root-context.d.ts +8 -0
- package/dist/contexts/root-context.js +34 -0
- package/dist/contexts/root-context.js.map +1 -0
- package/dist/controllers/ambient-controller.d.ts +16 -0
- package/dist/controllers/ambient-controller.js +24 -0
- package/dist/controllers/ambient-controller.js.map +1 -0
- package/dist/controllers/dictation-controller.d.ts +8 -31
- package/dist/controllers/dictation-controller.js +17 -283
- package/dist/controllers/dictation-controller.js.map +1 -1
- package/dist/controllers/languages-controller.js +0 -4
- package/dist/controllers/languages-controller.js.map +1 -1
- package/dist/controllers/socket-controller.d.ts +51 -0
- package/dist/controllers/socket-controller.js +281 -0
- package/dist/controllers/socket-controller.js.map +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +3 -0
- package/dist/types.js.map +1 -1
- package/dist/utils/devices.d.ts +12 -8
- package/dist/utils/devices.js +39 -28
- package/dist/utils/devices.js.map +1 -1
- package/dist/utils/events.d.ts +5 -3
- package/dist/utils/events.js +7 -0
- package/dist/utils/events.js.map +1 -1
- package/dist/utils/keybinding.d.ts +2 -1
- package/dist/utils/keybinding.js +12 -6
- package/dist/utils/keybinding.js.map +1 -1
- package/package.json +1 -1
- package/dist/components/recording-button.js +0 -331
- package/dist/components/recording-button.js.map +0 -1
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
13
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
14
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
15
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
16
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
17
|
-
};
|
|
18
|
-
var _DictationRecordingButton_instances, _DictationRecordingButton_mediaController, _DictationRecordingButton_dictationController, _DictationRecordingButton_keybindingController, _DictationRecordingButton_closeConnectionOnInit, _DictationRecordingButton_processing, _DictationRecordingButton_connection, _DictationRecordingButton_handleClick, _DictationRecordingButton_handleWebSocketMessage, _DictationRecordingButton_handleWebSocketError, _DictationRecordingButton_handleWebSocketClose, _DictationRecordingButton_dispatchRecordingStateChanged, _DictationRecordingButton_handleStart, _DictationRecordingButton_handleStop;
|
|
19
|
-
import { consume } from "@lit/context";
|
|
20
|
-
import { html, LitElement, } from "lit";
|
|
21
|
-
import { customElement, property, state } from "lit/decorators.js";
|
|
22
|
-
import { AUDIO_CHUNK_INTERVAL_MS } from "../constants.js";
|
|
23
|
-
import { accessTokenContext, authConfigContext, debugDisplayAudioContext, dictationConfigContext, pushToTalkKeybindingContext, recordingStateContext, regionContext, selectedDeviceContext, socketProxyContext, socketUrlContext, tenantNameContext, toggleToTalkKeybindingContext, } from "../contexts/dictation-context.js";
|
|
24
|
-
import { DictationController, } from "../controllers/dictation-controller.js";
|
|
25
|
-
import { KeybindingController } from "../controllers/keybinding-controller.js";
|
|
26
|
-
import { MediaController } from "../controllers/media-controller.js";
|
|
27
|
-
import ButtonStyles from "../styles/buttons.js";
|
|
28
|
-
import RecordingButtonStyles from "../styles/recording-button.js";
|
|
29
|
-
import { audioLevelChangedEvent, commandEvent, deltaUsageEvent, errorEvent, networkActivityEvent, recordingStateChangedEvent, streamClosedEvent, transcriptEvent, usageEvent, } from "../utils/events.js";
|
|
30
|
-
import "./audio-visualiser.js";
|
|
31
|
-
import "../icons/icons.js";
|
|
32
|
-
let DictationRecordingButton = class DictationRecordingButton extends LitElement {
|
|
33
|
-
constructor() {
|
|
34
|
-
super(...arguments);
|
|
35
|
-
_DictationRecordingButton_instances.add(this);
|
|
36
|
-
this._recordingState = "stopped";
|
|
37
|
-
this.allowButtonFocus = false;
|
|
38
|
-
_DictationRecordingButton_mediaController.set(this, new MediaController(this));
|
|
39
|
-
_DictationRecordingButton_dictationController.set(this, new DictationController(this));
|
|
40
|
-
_DictationRecordingButton_keybindingController.set(this, new KeybindingController(this));
|
|
41
|
-
_DictationRecordingButton_closeConnectionOnInit.set(this, false);
|
|
42
|
-
_DictationRecordingButton_processing.set(this, false);
|
|
43
|
-
_DictationRecordingButton_connection.set(this, "CLOSED");
|
|
44
|
-
_DictationRecordingButton_handleWebSocketMessage.set(this, (message) => {
|
|
45
|
-
switch (message.type) {
|
|
46
|
-
case "CONFIG_DENIED":
|
|
47
|
-
this.dispatchEvent(errorEvent(`Config denied: ${message.reason ?? "Unknown reason"}`));
|
|
48
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
|
|
49
|
-
break;
|
|
50
|
-
case "CONFIG_TIMEOUT":
|
|
51
|
-
this.dispatchEvent(errorEvent("Config timeout"));
|
|
52
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
|
|
53
|
-
break;
|
|
54
|
-
case "transcript":
|
|
55
|
-
this.dispatchEvent(transcriptEvent(message));
|
|
56
|
-
break;
|
|
57
|
-
case "command":
|
|
58
|
-
this.dispatchEvent(commandEvent(message));
|
|
59
|
-
break;
|
|
60
|
-
case "usage":
|
|
61
|
-
this.dispatchEvent(usageEvent(message));
|
|
62
|
-
break;
|
|
63
|
-
case "delta_usage":
|
|
64
|
-
this.dispatchEvent(deltaUsageEvent(message));
|
|
65
|
-
break;
|
|
66
|
-
case "error":
|
|
67
|
-
this.dispatchEvent(errorEvent(message.error));
|
|
68
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
|
|
69
|
-
break;
|
|
70
|
-
case "flushed":
|
|
71
|
-
if (this._recordingState === "stopped" ||
|
|
72
|
-
this._recordingState === "stopping") {
|
|
73
|
-
__classPrivateFieldSet(this, _DictationRecordingButton_processing, false, "f");
|
|
74
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, this._recordingState);
|
|
75
|
-
}
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
_DictationRecordingButton_handleWebSocketError.set(this, (error) => {
|
|
80
|
-
this.dispatchEvent(errorEvent("Socket error: " + error.message));
|
|
81
|
-
__classPrivateFieldSet(this, _DictationRecordingButton_processing, false, "f");
|
|
82
|
-
__classPrivateFieldSet(this, _DictationRecordingButton_connection, "CLOSED", "f");
|
|
83
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
|
|
84
|
-
});
|
|
85
|
-
_DictationRecordingButton_handleWebSocketClose.set(this, (event) => {
|
|
86
|
-
// When we already have new socket opened
|
|
87
|
-
if (__classPrivateFieldGet(this, _DictationRecordingButton_dictationController, "f").isConnectionOpen() ||
|
|
88
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_dictationController, "f").isConnecting()) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
__classPrivateFieldSet(this, _DictationRecordingButton_processing, false, "f");
|
|
92
|
-
__classPrivateFieldSet(this, _DictationRecordingButton_connection, "CLOSED", "f");
|
|
93
|
-
this.dispatchEvent(streamClosedEvent(event));
|
|
94
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, this._recordingState);
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
update(changedProperties) {
|
|
98
|
-
if (changedProperties.has("_recordingState") &&
|
|
99
|
-
this._recordingState === "recording" &&
|
|
100
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_closeConnectionOnInit, "f")) {
|
|
101
|
-
__classPrivateFieldSet(this, _DictationRecordingButton_closeConnectionOnInit, false, "f");
|
|
102
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
|
|
103
|
-
}
|
|
104
|
-
super.update(changedProperties);
|
|
105
|
-
}
|
|
106
|
-
startRecording() {
|
|
107
|
-
if (this._recordingState !== "stopped") {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStart).call(this);
|
|
111
|
-
}
|
|
112
|
-
stopRecording() {
|
|
113
|
-
if (this._recordingState === "stopped" ||
|
|
114
|
-
this._recordingState === "stopping") {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
if (this._recordingState === "initializing") {
|
|
118
|
-
__classPrivateFieldSet(this, _DictationRecordingButton_closeConnectionOnInit, true, "f");
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
|
|
122
|
-
}
|
|
123
|
-
toggleRecording() {
|
|
124
|
-
if (this._recordingState === "stopped") {
|
|
125
|
-
this.startRecording();
|
|
126
|
-
}
|
|
127
|
-
else if (this._recordingState === "recording") {
|
|
128
|
-
this.stopRecording();
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
async openConnection() {
|
|
132
|
-
if (this._recordingState !== "stopped" || __classPrivateFieldGet(this, _DictationRecordingButton_processing, "f")) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
if (__classPrivateFieldGet(this, _DictationRecordingButton_dictationController, "f").isConnectionOpen()) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
try {
|
|
139
|
-
__classPrivateFieldSet(this, _DictationRecordingButton_connection, "CONNECTING", "f");
|
|
140
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, this._recordingState);
|
|
141
|
-
await __classPrivateFieldGet(this, _DictationRecordingButton_dictationController, "f").connect(this._dictationConfig, {
|
|
142
|
-
onClose: __classPrivateFieldGet(this, _DictationRecordingButton_handleWebSocketClose, "f"),
|
|
143
|
-
onError: __classPrivateFieldGet(this, _DictationRecordingButton_handleWebSocketError, "f"),
|
|
144
|
-
onMessage: __classPrivateFieldGet(this, _DictationRecordingButton_handleWebSocketMessage, "f"),
|
|
145
|
-
onNetworkActivity: (direction, data) => {
|
|
146
|
-
this.dispatchEvent(networkActivityEvent(direction, data));
|
|
147
|
-
},
|
|
148
|
-
});
|
|
149
|
-
__classPrivateFieldSet(this, _DictationRecordingButton_connection, "OPEN", "f");
|
|
150
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, this._recordingState);
|
|
151
|
-
}
|
|
152
|
-
catch (error) {
|
|
153
|
-
__classPrivateFieldSet(this, _DictationRecordingButton_connection, "CLOSED", "f");
|
|
154
|
-
this.dispatchEvent(errorEvent(error));
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
async closeConnection() {
|
|
158
|
-
if (this._recordingState !== "stopped" || __classPrivateFieldGet(this, _DictationRecordingButton_processing, "f")) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
if (__classPrivateFieldGet(this, _DictationRecordingButton_dictationController, "f").isConnecting()) {
|
|
162
|
-
await __classPrivateFieldGet(this, _DictationRecordingButton_dictationController, "f").waitForConnection();
|
|
163
|
-
}
|
|
164
|
-
if (!__classPrivateFieldGet(this, _DictationRecordingButton_dictationController, "f").isConnectionOpen()) {
|
|
165
|
-
__classPrivateFieldSet(this, _DictationRecordingButton_connection, "CLOSED", "f");
|
|
166
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, "stopped");
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
try {
|
|
170
|
-
__classPrivateFieldSet(this, _DictationRecordingButton_connection, "CLOSING", "f");
|
|
171
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, "stopped");
|
|
172
|
-
await __classPrivateFieldGet(this, _DictationRecordingButton_dictationController, "f").closeConnection(__classPrivateFieldGet(this, _DictationRecordingButton_handleWebSocketClose, "f"));
|
|
173
|
-
}
|
|
174
|
-
catch (error) {
|
|
175
|
-
this.dispatchEvent(errorEvent(error));
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
render() {
|
|
179
|
-
const isLoading = this._recordingState === "initializing" ||
|
|
180
|
-
this._recordingState === "stopping";
|
|
181
|
-
const isRecording = this._recordingState === "recording";
|
|
182
|
-
return html `
|
|
183
|
-
<button
|
|
184
|
-
@click=${__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleClick)}
|
|
185
|
-
?disabled=${isLoading}
|
|
186
|
-
class=${isRecording ? "red" : "accent"}
|
|
187
|
-
aria-label=${isRecording ? "Stop recording" : "Start recording"}
|
|
188
|
-
aria-pressed=${isRecording}
|
|
189
|
-
>
|
|
190
|
-
${isLoading
|
|
191
|
-
? html `<icon-loading-spinner />`
|
|
192
|
-
: isRecording
|
|
193
|
-
? html `<icon-recording />`
|
|
194
|
-
: html `<icon-mic-on />`}
|
|
195
|
-
<dictation-audio-visualiser
|
|
196
|
-
.level=${__classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").audioLevel}
|
|
197
|
-
?active=${isRecording}
|
|
198
|
-
/>
|
|
199
|
-
</button>
|
|
200
|
-
`;
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
_DictationRecordingButton_mediaController = new WeakMap();
|
|
204
|
-
_DictationRecordingButton_dictationController = new WeakMap();
|
|
205
|
-
_DictationRecordingButton_keybindingController = new WeakMap();
|
|
206
|
-
_DictationRecordingButton_closeConnectionOnInit = new WeakMap();
|
|
207
|
-
_DictationRecordingButton_processing = new WeakMap();
|
|
208
|
-
_DictationRecordingButton_connection = new WeakMap();
|
|
209
|
-
_DictationRecordingButton_handleWebSocketMessage = new WeakMap();
|
|
210
|
-
_DictationRecordingButton_handleWebSocketError = new WeakMap();
|
|
211
|
-
_DictationRecordingButton_handleWebSocketClose = new WeakMap();
|
|
212
|
-
_DictationRecordingButton_instances = new WeakSet();
|
|
213
|
-
_DictationRecordingButton_handleClick = function _DictationRecordingButton_handleClick(event) {
|
|
214
|
-
if (!this.allowButtonFocus) {
|
|
215
|
-
event.preventDefault();
|
|
216
|
-
}
|
|
217
|
-
this.toggleRecording();
|
|
218
|
-
};
|
|
219
|
-
_DictationRecordingButton_dispatchRecordingStateChanged = function _DictationRecordingButton_dispatchRecordingStateChanged(state) {
|
|
220
|
-
this.dispatchEvent(recordingStateChangedEvent(state, {
|
|
221
|
-
connection: __classPrivateFieldGet(this, _DictationRecordingButton_connection, "f"),
|
|
222
|
-
processing: __classPrivateFieldGet(this, _DictationRecordingButton_processing, "f"),
|
|
223
|
-
}));
|
|
224
|
-
};
|
|
225
|
-
_DictationRecordingButton_handleStart = async function _DictationRecordingButton_handleStart() {
|
|
226
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, "initializing");
|
|
227
|
-
try {
|
|
228
|
-
await __classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").initialize(() => {
|
|
229
|
-
if (this._recordingState === "recording") {
|
|
230
|
-
this.dispatchEvent(errorEvent("Recording device access was lost."));
|
|
231
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
|
|
232
|
-
}
|
|
233
|
-
}, __classPrivateFieldGet(this, _DictationRecordingButton_dictationController, "f").mediaRecorderHandler);
|
|
234
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").mediaRecorder?.start(AUDIO_CHUNK_INTERVAL_MS);
|
|
235
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").startAudioLevelMonitoring((level) => {
|
|
236
|
-
this.dispatchEvent(audioLevelChangedEvent(level));
|
|
237
|
-
});
|
|
238
|
-
__classPrivateFieldSet(this, _DictationRecordingButton_processing, true, "f");
|
|
239
|
-
if (__classPrivateFieldGet(this, _DictationRecordingButton_connection, "f") !== "OPEN") {
|
|
240
|
-
__classPrivateFieldSet(this, _DictationRecordingButton_connection, "CONNECTING", "f");
|
|
241
|
-
}
|
|
242
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, "recording");
|
|
243
|
-
const isNewConnection = await __classPrivateFieldGet(this, _DictationRecordingButton_dictationController, "f").connect(this._dictationConfig, {
|
|
244
|
-
onClose: __classPrivateFieldGet(this, _DictationRecordingButton_handleWebSocketClose, "f"),
|
|
245
|
-
onError: __classPrivateFieldGet(this, _DictationRecordingButton_handleWebSocketError, "f"),
|
|
246
|
-
onMessage: __classPrivateFieldGet(this, _DictationRecordingButton_handleWebSocketMessage, "f"),
|
|
247
|
-
onNetworkActivity: (direction, data) => {
|
|
248
|
-
this.dispatchEvent(networkActivityEvent(direction, data));
|
|
249
|
-
},
|
|
250
|
-
});
|
|
251
|
-
if (isNewConnection === "superseded") {
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
__classPrivateFieldSet(this, _DictationRecordingButton_connection, "OPEN", "f");
|
|
255
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, this._recordingState);
|
|
256
|
-
}
|
|
257
|
-
catch (error) {
|
|
258
|
-
this.dispatchEvent(errorEvent(error));
|
|
259
|
-
await __classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
_DictationRecordingButton_handleStop = async function _DictationRecordingButton_handleStop() {
|
|
263
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, "stopping");
|
|
264
|
-
try {
|
|
265
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").stopAudioLevelMonitoring();
|
|
266
|
-
await __classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").stopRecording();
|
|
267
|
-
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_dispatchRecordingStateChanged).call(this, "stopped");
|
|
268
|
-
await __classPrivateFieldGet(this, _DictationRecordingButton_dictationController, "f").pause();
|
|
269
|
-
await __classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").cleanup();
|
|
270
|
-
}
|
|
271
|
-
catch (error) {
|
|
272
|
-
this.dispatchEvent(errorEvent(error));
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
DictationRecordingButton.styles = [RecordingButtonStyles, ButtonStyles];
|
|
276
|
-
__decorate([
|
|
277
|
-
consume({ context: recordingStateContext, subscribe: true }),
|
|
278
|
-
state()
|
|
279
|
-
], DictationRecordingButton.prototype, "_recordingState", void 0);
|
|
280
|
-
__decorate([
|
|
281
|
-
consume({ context: selectedDeviceContext, subscribe: true }),
|
|
282
|
-
state()
|
|
283
|
-
], DictationRecordingButton.prototype, "_selectedDevice", void 0);
|
|
284
|
-
__decorate([
|
|
285
|
-
consume({ context: accessTokenContext, subscribe: true }),
|
|
286
|
-
state()
|
|
287
|
-
], DictationRecordingButton.prototype, "_accessToken", void 0);
|
|
288
|
-
__decorate([
|
|
289
|
-
consume({ context: authConfigContext, subscribe: true }),
|
|
290
|
-
state()
|
|
291
|
-
], DictationRecordingButton.prototype, "_authConfig", void 0);
|
|
292
|
-
__decorate([
|
|
293
|
-
consume({ context: regionContext, subscribe: true }),
|
|
294
|
-
state()
|
|
295
|
-
], DictationRecordingButton.prototype, "_region", void 0);
|
|
296
|
-
__decorate([
|
|
297
|
-
consume({ context: tenantNameContext, subscribe: true }),
|
|
298
|
-
state()
|
|
299
|
-
], DictationRecordingButton.prototype, "_tenantName", void 0);
|
|
300
|
-
__decorate([
|
|
301
|
-
consume({ context: dictationConfigContext, subscribe: true }),
|
|
302
|
-
state()
|
|
303
|
-
], DictationRecordingButton.prototype, "_dictationConfig", void 0);
|
|
304
|
-
__decorate([
|
|
305
|
-
consume({ context: socketUrlContext, subscribe: true }),
|
|
306
|
-
state()
|
|
307
|
-
], DictationRecordingButton.prototype, "_socketUrl", void 0);
|
|
308
|
-
__decorate([
|
|
309
|
-
consume({ context: socketProxyContext, subscribe: true }),
|
|
310
|
-
state()
|
|
311
|
-
], DictationRecordingButton.prototype, "_socketProxy", void 0);
|
|
312
|
-
__decorate([
|
|
313
|
-
consume({ context: debugDisplayAudioContext, subscribe: true }),
|
|
314
|
-
state()
|
|
315
|
-
], DictationRecordingButton.prototype, "_debug_displayAudio", void 0);
|
|
316
|
-
__decorate([
|
|
317
|
-
consume({ context: pushToTalkKeybindingContext, subscribe: true }),
|
|
318
|
-
state()
|
|
319
|
-
], DictationRecordingButton.prototype, "_pushToTalkKeybinding", void 0);
|
|
320
|
-
__decorate([
|
|
321
|
-
consume({ context: toggleToTalkKeybindingContext, subscribe: true }),
|
|
322
|
-
state()
|
|
323
|
-
], DictationRecordingButton.prototype, "_toggleToTalkKeybinding", void 0);
|
|
324
|
-
__decorate([
|
|
325
|
-
property({ type: Boolean })
|
|
326
|
-
], DictationRecordingButton.prototype, "allowButtonFocus", void 0);
|
|
327
|
-
DictationRecordingButton = __decorate([
|
|
328
|
-
customElement("dictation-recording-button")
|
|
329
|
-
], DictationRecordingButton);
|
|
330
|
-
export { DictationRecordingButton };
|
|
331
|
-
//# sourceMappingURL=recording-button.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,EA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O,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,CA6UpC","sourcesContent":["import type { Corti, CortiAuth } 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 deltaUsageEvent,\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?: CortiAuth.AuthTokenDerivable;\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_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 \"delta_usage\":\n this.dispatchEvent(deltaUsageEvent(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 (\n this.#dictationController.isConnectionOpen() ||\n this.#dictationController.isConnecting()\n ) {\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 }, this.#dictationController.mediaRecorderHandler);\n this.#mediaController.mediaRecorder?.start(AUDIO_CHUNK_INTERVAL_MS);\n this.#mediaController.startAudioLevelMonitoring((level) => {\n this.dispatchEvent(audioLevelChangedEvent(level));\n });\n\n this.#processing = true;\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 === \"superseded\") {\n return;\n }\n\n this.#connection = \"OPEN\";\n\n this.#dispatchRecordingStateChanged(this._recordingState);\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\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(this._recordingState);\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(this._recordingState);\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.isConnecting()) {\n await this.#dictationController.waitForConnection();\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"]}
|