gpreston

gpreston

Has anyone had success using the phoenix.js library for interacting with channels in a standalone node.js application?

For context, I am creating a web app from which I want to be able to control LEDs. The idea is that any browser with the web page pulled up is connected to a Phoenix channel, and there is a separate program running on a computer with LEDs attached also joined to that channel. When a message is broadcasted to that channel saying to change the lights, the client sees this and changes them accordingly.

My plan so far is to create a node application which controls LEDs and uses phoenix.js to communicate with channels. However, in testing this out, I installed phoenix.js 1.5.4 (npm install --save phoenix) and wrote the most basic code to create a Socket object

var phoenix = require('phoenix');
const { Socket } = phoenix;

var socket = new Socket('/socket', {params: null});

and I got the following error:

TyperError: Cannot read property 'WebSocket' of undefined
    at new e (/home/gpreston/code/webcandy2-client/node_modules/phoenix/priv/static/phoenix.js:1:10519)
    at Object.<anonymous> (/home/gpreston/code/webcandy2-client/app.js:4:14)

Is there something I’m missing? I know my environment setup is different than that of a mix phx.new project, but I’m having trouble figuring out what would cause such an error. I’m also not an expert on node, so apologies if this ends up looking kinda dumb…thanks for any help.

Showing Posts 1 to 2

tcoopman

tcoopman

Using it should be no problem in a browser environment. In nodejs though you are missing some browser APIs like websocket.
You can try with polyfills but I don’t know which you’ll need exactly

gpreston

gpreston OP

Update for anyone wanting to do something similar: I ended up using this 3rd party Kotlin client library for Phoenix and it worked great. Seems like it’s advertised for Android but it works just the same in regular desktop Kotlin. Been meaning to try out Kotlin for something so this is the perfect thing to do that with :slight_smile:

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews