LiveReactNative.MobileChannel (live_react_native v0.0.3)
View SourcePhoenix Channel that bridges React Native clients to Phoenix LiveView business logic.
Each joined channel resolves the requested LiveView from the router, runs its
on_mount hooks, and drives its callbacks (mount/3, handle_event/3, …) on a
persisted %Phoenix.LiveView.Socket{} — the "channel-as-process" model. Assigns and
side-effect commands stream back to the client as JSON; no HTML is rendered.
Topics
React Native client (MobileClientProvider + useChannel)
↓ Phoenix Channel, topic "mobile:<path>"
LiveReactNative.MobileChannel (holds the persisted LiveView socket)
↓ direct callback invocation
your LiveView (mount/handle_event/handle_info) — unchangedClients join topics of the form mobile:<path> (e.g. mobile:/mobile/counter),
which map to the LiveView routed at <path>.
Authentication
Auth is handled at the socket level by a LiveReactNative.MobileSocket behaviour
implementation (resolve_user/2 turns the connect params — e.g. a token — into a user;
build_session/3 builds the session map). The resolved session is then gated by the
router's on_mount hooks when this channel joins, so the same hooks protect web and
mobile. See the docs/ architecture and auth guides.
Summary
Functions
Combines mount params, path params, and query params with proper precedence. Path params override mount params (Phoenix Router behavior).
Execute on_mount hooks extracted from live_session - this is CRITICAL for security!
Extracts path parameters from route patterns, exactly like Phoenix Router.
Extracts path parameters from Phoenix Router route_info and actual path.
Extract a navigation intent from a LiveView socket after an event, or nil.
Callback implementation for Phoenix.Channel.handle_in/3.
Callback implementation for Phoenix.Channel.handle_info/2.
Alias for handle_params_navigation/3 - for test compatibility.
Handles navigation with handle_params/3 (for parameter-only changes). Used when navigating within the same LiveView with new parameters.
Callback implementation for Phoenix.Channel.join/3.
Alias for extract_path_parameters/2 - for test compatibility.
Mounts a LiveView for the URI the client last had (reconnect restore).
Alias for mount_with_params/5 but with different signature for test compatibility.
Mounts LiveView with handle_params/3 support (like web LiveView does).
Parses URL parameters from a mobile path, splitting path and query string.
Build the channel message {event, payload} for a post-event navigation, or nil.
Internal testing seam — not part of the stable public API.
Callback implementation for Phoenix.Channel.terminate/2.
Extracts the client-sent current URI from join params (for reconnect restore).
Functions
Combines mount params, path params, and query params with proper precedence. Path params override mount params (Phoenix Router behavior).
Execute on_mount hooks extracted from live_session - this is CRITICAL for security!
This ensures mobile clients go through the SAME authentication pipeline as web clients, respecting live_session boundaries and on_mount hook requirements.
Extracts path parameters from route patterns, exactly like Phoenix Router.
Examples: extract_path_parameters("/mobile/users/123", "/mobile/users/:id") # => %{"id" => "123"}
extract_path_parameters("/mobile/api/v2/pages/100", "/mobile/api/v:version/pages/:id") # => %{"version" => "2", "id" => "100"}
Extracts path parameters from Phoenix Router route_info and actual path.
@spec extract_redirect(Phoenix.LiveView.Socket.t()) :: {:navigate, String.t()} | {:redirect, String.t()} | nil
Extract a navigation intent from a LiveView socket after an event, or nil.
Only INTERNAL navigation (push_navigate/redirect with a :to path) is
surfaced to the mobile client. External redirects (redirect(external: ...))
are intentionally out of scope — a native app shell has no in-app analog — and
return nil. Internal testing seam; not part of the stable public API.
Callback implementation for Phoenix.Channel.handle_in/3.
Callback implementation for Phoenix.Channel.handle_info/2.
Callback implementation for Phoenix.Channel.join/3.
Alias for extract_path_parameters/2 - for test compatibility.
Mounts a LiveView for the URI the client last had (reconnect restore).
Parses the "uri" join param's query string, then runs mount/3 followed by
handle_params/3 (when implemented) so a reconnect lands on the same
filter/page/params the user was on — not the initial mount. Returns the
resulting assigns map.
Alias for mount_with_params/5 but with different signature for test compatibility.
Mounts LiveView with handle_params/3 support (like web LiveView does).
Calls both mount/3 AND handle_params/3 in sequence:
- mount/3 with mount params (device_id, user_id, etc.)
- handle_params/3 with URL params (query + path parameters)
Parses URL parameters from a mobile path, splitting path and query string.
Examples: parse_url_parameters("/mobile/posts?category=tech&page=2") # => {"/mobile/posts", %{"category" => "tech", "page" => "2"}}
parse_url_parameters("/mobile/counter") # => {"/mobile/counter", %{}}
@spec redirect_message(Phoenix.LiveView.Socket.t()) :: {String.t(), map()} | nil
Build the channel message {event, payload} for a post-event navigation, or nil.
Internal testing seam — not part of the stable public API.
Callback implementation for Phoenix.Channel.terminate/2.
Extracts the client-sent current URI from join params (for reconnect restore).
Returns nil when the client did not send one.