-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start of device features (previously "extensions") which allow for specialized features on device to report data and interactions safely outside the update mechanism.
- Loading branch information
1 parent
9cb7633
commit 61b9720
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
defmodule NervesHubWeb.FeaturesChannel do | ||
use Phoenix.Channel | ||
|
||
alias Phoenix.Socket.Broadcast | ||
|
||
@impl Phoenix.Channel | ||
def join("features", payload, socket) do | ||
enable_list = | ||
for {feature, ver} <- payload, into: %{} do | ||
{feature, allowed?(feature, ver)} | ||
end | ||
|
||
topic = "device:#{socket.assigns.device.id}:features" | ||
Phoenix.PubSub.subscribe(NervesHub.PubSub, topic) | ||
|
||
{:ok, enable_list, socket} | ||
end | ||
|
||
defp allowed?(feature, ver) do | ||
# TODO: Some conditions for allow/disallow feature | ||
true | ||
end | ||
|
||
@impl Phoenix.Channel | ||
def handle_in(event, payload, socket) do | ||
dbg({event, payload}) | ||
{:noreply, socket} | ||
end | ||
|
||
@impl Phoenix.Channel | ||
# TODO: Get specific on messages passed to device | ||
def handle_info(%Broadcast{event: event, payload: payload}, socket) do | ||
push(socket, event, payload) | ||
{:noreply, socket} | ||
end | ||
end |