set connect url from server config

This commit is contained in:
Victor Martinez 2024-03-29 16:42:56 +01:00
parent 426323ef91
commit 69ba0caafb
6 changed files with 14 additions and 30 deletions

View file

@ -4,10 +4,7 @@ import { LiveSocket } from "phoenix_live_view";
import HubHook from "./hubHook";
const Hooks = {
HubHook: HubHook(
"ws://127.0.0.1:12345/buttplug",
"ws://192.168.1.45:12345/buttplug",
),
HubHook: HubHook(),
};
const liveSocket = new LiveSocket("/live", Socket, {

View file

@ -3,7 +3,7 @@ import {
ButtplugBrowserWebsocketClientConnector,
} from "buttplug";
const Hub = (localAddress, remoteAddress) => {
const Hub = () => {
const client = new ButtplugClient("IntisyncClient");
const connect = async (view, address) => {
@ -32,15 +32,7 @@ const Hub = (localAddress, remoteAddress) => {
await device.vibrate(vibration / 100.0);
});
this.handleEvent(
"local_connect",
async () => await connect(this, localAddress),
);
this.handleEvent(
"remote_connect",
async () => await connect(this, remoteAddress),
);
this.handleEvent("connect", async ({ url }) => await connect(this, url));
client.addListener("deviceadded", async (device) => {
const event = {

View file

@ -18,6 +18,8 @@ config :intisync, IntisyncWeb.Endpoint,
pubsub_server: Intisync.PubSub,
live_view: [signing_salt: "aSHjRP5j"]
config :intisync, IntisyncWeb.HubLive, connect_url: "ws://127.0.0.1:12345/buttplug"
# Configure esbuild (the version is required)
config :esbuild,
version: "0.17.11",

View file

@ -13,6 +13,10 @@ defmodule IntisyncWeb.HubLive do
|> assign(:intiface_client_status, nil)
|> assign(:devices, %{})
|> assign(:session_id, nil)
|> assign(
:connect_url,
Application.get_env(:intisync, __MODULE__, :connect_url) |> IO.inspect("CONNECT URL")
)
{:ok, socket}
end
@ -94,13 +98,8 @@ defmodule IntisyncWeb.HubLive do
# Intiface Client events #
##########################
def handle_event("local_connect", %{}, socket) do
socket = push_event(socket, "local_connect", %{})
{:noreply, socket}
end
def handle_event("remote_connect", %{}, socket) do
socket = push_event(socket, "remote_connect", %{})
def handle_event("connect", %{}, socket) do
socket = push_event(socket, "connect", %{url: socket.assigns.connect_url})
{:noreply, socket}
end

View file

@ -46,15 +46,9 @@
id="connect-buttons"
class="flex flex-col gap-6 items-center"
>
<.button id="intiface-local-connect-button" type="button" phx-click="local_connect">
<.button id="intiface-connect-button" type="button" phx-click="connect">
Connect to Intiface Central
</.button>
<p class="font-semibold">or</p>
<.button id="intiface-remote-connect-button" type="button" phx-click="remote_connect">
Connect to a remote Intiface Central
</.button>
</section>
<section :if={@intiface_client_status == :connected} id="connected-devices-section">

View file

@ -142,9 +142,9 @@ defmodule IntisyncWeb.HubLiveTest do
assert view |> element("#connect-buttons") |> has_element?()
assert view |> element("#intiface-local-connect-button") |> render_click()
assert view |> element("#intiface-connect-button") |> render_click()
assert_push_event(view, "local_connect", %{})
assert_push_event(view, "connect", %{})
end
test "A device connected event is ignored if intiface central is not connected", %{