general solution to voice control
Some checks failed
CI/CD Pipeline / build (push) Failing after 4s

This commit is contained in:
2026-03-25 09:22:48 -06:00
parent 86ff82a015
commit d857e91241
14 changed files with 309 additions and 31 deletions

View File

@@ -0,0 +1,35 @@
defmodule ElixirAi.AiControllable.Hook do
@moduledoc """
LiveView on_mount hook that registers a page LiveView in the
`:ai_page_tools` pg group so VoiceLive can discover it.
The group key is `{:page, voice_session_id}` where `voice_session_id`
comes from the Plug session, tying the page LiveView to the same browser
tab as VoiceLive.
Only joins when the LiveView module implements `ai_tools/0`
(i.e. uses `ElixirAi.AiControllable`).
"""
import Phoenix.LiveView
import Phoenix.Component, only: [assign: 3]
def on_mount(:default, _params, session, socket) do
voice_session_id = session["voice_session_id"]
module = socket.view
if voice_session_id && function_exported?(module, :ai_tools, 0) do
if connected?(socket) do
try do
:pg.join(ElixirAi.PageToolsPG, {:page, voice_session_id}, self())
catch
:exit, _ -> :ok
end
end
{:cont, assign(socket, :voice_session_id, voice_session_id)}
else
{:cont, socket}
end
end
end