gpreston

gpreston

Using phoenix.js outside of a Phoenix application

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.

Most Liked

gpreston

gpreston

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:

Where Next?

Popular in Questions Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New

Other popular topics Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement