defmodule LivebookWeb.Output.AudioInputComponent do use LivebookWeb, :live_component @impl true def mount(socket) do {:ok, assign(socket, endianness: System.endianness(), initialized: false)} end @impl true def update(assigns, socket) do {value, assigns} = Map.pop!(assigns, :value) socket = assign(socket, assigns) socket = if socket.assigns.initialized do socket else socket = if value do push_event(socket, "audio_input_init:#{socket.assigns.id}", %{ data: Base.encode64(value.data), num_channels: value.num_channels, sampling_rate: value.sampling_rate }) else socket end assign(socket, initialized: true) end {:ok, socket} end @impl true def render(assigns) do ~H"""
""" end @impl true def handle_event("change", params, socket) do value = %{ data: Base.decode64!(params["data"]), num_channels: params["num_channels"], sampling_rate: params["sampling_rate"], format: socket.assigns.format } send_update(LivebookWeb.Output.InputComponent, id: socket.assigns.input_component_id, event: :change, value: value ) {:noreply, socket} end end