tube v0.1.1 Tube.Websocket

Represents a WebSocket connection

This GenServer will handle the whole lifecycle of one WebSocket connection.

Setup

{:ok, pid} = GenServer.start_link(Tube.Websocket,
  uri: "ws://localhost:4000/ws",
  opts: [parent: self])
:ok = Tube.Websocket.connect(pid)

This will open a WebSocket connection to ws://localhost:4000/ws.

Incoming frames will be sent via message passing to the pid given in opts.parent.

Messages to parent

  • {:websocket, :frame, frame}
  • {:websocket, :open}
  • {:websocket, :closed}

Summary

Functions

Closes the connection by sending a close frame to the server

Connects to the given uri

Sends a frame to the server

Changes the uri that will be used the next time connect/1 is called

Functions

close(pid)

Specs

close(pid :: pid) :: :ok

Closes the connection by sending a close frame to the server.

connect(pid)

Specs

connect(pid) :: :ok

Connects to the given uri

send_frame(frame, socket)

Specs

send_frame(frame :: map, socket :: map) :: :ok

Sends a frame to the server

set_uri(pid, uri)

Specs

set_uri(pid :: pid, uri :: string) :: :ok

Changes the uri that will be used the next time connect/1 is called.