Send a frame just after the connected
Closed this issue · 1 comments
alvises commented
defmodule GdaxStream.Client do
use WebSockex
def start_link(url, state) do
WebSockex.start_link(url, __MODULE__, state)
end
def handle_connect(conn, state) do
IO.puts("connected!")
{:ok, state}
end
end
What can I do if I want to send a subscription frame just after connected?
def subscription_frame() do
data =
Poison.encode!(%{
type: "subscribe",
product_ids: ["BTC-USD"],
channels: ["ticker"]
})
{:text, data}
end
def handle_connect(conn, state) do
WebSockex.send_frame(self(), subscription_frame())
{:ok, state}
end
doing so doesn't work, {:error, %WebSockex.CallingSelfError{function: :send_frame}}
alvises commented
Actually, I've just seen, in one of your examples, solution that works in my case (https://github.com/Azolo/websockex/blob/master/examples/chrome_debbuger.exs)
def start_link(products \\ [], options \\ []) do
{:ok, pid} = WebSockex.start_link(@url, __MODULE__, %{}, options) do
subscribe(pid, products)
{:ok, pid}
end