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

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
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 & 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