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:
-
wss://echo.websocket.org/?encoding=text
(the official test endpoint) -
wss://ws.postman-echo.com/raw
(from Postman) -
wss://kobrakai.de/ws/connection_timer/blogpost
(from the blog Bare WebSockets (with Elixir and Phoenix))
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()
)