Skip to content

Commit 695b5c6

Browse files
authored
init back with phoenix (#2)
1 parent 3d2e8ee commit 695b5c6

File tree

7 files changed

+26
-4
lines changed

7 files changed

+26
-4
lines changed

server/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ npm-debug.log
3636
/assets/node_modules/
3737

3838
.elixir_ls
39+
.idea/
3940

server/lib/server/application.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ defmodule Server.Application do
1212
Server.Repo,
1313
{DNSCluster, query: Application.get_env(:server, :dns_cluster_query) || :ignore},
1414
{Phoenix.PubSub, name: Server.PubSub},
15+
{Server.Room.RoomDatabase, name: Server.Room.RoomDatabase},
1516
# Start the Finch HTTP client for sending emails
1617
{Finch, name: Server.Finch},
1718
# Start a worker by calling: Server.Worker.start_link(arg)

server/lib/server/room/Room.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
defmodule Server.Room do
2+
def create(_) do
3+
Ecto.UUID.generate()
4+
end
5+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
defmodule Server.Room.RoomDatabase do
2+
use Agent
3+
4+
def start_link(_) do
5+
Agent.start_link(fn -> [] end, name: __MODULE__)
6+
end
7+
8+
end

server/lib/server_web/channels/room_channel.ex renamed to server/lib/server_web/channels/lobby_channel.ex

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
defmodule ServerWeb.RoomChannel do
1+
defmodule ServerWeb.LobbyChannel do
22
use ServerWeb, :channel
33

44
@impl true
5-
def join("room:lobby", payload, socket) do
5+
def join("lobby", payload, socket) do
66
if authorized?(payload) do
77
{:ok, socket}
88
else
@@ -25,6 +25,13 @@ defmodule ServerWeb.RoomChannel do
2525
{:noreply, socket}
2626
end
2727

28+
@impl true
29+
def handle_in("create", %{"name" => name}, socket) do
30+
# Faire des
31+
uuid = Server.Room.create(name)
32+
{:reply, {:ok, uuid}, socket}
33+
end
34+
2835
# Add authorization logic here as required.
2936
defp authorized?(_payload) do
3037
true

server/lib/server_web/channels/user_socket.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ defmodule ServerWeb.UserSocket do
88

99
## Channels
1010

11-
channel "room:*", ServerWeb.RoomChannel
11+
channel "lobby", ServerWeb.LobbyChannel
1212

1313
# Socket params are passed from the client and can
1414
# be used to verify and authenticate a user. After

server/mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ defmodule Server.MixProject do
1919
def application do
2020
[
2121
mod: {Server.Application, []},
22-
extra_applications: [:logger, :runtime_tools]
22+
extra_applications: [:logger, :runtime_tools, :observer]
2323
]
2424
end
2525

0 commit comments

Comments
 (0)