Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Websock Smartcell Demo

content/demo.livemd

Websock Smartcell Demo

Mix.install(
  [
    case System.user_home() do
      "C:\\Users\\chgeuer" -> {:kino_websocket, path: "c:/github/chgeuer/kino_websocket"}
      "/home/chgeuer" -> {:kino_websocket, path: "/mnt/c/github/chgeuer/kino_websocket"}
      _ -> {:kino_websocket, github: "chgeuer/kino_websocket"}
    end
  ], 
  force: false
)

Section

A few endpoints to connect to:

defmodule Kino.WebSocket.SmartCell.Client do
  use WebSockex

  def start_link(endpoint, parent) do
    WebSockex.start_link(endpoint, __MODULE__, parent, extra_headers: [])
  end

  def handle_frame({:text, message}, parent) do
    send(parent, {:websocket_message, message})
    {:ok, parent}
  end

  def handle_disconnect(%{reason: {:local, _reason}}, state) do
    {:ok, state}
  end

  def handle_cast(:close, state) do
    {:close, state}
  end
end

Kino.WebSocket.SmartCell.Client.start_link(
  "wss://echo.websocket.org/?encoding=text",
  self()
)