-
Notifications
You must be signed in to change notification settings - Fork 917
/
socket.ex
90 lines (74 loc) · 2.31 KB
/
socket.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
defmodule Phoenix.LiveView.Socket.AssignsNotInSocket do
@moduledoc false
defimpl Inspect do
def inspect(_, _) do
"#Phoenix.LiveView.Socket.AssignsNotInSocket<>"
end
end
defstruct [:__assigns__]
@type t :: %__MODULE__{}
end
defmodule Phoenix.LiveView.Socket do
@moduledoc """
The LiveView socket for Phoenix Endpoints.
This is typically mounted directly in your endpoint.
socket "/live", Phoenix.LiveView.Socket
"""
use Phoenix.Socket
require Logger
if Version.match?(System.version(), ">= 1.8.0") do
@derive {Inspect,
only: [
:id,
:endpoint,
:router,
:view,
:parent_pid,
:root_pid,
:assigns,
:changed,
:transport_pid
]}
end
defstruct id: nil,
endpoint: nil,
view: nil,
parent_pid: nil,
root_pid: nil,
router: nil,
assigns: %{},
changed: %{},
private: %{changed: %{}},
fingerprints: Phoenix.LiveView.Diff.new_fingerprints(),
redirected: nil,
host_uri: nil,
transport_pid: nil
@typedoc "Struct returned when `assigns` is not in the socket."
@opaque assigns_not_in_socket :: Phoenix.LiveView.Socket.AssignsNotInSocket.t()
@typedoc "The data in a LiveView as stored in the socket."
@type assigns :: map | assigns_not_in_socket()
@type fingerprints :: {nil, map} | {binary, map}
@type t :: %__MODULE__{
id: binary(),
endpoint: module(),
view: module(),
parent_pid: nil | pid(),
root_pid: pid(),
router: module(),
assigns: assigns,
changed: map(),
private: map(),
fingerprints: fingerprints,
redirected: nil | tuple(),
host_uri: URI.t() | :not_mounted_at_router,
transport_pid: pid() | nil
}
channel "lvu:*", Phoenix.LiveView.UploadChannel
channel "lv:*", Phoenix.LiveView.Channel
@impl Phoenix.Socket
def connect(_params, %Phoenix.Socket{} = socket, connect_info) do
{:ok, put_in(socket.private[:connect_info], connect_info)}
end
@impl Phoenix.Socket
def id(socket), do: socket.private.connect_info[:session]["live_socket_id"]
end