Can't load phoenix.js library - Cannot read property 'WebSocket' of undefined
-
wrote on 1 Jul 2024, 19:47 last edited by Kobid 7 Jan 2024, 19:49
Hi,
My friend have phoenix server to which one I want to connect as client.
He gave me simple example:
source: https://github.com/phoenixframework/phoenix/blob/main/priv/static/phoenix.jsimport {Socket, Presence} from "phoenix" let socket = new Socket("ws://localhost:4000/socket", {params: {token: "test_token"}})
First problem was importing module. I have syntax errors with
import {Socket, Presence} from "phoenix"
. Finally I was able to import it with this:import "./phoenix.js" as MyScript
Now. This:let socket = new Socket("ws://localhost:4000/socket", {params: {token: "test_token"}})
Return:
ReferenceError: Socket is not defined
This:let socket = new Phoenix.Socket("ws://localhost:4000/socket", {params: {token: "test_token"}})
Return:
ReferenceError: Phoenix is not defined
This:let socket = new MyScript.Socket("ws://localhost:4000/socket", {params: {token: "test_token"}})
Return:
TypeError: Type error
And finally this:let socket = new MyScript.Phoenix.Socket("ws://localhost:4000/socket", {params: {token: "test_token"}})
Return:
TypeError: Cannot read property 'WebSocket' of undefined
First attempts were with phoenix.js from master but same errors with downloaded from stable release like 1.7.14.
Also. Seems that phoenix library worked fine with QML JavaScript because there is also this article:
https://chatgpt.com/share/4aa7e9c0-5b74-4e6b-9412-c5be248c95ac
He is usingQt.include("js/phoenix.js")
which doesn't work on my Qt 6.7:
Qt.include(): Can only be called from JavaScript files
Probably he made it on some Qt 5.X. Qt Doc is saying that this method is deprecated and will be removed in future Qt.Any ideas?
Regards -
wrote on 2 Jul 2024, 18:49 last edited by
I found this topic:
https://stackoverflow.com/questions/38935558/instantiate-browser-like-websocket-in-qml-js
Seems like Qt QML JavaScript engine has cut out websockets which is understandable since QML has its own WebSocket component. Is there any workaround?
1/2