dibok

dibok

Hi,

I’m trying to use phoenix.js in my Qt QML project which has it’s own buildin JavaScript engine. Problem is that (what I googled so far) that this engine has cut out WebSocket class, because QML has its own WebSocket component. When I import phoenix.js library and try to create Socket then I get error:

TypeError: Cannot read property 'WebSocket' of undefined

Problem is probably in this line:

this.transport = opts.transport || global.WebSocket || LongPoll;

So in theory, it is possible to inject QML WebSocket{} engine in phoenix.js by Qt.createQmlObject() or Qt.createComponent(). But this probably require change names of original WebSocket’s method names and signals etc. in phoenix.js file.
Did anyone tried this? I’m still newbie in QML and JavaScript, as C++ and Qt Widgetsets programmer, I’m trying to make new project using QML framework so I’m not such experienced to do it by my self.
Regards

Showing Posts 1 to 9

thomas.fortes

thomas.fortes

Hi and welcome :slight_smile:

How are you initializing your socket?
The phoenix.js docs have a list of options that you can pass when initializing it and transport is one of the options which would allow you to override (as you can see in the line that you highlighted as the source of the error).

dibok

dibok OP

Hi,
Thanks for reply.
I’m importing phoenix in my QML by this:

import "phoenix.js" as MyScript

And creating:

let socket = new MyScript.Phoenix.Socket("ws://localhost:4000/socket", {params: {token: "test_token"}})

I tried now with:

let socket = new MyScript.Phoenix.LongPoll("ws://localhost:4000/socket", {params: {token: "test_token"}})

But getting error:

phoenix.js:639: ReferenceError: setTimeout is not defined
linusdm

linusdm

I remember that this Qt JavaScript environment is a pita to work with…

What are you trying to accomplish? You want to interact and display a remote LiveView application? Or do you want to communicate with a Phoenix channel from within your Qt application?

dibok

dibok OP

Well. My friend is writting kind of chat (with rooms etc) using phoenix serwer. Beside WebApp client, we want to also have lightweight multiplatform desktop app which also cover mobiles. As a desktop programmer who have some experience with Qt Widgetsets C++ framework, decided to use Qt Quick QML framework to gain practice

linusdm

linusdm

If you’re only interested in communicating through a channel, then you don’t really need to use the javascript runtime. I think there are implementations in C and C++ to connect to a Phoenix Channel (can’t find it right now, so if anyone knows where to find those other language bindings, pls share).

If you want to display a LV, then you’ll have to solve this indeed. Or use another way to package your application. There are a few other ways to package a Phoenix app for desktop. Check LiveView Native for mobile.

dibok

dibok OP

Thanks for hints. I’ll do some research this evening. If indeed there is some unofficial C++ wrapper for phoenix then I can still use it in QML, because C++ is backend for QML and you can share C++ objects between Qt JavaScript and backend

LostKobrakai

LostKobrakai

dibok

dibok OP

There is no wrappers for C/C++ :frowning: . Seems that I must search for some unofficial

dibok

dibok OP

Look like there is no good C++ wrappers for phoenix. This one wasn’t updated from 7 years so I guess it will not work
https://github.com/jojojames/PhxSocketCPP

— All posts loaded —

Where Next? Top

Trending in Proposals: Ideas Top

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
raa-ziq
Hi everyone :waving_hand: I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews