I’m wondering if there is a (reasonable) way to conditionally prevent the live view lifecycle from connecting via socket?
For example, I have a small game app. If the game is over, there is no more interactivity, and so a new visit to this page has no need for the live view to do anything after the initial pass through mount/3 and handle_params/3.
Everything is controlled from the client side: You can conditionally don’t connect from the client side, or tell the client side to disconnect by pushing a event that define.
Indeed. You can control from the server whether the client will connect though, by including the LV js script or not, something like:
current_user = current_user(assigns)
js =
if not is_nil(current_user) and current_user.game_state.status !=:over do
static_path("/assets/live.js")
else
static_path("/assets/basic.js")
end
"""
<script defer phx-track-static crossorigin='anonymous' src='#{js}'></script>
[...]