mirror of
https://codeberg.org/JasterV/intisync.ex.git
synced 2026-04-26 18:10:07 +00:00
Merge pull request #3 from JasterV/refactor/set-connect-url-on-server
refactor: set connect url on server
This commit is contained in:
commit
5b40c342f8
6 changed files with 12 additions and 30 deletions
|
|
@ -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, {
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ defmodule IntisyncWeb.HubLive do
|
|||
alias Intisync.SessionsSupervisor
|
||||
alias Intisync.SessionServer
|
||||
|
||||
@config Application.compile_env!(:intisync, __MODULE__)
|
||||
|
||||
def mount(_params, _session, socket) do
|
||||
socket =
|
||||
socket
|
||||
|
|
@ -94,13 +96,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: @config[:connect_url]})
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -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">
|
||||
|
|
|
|||
|
|
@ -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", %{
|
||||
|
|
|
|||
Loading…
Reference in a new issue