GOOS Playground
Section
alias Romeo.Stanza
alias Romeo.Connection
alias Romeo.Roster
defmodule Listener do
def listen do
receive do
{:stanza,
%{
to: %{user: "auction-item-54321"},
from: %{user: "sniper"},
type: "chat",
body: body
}} ->
IO.puts("Received #{inspect(body)} from sniper")
_msg ->
# IO.inspect(msg, label: "Received message")
listen()
after
:timer.seconds(5) ->
nil
end
end
end
{:ok, auction_pid} =
Connection.start_link(
jid: "auction-item-54321@localhost",
password: "auction",
ssl_opts: [verify: :verify_none]
)
:ok = Connection.send(auction_pid, Stanza.presence())
{:ok, sniper_pid} =
Connection.start_link(
jid: "sniper@localhost",
password: "sniper",
ssl_opts: [verify: :verify_none]
)
:ok = Connection.send(sniper_pid, Stanza.presence())
:ok = Connection.send(sniper_pid, Stanza.message("auction-item-54321@localhost", "chat", "Join"))
Listener.listen()
Connection.close(auction_pid)
Connection.close(sniper_pid)