Skip to content

Commit

Permalink
index
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT committed Sep 5, 2024
1 parent 641475c commit b7f500c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/login.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ defmodule Sample.Login do
require Logger

def event(:init) do
login_button = NITRO.button(id: :loginButton, body: "HELO", postback: :login2, source: [:user, :room])
:io.format 'LOGIN INIT'
login_button = NITRO.button(id: :loginButton, body: "HELO", postback: :login, source: [:user, :room])
:nitro.update(:loginButton, login_button)
end

def event(:login2) do
def event(:login) do
:io.format 'LOGIN PRESSED'
user = :nitro.to_list(:nitro.q(:user))
room = :nitro.to_binary(:nitro.q(:room))
:n2o.user(user)
Expand Down
7 changes: 6 additions & 1 deletion lib/ws.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ defmodule Sample.WS do
def init(args), do: {:ok, N2O.cx(module: Keyword.get(args, :module)) }
def handle_in({"N2O," <> _ = message, _}, state), do: response(:n2o_proto.stream({:text,message},[],state))
def handle_in({"PING", _}, state), do: {:reply, :ok, {:text, "PONG"}, state}
def handle_in({message, _}, state), do: response(:n2o_proto.stream(message,[],state))
def handle_in({message, _}, state) do
:io.format 'Message: ~p~n', [:erlang.binary_to_term(message)]
x = :n2o_proto.stream(message,[],state)
:io.format 'X: ~p~n', [x]
response(x)
end

def response({:reply,{:binary,rep},_,s}), do: {:reply,:ok,{:binary,rep},s}
def response({:reply,{:text,rep},_,s}), do: {:reply,:ok,{:text,rep},s}
Expand Down

0 comments on commit b7f500c

Please sign in to comment.