7
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Elixirで作る「DDJ-FLX4のジョグ対応ブロックくずし」 その7 対策をする、そしてプロジェクトを3分割のつづきddj_server 編

Last updated at Posted at 2024-12-20

ddj_clientのつづきです

基本的には下記のソースのddj_serverを見てください

実施していることは

  • mix phx.new ddj_server --no-ecto --no-html でプロジェクト生成
  • mix phx.gen.socket Ddj でソケット生成
  • mix phx.gen.channel Ddj でchannel生成
  • channel ddj:lobby 追加
  • handle_in "new_msg" 追加

プロジェクト生成

$ mix phx.new ddj_server --no-ecto --no-html
$ cd ddj_server

結果

ソケット生成

$ mix phx.gen.socket Ddj

結果

channel生成

$ mix phx.gen.channel Ddj

結果

channel ddj:lobby 追加

ddj_server/lib/ddj_server_web/channels/ddj_socket.ex
# 省略
  # See the [`Channels guide`](https://hexdocs.pm/phoenix/channels.html)
  # for further details.

+  channel "ddj:lobby", DdjServerWeb.DdjChannel

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

handle_in "new_msg" 追加

ddj_server/lib/ddj_server_web/channels/ddj_channel.ex
# 省略
+  def handle_in("new_msg", %{"body" => body}, socket) do
+    broadcast!(socket, "new_msg", %{body: body})
+    {:noreply, socket}
+  end
  # It is also common to receive messages from the client and
  # broadcast to everyone in the current topic (ddj:lobby).
# 省略

これで、ddj_serverは完成

つづく

7
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?