Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send connection types to NervesHub #118

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/nerves_hub_link/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ defmodule NervesHubLink.Client do
"""
@callback handle_error(any()) :: :ok

@doc """
Callback to perform an action when the device has connected to NervesHub.
"""
@callback connected() :: :ok

@doc """
Callback to identify the device from NervesHub.
"""
Expand Down Expand Up @@ -139,6 +144,13 @@ defmodule NervesHubLink.Client do
end
end

@doc """
This function is called internally by NervesHubLink to notify clients of connecting to NervesHub.
"""
def connected() do
apply_wrap(mod(), :connected, [])
end

@doc """
This function is called internally by NervesHubLink to identify a device.
"""
Expand Down
3 changes: 3 additions & 0 deletions lib/nerves_hub_link/client/default.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ defmodule NervesHubLink.Client.Default do
Logger.warn("[NervesHubLink] error: #{inspect(error)}")
end

@impl NervesHubLink.Client
def connected(), do: :ok

@impl NervesHubLink.Client
def identify() do
Logger.info("[NervesHubLink] identifying")
Expand Down
10 changes: 10 additions & 0 deletions lib/nerves_hub_link/socket.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ defmodule NervesHubLink.Socket do
GenServer.cast(__MODULE__, {:send_update_status, status})
end

def send_connection_types(types) do
GenServer.cast(__MODULE__, {:send_connection_types, types})
end

def check_connection(type) do
GenServer.call(__MODULE__, {:check_connection, type})
end
Expand Down Expand Up @@ -88,6 +92,7 @@ defmodule NervesHubLink.Socket do
def handle_join(@device_topic, reply, socket) do
Logger.debug("[#{inspect(__MODULE__)}] Joined Device channel")
NervesHubLink.Connection.connected()
NervesHubLink.Client.connected()
_ = handle_join_reply(reply)
{:ok, socket}
end
Expand Down Expand Up @@ -127,6 +132,11 @@ defmodule NervesHubLink.Socket do
{:noreply, socket}
end

def handle_cast({:send_connection_types, types}, socket) do
_ = push(socket, @device_topic, "connection_types", %{value: types})
{:noreply, socket}
end

@impl Slipstream
##
# Device API messages
Expand Down