@myned-ai/avatar-chat-widget 0.12.0 → 0.13.0
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.
|
@@ -1815,15 +1815,21 @@ const _AudioContextManagerImpl = class _AudioContextManagerImpl {
|
|
|
1815
1815
|
* Call this synchronously from any user-gesture handler (pointerdown, touchend,
|
|
1816
1816
|
* click, keydown) to guarantee iOS audio unlock.
|
|
1817
1817
|
*/
|
|
1818
|
-
ensureAudioReady() {
|
|
1818
|
+
ensureAudioReady(source) {
|
|
1819
|
+
const tag = source ? `[${source}]` : "";
|
|
1819
1820
|
if (!this._context) {
|
|
1820
1821
|
this.createContext();
|
|
1821
1822
|
}
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1823
|
+
const ctx = this._context;
|
|
1824
|
+
if (!ctx) return;
|
|
1825
|
+
if (ctx.state === "running") return;
|
|
1826
|
+
log$c.debug(`${tag} Attempting AudioContext unlock, current state=${ctx.state}`);
|
|
1827
|
+
ctx.resume().then(() => {
|
|
1828
|
+
log$c.info(`${tag} AudioContext unlocked via ensureAudioReady`);
|
|
1829
|
+
this.removeResumeListeners();
|
|
1830
|
+
}).catch((error2) => {
|
|
1831
|
+
log$c.warn(`${tag} ensureAudioReady resume failed (will retry on next gesture):`, error2);
|
|
1832
|
+
});
|
|
1827
1833
|
}
|
|
1828
1834
|
/**
|
|
1829
1835
|
* Internal: create the AudioContext and wire up fallback document listeners.
|
|
@@ -1839,7 +1845,9 @@ const _AudioContextManagerImpl = class _AudioContextManagerImpl {
|
|
|
1839
1845
|
latencyHint: "interactive"
|
|
1840
1846
|
});
|
|
1841
1847
|
log$c.info(`AudioContext created: sampleRate=${this._context.sampleRate}, state=${this._context.state}`);
|
|
1842
|
-
this.
|
|
1848
|
+
if (this._context.state !== "running") {
|
|
1849
|
+
this.setupResumeListener();
|
|
1850
|
+
}
|
|
1843
1851
|
this._context.onstatechange = () => {
|
|
1844
1852
|
log$c.debug(`AudioContext state changed: ${this._context?.state}`);
|
|
1845
1853
|
if (this._context?.state === "running") {
|
|
@@ -5912,8 +5920,18 @@ class AvatarChatElement extends HTMLElement {
|
|
|
5912
5920
|
* Setup UI event listeners
|
|
5913
5921
|
*/
|
|
5914
5922
|
setupUIEvents() {
|
|
5923
|
+
const unlockAudio = (e) => {
|
|
5924
|
+
AudioContextManager.ensureAudioReady(`widget:${e.type}`);
|
|
5925
|
+
};
|
|
5926
|
+
this.shadow.addEventListener("pointerdown", unlockAudio, { capture: true, passive: true });
|
|
5927
|
+
this.shadow.addEventListener("touchend", unlockAudio, { capture: true, passive: true });
|
|
5928
|
+
this.shadow.addEventListener("click", unlockAudio, { capture: true, passive: true });
|
|
5929
|
+
this.shadow.addEventListener("focusin", unlockAudio, { capture: true });
|
|
5915
5930
|
const minimizeBtn = this.shadow.getElementById("minimizeBtn");
|
|
5916
|
-
minimizeBtn?.addEventListener("click", () =>
|
|
5931
|
+
minimizeBtn?.addEventListener("click", () => {
|
|
5932
|
+
AudioContextManager.ensureAudioReady();
|
|
5933
|
+
this.collapse();
|
|
5934
|
+
});
|
|
5917
5935
|
const chatInput = this.shadow.getElementById("chatInput");
|
|
5918
5936
|
const inputControls = this.shadow.querySelector(".chat-input-controls");
|
|
5919
5937
|
if (chatInput && inputControls) {
|
|
@@ -6110,6 +6128,7 @@ class AvatarChatElement extends HTMLElement {
|
|
|
6110
6128
|
return;
|
|
6111
6129
|
}
|
|
6112
6130
|
expandBtn.addEventListener("click", () => {
|
|
6131
|
+
AudioContextManager.ensureAudioReady();
|
|
6113
6132
|
const isExpanded = widgetRoot.classList.toggle("expanded");
|
|
6114
6133
|
expandBtn.setAttribute("aria-label", isExpanded ? "Collapse chat" : "Expand chat");
|
|
6115
6134
|
expandBtn.setAttribute("title", isExpanded ? "Collapse" : "Expand");
|
|
@@ -6127,6 +6146,7 @@ class AvatarChatElement extends HTMLElement {
|
|
|
6127
6146
|
return;
|
|
6128
6147
|
}
|
|
6129
6148
|
viewModeBtn.addEventListener("click", (e) => {
|
|
6149
|
+
AudioContextManager.ensureAudioReady();
|
|
6130
6150
|
e.stopPropagation();
|
|
6131
6151
|
if (this.drawerController) {
|
|
6132
6152
|
const currentState = this.drawerController.getState();
|
|
@@ -6178,7 +6198,7 @@ class AvatarChatElement extends HTMLElement {
|
|
|
6178
6198
|
*/
|
|
6179
6199
|
async expand() {
|
|
6180
6200
|
if (!this._isCollapsed) return;
|
|
6181
|
-
AudioContextManager.ensureAudioReady();
|
|
6201
|
+
AudioContextManager.ensureAudioReady("widget:expand");
|
|
6182
6202
|
this._isCollapsed = false;
|
|
6183
6203
|
this.classList.remove("collapsed");
|
|
6184
6204
|
this.style.width = `${this.config.width}px`;
|