fbonetti/elm-phoenix-socket

It's not possible to subscribe for "phx_reply" event

Closed this issue · 1 comments

{-| Event to connect channel -}
eventConnect : String
eventConnect = "phx_reply"

{-| Event to load all avaliable chat rooms for the user -}
eventGetChats : String
eventGetChats = "get_chats"

{-| Event to send new message by user -}
eventNewMsg : String
eventNewMsg = "new_msg"

{-| Initialise listener for all socket messages -}
initSocketListeners : String -> Phoenix.Socket.Socket MsgSign
initSocketListeners token =
    Phoenix.Socket.init (socketServer ++ "?guardian_token=" ++ token)
        |> Phoenix.Socket.withDebug
        |> Phoenix.Socket.on eventConnect defaultChannel ConnectedData
        |> Phoenix.Socket.on eventGetChats defaultChannel ChatRoomsData
        |> Phoenix.Socket.on eventNewMsg defaultChannel SendMessageData

All events work but eventConnect

Some log data:

MSG: Connect
Phoenix message: { event = "phx_reply", topic = "rooms:lobby", payload = { status = "ok", response = "{\"id\":\"5762622d52f07802de7fc8c2\",\"displayName\":\"voronchuk@gmail.com\"}" }, ref = Just 0 }
MSG: PhoenixMsg (ChannelJoined "rooms:lobby")
MSG: ChatRooms
Phoenix message: { event = "get_chats", topic = "rooms:lobby", payload = { status = "ok", response = "[{\"name\":\"Test chat\",\"id\":\"576528e252f0781ddc6c22ae\"}]" }, ref = Nothing }
MSG: PhoenixMsg NoOp
MSG: ChatRoomsData { status = "ok", response = "[{\"name\":\"Test chat\",\"id\":\"576528e252f0781ddc6c22ae\"}]" }

You can't subscribe to "phx_reply" - that's an internal event that's handled by the library. If you want something to happen after you've joined a channel, use Phoenix.Channel.onJoin:

http://package.elm-lang.org/packages/fbonetti/elm-phoenix-socket/1.0.1/Phoenix-Channel#onJoin

Edit: Here's an example:

https://github.com/fbonetti/elm-phoenix-socket/blob/master/examples/Chat.elm#L146-L158