jeregrine / readme.md secret
Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View readme.md
  1. browse to localhost:5000
  2. open javascript console
  3. ws = new WebSocket("ws://localhost:5000/my_websocket")
  4. ws.onmessage = function(resp){console.log(resp.data)}
  5. ws.send("Hey")
View readme.md
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
defmodule Totem.Router do
use Phoenix.Router, port: 5000
 
resources "/user", UserController
websocket "/my_websocket", Totem.SocketController
end
 
defmodule Totem.SocketController do
use Phoenix.Controller.Websocket
 
def start(_transport, socket, _state) do
:erlang.start_timer(1000, self(), "Hello!")
IO.puts "INIT"
:ok
end
 
def stream(_data, socket, _state) do
IO.puts "RECIEVED DATA"
reply socket, {:text, "Thats what she said!"}
end
 
def info({:timeout, _ref, msg}, socket, _state) do
IO.puts "TIMEOUT SENDING DATA"
reply socket, {:text, msg}
:erlang.start_timer(1000, self(), "How' you doin'?")
end
 
def closed(reason, _req, _state) do
IO.inspect reason
:ok
end
end

I am so looking forward for this to be merged to master!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.