timgremore
commited on
Commit
•
643358c
1
Parent(s):
34b4725
wip: feat: Subscribe to pubsub in HomeLive
Browse files
lib/medical_transcription_web/live/home_live/index.ex
CHANGED
@@ -6,6 +6,8 @@ defmodule MedicalTranscriptionWeb.HomeLive.Index do
|
|
6 |
|
7 |
@impl Phoenix.LiveView
|
8 |
def mount(_params, session, socket) do
|
|
|
|
|
9 |
# We're storing atoms in `:status` as LiveView's AsyncResult doesn't support modeling a "pending" state, but only
|
10 |
# loading / ok / failed.
|
11 |
initial_state = %{
|
@@ -83,16 +85,9 @@ defmodule MedicalTranscriptionWeb.HomeLive.Index do
|
|
83 |
{:ok, dest}
|
84 |
end)
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
{:ok, _transcription} =
|
90 |
-
Transcriptions.create_transcription(%{
|
91 |
-
user_id: socket.assigns.current_user.id,
|
92 |
-
filename: filename
|
93 |
-
})
|
94 |
-
|
95 |
-
Task.async(fn -> transcribe_and_tag_audio(live_view_pid, uploaded_file) end)
|
96 |
|
97 |
socket =
|
98 |
socket
|
@@ -149,7 +144,7 @@ defmodule MedicalTranscriptionWeb.HomeLive.Index do
|
|
149 |
end
|
150 |
|
151 |
@impl true
|
152 |
-
def handle_info({:
|
153 |
# The processing sends a message as each chunk of text is coded. See here for some background and potential
|
154 |
# inspiration for this: https://elixirforum.com/t/liveview-asynchronous-task-patterns/44695
|
155 |
|
@@ -213,9 +208,8 @@ defmodule MedicalTranscriptionWeb.HomeLive.Index do
|
|
213 |
{:noreply, assign(socket, :status, :success)}
|
214 |
end
|
215 |
|
216 |
-
defp transcribe_and_tag_audio(
|
217 |
MedicalTranscription.Transcription.stream_transcription_and_search(
|
218 |
-
live_view_pid,
|
219 |
audio_file_path
|
220 |
)
|
221 |
end
|
|
|
6 |
|
7 |
@impl Phoenix.LiveView
|
8 |
def mount(_params, session, socket) do
|
9 |
+
if connected?(socket), do: Phoenix.PubSub.subscribe(MedicalTranscription.PubSub, "transcriptions")
|
10 |
+
|
11 |
# We're storing atoms in `:status` as LiveView's AsyncResult doesn't support modeling a "pending" state, but only
|
12 |
# loading / ok / failed.
|
13 |
initial_state = %{
|
|
|
85 |
{:ok, dest}
|
86 |
end)
|
87 |
|
88 |
+
uploaded_files
|
89 |
+
|> Enum.at(0)
|
90 |
+
|> transcribe_and_tag_audio()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
socket =
|
93 |
socket
|
|
|
144 |
end
|
145 |
|
146 |
@impl true
|
147 |
+
def handle_info({:chunk, chunk_result}, socket) do
|
148 |
# The processing sends a message as each chunk of text is coded. See here for some background and potential
|
149 |
# inspiration for this: https://elixirforum.com/t/liveview-asynchronous-task-patterns/44695
|
150 |
|
|
|
208 |
{:noreply, assign(socket, :status, :success)}
|
209 |
end
|
210 |
|
211 |
+
defp transcribe_and_tag_audio(audio_file_path) do
|
212 |
MedicalTranscription.Transcription.stream_transcription_and_search(
|
|
|
213 |
audio_file_path
|
214 |
)
|
215 |
end
|